Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkBSplineDeformableTransform.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkBSplineDeformableTransform.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-04-11 16:28:11 $
00007   Version:   $Revision: 1.38 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __itkBSplineDeformableTransform_h
00019 #define __itkBSplineDeformableTransform_h
00020 
00021 #include <iostream>
00022 #include "itkTransform.h"
00023 #include "itkImage.h"
00024 #include "itkImageRegion.h"
00025 #include "itkBSplineInterpolationWeightFunction.h"
00026 
00027 namespace itk
00028 {
00029 
00107 template <
00108     class TScalarType = double,          // Data type for scalars
00109     unsigned int NDimensions = 3,        // Number of dimensions
00110     unsigned int VSplineOrder = 3 >      // Spline order
00111 class ITK_EXPORT BSplineDeformableTransform : 
00112           public Transform< TScalarType, NDimensions, NDimensions >
00113 {
00114 public:
00116   typedef BSplineDeformableTransform                         Self;
00117   typedef Transform< TScalarType, NDimensions, NDimensions > Superclass;
00118   typedef SmartPointer<Self>                                 Pointer;
00119   typedef SmartPointer<const Self>                           ConstPointer;
00120 
00122   itkNewMacro( Self );
00123 
00125   itkTypeMacro( BSplineDeformableTransform, Transform );
00126 
00128   itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
00129 
00131   itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
00132 
00134   typedef typename Superclass::ScalarType ScalarType;
00135 
00137   typedef typename Superclass::ParametersType ParametersType;
00138 
00140   typedef typename Superclass::JacobianType JacobianType;
00141 
00143   typedef Vector<TScalarType,
00144                  itkGetStaticConstMacro(SpaceDimension)> InputVectorType;
00145   typedef Vector<TScalarType,
00146                  itkGetStaticConstMacro(SpaceDimension)> OutputVectorType;
00148 
00150   typedef CovariantVector<TScalarType,
00151              itkGetStaticConstMacro(SpaceDimension)> InputCovariantVectorType;
00152   typedef CovariantVector<TScalarType,
00153             itkGetStaticConstMacro(SpaceDimension)> OutputCovariantVectorType;
00155 
00157   typedef vnl_vector_fixed<TScalarType,
00158                    itkGetStaticConstMacro(SpaceDimension)> InputVnlVectorType;
00159   typedef vnl_vector_fixed<TScalarType,
00160                   itkGetStaticConstMacro(SpaceDimension)> OutputVnlVectorType;
00162 
00164   typedef Point<TScalarType,
00165                 itkGetStaticConstMacro(SpaceDimension)> InputPointType;
00166   typedef Point<TScalarType,
00167                 itkGetStaticConstMacro(SpaceDimension)> OutputPointType;
00169 
00189   void SetParameters(const ParametersType & parameters);
00190 
00207   void SetFixedParameters(const ParametersType & parameters);
00209 
00227   void SetParametersByValue(const ParametersType & parameters);
00228 
00237   void SetIdentity();
00238 
00240   virtual const ParametersType& GetParameters(void) const;
00241 
00243   virtual const ParametersType& GetFixedParameters(void) const;
00244 
00246   typedef typename ParametersType::ValueType                      PixelType;
00247   typedef Image<PixelType,itkGetStaticConstMacro(SpaceDimension)> ImageType;
00248   typedef typename ImageType::Pointer                             ImagePointer;
00249 
00251   virtual ImagePointer * GetCoefficientImage()
00252     { return m_CoefficientImage; }
00253   virtual const ImagePointer * GetCoefficientImage() const
00254     { return m_CoefficientImage; }
00256 
00269   virtual void SetCoefficientImage( ImagePointer images[] );  
00270 
00272   typedef ImageRegion<itkGetStaticConstMacro(SpaceDimension)>    RegionType;
00273 
00274   typedef typename RegionType::IndexType  IndexType;
00275   typedef typename RegionType::SizeType   SizeType;
00276   typedef typename ImageType::SpacingType SpacingType;
00277   typedef typename ImageType::DirectionType DirectionType;
00278   typedef typename ImageType::PointType   OriginType;
00279 
00281   virtual void SetGridRegion( const RegionType& region );
00282   itkGetMacro( GridRegion, RegionType );
00283   itkGetConstMacro( GridRegion, RegionType );
00285 
00287   virtual void SetGridSpacing( const SpacingType& spacing );
00288   itkGetMacro( GridSpacing, SpacingType );
00289   itkGetConstMacro( GridSpacing, SpacingType );
00291 
00293   virtual void SetGridDirection( const DirectionType & spacing );
00294   itkGetMacro( GridDirection, DirectionType );
00295   itkGetConstMacro( GridDirection, DirectionType );
00297 
00299   virtual void SetGridOrigin( const OriginType& origin );
00300   itkGetMacro( GridOrigin, OriginType );
00301   itkGetConstMacro( GridOrigin, OriginType );
00303 
00305   typedef Transform<ScalarType,itkGetStaticConstMacro(SpaceDimension),
00306                     itkGetStaticConstMacro(SpaceDimension)> BulkTransformType;
00307   typedef typename BulkTransformType::ConstPointer       BulkTransformPointer;
00309 
00313   itkSetConstObjectMacro( BulkTransform, BulkTransformType );
00314   itkGetConstObjectMacro( BulkTransform, BulkTransformType );
00316 
00318   OutputPointType  TransformPoint(const InputPointType  &point ) const;
00319 
00321   typedef BSplineInterpolationWeightFunction<ScalarType,
00322                      itkGetStaticConstMacro(SpaceDimension),
00323                      itkGetStaticConstMacro(SplineOrder)> WeightsFunctionType;
00324   typedef typename WeightsFunctionType::WeightsType       WeightsType;
00325   typedef typename WeightsFunctionType::ContinuousIndexType 
00326                                                           ContinuousIndexType;
00328 
00330   typedef Array<unsigned long> ParameterIndexArrayType;
00331 
00339   virtual void TransformPoint( const InputPointType & inputPoint,
00340                        OutputPointType & outputPoint,
00341                        WeightsType & weights,
00342                        ParameterIndexArrayType & indices, 
00343                        bool & inside ) const;
00344 
00345   virtual void GetJacobian( const InputPointType & inputPoint,
00346                        WeightsType & weights,
00347                        ParameterIndexArrayType & indices
00348                        ) const;
00349 
00350 
00352   unsigned long GetNumberOfWeights() const
00353     { return m_WeightsFunction->GetNumberOfWeights(); }
00354 
00357   virtual OutputVectorType TransformVector(const InputVectorType &) const
00358     { 
00359     itkExceptionMacro(<< "Method not applicable for deformable transform." );
00360     return OutputVectorType(); 
00361     }
00363 
00366   virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
00367     { 
00368     itkExceptionMacro(<< "Method not applicable for deformable transform. ");
00369     return OutputVnlVectorType(); 
00370     }
00372 
00375   virtual OutputCovariantVectorType TransformCovariantVector(
00376     const InputCovariantVectorType &) const
00377     { 
00378     itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
00379     return OutputCovariantVectorType(); 
00380     } 
00382 
00384   virtual const JacobianType& GetJacobian(const InputPointType  &point ) const;
00385 
00387   virtual unsigned int GetNumberOfParameters(void) const;
00388 
00390   unsigned int GetNumberOfParametersPerDimension(void) const;
00391 
00393   itkGetConstReferenceMacro( ValidRegion, RegionType );
00394 
00400   virtual bool IsLinear() const { return false; }
00401 
00402   unsigned int GetNumberOfAffectedWeights() const;
00403 
00404 protected:
00406   void PrintSelf(std::ostream &os, Indent indent) const;
00407 
00408 
00409   BSplineDeformableTransform();
00410   virtual ~BSplineDeformableTransform();
00411 
00413   itkSetObjectMacro( WeightsFunction, WeightsFunctionType );
00414   itkGetObjectMacro( WeightsFunction, WeightsFunctionType );
00416 
00418   void WrapAsImages();
00419 
00421   void TransformPointToContinuousIndex( 
00422    const InputPointType & point, ContinuousIndexType & index ) const;
00423 
00424 private:
00425   BSplineDeformableTransform(const Self&); //purposely not implemented
00426   void operator=(const Self&); //purposely not implemented
00427 
00429   BulkTransformPointer  m_BulkTransform;
00430 
00432   RegionType    m_GridRegion;
00433   SpacingType   m_GridSpacing;
00434   DirectionType m_GridDirection;
00435   OriginType    m_GridOrigin;
00436 
00437   DirectionType m_PointToIndex;
00438   DirectionType m_IndexToPoint;
00439   
00440   RegionType    m_ValidRegion;
00441 
00443   unsigned long m_Offset;
00444   bool          m_SplineOrderOdd;
00445   SizeType      m_SupportSize;
00446   IndexType     m_ValidRegionLast;
00447 
00449   ImagePointer   m_WrappedImage[NDimensions];
00450 
00453   ImagePointer   m_CoefficientImage[NDimensions];
00454 
00456   typedef typename JacobianType::ValueType JacobianPixelType;
00457   typedef Image<JacobianPixelType,
00458                 itkGetStaticConstMacro(SpaceDimension)> JacobianImageType;
00459 
00460   typename JacobianImageType::Pointer m_JacobianImage[NDimensions];
00461 
00465   mutable IndexType m_LastJacobianIndex;
00466 
00468   const ParametersType *  m_InputParametersPointer;
00469 
00471   ParametersType          m_InternalParametersBuffer;
00472 
00474   typename WeightsFunctionType::Pointer  m_WeightsFunction;
00475 
00477   bool InsideValidRegion( const ContinuousIndexType& index ) const;
00478 
00479 
00480 }; //class BSplineDeformableTransform
00481 
00482 
00483 }  // namespace itk
00484 
00485 // Define instantiation macro for this template.
00486 #define ITK_TEMPLATE_BSplineDeformableTransform(_, EXPORT, x, y) namespace itk { \
00487   _(3(class EXPORT BSplineDeformableTransform< ITK_TEMPLATE_3 x >)) \
00488   namespace Templates { typedef BSplineDeformableTransform< ITK_TEMPLATE_3 x > \
00489                                                    BSplineDeformableTransform##y; } \
00490   }
00491 
00492 #if ITK_TEMPLATE_EXPLICIT
00493 # include "Templates/itkBSplineDeformableTransform+-.h"
00494 #endif
00495 
00496 #if ITK_TEMPLATE_TXX
00497 # include "itkBSplineDeformableTransform.txx"
00498 #endif
00499 
00500 #endif /* __itkBSplineDeformableTransform_h */
00501 

Generated at Tue Jul 29 19:23:05 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000