ITK  4.2.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 <math.h>
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::InputPointType InputPointType;
93  typedef typename Superclass::OutputPointType OutputPointType;
94 
96  typedef typename Superclass::InputVectorType InputVectorType;
97  typedef typename Superclass::OutputVectorType OutputVectorType;
98 
100  typedef typename Superclass::InputCovariantVectorType InputCovariantVectorType;
101  typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;
102 
104  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
105  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
106 
111 
117 
121 
123  itkGetObjectMacro(SourceLandmarks, PointSetType);
124 
126  virtual void SetSourceLandmarks(PointSetType *);
127 
129  itkGetObjectMacro(TargetLandmarks, PointSetType);
130 
132  virtual void SetTargetLandmarks(PointSetType *);
133 
136  itkGetObjectMacro(Displacements, VectorSetType);
137 
139  void ComputeWMatrix(void);
140 
142  virtual OutputPointType TransformPoint(const InputPointType & thisPoint) const;
143 
145  using Superclass::TransformVector;
146  virtual OutputVectorType TransformVector(const InputVectorType &) const \
147  { \
148  itkExceptionMacro( \
149  << "TransformVector(const InputVectorType &) is not implemented for KernelTransform"); \
150  }
152 
153  virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const \
154  { \
155  itkExceptionMacro( \
156  << "TransformVector(const InputVnlVectorType &) is not implemented for KernelTransform"); \
157  }
158 
160  using Superclass::TransformCovariantVector;
161  virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const \
162  { \
163  itkExceptionMacro( \
164  << "TransformCovariantVector(const InputCovariantVectorType &) is not implemented for KernelTransform"); \
165  }
167 
169  typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> IMatrixType;
170 
172  virtual void ComputeJacobianWithRespectToParameters( const InputPointType & p, JacobianType & jacobian) const;
173 
174  virtual void ComputeJacobianWithRespectToPosition(const InputPointType &,
175  JacobianType &) const \
176  { \
177  itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented " \
178  "for " << this->GetNameOfClass() ); \
179  }
180 
185  virtual void SetParameters(const ParametersType &);
186 
192  virtual void SetFixedParameters(const ParametersType &);
193 
195  virtual void UpdateParameters(void) const;
196 
198  virtual const ParametersType & GetParameters(void) const;
199 
201  virtual const ParametersType & GetFixedParameters(void) const;
202 
206  virtual bool IsLinear() const
207  {
208  return false;
209  }
210 
221  itkSetClampMacro( Stiffness, double, 0.0, NumericTraits<double>::max() );
222  itkGetConstMacro(Stiffness, double);
223 protected:
224  KernelTransform();
225  virtual ~KernelTransform();
226  void PrintSelf(std::ostream & os, Indent indent) const;
228 
229 public:
231  typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> GMatrixType;
232 
235 
238 
241 
244 
247 
250 
252  typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> AMatrixType;
253 
255  typedef vnl_vector_fixed<TScalarType, NDimensions> BMatrixType;
256 
258  typedef vnl_matrix_fixed<TScalarType, 1, NDimensions> RowMatrixType;
259 
261  typedef vnl_matrix_fixed<TScalarType, NDimensions, 1> ColumnMatrixType;
262 protected:
263 
270  virtual void ComputeG(const InputVectorType & landmarkVector, GMatrixType & gmatrix) const;
271 
281  virtual const GMatrixType & ComputeReflexiveG(PointsIterator) const;
282 
285  virtual void ComputeDeformationContribution(const InputPointType & inputPoint, OutputPointType & result) const;
286 
288  void ComputeK();
289 
291  void ComputeL();
292 
294  void ComputeP();
295 
297  void ComputeY();
298 
300  void ComputeD();
301 
306  void ReorganizeW(void);
307 
309  double m_Stiffness;
310 
314 
317 
320 
323 
326 
329 
336 
339 
342 
347 
350 
353 
356 
359 private:
360 
361  KernelTransform(const Self &); // purposely not implemented
362  void operator=(const Self &); // purposely not implemented
363 
364 };
365 } // end namespace itk
366 
367 // Define instantiation macro for this template.
368 #define ITK_TEMPLATE_KernelTransform(_, EXPORT, TypeX, TypeY) \
369  namespace itk \
370  { \
371  _( 2 ( class EXPORT KernelTransform<ITK_TEMPLATE_2 TypeX> ) ) \
372  namespace Templates \
373  { \
374  typedef KernelTransform<ITK_TEMPLATE_2 TypeX> \
375  KernelTransform##TypeY; \
376  } \
377  }
378 
379 #if ITK_TEMPLATE_EXPLICIT
380 #include "Templates/itkKernelTransform+-.h"
381 #endif
382 
383 #if ITK_TEMPLATE_TXX
384 #include "itkKernelTransform.hxx"
385 #endif
386 
387 #endif // __itkKernelTransform_h
388