Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
itkInterpolatingStatisticalDeformationModelTransform.h
1 /*
2  * This file is part of the statismo library.
3  *
4  * Author: Marcel Luethi (marcel.luethi@unibas.ch)
5  *
6  * Copyright (c) 2011 University of Basel
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * Neither the name of the project's author nor the names of its
21  * contributors may be used to endorse or promote products derived from
22  * this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef __ItkInterpolatingStatisticalDeformationModelTransform
39 #define __ItkInterpolatingStatisticalDeformationModelTransform
40 
41 #include <iostream>
42 
43 #include <itkImage.h>
44 #include <itkVector.h>
45 #include <itkVectorLinearInterpolateImageFunction.h>
46 
47 #include "itkStandardImageRepresenter.h"
48 #include "itkStatisticalModel.h"
49 #include "itkStatisticalModelTransformBase.h"
50 
51 #include "Representer.h"
52 
53 namespace itk {
54 
65 template <class TDataset, class TScalarType, unsigned int TDimension >
67  public itk::StatisticalModelTransformBase< TDataset, TScalarType , TDimension> {
68  public:
69 
70  /* Standard class typedefs. */
73  typedef SmartPointer<Self> Pointer;
74  typedef SmartPointer<const Self> ConstPointer;
75 
76 
77  itkSimpleNewMacro( Self );
78 
79 
82 
83 
84  typedef typename Superclass::InputPointType InputPointType;
85  typedef typename Superclass::OutputPointType OutputPointType;
86  typedef typename Superclass::RepresenterType RepresenterType;
88  typedef typename Superclass::JacobianType JacobianType;
89 
90 
91  typedef typename RepresenterType::DatasetType DeformationFieldType;
92  typedef VectorLinearInterpolateImageFunction<DeformationFieldType, TScalarType> InterpolatorType;
93 
97  virtual ::itk::LightObject::Pointer CreateAnother() const {
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);
104  return smartPtr;
105  }
106 
107  virtual void SetStatisticalModel(const StatisticalModelType* model) {
108  this->Superclass::SetStatisticalModel(model);
109 
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);
118  }
119  }
120 
121 
122 
123  void ComputeJacobianWithRespectToParameters(const InputPointType &pt, JacobianType &jacobian) const {
124  jacobian.SetSize(TDimension, m_PCABasisDeformations.size());
125  jacobian.Fill(0);
126  if (m_meanDeformation->IsInsideBuffer(pt) == false)
127  return;
128 
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] ;
133  }
134  }
135 
136  itkDebugMacro( << "Jacobian with MM:\n" << jacobian);
137  itkDebugMacro( << "After GetMorphableModelJacobian:"
138  << "\nJacobian = \n" << jacobian);
139  }
140 
141 
149  virtual OutputPointType TransformPoint(const InputPointType &pt) const {
150  if (m_meanDeformation->IsInsideBuffer(pt) == false) {
151  return pt;
152  }
153  assert(this->m_coeff_vector.size() == m_PCABasisDeformations.size());
154  typename RepresenterType::ValueType def = m_meanDeformation->Evaluate(pt);
155 
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]);
159  }
160 
161  OutputPointType transformedPoint;
162  for (unsigned i = 0; i < pt.GetPointDimension(); i++) {
163  transformedPoint[i] = pt[i] + def[i];
164  }
165 
166  return transformedPoint;
167  }
168 
170 
171  InterpolatingStatisticalDeformationModelTransform() {}
172 
173  private:
174 
175 
176  InterpolatingStatisticalDeformationModelTransform(const InterpolatingStatisticalDeformationModelTransform& orig); // purposely not implemented
177  InterpolatingStatisticalDeformationModelTransform& operator=(const InterpolatingStatisticalDeformationModelTransform& rhs); //purposely not implemented
178 
179 
180  typename InterpolatorType::Pointer m_meanDeformation;
181  std::vector<typename InterpolatorType::Pointer> m_PCABasisDeformations;
182 };
183 
184 
185 } // namespace itk
186 
187 #endif // __ItkInterpolatingStatisticalDeformationModelTransform
virtual ::itk::LightObject::Pointer CreateAnother() const
Definition: itkInterpolatingStatisticalDeformationModelTransform.h:97
Base class that implements an itk transform interface for statistical models.
Definition: itkStatisticalModelTransformBase.h:66
An itk transform that allows for deformations defined by a given Statistical Deformation Model...
Definition: itkInterpolatingStatisticalDeformationModelTransform.h:66
virtual OutputPointType TransformPoint(const InputPointType &pt) const
Definition: itkInterpolatingStatisticalDeformationModelTransform.h:149
ITK Wrapper for the statismo::StatisticalModel class.
Definition: itkStatisticalModel.h:62