29 const std::string mitk::PointSetWriterService::XML_POINT_SET_FILE =
"point_set_file";
30 const std::string mitk::PointSetWriterService::XML_FILE_VERSION =
"file_version";
31 const std::string mitk::PointSetWriterService::XML_POINT_SET =
"point_set";
32 const std::string mitk::PointSetWriterService::XML_TIME_SERIES =
"time_series";
33 const std::string mitk::PointSetWriterService::XML_TIME_SERIES_ID =
"time_series_id";
34 const std::string mitk::PointSetWriterService::XML_POINT =
"point";
35 const std::string mitk::PointSetWriterService::XML_ID =
"id";
36 const std::string mitk::PointSetWriterService::XML_SPEC =
"specification";
37 const std::string mitk::PointSetWriterService::XML_X =
"x";
38 const std::string mitk::PointSetWriterService::XML_Y =
"y";
39 const std::string mitk::PointSetWriterService::XML_Z =
"z";
40 const std::string mitk::PointSetWriterService::VERSION_STRING =
"0.1";
63 auto *decl =
new TiXmlDeclaration(
65 doc.LinkEndChild(decl);
67 auto *rootNode =
new TiXmlElement(XML_POINT_SET_FILE);
68 doc.LinkEndChild(rootNode);
70 auto *versionNode =
new TiXmlElement(XML_FILE_VERSION);
71 auto *versionText =
new TiXmlText(VERSION_STRING);
72 versionNode->LinkEndChild(versionText);
73 rootNode->LinkEndChild(versionNode);
75 TiXmlElement *pointSetNode = ToXML(static_cast<const PointSet *>(this->
GetInput()));
78 mitkThrow() <<
"Serialization error during PointSet writing.";
80 rootNode->LinkEndChild(pointSetNode);
88 mitkThrow() <<
"Some error during point set writing.";
97 TiXmlElement *mitk::PointSetWriterService::ToXML(
const mitk::PointSet *pointSet)
102 auto *pointSetElement =
new TiXmlElement(XML_POINT_SET);
105 for (
unsigned int i = 0; i < timecount; i++)
107 auto *timeSeriesElement =
new TiXmlElement(XML_TIME_SERIES);
108 pointSetElement->LinkEndChild(timeSeriesElement);
110 auto *timeSeriesIDElement =
new TiXmlElement(XML_TIME_SERIES_ID);
111 timeSeriesElement->LinkEndChild(timeSeriesIDElement);
112 TiXmlText *timeSeriesIDText =
new TiXmlText(ConvertToString(i));
113 timeSeriesIDElement->LinkEndChild(timeSeriesIDText);
116 PointSet::PointsContainer::Iterator it;
119 if (geometry ==
nullptr)
121 MITK_WARN <<
"Writing a PointSet with something other that a Geometry3D. This is not foreseen and not handled.";
127 timeSeriesElement->LinkEndChild(geometryElement);
130 for (it = pointsContainer->Begin(); it != pointsContainer->End(); ++it)
132 auto *pointElement =
new TiXmlElement(XML_POINT);
133 timeSeriesElement->LinkEndChild(pointElement);
135 auto *pointIDElement =
new TiXmlElement(XML_ID);
136 TiXmlText *pointIDText =
new TiXmlText(ConvertToString(it->Index()));
137 pointIDElement->LinkEndChild(pointIDText);
138 pointElement->LinkEndChild(pointIDElement);
142 auto *pointSpecElement =
new TiXmlElement(XML_SPEC);
144 pointSpecElement->LinkEndChild(pointSpecText);
145 pointElement->LinkEndChild(pointSpecElement);
147 auto *pointXElement =
new TiXmlElement(XML_X);
148 TiXmlText *pointXText =
new TiXmlText(ConvertToString(point[0]));
149 pointXElement->LinkEndChild(pointXText);
150 pointElement->LinkEndChild(pointXElement);
152 auto *pointYElement =
new TiXmlElement(XML_Y);
153 TiXmlText *pointYText =
new TiXmlText(ConvertToString(point[1]));
154 pointYElement->LinkEndChild(pointYText);
155 pointElement->LinkEndChild(pointYElement);
157 auto *pointZElement =
new TiXmlElement(XML_Z);
158 TiXmlText *pointZText =
new TiXmlText(ConvertToString(point[2]));
159 pointZElement->LinkEndChild(pointZText);
160 pointElement->LinkEndChild(pointZElement);
164 return pointSetElement;
167 template <
typename T>
168 std::string mitk::PointSetWriterService::ConvertToString(T value)
170 std::ostringstream o;
174 if (o << std::setprecision(12) << value)
180 return "conversion error";
AbstractFileWriter(const AbstractFileWriter &other)
Standard implementation of BaseGeometry.
virtual PointSpecificationType GetSpecificationTypeInfo(int position, int t) const
to get the type of the point at the position and the moment
std::string GetFileName()
static TiXmlElement * ToXML(const Geometry3D *geometry)
Serialize given geometry to XML.
void Write() override
Write the base data to the specified location or output stream.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
Data structure which stores a set of points. Superclass of mitk::Mesh.
Convenience class to temporarily change the current locale.
virtual DataType::Pointer GetPointSet(int t=0) const
returns the pointset
const BaseData * GetInput() const override
Get the input data set via SetInput().
A local file representation for streams.
~PointSetWriterService() override
DataType::PointsContainer PointsContainer
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
unsigned int GetTimeSteps() const
Get the number of time steps from the TimeGeometry As the base data has not a data vector given by it...
Base class for writing mitk::BaseData objects to files or streams.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.