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
mitkNrrdTensorImageWriter.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 "itkMetaDataDictionary.h"
19 #include "itkMetaDataObject.h"
20 #include "itkNrrdImageIO.h"
21 #include "itkImageFileWriter.h"
22 #include "itkDiffusionTensor3D.h"
23 #include "mitkImageCast.h"
25 #include <mitkLocaleSwitch.h>
26 
27 
30 {
32 }
33 
35  : AbstractFileWriter(other)
36 {
37 }
38 
39 
41 {}
42 
43 
45 {
46  InputType::ConstPointer input = dynamic_cast<const InputType*>(this->GetInput());
47  if (input.IsNull() )
48  {
49  MITK_ERROR <<"Sorry, input to NrrdTensorImageWriter is NULL!";
50  return;
51  }
52  if ( this->GetOutputLocation().empty() )
53  {
54  MITK_ERROR << "Sorry, filename has not been set!" ;
55  return ;
56  }
57  mitk::LocaleSwitch localeSwitch("C");
58 
60  io->SetFileType( itk::ImageIOBase::Binary );
61  io->UseCompressionOn();
62 
63  typedef itk::Image<itk::DiffusionTensor3D<float>,3> ImageType;
64  typedef itk::ImageFileWriter<ImageType> WriterType;
65  WriterType::Pointer nrrdWriter = WriterType::New();
66 
68  CastToItkImage(input, outimage);
69 
70  nrrdWriter->SetInput( outimage );
71  nrrdWriter->SetImageIO(io);
72  nrrdWriter->SetFileName(this->GetOutputLocation().c_str());
73  nrrdWriter->UseCompressionOn();
74 
75  try
76  {
77  nrrdWriter->Update();
78  }
79  catch (itk::ExceptionObject e)
80  {
81  std::cout << e << std::endl;
82  }
83 }
84 
86 {
87  return new NrrdTensorImageWriter(*this);
88 }
89 
91 {
92  InputType::ConstPointer input = dynamic_cast<const InputType*>(this->GetInput());
93  if (input.IsNull() )
94  {
95  return Unsupported;
96  }
97  else
98  {
99  return Supported;
100  }
101 }
itk::SmartPointer< Self > Pointer
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
virtual mitk::NrrdTensorImageWriter * Clone() const override
virtual ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
map::core::discrete::Elements< 3 >::InternalImageType ImageType
Convenience class to temporarily change the current locale.
static const char * GetStaticNameOfClass()
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
virtual void Write() override
Write the base data to the specified location or output stream.
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
this class encapsulates tensor images
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:49
Base class for writing mitk::BaseData objects to files or streams.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.