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
itkFslPeakImageConverter.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 #ifndef __itkFslPeakImageConverter_cpp
17 #define __itkFslPeakImageConverter_cpp
18 
19 #include <time.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 
24 #include <itkImageRegionConstIterator.h>
25 #include <itkImageRegionConstIteratorWithIndex.h>
26 #include <itkImageRegionIterator.h>
27 #include <itkContinuousIndex.h>
28 
29 #include <vtkSmartPointer.h>
30 #include <vtkPolyData.h>
31 #include <vtkCellArray.h>
32 #include <vtkPoints.h>
33 #include <vtkPolyLine.h>
34 
35 
36 namespace itk {
37 
38 template< class PixelType >
40  m_NormalizationMethod(NO_NORM)
41 {
42 
43 }
44 
45 template< class PixelType >
48 {
49  // output vector field
50  vtkSmartPointer<vtkCellArray> m_VtkCellArray = vtkSmartPointer<vtkCellArray>::New();
51  vtkSmartPointer<vtkPoints> m_VtkPoints = vtkSmartPointer<vtkPoints>::New();
52 
53  Vector<float, 4> spacing4 = m_InputImages->GetElement(0)->GetSpacing();
54  Point<float, 4> origin4 = m_InputImages->GetElement(0)->GetOrigin();
55  Matrix<double, 4, 4> direction4 = m_InputImages->GetElement(0)->GetDirection();
56  ImageRegion<4> imageRegion4 = m_InputImages->GetElement(0)->GetLargestPossibleRegion();
57 
58  itk::Vector<double,3> spacing3;
59  Point<float, 3> origin3;
60  Matrix<double, 3, 3> direction3;
61  ImageRegion<3> imageRegion3;
62 
63  spacing3[0] = spacing4[0]; spacing3[1] = spacing4[1]; spacing3[2] = spacing4[2];
64  origin3[0] = origin4[0]; origin3[1] = origin4[1]; origin3[2] = origin4[2];
65  for (int r=0; r<3; r++)
66  for (int c=0; c<3; c++)
67  direction3[r][c] = direction4[r][c];
68  imageRegion3.SetSize(0, imageRegion4.GetSize()[0]);
69  imageRegion3.SetSize(1, imageRegion4.GetSize()[1]);
70  imageRegion3.SetSize(2, imageRegion4.GetSize()[2]);
71 
72  double minSpacing = spacing3[0];
73  if (spacing3[1]<minSpacing)
74  minSpacing = spacing3[1];
75  if (spacing3[2]<minSpacing)
76  minSpacing = spacing3[2];
77 
78  m_DirectionImageContainer = DirectionImageContainerType::New();
79 
80  typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
81  for (int i=0; i<m_InputImages->Size(); i++)
82  {
83  InputImageType::Pointer img = m_InputImages->GetElement(i);
84  int x = img->GetLargestPossibleRegion().GetSize(0);
85  int y = img->GetLargestPossibleRegion().GetSize(1);
86  int z = img->GetLargestPossibleRegion().GetSize(2);
87 
89  directionImage->SetSpacing( spacing3 );
90  directionImage->SetOrigin( origin3 );
91  directionImage->SetDirection( direction3 );
92  directionImage->SetRegions( imageRegion3 );
93  directionImage->Allocate();
94  Vector< PixelType, 3 > nullVec; nullVec.Fill(0.0);
95  directionImage->FillBuffer(nullVec);
96 
97  for (int a=0; a<x; a++)
98  for (int b=0; b<y; b++)
99  for (int c=0; c<z; c++)
100  {
101  // generate vector field
102  typename InputImageType::IndexType index;
103  index.SetElement(0,a);
104  index.SetElement(1,b);
105  index.SetElement(2,c);
106  vnl_vector<double> dirVec; dirVec.set_size(4);
107  for (int k=0; k<3; k++)
108  {
109  index.SetElement(3,k);
110  dirVec[k] = img->GetPixel(index);
111  }
112  dirVec[3] = 0;
113 
114  vtkSmartPointer<vtkPolyLine> container = vtkSmartPointer<vtkPolyLine>::New();
115  itk::ContinuousIndex<double, 4> center;
116  center[0] = index[0];
117  center[1] = index[1];
118  center[2] = index[2];
119  center[3] = 0;
120  itk::Point<double, 4> worldCenter;
121  img->TransformContinuousIndexToPhysicalPoint( center, worldCenter );
122 
123  switch (m_NormalizationMethod)
124  {
125  case NO_NORM:
126  break;
127  case SINGLE_VEC_NORM:
128  dirVec.normalize();
129  break;
130  }
131  dirVec.normalize();
132  dirVec = img->GetDirection()*dirVec;
133 
134  itk::Point<double> worldStart;
135  worldStart[0] = worldCenter[0]-dirVec[0]/2 * minSpacing;
136  worldStart[1] = worldCenter[1]-dirVec[1]/2 * minSpacing;
137  worldStart[2] = worldCenter[2]-dirVec[2]/2 * minSpacing;
138  vtkIdType id = m_VtkPoints->InsertNextPoint(worldStart.GetDataPointer());
139  container->GetPointIds()->InsertNextId(id);
140  itk::Point<double> worldEnd;
141  worldEnd[0] = worldCenter[0]+dirVec[0]/2 * minSpacing;
142  worldEnd[1] = worldCenter[1]+dirVec[1]/2 * minSpacing;
143  worldEnd[2] = worldCenter[2]+dirVec[2]/2 * minSpacing;
144  id = m_VtkPoints->InsertNextPoint(worldEnd.GetDataPointer());
145  container->GetPointIds()->InsertNextId(id);
146  m_VtkCellArray->InsertNextCell(container);
147 
148  // generate direction image
149  typename ItkDirectionImageType::IndexType index2;
150  index2[0] = index[0]; index2[1] = index[1]; index2[2] = index[2];
151 
152 
153  Vector< PixelType, 3 > pixel;
154  pixel.SetElement(0, dirVec[0]);
155  pixel.SetElement(1, dirVec[1]);
156  pixel.SetElement(2, dirVec[2]);
157  directionImage->SetPixel(index2, pixel);
158  }
159 
160  m_DirectionImageContainer->InsertElement(m_DirectionImageContainer->Size(), directionImage);
161  }
162 
163  vtkSmartPointer<vtkPolyData> directionsPolyData = vtkSmartPointer<vtkPolyData>::New();
164  directionsPolyData->SetPoints(m_VtkPoints);
165  directionsPolyData->SetLines(m_VtkCellArray);
166  m_OutputFiberBundle = mitk::FiberBundle::New(directionsPolyData);
167 }
168 
169 }
170 
171 #endif // __itkFslPeakImageConverter_cpp
itk::SmartPointer< Self > Pointer
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.