19 #include <itksys/SystemTools.hxx> 26 "MITK NavigationData Reader (XML)"), m_parentElement(nullptr), m_currentNode(nullptr)
55 std::vector<mitk::BaseData::Pointer> result;
57 result.push_back(base);
70 TiXmlDocument document;
71 if (!document.LoadFile(fileName))
76 TiXmlElement* m_DataElem = document.FirstChildElement(
"Version");
80 m_DataElem = document.FirstChildElement(
"Data");
88 if (m_DataElem->QueryIntAttribute(
"Ver", &
m_FileVersion) != TIXML_SUCCESS)
90 if (m_DataElem->QueryIntAttribute(
"version", &
m_FileVersion) != TIXML_SUCCESS)
111 return navigationDataSet;
125 StreamInvalid(
"Playing not possible. Invalid file version!");
140 mitk::NavigationData::Pointer curNavigationData;
149 if (curNavigationData.IsNull())
154 <<
"Different number of NavigationData objects for different tools. Ignoring last ones.";
158 navDatas.at(n) = curNavigationData;
161 if (curNavigationData.IsNotNull())
163 navigationDataSet->AddNavigationDatas(navDatas);
166 while (curNavigationData.IsNotNull());
168 return navigationDataSet;
195 elem =
new TiXmlElement(
"");
202 if(delElem) {
delete elem; }
209 if (elem ==
nullptr) {
mitkThrow() <<
"Error: Element is nullptr!";}
218 bool hasPosition =
true;
219 bool hasOrientation =
true;
220 bool dataValid =
false;
223 matrix.SetIdentity();
225 elem->QueryDoubleAttribute(
"Time",×tamp);
231 elem->QueryDoubleAttribute(
"X", &position[0]);
232 elem->QueryDoubleAttribute(
"Y", &position[1]);
233 elem->QueryDoubleAttribute(
"Z", &position[2]);
235 elem->QueryDoubleAttribute(
"QX", &orientation[0]);
236 elem->QueryDoubleAttribute(
"QY", &orientation[1]);
237 elem->QueryDoubleAttribute(
"QZ", &orientation[2]);
238 elem->QueryDoubleAttribute(
"QR", &orientation[3]);
240 elem->QueryDoubleAttribute(
"C00", &matrix[0][0]);
241 elem->QueryDoubleAttribute(
"C01", &matrix[0][1]);
242 elem->QueryDoubleAttribute(
"C02", &matrix[0][2]);
243 elem->QueryDoubleAttribute(
"C03", &matrix[0][3]);
244 elem->QueryDoubleAttribute(
"C04", &matrix[0][4]);
245 elem->QueryDoubleAttribute(
"C05", &matrix[0][5]);
246 elem->QueryDoubleAttribute(
"C10", &matrix[1][0]);
247 elem->QueryDoubleAttribute(
"C11", &matrix[1][1]);
248 elem->QueryDoubleAttribute(
"C12", &matrix[1][2]);
249 elem->QueryDoubleAttribute(
"C13", &matrix[1][3]);
250 elem->QueryDoubleAttribute(
"C14", &matrix[1][4]);
251 elem->QueryDoubleAttribute(
"C15", &matrix[1][5]);
254 elem->QueryIntAttribute(
"Valid", &tmpval);
261 elem->QueryIntAttribute(
"hO", &tmpval);
263 hasOrientation =
false;
265 hasOrientation =
true;
268 elem->QueryIntAttribute(
"hP", &tmpval);
274 nd->SetIGTTimeStamp(timestamp);
275 nd->SetPosition(position);
276 nd->SetOrientation(orientation);
277 nd->SetCovErrorMatrix(matrix);
278 nd->SetDataValid(dataValid);
279 nd->SetHasOrientation(hasOrientation);
280 nd->SetHasPosition(hasPosition);
301 auto dec =
new TiXmlDeclaration();
303 if(strcmp(dec->Version(),
"") == 0)
305 MITK_ERROR <<
"The input stream seems to have XML incompatible format";
312 std::string tempValue = m_parentElement->Value();
313 if(tempValue !=
"Version")
315 if(tempValue ==
"Data"){
316 m_parentElement->QueryIntAttribute(
"version",&version);
321 m_parentElement->QueryIntAttribute(
"Ver",&version);
324 if (version > 0) {
return version; }
330 if (stream ==
nullptr)
344 int numberOfTools = 0;
347 if(tempValue ==
"Version"){
352 if (numberOfTools > 0) {
return numberOfTools; }
std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
TiXmlNode * m_currentNode
unsigned int GetNumberOfNavigationDatas(std::istream *stream)
Returns the number of tracked tools out of the XML document.
itk::Matrix< mitk::ScalarType, 6, 6 > CovarianceMatrixType
type that holds the error characterization of the position and orientation measurements ...
TiXmlElement * m_parentElement
std::istream * GetInputStream() const override
Get the input stream.
An object of this class represents an exception of the MITK-IGT module.
mitk::NavigationData::Pointer ReadVersion1()
This method reads one line of the XML document and returns the data as a NavigationData object If the...
DataCollection - Class to facilitate loading/accessing structured data.
int m_FileVersion
indicates which XML encoding is used
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
An object of this class represents an exception of the MITK-IGT module which are releated to the inpu...
double TimeStampType
type that holds the time at which the data was recorded in milliseconds
void StreamInvalid(std::string message)
This is a helping method which gives an error message and throws an exception with the given message...
bool m_StreamValid
stores if the input stream is valid or not
std::string m_ErrorMessage
stores the error message if the stream is invalid
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Convenience class to temporarily change the current locale.
~NavigationDataReaderXML() override
NavigationDataSet::Pointer ReadNavigationDataSet()
mitk::NavigationData::Pointer ReadNavigationData(TiXmlElement *elem)
NavigationDataReaderXML()
mitk::NavigationDataReaderXML * Clone() const override
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
#define mitkThrowException(classname)
Base class for creating mitk::BaseData objects from files or streams.
int m_NumberOfOutputs
stores the number of outputs known from the XML document
bool m_StreamEnd
stores if the input stream arrived at end
std::string GetInputLocation() const override
Get the current input location.
unsigned int GetFileVersion(std::istream *stream)
Creates a stream out of the filename given by the variable m_FileName. The stream is then set to m_St...