MCPcopy Create free account
hub / github.com/MITK/MITK / dictToProperty

Function dictToProperty

Wrapping/Python/mitk/PropertyConversionUtils.h:136–171  ·  view source on GitHub ↗

Convert dict to BaseProperty for JSON deserialization

Source from the content-addressed store, hash-verified

134
135 // Convert dict to BaseProperty for JSON deserialization
136 inline mitk::BaseProperty::Pointer dictToProperty(const py::dict &d)
137 {
138 std::string type = d["type"].cast<std::string>();
139
140 if (type == "StringProperty")
141 {
142 return mitk::StringProperty::New(d["value"].cast<std::string>());
143 }
144 else if (type == "BoolProperty")
145 {
146 return mitk::BoolProperty::New(d["value"].cast<bool>());
147 }
148 else if (type == "IntProperty")
149 {
150 return mitk::IntProperty::New(d["value"].cast<int>());
151 }
152 else if (type == "FloatProperty")
153 {
154 return mitk::FloatProperty::New(d["value"].cast<float>());
155 }
156 else if (type == "DoubleProperty")
157 {
158 return mitk::DoubleProperty::New(d["value"].cast<double>());
159 }
160 else if (type == "ColorProperty")
161 {
162 auto value = d["value"].cast<py::tuple>();
163 mitk::Color color;
164 color[0] = value[0].cast<float>();
165 color[1] = value[1].cast<float>();
166 color[2] = value[2].cast<float>();
167 return mitk::ColorProperty::New(color);
168 }
169
170 throw std::runtime_error("Unsupported property type: " + type);
171 }
172
173 } // namespace python
174} // namespace mitk

Callers 2

InitPropertyListFunction · 0.85
InitPropertyFunction · 0.85

Calls 1

NewFunction · 0.50

Tested by

no test coverage detected