Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFiberBundleTrackVisWriter.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 <vtkSmartPointer.h>
19 #include <vtkCleanPolyData.h>
20 #include <itksys/SystemTools.hxx>
21 #include <mitkTrackvis.h>
22 #include <itkSize.h>
23 #include <vtkFloatArray.h>
24 #include <vtkCellData.h>
25 #include <vtkPointData.h>
26 #include <mitkAbstractFileWriter.h>
27 #include <mitkCustomMimeType.h>
29 
31  : mitk::AbstractFileWriter(mitk::FiberBundle::GetStaticNameOfClass(), mitk::DiffusionIOMimeTypes::FIBERBUNDLE_TRK_MIMETYPE_NAME(), "TrackVis Fiber Bundle Reader")
32 {
33  // Options defaultOptions;
34  // this->SetDefaultOptions(defaultOptions);
36 }
37 
39  :mitk::AbstractFileWriter(other)
40 {}
41 
43 {}
44 
46 {
47  return new mitk::FiberBundleTrackVisWriter(*this);
48 }
49 
51 {
52 
53  std::ostream* out;
54  std::ofstream outStream;
55 
56  if( this->GetOutputStream() )
57  {
58  out = this->GetOutputStream();
59  }else{
60  outStream.open( this->GetOutputLocation().c_str() );
61  out = &outStream;
62  }
63 
64  if ( !out->good() )
65  {
66  mitkThrow() << "Stream not good.";
67  }
68 
69  try
70  {
71  const std::string& locale = "C";
72  const std::string& currLocale = setlocale( LC_ALL, NULL );
73  setlocale(LC_ALL, locale.c_str());
74 
75  std::locale previousLocale(out->getloc());
76  std::locale I("C");
77  out->imbue(I);
78 
79  std::string filename = this->GetOutputLocation().c_str();
80 
81  mitk::FiberBundle::ConstPointer input = dynamic_cast<const mitk::FiberBundle*>(this->GetInput());
82  std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation().c_str());
83 
84  // default extension is .fib
85  if(ext == "")
86  {
87  ext = ".trk";
88  this->SetOutputLocation(this->GetOutputLocation() + ext);
89  }
90 
91  MITK_INFO << "Writing fiber bundle as TRK";
93  trk.create(filename, input.GetPointer());
94  trk.writeHdr();
95  trk.append(input.GetPointer());
96 
97  setlocale(LC_ALL, currLocale.c_str());
98  MITK_INFO << "Fiber bundle written";
99  }
100  catch(...)
101  {
102  throw;
103  }
104 }
#define MITK_INFO
Definition: mitkLogMacros.h:22
virtual void Write() override
Write the base data to the specified location or output stream.
DataCollection - Class to facilitate loading/accessing structured data.
short append(const mitk::FiberBundle *fib)
static const std::string filename
#define mitkThrow()
short create(string m_Filename, const mitk::FiberBundle *fib)
Base Class for Fiber Bundles;.
static const char * GetStaticNameOfClass()
virtual FiberBundleTrackVisWriter * Clone() const override
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Base class for writing mitk::BaseData objects to files or streams.