Shapeworks Studio  2.1
Shape analysis software suite
itkSparseKernelTransform.h
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSparseKernelTransform.h,v $
5  Language: C++
6  Date: $Date: 2006-11-28 14:22:18 $
7  Version: $Revision: 1.1 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkSparseKernelTransform_h
18 #define __itkSparseKernelTransform_h
19 
20 #include <itkTransform.h>
21 #include <itkPoint.h>
22 #include <itkVector.h>
23 #include <itkMatrix.h>
24 #include <itkPointSet.h>
25 #include <deque>
26 #include <math.h>
27 #include <vnl/vnl_matrix_fixed.h>
28 #include <vnl/vnl_matrix.h>
29 #include <vnl/vnl_vector.h>
30 #include <vnl/vnl_vector_fixed.h>
31 #include <vnl/algo/vnl_svd.h>
32 #include <vnl/vnl_sample.h>
33 
34 //#define EIGEN_USE_MKL_ALL
35 #include "Eigen/Dense"
36 #include "Eigen/Sparse"
37 #include <stdint.h>
38 #include <iostream>
39 
40 
41 namespace itk
42 {
43 
74 template <class TScalarType, // probably only float and double make sense here
75  unsigned int NDimensions> // Number of dimensions
76 class ITK_EXPORT SparseKernelTransform :
77  public Transform<TScalarType, NDimensions,NDimensions>
78 {
79 public:
82  typedef Transform<TScalarType, NDimensions, NDimensions > Superclass;
83  typedef SmartPointer<Self> Pointer;
84  typedef SmartPointer<const Self> ConstPointer;
85 
87  itkTypeMacro( SparseKernelTransform, Transform );
88 
90  itkNewMacro( Self );
91 
93  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
94 
96  typedef typename Superclass::ScalarType ScalarType;
97 
99  typedef typename Superclass::ParametersType ParametersType;
100 
102  typedef typename Superclass::JacobianType JacobianType;
103 
105  typedef typename Superclass::InputPointType InputPointType;
106  typedef typename Superclass::OutputPointType OutputPointType;
107 
109  typedef typename Superclass::InputVectorType InputVectorType;
110  typedef typename Superclass::OutputVectorType OutputVectorType;
111 
114  typedef DefaultStaticMeshTraits<TScalarType,
115  NDimensions,
116  NDimensions,
117  TScalarType,
118  TScalarType> PointSetTraitsType;
119  typedef PointSet<InputPointType, NDimensions, PointSetTraitsType> PointSetType;
120  typedef typename PointSetType::Pointer PointSetPointer;
121  typedef typename PointSetType::PointsContainer PointsContainer;
122  typedef typename PointSetType::PointsContainerIterator PointsIterator;
123  typedef typename PointSetType::PointsContainerConstIterator PointsConstIterator;
124 
126  typedef itk::VectorContainer<unsigned long,InputVectorType> VectorSetType;
127  typedef typename VectorSetType::Pointer VectorSetPointer;
128 
130  itkGetObjectMacro( SourceLandmarks, PointSetType);
131 
133  virtual void SetSourceLandmarks(PointSetType *);
134 
136  itkGetObjectMacro( TargetLandmarks, PointSetType);
137 
139  virtual void SetTargetLandmarks(PointSetType *);
140 
143  itkGetObjectMacro( Displacements, VectorSetType );
144 
146  void ComputeWMatrix(void) const;
147 
149  //void ComputeLInverse() const;
150 
152  virtual OutputPointType TransformPoint(const InputPointType& thisPoint) const;
153 
156  //typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> IMatrixType;
157 
158 
160  //virtual const JacobianType & GetJacobian(const InputPointType &point ) const;
161 
163  virtual void SetIdentity();
164 
169  virtual void SetParameters(const ParametersType &);
170 
176  virtual void SetFixedParameters(const ParametersType &);
177 
179  virtual void UpdateParameters(void) const;
180 
182  virtual const ParametersType& GetParameters(void) const;
183 
185  virtual const ParametersType& GetFixedParameters(void) const;
186  virtual void ComputeJacobianWithRespectToParameters(
187  const InputPointType &in, JacobianType &jacobian) const;
188 
199  virtual void SetStiffness(double stiffness)
200  {m_Stiffness=(stiffness>0)?stiffness:0.0;
201  m_LMatrixComputed=false;
202  m_LInverseComputed=false;
203  m_WMatrixComputed=false;
204  }
205  //itkSetClampMacro(Stiffness, double, 0.0, NumericTraits<double>::max());
206  // Cant use the macro because the matrices must be recomputed
207  itkGetMacro(Stiffness, double);
208 
209 
210 protected:
212  virtual ~SparseKernelTransform();
213  void PrintSelf(std::ostream& os, Indent indent) const;
214 
215 public:
218 
221  //typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> GMatrixType;
222 
225  //typedef vnl_matrix<TScalarType> LMatrixType;
226 
229  //typedef vnl_matrix<TScalarType> KMatrixType;
230 
233  //typedef Eigen::Matrix<TScalarType, Eigen::Dynamic, NDimensions*(NDimensions+1)> PMatrixType;
234  //typedef vnl_matrix<TScalarType> PMatrixType;
235 
238  //typedef vnl_matrix<TScalarType> YMatrixType;
239 
242  //typedef vnl_matrix<TScalarType> WMatrixType;
243 
246  //typedef vnl_matrix<TScalarType> DMatrixType;
247 
250  //typedef vnl_matrix_fixed<TScalarType,NDimensions,NDimensions> AMatrixType;
251 
254  //typedef vnl_vector_fixed<TScalarType,NDimensions> BMatrixType;
255 
258  //typedef vnl_matrix_fixed<TScalarType, 1, NDimensions> RowMatrixType;
259 
262  //typedef vnl_matrix_fixed<TScalarType, NDimensions, 1> ColumnMatrixType;
263 
265  PointSetPointer m_SourceLandmarks;
266 
268  PointSetPointer m_TargetLandmarks;
269 
270 protected:
277  virtual const GMatrixType & ComputeG(const InputVectorType & landmarkVector) const;
278 
285  virtual const GMatrixType & ComputeReflexiveG(PointsIterator) const;
286 
287 
290  virtual void ComputeDeformationContribution( const InputPointType & inputPoint,
291  OutputPointType & result ) const;
292 
294  void ComputeK() const;
295 
297  void ComputeL() const;
298 
299 
301  void ComputeP() const;
302 
304  void ComputeY() const;
305 
307  void ComputeD() const;
308 
313  void ReorganizeW(void) const;
314 
316  double m_Stiffness;
317 
320  VectorSetPointer m_Displacements;
321 
323  mutable LMatrixType m_LMatrix;
324 
326  mutable LMatrixType m_LMatrixInverse;
327 
329  mutable KMatrixType m_KMatrix;
330 
332  mutable PMatrixType m_PMatrix;
333 
335  mutable YMatrixType m_YMatrix;
336 
338  mutable WMatrixType m_WMatrix;
339 
345  mutable DMatrixType m_DMatrix;
346 
348  mutable AMatrixType m_AMatrix;
349 
351  mutable BMatrixType m_BVector;
352 
356  mutable GMatrixType m_GMatrix;
357 
359  mutable bool m_WMatrixComputed;
361  mutable bool m_LMatrixComputed;
363  mutable bool m_LInverseComputed;
364 
366  IMatrixType m_I;
367 
368 private:
369  SparseKernelTransform(const Self&); //purposely not implemented
370  void operator=(const Self&); //purposely not implemented
371 
372 };
373 
374 } // end namespace itk
375 
376 #ifndef ITK_MANUAL_INSTANTIATION
377 #include "itkSparseKernelTransform.hxx"
378 #endif
379 
380 #endif // __itkSparseKernelTransform_h
Superclass::JacobianType JacobianType
virtual void SetStiffness(double stiffness)
Eigen::Triplet< TScalarType > TripletType
Superclass::ParametersType ParametersType
Superclass::InputVectorType InputVectorType
Eigen::SparseMatrix< TScalarType > LMatrixType
Superclass::InputPointType InputPointType
Eigen::Matrix< TScalarType, Eigen::Dynamic, Eigen::Dynamic > DMatrixType
itk::VectorContainer< unsigned long, InputVectorType > VectorSetType
Superclass::ScalarType ScalarType
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:147
Eigen::Matrix< TScalarType, NDimensions, 1 > ColumnMatrixType
DefaultStaticMeshTraits< TScalarType, NDimensions, NDimensions, TScalarType, TScalarType > PointSetTraitsType
Eigen::SparseMatrix< TScalarType > KMatrixType
Eigen::Matrix< TScalarType, Eigen::Dynamic, Eigen::Dynamic > YMatrixType
Eigen::Matrix< TScalarType, 1, NDimensions > RowMatrixType
Eigen::Matrix< TScalarType, NDimensions, 1 > BMatrixType
Eigen::Matrix< TScalarType, NDimensions, NDimensions > IMatrixType
Eigen::SparseMatrix< TScalarType > PMatrixType
Eigen::Matrix< TScalarType, Eigen::Dynamic, Eigen::Dynamic > WMatrixType
Eigen::Matrix< TScalarType, NDimensions, NDimensions > AMatrixType
Eigen::Matrix< TScalarType, NDimensions, NDimensions > GMatrixType