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

mitk::NavigationDataSequentialPlayer Class Reference

This class is a slightly changed reimplementation of the NavigationDataPlayer which does not care about timestamps and just outputs the navigationdatas in their sequential order. More...

#include <mitkNavigationDataSequentialPlayer.h>

Inheritance diagram for mitk::NavigationDataSequentialPlayer:
Inheritance graph
[legend]
Collaboration diagram for mitk::NavigationDataSequentialPlayer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 mitkClassMacro (NavigationDataSequentialPlayer, NavigationDataSource)
void SetFileName (const std::string &_FileName)
 sets the file name and path (if XMLString is set, this is neglected)
virtual const char * GetFileName () const
 returns the file name and path
void SetXMLString (const std::string &_XMLString)
 sets a xml string (by this, the xml string is not read from file)
virtual const char * GetXMLString () const
 returns the current xml string
virtual void SetRepeat (bool _arg)
virtual bool GetRepeat ()
virtual unsigned int GetNumberOfSnapshots ()
void GoToSnapshot (int i)
virtual void UpdateOutputInformation ()
 Used for pipeline update just to tell the pipeline that we always have to update.

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 NavigationDataSequentialPlayer ()
virtual ~NavigationDataSequentialPlayer ()
void ReinitXML ()
mitk::NavigationData::Pointer ReadVersion1 ()
virtual void GenerateData ()

Protected Attributes

std::string m_FileName
std::string m_XMLString
TiXmlDocumentm_Doc
TiXmlElementm_DataElem
TiXmlElementm_CurrentElem
bool m_Repeat
unsigned int m_NumberOfSnapshots
int m_LastGoTo

Detailed Description

This class is a slightly changed reimplementation of the NavigationDataPlayer which does not care about timestamps and just outputs the navigationdatas in their sequential order.

Documentation

Definition at line 36 of file mitkNavigationDataSequentialPlayer.h.


Constructor & Destructor Documentation

mitk::NavigationDataSequentialPlayer::NavigationDataSequentialPlayer (  ) [protected]
mitk::NavigationDataSequentialPlayer::~NavigationDataSequentialPlayer (  ) [protected, virtual]

Definition at line 38 of file mitkNavigationDataSequentialPlayer.cpp.

{
  delete m_Doc;
}

Member Function Documentation

void mitk::NavigationDataSequentialPlayer::GenerateData (  ) [protected, virtual]

do the work here

Definition at line 146 of file mitkNavigationDataSequentialPlayer.cpp.

References mitk::NavigationData::Graft(), and mitk::NavigationData::SetDataValid().

{
  assert(m_DataElem);

  // very important: go through the tools (there could be more then one)
  mitk::NavigationData::Pointer tmp;
  for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++)
  {
    // go to the first element
    if(!m_CurrentElem)
      m_CurrentElem = m_DataElem->FirstChildElement("ND");
    // go to the next element
    else
      m_CurrentElem = m_CurrentElem->NextSiblingElement();

    // if repeat is on: go back to the first element (prior calls delivered NULL
    // elem)
    if(!m_CurrentElem && m_Repeat)
      m_CurrentElem = m_DataElem->FirstChildElement("ND");

    mitk::NavigationData* output = this->GetOutput(index);
    tmp = this->ReadVersion1();
    if(tmp.IsNotNull())
      output->Graft(tmp);
    else // no valid output
      output->SetDataValid(false);
  }
}
virtual const char* mitk::NavigationDataSequentialPlayer::GetFileName (  ) const [virtual]

returns the file name and path

virtual unsigned int mitk::NavigationDataSequentialPlayer::GetNumberOfSnapshots (  ) [virtual]
Returns:
the number of navigation data snapshots available in the file
virtual bool mitk::NavigationDataSequentialPlayer::GetRepeat (  ) [virtual]

set if the data player should repeat the outputs

virtual const char* mitk::NavigationDataSequentialPlayer::GetXMLString (  ) const [virtual]

returns the current xml string

void mitk::NavigationDataSequentialPlayer::GoToSnapshot ( int  i )

advance the output to the i-th snapshot e.g. if you want to have the NavData of snapshot 17 then you can call GoToSnapshot(17). index begins at 1! you can then also go back to snapshot 1 with GoToSnapshot(1)

