Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
itkStatisticalModelTransformBase.hxx
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 __itkStatisticalModelTransformBase_hxx
39 #define __itkStatisticalModelTransformBase_hxx
40 
41 #include "itkStatisticalModelTransformBase.h"
42 
43 
44 namespace itk {
45 
49 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
52  Superclass(0), // we don't know the number of parameters at this point.
53  m_StatisticalModel(0),
54  m_coeff_vector(0),
55  m_usedNumberCoefficients(10000) { // something large
56  itkDebugMacro( << "Constructor MorphableModelTransform()");
57 
58  this->m_FixedParameters.SetSize(0);
59 }
60 
61 
62 
66 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
67 void
70  itkDebugMacro( << "Setting statistical model ");
71  m_StatisticalModel = model;
72 
73 
74  this->m_Parameters.SetSize(model->GetNumberOfPrincipalComponents());
75  this->m_Parameters.Fill(0.0);
76 
77  this->m_coeff_vector.set_size(model->GetNumberOfPrincipalComponents());
78 
79 }
80 
81 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
82 typename StatisticalModelTransformBase<TRepresenter, TScalarType, TInputDimension, TOutputDimension>::StatisticalModelType::ConstPointer
85  itkDebugMacro( << "Getting statistical model ");
86  return m_StatisticalModel;
87 }
88 
89 
93 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
94 void
97  itkDebugMacro( << "Setting Identity");
98 
99  for (unsigned i = 0; i < this->GetNumberOfParameters(); i++)
100  this->m_coeff_vector[i] = 0;
101 
102 
103  this->Modified();
104 }
105 
106 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
107 void
109 ::SetParameters( const ParametersType & parameters ) {
110  itkDebugMacro( << "Setting parameters " << parameters );
111 
112  // Set angle
113  for(unsigned int i=0; i < std::min(m_usedNumberCoefficients, (unsigned) this->GetNumberOfParameters()); i++) {
114  m_coeff_vector[i] = parameters[i];
115  }
116  for (unsigned int i = std::min(m_usedNumberCoefficients, (unsigned) this->GetNumberOfParameters()); i < this->GetNumberOfParameters(); i++) {
117  m_coeff_vector[i] = 0;
118  }
119 
120  // Modified is always called since we just have a pointer to the
121  // parameters and cannot know if the parameters have changed.
122  this->Modified();
123 
124  itkDebugMacro(<<"After setting parameters ");
125 }
126 
127 
128 
129 
130 
131 // Get Parameters
132 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
133 const typename StatisticalModelTransformBase<TRepresenter, TScalarType, TInputDimension, TOutputDimension>::ParametersType &
135 ::GetParameters( void ) const {
136  itkDebugMacro( << "Getting parameters ");
137 
138 
139  // Get the translation
140  for(unsigned int i=0; i < this->GetNumberOfParameters(); i++) {
141  this->m_Parameters[i] = this->m_coeff_vector[i];
142  }
143  itkDebugMacro(<<"After getting parameters " << this->m_Parameters );
144 
145  return this->m_Parameters;
146 }
147 
148 
149 
150 
151 
152 
153 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
154 void
156 ::ComputeJacobianWithRespectToParameters(const InputPointType &pt, JacobianType &jacobian) const {
157  jacobian.SetSize(OutputSpaceDimension, m_StatisticalModel->GetNumberOfPrincipalComponents());
158  jacobian.Fill(0);
159 
160  const MatrixType& statModelJacobian = m_StatisticalModel->GetJacobian(pt);
161 
162  for (unsigned i = 0; i < statModelJacobian.rows(); i++) {
163  for (unsigned j = 0; j < std::min(m_usedNumberCoefficients, (unsigned) this->GetNumberOfParameters()); j++) {
164  jacobian[i][j] = statModelJacobian[i][j];
165  }
166  }
167 
168 
169  itkDebugMacro( << "Jacobian with MM:\n" << jacobian);
170  itkDebugMacro( << "After GetMorphableModelJacobian:"
171  << "\nJacobian = \n" << jacobian);
172 }
173 
174 
175 
176 // Print self
177 template <class TRepresenter, class TScalarType, unsigned int TInputDimension, unsigned int TOutputDimension >
178 void
179 StatisticalModelTransformBase<TRepresenter, TScalarType, TInputDimension, TOutputDimension>::
180 PrintSelf(std::ostream &os, Indent indent) const {
181  Superclass::PrintSelf(os,indent);
182 }
183 
184 } // namespace
185 
186 #endif
StatisticalModelType::ConstPointer GetStatisticalModel() const
Definition: itkStatisticalModelTransformBase.hxx:84
virtual const ParametersType & GetParameters(void) const
Definition: itkStatisticalModelTransformBase.hxx:135
StatisticalModelTransformBase()
Definition: itkStatisticalModelTransformBase.hxx:51
virtual void SetIdentity(void)
Definition: itkStatisticalModelTransformBase.hxx:96
Base class that implements an itk transform interface for statistical models.
Definition: itkStatisticalModelTransformBase.h:66
virtual void SetParameters(const ParametersType &)
Definition: itkStatisticalModelTransformBase.hxx:109
void SetStatisticalModel(const StatisticalModelType *model)
Definition: itkStatisticalModelTransformBase.hxx:69
ITK Wrapper for the statismo::StatisticalModel class.
Definition: itkStatisticalModel.h:62