Page MenuHomePhabricator

4DPointSetReaderWriter.patch

Authored By
seitelm
Feb 24 2010, 4:55 PM
Size
43 KB
Referenced Files
None
Subscribers
None

4DPointSetReaderWriter.patch

This document is not UTF8. It was detected as ISO-8859-1 (Latin 1) and converted to UTF8 for display.
Index: mitk/Core/Code/IO/mitkPointSetReader.cpp
===================================================================
--- mitk/Core/Code/IO/mitkPointSetReader.cpp (revision 21444)
+++ mitk/Core/Code/IO/mitkPointSetReader.cpp (working copy)
@@ -33,43 +33,52 @@
void mitk::PointSetReader::GenerateData()
{
- m_Success = false;
- if ( m_FileName == "" )
- {
- itkWarningMacro( << "Sorry, filename has not been set!" );
- return ;
- }
- if ( ! this->CanReadFile( m_FileName.c_str() ) )
- {
- itkWarningMacro( << "Sorry, can't read file " << m_FileName << "!" );
- return ;
- }
- std::ifstream in( m_FileName.c_str() );
- if ( ! in.good() )
- {
- itkWarningMacro( << "Sorry, can't read file " << m_FileName << "!" );
- in.close();
- return ;
- }
+ m_Success = false;
+ if ( m_FileName == "" )
+ {
+ itkWarningMacro( << "Sorry, filename has not been set!" );
+ return ;
+ }
+ if ( ! this->CanReadFile( m_FileName.c_str() ) )
+ {
+ itkWarningMacro( << "Sorry, can't read file " << m_FileName << "!" );
+ return ;
+ }
+ std::ifstream in( m_FileName.c_str() );
+ if ( ! in.good() )
+ {
+ itkWarningMacro( << "Sorry, can't read file " << m_FileName << "!" );
in.close();
+ return ;
+ }
+ in.close();
- mitk::vtkPointSetXMLParser* parser = mitk::vtkPointSetXMLParser::New();
- parser->SetFileName( m_FileName.c_str() );
- if ( parser->Parse() == 0 ) //Parse returns zero as error indicator
- {
- itkWarningMacro( << "Sorry, an error occurred during parsing!" );
- return ;
- }
- mitk::vtkPointSetXMLParser::PointSetList pointSetList = parser->GetParsedPointSets();
- this->ResizeOutputs( pointSetList.size() );
+ mitk::vtkPointSetXMLParser* parser = mitk::vtkPointSetXMLParser::New();
+ parser->SetFileName( m_FileName.c_str() );
+ if ( parser->Parse() == 0 ) //Parse returns zero as error indicator
+ {
+ itkWarningMacro( << "Sorry, an error occurred during parsing!" );
+ return ;
+ }
+ mitk::vtkPointSetXMLParser::PointSetList pointSetList = parser->GetParsedPointSets();
+ this->ResizeOutputs( pointSetList.size() );
- unsigned int i = 0;
- for ( mitk::vtkPointSetXMLParser::PointSetList::iterator it = pointSetList.begin(); it != pointSetList.end(); ++it, ++i )
+ unsigned int i = 0;
+ for ( mitk::vtkPointSetXMLParser::PointSetList::iterator it = pointSetList.begin(); it != pointSetList.end(); ++it, ++i )
+ {
+ mitk::PointSet::Pointer pointSet = *it;
+ for (unsigned int j=0;j<pointSet->GetPointSetSeriesSize();j++)
{
- this->SetNthOutput( i, *it );
+ std::cout<<"ReaderPointSetSeriesSize: "<<pointSet->GetPointSetSeriesSize()<<std::endl;
+ for(int i=0; i<pointSet->GetSize(j); i++)
+ {
+ std::cout<< "Pointset Reader: " <<pointSet->GetPoint(i,j)<<std::endl;
+ }
}
- parser->Delete();
- m_Success = true;
+ this->SetNthOutput( i, *it );
+ }
+ parser->Delete();
+ m_Success = true;
}
@@ -79,20 +88,20 @@
int mitk::PointSetReader::CanReadFile ( const char *name )
{
- std::ifstream in( name );
- if ( !in.good() )
- {
- in.close();
- return false;
- }
- else
- {
- in.close();
- return true;
- }
+ std::ifstream in( name );
+ if ( !in.good() )
+ {
+ in.close();
+ return false;
+ }
+ else
+ {
+ in.close();
+ return true;
+ }
}
-bool mitk::PointSetReader::CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern)
+bool mitk::PointSetReader::CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern)
{
// First check the extension
if( filename == "" )
@@ -109,38 +118,38 @@
std::string::size_type MPSPos = filename.rfind(".mps");
if ((MPSPos != std::string::npos)
&& (MPSPos == filename.length() - 4))
- {
+ {
extensionFound = true;
- }
+ }
MPSPos = filename.rfind(".MPS");
if ((MPSPos != std::string::npos)
&& (MPSPos == filename.length() - 4))
- {
+ {
extensionFound = true;
- }
+ }
if( !extensionFound )
- {
- //MITK_INFO<<"The filename extension is not recognized."<<std::endl;
+ {
+ //MITK_INFO<<"The filename extension is not recognized."<<std::endl;
return false;
- }
+ }
return true;
}
void mitk::PointSetReader::ResizeOutputs( const unsigned int& num )
{
- unsigned int prevNum = this->GetNumberOfOutputs();
- this->SetNumberOfOutputs( num );
- for ( unsigned int i = prevNum; i < num; ++i )
- {
- this->SetNthOutput( i, this->MakeOutput( i ).GetPointer() );
- }
+ unsigned int prevNum = this->GetNumberOfOutputs();
+ this->SetNumberOfOutputs( num );
+ for ( unsigned int i = prevNum; i < num; ++i )
+ {
+ this->SetNthOutput( i, this->MakeOutput( i ).GetPointer() );
+ }
}
bool mitk::PointSetReader::GetSuccess() const
{
- return m_Success;
+ return m_Success;
}
Index: mitk/Core/Code/IO/mitkPointSetWriter.cpp
===================================================================
--- mitk/Core/Code/IO/mitkPointSetWriter.cpp (revision 21444)
+++ mitk/Core/Code/IO/mitkPointSetWriter.cpp (working copy)
@@ -15,12 +15,11 @@
=========================================================================*/
-
#include "mitkPointSetWriter.h"
#include <iostream>
#include <fstream>
+#include <locale>
-
//
// Initialization of the xml tags.
//
@@ -29,6 +28,10 @@
const char* mitk::PointSetWriter::XML_FILE_VERSION = "file_version" ;
+const char* mitk::PointSetWriter::XML_TIME_SERIES = "time_series";
+
+const char* mitk::PointSetWriter::XML_TIME_SERIES_ID= "time_series_id";
+
const char* mitk::PointSetWriter::XML_POINT_SET = "point_set" ;
const char* mitk::PointSetWriter::XML_POINT = "point" ;
@@ -43,12 +46,8 @@
const char* mitk::PointSetWriter::VERSION_STRING = "0.1" ;
-
-
-
-mitk::PointSetWriter::PointSetWriter()
- : m_FileName(""), m_FilePrefix(""), m_FilePattern("")
-{
+mitk::PointSetWriter::PointSetWriter() :
+ m_FileName(""), m_FilePrefix(""), m_FilePattern("") {
this->SetNumberOfRequiredInputs( 1 );
this->SetNumberOfOutputs( 1 );
this->SetNthOutput( 0, mitk::PointSet::New().GetPointer() );
@@ -57,37 +56,32 @@
m_Success = false;
}
+mitk::PointSetWriter::~PointSetWriter() {
+}
-
-
-mitk::PointSetWriter::~PointSetWriter()
-{}
-
-
-
-
-void mitk::PointSetWriter::GenerateData()
-{
+void mitk::PointSetWriter::GenerateData() {
m_Success = false;
m_IndentDepth = 0;
//
// Opening the file to write to
//
- if ( m_FileName == "" )
- {
+ if ( m_FileName == "") {
itkWarningMacro( << "Sorry, filename has not been set!" );
return ;
}
std::ofstream out( m_FileName.c_str() );
- if ( !out.good() )
- {
+ if (!out.good()) {
itkExceptionMacro(<< "File " << m_FileName << " could not be opened!");
- itkWarningMacro( << "Sorry, file " << m_FileName << " could not be opened!" );
- out.close();
+ 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
//
@@ -101,15 +95,14 @@
// for each input object write its xml representation to
// the stream
//
- for ( unsigned int i = 0 ; i < this->GetNumberOfInputs(); ++i )
- {
+ 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 );
-
+ WriteEndElement( XML_POINT_SET_FILE, out );
+ out.imbue(previousLocale);
if ( !out.good() ) // some error during output
{
out.close();
@@ -121,16 +114,18 @@
m_MimeType = "application/MITK.PointSet";
}
-
-
-
-void mitk::PointSetWriter::WriteXML( mitk::PointSet* pointSet, std::ofstream& out )
-{
+void mitk::PointSetWriter::WriteXML(mitk::PointSet* pointSet,
+ std::ofstream& out) {
WriteStartElement( XML_POINT_SET, out );
- mitk::PointSet::PointsContainer* pointsContainer = pointSet->GetPointSet()->GetPoints();
+ for (unsigned int t = 0; t < pointSet->GetPointSetSeriesSize(); ++t) {
+ WriteStartElement(XML_TIME_SERIES, out);
+ WriteStartElement(XML_TIME_SERIES_ID,out);
+ WriteCharacterData(ConvertToString(t).c_str(),out);
+ WriteEndElement(XML_TIME_SERIES_ID,out,false);
+ mitk::PointSet::PointsContainer* pointsContainer =
+ pointSet->GetPointSet(t)->GetPoints();
mitk::PointSet::PointsContainer::Iterator it;
- for ( it = pointsContainer->Begin(); it != pointsContainer->End(); ++it )
- {
+ for (it = pointsContainer->Begin(); it != pointsContainer->End(); ++it) {
WriteStartElement( XML_POINT, out );
WriteStartElement( XML_ID, out );
@@ -153,170 +148,115 @@
WriteEndElement( XML_POINT, out );
}
+ WriteEndElement(XML_TIME_SERIES, out);
+ }
WriteEndElement( XML_POINT_SET, out );
}
-
-
-
-
-void mitk::PointSetWriter::ResizeInputs( const unsigned int& num )
-{
+void mitk::PointSetWriter::ResizeInputs(const unsigned int& num) {
unsigned int prevNum = this->GetNumberOfInputs();
this->SetNumberOfInputs( num );
- for ( unsigned int i = prevNum; i < num; ++i )
- {
+ for (unsigned int i = prevNum; i < num; ++i) {
this->SetNthInput( i, mitk::PointSet::New().GetPointer() );
}
}
-
-
-
-void mitk::PointSetWriter::SetInput( InputType* pointSet )
-{
+void mitk::PointSetWriter::SetInput(InputType* pointSet) {
this->ProcessObject::SetNthInput( 0, pointSet );
}
-
-
-
-void mitk::PointSetWriter::SetInput( const unsigned int& id, InputType* pointSet )
-{
+void mitk::PointSetWriter::SetInput(const unsigned int& id, InputType* pointSet) {
if ( id >= this->GetNumberOfInputs() )
this->ResizeInputs( id + 1 );
this->ProcessObject::SetNthInput( id, pointSet );
}
-
-
-mitk::PointSet* mitk::PointSetWriter::GetInput()
-{
- if ( this->GetNumberOfInputs() < 1 )
- {
+mitk::PointSet* mitk::PointSetWriter::GetInput() {
+ if (this->GetNumberOfInputs() < 1) {
return 0;
- }
- else
- {
+ } else {
return dynamic_cast<InputType*> ( this->GetInput( 0 ) );
}
}
-
-
-
-mitk::PointSet* mitk::PointSetWriter::GetInput( const unsigned int& num )
-{
+mitk::PointSet* mitk::PointSetWriter::GetInput(const unsigned int& num) {
return dynamic_cast<InputType*> ( this->ProcessObject::GetInput( num ) );
}
-
-
-
-
template < typename T>
-std::string mitk::PointSetWriter::ConvertToString( T value )
-{
+std::string mitk::PointSetWriter::ConvertToString(T value) {
std::ostringstream o;
+ std::locale I("C");
+ o.imbue(I);
+
if ( o << value )
+ {
return o.str();
+ }
else
return "conversion error";
}
-
void mitk::PointSetWriter::WriteXMLHeader( std::ofstream &file )
{
file << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
}
-
-
-
-void mitk::PointSetWriter::WriteStartElement( const char *const tag, std::ofstream &file )
-{
+void mitk::PointSetWriter::WriteStartElement(const char *const tag,
+ std::ofstream &file) {
file << std::endl;
WriteIndent( file );
file << '<' << tag << '>';
m_IndentDepth++;
}
-
-
-
-void mitk::PointSetWriter::WriteEndElement( const char *const tag, std::ofstream &file, const bool& indent )
-{
+void mitk::PointSetWriter::WriteEndElement(const char *const tag,
+ std::ofstream &file, const bool& indent) {
m_IndentDepth--;
- if ( indent )
- {
+ if (indent) {
file << std::endl;
WriteIndent( file );
}
file << '<' << '/' << tag << '>';
}
-
-
-
-void mitk::PointSetWriter::WriteCharacterData( const char *const data, std::ofstream &file )
-{
+void mitk::PointSetWriter::WriteCharacterData(const char *const data,
+ std::ofstream &file) {
file << data;
}
-
-
-
-void mitk::PointSetWriter::WriteStartElement( std::string &tag, std::ofstream &file )
-{
+void mitk::PointSetWriter::WriteStartElement(std::string &tag,
+ std::ofstream &file) {
WriteStartElement( tag.c_str(), file );
}
-
-
-
-void mitk::PointSetWriter::WriteEndElement( std::string &tag, std::ofstream &file, const bool& indent )
-{
+void mitk::PointSetWriter::WriteEndElement(std::string &tag,
+ std::ofstream &file, const bool& indent) {
WriteEndElement( tag.c_str(), file, indent );
}
-
-
-
-void mitk::PointSetWriter::WriteCharacterData( std::string &data, std::ofstream &file )
-{
+void mitk::PointSetWriter::WriteCharacterData(std::string &data,
+ std::ofstream &file) {
WriteCharacterData( data.c_str(), file );
}
-
-
-
-void mitk::PointSetWriter::WriteIndent( std::ofstream& file )
-{
+void mitk::PointSetWriter::WriteIndent(std::ofstream& file) {
std::string spaces( m_IndentDepth * m_Indent, ' ' );
file << spaces.c_str();
}
-
-
-bool mitk::PointSetWriter::GetSuccess() const
-{
+bool mitk::PointSetWriter::GetSuccess() const {
return m_Success;
}
-
-
-bool mitk::PointSetWriter::CanWriteDataType( DataTreeNode* input )
-{
- if ( input )
- {
+bool mitk::PointSetWriter::CanWriteDataType(DataTreeNode* input) {
+ if (input) {
mitk::BaseData* data = input->GetData();
- if ( data )
- {
+ if (data) {
mitk::PointSet::Pointer pointSet = dynamic_cast<mitk::PointSet*>( data );
- if( pointSet.IsNotNull() )
- {
+ if (pointSet.IsNotNull()) {
//this writer has no "SetDefaultExtension()" - function
m_Extension = ".mps";
return true;
@@ -326,25 +266,22 @@
return false;
}
-void mitk::PointSetWriter::SetInput( DataTreeNode* input )
-{
+void mitk::PointSetWriter::SetInput(DataTreeNode* input) {
if( input && CanWriteDataType( input ) )
- this->ProcessObject::SetNthInput( 0, dynamic_cast<mitk::PointSet*>( input->GetData() ) );
+ this->ProcessObject::SetNthInput(0,
+ dynamic_cast<mitk::PointSet*> (input->GetData()));
}
-std::string mitk::PointSetWriter::GetWritenMIMEType()
-{
+std::string mitk::PointSetWriter::GetWritenMIMEType() {
return m_MimeType;
}
-std::vector<std::string> mitk::PointSetWriter::GetPossibleFileExtensions()
-{
+std::vector<std::string> mitk::PointSetWriter::GetPossibleFileExtensions() {
std::vector<std::string> possibleFileExtensions;
possibleFileExtensions.push_back(".mps");
return possibleFileExtensions;
}
-std::string mitk::PointSetWriter::GetFileExtension()
-{
+std::string mitk::PointSetWriter::GetFileExtension() {
return m_Extension;
}
Index: mitk/Core/Code/IO/mitkPointSetWriter.h
===================================================================
--- mitk/Core/Code/IO/mitkPointSetWriter.h (revision 21444)
+++ mitk/Core/Code/IO/mitkPointSetWriter.h (working copy)
@@ -27,10 +27,10 @@
{
/**
- * @brief XML-based writer for mitk::PointSets
+ * @brief 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.
+ * 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.
* @ingroup Process
@@ -101,11 +101,11 @@
/**
* @param num the index of the desired output object.
- * @returns the n'th input object of the filter.
+ * @returns the n'th input object of the filter.
*/
PointSet* GetInput( const unsigned int& num );
-
+
/**
* @brief Return the possible file extensions for the data type associated with the writer
*/
@@ -117,7 +117,7 @@
virtual std::string GetFileExtension();
/**
- * @brief Check if the Writer can write the Content of the
+ * @brief Check if the Writer can write the Content of the
*/
virtual bool CanWriteDataType( DataTreeNode* );
@@ -135,7 +135,7 @@
* @returns whether the last write attempt was successful or not.
*/
bool GetSuccess() const;
-
+
protected:
/**
@@ -162,7 +162,7 @@
*/
virtual void ResizeInputs( const unsigned int& num );
-
+
/**
* Converts an arbitrary type to a string. The type has to
* support the << operator. This works fine at least for integral
@@ -172,9 +172,9 @@
*/
template < typename T>
std::string ConvertToString( T value );
-
+
/**
- * Writes an XML representation of the given point set to
+ * Writes an XML representation of the given point set to
* an outstream. The XML-Header an root node is not included!
* @param pointSet the point set to be converted to xml
* @param out the stream to write to.
@@ -186,7 +186,7 @@
* @param file the stream in which the header is written.
*/
void WriteXMLHeader( std::ofstream &file );
-
+
/** Write a start element tag */
void WriteStartElement( const char *const tag, std::ofstream &file );
@@ -224,29 +224,33 @@
unsigned int m_IndentDepth;
unsigned int m_Indent;
-
+
bool m_Success;
-
-
-
+
+
+
public:
static const char* XML_POINT_SET;
-
+
static const char* XML_POINT_SET_FILE;
-
+
static const char* XML_FILE_VERSION;
-
+
+ static const char* XML_TIME_SERIES;
+
+ static const char* XML_TIME_SERIES_ID;
+
static const char* XML_POINT;
-
+
static const char* XML_ID;
-
+
static const char* XML_X;
-
+
static const char* XML_Y;
-
+
static const char* XML_Z;
-
+
static const char* VERSION_STRING;
};
Index: mitk/Core/Code/IO/vtkPointSetXMLParser.cpp
===================================================================
--- mitk/Core/Code/IO/vtkPointSetXMLParser.cpp (revision 21444)
+++ mitk/Core/Code/IO/vtkPointSetXMLParser.cpp (working copy)
@@ -22,146 +22,144 @@
#include "mitkInteractionConst.h"
#include "mitkPointOperation.h"
-namespace mitk
+namespace mitk
{
-vtkStandardNewMacro(vtkPointSetXMLParser);
+ vtkStandardNewMacro(vtkPointSetXMLParser);
}
-mitk::vtkPointSetXMLParser::vtkPointSetXMLParser()
+mitk::vtkPointSetXMLParser::vtkPointSetXMLParser()
{
+ m_TimeIndex = -1;
}
mitk::vtkPointSetXMLParser::~vtkPointSetXMLParser()
{
}
-
-void mitk::vtkPointSetXMLParser::StartElement ( const char *name, const char ** /*atts */)
+void mitk::vtkPointSetXMLParser::StartElement(const char *name, const char ** /*atts */)
{
- std::string currentElement = name;
- //
- // when a new point set begins in the file, create a new
- // mitk::point set and store it in m_PointSetList
- //
- if ( currentElement == mitk::PointSetWriter::XML_POINT_SET )
- {
- m_CurrentPointSet = PointSetType::New();
- }
- //
- // when a new point begins, initialize it to zero.
- //
- else if ( currentElement == mitk::PointSetWriter::XML_POINT )
- {
- m_CurrentPoint[ 0 ] = 0.0f;
- m_CurrentPoint[ 1 ] = 0.0f;
- m_CurrentPoint[ 2 ] = 0.0f;
- m_CurId.clear();
- m_CurXString.clear();
- m_CurYString.clear();
- m_CurZString.clear();
- }
+ std::string currentElement = name;
+ //
+ // when a new point set begins in the file, create a new
+ // mitk::point set and store it in m_PointSetList
+ //
+ if (currentElement == mitk::PointSetWriter::XML_POINT_SET)
+ {
+ m_CurrentPointSet = PointSetType::New();
+ //when a new Pointset begins, the timeseriessize has to be increased
+ //when a new Timeseries begins in the file, create a new serie and store it in
+ }
+ else if (currentElement == mitk::PointSetWriter::XML_TIME_SERIES)
+ {
+ m_TimeIndex++;
+ m_CurrentPointSet->Expand(m_TimeIndex+1);
+ }
+ //
+ // when a new point begins, initialize it to zero.
+ //
+ else if (currentElement == mitk::PointSetWriter::XML_POINT)
+ {
+ m_CurrentPoint.Fill(0.0f);
+ }
- //
- // the current element is pushed on to the stack
- // to be able to detect some errors in the xml file
- //
- m_ParseStack.push( currentElement );
+ //
+ // the current element is pushed on to the stack
+ // to be able to detect some errors in the xml file
+ //
+ m_ParseStack.push( currentElement );
}
-
-
-
-void mitk::vtkPointSetXMLParser::EndElement ( const char *name )
+void mitk::vtkPointSetXMLParser::EndElement(const char *name)
{
- std::string currentElement = name;
-
- //
- // make sure, that the current end element matches with the
- // last start tag
- //
- if ( m_ParseStack.top() != currentElement )
- {
- MITK_ERROR << "Top of parse stack ( " << m_ParseStack.top() << " ) is != currentEndElement ( " << currentElement << " )!" << std::endl;
- }
- m_ParseStack.pop();
+ std::string currentElement = name;
+ //
+ // make sure, that the current end element matches with the
+ // last start tag
+ //
+ if ( m_ParseStack.top() != currentElement )
+ {
+ MITK_ERROR << "Top of parse stack ( " << m_ParseStack.top() << " ) is != currentEndElement ( " << currentElement << " )!" << std::endl;
+ }
+ m_ParseStack.pop();
+ //
+ // After a complete point set has been parsed, its
+ // output information is updated and it is inserted into the list
+ // of parsed currentElementpoint sets.
+ //
+ if (currentElement == mitk::PointSetWriter::XML_POINT_SET)
+ {
+ m_CurrentPointSet->UpdateOutputInformation();
+ m_PointSetList.push_back( m_CurrentPointSet );
+ }
+ else if (currentElement == mitk::PointSetWriter::XML_TIME_SERIES)
+ {
+ }
+ else if (currentElement == mitk::PointSetWriter::XML_POINT)
+ {
//
- // After a complete point set has been parsed, its
- // output information is updated and it is inserted into the list
- // of parsed point sets.
- //
- if (currentElement == mitk::PointSetWriter::XML_POINT_SET)
- {
- m_CurrentPointSet->UpdateOutputInformation();
- m_PointSetList.push_back( m_CurrentPointSet );
- }
- //
// if we have finished parsing a point, insert it to the current
// point set.
//
- else if ( currentElement == mitk::PointSetWriter::XML_POINT )
- {
- m_CurrentPointId = ParsePointIdentifier( m_CurId );
- m_CurrentPoint[ 0 ] = ParseScalarType( m_CurXString );
- m_CurrentPoint[ 1 ] = ParseScalarType( m_CurYString );
- m_CurrentPoint[ 2 ] = ParseScalarType( m_CurZString );
-
- mitk::PointOperation popInsert( mitk::OpINSERT, m_CurrentPoint, m_CurrentPointId );
- mitk::PointOperation popDeactivate( mitk::OpDESELECTPOINT, m_CurrentPoint, m_CurrentPointId );
- assert( m_CurrentPointSet.IsNotNull() );
- m_CurrentPointSet->ExecuteOperation( &popInsert );
- m_CurrentPointSet->ExecuteOperation( &popDeactivate );
- }
+ mitk::PointOperation popInsert(mitk::OpINSERT, m_TimeIndex, m_CurrentPoint,
+ m_CurrentPointId);
+ mitk::PointOperation popDeactivate(mitk::OpDESELECTPOINT, m_TimeIndex,
+ m_CurrentPoint, m_CurrentPointId);
+ assert( m_CurrentPointSet.IsNotNull() );
+ m_CurrentPointSet->ExecuteOperation( &popInsert );
+ m_CurrentPointSet->ExecuteOperation( &popDeactivate );
+ }
}
+void mitk::vtkPointSetXMLParser::CharacterDataHandler(const char *inData,
+ int inLength)
+{
+ std::string currentElement = m_ParseStack.top();
+ std::string data;
+ data.append(inData, inLength);
+ if (currentElement == mitk::PointSetWriter::XML_ID)
+ {
+ m_CurrentPointId = ParsePointIdentifier(data);
+ }
+ else if (currentElement == mitk::PointSetWriter::XML_X)
+ {
+ m_CurrentPoint[0] = ParseScalarType(data);
+ }
+ else if (currentElement == mitk::PointSetWriter::XML_Y)
+ {
+ m_CurrentPoint[1] = ParseScalarType(data);
+ }
+ else if (currentElement == mitk::PointSetWriter::XML_Z)
+ {
+ m_CurrentPoint[2] = ParseScalarType(data);
+ }
+ else if (currentElement == mitk::PointSetWriter::XML_TIME_SERIES_ID)
+ {
+ }
+}
-
-void mitk::vtkPointSetXMLParser::CharacterDataHandler ( const char *inData, int inLength )
+mitk::ScalarType mitk::vtkPointSetXMLParser::ParseScalarType(
+ const std::string &data)
{
- std::string currentElement = m_ParseStack.top();
- if ( currentElement == mitk::PointSetWriter::XML_ID )
- {
- m_CurId.append( inData, inLength );
- }
- else if ( currentElement == mitk::PointSetWriter::XML_X )
- {
- m_CurXString.append(inData, inLength);
- }
- else if ( currentElement == mitk::PointSetWriter::XML_Y )
- {
- m_CurYString.append(inData, inLength);
- }
- else if ( currentElement == mitk::PointSetWriter::XML_Z )
- {
- m_CurZString.append(inData, inLength);
- }
+ return ( mitk::ScalarType ) atof( data.c_str() );
}
-
-
-
-mitk::ScalarType mitk::vtkPointSetXMLParser::ParseScalarType( const std::string &data )
+mitk::ScalarType mitk::vtkPointSetXMLParser::ParseSize(const std::string &data)
{
- return ( mitk::ScalarType ) atof( data.c_str() );
+ return (mitk::ScalarType) atoi(data.c_str());
}
-
-
-
-mitk::vtkPointSetXMLParser::PointIdentifier mitk::vtkPointSetXMLParser::ParsePointIdentifier( const std::string &data )
+mitk::vtkPointSetXMLParser::PointIdentifier mitk::vtkPointSetXMLParser::ParsePointIdentifier(
+ const std::string &data)
{
- return ( mitk::vtkPointSetXMLParser::PointIdentifier ) atol( data.c_str() );
+ return ( mitk::vtkPointSetXMLParser::PointIdentifier ) atol( data.c_str() );
}
-
-
-
-mitk::vtkPointSetXMLParser::PointSetList mitk::vtkPointSetXMLParser::GetParsedPointSets()
+mitk::vtkPointSetXMLParser::PointSetList mitk::vtkPointSetXMLParser::GetParsedPointSets()
{
- return m_PointSetList;
+ return m_PointSetList;
}
-
Index: mitk/Core/Code/IO/vtkPointSetXMLParser.h
===================================================================
--- mitk/Core/Code/IO/vtkPointSetXMLParser.h (revision 21444)
+++ mitk/Core/Code/IO/vtkPointSetXMLParser.h (working copy)
@@ -39,94 +39,96 @@
class MITK_CORE_EXPORT vtkPointSetXMLParser : public vtkXMLParser
{
public:
- vtkTypeMacro(vtkPointSetXMLParser,vtkXMLParser);
+ vtkTypeMacro(vtkPointSetXMLParser,vtkXMLParser);
- static vtkPointSetXMLParser* New();
+ static vtkPointSetXMLParser* New();
- typedef mitk::PointSet PointSetType;
+ typedef mitk::PointSet PointSetType;
- typedef std::stack< std::string > ParseStack;
-
- typedef std::list< PointSetType::Pointer > PointSetList;
-
- typedef PointSetType::DataType::PointIdentifier PointIdentifier;
-
- typedef PointSetType::PointType PointType;
+ typedef std::stack< std::string > ParseStack;
+
+ typedef std::list< PointSetType::Pointer > PointSetList;
+
+ typedef PointSetType::DataType::PointIdentifier PointIdentifier;
+
+ typedef PointSetType::PointType PointType;
- /**
- * Handler function which is called, when a new xml start-tag
- * has been parsed.
- */
- virtual void StartElement (const char *name, const char **atts);
+ /**
+ * Handler function which is called, when a new xml start-tag
+ * has been parsed.
+ */
+ virtual void StartElement (const char *name, const char **atts);
+
+ /**
+ * Handler function which is called, when a xml end-tag
+ * has been parsed.
+ */
+ virtual void EndElement (const char *name);
+
+ /**
+ * Handler function which is called, if characted data has been
+ * parsed by expat.
+ * @param inData a char array containing the parsed string data
+ * @param inLength the length of the parsed data string.
+ */
+ virtual void CharacterDataHandler (const char *inData, int inLength);
+
+ /**
+ * Converts the given data to mitk::ScalarType.
+ */
+ virtual mitk::ScalarType ParseScalarType(const std::string &data);
+
+ virtual mitk::ScalarType ParseSize (const std::string &data);
+
+ /**
+ * Converts the given data to an PointIdentifier
+ */
+ virtual PointIdentifier ParsePointIdentifier(const std::string &data);
+
+ /**
+ * @returns the list of point sets which have been read from file.
+ * NOTE: your have to call the Parse() function, before this function.
+ */
+ virtual PointSetList GetParsedPointSets();
- /**
- * Handler function which is called, when a xml end-tag
- * has been parsed.
- */
- virtual void EndElement (const char *name);
-
- /**
- * Handler function which is called, if characted data has been
- * parsed by expat.
- * @param inData a char array containing the parsed string data
- * @param inLength the length of the parsed data string.
- */
- virtual void CharacterDataHandler (const char *inData, int inLength);
-
- /**
- * Converts the given data to mitk::ScalarType.
- */
- virtual mitk::ScalarType ParseScalarType(const std::string &data);
-
- /**
- * Converts the given data to an PointIdentifier
- */
- virtual PointIdentifier ParsePointIdentifier(const std::string &data);
-
- /**
- * @returns the list of point sets which have been read from file.
- * NOTE: your have to call the Parse() function, before this function.
- */
- virtual PointSetList GetParsedPointSets();
-
protected:
- vtkPointSetXMLParser();
- virtual ~vtkPointSetXMLParser();
-
- /**
- * A stack containing the parsed start-tags.
- * If an end tag is encountered, it is matched with the
- * top element of the stack.
- */
- ParseStack m_ParseStack;
-
- /**
- * Contains the parsed point sets.
- */
- PointSetList m_PointSetList;
-
- /**
- * The current point set which is processed
- * by the parser.
- */
- PointSetType::Pointer m_CurrentPointSet;
-
- /**
- * The current point which is processed
- * by the parser.
- */
- PointType m_CurrentPoint;
+ vtkPointSetXMLParser();
+ virtual ~vtkPointSetXMLParser();
+
+ /**
+ * A stack containing the parsed start-tags.
+ * If an end tag is encountered, it is matched with the
+ * top element of the stack.
+ */
+ ParseStack m_ParseStack;
+
+ /**
+ * Contains the parsed point sets.
+ */
+ PointSetList m_PointSetList;
+
+ /**
+ * The current point set which is processed
+ * by the parser.
+ */
+ PointSetType::Pointer m_CurrentPointSet;
+
+ /**
+ * The current point which is processed
+ * by the parser.
+ */
+ PointType m_CurrentPoint;
- std::string m_CurId;
- std::string m_CurXString;
- std::string m_CurYString;
- std::string m_CurZString;
-
- /**
- * The current point id which is processed
- * by the parser.
- */
- PointIdentifier m_CurrentPointId;
+ /**
+ * Time-Index
+ */
+ int m_TimeIndex;
+
+ /**
+ * The current point id which is processed
+ * by the parser.
+ */
+ PointIdentifier m_CurrentPointId;
};
}
Index: mitk/Core/Code/Testing/mitkPointSetFileIOTest.cpp
===================================================================
--- mitk/Core/Code/Testing/mitkPointSetFileIOTest.cpp (revision 21444)
+++ mitk/Core/Code/Testing/mitkPointSetFileIOTest.cpp (working copy)
@@ -1,147 +1,245 @@
/*=========================================================================
-
-Program: Medical Imaging & Interaction Toolkit
-Language: C++
-Date: $Date$
-Version: $Revision$
-
-Copyright (c) German Cancer Research Center, Division of Medical and
-Biological Informatics. All rights reserved.
-See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
-
-This software is distributed WITHOUT ANY WARRANTY; without even
-the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-PURPOSE. See the above copyright notices for more information.
-
-=========================================================================*/
+ Program: Medical Imaging & Interaction Toolkit
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) German Cancer Research Center, Division of Medical and
+ Biological Informatics. All rights reserved.
+ See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+ =========================================================================*/
+
#include "mitkPointSet.h"
#include "mitkPointSetWriter.h"
#include "mitkPointSetReader.h"
#include <itksys/SystemTools.hxx>
-unsigned int numberOfTestPointSets = 1;
+unsigned int numberOfTestPointSets = 2;
// create one test PointSet
-mitk::PointSet::Pointer CreateTestPointSet(unsigned int which)
-{
+mitk::PointSet::Pointer CreateTestPointSet(unsigned int which) {
mitk::PointSet::Pointer pointSet = mitk::PointSet::New();
- switch (which)
- {
- case 0:
- {
- unsigned int position(0);
- mitk::Point3D point;
- mitk::FillVector3D(point, 1.0, 2.0, 3.0); pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
- mitk::FillVector3D(point, 2.0, 3.0, 4.0); ++position; pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
- mitk::FillVector3D(point, 3.0, 4.0, 5.0); ++position; pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
- }
+ switch (which) {
+ //3DPointSet
+ case 0: {
+// unsigned int position(0);
+// mitk::Point3D point;
+// mitk::FillVector3D(point, 1.0, 2.0, 3.0);
+// pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
+// mitk::FillVector3D(point, 2.0, 3.0, 4.0);
+// ++position;
+// pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
+// mitk::FillVector3D(point, 3.0, 4.0, 5.0);
+// ++position;
+// pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
+ unsigned int numberOfPoints = 1000;
+ for (unsigned int i = 0; i <= numberOfPoints; ++i) {
+ mitk::Point3D point;
+ point[0] = 940;
+ point[1] = 762;//(mitk::ScalarType) (rand() % 1000);
+ point[2] = 41;//(mitk::ScalarType) (rand() % 1000);
+ std::cout << "Point:" << point << std::endl;
+ pointSet->SetPoint(i, point);
+ }
+ }
break;
+ //4DPointSet
+ case 1: {
+ // unsigned int position(0);
+ // unsigned int timeStep(0);
+ // mitk::Point3D point;
+ //
+ // //timestep 1
+ // mitk::FillVector3D(point, 100.0, 200.0, 300.0);
+ // pointSet->SetPoint(position, point, 0);
+ // mitk::FillVector3D(point, 200.0, 300.0, 400.0);
+ // ++position;
+ // pointSet->SetPoint(position, point, 0);
+ // mitk::FillVector3D(point, 300.0, 400.0, 500.0);
+ // ++position;
+ // pointSet->SetPoint(position, point, 0);
+ //
+ // //timestep 2
+ // unsigned int position1(0);
+ // mitk::Point3D point1;
+ // mitk::FillVector3D(point1, 400.0, 500.0, 600.0);
+ // pointSet->SetPoint(position1, point1, 1);
+ // mitk::FillVector3D(point1, 500.0, 600.0, 700.0);
+ // ++position1;
+ // pointSet->SetPoint(position1, point1, 1);
+ // mitk::FillVector3D(point1, 600.0, 700.0, 800.0);
+ // ++position1;
+ // pointSet->SetPoint(position1, point1, 1);
+ //
+ // //timestep 3
+ // unsigned int position2(0);
+ // mitk::Point3D point2;
+ // mitk::FillVector3D(point2, 700.0, 800.0, 900.0);
+ // pointSet->SetPoint(position2, point2, 2);
+ // mitk::FillVector3D(point2, 800.0, 900.0, 1000.0);
+ // ++position2;
+ // pointSet->SetPoint(position2, point2, 2);
+ // mitk::FillVector3D(point2, 900.0, 1000.0, 1100.0);
+ // ++position2;
+ // pointSet->SetPoint(position2, point2, 2);
+ //
+ // //timestep 4
+ // unsigned int position3(0);
+ // mitk::Point3D point3;
+ // mitk::FillVector3D(point3, 71.0, 82.0, 93.0);
+ // pointSet->SetPoint(position3, point3, 3);
+ // mitk::FillVector3D(point3, 84.0, 95.0, 106.0);
+ // ++position3;
+ // pointSet->SetPoint(position3, point3, 3);
+ // mitk::FillVector3D(point3, 97.0, 18.0, 119.0);
+ // ++position3;
+ // pointSet->SetPoint(position3, point3, 3);
+ //
+ // //timestep 5
+ // unsigned int position4(0);
+ // mitk::Point3D point4;
+ // mitk::FillVector3D(point4, 77.0, 88.0, 99.0);
+ // pointSet->SetPoint(position2, point4, 4);
+ // mitk::FillVector3D(point4, 88.0, 99.0, 1010.0);
+ // ++position4;
+ // pointSet->SetPoint(position2, point4, 4);
+ // mitk::FillVector3D(point4, 99.0, 1010.0, 1111.0);
+ // ++position4;
+ // pointSet->SetPoint(position2, point4, 4);
- default:
- {
- unsigned int position(0);
- mitk::Point3D point;
- mitk::FillVector3D(point, 1.0, 2.0, 3.0); pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
- mitk::FillVector3D(point, 2.0, 3.0, 4.0); ++position; pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
- mitk::FillVector3D(point, 3.0, 4.0, 5.0); ++position; pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
+ unsigned int numberOfPoints = 5;
+ unsigned int numberOfTimeSteps = 34;
+ for (unsigned int timeStep = 0; timeStep <= numberOfTimeSteps; ++timeStep) {
+ std::cout << "timestep writer : " << timeStep << "\n" << std::endl;
+ for (unsigned int i = 0; i <= numberOfPoints; ++i) {
+ mitk::Point3D point;
+ point[0] = (mitk::ScalarType) (rand() % 1000);
+ point[1] = (mitk::ScalarType) (rand() % 1000);
+ point[2] = (mitk::ScalarType) (rand() % 1000);
+ std::cout << "Point:" << point << std::endl;
+ pointSet->SetPoint(i, point, timeStep);
+ }
}
}
+ break;
+ //3DPointSet
+ default: {
+ unsigned int position(0);
+ mitk::Point3D point;
+ mitk::FillVector3D(point, 1.0, 2.0, 3.0);
+ pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
+ mitk::FillVector3D(point, 2.0, 3.0, 4.0);
+ ++position;
+ pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
+ mitk::FillVector3D(point, 3.0, 4.0, 5.0);
+ ++position;
+ pointSet->GetPointSet()->GetPoints()->InsertElement(position, point);
+ }
+ }
return pointSet;
}
-void PointSetCompare( mitk::PointSet* pointSet2, mitk::PointSet* pointSet1, bool& identical )
-{
- if (pointSet1->GetSize() != pointSet2->GetSize())
- {
- std::cerr << "point sets differ in size" << std::endl;
+void PointSetCompare(mitk::PointSet* pointSet2, mitk::PointSet* pointSet1,
+ bool& identical) {
+ if (pointSet1->GetSize() != pointSet2->GetSize() || pointSet1->GetTimeSteps()
+ != pointSet2->GetTimeSteps()) {
+ std::cout << "Poinset1grösse: " << pointSet1->GetSize()
+ << " Seriessize: " << pointSet1->GetTimeSteps() << std::endl;
+ std::cout << "Poinset2grösse: " << pointSet2->GetSize()
+ << " Seriessize: " << pointSet2->GetTimeSteps() << std::endl;
+ std::cerr << "point sets differ in size or timeseries" << std::endl;
identical = false;
return;
}
+ for (unsigned int timeStep = 0; timeStep
+ < (unsigned int) pointSet1->GetTimeSteps(); ++timeStep) {
+ for (unsigned int i = 0; i < (unsigned int) pointSet1->GetSize(); ++i) {
+ mitk::Point3D p1 = pointSet1->GetPoint(i, timeStep);
+ mitk::Point3D p2 = pointSet2->GetPoint(i, timeStep);
- for (unsigned int i = 0; i < (unsigned int)pointSet1->GetSize(); ++i)
- {
- mitk::Point3D p1 = pointSet1->GetPoint(i);
- mitk::Point3D p2 = pointSet2->GetPoint(i);
+ double difference = (abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) + abs(p1[2]
+ - p2[2]));
- double difference = ( (p1[0] - p2[0])
- + (p1[1] - p2[1])
- + (p1[2] - p2[2])
- );
-
- if (difference > 0.0001)
- {
- std::cerr << "points not at the same position" << std::endl;
- identical = false;
- break;
+ if (difference > 0.0001) {
+ std::cerr << "points not at the same position" << std::endl;
+ std::cout << "TimeStep error:" << timeStep << std::endl;
+ std::cout << "Punkt1 error:" << p1 << std::endl;
+ std::cout << "Punkt2 error:" << p2 << std::endl;
+ identical = false;
+ break;
+ }
}
}
}
-int mitkPointSetFileIOTest(int, char*[])
-{
+int mitkPointSetFileIOTest(int, char*[]) {
unsigned int numberFailed(0);
- for (unsigned int i = 0; i < numberOfTestPointSets; ++i)
- {
+ for (unsigned int i = 1; i < numberOfTestPointSets; ++i) {
mitk::PointSet::Pointer originalPointSet = CreateTestPointSet(i);
mitk::PointSet::Pointer secondPointSet;
// write
- try
- {
- mitk::PointSetWriter::Pointer pointSetWriter = mitk::PointSetWriter::New();
- pointSetWriter->SetInput(originalPointSet);
- pointSetWriter->SetFileName("test_pointset.mps");
- pointSetWriter->Write();
- }
- catch ( std::exception& e )
- {
- std::cerr << "Error during attempt to write 'test_pointset.mps' Exception says:" << std::endl;
- std::cerr << e.what() << std::endl;
- ++numberFailed;
- continue;
- }
+ try {
+ mitk::PointSetWriter::Pointer pointSetWriter =
+ mitk::PointSetWriter::New();
+ pointSetWriter->SetInput(originalPointSet);
+ pointSetWriter->SetFileName("c:/temp/test_pointset.mps");
+ pointSetWriter->Write();
+ } catch (std::exception& e) {
+ std::cerr
+ << "Error during attempt to write 'test_pointset.mps' Exception says:"
+ << std::endl;
+ std::cerr << e.what() << std::endl;
+ ++numberFailed;
+ continue;
+ }
// load
- try
- {
- mitk::PointSetReader::Pointer pointSetReader = mitk::PointSetReader::New();
-
- pointSetReader->SetFileName("test_pointset.mps");
- pointSetReader->Update();
+ try {
+ mitk::PointSetReader::Pointer pointSetReader =
+ mitk::PointSetReader::New();
- secondPointSet = pointSetReader->GetOutput();
- }
- catch ( std::exception& e )
- {
- std::cerr << "Error during attempt to read 'test_pointset.mps' Exception says:" << std::endl;
- std::cerr << e.what() << std::endl;
- ++numberFailed;
- continue;
- }
+ pointSetReader->SetFileName("c:/temp/test_pointset.mps");
+ pointSetReader->Update();
- if (secondPointSet.IsNull())
- {
- std::cerr << "Error reading 'test_pointset.mps'. No PointSet created." << std::endl;
- ++numberFailed;
- continue;
- }
-
- std::remove( "test_pointset.mps" );
-
+ secondPointSet = pointSetReader->GetOutput();
+ } catch (std::exception& e) {
+ std::cerr
+ << "Error during attempt to read 'test_pointset.mps' Exception says:"
+ << std::endl;
+ std::cerr << e.what() << std::endl;
+ ++numberFailed;
+ continue;
+ }
+
+ if (secondPointSet.IsNull()) {
+ std::cerr << "Error reading 'test_pointset.mps'. No PointSet created."
+ << std::endl;
+ ++numberFailed;
+ continue;
+ }
+
+ //std::remove("test_pointset.mps");
+
// compare
bool identical(true);
- PointSetCompare( secondPointSet.GetPointer(), originalPointSet.GetPointer(), identical );
+ PointSetCompare(secondPointSet.GetPointer(), originalPointSet.GetPointer(),
+ identical);
- if (!identical)
- {
+ if (!identical) {
std::cerr << "PointSets differ for testPointSet " << i << std::endl;
++numberFailed;
continue;
@@ -149,13 +247,11 @@
}
// if one fails, whole test fails
- if (numberFailed > 0)
- {
- std::cout << "[FAILED]: " << numberFailed << " of " << numberOfTestPointSets << " sub-tests failed." << std::endl;
+ if (numberFailed > 0) {
+ std::cout << "[FAILED]: " << numberFailed << " of "
+ << numberOfTestPointSets << " sub-tests failed." << std::endl;
return EXIT_FAILURE;
- }
- else
- {
+ } else {
std::cout << "[PASSED]" << std::endl;
return EXIT_SUCCESS;
}

File Metadata

Mime Type
application/octet-stream
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
132
Default Alt Text
4DPointSetReaderWriter.patch (43 KB)

Event Timeline

Patch includes the original changes applied to a current checkout of MITK