33 const std::string mitk::PointSetWriterService::XML_POINT_SET_FILE =
"point_set_file";
34 const std::string mitk::PointSetWriterService::XML_FILE_VERSION =
"file_version";
35 const std::string mitk::PointSetWriterService::XML_POINT_SET =
"point_set";
36 const std::string mitk::PointSetWriterService::XML_TIME_SERIES =
"time_series";
37 const std::string mitk::PointSetWriterService::XML_TIME_SERIES_ID =
"time_series_id";
38 const std::string mitk::PointSetWriterService::XML_POINT =
"point";
39 const std::string mitk::PointSetWriterService::XML_ID =
"id";
40 const std::string mitk::PointSetWriterService::XML_SPEC =
"specification";
41 const std::string mitk::PointSetWriterService::XML_X =
"x";
42 const std::string mitk::PointSetWriterService::XML_Y =
"y";
43 const std::string mitk::PointSetWriterService::XML_Z =
"z";
44 const std::string mitk::PointSetWriterService::VERSION_STRING =
"0.1";
67 TiXmlDeclaration *decl =
new TiXmlDeclaration(
69 doc.LinkEndChild(decl);
71 TiXmlElement *rootNode =
new TiXmlElement(XML_POINT_SET_FILE);
72 doc.LinkEndChild(rootNode);
74 TiXmlElement *versionNode =
new TiXmlElement(XML_FILE_VERSION);
75 TiXmlText *versionText =
new TiXmlText(VERSION_STRING);
76 versionNode->LinkEndChild(versionText);
77 rootNode->LinkEndChild(versionNode);
79 TiXmlElement *pointSetNode = ToXML(static_cast<const PointSet *>(this->GetInput()));
82 mitkThrow() <<
"Serialization error during PointSet writing.";
84 rootNode->LinkEndChild(pointSetNode);
92 mitkThrow() <<
"Some error during point set writing.";
101 TiXmlElement *mitk::PointSetWriterService::ToXML(
const mitk::PointSet *pointSet)
106 TiXmlElement *pointSetElement =
new TiXmlElement(XML_POINT_SET);
109 for (
unsigned int i = 0; i < timecount; i++)
111 TiXmlElement *timeSeriesElement =
new TiXmlElement(XML_TIME_SERIES);
112 pointSetElement->LinkEndChild(timeSeriesElement);
114 TiXmlElement *timeSeriesIDElement =
new TiXmlElement(XML_TIME_SERIES_ID);
115 timeSeriesElement->LinkEndChild(timeSeriesIDElement);
116 TiXmlText *timeSeriesIDText =
new TiXmlText(ConvertToString(i));
117 timeSeriesIDElement->LinkEndChild(timeSeriesIDText);
120 PointSet::PointsContainer::Iterator it;
122 Geometry3D *geometry =
dynamic_cast<Geometry3D *
>(pointSet->
GetGeometry(i));
123 if (geometry ==
nullptr)
125 MITK_WARN <<
"Writing a PointSet with something other that a Geometry3D. This is not foreseen and not handled.";
131 timeSeriesElement->LinkEndChild(geometryElement);
134 for (it = pointsContainer->Begin(); it != pointsContainer->End(); ++it)
136 TiXmlElement *pointElement =
new TiXmlElement(XML_POINT);
137 timeSeriesElement->LinkEndChild(pointElement);
139 TiXmlElement *pointIDElement =
new TiXmlElement(XML_ID);
140 TiXmlText *pointIDText =
new TiXmlText(ConvertToString(it->Index()));
141 pointIDElement->LinkEndChild(pointIDText);
142 pointElement->LinkEndChild(pointIDElement);
146 TiXmlElement *pointSpecElement =
new TiXmlElement(XML_SPEC);
148 pointSpecElement->LinkEndChild(pointSpecText);
149 pointElement->LinkEndChild(pointSpecElement);
151 TiXmlElement *pointXElement =
new TiXmlElement(XML_X);
152 TiXmlText *pointXText =
new TiXmlText(ConvertToString(point[0]));
153 pointXElement->LinkEndChild(pointXText);
154 pointElement->LinkEndChild(pointXElement);
156 TiXmlElement *pointYElement =
new TiXmlElement(XML_Y);
157 TiXmlText *pointYText =
new TiXmlText(ConvertToString(point[1]));
158 pointYElement->LinkEndChild(pointYText);
159 pointElement->LinkEndChild(pointYElement);
161 TiXmlElement *pointZElement =
new TiXmlElement(XML_Z);
162 TiXmlText *pointZText =
new TiXmlText(ConvertToString(point[2]));
163 pointZElement->LinkEndChild(pointZText);
164 pointElement->LinkEndChild(pointZElement);
168 return pointSetElement;
171 template <
typename T>
172 std::string mitk::PointSetWriterService::ConvertToString(T value)
174 std::ostringstream o;
178 if (o << std::setprecision(12) << value)
184 return "conversion error";
std::string GetFileName()
virtual PointSpecificationType GetSpecificationTypeInfo(int position, int t) const
to get the type of the point at the position and the moment
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...
static TiXmlElement * ToXML(const Geometry3D *geometry)
Serialize given geometry to XML.
virtual void Write() override
Write the base data to the specified location or output stream.
virtual ~PointSetWriterService()
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
static const char * GetStaticNameOfClass()
A local file representation for streams.
DataType::PointsContainer PointsContainer
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Base class for writing mitk::BaseData objects to files or streams.