74 std::string category =
"Contour File";
86 :
AbstractFileWriter(other), m_IndentDepth(other.m_IndentDepth), m_Indent(other.m_Indent)
97 std::ofstream outStream;
99 if (this->GetOutputStream())
101 out = this->GetOutputStream();
105 outStream.open(this->GetOutputLocation().c_str());
114 std::locale previousLocale(out->getloc());
121 WriteXMLHeader(*out);
128 assert(contourModel.IsNotNull());
129 WriteXML(contourModel.GetPointer(), *out);
131 out->imbue(previousLocale);
135 throw std::ios_base::failure(
"Some error during contour writing.");
147 WriteStartElement(XML_CONTOURMODEL, out);
150 WriteStartElement(XML_HEAD, out);
153 WriteStartElement(XML_GEOMETRY_INFO, out);
158 WriteEndElement(XML_GEOMETRY_INFO, out);
161 WriteEndElement(XML_HEAD, out);
164 WriteStartElement(XML_DATA, out);
168 for (
unsigned int i = 0; i < timecount; i++)
171 std::vector<std::string> at;
173 std::vector<std::string> val;
174 val.push_back(ConvertToString(i));
176 at.push_back(
"isClosed");
177 val.push_back(ConvertToString(contourModel->
IsClosed()));
179 WriteStartElementWithAttribut(XML_TIME_STEP, at, val, out);
182 WriteStartElement(XML_CONTROL_POINTS, out);
192 std::vector<std::string> attr;
193 attr.push_back(
"IsControlPoint");
194 std::vector<std::string> value;
196 WriteStartElementWithAttribut(XML_POINT, attr, value, out);
199 WriteStartElement(XML_X, out);
200 WriteCharacterData(ConvertToString(v->
Coordinates[0]).c_str(), out);
202 WriteEndElement(XML_X, out,
false);
205 WriteStartElement(XML_Y, out);
206 WriteCharacterData(ConvertToString(v->
Coordinates[1]).c_str(), out);
208 WriteEndElement(XML_Y, out,
false);
211 WriteStartElement(XML_Z, out);
212 WriteCharacterData(ConvertToString(v->
Coordinates[2]).c_str(), out);
214 WriteEndElement(XML_Z, out,
false);
217 WriteEndElement(XML_POINT, out);
223 WriteEndElement(XML_CONTROL_POINTS, out);
226 WriteEndElement(XML_TIME_STEP, out);
230 WriteEndElement(XML_DATA, out);
233 WriteEndElement(XML_CONTOURMODEL, out);
238 WriteCharacterData(
"<!-- geometry information -->", out);
241 template <
typename T>
244 std::ostringstream o;
253 return "conversion error";
258 file <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>";
265 file << '<' << tag << '>
';
269 void mitk::ContourModelWriter::WriteStartElementWithAttribut(const char *const tag,
270 std::vector<std::string> attributes,
271 std::vector<std::string> values,
278 unsigned int attributesSize = attributes.size();
279 unsigned int valuesSize = values.size();
281 if (attributesSize == valuesSize)
283 std::vector<std::string>::iterator attributesIt = attributes.begin();
284 std::vector<std::string>::iterator end = attributes.end();
286 std::vector<std::string>::iterator valuesIt = values.begin();
288 while (attributesIt != end)
291 WriteCharacterData(*attributesIt, file);
293 WriteCharacterData(*valuesIt, file);
304 void mitk::ContourModelWriter::WriteEndElement(const char *const tag, std::ostream &file, const bool &indent)
312 file << '<
' << '/
' << tag << '>
';
315 void mitk::ContourModelWriter::WriteCharacterData(const char *const data, std::ostream &file)
320 void mitk::ContourModelWriter::WriteStartElement(std::string &tag, std::ostream &file)
322 WriteStartElement(tag.c_str(), file);
325 void mitk::ContourModelWriter::WriteEndElement(std::string &tag, std::ostream &file, const bool &indent)
327 WriteEndElement(tag.c_str(), file, indent);
330 void mitk::ContourModelWriter::WriteCharacterData(std::string &data, std::ostream &file)
332 WriteCharacterData(data.c_str(), file);
335 void mitk::ContourModelWriter::WriteIndent(std::ostream &file)
337 std::string spaces(m_IndentDepth * m_Indent, ' ');
338 file << spaces.c_str();
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
mitk::Point3D Coordinates
Coordinates in 3D space.
static const char * XML_DATA
void WriteGeometryInformation(const mitk::TimeGeometry *geometry, std::ostream &out)
mitk::ContourElement::VertexIterator VertexIterator
static const char * XML_Z
static const char * XML_POINT
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
static const char * XML_GEOMETRY_INFO
bool IsControlPoint
Treat point special.
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...
VertexIterator IteratorBegin(int timestep=0) const
Returns a const VertexIterator at the start element of the contour.
static const char * XML_X
void WriteXMLHeader(std::ostream &file)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static const char * XML_CONTROL_POINTS
static const char * XML_TIME_STEP
static const char * XML_HEAD
void WriteStartElement(const char *const tag, std::ostream &file)
virtual void Write() override
Write the base data to the specified location or output stream.
static const char * GetStaticNameOfClass()
void AddExtension(const std::string &extension)
void SetCategory(const std::string &category)
virtual ~ContourModelWriter()
std::string ConvertToString(T value)
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
bool IsClosed(int timestep=0) const
Return if the contour is closed or not.
void SetMimeType(const CustomMimeType &mimeType)
static const char * XML_CONTOURMODEL
void WriteXML(const mitk::ContourModel *contourModel, std::ostream &out)
virtual mitk::ContourModelWriter * Clone() const override
VertexIterator IteratorEnd(int timestep=0) const
Returns a const VertexIterator at the end element of the contour.
Base class for writing mitk::BaseData objects to files or streams.
void SetDescription(const std::string &description)
Sets a human readable description of this writer.
static const char * XML_Y
Represents a single vertex of contour.