52 this->SetNumberOfRequiredInputs(1);
53 this->SetNumberOfIndexedOutputs(1);
74 itkWarningMacro(<<
"Sorry, filename has not been set!");
77 std::ofstream out(m_FileName.c_str());
80 itkExceptionMacro(<<
"File " << m_FileName <<
" could not be opened!");
81 itkWarningMacro(<<
"Sorry, file " << m_FileName <<
" could not be opened!");
86 std::locale previousLocale(out.getloc());
94 WriteStartElement(XML_POINT_SET_FILE, out);
95 WriteStartElement(XML_FILE_VERSION, out);
96 WriteCharacterData(VERSION_STRING, out);
97 WriteEndElement(XML_FILE_VERSION, out,
false);
103 for (
unsigned int i = 0; i < this->GetNumberOfInputs(); ++i)
106 assert(pointSet.IsNotNull());
107 WriteXML(pointSet.GetPointer(), out);
110 WriteEndElement(XML_POINT_SET_FILE, out);
111 out.imbue(previousLocale);
115 throw std::ios_base::failure(
"Some error during point set writing.");
120 m_MimeType =
"application/MITK.PointSet";
125 WriteStartElement(XML_POINT_SET, out);
128 for (
unsigned int i = 0; i < timecount; i++)
130 WriteStartElement(XML_TIME_SERIES, out);
132 WriteStartElement(XML_TIME_SERIES_ID, out);
133 WriteCharacterData(ConvertToString(i).c_str(), out);
134 WriteEndElement(XML_TIME_SERIES_ID, out,
false);
137 mitk::PointSet::PointsContainer::Iterator it;
139 for (it = pointsContainer->Begin(); it != pointsContainer->End(); ++it)
141 WriteStartElement(XML_POINT, out);
143 WriteStartElement(XML_ID, out);
144 WriteCharacterData(ConvertToString(it->Index()).c_str(), out);
145 WriteEndElement(XML_ID, out,
false);
149 WriteStartElement(XML_SPEC, out);
151 WriteEndElement(XML_SPEC, out,
false);
153 WriteStartElement(XML_X, out);
154 WriteCharacterData(ConvertToString(point[0]).c_str(), out);
155 WriteEndElement(XML_X, out,
false);
157 WriteStartElement(XML_Y, out);
158 WriteCharacterData(ConvertToString(point[1]).c_str(), out);
159 WriteEndElement(XML_Y, out,
false);
161 WriteStartElement(XML_Z, out);
162 WriteCharacterData(ConvertToString(point[2]).c_str(), out);
163 WriteEndElement(XML_Z, out,
false);
165 WriteEndElement(XML_POINT, out);
167 WriteEndElement(XML_TIME_SERIES, out);
170 WriteEndElement(XML_POINT_SET, out);
175 unsigned int prevNum = this->GetNumberOfInputs();
176 this->SetNumberOfIndexedInputs(num);
177 for (
unsigned int i = prevNum; i < num; ++i)
185 this->ProcessObject::SetNthInput(0, pointSet);
190 if (
id >= this->GetNumberOfInputs())
191 this->ResizeInputs(
id + 1);
192 this->ProcessObject::SetNthInput(
id, pointSet);
197 if (this->GetNumberOfInputs() < 1)
203 return dynamic_cast<InputType *
>(this->GetInput(0));
209 return dynamic_cast<InputType *
>(this->ProcessObject::GetInput(num));
212 template <
typename T>
215 std::ostringstream o;
224 return "conversion error";
229 file <<
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
236 file << '<' << tag << '>
';
240 void mitk::PointSetWriter::WriteEndElement(const char *const tag, std::ofstream &file, const bool &indent)
248 file << '<
' << '/
' << tag << '>
';
251 void mitk::PointSetWriter::WriteCharacterData(const char *const data, std::ofstream &file)
256 void mitk::PointSetWriter::WriteStartElement(std::string &tag, std::ofstream &file)
258 WriteStartElement(tag.c_str(), file);
261 void mitk::PointSetWriter::WriteEndElement(std::string &tag, std::ofstream &file, const bool &indent)
263 WriteEndElement(tag.c_str(), file, indent);
266 void mitk::PointSetWriter::WriteCharacterData(std::string &data, std::ofstream &file)
268 WriteCharacterData(data.c_str(), file);
271 void mitk::PointSetWriter::WriteIndent(std::ofstream &file)
273 std::string spaces(m_IndentDepth * m_Indent, ' ');
274 file << spaces.c_str();
277 bool mitk::PointSetWriter::GetSuccess() const
282 bool mitk::PointSetWriter::CanWriteDataType(DataNode *input)
286 mitk::BaseData *data = input->GetData();
289 mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet *>(data);
290 if (pointSet.IsNotNull())
292 // this writer has no "SetDefaultExtension()" - function
293 m_Extension = ".mps";
301 void mitk::PointSetWriter::SetInput(DataNode *input)
303 if (input && CanWriteDataType(input))
304 this->ProcessObject::SetNthInput(0, dynamic_cast<mitk::PointSet *>(input->GetData()));
307 std::string mitk::PointSetWriter::GetWritenMIMEType()
312 std::vector<std::string> mitk::PointSetWriter::GetPossibleFileExtensions()
314 std::vector<std::string> possibleFileExtensions;
315 possibleFileExtensions.push_back(".mps");
316 return possibleFileExtensions;
319 std::string mitk::PointSetWriter::GetSupportedBaseData() const
321 return PointSet::GetStaticNameOfClass();
324 std::string mitk::PointSetWriter::GetFileExtension()
void SetInput(InputType *input)
virtual ~PointSetWriter()
static const char * XML_POINT
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...
std::string ConvertToString(T value)
static const char * XML_POINT_SET_FILE
static const char * XML_ID
static const char * XML_POINT_SET
static const char * XML_TIME_SERIES
void WriteStartElement(const char *const tag, std::ofstream &file)
Data structure which stores a set of points. Superclass of mitk::Mesh.
virtual DataType::Pointer GetPointSet(int t=0) const
returns the pointset
void WriteXML(mitk::PointSet *pointSet, std::ofstream &out)
DataType::PointsContainer PointsContainer
static const char * XML_TIME_SERIES_ID
static const char * XML_Y
void WriteXMLHeader(std::ofstream &file)
static const char * XML_FILE_VERSION
static const char * XML_Z
static const char * XML_SPEC
static const char * VERSION_STRING
static const char * XML_X
unsigned int m_IndentDepth
virtual void ResizeInputs(const unsigned int &num)
virtual void GenerateData() override