Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkNavigationDataSetWriterCSV.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found 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 {
23 }
24 
26 {}
27 
29 {
30 }
31 
33 {
34  return new NavigationDataSetWriterCSV(*this);
35 }
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 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
DataCollection - Class to facilitate loading/accessing structured data.
Convenience class to temporarily change the current locale.
const BaseData * GetInput() const override
Get the input data set via SetInput().
mitk::NavigationDataSetWriterCSV * Clone() const override
Data structure which stores streams of mitk::NavigationData for multiple tools.
std::ostream * GetOutputStream() const override
Get the output stream.
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
std::string GetOutputLocation() const override
Get the current output location.
void Write() override
Write the base data to the specified location or output stream.
Base class for writing mitk::BaseData objects to files or streams.