Definition at line 85 of file mitkNavigationDataSequentialPlayer.cpp.

References MITK_WARN.

{
  assert(m_DataElem);

  int numOfUpdateCalls = 0;

  // i.e. number of snapshots 10
  // goto(7), m_LastGoTo=3 => numOfUpdateCalls = 4
  if(m_LastGoTo <= i)
    numOfUpdateCalls = i - m_LastGoTo;
  // goto(4), m_LastGoTo=7 => numOfUpdateCalls = 7
  else
  {
    if(!m_Repeat)
    {
      MITK_WARN << "cannot go back to snapshot " << i << " because the "
          << this->GetNameOfClass() << " is configured to not repeat the"
          << " navigation data";

    }
    else
    {
      numOfUpdateCalls = (m_NumberOfSnapshots - m_LastGoTo) + i;
    }
  }

  for(int j=0; j<numOfUpdateCalls; ++j)
    this->Update();

  m_LastGoTo = i;
}
mitk::NavigationDataSequentialPlayer::mitkClassMacro ( NavigationDataSequentialPlayer  ,
NavigationDataSource   
)
static Pointer mitk::NavigationDataSequentialPlayer::New (  ) [static]
mitk::NavigationData::Pointer mitk::NavigationDataSequentialPlayer::ReadVersion1 (  ) [protected]

Definition at line 175 of file mitkNavigationDataSequentialPlayer.cpp.

References matrix(), mitk::NavigationData::New(), TiXmlElement::QueryDoubleAttribute(), TiXmlElement::QueryFloatAttribute(), and TiXmlElement::QueryIntAttribute().

{
  mitk::NavigationData::Pointer nd = mitk::NavigationData::New();
  mitk::NavigationData::PositionType position;
  mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0);
  mitk::NavigationData::TimeStampType timestamp = -1;
  mitk::NavigationData::CovarianceMatrixType matrix;

  bool hasPosition = true;
  bool hasOrientation = true;
  bool dataValid = false;

  position.Fill(0.0);
  matrix.SetIdentity();

  TiXmlElement* elem = m_CurrentElem;

  if(!elem)
    return NULL;

  //check here if EOF (the query don't change the timestamp value which should always be > 0)
  elem->QueryDoubleAttribute("Time",&timestamp);
  if (timestamp == -1)
  {
    return NULL;  //the calling method should check the return value if it is valid/not NULL
  }

  elem->QueryFloatAttribute("X", &position[0]);
  elem->QueryFloatAttribute("Y", &position[1]);
  elem->QueryFloatAttribute("Z", &position[2]);

  elem->QueryFloatAttribute("QX", &orientation[0]);
  elem->QueryFloatAttribute("QY", &orientation[1]);
  elem->QueryFloatAttribute("QZ", &orientation[2]);
  elem->QueryFloatAttribute("QR", &orientation[3]);

  elem->QueryFloatAttribute("C00", &matrix[0][0]);
  elem->QueryFloatAttribute("C01", &matrix[0][1]);
  elem->QueryFloatAttribute("C02", &matrix[0][2]);
  elem->QueryFloatAttribute("C03", &matrix[0][3]);
  elem->QueryFloatAttribute("C04", &matrix[0][4]);
  elem->QueryFloatAttribute("C05", &matrix[0][5]);
  elem->QueryFloatAttribute("C10", &matrix[1][0]);
  elem->QueryFloatAttribute("C11", &matrix[1][1]);
  elem->QueryFloatAttribute("C12", &matrix[1][2]);
  elem->QueryFloatAttribute("C13", &matrix[1][3]);
  elem->QueryFloatAttribute("C14", &matrix[1][4]);
  elem->QueryFloatAttribute("C15", &matrix[1][5]);

  int tmpval = 0;
  elem->QueryIntAttribute("Valid", &tmpval);
  if (tmpval == 0)
    dataValid = false;
  else
    dataValid = true;

  tmpval = 0;
  elem->QueryIntAttribute("hO", &tmpval);
  if (tmpval == 0)
    hasOrientation = false;
  else
    hasOrientation = true;

  tmpval = 0;
  elem->QueryIntAttribute("hP", &tmpval);
  if (tmpval == 0)
    hasPosition = false;
  else
    hasPosition = true;

  nd->SetTimeStamp(timestamp);
  nd->SetPosition(position);
  nd->SetOrientation(orientation);
  nd->SetCovErrorMatrix(matrix);
  nd->SetDataValid(dataValid);
  nd->SetHasOrientation(hasOrientation);
  nd->SetHasPosition(hasPosition);

  //delete elem;
  return nd;
}
void mitk::NavigationDataSequentialPlayer::ReinitXML (  ) [protected]

