Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include <fstream>
19 #include <mitkIGTMimeTypes.h>
20 #include <mitkLocaleSwitch.h>
21 
23  mitk::IGTMimeTypes::NAVIGATIONDATASETCSV_MIMETYPE(),
24  "MITK NavigationDataSet Reader (CSV)")
25 {
27 }
28 
30 {}
31 
33 {
34 }
35 
37 {
38  return new NavigationDataSetWriterCSV(*this);
39 }
40 
42 {
43  std::ostream* out = GetOutputStream();
44  if (out == nullptr)
45  {
46  out = new std::ofstream(GetOutputLocation().c_str());
47  }
48  mitk::NavigationDataSet::ConstPointer data = dynamic_cast<const NavigationDataSet*> (this->GetInput());
49 
50  //define own locale
51  mitk::LocaleSwitch localeSwitch("C");
52 
53  //write header
54  unsigned int numberOfTools = data->GetNumberOfTools();
55  for (unsigned int index = 0; index < numberOfTools; index++){ *out << "TimeStamp_Tool" << index <<
56  ";Valid_Tool" << index <<
57  ";X_Tool" << index <<
58  ";Y_Tool" << index <<
59  ";Z_Tool" << index <<
60  ";QX_Tool" << index <<
61  ";QY_Tool" << index <<
62  ";QZ_Tool" << index <<
63  ";QR_Tool" << index << ";";}
64  *out << "\n";
65 
66  out->precision(15); // rounding precision because we don't want to loose data.
67 
68  //write data
69  MITK_INFO << "Number of timesteps: " << data->Size();
70  for (unsigned int i=0; i<data->Size(); i++)
71  {
72  std::vector< mitk::NavigationData::Pointer > NavigationDatasOfCurrentStep = data->GetTimeStep(i);
73  for (unsigned int toolIndex = 0; toolIndex < numberOfTools; toolIndex++)
74  {
75  mitk::NavigationData::Pointer nd = NavigationDatasOfCurrentStep.at(toolIndex);
76  *out << nd->GetTimeStamp() << ";"
77  << nd->IsDataValid() << ";"
78  << nd->GetPosition()[0] << ";"
79  << nd->GetPosition()[1] << ";"
80  << nd->GetPosition()[2] << ";"
81  << nd->GetOrientation()[0] << ";"
82  << nd->GetOrientation()[1] << ";"
83  << nd->GetOrientation()[2] << ";"
84  << nd->GetOrientation()[3] << ";";
85  }
86  *out << "\n";
87  }
88 
89  out->flush();
90  delete out;
91 }
itk::SmartPointer< Self > Pointer
#define MITK_INFO
Definition: mitkLogMacros.h:22
DataCollection - Class to facilitate loading/accessing structured data.
Convenience class to temporarily change the current locale.
static const char * GetStaticNameOfClass()
virtual mitk::NavigationDataSetWriterCSV * Clone() const override
Data structure which stores streams of mitk::NavigationData for multiple tools.
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
virtual 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.