Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkNavigationDataSequentialPlayer.h"
00019
00020
00021 #include <itksys/SystemTools.hxx>
00022
00023 #include <mitkTimeStamp.h>
00024 #include <fstream>
00025 #include <sstream>
00026
00027 mitk::NavigationDataSequentialPlayer::NavigationDataSequentialPlayer()
00028 : m_Doc(new TiXmlDocument)
00029 , m_DataElem(0)
00030 , m_CurrentElem(0)
00031 , m_Repeat(false)
00032 , m_NumberOfSnapshots(0)
00033 , m_LastGoTo(0)
00034 {
00035 }
00036
00037
00038 mitk::NavigationDataSequentialPlayer::~NavigationDataSequentialPlayer()
00039 {
00040 delete m_Doc;
00041 }
00042
00043 void mitk::NavigationDataSequentialPlayer::ReinitXML()
00044 {
00045 m_DataElem = m_Doc->FirstChildElement("Data");
00046 int toolcount;
00047 if(!m_DataElem)
00048 MITK_WARN << "Data element not found";
00049 else
00050 {
00051 m_DataElem->QueryIntAttribute("ToolCount", &toolcount);
00052 this->SetNumberOfOutputs(toolcount);
00053
00054 mitk::NavigationData::Pointer emptyNd = mitk::NavigationData::New();
00055 mitk::NavigationData::PositionType position;
00056 mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0);
00057 position.Fill(0.0);
00058
00059 emptyNd->SetPosition(position);
00060 emptyNd->SetOrientation(orientation);
00061 emptyNd->SetDataValid(false);
00062
00063 mitk::NavigationData::Pointer tmp;
00064 for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++)
00065 {
00066 tmp = mitk::NavigationData::New();
00067 tmp->Graft(emptyNd);
00068 this->SetNthOutput(index, tmp);
00069 }
00070
00071
00072 m_NumberOfSnapshots = 0;
00073 TiXmlElement* nextND = m_DataElem->FirstChildElement("ND");
00074 while(nextND)
00075 {
00076 ++m_NumberOfSnapshots;
00077 nextND = nextND->NextSiblingElement("ND");
00078 }
00079
00080 m_NumberOfSnapshots = m_NumberOfSnapshots/toolcount;
00081
00082 }
00083 }
00084
00085 void mitk::NavigationDataSequentialPlayer::GoToSnapshot(int i)
00086 {
00087 assert(m_DataElem);
00088
00089 int numOfUpdateCalls = 0;
00090
00091
00092
00093 if(m_LastGoTo <= i)
00094 numOfUpdateCalls = i - m_LastGoTo;
00095
00096 else
00097 {
00098 if(!m_Repeat)
00099 {
00100 MITK_WARN << "cannot go back to snapshot " << i << " because the "
00101 << this->GetNameOfClass() << " is configured to not repeat the"
00102 << " navigation data";
00103
00104 }
00105 else
00106 {
00107 numOfUpdateCalls = (m_NumberOfSnapshots - m_LastGoTo) + i;
00108 }
00109 }
00110
00111 for(int j=0; j<numOfUpdateCalls; ++j)
00112 this->Update();
00113
00114 m_LastGoTo = i;
00115 }
00116
00117 void mitk::NavigationDataSequentialPlayer::
00118 SetFileName(const std::string& _FileName)
00119 {
00120 m_FileName = _FileName;
00121
00122 if(!m_Doc->LoadFile(m_FileName))
00123 {
00124 this->SetNumberOfOutputs(0);
00125 std::ostringstream s;
00126 s << "File " << _FileName << " could not be loaded";
00127 throw std::invalid_argument(s.str());
00128 }
00129 else
00130 this->ReinitXML();
00131
00132 this->Modified();
00133 }
00134
00135 void mitk::NavigationDataSequentialPlayer::
00136 SetXMLString(const std::string& _XMLString)
00137 {
00138 m_XMLString = _XMLString;
00139
00140 m_Doc->Parse( m_XMLString.c_str() );
00141 this->ReinitXML();
00142
00143 this->Modified();
00144 }
00145
00146 void mitk::NavigationDataSequentialPlayer::GenerateData()
00147 {
00148 assert(m_DataElem);
00149
00150
00151 mitk::NavigationData::Pointer tmp;
00152 for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++)
00153 {
00154
00155 if(!m_CurrentElem)
00156 m_CurrentElem = m_DataElem->FirstChildElement("ND");
00157
00158 else
00159 m_CurrentElem = m_CurrentElem->NextSiblingElement();
00160
00161
00162
00163 if(!m_CurrentElem && m_Repeat)
00164 m_CurrentElem = m_DataElem->FirstChildElement("ND");
00165
00166 mitk::NavigationData* output = this->GetOutput(index);
00167 tmp = this->ReadVersion1();
00168 if(tmp.IsNotNull())
00169 output->Graft(tmp);
00170 else
00171 output->SetDataValid(false);
00172 }
00173 }
00174
00175 mitk::NavigationData::Pointer mitk::NavigationDataSequentialPlayer::ReadVersion1()
00176 {
00177 mitk::NavigationData::Pointer nd = mitk::NavigationData::New();
00178 mitk::NavigationData::PositionType position;
00179 mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0);
00180 mitk::NavigationData::TimeStampType timestamp = -1;
00181 mitk::NavigationData::CovarianceMatrixType matrix;
00182
00183 bool hasPosition = true;
00184 bool hasOrientation = true;
00185 bool dataValid = false;
00186
00187 position.Fill(0.0);
00188 matrix.SetIdentity();
00189
00190 TiXmlElement* elem = m_CurrentElem;
00191
00192 if(!elem)
00193 return NULL;
00194
00195
00196 elem->QueryDoubleAttribute("Time",×tamp);
00197 if (timestamp == -1)
00198 {
00199 return NULL;
00200 }
00201
00202 elem->QueryFloatAttribute("X", &position[0]);
00203 elem->QueryFloatAttribute("Y", &position[1]);
00204 elem->QueryFloatAttribute("Z", &position[2]);
00205
00206 elem->QueryFloatAttribute("QX", &orientation[0]);
00207 elem->QueryFloatAttribute("QY", &orientation[1]);
00208 elem->QueryFloatAttribute("QZ", &orientation[2]);
00209 elem->QueryFloatAttribute("QR", &orientation[3]);
00210
00211 elem->QueryFloatAttribute("C00", &matrix[0][0]);
00212 elem->QueryFloatAttribute("C01", &matrix[0][1]);
00213 elem->QueryFloatAttribute("C02", &matrix[0][2]);
00214 elem->QueryFloatAttribute("C03", &matrix[0][3]);
00215 elem->QueryFloatAttribute("C04", &matrix[0][4]);
00216 elem->QueryFloatAttribute("C05", &matrix[0][5]);
00217 elem->QueryFloatAttribute("C10", &matrix[1][0]);
00218 elem->QueryFloatAttribute("C11", &matrix[1][1]);
00219 elem->QueryFloatAttribute("C12", &matrix[1][2]);
00220 elem->QueryFloatAttribute("C13", &matrix[1][3]);
00221 elem->QueryFloatAttribute("C14", &matrix[1][4]);
00222 elem->QueryFloatAttribute("C15", &matrix[1][5]);
00223
00224 int tmpval = 0;
00225 elem->QueryIntAttribute("Valid", &tmpval);
00226 if (tmpval == 0)
00227 dataValid = false;
00228 else
00229 dataValid = true;
00230
00231 tmpval = 0;
00232 elem->QueryIntAttribute("hO", &tmpval);
00233 if (tmpval == 0)
00234 hasOrientation = false;
00235 else
00236 hasOrientation = true;
00237
00238 tmpval = 0;
00239 elem->QueryIntAttribute("hP", &tmpval);
00240 if (tmpval == 0)
00241 hasPosition = false;
00242 else
00243 hasPosition = true;
00244
00245 nd->SetTimeStamp(timestamp);
00246 nd->SetPosition(position);
00247 nd->SetOrientation(orientation);
00248 nd->SetCovErrorMatrix(matrix);
00249 nd->SetDataValid(dataValid);
00250 nd->SetHasOrientation(hasOrientation);
00251 nd->SetHasPosition(hasPosition);
00252
00253
00254 return nd;
00255 }
00256
00257 void mitk::NavigationDataSequentialPlayer::UpdateOutputInformation()
00258 {
00259 this->Modified();
00260 Superclass::UpdateOutputInformation();
00261 }