ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkKernelTransform_h 00019 #define __itkKernelTransform_h 00020 00021 #include "itkTransform.h" 00022 #include "itkMatrix.h" 00023 #include "itkPointSet.h" 00024 #include <deque> 00025 #include <math.h> 00026 #include "vnl/vnl_matrix_fixed.h" 00027 #include "vnl/vnl_matrix.h" 00028 #include "vnl/vnl_vector.h" 00029 #include "vnl/vnl_vector_fixed.h" 00030 #include "vnl/algo/vnl_svd.h" 00031 #include "vnl/vnl_sample.h" 00032 00033 namespace itk 00034 { 00060 template <class TScalarType, // probably only float and double make sense here 00061 unsigned int NDimensions> 00062 // Number of dimensions 00063 class ITK_EXPORT KernelTransform : 00064 public Transform<TScalarType, NDimensions, NDimensions> 00065 { 00066 public: 00068 typedef KernelTransform Self; 00069 typedef Transform<TScalarType, NDimensions, NDimensions> Superclass; 00070 typedef SmartPointer<Self> Pointer; 00071 typedef SmartPointer<const Self> ConstPointer; 00072 00074 itkTypeMacro(KernelTransform, Transform); 00075 00077 itkNewMacro(Self); 00078 00080 itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions); 00081 00083 typedef typename Superclass::ScalarType ScalarType; 00084 00086 typedef typename Superclass::ParametersType ParametersType; 00087 00089 typedef typename Superclass::JacobianType JacobianType; 00090 00092 typedef typename Superclass::InputPointType InputPointType; 00093 typedef typename Superclass::OutputPointType OutputPointType; 00094 00096 typedef typename Superclass::InputVectorType InputVectorType; 00097 typedef typename Superclass::OutputVectorType OutputVectorType; 00098 00100 typedef typename Superclass::InputCovariantVectorType InputCovariantVectorType; 00101 typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType; 00102 00104 typedef typename Superclass::InputVnlVectorType InputVnlVectorType; 00105 typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType; 00106 00109 typedef DefaultStaticMeshTraits<TScalarType, NDimensions, NDimensions, TScalarType, TScalarType> PointSetTraitsType; 00110 typedef PointSet<InputPointType, NDimensions, PointSetTraitsType> PointSetType; 00111 00112 typedef typename PointSetType::Pointer PointSetPointer; 00113 typedef typename PointSetType::PointsContainer PointsContainer; 00114 typedef typename PointSetType::PointsContainerIterator PointsIterator; 00115 typedef typename PointSetType::PointsContainerConstIterator PointsConstIterator; 00116 typedef typename PointSetType::PointIdentifier PointIdentifier; 00117 00119 typedef itk::VectorContainer<SizeValueType, InputVectorType> VectorSetType; 00120 typedef typename VectorSetType::Pointer VectorSetPointer; 00121 00123 itkGetObjectMacro(SourceLandmarks, PointSetType); 00124 00126 virtual void SetSourceLandmarks(PointSetType *); 00127 00129 itkGetObjectMacro(TargetLandmarks, PointSetType); 00130 00132 virtual void SetTargetLandmarks(PointSetType *); 00133 00136 itkGetObjectMacro(Displacements, VectorSetType); 00137 00139 void ComputeWMatrix(void); 00140 00142 virtual OutputPointType TransformPoint(const InputPointType & thisPoint) const; 00143 00145 using Superclass::TransformVector; 00146 virtual OutputVectorType TransformVector(const InputVectorType &) const \ 00147 { \ 00148 itkExceptionMacro( \ 00149 << "TransformVector(const InputVectorType &) is not implemented for KernelTransform"); \ 00150 } 00152 00153 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const \ 00154 { \ 00155 itkExceptionMacro( \ 00156 << "TransformVector(const InputVnlVectorType &) is not implemented for KernelTransform"); \ 00157 } 00158 00160 using Superclass::TransformCovariantVector; 00161 virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const \ 00162 { \ 00163 itkExceptionMacro( \ 00164 << "TransformCovariantVector(const InputCovariantVectorType &) is not implemented for KernelTransform"); \ 00165 } 00167 00169 typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> IMatrixType; 00170 00172 virtual void ComputeJacobianWithRespectToParameters( const InputPointType & p, JacobianType & jacobian) const; 00173 00174 virtual void ComputeJacobianWithRespectToPosition(const InputPointType &, 00175 JacobianType &) const \ 00176 { \ 00177 itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented " \ 00178 "for " << this->GetNameOfClass() ); \ 00179 } 00180 00185 virtual void SetParameters(const ParametersType &); 00186 00192 virtual void SetFixedParameters(const ParametersType &); 00193 00195 virtual void UpdateParameters(void) const; 00196 00198 virtual const ParametersType & GetParameters(void) const; 00199 00201 virtual const ParametersType & GetFixedParameters(void) const; 00202 00206 virtual bool IsLinear() const 00207 { 00208 return false; 00209 } 00210 00221 itkSetClampMacro( Stiffness, double, 0.0, NumericTraits<double>::max() ); 00222 itkGetConstMacro(Stiffness, double); 00223 protected: 00224 KernelTransform(); 00225 virtual ~KernelTransform(); 00226 void PrintSelf(std::ostream & os, Indent indent) const; 00228 00229 public: 00231 typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> GMatrixType; 00232 00234 typedef vnl_matrix<TScalarType> LMatrixType; 00235 00237 typedef vnl_matrix<TScalarType> KMatrixType; 00238 00240 typedef vnl_matrix<TScalarType> PMatrixType; 00241 00243 typedef vnl_matrix<TScalarType> YMatrixType; 00244 00246 typedef vnl_matrix<TScalarType> WMatrixType; 00247 00249 typedef vnl_matrix<TScalarType> DMatrixType; 00250 00252 typedef vnl_matrix_fixed<TScalarType, NDimensions, NDimensions> AMatrixType; 00253 00255 typedef vnl_vector_fixed<TScalarType, NDimensions> BMatrixType; 00256 00258 typedef vnl_matrix_fixed<TScalarType, 1, NDimensions> RowMatrixType; 00259 00261 typedef vnl_matrix_fixed<TScalarType, NDimensions, 1> ColumnMatrixType; 00262 protected: 00263 00270 virtual void ComputeG(const InputVectorType & landmarkVector, GMatrixType & gmatrix) const; 00271 00281 virtual const GMatrixType & ComputeReflexiveG(PointsIterator) const; 00282 00285 virtual void ComputeDeformationContribution(const InputPointType & inputPoint, OutputPointType & result) const; 00286 00288 void ComputeK(); 00289 00291 void ComputeL(); 00292 00294 void ComputeP(); 00295 00297 void ComputeY(); 00298 00300 void ComputeD(); 00301 00306 void ReorganizeW(void); 00307 00309 double m_Stiffness; 00310 00313 VectorSetPointer m_Displacements; 00314 00316 LMatrixType m_LMatrix; 00317 00319 KMatrixType m_KMatrix; 00320 00322 PMatrixType m_PMatrix; 00323 00325 YMatrixType m_YMatrix; 00326 00328 WMatrixType m_WMatrix; 00329 00335 DMatrixType m_DMatrix; 00336 00338 AMatrixType m_AMatrix; 00339 00341 BMatrixType m_BVector; 00342 00346 mutable GMatrixType m_GMatrix; 00347 00349 bool m_WMatrixComputed; 00350 00352 IMatrixType m_I; 00353 00355 PointSetPointer m_SourceLandmarks; 00356 00358 PointSetPointer m_TargetLandmarks; 00359 private: 00360 00361 KernelTransform(const Self &); // purposely not implemented 00362 void operator=(const Self &); // purposely not implemented 00363 00364 }; 00365 } // end namespace itk 00366 00367 // Define instantiation macro for this template. 00368 #define ITK_TEMPLATE_KernelTransform(_, EXPORT, TypeX, TypeY) \ 00369 namespace itk \ 00370 { \ 00371 _( 2 ( class EXPORT KernelTransform<ITK_TEMPLATE_2 TypeX> ) ) \ 00372 namespace Templates \ 00373 { \ 00374 typedef KernelTransform<ITK_TEMPLATE_2 TypeX> \ 00375 KernelTransform##TypeY; \ 00376 } \ 00377 } 00378 00379 #if ITK_TEMPLATE_EXPLICIT 00380 #include "Templates/itkKernelTransform+-.h" 00381 #endif 00382 00383 #if ITK_TEMPLATE_TXX 00384 #include "itkKernelTransform.hxx" 00385 #endif 00386 00387 #endif // __itkKernelTransform_h 00388