00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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,
00109 unsigned int NDimensions = 3,
00110 unsigned int VSplineOrder = 3 >
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 static Pointer New(void);
00123
00126 virtual ::itk::LightObject::Pointer CreateAnother(void) const;
00127
00129 itkTypeMacro( BSplineDeformableTransform, Transform );
00130
00132 itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
00133
00135 itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
00136
00138 typedef typename Superclass::ScalarType ScalarType;
00139
00141 typedef typename Superclass::ParametersType ParametersType;
00142
00144 typedef typename Superclass::JacobianType JacobianType;
00145
00147 typedef Vector<TScalarType,
00148 itkGetStaticConstMacro(SpaceDimension)> InputVectorType;
00149 typedef Vector<TScalarType,
00150 itkGetStaticConstMacro(SpaceDimension)> OutputVectorType;
00152
00154 typedef CovariantVector<TScalarType,
00155 itkGetStaticConstMacro(SpaceDimension)> InputCovariantVectorType;
00156 typedef CovariantVector<TScalarType,
00157 itkGetStaticConstMacro(SpaceDimension)> OutputCovariantVectorType;
00159
00161 typedef vnl_vector_fixed<TScalarType,
00162 itkGetStaticConstMacro(SpaceDimension)> InputVnlVectorType;
00163 typedef vnl_vector_fixed<TScalarType,
00164 itkGetStaticConstMacro(SpaceDimension)> OutputVnlVectorType;
00166
00168 typedef Point<TScalarType,
00169 itkGetStaticConstMacro(SpaceDimension)> InputPointType;
00170 typedef Point<TScalarType,
00171 itkGetStaticConstMacro(SpaceDimension)> OutputPointType;
00173
00193 void SetParameters(const ParametersType & parameters);
00194
00211 void SetFixedParameters(const ParametersType & parameters);
00213
00231 void SetParametersByValue(const ParametersType & parameters);
00232
00241 void SetIdentity();
00242
00244 virtual const ParametersType& GetParameters(void) const;
00245
00247 virtual const ParametersType& GetFixedParameters(void) const;
00248
00250 typedef typename ParametersType::ValueType PixelType;
00251 typedef Image<PixelType,itkGetStaticConstMacro(SpaceDimension)> ImageType;
00252 typedef typename ImageType::Pointer ImagePointer;
00253
00255 virtual ImagePointer * GetCoefficientImage()
00256 { return m_CoefficientImage; }
00257 virtual const ImagePointer * GetCoefficientImage() const
00258 { return m_CoefficientImage; }
00260
00273 virtual void SetCoefficientImage( ImagePointer images[] );
00274
00276 typedef ImageRegion<itkGetStaticConstMacro(SpaceDimension)> RegionType;
00277
00278 typedef typename RegionType::IndexType IndexType;
00279 typedef typename RegionType::SizeType SizeType;
00280 typedef typename ImageType::SpacingType SpacingType;
00281 typedef typename ImageType::DirectionType DirectionType;
00282 typedef typename ImageType::PointType OriginType;
00283
00285 virtual void SetGridRegion( const RegionType& region );
00286 itkGetConstMacro( GridRegion, RegionType );
00288
00290 virtual void SetGridSpacing( const SpacingType& spacing );
00291 itkGetConstMacro( GridSpacing, SpacingType );
00293
00295 virtual void SetGridDirection( const DirectionType & spacing );
00296 itkGetConstMacro( GridDirection, DirectionType );
00298
00300 virtual void SetGridOrigin( const OriginType& origin );
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&);
00426 void operator=(const Self&);
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 IndexType m_ValidRegionFirst;
00448
00450 ImagePointer m_WrappedImage[NDimensions];
00451
00454 ImagePointer m_CoefficientImage[NDimensions];
00455
00457 typedef typename JacobianType::ValueType JacobianPixelType;
00458 typedef Image<JacobianPixelType,
00459 itkGetStaticConstMacro(SpaceDimension)> JacobianImageType;
00460
00461 typename JacobianImageType::Pointer m_JacobianImage[NDimensions];
00462
00466 mutable IndexType m_LastJacobianIndex;
00467
00469 const ParametersType * m_InputParametersPointer;
00470
00472 ParametersType m_InternalParametersBuffer;
00473
00475 typename WeightsFunctionType::Pointer m_WeightsFunction;
00476
00478 bool InsideValidRegion( const ContinuousIndexType& index ) const;
00479
00480
00481 };
00482
00483
00484 }
00485
00486
00487 #define ITK_TEMPLATE_BSplineDeformableTransform(_, EXPORT, x, y) namespace itk { \
00488 _(3(class EXPORT BSplineDeformableTransform< ITK_TEMPLATE_3 x >)) \
00489 namespace Templates { typedef BSplineDeformableTransform< ITK_TEMPLATE_3 x > \
00490 BSplineDeformableTransform##y; } \
00491 }
00492
00493 #if ITK_TEMPLATE_EXPLICIT
00494 # include "Templates/itkBSplineDeformableTransform+-.h"
00495 #endif
00496
00497 #if ITK_TEMPLATE_TXX
00498 # include "itkBSplineDeformableTransform.txx"
00499 #endif
00500
00501 #endif
00502