23 #include <itksys/SystemTools.hxx>
30 "MITK NavigationData Reader (XML)"), m_parentElement(nullptr), m_currentNode(nullptr)
52 std::istream*
in = GetInputStream();
55 dataset = Read(GetInputLocation());
59 std::vector<mitk::BaseData::Pointer> result;
61 result.push_back(base);
72 m_FileName = fileName;
74 TiXmlDocument document;
75 if (!document.LoadFile(fileName))
80 TiXmlElement* m_DataElem = document.FirstChildElement(
"Version");
84 m_DataElem = document.FirstChildElement(
"Data");
92 if (m_DataElem->QueryIntAttribute(
"Ver", &m_FileVersion) != TIXML_SUCCESS)
94 if (m_DataElem->QueryIntAttribute(
"version", &m_FileVersion) != TIXML_SUCCESS)
100 if (m_FileVersion != 1)
105 m_parentElement = document.FirstChildElement(
"Data");
106 if (!m_parentElement)
111 m_parentElement->QueryIntAttribute(
"ToolCount", &m_NumberOfOutputs);
115 return navigationDataSet;
124 m_FileVersion = this->GetFileVersion(stream);
127 if (m_FileVersion < 1)
129 StreamInvalid(
"Playing not possible. Invalid file version!");
133 m_NumberOfOutputs = this->GetNumberOfNavigationDatas(stream);
134 if (m_NumberOfOutputs == 0) {
return nullptr; }
148 std::vector<mitk::NavigationData::Pointer> navDatas(m_NumberOfOutputs);
149 for (
int n = 0; n < m_NumberOfOutputs; ++n)
151 curNavigationData = this->ReadVersion1();
153 if (curNavigationData.IsNull())
158 <<
"Different number of NavigationData objects for different tools. Ignoring last ones.";
162 navDatas.at(n) = curNavigationData;
165 if (curNavigationData.IsNotNull())
167 navigationDataSet->AddNavigationDatas(navDatas);
170 while (curNavigationData.IsNotNull());
172 return navigationDataSet;
177 if ( !m_parentElement )
183 m_currentNode = m_parentElement->IterateChildren(m_currentNode);
189 elem = m_currentNode->ToElement();
199 elem =
new TiXmlElement(
"");
206 if(delElem) {
delete elem; }
213 if (elem ==
nullptr) {
mitkThrow() <<
"Error: Element is NULL!";}
222 bool hasPosition =
true;
223 bool hasOrientation =
true;
224 bool dataValid =
false;
227 matrix.SetIdentity();
229 elem->QueryDoubleAttribute(
"Time",×tamp);
235 elem->QueryDoubleAttribute(
"X", &position[0]);
236 elem->QueryDoubleAttribute(
"Y", &position[1]);
237 elem->QueryDoubleAttribute(
"Z", &position[2]);
239 elem->QueryDoubleAttribute(
"QX", &orientation[0]);
240 elem->QueryDoubleAttribute(
"QY", &orientation[1]);
241 elem->QueryDoubleAttribute(
"QZ", &orientation[2]);
242 elem->QueryDoubleAttribute(
"QR", &orientation[3]);
244 elem->QueryDoubleAttribute(
"C00", &matrix[0][0]);
245 elem->QueryDoubleAttribute(
"C01", &matrix[0][1]);
246 elem->QueryDoubleAttribute(
"C02", &matrix[0][2]);
247 elem->QueryDoubleAttribute(
"C03", &matrix[0][3]);
248 elem->QueryDoubleAttribute(
"C04", &matrix[0][4]);
249 elem->QueryDoubleAttribute(
"C05", &matrix[0][5]);
250 elem->QueryDoubleAttribute(
"C10", &matrix[1][0]);
251 elem->QueryDoubleAttribute(
"C11", &matrix[1][1]);
252 elem->QueryDoubleAttribute(
"C12", &matrix[1][2]);
253 elem->QueryDoubleAttribute(
"C13", &matrix[1][3]);
254 elem->QueryDoubleAttribute(
"C14", &matrix[1][4]);
255 elem->QueryDoubleAttribute(
"C15", &matrix[1][5]);
258 elem->QueryIntAttribute(
"Valid", &tmpval);
265 elem->QueryIntAttribute(
"hO", &tmpval);
267 hasOrientation =
false;
269 hasOrientation =
true;
272 elem->QueryIntAttribute(
"hP", &tmpval);
278 nd->SetIGTTimeStamp(timestamp);
279 nd->SetPosition(position);
280 nd->SetOrientation(orientation);
281 nd->SetCovErrorMatrix(matrix);
282 nd->SetDataValid(dataValid);
283 nd->SetHasOrientation(hasOrientation);
284 nd->SetHasPosition(hasPosition);
305 auto dec =
new TiXmlDeclaration();
307 if(strcmp(dec->Version(),
"") == 0)
309 MITK_ERROR <<
"The input stream seems to have XML incompatible format";
313 m_parentElement =
new TiXmlElement(
"");
314 *stream >> *m_parentElement;
316 std::string tempValue = m_parentElement->Value();
317 if(tempValue !=
"Version")
319 if(tempValue ==
"Data"){
320 m_parentElement->QueryIntAttribute(
"version",&version);
325 m_parentElement->QueryIntAttribute(
"Ver",&version);
328 if (version > 0) {
return version; }
334 if (stream ==
nullptr)
348 int numberOfTools = 0;
350 std::string tempValue = m_parentElement->Value();
351 if(tempValue ==
"Version"){
352 *stream >> *m_parentElement;
354 m_parentElement->QueryIntAttribute(
"ToolCount",&numberOfTools);
356 if (numberOfTools > 0) {
return numberOfTools; }
364 m_ErrorMessage = message;
365 m_StreamValid =
false;
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
itk::SmartPointer< Self > Pointer
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 ...
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.
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
void StreamInvalid(std::string message)
This is a helping method which gives an error message and throws an exception with the given message...
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Convenience class to temporarily change the current locale.
NavigationDataSet::Pointer ReadNavigationDataSet()
mitk::NavigationData::Pointer ReadNavigationData(TiXmlElement *elem)
virtual ~NavigationDataReaderXML()
NavigationDataReaderXML()
virtual 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.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.
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...