32 #include <itksys/SystemTools.hxx> 38 this->SetNumberOfRequiredOutputs(1);
39 this->SetNumberOfIndexedOutputs(1);
57 this->SetNumberOfIndexedOutputs(0);
59 TiXmlDocument document;
66 itkWarningMacro(<<
"Sorry, memory buffer has not been set!");
88 itkWarningMacro(<<
"Sorry, filename has not been set!");
93 itkWarningMacro(<<
"Sorry, can't read file " <<
m_FileName <<
"!");
98 MITK_ERROR <<
"Could not open/read/parse " <<
m_FileName <<
". TinyXML reports: '" << document.ErrorDesc()
100 <<
"The error occurred in row " << document.ErrorRow() <<
", column " << document.ErrorCol() <<
".";
106 TiXmlElement *versionObject = document.FirstChildElement(
"Version");
107 if (versionObject !=
nullptr)
109 if (versionObject->QueryIntAttribute(
"FileVersion", &fileVersion) != TIXML_SUCCESS)
111 MITK_WARN <<
m_FileName <<
" does not contain version information! Trying version 1 format." << std::endl;
116 MITK_WARN <<
m_FileName <<
" does not contain version information! Trying version 1 format." << std::endl;
121 MITK_WARN <<
"File version > 1 is not supported by this reader.";
126 for (TiXmlElement *pfElement = document.FirstChildElement(
"PlanarFigure"); pfElement !=
nullptr;
127 pfElement = pfElement->NextSiblingElement(
"PlanarFigure"))
129 std::string type = pfElement->Attribute(
"type");
132 if (type ==
"PlanarAngle")
136 else if (type ==
"PlanarCircle")
140 else if (type ==
"PlanarEllipse")
144 else if (type ==
"PlanarCross")
148 else if (type ==
"PlanarFourPointAngle")
152 else if (type ==
"PlanarLine")
156 else if (type ==
"PlanarPolygon")
160 else if (type ==
"PlanarSubdivisionPolygon")
164 else if (type ==
"PlanarRectangle")
168 else if (type ==
"PlanarArrow")
172 else if (type ==
"PlanarDoubleEllipse")
174 planarFigure = mitk::PlanarDoubleEllipse::New();
176 else if (type ==
"PlanarBezierCurve")
183 MITK_WARN <<
"encountered unknown planar figure type '" << type <<
"'. Skipping this element.";
188 for (TiXmlElement *propertyElement = pfElement->FirstChildElement(
"property"); propertyElement !=
nullptr;
189 propertyElement = propertyElement->NextSiblingElement(
"property"))
191 const char *keya = propertyElement->Attribute(
"key");
192 const std::string key(keya ? keya :
"");
194 const char *typea = propertyElement->Attribute(
"type");
195 const std::string type(typea ? typea :
"");
198 std::stringstream propertyDeserializerClassName;
199 propertyDeserializerClassName << type <<
"Serializer";
201 const std::list<itk::LightObject::Pointer> readers =
202 itk::ObjectFactoryBase::CreateAllInstance(propertyDeserializerClassName.str().c_str());
203 if (readers.size() < 1)
205 MITK_ERROR <<
"No property reader found for " << type;
207 if (readers.size() > 1)
209 MITK_WARN <<
"Multiple property readers found for " << type <<
". Using arbitrary first one.";
212 for (
auto iter = readers.cbegin(); iter != readers.cend(); ++iter)
214 if (
auto *reader = dynamic_cast<BasePropertySerializer *>(iter->GetPointer()))
217 if (property.IsNotNull())
219 planarFigure->GetPropertyList()->ReplaceProperty(key, property);
223 MITK_ERROR <<
"There were errors while loading property '" << key <<
"' of type " << type
224 <<
". Your data may be corrupted";
234 planarFigure->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
238 auto *planarPolygon =
dynamic_cast<PlanarPolygon *
>(planarFigure.GetPointer());
239 if (planarPolygon !=
nullptr)
241 bool isClosed =
false;
242 planarFigure->GetPropertyList()->GetBoolProperty(
"closed", isClosed);
243 planarPolygon->SetClosed(isClosed);
247 TiXmlElement *geoElement = pfElement->FirstChildElement(
"Geometry");
248 if (geoElement !=
nullptr)
260 TransformType::ParametersType parameters;
261 parameters.SetSize(12);
264 DoubleList::const_iterator it;
265 for (it = transformList.cbegin(), i = 0; it != transformList.cend(); ++it, ++i)
267 parameters.SetElement(i, *it);
271 TransformType::Pointer affineGeometry = TransformType::New();
272 affineGeometry->SetParameters(parameters);
273 planeGeo->SetIndexToWorldTransform(affineGeometry);
281 BoundsArrayType bounds;
282 for (it = boundsList.cbegin(), i = 0; it != boundsList.cend(); ++it, ++i)
287 planeGeo->SetBounds(bounds);
291 planeGeo->SetSpacing(spacing);
294 planeGeo->SetOrigin(origin);
295 planarFigure->SetPlaneGeometry(planeGeo);
301 TiXmlElement *cpElement = pfElement->FirstChildElement(
"ControlPoints");
303 if (cpElement !=
nullptr)
304 for (TiXmlElement *vertElement = cpElement->FirstChildElement(
"Vertex"); vertElement !=
nullptr;
305 vertElement = vertElement->NextSiblingElement(
"Vertex"))
310 if (vertElement->QueryIntAttribute(
"id", &
id) == TIXML_WRONG_TYPE)
312 if (vertElement->QueryDoubleAttribute(
"x", &x) == TIXML_WRONG_TYPE)
314 if (vertElement->QueryDoubleAttribute(
"y", &y) == TIXML_WRONG_TYPE)
321 planarFigure->PlaceFigure(p);
324 planarFigure->SetControlPoint(
id, p,
true);
328 planarFigure->EvaluateFeatures();
331 planarFigure->DeselectControlPoint();
334 this->SetNthOutput(this->GetNumberOfOutputs(), planarFigure);
343 throw std::invalid_argument(
"node invalid");
346 if (e->QueryDoubleAttribute(
"x", &p) == TIXML_WRONG_TYPE)
347 throw std::invalid_argument(
"node malformatted");
348 point.SetElement(0, p);
349 if (e->QueryDoubleAttribute(
"y", &p) == TIXML_WRONG_TYPE)
350 throw std::invalid_argument(
"node malformatted");
351 point.SetElement(1, p);
352 if (e->QueryDoubleAttribute(
"z", &p) == TIXML_WRONG_TYPE)
353 throw std::invalid_argument(
"node malformatted");
354 point.SetElement(2, p);
361 throw std::invalid_argument(
"node invalid");
364 if (e->QueryDoubleAttribute(
"x", &p) == TIXML_WRONG_TYPE)
365 throw std::invalid_argument(
"node malformatted");
366 vector.SetElement(0, p);
367 if (e->QueryDoubleAttribute(
"y", &p) == TIXML_WRONG_TYPE)
368 throw std::invalid_argument(
"node malformatted");
369 vector.SetElement(1, p);
370 if (e->QueryDoubleAttribute(
"z", &p) == TIXML_WRONG_TYPE)
371 throw std::invalid_argument(
"node malformatted");
372 vector.SetElement(2, p);
377 TiXmlElement *e,
const char *attributeNameBase,
unsigned int count)
382 throw std::invalid_argument(
"node invalid");
384 for (
unsigned int i = 0; i < count; ++i)
387 std::stringstream attributeName;
388 attributeName << attributeNameBase << i;
390 if (e->QueryDoubleAttribute(attributeName.str().c_str(), &p) == TIXML_WRONG_TYPE)
391 throw std::invalid_argument(
"node malformatted");
404 if (std::string(name).empty())
407 return (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(name)) ==
418 if (filename.empty())
421 return (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(filename)) ==
432 unsigned int prevNum = this->GetNumberOfOutputs();
433 this->SetNumberOfIndexedOutputs(num);
434 for (
unsigned int i = prevNum; i < num; ++i)
436 this->SetNthOutput(i, this->
MakeOutput(i).GetPointer());
BoundingBoxType::BoundsArrayType BoundsArrayType
GeometryTransformHolder::TransformType TransformType
Implementation of PlanarFigure representing a polygon with two or more control points.
Convenience class to temporarily change the current locale.
unsigned int m_MemorySize
ValueType
Type of the value held by a Value object.
const char * m_MemoryBuffer
Interface class of readers that read from files.
BoundingBoxType::BoundsArrayType BoundsArrayType