Definition at line 43 of file mitkNavigationDataSequentialPlayer.cpp.

References TiXmlNode::FirstChildElement(), MITK_WARN, mitk::NavigationData::New(), and TiXmlNode::NextSiblingElement().

{
  m_DataElem = m_Doc->FirstChildElement("Data");
  int toolcount;
  if(!m_DataElem)
    MITK_WARN << "Data element not found";
  else
  {
    m_DataElem->QueryIntAttribute("ToolCount", &toolcount);
    this->SetNumberOfOutputs(toolcount);

    mitk::NavigationData::Pointer emptyNd = mitk::NavigationData::New();
    mitk::NavigationData::PositionType position;
    mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0);
    position.Fill(0.0);

    emptyNd->SetPosition(position);
    emptyNd->SetOrientation(orientation);
    emptyNd->SetDataValid(false);

    mitk::NavigationData::Pointer tmp;
    for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++)
    {
      tmp = mitk::NavigationData::New();
      tmp->Graft(emptyNd);
      this->SetNthOutput(index, tmp);
    }

    // find out _NumberOfSnapshots
    m_NumberOfSnapshots = 0;
    TiXmlElement* nextND = m_DataElem->FirstChildElement("ND");
    while(nextND)
    {
      ++m_NumberOfSnapshots;
      nextND = nextND->NextSiblingElement("ND");
    }
    // e.g. 12 nd found and 2 tools used => number of snapshots is 12:2=6
    m_NumberOfSnapshots = m_NumberOfSnapshots/toolcount;

  }
}
void mitk::NavigationDataSequentialPlayer::SetFileName ( const std::string &  _FileName )

sets the file name and path (if XMLString is set, this is neglected)

Definition at line 118 of file mitkNavigationDataSequentialPlayer.cpp.

{
  m_FileName = _FileName;

  if(!m_Doc->LoadFile(m_FileName))
  {
    this->SetNumberOfOutputs(0);
    std::ostringstream s;
    s << "File " << _FileName << " could not be loaded";
    throw std::invalid_argument(s.str());
  }
  else
    this->ReinitXML();

  this->Modified();
}
virtual void mitk::NavigationDataSequentialPlayer::SetRepeat ( bool  _arg ) [virtual]

set to true if the data player should repeat the outputs

void mitk::NavigationDataSequentialPlayer::SetXMLString ( const std::string &  _XMLString )

sets a xml string (by this, the xml string is not read from file)

Definition at line 136 of file mitkNavigationDataSequentialPlayer.cpp.

{
  m_XMLString = _XMLString;

  m_Doc->Parse( m_XMLString.c_str() );
  this->ReinitXML();

  this->Modified();
}
void mitk::NavigationDataSequentialPlayer::UpdateOutputInformation (  ) [virtual]

Used for pipeline update just to tell the pipeline that we always have to update.

Definition at line 257 of file mitkNavigationDataSequentialPlayer.cpp.

{
  this->Modified();  // make sure that we need to be updated
  Superclass::UpdateOutputInformation();
}

Member Data Documentation

Definition at line 104 of file mitkNavigationDataSequentialPlayer.h.

Definition at line 103 of file mitkNavigationDataSequentialPlayer.h.

Definition at line 102 of file mitkNavigationDataSequentialPlayer.h.

Definition at line 100 of file mitkNavigationDataSequentialPlayer.h.

Definition at line 107 of file mitkNavigationDataSequentialPlayer.h.

Definition at line 106 of file mitkNavigationDataSequentialPlayer.h.

Definition at line 105 of file mitkNavigationDataSequentialPlayer.h.

Definition at line 101 of file mitkNavigationDataSequentialPlayer.h.


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