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
mitkTbssImporter.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 
17 #ifndef __mitkTbssImporter_cpp
18 #define __mitkTbssImporter_cpp
19 
20 #include "mitkTbssImporter.h"
21 #include <mitkPixelTypeMultiplex.h>
23 
24 namespace mitk
25 {
26 
28 {
30  mitkPixelTypeMultiplex1( Import, m_InputVolume->GetPixelType(), tbssImg);
31  return tbssImg;
32 }
33 
34 template <typename TPixel>
36 {
37  // read all images with all_*.nii.gz
38  MITK_INFO << "called import ...";
40 
41  mitk::BaseGeometry* geo = m_InputVolume->GetGeometry();
42  mitk::Vector3D spacing = geo->GetSpacing();
43  mitk::Point3D origin = geo->GetOrigin();
44 
45  //Size size
46  DataImageType::SizeType dataSize;
47  dataSize[0] = m_InputVolume->GetDimension(0);
48  dataSize[1] = m_InputVolume->GetDimension(1);
49  dataSize[2] = m_InputVolume->GetDimension(2);
50 
51  m_Data->SetRegions(dataSize);
52 
53  // Set spacing
54  DataImageType::SpacingType dataSpacing;
55  dataSpacing[0] = spacing[0];
56  dataSpacing[1] = spacing[1];
57  dataSpacing[2] = spacing[2];
58  m_Data->SetSpacing(dataSpacing);
59 
60  DataImageType::PointType dataOrigin;
61  dataOrigin[0] = origin[0];
62  dataOrigin[1] = origin[1];
63  dataOrigin[2] = origin[2];
64  m_Data->SetOrigin(dataOrigin);
65 
66  //Direction must be set
67  DataImageType::DirectionType dir;
68  const itk::Transform<ScalarType, 3, 3>* transform3D = geo->GetIndexToWorldTransform();
69  itk::Transform<ScalarType,3,3>::ParametersType p = transform3D->GetParameters();
70  int t=0;
71  for(int i=0; i<3; i++)
72  {
73  for(int j=0; j<3; j++)
74  {
75  dir[i][j] = p[t]; // row-major order (where the column index varies the fastest)
76  t++;
77  }
78  }
79 
80  m_Data->SetDirection(dir);
81 
82  // Set the length to one because otherwise allocate fails. Should be changed when groups/measurements are added
83  m_Data->SetVectorLength(m_InputVolume->GetDimension(3));
84  m_Data->Allocate();
85 
86  // Determine vector size of m_Data
87 
88  int vecSize = m_Data->GetVectorLength();
89 
90  MITK_INFO << "vecsize " <<vecSize;
91  try {
93 
94  for(unsigned int i=0; i<dataSize[0]; i++)
95  {
96  MITK_INFO << "i " << i << " / " << dataSize[0];
97  for(unsigned int j=0; j<dataSize[1]; j++)
98  {
99  for(unsigned int k=0; k<dataSize[2]; k++)
100  {
102  itk::Index<3> id;
103  itk::Index<4> ix;
104 
105  ix[0] = id[0] = i;
106  ix[1] = id[1] = j;
107  ix[2] = id[2] = k;
108 
109  pixel = m_Data->GetPixel(id);
110 
111  for(int z=0; z<vecSize; z++)
112  {
113  ix[3] = z;
114  float value = readTbss.GetPixelByIndex(ix);
115  pixel.SetElement(z, value);
116  }
117  m_Data->SetPixel(id, pixel);
118  }
119  }
120  }
121  }
122  catch ( mitk::Exception& e )
123  {
124  MITK_ERROR << "TbssImporter::Import: No read access to tbss image: " << e.what() ;
125  }
126 
127  tbssImg->SetGroupInfo(m_Groups);
128  tbssImg->SetMeasurementInfo(m_MeasurementInfo);
129  tbssImg->SetImage(m_Data);
130 
131  tbssImg->InitializeFromVectorImage();
132 
133 }
134 
135 
136 }
137 #endif // __mitkTbssImporter_cpp
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
mitk::Point3D PointType
DataImageType::Pointer m_Data
Gives locked and index-based read access for a particular image part. The class provides several set-...
const TPixel & GetPixelByIndex(const itk::Index< VDimension > &idx) const
#define MITK_INFO
Definition: mitkLogMacros.h:22
#define MITK_ERROR
Definition: mitkLogMacros.h:24
std::vector< std::pair< std::string, int > > m_Groups
DataCollection - Class to facilitate loading/accessing structured data.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
std::string m_MeasurementInfo
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:49
mitk::TbssImage::Pointer Import()
Converts the FSL Nifty to NRRD and adds the meta data.
static Pointer New()
#define mitkPixelTypeMultiplex1(function, ptype, param1)
mitk::Image::Pointer m_InputVolume
BaseGeometry Describes the geometry of a data object.
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.