2 #include <itkSymmetricEigenAnalysis.h> 5 #include <vtkDoubleArray.h> 6 #include <vtkPointData.h> 14 m_StopFAThreshold = 0.1;
15 m_StopADCThreshold = 2.0e-3;
26 m_DTIInterpolator = DTIInterpolatorType::New();
32 typedef vnl_matrix <double> MatrixType;
34 itk::SymmetricEigenAnalysis <MatrixType,vnl_diag_matrix <double>,MatrixType> EigenAnalysis(3);
35 MatrixType tmpMat(3,3);
39 vnl_diag_matrix <double> eVals(3);
40 EigenAnalysis.ComputeEigenValues(tmpMat,eVals);
43 for (
unsigned int i = 0;i < 3;++i)
45 eVals[i] = std::exp(eVals[i]);
46 meanEvals += eVals[i];
51 if (meanEvals > m_StopADCThreshold)
56 for (
unsigned int i = 0;i < 3;++i)
58 num += (eVals[i] - meanEvals) * (eVals[i] - meanEvals);
59 denom += eVals[i] * eVals[i];
62 double FAValue = std::sqrt(3.0 * num / (2.0 * denom));
64 if (FAValue < m_StopFAThreshold)
72 return m_DTIInterpolator->IsInsideBuffer(index);
78 modelValue = m_DTIInterpolator->EvaluateAtContinuousIndex(index);
84 typedef vnl_matrix <double> MatrixType;
86 itk::SymmetricEigenAnalysis <MatrixType,vnl_diag_matrix <double>,MatrixType> EigenAnalysis(3);
88 MatrixType tmpMat(3,3);
89 vnl_diag_matrix <double> eVals(3);
94 EigenAnalysis.ComputeEigenValuesAndVectors(tmpMat,eVals,eVec);
98 for (
unsigned int i = 0;i < 3;++i)
99 resDir[i] = eVec(2,i);
106 for (
unsigned int i = 0;i < 2;++i)
107 norm += resDir[i] * resDir[i];
108 norm = std::sqrt(norm);
110 for (
unsigned int i = 0;i < 2;++i)
119 itk::ThreadIdType threadId)
125 typedef vnl_matrix <double> MatrixType;
126 MatrixType tmpMat(3,3);
130 vnl_diag_matrix <double> eVals(3);
131 itk::SymmetricEigenAnalysis <MatrixType,vnl_diag_matrix <double>,MatrixType> EigenAnalysis(3);
132 MatrixType eVecs(3,3);
133 EigenAnalysis.ComputeEigenValuesAndVectors(tmpMat,eVals, eVecs);
135 double sumEigs = 0.0;
136 for (
unsigned int i = 0;i < 3;++i)
138 eVals[i] = std::exp(eVals[i]);
147 for (
unsigned int i = 0;i < 3;++i)
149 advectedDirection[i] = 0.0;
150 for (
unsigned int j = 0;j < 3;++j)
151 advectedDirection[i] += tmpMat(i,j) * previousDirection[j];
158 double linearCoefficient = (eVals[2] - eVals[0]) / sumEigs;
160 for (
unsigned int i = 0;i < 3;++i)
161 newDirection[i] = newDirection[i] * linearCoefficient + (1.0 - linearCoefficient) * ((1.0 - this->
GetPunctureWeight()) * previousDirection[i] + this->
GetPunctureWeight() * advectedDirection[i]);
171 vtkSmartPointer <vtkPolyData> outputPtr = this->
GetOutput();
173 unsigned int numPoints = outputPtr->GetPoints()->GetNumberOfPoints();
174 vtkPoints *myPoints = outputPtr->GetPoints();
176 vtkSmartPointer <vtkDoubleArray> faArray = vtkDoubleArray::New();
177 faArray->SetNumberOfComponents(1);
178 faArray->SetName(
"FA");
180 vtkSmartPointer <vtkDoubleArray> adcArray = vtkDoubleArray::New();
181 adcArray->SetNumberOfComponents(1);
182 adcArray->SetName(
"ADC");
185 DTIInterpolatorType::ContinuousIndexType tmpIndex;
187 typedef vnl_matrix <double> MatrixType;
188 MatrixType tmpMat(3,3);
190 vnl_diag_matrix <double> eVals(3);
191 itk::SymmetricEigenAnalysis <MatrixType,vnl_diag_matrix <double>,MatrixType> EigenAnalysis(3);
196 for (
unsigned int i = 0;i < numPoints;++i)
198 for (
unsigned int j = 0;j < 3;++j)
199 tmpPoint[j] = myPoints->GetPoint(i)[j];
201 this->
GetInputImage()->TransformPhysicalPointToContinuousIndex(tmpPoint,tmpIndex);
202 tensorValue.Fill(0.0);
203 if (m_DTIInterpolator->IsInsideBuffer(tmpIndex))
210 for (
unsigned int j = 0;j < 3;++j)
211 adcValue += tmpMat(j,j);
213 adcArray->InsertNextValue(adcValue / 3.0);
216 double faValueDenom = 0;
217 EigenAnalysis.ComputeEigenValues(tmpMat,eVals);
218 for (
unsigned int j = 0;j < 3;++j)
220 faValueDenom += eVals[j] * eVals[j];
221 for (
unsigned int k = j + 1;k < 3;++k)
222 faValue += (eVals[j] - eVals[k]) * (eVals[j] - eVals[k]);
225 faValue = std::sqrt(faValue / (2.0 * faValueDenom));
226 faArray->InsertNextValue(faValue);
229 outputPtr->GetPointData()->AddArray(faArray);
230 outputPtr->GetPointData()->AddArray(adcArray);
void Revert(const VectorType &v, const unsigned int vSize, VectorType &resVec)
virtual PointType GetModelPrincipalDirection(VectorType &modelValue, bool is2d, itk::ThreadIdType threadId) ITK_OVERRIDE
virtual PointType GetNextDirection(PointType &previousDirection, VectorType &modelValue, bool is2d, itk::ThreadIdType threadId) ITK_OVERRIDE
virtual ~dtiTractographyImageFilter()
virtual bool CheckModelCompatibility(VectorType &modelValue, itk::ThreadIdType threadId) ITK_OVERRIDE
virtual void SetInputImage(ModelImageType *input)
virtual double GetPunctureWeight()
virtual void SetInputImage(ModelImageType *input) ITK_OVERRIDE
vtkPolyData * GetOutput()
virtual bool CheckIndexInImageBounds(ContinuousIndexType &index) ITK_OVERRIDE
itk::SmartPointer< Self > Pointer
MaskImageType::PointType PointType
void GetTensorExponential(const vnl_matrix< TScalarType > &tensor, vnl_matrix< TScalarType > &log_tensor)
virtual void ComputeAdditionalScalarMaps() ITK_OVERRIDE
itk::ContinuousIndex< double, 3 > ContinuousIndexType
void GetTensorFromVectorRepresentation(const itk::VariableLengthVector< T1 > &vector, vnl_matrix< T2 > &tensor, unsigned int tensDim=0, bool scale=false)
dtiTractographyImageFilter()
virtual void GetModelValue(ContinuousIndexType &index, VectorType &modelValue) ITK_OVERRIDE
Computes value of model from data. May use SNR and previous model value to perform smart interpolatio...
ModelImageType::PixelType VectorType
void RecomposeTensor(vnl_diag_matrix< T1 > &eigs, vnl_matrix< T1 > &eigVecs, vnl_matrix< T2 > &resMatrix)
Recompose tensor from values extracted using SymmetricEigenAnalysis (vnl_symmetric_eigensystem transp...
void Normalize(const VectorType &v, const unsigned int NDimension, VectorType &resVec)
double ComputeScalarProduct(const VectorType &v1, const VectorType &v2, const unsigned int NDimension)
Superclass::PointType PointType
ModelImageType * GetInputImage()
itk::VectorImage< double, 3 > ModelImageType