MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataSetWriterCSV.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include <fstream>
15#include <mitkIGTMimeTypes.h>
16#include <mitkLocaleSwitch.h>
17
19 mitk::IGTMimeTypes::NAVIGATIONDATASETCSV_MIMETYPE(),
20 "MITK NavigationDataSet Reader (CSV)")
21{
22 RegisterService();
23}
24
27
31
36
38{
39 std::ostream* out = GetOutputStream();
40 if (out == nullptr)
41 {
42 out = new std::ofstream(GetOutputLocation().c_str());
43 }
44 mitk::NavigationDataSet::ConstPointer data = dynamic_cast<const NavigationDataSet*> (this->GetInput());
45
46 //define own locale
47 mitk::LocaleSwitch localeSwitch("C");
48
49 //write header
50 unsigned int numberOfTools = data->GetNumberOfTools();
51 for (unsigned int index = 0; index < numberOfTools; index++){ *out << "TimeStamp_Tool" << index <<
52 ";Valid_Tool" << index <<
53 ";X_Tool" << index <<
54 ";Y_Tool" << index <<
55 ";Z_Tool" << index <<
56 ";QX_Tool" << index <<
57 ";QY_Tool" << index <<
58 ";QZ_Tool" << index <<
59 ";QR_Tool" << index << ";";}
60 *out << "\n";
61
62 out->precision(15); // rounding precision because we don't want to loose data.
63
64 //write data
65 MITK_INFO << "Number of timesteps: " << data->Size();
66 for (unsigned int i=0; i<data->Size(); i++)
67 {
68 std::vector< mitk::NavigationData::Pointer > NavigationDatasOfCurrentStep = data->GetTimeStep(i);
69 for (unsigned int toolIndex = 0; toolIndex < numberOfTools; toolIndex++)
70 {
71 mitk::NavigationData::Pointer nd = NavigationDatasOfCurrentStep.at(toolIndex);
72 *out << nd->GetIGTTimeStamp() << ";"
73 << nd->IsDataValid() << ";"
74 << nd->GetPosition()[0] << ";"
75 << nd->GetPosition()[1] << ";"
76 << nd->GetPosition()[2] << ";"
77 << nd->GetOrientation()[0] << ";"
78 << nd->GetOrientation()[1] << ";"
79 << nd->GetOrientation()[2] << ";"
80 << nd->GetOrientation()[3] << ";";
81 }
82 *out << "\n";
83 }
84
85 out->flush();
86 delete out;
87}
mitk::NavigationDataSetWriterCSV * Clone() const override
Data structure which stores streams of mitk::NavigationData for multiple tools.
IGT Exceptions.