Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

mitk::vtkPointSetXMLParser Class Reference
[Process Classes]

Implementation of the vtkXMLParser interface for reading mitk::PointSets. More...

#include <vtkPointSetXMLParser.h>

List of all members.

Public Types

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

Public Member Functions

 vtkTypeMacro (vtkPointSetXMLParser, vtkXMLParser)
virtual int InitializeParser ()
virtual int CleanupParser ()
virtual void StartElement (const char *name, const char **atts)
virtual void EndElement (const char *name)
virtual void CharacterDataHandler (const char *inData, int inLength)
virtual mitk::ScalarType ParseScalarType (const std::string &data)
virtual PointIdentifier ParsePointIdentifier (const std::string &data)
virtual PointSetList GetParsedPointSets ()

Static Public Member Functions

static vtkPointSetXMLParserNew ()

Protected Member Functions

 vtkPointSetXMLParser ()
virtual ~vtkPointSetXMLParser ()

Protected Attributes

ParseStack m_ParseStack
PointSetList m_PointSetList
PointSetType::Pointer m_CurrentPointSet
PointType m_CurrentPoint
std::string m_CurId
std::string m_CurXString
std::string m_CurYString
std::string m_CurZString
PointIdentifier m_CurrentPointId
std::locale m_PreviousLocale

Detailed Description

Implementation of the vtkXMLParser interface for reading mitk::PointSets.

This class implements the XMLParser interface of the vtkXMLParser which is based on expat. It is used by the mitk::PointSetReader and is NOT INTENDED TO BE USED FROM THE END-USER. If you want to read point sets, use the mitk::PointSetReader.

Definition at line 39 of file vtkPointSetXMLParser.h.


Member Typedef Documentation

typedef std::stack< std::string > mitk::vtkPointSetXMLParser::ParseStack

Definition at line 48 of file vtkPointSetXMLParser.h.

Definition at line 52 of file vtkPointSetXMLParser.h.

Definition at line 50 of file vtkPointSetXMLParser.h.

Definition at line 46 of file vtkPointSetXMLParser.h.

Definition at line 54 of file vtkPointSetXMLParser.h.


Constructor & Destructor Documentation

mitk::vtkPointSetXMLParser::vtkPointSetXMLParser (  ) [protected]

Definition at line 30 of file vtkPointSetXMLParser.cpp.

{
}
mitk::vtkPointSetXMLParser::~vtkPointSetXMLParser (  ) [protected, virtual]

Definition at line 34 of file vtkPointSetXMLParser.cpp.

{
}

Member Function Documentation

void mitk::vtkPointSetXMLParser::CharacterDataHandler ( const char *  inData,
int  inLength 
) [virtual]

Handler function which is called, if characted data has been parsed by expat.

Parameters:
inDataa char array containing the parsed string data
inLengththe length of the parsed data string.

Definition at line 152 of file vtkPointSetXMLParser.cpp.

References mitk::PointSetWriter::XML_ID, mitk::PointSetWriter::XML_X, mitk::PointSetWriter::XML_Y, and mitk::PointSetWriter::XML_Z.

{
    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);
    }
}
int mitk::vtkPointSetXMLParser::CleanupParser (  ) [virtual]

Definition at line 54 of file vtkPointSetXMLParser.cpp.

{
  std::istream* stream = this -> GetStream();
   if (!stream)
   {
      vtkErrorMacro("no stream available in XML file reader");
        this->ParseError = 1;
        return 0;
   }
   stream->imbue( m_PreviousLocale );
   vtkXMLParser::CleanupParser();
   return 1;
}
void mitk::vtkPointSetXMLParser::EndElement ( const char *  name ) [virtual]

Handler function which is called, when a xml end-tag has been parsed.

Definition at line 105 of file vtkPointSetXMLParser.cpp.

References MITK_ERROR, mitk::OpDESELECTPOINT, mitk::OpINSERT, mitk::PointSetWriter::XML_POINT, and mitk::PointSetWriter::XML_POINT_SET.

{
    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 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::vtkPointSetXMLParser::PointSetList mitk::vtkPointSetXMLParser::GetParsedPointSets (  ) [virtual]
Returns:
the list of point sets which have been read from file. NOTE: your have to call the Parse() function, before this function.

Definition at line 200 of file vtkPointSetXMLParser.cpp.

{
    return m_PointSetList;
}
int mitk::vtkPointSetXMLParser::InitializeParser (  ) [virtual]

Definition at line 38 of file vtkPointSetXMLParser.cpp.

{
   vtkXMLParser::InitializeParser();
   std::istream* stream = this -> GetStream();
   if (!stream)
   {
      vtkErrorMacro("no stream available in XML file reader");
       this->ParseError = 1;
       return 0;
   }
   m_PreviousLocale = stream->getloc();
   std::locale I("C");
   stream->imbue(I);
   return 1;
}
static vtkPointSetXMLParser* mitk::vtkPointSetXMLParser::New (  ) [static]
mitk::vtkPointSetXMLParser::PointIdentifier mitk::vtkPointSetXMLParser::ParsePointIdentifier ( const std::string &  data ) [virtual]

Converts the given data to an PointIdentifier

Definition at line 188 of file vtkPointSetXMLParser.cpp.

{
   std::istringstream stm;
   stm.str(data);
   PointIdentifier pointID;
   stm >>pointID;
    return pointID;
}
mitk::ScalarType mitk::vtkPointSetXMLParser::ParseScalarType ( const std::string &  data ) [virtual]

Converts the given data to mitk::ScalarType.

Definition at line 176 of file vtkPointSetXMLParser.cpp.

{
    std::istringstream stm;
    stm.str(data);
    ScalarType number;
    stm >>number;
     return number;
}
void mitk::vtkPointSetXMLParser::StartElement ( const char *  name,
const char **  atts 
) [virtual]

Handler function which is called, when a new xml start-tag has been parsed.

Definition at line 70 of file vtkPointSetXMLParser.cpp.

References mitk::PointSetWriter::XML_POINT, and mitk::PointSetWriter::XML_POINT_SET.

{
    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();
    }
    
    //
    // the current element is pushed on to the stack
    // to be able to detect some errors in the xml file
    //
    m_ParseStack.push( currentElement );
}
mitk::vtkPointSetXMLParser::vtkTypeMacro ( vtkPointSetXMLParser  ,
vtkXMLParser   
)

Member Data Documentation

std::string mitk::vtkPointSetXMLParser::m_CurId [protected]

Definition at line 122 of file vtkPointSetXMLParser.h.

The current point which is processed by the parser.

Definition at line 120 of file vtkPointSetXMLParser.h.

The current point id which is processed by the parser.

Definition at line 131 of file vtkPointSetXMLParser.h.

The current point set which is processed by the parser.

Definition at line 114 of file vtkPointSetXMLParser.h.

Definition at line 123 of file vtkPointSetXMLParser.h.

Definition at line 124 of file vtkPointSetXMLParser.h.

Definition at line 125 of file vtkPointSetXMLParser.h.

A stack containing the parsed start-tags. If an end tag is encountered, it is matched with the top element of the stack.

Definition at line 103 of file vtkPointSetXMLParser.h.

Contains the parsed point sets.

Definition at line 108 of file vtkPointSetXMLParser.h.

Definition at line 133 of file vtkPointSetXMLParser.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines