Skip to content

Commit 3050354

Browse files
committed
Fix crash in Python when calling dip.Polygon.FitCircle() without previously having output any dip.VertexFloat.
This is probably a bug in Pybind11.
1 parent dc13248 commit 3050354

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

pydip/src/measurement.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ DIP_OUTPUT_TYPE_CASTER( Measurement::FeatureInformation, "FeatureInformation", "
3535
DIP_OUTPUT_TYPE_CASTER( Feature::ValueInformation, "ValueInformation", "name units", src.name, src.units )
3636
DIP_OUTPUT_TYPE_CASTER( FeretValues, "FeretValues", "maxDiameter minDiameter maxPerpendicular maxAngle minAngle", src.maxDiameter, src.minDiameter, src.maxPerpendicular, src.maxAngle, src.minAngle )
3737
DIP_OUTPUT_TYPE_CASTER( RadiusValues, "RadiusValues", "mean standardDev maximum minimum circularity", src.Mean(), src.StandardDeviation(), src.Maximum(), src.Minimum(), src.Circularity() )
38-
DIP_OUTPUT_TYPE_CASTER( CircleParameters, "CircleParameters", "center diameter", src.center, src.diameter )
39-
DIP_OUTPUT_TYPE_CASTER( EllipseParameters, "EllipseParameters", "center majorAxis minorAxis orientation eccentricity", src.center, src.majorAxis, src.minorAxis, src.orientation, src.eccentricity )
4038

4139
} // namespace detail
4240
} // namespace pybind11
@@ -150,6 +148,40 @@ class type_caster< dip::BoundingBoxInteger > {
150148
PYBIND11_TYPE_CASTER( type, _( "BoundingBoxInteger" ));
151149
};
152150

151+
template<>
152+
class type_caster< dip::CircleParameters > {
153+
public:
154+
using type = dip::CircleParameters;
155+
156+
bool load( handle /*src*/, bool /*convert*/ ) {
157+
return false; // Disallow casting to the type, this is not an input argument anywhere
158+
}
159+
160+
static handle cast( dip::CircleParameters const& src, return_value_policy /*policy*/, handle /*parent*/ ) {
161+
auto center = VertexTuple( src.center );
162+
return CreateNamedTuple( "CircleParameters", "topLeft bottomRight", center, src.diameter ).release();
163+
}
164+
165+
PYBIND11_TYPE_CASTER( type, _( "CircleParameters" ));
166+
};
167+
168+
template<>
169+
class type_caster< dip::EllipseParameters > {
170+
public:
171+
using type = dip::EllipseParameters;
172+
173+
bool load( handle /*src*/, bool /*convert*/ ) {
174+
return false; // Disallow casting to the type, this is not an input argument anywhere
175+
}
176+
177+
static handle cast( dip::EllipseParameters const& src, return_value_policy /*policy*/, handle /*parent*/ ) {
178+
auto center = VertexTuple( src.center );
179+
return CreateNamedTuple( "EllipseParameters", "center majorAxis minorAxis orientation eccentricity", center, src.majorAxis, src.minorAxis, src.orientation, src.eccentricity ).release();
180+
}
181+
182+
PYBIND11_TYPE_CASTER( type, _( "EllipseParameters" ));
183+
};
184+
153185
} // namespace detail
154186
} // namespace pybind11
155187

0 commit comments

Comments
 (0)