ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkKernelTransform.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkKernelTransform_h
19 #define __itkKernelTransform_h
20 
21 #include "itkTransform.h"
22 #include "itkMatrix.h"
23 #include "itkPointSet.h"
24 #include <deque>
25 #include <cmath>
26 #include "vnl/vnl_matrix_fixed.h"
27 #include "vnl/vnl_matrix.h"
28 #include "vnl/vnl_vector.h"
29 #include "vnl/vnl_vector_fixed.h"
30 #include "vnl/algo/vnl_svd.h"
31 #include "vnl/vnl_sample.h"
32 
33 namespace itk
34 {
60 template <class TScalarType, // probably only float and double make sense here
61  unsigned int NDimensions>
62 // Number of dimensions
63 class ITK_EXPORT KernelTransform :
64  public Transform<TScalarType, NDimensions, NDimensions>
65 {
66 public:
72 
74  itkTypeMacro(KernelTransform, Transform);
75 
77  itkNewMacro(Self);
78 
80  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
81 
83  typedef typename Superclass::ScalarType ScalarType;
84 
86  typedef typename Superclass::ParametersType ParametersType;
87 
89  typedef typename Superclass::JacobianType JacobianType;
90 
92  typedef typename Superclass::TransformCategoryType TransformCategoryType;
93 
95  typedef typename Superclass::InputPointType InputPointType;
96  typedef typename Superclass::OutputPointType OutputPointType;
97 
99  typedef typename Superclass::InputVectorType InputVectorType;
100  typedef typename Superclass::OutputVectorType OutputVectorType;
101 
103  typedef typename Superclass::InputCovariantVectorType InputCovariantVectorType;
104  typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;
105 
107  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
108  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
109 
114 
120 
124 
126  itkGetObjectMacro(SourceLandmarks, PointSetType);
127 
129  virtual void SetSourceLandmarks(PointSetType *);
130 
132  itkGetObjectMacro(TargetLandmarks, PointSetType);
133 
135  virtual void SetTargetLandmarks(PointSetType *);
136 
139  itkGetObjectMacro(Displacements, VectorSetType);
140 
142  void ComputeWMatrix(void);
143 
145  virtual OutputPointType TransformPoint(const InputPointType & thisPoint) const;
146 
148  using Superclass::TransformVector;
149  virtual OutputVectorType TransformVector(const InputVectorType &) const \
150  { \
151  itkExceptionMacro( \
152  << "TransformVector(const InputVectorType &) is not implemented for KernelTransform"); \
153  }
155 
156  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const \
157  { \
158  itkExceptionMacro( \
159  << "TransformVector(const InputVnlVectorType &) is not implemented for KernelTransform"); \
160  }
161 
163  using Superclass::TransformCovariantVector;
164  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const \
165  { \
166  itkExceptionMacro( \
167  << "TransformCovariantVector(const InputCovariantVectorType &) is not implemented for KernelTransform"); \
168  }
170 
172  typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> IMatrixType;
173 
175  virtual void ComputeJacobianWithRespectToParameters( const InputPointType & p, JacobianType & jacobian) const;
176 
177  virtual void ComputeJacobianWithRespectToPosition(const InputPointType &,
178  JacobianType &) const \
179  { \
180  itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented " \
181  "for " << this->GetNameOfClass() ); \
182  }
183 
188  virtual void SetParameters(const ParametersType &);
189 
195  virtual void SetFixedParameters(const ParametersType &);
196 
198  virtual void UpdateParameters(void) const;
199 
201  virtual const ParametersType & GetParameters(void) const;
202 
204  virtual const ParametersType & GetFixedParameters(void) const;
205 
209  virtual TransformCategoryType GetTransformCategory() const
210  {
211  return Self::Spline;
212  }
213 
224  itkSetClampMacro( Stiffness, double, 0.0, NumericTraits<double>::max() );
225  itkGetConstMacro(Stiffness, double);
227 
228 protected:
229  KernelTransform();
230  virtual ~KernelTransform();
231  void PrintSelf(std::ostream & os, Indent indent) const;
232 
233 public:
235  typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> GMatrixType;
236 
239 
242 
245 
248 
251 
254 
256  typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> AMatrixType;
257 
259  typedef vnl_vector_fixed<TScalarType, NDimensions> BMatrixType;
260 
262  typedef vnl_matrix_fixed<TScalarType, 1, NDimensions> RowMatrixType;
263 
265  typedef vnl_matrix_fixed<TScalarType, NDimensions, 1> ColumnMatrixType;
266 
267 protected:
274  virtual void ComputeG(const InputVectorType & landmarkVector, GMatrixType & gmatrix) const;
275 
285  virtual const GMatrixType & ComputeReflexiveG(PointsIterator) const;
286 
289  virtual void ComputeDeformationContribution(const InputPointType & inputPoint, OutputPointType & result) const;
290 
292  void ComputeK();
293 
295  void ComputeL();
296 
298  void ComputeP();
299 
301  void ComputeY();
302 
304  void ComputeD();
305 
310  void ReorganizeW(void);
311 
313  double m_Stiffness;
314 
318 
321 
324 
327 
330 
333 
340 
343 
346 
351 
354 
357 
360 
363 
364 private:
365 
366  KernelTransform(const Self &); // purposely not implemented
367  void operator=(const Self &); // purposely not implemented
368 
369 };
370 } // end namespace itk
371 
372 #ifndef ITK_MANUAL_INSTANTIATION
373 #include "itkKernelTransform.hxx"
374 #endif
375 
376 #endif // __itkKernelTransform_h
377