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
mitkNrrdQBallImageReader.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 <mitkCustomMimeType.h>
20 
21 #include "itkImageFileReader.h"
22 #include "itkImageRegionIterator.h"
23 #include "itkMetaDataObject.h"
24 #include "itkNrrdImageIO.h"
25 #include "mitkITKImageImport.h"
26 #include "mitkImageDataItem.h"
27 #include <mitkLocaleSwitch.h>
28 
29 namespace mitk
30 {
32  : mitk::AbstractFileReader(other)
33  {
34  }
35 
37  : mitk::AbstractFileReader( CustomMimeType( mitk::DiffusionCoreIOMimeTypes::QBI_MIMETYPE() ), mitk::DiffusionCoreIOMimeTypes::QBI_MIMETYPE_DESCRIPTION() )
38  {
39  m_ServiceReg = this->RegisterService();
40  }
41 
43  {
44  }
45 
46  std::vector<itk::SmartPointer<BaseData> > NrrdQBallImageReader::Read()
47  {
48  std::vector<itk::SmartPointer<mitk::BaseData> > result;
49  std::string location = GetInputLocation();
50 
51  if ( location == "")
52  {
53  throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, the filename of the vessel tree to be read is empty!");
54  }
55  else
56  {
57  try
58  {
59  mitk::LocaleSwitch localeSwitch("C");
60 
61  typedef itk::VectorImage<float,3> ImageType;
63  typedef itk::ImageFileReader<ImageType> FileReaderType;
65  reader->SetImageIO(io);
66  reader->SetFileName(location);
67  reader->Update();
68  ImageType::Pointer img = reader->GetOutput();
69 
70  typedef itk::Image<itk::Vector<float,QBALL_ODFSIZE>,3> VecImgType;
72  vecImg->SetSpacing( img->GetSpacing() ); // Set the image spacing
73  vecImg->SetOrigin( img->GetOrigin() ); // Set the image origin
74  vecImg->SetDirection( img->GetDirection() ); // Set the image direction
75  vecImg->SetLargestPossibleRegion( img->GetLargestPossibleRegion());
76  vecImg->SetBufferedRegion( img->GetLargestPossibleRegion() );
77  vecImg->Allocate();
78 
79  itk::ImageRegionIterator<VecImgType> ot (vecImg, vecImg->GetLargestPossibleRegion() );
80  ot.GoToBegin();
81 
82  itk::ImageRegionIterator<ImageType> it (img, img->GetLargestPossibleRegion() );
83 
84  typedef ImageType::PixelType VarPixType;
85  typedef VecImgType::PixelType FixPixType;
86 
87  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
88  {
89  VarPixType vec = it.Get();
90  FixPixType fixVec(vec.GetDataPointer());
91  ot.Set(fixVec);
92  ++ot;
93  }
94 
95  OutputType::Pointer resultImage = OutputType::New();
96  resultImage->InitializeByItk( vecImg.GetPointer() );
97  resultImage->SetVolume( vecImg->GetBufferPointer() );
98  result.push_back( resultImage.GetPointer() );
99 
100  }
101  catch(std::exception& e)
102  {
103  throw itk::ImageFileReaderException(__FILE__, __LINE__, e.what());
104  }
105  catch(...)
106  {
107  throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, an error occurred while reading the requested vessel tree file!");
108  }
109  }
110  return result;
111  }
112 
113 } //namespace MITK
114 
115 mitk::NrrdQBallImageReader* mitk::NrrdQBallImageReader::Clone() const
116 {
117  return new NrrdQBallImageReader(*this);
118 }
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static Pointer New()
map::core::discrete::Elements< 3 >::InternalImageType ImageType
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Convenience class to temporarily change the current locale.
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
Base class for creating mitk::BaseData objects from files or streams.
unsigned short PixelType
virtual std::string GetInputLocation() const override
Get the current input location.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.