38 #ifndef __ItkInterpolatingStatisticalDeformationModelTransform
39 #define __ItkInterpolatingStatisticalDeformationModelTransform
44 #include <itkVector.h>
45 #include <itkVectorLinearInterpolateImageFunction.h>
47 #include "itkStandardImageRepresenter.h"
48 #include "itkStatisticalModel.h"
49 #include "itkStatisticalModelTransformBase.h"
51 #include "Representer.h"
65 template <
class TDataset,
class TScalarType,
unsigned int TDimension >
73 typedef SmartPointer<Self> Pointer;
74 typedef SmartPointer<const Self> ConstPointer;
77 itkSimpleNewMacro(
Self );
84 typedef typename Superclass::InputPointType InputPointType;
85 typedef typename Superclass::OutputPointType OutputPointType;
86 typedef typename Superclass::RepresenterType RepresenterType;
88 typedef typename Superclass::JacobianType JacobianType;
91 typedef typename RepresenterType::DatasetType DeformationFieldType;
92 typedef VectorLinearInterpolateImageFunction<DeformationFieldType, TScalarType> InterpolatorType;
98 ::itk::LightObject::Pointer smartPtr;
99 Pointer another = Self::New().GetPointer();
100 this->CopyBaseMembers(another);
101 another->m_meanDeformation = this->m_meanDeformation;
102 another->m_PCABasisDeformations = this->m_PCABasisDeformations;
103 smartPtr =
static_cast<Pointer
>(another);
108 this->Superclass::SetStatisticalModel(model);
110 m_meanDeformation = InterpolatorType::New();
111 typename DeformationFieldType::Pointer meanDf = model->DrawMean();
112 m_meanDeformation->SetInputImage(meanDf);
113 for (
unsigned i = 0; i < model->GetNumberOfPrincipalComponents(); i++) {
114 typename DeformationFieldType::Pointer deformationField = model->DrawPCABasisSample(i);
115 typename InterpolatorType::Pointer basisI = InterpolatorType::New();
116 basisI->SetInputImage(deformationField);
117 m_PCABasisDeformations.push_back(basisI);
123 void ComputeJacobianWithRespectToParameters(
const InputPointType &pt, JacobianType &jacobian)
const {
124 jacobian.SetSize(TDimension, m_PCABasisDeformations.size());
126 if (m_meanDeformation->IsInsideBuffer(pt) ==
false)
129 for(
unsigned j = 0; j < m_PCABasisDeformations.size(); j++) {
130 typename RepresenterType::ValueType d = m_PCABasisDeformations[j]->Evaluate(pt);
131 for(
unsigned i = 0; i < TDimension; i++) {
132 jacobian(i,j) += d[i] ;
136 itkDebugMacro( <<
"Jacobian with MM:\n" << jacobian);
137 itkDebugMacro( <<
"After GetMorphableModelJacobian:"
138 <<
"\nJacobian = \n" << jacobian);
150 if (m_meanDeformation->IsInsideBuffer(pt) ==
false) {
153 assert(this->m_coeff_vector.size() == m_PCABasisDeformations.size());
154 typename RepresenterType::ValueType def = m_meanDeformation->Evaluate(pt);
156 for (
unsigned i = 0; i < m_PCABasisDeformations.size(); i++) {
157 typename RepresenterType::ValueType defBasisI = m_PCABasisDeformations[i]->Evaluate(pt);
158 def += (defBasisI * this->m_coeff_vector[i]);
161 OutputPointType transformedPoint;
162 for (
unsigned i = 0; i < pt.GetPointDimension(); i++) {
163 transformedPoint[i] = pt[i] + def[i];
166 return transformedPoint;
171 InterpolatingStatisticalDeformationModelTransform() {}
176 InterpolatingStatisticalDeformationModelTransform(
const InterpolatingStatisticalDeformationModelTransform& orig);
177 InterpolatingStatisticalDeformationModelTransform& operator=(
const InterpolatingStatisticalDeformationModelTransform& rhs);
180 typename InterpolatorType::Pointer m_meanDeformation;
181 std::vector<typename InterpolatorType::Pointer> m_PCABasisDeformations;
187 #endif // __ItkInterpolatingStatisticalDeformationModelTransform
ITK Wrapper for the statismo::StatisticalModel class.
Definition: itkStatisticalModel.h:62