reads xml representations of mitk::PointSets from a file More...
#include <mitkPointSetReader.h>
Public Types | |
typedef PointSetReader | Self |
typedef FileReader | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | SetFileName (const char *_arg) |
Sets the filename of the file to be read. | |
virtual const char * | GetFileName () const |
Returns the filename of the point set xml-file. | |
virtual void | SetFilePrefix (const char *_arg) |
virtual const char * | GetFilePrefix () const |
virtual void | SetFilePattern (const char *_arg) |
virtual const char * | GetFilePattern () const |
bool | GetSuccess () const |
Static Public Member Functions | |
static Pointer | New () |
static bool | CanReadFile (const std::string filename, const std::string filePrefix, const std::string filePattern) |
Protected Member Functions | |
PointSetReader () | |
virtual | ~PointSetReader () |
virtual void | GenerateData () |
virtual mitk::PointSet::Pointer | ReadPoint (mitk::PointSet::Pointer newPointSet, TiXmlElement *currentTimeSeries, unsigned int currentTimeStep) |
virtual void | GenerateOutputInformation () |
virtual void | ResizeOutputs (const unsigned int &num) |
virtual int | CanReadFile (const char *name) |
Protected Attributes | |
std::string | m_FileName |
std::string | m_FilePrefix |
std::string | m_FilePattern |
bool | m_Success |
reads xml representations of mitk::PointSets from a file
Reader for xml files containing one or multiple xml represenations of mitk::PointSets. If multiple mitk::PointSets are stored in one file, these are assigned to multiple outputs of the filter. The number of point sets which have be read can be retrieven by a call to GetNumberOfOutputs() after the pipeline update(). The reader is able to read the old 3D Pointsets without the "specification" and "timeseries" tags and the new 4D Pointsets.
Definition at line 45 of file mitkPointSetReader.h.
typedef itk::SmartPointer<const Self> mitk::PointSetReader::ConstPointer |
Definition at line 49 of file mitkPointSetReader.h.
typedef itk::SmartPointer<Self> mitk::PointSetReader::Pointer |
Definition at line 49 of file mitkPointSetReader.h.
Definition at line 49 of file mitkPointSetReader.h.
Definition at line 49 of file mitkPointSetReader.h.
mitk::PointSetReader::PointSetReader | ( | ) | [protected] |
Constructor
Definition at line 24 of file mitkPointSetReader.cpp.
References m_Success.
{ m_Success = false; }
mitk::PointSetReader::~PointSetReader | ( | ) | [protected, virtual] |
bool mitk::PointSetReader::CanReadFile | ( | const std::string | filename, |
const std::string | filePrefix, | ||
const std::string | filePattern | ||
) | [static] |
Definition at line 135 of file mitkPointSetReader.cpp.
{ // First check the extension if( filename == "" ) { //MITK_INFO<<"No filename specified."<<std::endl; return false; } // check if image is serie if( filePattern != "" && filePrefix != "" ) return false; bool extensionFound = false; 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; return false; } return true; }
int mitk::PointSetReader::CanReadFile | ( | const char * | name ) | [protected, virtual] |
Checks if the given file has appropriate read access.
Definition at line 127 of file mitkPointSetReader.cpp.
{ std::ifstream in( name ); bool isGood = in.good(); in.close(); return isGood; }
void mitk::PointSetReader::GenerateData | ( | ) | [protected, virtual] |
Actually reads the point sets from the given file
Definition at line 34 of file mitkPointSetReader.cpp.
References TiXmlNode::FirstChildElement(), TiXmlHandle::FirstChildElement(), TiXmlElement::GetText(), TiXmlDocument::LoadFile(), MITK_ERROR, MITK_WARN, mitk::PointSet::New(), TiXmlNode::NextSiblingElement(), TiXmlElement::ToElement(), and TiXmlHandle::ToElement().
{ std::locale::global(std::locale("C")); 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 ; } try{ TiXmlDocument doc(m_FileName.c_str()); bool loadOkay = doc.LoadFile(); if (loadOkay) { TiXmlHandle docHandle( &doc ); unsigned int pointSetCounter(0); for( TiXmlElement* currentPointSetElement = docHandle.FirstChildElement("point_set_file").FirstChildElement("point_set").ToElement(); currentPointSetElement != NULL; currentPointSetElement = currentPointSetElement->NextSiblingElement()) { mitk::PointSet::Pointer newPointSet = mitk::PointSet::New(); if(currentPointSetElement->FirstChildElement("time_series") != NULL) { for( TiXmlElement* currentTimeSeries = currentPointSetElement->FirstChildElement("time_series")->ToElement(); currentTimeSeries != NULL; currentTimeSeries = currentTimeSeries->NextSiblingElement()) { unsigned int currentTimeStep(0); TiXmlElement* currentTimeSeriesID = currentTimeSeries->FirstChildElement("time_series_id"); currentTimeStep = atoi(currentTimeSeriesID->GetText()); newPointSet = this->ReadPoint(newPointSet, currentTimeSeries, currentTimeStep); } } else { newPointSet = this->ReadPoint(newPointSet, currentPointSetElement, 0); } this->SetNthOutput( pointSetCounter, newPointSet ); pointSetCounter++; } } else { MITK_WARN << "XML parser error!"; } }catch(...) { MITK_ERROR << "Cannot read point set."; m_Success = false; } m_Success = true; }
void mitk::PointSetReader::GenerateOutputInformation | ( | ) | [protected, virtual] |
Does nothing in the current implementation
Definition at line 123 of file mitkPointSetReader.cpp.
{ }
virtual const char* mitk::PointSetReader::GetClassName | ( | ) | const [virtual] |
virtual const char* mitk::PointSetReader::GetFileName | ( | ) | const [virtual] |
Returns the filename of the point set xml-file.
Implements mitk::FileReader.
virtual const char* mitk::PointSetReader::GetFilePattern | ( | ) | const [virtual] |
Implements mitk::FileReader.
virtual const char* mitk::PointSetReader::GetFilePrefix | ( | ) | const [virtual] |
Implements mitk::FileReader.
bool mitk::PointSetReader::GetSuccess | ( | ) | const |
Definition at line 183 of file mitkPointSetReader.cpp.
{ return m_Success; }
static Pointer mitk::PointSetReader::New | ( | ) | [static] |
Reimplemented from mitk::PointSetSource.
Referenced by QmitkPointListWidget::OnBtnLoadPoints(), mitkPointSetFileIOTestClass::PointSetLoadAndCompareTest(), and ReaderLocaleTest().
mitk::PointSet::Pointer mitk::PointSetReader::ReadPoint | ( | mitk::PointSet::Pointer | newPointSet, |
TiXmlElement * | currentTimeSeries, | ||
unsigned int | currentTimeStep | ||
) | [protected, virtual] |
Definition at line 92 of file mitkPointSetReader.cpp.
References TiXmlNode::FirstChildElement(), TiXmlNode::NextSiblingElement(), and TiXmlElement::ToElement().
{ if(currentTimeSeries->FirstChildElement("point") != NULL) { for( TiXmlElement* currentPoint = currentTimeSeries->FirstChildElement("point")->ToElement(); currentPoint != NULL; currentPoint = currentPoint->NextSiblingElement()) { unsigned int id(0); mitk::PointSpecificationType spec((mitk::PointSpecificationType) 0); double x(0.0); double y(0.0); double z(0.0); id = atoi(currentPoint->FirstChildElement("id")->GetText()); if(currentPoint->FirstChildElement("specification") != NULL) { spec = (mitk::PointSpecificationType) atoi(currentPoint->FirstChildElement("specification")->GetText()); } x = atof(currentPoint->FirstChildElement("x")->GetText()); y = atof(currentPoint->FirstChildElement("y")->GetText()); z = atof(currentPoint->FirstChildElement("z")->GetText()); mitk::Point3D point; mitk::FillVector3D(point, x, y, z); newPointSet->SetPoint(id, point, spec, currentTimeStep); } } return newPointSet; }
void mitk::PointSetReader::ResizeOutputs | ( | const unsigned int & | num ) | [protected, virtual] |
Resizes the output-objects according to the given number.
num | the new number of output objects. |
Definition at line 172 of file mitkPointSetReader.cpp.
{ unsigned int prevNum = this->GetNumberOfOutputs(); this->SetNumberOfOutputs( num ); for ( unsigned int i = prevNum; i < num; ++i ) { this->SetNthOutput( i, this->MakeOutput( i ).GetPointer() ); } }
virtual void mitk::PointSetReader::SetFileName | ( | const char * | _arg ) | [virtual] |
Sets the filename of the file to be read.
_arg | the filename of the point set xml-file |
Implements mitk::FileReader.
virtual void mitk::PointSetReader::SetFilePattern | ( | const char * | _arg ) | [virtual] |
Implements mitk::FileReader.
virtual void mitk::PointSetReader::SetFilePrefix | ( | const char * | _arg ) | [virtual] |
Implements mitk::FileReader.
std::string mitk::PointSetReader::m_FileName [protected] |
Definition at line 132 of file mitkPointSetReader.h.
std::string mitk::PointSetReader::m_FilePattern [protected] |
Definition at line 136 of file mitkPointSetReader.h.
std::string mitk::PointSetReader::m_FilePrefix [protected] |
Definition at line 134 of file mitkPointSetReader.h.
bool mitk::PointSetReader::m_Success [protected] |
Definition at line 138 of file mitkPointSetReader.h.
Referenced by PointSetReader().