XML-based writer for mitk::PointSets. More...
#include <mitkPointSetWriter.h>
Public Types | |
typedef PointSetWriter | Self |
typedef mitk::FileWriter | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
typedef mitk::PointSet | InputType |
typedef InputType::Pointer | InputTypePointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | Write () |
virtual void | Update () |
virtual void | SetFileName (const char *_arg) |
virtual const char * | GetFileName () const |
virtual void | SetFilePrefix (const char *_arg) |
virtual const char * | GetFilePrefix () const |
virtual void | SetFilePattern (const char *_arg) |
virtual const char * | GetFilePattern () const |
void | SetInput (InputType *input) |
void | SetInput (const unsigned int &num, InputType *input) |
PointSet * | GetInput () |
PointSet * | GetInput (const unsigned int &num) |
virtual std::vector< std::string > | GetPossibleFileExtensions () |
Return the possible file extensions for the data type associated with the writer. | |
virtual std::string | GetFileExtension () |
Return the extension to be added to the filename. | |
virtual bool | CanWriteDataType (DataNode *) |
Check if the Writer can write the Content of the. | |
virtual std::string | GetWritenMIMEType () |
Return the MimeType of the saved File. | |
virtual void | SetInput (DataNode *) |
Set the DataTreenode as Input. Important: The Writer always have a SetInput-Function. | |
bool | GetSuccess () const |
Static Public Member Functions | |
static Pointer | New () |
Static Public Attributes | |
static const char * | XML_POINT_SET = "point_set" |
static const char * | XML_TIME_SERIES = "time_series" |
static const char * | XML_TIME_SERIES_ID = "time_series_id" |
static const char * | XML_POINT_SET_FILE = "point_set_file" |
static const char * | XML_FILE_VERSION = "file_version" |
static const char * | XML_POINT = "point" |
static const char * | XML_SPEC = "specification" |
static const char * | XML_ID = "id" |
static const char * | XML_X = "x" |
static const char * | XML_Y = "y" |
static const char * | XML_Z = "z" |
static const char * | VERSION_STRING = "0.1" |
Protected Member Functions | |
PointSetWriter () | |
virtual | ~PointSetWriter () |
virtual void | GenerateData () |
virtual void | ResizeInputs (const unsigned int &num) |
template<typename T > | |
std::string | ConvertToString (T value) |
void | WriteXML (mitk::PointSet *pointSet, std::ofstream &out) |
void | WriteXMLHeader (std::ofstream &file) |
void | WriteStartElement (const char *const tag, std::ofstream &file) |
void | WriteEndElement (const char *const tag, std::ofstream &file, const bool &indent=true) |
void | WriteCharacterData (const char *const data, std::ofstream &file) |
void | WriteStartElement (std::string &tag, std::ofstream &file) |
void | WriteEndElement (std::string &tag, std::ofstream &file, const bool &indent=true) |
void | WriteCharacterData (std::string &data, std::ofstream &file) |
void | WriteIndent (std::ofstream &file) |
Protected Attributes | |
std::string | m_FileName |
std::string | m_FilePrefix |
std::string | m_FilePattern |
std::string | m_Extension |
std::string | m_MimeType |
unsigned int | m_IndentDepth |
unsigned int | m_Indent |
bool | m_Success |
XML-based writer for mitk::PointSets.
XML-based writer for mitk::PointSets. Multiple PointSets can be written in a single XML file by simply setting multiple inputs to the filter. Writing of multiple XML files according to a given filename pattern is not yet supported.
Definition at line 39 of file mitkPointSetWriter.h.
typedef itk::SmartPointer<const Self> mitk::PointSetWriter::ConstPointer |
Reimplemented from mitk::FileWriter.
Definition at line 43 of file mitkPointSetWriter.h.
Definition at line 47 of file mitkPointSetWriter.h.
Definition at line 51 of file mitkPointSetWriter.h.
typedef itk::SmartPointer<Self> mitk::PointSetWriter::Pointer |
Reimplemented from mitk::FileWriter.
Definition at line 43 of file mitkPointSetWriter.h.
Reimplemented from mitk::FileWriter.
Definition at line 43 of file mitkPointSetWriter.h.
Reimplemented from mitk::FileWriter.
Definition at line 43 of file mitkPointSetWriter.h.
mitk::PointSetWriter::PointSetWriter | ( | ) | [protected] |
Constructor.
Definition at line 56 of file mitkPointSetWriter.cpp.
References m_Indent, m_IndentDepth, m_Success, and mitk::PointSet::New().
: m_FileName(""), m_FilePrefix(""), m_FilePattern("") { this->SetNumberOfRequiredInputs( 1 ); this->SetNumberOfOutputs( 1 ); this->SetNthOutput( 0, mitk::PointSet::New().GetPointer() ); m_Indent = 2; m_IndentDepth = 0; m_Success = false; }
mitk::PointSetWriter::~PointSetWriter | ( | ) | [protected, virtual] |
bool mitk::PointSetWriter::CanWriteDataType | ( | DataNode * | input ) | [virtual] |
Check if the Writer can write the Content of the.
Reimplemented from mitk::FileWriter.
Definition at line 343 of file mitkPointSetWriter.cpp.
{ if ( input ) { mitk::BaseData* data = input->GetData(); if ( data ) { mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet*>( data ); if( pointSet.IsNotNull() ) { //this writer has no "SetDefaultExtension()" - function m_Extension = ".mps"; return true; } } } return false; }
std::string mitk::PointSetWriter::ConvertToString | ( | T | value ) | [protected] |
Converts an arbitrary type to a string. The type has to support the << operator. This works fine at least for integral data types as float, int, long etc.
value | the value to convert |
Definition at line 247 of file mitkPointSetWriter.cpp.
{ std::ostringstream o; std::locale I("C"); o.imbue(I); if ( o << value ) { return o.str(); } else return "conversion error"; }
void mitk::PointSetWriter::GenerateData | ( | ) | [protected, virtual] |
Writes the XML file
Definition at line 76 of file mitkPointSetWriter.cpp.
{ m_Success = false; m_IndentDepth = 0; // // Opening the file to write to // if ( m_FileName == "" ) { itkWarningMacro( << "Sorry, filename has not been set!" ); return ; } std::ofstream out( m_FileName.c_str() ); if ( !out.good() ) { itkExceptionMacro(<< "File " << m_FileName << " could not be opened!"); itkWarningMacro( << "Sorry, file " << m_FileName << " could not be opened!" ); out.close(); return ; } std::locale previousLocale(out.getloc()); std::locale I("C"); out.imbue(I); // // Here the actual xml writing begins // WriteXMLHeader( out ); WriteStartElement( XML_POINT_SET_FILE, out ); WriteStartElement( XML_FILE_VERSION, out ); WriteCharacterData( VERSION_STRING, out ); WriteEndElement( XML_FILE_VERSION, out, false ); // // for each input object write its xml representation to // the stream // for ( unsigned int i = 0 ; i < this->GetNumberOfInputs(); ++i ) { InputType::Pointer pointSet = this->GetInput( i ); assert( pointSet.IsNotNull() ); WriteXML( pointSet.GetPointer(), out ); } WriteEndElement( XML_POINT_SET_FILE, out ); out.imbue(previousLocale); if ( !out.good() ) // some error during output { out.close(); throw std::ios_base::failure("Some error during point set writing."); } out.close(); m_Success = true; m_MimeType = "application/MITK.PointSet"; }
virtual const char* mitk::PointSetWriter::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::FileWriter.
std::string mitk::PointSetWriter::GetFileExtension | ( | ) | [virtual] |
Return the extension to be added to the filename.
Reimplemented from mitk::FileWriter.
Definition at line 380 of file mitkPointSetWriter.cpp.
{ return m_Extension; }
virtual const char* mitk::PointSetWriter::GetFileName | ( | ) | const [virtual] |
Implements mitk::FileWriter.
virtual const char* mitk::PointSetWriter::GetFilePattern | ( | ) | const [virtual] |
Implements mitk::FileWriter.
virtual const char* mitk::PointSetWriter::GetFilePrefix | ( | ) | const [virtual] |
Implements mitk::FileWriter.
mitk::PointSet * mitk::PointSetWriter::GetInput | ( | void | ) |
Definition at line 222 of file mitkPointSetWriter.cpp.
mitk::PointSet * mitk::PointSetWriter::GetInput | ( | const unsigned int & | num ) |
num | the index of the desired output object. |
Definition at line 237 of file mitkPointSetWriter.cpp.
{ return dynamic_cast<InputType*> ( this->ProcessObject::GetInput( num ) ); }
std::vector< std::string > mitk::PointSetWriter::GetPossibleFileExtensions | ( | ) | [virtual] |
Return the possible file extensions for the data type associated with the writer.
Implements mitk::FileWriter.
Definition at line 373 of file mitkPointSetWriter.cpp.
{ std::vector<std::string> possibleFileExtensions; possibleFileExtensions.push_back(".mps"); return possibleFileExtensions; }
bool mitk::PointSetWriter::GetSuccess | ( | ) | const |
Definition at line 336 of file mitkPointSetWriter.cpp.
{ return m_Success; }
std::string mitk::PointSetWriter::GetWritenMIMEType | ( | ) | [virtual] |
Return the MimeType of the saved File.
Reimplemented from mitk::FileWriter.
Definition at line 368 of file mitkPointSetWriter.cpp.
{ return m_MimeType; }
static Pointer mitk::PointSetWriter::New | ( | ) | [static] |
void mitk::PointSetWriter::ResizeInputs | ( | const unsigned int & | num ) | [protected, virtual] |
Resizes the number of inputs of the writer. The inputs are initialized by empty PointSets
num | the new number of inputs |
Definition at line 192 of file mitkPointSetWriter.cpp.
References mitk::PointSet::New().
{ unsigned int prevNum = this->GetNumberOfInputs(); this->SetNumberOfInputs( num ); for ( unsigned int i = prevNum; i < num; ++i ) { this->SetNthInput( i, mitk::PointSet::New().GetPointer() ); } }
virtual void mitk::PointSetWriter::SetFileName | ( | const char * | _arg ) | [virtual] |
Sets the filename of the file to write.
FileName | the name of the file to write. |
Implements mitk::FileWriter.
virtual void mitk::PointSetWriter::SetFilePattern | ( | const char * | _arg ) | [virtual] |
Implements mitk::FileWriter.
virtual void mitk::PointSetWriter::SetFilePrefix | ( | const char * | _arg ) | [virtual] |
Implements mitk::FileWriter.
void mitk::PointSetWriter::SetInput | ( | DataNode * | input ) | [virtual] |
Set the DataTreenode as Input. Important: The Writer always have a SetInput-Function.
Reimplemented from mitk::FileWriter.
Definition at line 362 of file mitkPointSetWriter.cpp.
{ if( input && CanWriteDataType( input ) ) this->ProcessObject::SetNthInput( 0, dynamic_cast<mitk::PointSet*>( input->GetData() ) ); }
void mitk::PointSetWriter::SetInput | ( | InputType * | input ) |
Sets the 0'th input object for the filter.
input | the first input for the filter. |
Definition at line 205 of file mitkPointSetWriter.cpp.
{ this->ProcessObject::SetNthInput( 0, pointSet ); }
void mitk::PointSetWriter::SetInput | ( | const unsigned int & | num, |
InputType * | input | ||
) |
Sets the n'th input object for the filter. If num is larger than GetNumberOfInputs() the number of inputs is resized appropriately.
input | the n'th input for the filter. |
Definition at line 213 of file mitkPointSetWriter.cpp.
{ if ( id >= this->GetNumberOfInputs() ) this->ResizeInputs( id + 1 ); this->ProcessObject::SetNthInput( id, pointSet ); }
virtual void mitk::PointSetWriter::Update | ( | ) | [inline, virtual] |
Definition at line 45 of file mitkPointSetWriter.h.
virtual void mitk::PointSetWriter::Write | ( | ) | [inline, virtual] |
Implements mitk::FileWriter.
Definition at line 45 of file mitkPointSetWriter.h.
void mitk::PointSetWriter::WriteCharacterData | ( | std::string & | data, |
std::ofstream & | file | ||
) | [protected] |
Write character data inside a tag.
Definition at line 320 of file mitkPointSetWriter.cpp.
{ WriteCharacterData( data.c_str(), file ); }
void mitk::PointSetWriter::WriteCharacterData | ( | const char *const | data, |
std::ofstream & | file | ||
) | [protected] |
Write character data inside a tag.
Definition at line 296 of file mitkPointSetWriter.cpp.
{ file << data; }
void mitk::PointSetWriter::WriteEndElement | ( | std::string & | tag, |
std::ofstream & | file, | ||
const bool & | indent = true |
||
) | [protected] |
Write an end element tag
Definition at line 312 of file mitkPointSetWriter.cpp.
{ WriteEndElement( tag.c_str(), file, indent ); }
void mitk::PointSetWriter::WriteEndElement | ( | const char *const | tag, |
std::ofstream & | file, | ||
const bool & | indent = true |
||
) | [protected] |
Write an end element tag End-Elements following character data should pass indent = false.
Definition at line 282 of file mitkPointSetWriter.cpp.
{ m_IndentDepth--; if ( indent ) { file << std::endl; WriteIndent( file ); } file << '<' << '/' << tag << '>'; }
void mitk::PointSetWriter::WriteIndent | ( | std::ofstream & | file ) | [protected] |
Writes empty spaces to the stream according to m_IndentDepth and m_Indent
Definition at line 328 of file mitkPointSetWriter.cpp.
{ std::string spaces( m_IndentDepth * m_Indent, ' ' ); file << spaces.c_str(); }
void mitk::PointSetWriter::WriteStartElement | ( | std::string & | tag, |
std::ofstream & | file | ||
) | [protected] |
Write a start element tag
Definition at line 304 of file mitkPointSetWriter.cpp.
{ WriteStartElement( tag.c_str(), file ); }
void mitk::PointSetWriter::WriteStartElement | ( | const char *const | tag, |
std::ofstream & | file | ||
) | [protected] |
Write a start element tag
Definition at line 271 of file mitkPointSetWriter.cpp.
{ file << std::endl; WriteIndent( file ); file << '<' << tag << '>'; m_IndentDepth++; }
void mitk::PointSetWriter::WriteXML | ( | mitk::PointSet * | pointSet, |
std::ofstream & | out | ||
) | [protected] |
Writes an XML representation of the given point set to an outstream. The XML-Header an root node is not included!
pointSet | the point set to be converted to xml |
out | the stream to write to. |
Definition at line 138 of file mitkPointSetWriter.cpp.
References mitk::PointSet::GetPointSet(), mitk::PointSet::GetSpecificationTypeInfo(), and mitk::BaseData::GetTimeSteps().
{ WriteStartElement( XML_POINT_SET, out ); mitk::PointSet::PointsContainer* pointsContainer = pointSet->GetPointSet()->GetPoints(); mitk::PointSet::PointsContainer::Iterator it; unsigned int timecount = pointSet->GetTimeSteps(); for(unsigned int i=0; i< timecount; i++) { WriteStartElement( XML_TIME_SERIES, out ); WriteStartElement( XML_TIME_SERIES_ID, out ); WriteCharacterData( ConvertToString( i ).c_str() , out ); WriteEndElement( XML_TIME_SERIES_ID, out, false ); for ( it = pointsContainer->Begin(); it != pointsContainer->End(); ++it ) { WriteStartElement( XML_POINT, out ); WriteStartElement( XML_ID, out ); WriteCharacterData( ConvertToString( it->Index() ).c_str() , out ); WriteEndElement( XML_ID, out, false ); mitk::PointSet::PointType point = it->Value(); WriteStartElement( XML_SPEC, out ); WriteCharacterData( ConvertToString( pointSet->GetSpecificationTypeInfo(it->Index(), i) ).c_str() , out ); WriteEndElement( XML_SPEC, out, false ); WriteStartElement( XML_X, out ); WriteCharacterData( ConvertToString( point[ 0 ] ).c_str(), out ); WriteEndElement( XML_X, out, false ); WriteStartElement( XML_Y, out ); WriteCharacterData( ConvertToString( point[ 1 ] ).c_str(), out ); WriteEndElement( XML_Y, out, false ); WriteStartElement( XML_Z, out ); WriteCharacterData( ConvertToString( point[ 2 ] ).c_str(), out ); WriteEndElement( XML_Z, out, false ); WriteEndElement( XML_POINT, out ); } WriteEndElement( XML_TIME_SERIES, out ); } WriteEndElement( XML_POINT_SET, out ); }
void mitk::PointSetWriter::WriteXMLHeader | ( | std::ofstream & | file ) | [protected] |
Writes an standard xml header to the given stream.
file | the stream in which the header is written. |
Definition at line 263 of file mitkPointSetWriter.cpp.
{
file << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
}
std::string mitk::PointSetWriter::m_Extension [protected] |
Definition at line 221 of file mitkPointSetWriter.h.
std::string mitk::PointSetWriter::m_FileName [protected] |
Definition at line 215 of file mitkPointSetWriter.h.
std::string mitk::PointSetWriter::m_FilePattern [protected] |
Definition at line 219 of file mitkPointSetWriter.h.
std::string mitk::PointSetWriter::m_FilePrefix [protected] |
Definition at line 217 of file mitkPointSetWriter.h.
unsigned int mitk::PointSetWriter::m_Indent [protected] |
Definition at line 227 of file mitkPointSetWriter.h.
Referenced by PointSetWriter().
unsigned int mitk::PointSetWriter::m_IndentDepth [protected] |
Definition at line 225 of file mitkPointSetWriter.h.
Referenced by PointSetWriter().
std::string mitk::PointSetWriter::m_MimeType [protected] |
Definition at line 223 of file mitkPointSetWriter.h.
bool mitk::PointSetWriter::m_Success [protected] |
Definition at line 229 of file mitkPointSetWriter.h.
Referenced by PointSetWriter().
const char * mitk::PointSetWriter::VERSION_STRING = "0.1" [static] |
Definition at line 257 of file mitkPointSetWriter.h.
const char * mitk::PointSetWriter::XML_FILE_VERSION = "file_version" [static] |
Definition at line 243 of file mitkPointSetWriter.h.
const char * mitk::PointSetWriter::XML_ID = "id" [static] |
Definition at line 249 of file mitkPointSetWriter.h.
Referenced by mitk::vtkPointSetXMLParser::CharacterDataHandler().
const char * mitk::PointSetWriter::XML_POINT = "point" [static] |
Definition at line 245 of file mitkPointSetWriter.h.
Referenced by mitk::vtkPointSetXMLParser::EndElement(), and mitk::vtkPointSetXMLParser::StartElement().
const char * mitk::PointSetWriter::XML_POINT_SET = "point_set" [static] |
Definition at line 235 of file mitkPointSetWriter.h.
Referenced by mitk::vtkPointSetXMLParser::EndElement(), and mitk::vtkPointSetXMLParser::StartElement().
const char * mitk::PointSetWriter::XML_POINT_SET_FILE = "point_set_file" [static] |
Definition at line 241 of file mitkPointSetWriter.h.
const char * mitk::PointSetWriter::XML_SPEC = "specification" [static] |
Definition at line 247 of file mitkPointSetWriter.h.
const char * mitk::PointSetWriter::XML_TIME_SERIES = "time_series" [static] |
Definition at line 237 of file mitkPointSetWriter.h.
const char * mitk::PointSetWriter::XML_TIME_SERIES_ID = "time_series_id" [static] |
Definition at line 239 of file mitkPointSetWriter.h.
const char * mitk::PointSetWriter::XML_X = "x" [static] |
Definition at line 251 of file mitkPointSetWriter.h.
Referenced by mitk::vtkPointSetXMLParser::CharacterDataHandler().
const char * mitk::PointSetWriter::XML_Y = "y" [static] |
Definition at line 253 of file mitkPointSetWriter.h.
Referenced by mitk::vtkPointSetXMLParser::CharacterDataHandler().
const char * mitk::PointSetWriter::XML_Z = "z" [static] |
Definition at line 255 of file mitkPointSetWriter.h.
Referenced by mitk::vtkPointSetXMLParser::CharacterDataHandler().