16 #ifndef __itkShCoefficientImageImporter_cpp
17 #define __itkShCoefficientImageImporter_cpp
24 #include <itkImageRegionIterator.h>
25 #include <boost/math/special_functions.hpp>
31 template<
class PixelType,
int ShOrder >
38 template<
class PixelType,
int ShOrder >
43 if (m_InputImage.IsNull())
46 Vector<float, 4> spacing4 = m_InputImage->GetSpacing();
47 Point<float, 4> origin4 = m_InputImage->GetOrigin();
48 Matrix<double, 4, 4> direction4 = m_InputImage->GetDirection();
49 ImageRegion<4> imageRegion4 = m_InputImage->GetLargestPossibleRegion();
51 Vector<double, 3> spacing3;
52 Point<float, 3> origin3;
53 Matrix<double, 3, 3> direction3;
54 ImageRegion<3> imageRegion3;
56 spacing3[0] = spacing4[0]; spacing3[1] = spacing4[1]; spacing3[2] = spacing4[2];
57 origin3[0] = origin4[0]; origin3[1] = origin4[1]; origin3[2] = origin4[2];
58 for (
int r=0; r<3; r++)
59 for (
int c=0; c<3; c++)
60 direction3[r][c] = direction4[r][c];
61 imageRegion3.SetSize(0, imageRegion4.GetSize()[0]);
62 imageRegion3.SetSize(1, imageRegion4.GetSize()[1]);
63 imageRegion3.SetSize(2, imageRegion4.GetSize()[2]);
66 m_QballImage->SetSpacing( spacing3 );
67 m_QballImage->SetOrigin( origin3 );
68 m_QballImage->SetDirection( direction3 );
69 m_QballImage->SetRegions( imageRegion3 );
70 m_QballImage->Allocate();
71 Vector< PixelType, QBALL_ODFSIZE > nullVec1; nullVec1.Fill(0.0);
72 m_QballImage->FillBuffer(nullVec1);
75 m_CoefficientImage->SetSpacing( spacing3 );
76 m_CoefficientImage->SetOrigin( origin3 );
77 m_CoefficientImage->SetDirection( direction3 );
78 m_CoefficientImage->SetRegions( imageRegion3 );
79 m_CoefficientImage->Allocate();
80 Vector<
PixelType, (ShOrder*ShOrder + ShOrder + 2)/2 + ShOrder > nullVec2; nullVec2.Fill(0.0);
81 m_CoefficientImage->FillBuffer(nullVec2);
83 typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
84 int x = imageRegion4.GetSize(0);
85 int y = imageRegion4.GetSize(1);
86 int z = imageRegion4.GetSize(2);
87 int numCoeffs = imageRegion4.GetSize(3);
89 for (
int a=0; a<x; a++)
90 for (
int b=0; b<y; b++)
91 for (
int c=0; c<z; c++)
93 vnl_matrix<double> coeffs((ShOrder*ShOrder + ShOrder + 2)/2 + ShOrder,1);
95 typename InputImageType::IndexType index;
96 index.SetElement(0,a);
97 index.SetElement(1,b);
98 index.SetElement(2,c);
100 for (
int d=0; d<numCoeffs; d++)
102 index.SetElement(3,d);
103 pix[d] = m_InputImage->GetPixel(index);
104 coeffs[d][0] = pix[d];
106 typename CoefficientImageType::IndexType index2;
107 index2.SetElement(0,a);
108 index2.SetElement(1,b);
109 index2.SetElement(2,c);
110 m_CoefficientImage->SetPixel(index2, pix);
113 vnl_matrix<double> odf = m_ShBasis*coeffs;
117 m_QballImage->SetPixel(index2,pix2);
122 template<
class PixelType,
int ShOrder >
126 vnl_matrix_fixed<double, 2, QBALL_ODFSIZE> sphCoords = GetSphericalOdfDirections();
127 int j, m;
double mag, plm;
132 for (
int l=0; l<=ShOrder; l=l+2)
133 for (m=-l; m<=l; m++)
138 plm = legendre_p<double>(l,abs(m),cos(sphCoords(0,p)));
139 mag = sqrt((
double)(2*l+1)/(4.0*
M_PI)*factorial<double>(l-abs(m))/factorial<double>(l+abs(m)))*plm;
141 m_ShBasis(p,j) = sqrt(2.0)*mag*cos(-m*sphCoords(1,p));
143 m_ShBasis(p,j) = mag;
145 m_ShBasis(p,j) = pow(-1.0, m)*sqrt(2.0)*mag*sin(m*sphCoords(1,p));
148 plm = legendre_p<double>(l,abs(m),-cos(sphCoords(0,p)));
149 mag = sqrt((
double)(2*l+1)/(4.0*
M_PI)*factorial<double>(l-abs(m))/factorial<double>(l+abs(m)))*plm;
151 m_ShBasis(p,j) = mag*cos(m*sphCoords(1,p));
153 m_ShBasis(p,j) = mag;
155 m_ShBasis(p,j) = mag*sin(-m*sphCoords(1,p));
165 template<
class PixelType,
int ShOrder >
170 vnl_matrix_fixed<double, 3, QBALL_ODFSIZE>* dir = odf.
GetDirections();
171 vnl_matrix_fixed<double, 2, QBALL_ODFSIZE> sphCoords;
175 double mag = dir->get_column(i).magnitude();
179 sphCoords(0,i) =
M_PI/2;
180 sphCoords(1,i) =
M_PI/2;
184 sphCoords(0,i) = acos(dir->get(2,i)/mag);
185 sphCoords(1,i) = atan2(dir->get(1,i), dir->get(0,i));
193 #endif // __itkShCoefficientImageImporter_cpp
vnl_matrix< double > m_ShBasis
static DirectionsType * GetDirections()
Represents an ODF for Q-Ball imaging.
void GenerateData() override
MITKCORE_EXPORT const ScalarType eps
vnl_matrix_fixed< double, 2, QBALL_ODFSIZE > GetSphericalOdfDirections()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.