36 #include <itksys/SystemTools.hxx>
42 this->SetNumberOfRequiredOutputs(1);
43 this->SetNumberOfIndexedOutputs(1);
61 this->SetNumberOfIndexedOutputs(0);
63 TiXmlDocument document;
67 if (m_MemoryBuffer ==
nullptr || m_MemorySize == 0)
70 itkWarningMacro(<<
"Sorry, memory buffer has not been set!");
73 if (m_MemoryBuffer[m_MemorySize - 1] ==
'\0')
75 document.Parse(m_MemoryBuffer);
79 auto tmpArray =
new char[(int)m_MemorySize + 1];
80 tmpArray[m_MemorySize] =
'\0';
81 memcpy(tmpArray, m_MemoryBuffer, m_MemorySize);
83 document.Parse(m_MemoryBuffer);
90 if (m_FileName.empty())
92 itkWarningMacro(<<
"Sorry, filename has not been set!");
95 if (this->CanReadFile(m_FileName.c_str()) ==
false)
97 itkWarningMacro(<<
"Sorry, can't read file " << m_FileName <<
"!");
100 if (!document.LoadFile(m_FileName))
102 MITK_ERROR <<
"Could not open/read/parse " << m_FileName <<
". TinyXML reports: '" << document.ErrorDesc()
104 <<
"The error occurred in row " << document.ErrorRow() <<
", column " << document.ErrorCol() <<
".";
110 TiXmlElement *versionObject = document.FirstChildElement(
"Version");
111 if (versionObject !=
nullptr)
113 if (versionObject->QueryIntAttribute(
"FileVersion", &fileVersion) != TIXML_SUCCESS)
115 MITK_WARN << m_FileName <<
" does not contain version information! Trying version 1 format." << std::endl;
120 MITK_WARN << m_FileName <<
" does not contain version information! Trying version 1 format." << std::endl;
125 MITK_WARN <<
"File version > 1 is not supported by this reader.";
130 for (TiXmlElement *pfElement = document.FirstChildElement(
"PlanarFigure"); pfElement !=
nullptr;
131 pfElement = pfElement->NextSiblingElement(
"PlanarFigure"))
133 if (pfElement ==
nullptr)
136 std::string type = pfElement->Attribute(
"type");
139 if (type ==
"PlanarAngle")
143 else if (type ==
"PlanarCircle")
147 else if (type ==
"PlanarEllipse")
149 planarFigure = mitk::PlanarEllipse::New();
151 else if (type ==
"PlanarCross")
155 else if (type ==
"PlanarFourPointAngle")
159 else if (type ==
"PlanarLine")
163 else if (type ==
"PlanarPolygon")
167 else if (type ==
"PlanarSubdivisionPolygon")
171 else if (type ==
"PlanarRectangle")
175 else if (type ==
"PlanarArrow")
179 else if (type ==
"PlanarDoubleEllipse")
183 else if (type ==
"PlanarBezierCurve")
185 planarFigure = mitk::PlanarBezierCurve::New();
190 MITK_WARN <<
"encountered unknown planar figure type '" << type <<
"'. Skipping this element.";
195 for (TiXmlElement *propertyElement = pfElement->FirstChildElement(
"property"); propertyElement !=
nullptr;
196 propertyElement = propertyElement->NextSiblingElement(
"property"))
198 const char *keya = propertyElement->Attribute(
"key");
199 const std::string key(keya ? keya :
"");
201 const char *typea = propertyElement->Attribute(
"type");
202 const std::string type(typea ? typea :
"");
205 std::stringstream propertyDeserializerClassName;
206 propertyDeserializerClassName << type <<
"Serializer";
208 const std::list<itk::LightObject::Pointer> readers =
209 itk::ObjectFactoryBase::CreateAllInstance(propertyDeserializerClassName.str().c_str());
210 if (readers.size() < 1)
212 MITK_ERROR <<
"No property reader found for " << type;
214 if (readers.size() > 1)
216 MITK_WARN <<
"Multiple property readers found for " << type <<
". Using arbitrary first one.";
219 for (
auto iter = readers.cbegin(); iter != readers.cend(); ++iter)
224 if (property.IsNotNull())
226 planarFigure->GetPropertyList()->ReplaceProperty(key, property);
230 MITK_ERROR <<
"There were errors while loading property '" << key <<
"' of type " << type
231 <<
". Your data may be corrupted";
241 planarFigure->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
246 if (planarPolygon !=
nullptr)
248 bool isClosed =
false;
249 planarFigure->GetPropertyList()->GetBoolProperty(
"closed", isClosed);
254 TiXmlElement *geoElement = pfElement->FirstChildElement(
"Geometry");
255 if (geoElement !=
nullptr)
264 this->GetDoubleAttributeListFromXMLNode(geoElement->FirstChildElement(
"transformParam"),
"param", 12);
267 TransformType::ParametersType parameters;
268 parameters.SetSize(12);
271 DoubleList::const_iterator it;
272 for (it = transformList.cbegin(), i = 0; it != transformList.cend(); ++it, ++i)
274 parameters.SetElement(i, *it);
279 affineGeometry->SetParameters(parameters);
280 planeGeo->SetIndexToWorldTransform(affineGeometry);
284 this->GetDoubleAttributeListFromXMLNode(geoElement->FirstChildElement(
"boundsParam"),
"bound", 6);
288 BoundsArrayType bounds;
289 for (it = boundsList.cbegin(), i = 0; it != boundsList.cend(); ++it, ++i)
294 planeGeo->SetBounds(bounds);
297 const Vector3D spacing = this->GetVectorFromXMLNode(geoElement->FirstChildElement(
"Spacing"));
298 planeGeo->SetSpacing(spacing);
300 const Point3D origin = this->GetPointFromXMLNode(geoElement->FirstChildElement(
"Origin"));
301 planeGeo->SetOrigin(origin);
302 planarFigure->SetPlaneGeometry(planeGeo);
308 TiXmlElement *cpElement = pfElement->FirstChildElement(
"ControlPoints");
310 if (cpElement !=
nullptr)
311 for (TiXmlElement *vertElement = cpElement->FirstChildElement(
"Vertex"); vertElement !=
nullptr;
312 vertElement = vertElement->NextSiblingElement(
"Vertex"))
314 if (vertElement ==
nullptr)
319 if (vertElement->QueryIntAttribute(
"id", &
id) == TIXML_WRONG_TYPE)
321 if (vertElement->QueryDoubleAttribute(
"x", &x) == TIXML_WRONG_TYPE)
323 if (vertElement->QueryDoubleAttribute(
"y", &y) == TIXML_WRONG_TYPE)
330 planarFigure->PlaceFigure(p);
333 planarFigure->SetControlPoint(
id, p,
true);
337 planarFigure->EvaluateFeatures();
340 planarFigure->DeselectControlPoint();
343 this->SetNthOutput(this->GetNumberOfOutputs(), planarFigure);
352 throw std::invalid_argument(
"node invalid");
355 if (e->QueryDoubleAttribute(
"x", &p) == TIXML_WRONG_TYPE)
356 throw std::invalid_argument(
"node malformatted");
357 point.SetElement(0, p);
358 if (e->QueryDoubleAttribute(
"y", &p) == TIXML_WRONG_TYPE)
359 throw std::invalid_argument(
"node malformatted");
360 point.SetElement(1, p);
361 if (e->QueryDoubleAttribute(
"z", &p) == TIXML_WRONG_TYPE)
362 throw std::invalid_argument(
"node malformatted");
363 point.SetElement(2, p);
370 throw std::invalid_argument(
"node invalid");
373 if (e->QueryDoubleAttribute(
"x", &p) == TIXML_WRONG_TYPE)
374 throw std::invalid_argument(
"node malformatted");
375 vector.SetElement(0, p);
376 if (e->QueryDoubleAttribute(
"y", &p) == TIXML_WRONG_TYPE)
377 throw std::invalid_argument(
"node malformatted");
378 vector.SetElement(1, p);
379 if (e->QueryDoubleAttribute(
"z", &p) == TIXML_WRONG_TYPE)
380 throw std::invalid_argument(
"node malformatted");
381 vector.SetElement(2, p);
386 TiXmlElement *e,
const char *attributeNameBase,
unsigned int count)
391 throw std::invalid_argument(
"node invalid");
393 for (
unsigned int i = 0; i < count; ++i)
396 std::stringstream attributeName;
397 attributeName << attributeNameBase << i;
399 if (e->QueryDoubleAttribute(attributeName.str().c_str(), &p) == TIXML_WRONG_TYPE)
400 throw std::invalid_argument(
"node malformatted");
413 if (std::string(name).empty())
416 return (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(name)) ==
427 if (filename.empty())
430 return (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(filename)) ==
441 unsigned int prevNum = this->GetNumberOfOutputs();
442 this->SetNumberOfIndexedOutputs(num);
443 for (
unsigned int i = prevNum; i < num; ++i)
445 this->SetNthOutput(i, this->MakeOutput(i).GetPointer());
itk::SmartPointer< Self > Pointer
BoundingBoxType::BoundsArrayType BoundsArrayType
virtual void SetClosed(bool closed)
Set whether the polygon should be closed between first and last control point or not.
GeometryTransformHolder::TransformType TransformType
Implementation of PlanarFigure representing a polygon with two or more control points.
Convenience class to temporarily change the current locale.
ValueType
Type of the value held by a Value object.
static const std::string filename
Base class for objects that serialize BaseProperty types.
Interface class of readers that read from files.
BoundingBoxType::BoundsArrayType BoundsArrayType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.