16 #ifndef __itkMrtrixPeakImageConverter_cpp
17 #define __itkMrtrixPeakImageConverter_cpp
24 #include <itkImageRegionConstIterator.h>
25 #include <itkImageRegionConstIteratorWithIndex.h>
26 #include <itkImageRegionIterator.h>
27 #include <itkContinuousIndex.h>
29 #include <vtkSmartPointer.h>
30 #include <vtkPolyData.h>
31 #include <vtkCellArray.h>
32 #include <vtkPoints.h>
33 #include <vtkPolyLine.h>
38 template<
class PixelType >
40 m_NormalizationMethod(NO_NORM)
45 template<
class PixelType >
53 Vector<float, 4> spacing4 = m_InputImage->GetSpacing();
54 Point<float, 4> origin4 = m_InputImage->GetOrigin();
55 Matrix<double, 4, 4> direction4 = m_InputImage->GetDirection();
56 ImageRegion<4> imageRegion4 = m_InputImage->GetLargestPossibleRegion();
58 Vector<double, 3> spacing3;
59 Point<float, 3> origin3;
60 Matrix<double, 3, 3> direction3;
61 ImageRegion<3> imageRegion3;
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]);
72 double minSpacing = spacing3[0];
73 if (spacing3[1]<minSpacing)
74 minSpacing = spacing3[1];
75 if (spacing3[2]<minSpacing)
76 minSpacing = spacing3[2];
80 typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
82 int x = m_InputImage->GetLargestPossibleRegion().GetSize(0);
83 int y = m_InputImage->GetLargestPossibleRegion().GetSize(1);
84 int z = m_InputImage->GetLargestPossibleRegion().GetSize(2);
85 int numDirs = m_InputImage->GetLargestPossibleRegion().GetSize(3)/3;
88 m_NumDirectionsImage->SetSpacing( spacing3 );
89 m_NumDirectionsImage->SetOrigin( origin3 );
90 m_NumDirectionsImage->SetDirection( direction3 );
91 m_NumDirectionsImage->SetRegions( imageRegion3 );
92 m_NumDirectionsImage->Allocate();
93 m_NumDirectionsImage->FillBuffer(0);
95 for (
int i=0; i<numDirs; i++)
98 directionImage->SetSpacing( spacing3 );
99 directionImage->SetOrigin( origin3 );
100 directionImage->SetDirection( direction3 );
101 directionImage->SetRegions( imageRegion3 );
102 directionImage->Allocate();
103 Vector< PixelType, 3 > nullVec; nullVec.Fill(0.0);
104 directionImage->FillBuffer(nullVec);
105 m_DirectionImageContainer->InsertElement(m_DirectionImageContainer->Size(), directionImage);
109 for (
int i=0; i<numDirs; i++)
111 for (
int a=0; a<x; a++)
112 for (
int b=0; b<y; b++)
113 for (
int c=0; c<z; c++)
116 typename InputImageType::IndexType index;
117 index.SetElement(0,a);
118 index.SetElement(1,b);
119 index.SetElement(2,c);
120 vnl_vector<double> dirVec; dirVec.set_size(4);
121 for (
int k=0; k<3; k++)
123 index.SetElement(3,k+i*3);
124 dirVec[k] = m_InputImage->GetPixel(index);
128 if (dirVec.magnitude()<0.0001)
132 itk::ContinuousIndex<double, 4> center;
133 center[0] = index[0];
134 center[1] = index[1];
135 center[2] = index[2];
137 itk::Point<double, 4> worldCenter;
138 m_InputImage->TransformContinuousIndexToPhysicalPoint( center, worldCenter );
140 switch (m_NormalizationMethod)
144 case SINGLE_VEC_NORM:
149 dirVec = m_InputImage->GetDirection()*dirVec;
151 itk::Point<double> worldStart;
152 worldStart[0] = worldCenter[0]-dirVec[0]/2 * minSpacing;
153 worldStart[1] = worldCenter[1]-dirVec[1]/2 * minSpacing;
154 worldStart[2] = worldCenter[2]-dirVec[2]/2 * minSpacing;
155 vtkIdType
id = m_VtkPoints->InsertNextPoint(worldStart.GetDataPointer());
156 container->GetPointIds()->InsertNextId(
id);
157 itk::Point<double> worldEnd;
158 worldEnd[0] = worldCenter[0]+dirVec[0]/2 * minSpacing;
159 worldEnd[1] = worldCenter[1]+dirVec[1]/2 * minSpacing;
160 worldEnd[2] = worldCenter[2]+dirVec[2]/2 * minSpacing;
161 id = m_VtkPoints->InsertNextPoint(worldEnd.GetDataPointer());
162 container->GetPointIds()->InsertNextId(
id);
163 m_VtkCellArray->InsertNextCell(container);
166 typename ItkDirectionImageType::IndexType index2;
167 index2[0] = a; index2[1] = b; index2[2] = c;
170 dirVec = m_InputImage->GetDirection()*dirVec;
174 Vector< PixelType, 3 > pixel;
175 pixel.SetElement(0, dirVec[0]);
176 pixel.SetElement(1, dirVec[1]);
177 pixel.SetElement(2, dirVec[2]);
179 for (
int j=0; j<numDirs; j++)
182 Vector< PixelType, 3 > tempPix = directionImage->GetPixel(index2);
184 if (tempPix.GetNorm()<0.01)
186 directionImage->SetPixel(index2, pixel);
191 if ( fabs(dot_product(tempPix.GetVnlVector(), pixel.GetVnlVector()))>minangle )
193 minangle = fabs(dot_product(tempPix.GetVnlVector(), pixel.GetVnlVector()));
199 m_NumDirectionsImage->SetPixel(index2, m_NumDirectionsImage->GetPixel(index2)+1);
204 directionsPolyData->SetPoints(m_VtkPoints);
205 directionsPolyData->SetLines(m_VtkCellArray);
211 #endif // __itkMrtrixPeakImageConverter_cpp
itk::SmartPointer< Self > Pointer
void GenerateData() override
MrtrixPeakImageConverter()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.