Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkNrrdQBallImageWriter.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 "mitkImageCast.h"
23 #include "mitkIOMimeTypes.h"
25 #include <mitkLocaleSwitch.h>
26 
27 
30 {
32 }
33 
35  : AbstractFileWriter(other)
36 {
37 }
38 
40 {}
41 
42 
44 {
45  InputType::ConstPointer input = dynamic_cast<const InputType*>(this->GetInput());
46  if (input.IsNull())
47  {
48  MITK_ERROR <<"Sorry, input to NrrdQBallImageWriter is NULL!";
49  return;
50  }
51  if ( this->GetOutputLocation().empty() )
52  {
53  MITK_ERROR << "Sorry, filename has not been set!";
54  return ;
55  }
56 
57  mitk::LocaleSwitch localeSwitch("C");
58 
60  io->SetFileType( itk::ImageIOBase::Binary );
61  io->UseCompressionOn();
62 
63  typedef itk::VectorImage<float, 3> VecImgType;
64 
65  typedef itk::Image<itk::Vector<float,QBALL_ODFSIZE>,3> ImageType;
66  typedef itk::ImageFileWriter<VecImgType> WriterType;
67  WriterType::Pointer nrrdWriter = WriterType::New();
68 
70  CastToItkImage(input, outimage);
71 
73  vecImg->SetSpacing( outimage->GetSpacing() ); // Set the image spacing
74  vecImg->SetOrigin( outimage->GetOrigin() ); // Set the image origin
75  vecImg->SetDirection( outimage->GetDirection() ); // Set the image direction
76  vecImg->SetLargestPossibleRegion( outimage->GetLargestPossibleRegion());
77  vecImg->SetBufferedRegion( outimage->GetLargestPossibleRegion() );
78  vecImg->SetVectorLength(QBALL_ODFSIZE);
79  vecImg->Allocate();
80 
81  itk::ImageRegionIterator<VecImgType> ot (vecImg, vecImg->GetLargestPossibleRegion() );
82  ot.GoToBegin();
83 
84  itk::ImageRegionIterator<ImageType> it (outimage, outimage->GetLargestPossibleRegion() );
85 
86  typedef ImageType::PixelType VecPixType;
87  typedef VecImgType::PixelType VarVecType;
88 
89  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
90  {
91  VecPixType vec = it.Get();
92  VarVecType varVec(vec.GetVnlVector().data_block(), QBALL_ODFSIZE);
93  ot.Set(varVec);
94  ++ot;
95  }
96 
97  nrrdWriter->SetInput( vecImg );
98  nrrdWriter->SetImageIO(io);
99  nrrdWriter->SetFileName(this->GetOutputLocation().c_str());
100  nrrdWriter->UseCompressionOn();
101 
102 
103  try
104  {
105  nrrdWriter->Update();
106  }
107  catch (itk::ExceptionObject e)
108  {
109  std::cout << e << std::endl;
110  }
111 }
112 
114 {
115  return new NrrdQBallImageWriter(*this);
116 }
117 
119 {
120  InputType::ConstPointer input = dynamic_cast<const InputType*>(this->GetInput());
121  if (input.IsNull() )
122  {
123  return Unsupported;
124  }
125  else
126  {
127  return Supported;
128  }
129 }
virtual ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
itk::SmartPointer< Self > Pointer
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
virtual void Write() override
Write the base data to the specified location or output stream.
this class encapsulates qball images
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()
#define QBALL_ODFSIZE
virtual mitk::NrrdQBallImageWriter * Clone() const override
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
unsigned short PixelType
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.