18 #ifndef __itkCylinderModelGenerator_hxx 19 #define __itkCylinderModelGenerator_hxx 27 template <
class PreciseType>
39 m_CylinderAxis[2]=1.0;
42 m_LUTExp->SetVariableMax(0);
43 m_LUTExp->SetVariableMin(-30);
44 m_LUTExp->SetNumberOfBins(30*1e3);
48 template <
class PreciseType>
49 typename LightObject::Pointer
53 typename LightObject::Pointer loPtr = Superclass::InternalClone();
58 itkExceptionMacro(<<
"downcast to type " << this->GetNameOfClass()<<
" failed.");
61 rval->m_Length = m_Length;
62 rval->m_Radius = m_Radius;
64 rval->m_CylinderAxis = m_CylinderAxis;
65 rval->m_LUTExp = m_LUTExp->Clone();
70 template <
class PreciseType>
75 m_LUTExp->BuildTable();
78 template <
class PreciseType>
83 Superclass::PrintSelf(os, indent);
84 PrintVar3(
true, m_Length, m_Radius, m_D0, os<<indent);
85 os << indent <<
"m_CylinderAxis = " << m_CylinderAxis << std::endl;
95 template <
class PreciseType>
100 VectorType axis = m_CylinderAxis.GetVnlVector();
102 for (
int i = 0; i < 3; i += 1 )
103 m_CylinderAxis[i] = axis[i];
106 template <
class PreciseType>
112 this->VerifyInputParameters();
113 utlGlobalException(this->m_SamplingSchemeQSpace->GetNumberOfSamples()==0,
"need to set m_SamplingSchemeQSpace");
116 const int nMax = 1000, mMax = 10, kMax = 10;
117 int N = this->m_SamplingSchemeQSpace->GetNumberOfSamples();
120 double deltaBig = this->m_SamplingSchemeQSpace->GetDeltaBig();
121 double d0DeltaBig = m_D0*deltaBig;
122 double radius2 = m_Radius*m_Radius;
124 std::vector<double> nPiLength2(nMax+1);
125 std::vector<double> nPiLength2D0Delta(nMax+1);
126 for (
int n = 0; n <= nMax; n += 1 )
128 nPiLength2[n] = std::pow(n*
M_PI/m_Length,2);
129 nPiLength2D0Delta[n] = d0DeltaBig *nPiLength2[n];
138 #pragma omp parallel for private (i) 142 PointType sample = (*this->m_SamplingSchemeQSpace)[i];
143 double dott = sample[0]*m_CylinderAxis[0] + sample[1]*m_CylinderAxis[1] + sample[2]*m_CylinderAxis[2];
144 double angle = std::acos( dott>=1?1:(dott<=-1?-1:dott) );
146 angle =
M_PI - angle;
147 if (
M_PI/2-angle<1.0e-5)
148 angle =
M_PI/2 - 1.0e-5;
151 double angle2sin = std::sin(2*angle);
153 double signal_temp=0;
154 double qq = (*qVector)[i];
155 double pi2qcos = 2.0*
M_PI*qq*std::cos(angle);
156 double pi2qsin = 2.0*
M_PI*qq*std::sin(angle);
157 double pi2qsinRadius = pi2qsin*m_Radius;
158 double pi2qcosLengthcos = std::cos(pi2qcos*m_Length);
159 double first_temp = 2.0*std::pow(m_Radius,2) *std::pow(2*
M_PI*qq,4)*angle2sin*angle2sin / (m_Length*m_Length);
161 for (
int n = 0; n <= nMax; n += 1 )
163 double num2 = (n%2 ? (1+pi2qcosLengthcos) : (1-pi2qcosLengthcos));
164 double tmp1 = std::pow( nPiLength2[n] - std::pow(pi2qcos,2), 2 );
165 for (
int m = 0; m <= mMax; m += 1 )
168 double K_mn = m>0? (n>0?4:2) : (n>0?2:1);
169 third_temp(m,n) = num2 *K_mn / tmp1;
173 std::vector<double> besselJnVec(mMax+2);
174 for (
int m = 0; m <= mMax; m += 1 )
175 besselJnVec[m] = gsl_sf_bessel_Jn(m,pi2qsinRadius);
177 for (
int m = 0; m <=mMax; m += 1 )
179 double J_m_d = m/(pi2qsinRadius)*besselJnVec[m] - besselJnVec[m+1];
180 double J_m_d2 = J_m_d*J_m_d;
181 for (
int k = 1; k <=kMax; k += 1 )
184 double gamma_km2 = gamma_km * gamma_km;
186 double gamma_km_Radius2_D0Delta = gamma_km2/radius2 * d0DeltaBig;
187 double second_temp = J_m_d2 / std::pow(gamma_km2-std::pow(pi2qsinRadius,2) ,2) ;
189 second_temp *= gamma_km2 / (gamma_km2-m*m);
190 for (
int n = 0; n <=nMax; n += 1 )
194 double fourth_temp = m_LUTExp->GetFunctionValue( - (gamma_km_Radius2_D0Delta+nPiLength2D0Delta[n]));
197 signal_temp += first_temp*second_temp*third_temp(m,n)*fourth_temp;
201 (*this->m_DWISamples)[i] = signal_temp;
202 if (this->GetDebug())
204 std::cout <<
"i = " << i << std::endl << std::flush;
205 std::cout <<
"sample = " << sample << std::endl << std::flush;
206 std::cout <<
"qq = " << qq << std::endl << std::flush;
207 std::cout <<
"signal_temp = " << signal_temp << std::endl << std::flush;
212 template <
class PreciseType>
217 this->VerifyInputParameters();
218 utlGlobalException(this->m_SamplingSchemeRSpace->GetNumberOfSamples()==0,
"need to set m_SamplingSchemeRSpace");
222 template <
class PreciseType>
227 this->VerifyInputParameters();
228 utlGlobalException(this->m_SamplingSchemeRSpace->GetNumberOfSamples()==0,
"need to set m_SamplingSchemeRSpace");
LightObject::Pointer InternalClone() const
generate ground truth DWI/EAP/ODF ets from a given model
Superclass::PointType PointType
Superclass::STDVectorPointer STDVectorPointer
static const double BesselJPrimeZerosTable[]
#define utlGlobalException(cond, expout)
Superclass::VectorPointer VectorPointer
void PrintSelf(std::ostream &os, Indent indent) const
#define PrintVar3(cond, var1, var2, var3, os)
#define utlShowPosition(cond)
Superclass::MatrixType MatrixType
SmartPointer< Self > Pointer
Superclass::VectorType VectorType
void Rotate(const MatrixType &mat)