27 m_MimeType(
"application/MITK.PlanarFigure"),
30 this->SetNumberOfRequiredInputs(1);
31 this->SetNumberOfIndexedOutputs(0);
45 if (!m_WriteToMemory && m_FileName.empty())
47 MITK_ERROR <<
"Could not write planar figures. File name is invalid";
48 throw std::invalid_argument(
"file name is empty");
51 TiXmlDocument document;
52 auto decl =
new TiXmlDeclaration(
"1.0",
"",
"");
53 document.LinkEndChild(decl);
55 auto version =
new TiXmlElement(
"Version");
56 version->SetAttribute(
"Writer", __FILE__);
57 version->SetAttribute(
"CVSRevision",
"$Revision: 17055 $");
58 version->SetAttribute(
"FileVersion", 1);
59 document.LinkEndChild(version);
62 for (
unsigned int i = 0; i < this->GetNumberOfInputs(); ++i)
68 auto pfElement =
new TiXmlElement(
"PlanarFigure");
69 pfElement->SetAttribute(
"type", pf->GetNameOfClass());
70 document.LinkEndChild(pfElement);
72 if (pf->GetNumberOfControlPoints() == 0)
81 mitk::PropertyList::PropertyMap::const_iterator it;
82 for (it = propertyList->GetMap()->begin(); it != propertyList->GetMap()->end(); ++it)
86 std::string serializerName = std::string(prop->GetNameOfClass()) +
"Serializer";
87 std::list<itk::LightObject::Pointer> allSerializers =
88 itk::ObjectFactoryBase::CreateAllInstance(serializerName.c_str());
90 if (allSerializers.size() != 1)
98 if (serializer ==
nullptr)
103 auto keyElement =
new TiXmlElement(
"property");
104 keyElement->SetAttribute(
"key", it->first);
105 keyElement->SetAttribute(
"type", prop->GetNameOfClass());
108 TiXmlElement *valueElement =
nullptr;
117 if (valueElement ==
nullptr)
124 keyElement->LinkEndChild(valueElement);
127 pfElement->LinkEndChild(keyElement);
131 auto controlPointsElement =
new TiXmlElement(
"ControlPoints");
132 pfElement->LinkEndChild(controlPointsElement);
133 for (
unsigned int i = 0; i < pf->GetNumberOfControlPoints(); i++)
135 auto vElement =
new TiXmlElement(
"Vertex");
136 vElement->SetAttribute(
"id", i);
137 vElement->SetDoubleAttribute(
"x", pf->GetControlPoint(i)[0]);
138 vElement->SetDoubleAttribute(
"y", pf->GetControlPoint(i)[1]);
139 controlPointsElement->LinkEndChild(vElement);
141 auto geoElement =
new TiXmlElement(
"Geometry");
143 if (planeGeo !=
nullptr)
148 const TransformType::ParametersType ¶meters = affineGeometry->GetParameters();
149 auto vElement =
new TiXmlElement(
"transformParam");
150 for (
unsigned int i = 0; i < affineGeometry->GetNumberOfParameters(); ++i)
152 std::stringstream paramName;
153 paramName <<
"param" << i;
154 vElement->SetDoubleAttribute(paramName.str().c_str(), parameters.GetElement(i));
156 geoElement->LinkEndChild(vElement);
160 const BoundsArrayType &bounds = planeGeo->
GetBounds();
161 vElement =
new TiXmlElement(
"boundsParam");
162 for (
unsigned int i = 0; i < 6; ++i)
164 std::stringstream boundName;
165 boundName <<
"bound" << i;
166 vElement->SetDoubleAttribute(boundName.str().c_str(), bounds.GetElement(i));
168 geoElement->LinkEndChild(vElement);
173 geoElement->LinkEndChild(this->CreateXMLVectorElement(
"Spacing", spacing));
174 geoElement->LinkEndChild(this->CreateXMLVectorElement(
"Origin", origin));
176 pfElement->LinkEndChild(geoElement);
183 TiXmlPrinter printer;
185 document.Accept(&printer);
188 m_MemoryBufferSize = printer.Size() + 1;
189 m_MemoryBuffer =
new char[m_MemoryBufferSize];
190 strcpy(m_MemoryBuffer, printer.CStr());
194 if (document.SaveFile(m_FileName) ==
false)
196 MITK_ERROR <<
"Could not write planar figures to " << m_FileName <<
"\nTinyXML reports '" << document.ErrorDesc()
198 throw std::ios_base::failure(
"Error during writing of planar figure xml file.");
206 if (m_MemoryBuffer !=
nullptr)
208 delete[] m_MemoryBuffer;
214 auto vElement =
new TiXmlElement(name);
215 vElement->SetDoubleAttribute(
"x", v.GetElement(0));
216 vElement->SetDoubleAttribute(
"y", v.GetElement(1));
217 vElement->SetDoubleAttribute(
"z", v.GetElement(2));
224 this->SetNumberOfIndexedInputs(num);
233 this->ProcessObject::SetNthInput(0, PlanarFigure);
238 if (
id >= this->GetNumberOfInputs())
239 this->ResizeInputs(
id + 1);
240 this->ProcessObject::SetNthInput(
id, PlanarFigure);
245 if (this->GetNumberOfInputs() < 1)
248 return dynamic_cast<InputType *
>(this->GetInput(0));
253 return dynamic_cast<InputType *
>(this->ProcessObject::GetInput(num));
258 if (input ==
nullptr)
266 if (PlanarFigure.IsNull())
274 if (this->CanWriteDataType(input))
275 this->ProcessObject::SetNthInput(0, dynamic_cast<mitk::PlanarFigure *>(input->
GetData()));
290 std::vector<std::string> possibleFileExtensions;
291 possibleFileExtensions.push_back(m_Extension);
292 return possibleFileExtensions;
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
BoundingBoxType::BoundsArrayType BoundsArrayType
Base of all data objects.
virtual void SetProperty(const BaseProperty *_arg)
GeometryTransformHolder::TransformType TransformType
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
static const char * GetStaticNameOfClass()
const BoundsArrayType GetBounds() const
Abstract base class for properties.
virtual TiXmlElement * Serialize()
Serializes given BaseProperty object.
Base class for objects that serialize BaseProperty types.
Describes a two-dimensional, rectangular plane.
Class for nodes of the DataTree.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
BoundingBoxType::BoundsArrayType BoundsArrayType