43 #include <pybind11/pybind11.h>
45 namespace py = pybind11;
71 return py::cast(strProp->GetValue());
73 else if (
const mitk::BoolProperty *boolProp =
dynamic_cast<const mitk::BoolProperty *
>(&prop))
75 return py::cast(boolProp->GetValue());
77 else if (
const mitk::IntProperty *intProp =
dynamic_cast<const mitk::IntProperty *
>(&prop))
79 return py::cast(intProp->GetValue());
81 else if (
const mitk::FloatProperty *floatProp =
dynamic_cast<const mitk::FloatProperty *
>(&prop))
83 return py::cast(floatProp->GetValue());
85 else if (
const mitk::DoubleProperty *doubleProp =
dynamic_cast<const mitk::DoubleProperty *
>(&prop))
87 return py::cast(doubleProp->GetValue());
91 auto color = colorProp->GetColor();
92 return py::make_tuple(color[0], color[1], color[2]);
96 return py::cast(&prop, py::return_value_policy::reference);
103 result[
"type"] = prop.GetNameOfClass();
108 result[
"value"] = strProp->GetValue();
110 else if (
const mitk::BoolProperty *boolProp =
dynamic_cast<const mitk::BoolProperty *
>(&prop))
112 result[
"value"] = boolProp->GetValue();
114 else if (
const mitk::IntProperty *intProp =
dynamic_cast<const mitk::IntProperty *
>(&prop))
116 result[
"value"] = intProp->GetValue();
118 else if (
const mitk::FloatProperty *floatProp =
dynamic_cast<const mitk::FloatProperty *
>(&prop))
120 result[
"value"] = floatProp->GetValue();
122 else if (
const mitk::DoubleProperty *doubleProp =
dynamic_cast<const mitk::DoubleProperty *
>(&prop))
124 result[
"value"] = doubleProp->GetValue();
128 auto color = colorProp->GetColor();
129 result[
"value"] = py::make_tuple(color[0], color[1], color[2]);
138 std::string type = d[
"type"].cast<std::string>();
140 if (type ==
"StringProperty")
144 else if (type ==
"BoolProperty")
146 return mitk::BoolProperty::New(d[
"value"].cast<bool>());
148 else if (type ==
"IntProperty")
150 return mitk::IntProperty::New(d[
"value"].cast<int>());
152 else if (type ==
"FloatProperty")
154 return mitk::FloatProperty::New(d[
"value"].cast<float>());
156 else if (type ==
"DoubleProperty")
158 return mitk::DoubleProperty::New(d[
"value"].cast<double>());
160 else if (type ==
"ColorProperty")
162 auto value = d[
"value"].cast<py::tuple>();
164 color[0] = value[0].cast<
float>();
165 color[1] = value[1].cast<
float>();
166 color[2] = value[2].cast<
float>();
170 throw std::runtime_error(
"Unsupported property type: " + type);
Abstract base class for properties.
Property for storing RGB color values.
Property for storing string values.
Declares commonly used GenericProperty specializations for MITK.
py::object propertyToPythonValue(const mitk::BaseProperty &prop)
Converts a BaseProperty to its Python native value.
py::dict propertyToDict(const mitk::BaseProperty &prop)
mitk::BaseProperty::Pointer dictToProperty(const py::dict &d)
Find image slices visible on a given plane.
itk::RGBPixel< float > Color
Standard RGB color typedef using float components.