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 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
00206 void SetFixedParameters(const ParametersType & parameters);
00208
00226 void SetParametersByValue(const ParametersType & parameters);
00227
00236 void SetIdentity();
00237
00239 virtual const ParametersType& GetParameters(void) const;
00240
00242 virtual const ParametersType& GetFixedParameters(void) const;
00243
00245 typedef typename ParametersType::ValueType PixelType;
00246 typedef Image<PixelType,itkGetStaticConstMacro(SpaceDimension)> ImageType;
00247 typedef typename ImageType::Pointer ImagePointer;
00248
00250 virtual ImagePointer * GetCoefficientImage()
00251 { return m_CoefficientImage; }
00252
00265 virtual void SetCoefficientImage( ImagePointer images[] );
00266
00268 typedef ImageRegion<itkGetStaticConstMacro(SpaceDimension)> RegionType;
00269
00270 typedef typename RegionType::IndexType IndexType;
00271 typedef typename RegionType::SizeType SizeType;
00272 typedef typename ImageType::SpacingType SpacingType;
00273 typedef typename ImageType::PointType OriginType;
00274
00276 virtual void SetGridRegion( const RegionType& region );
00277 itkGetMacro( GridRegion, RegionType );
00278 itkGetConstMacro( GridRegion, RegionType );
00280
00282 virtual void SetGridSpacing( const SpacingType& spacing );
00283 itkGetMacro( GridSpacing, SpacingType );
00284 itkGetConstMacro( GridSpacing, SpacingType );
00286
00288 virtual void SetGridOrigin( const OriginType& origin );
00289 itkGetMacro( GridOrigin, OriginType );
00290 itkGetConstMacro( GridOrigin, OriginType );
00292
00294 typedef Transform<ScalarType,itkGetStaticConstMacro(SpaceDimension),
00295 itkGetStaticConstMacro(SpaceDimension)> BulkTransformType;
00296 typedef typename BulkTransformType::ConstPointer BulkTransformPointer;
00298
00302 itkSetConstObjectMacro( BulkTransform, BulkTransformType );
00303 itkGetConstObjectMacro( BulkTransform, BulkTransformType );
00305
00307 OutputPointType TransformPoint(const InputPointType &point ) const;
00308
00310 typedef BSplineInterpolationWeightFunction<ScalarType,
00311 itkGetStaticConstMacro(SpaceDimension),
00312 itkGetStaticConstMacro(SplineOrder)> WeightsFunctionType;
00313 typedef typename WeightsFunctionType::WeightsType WeightsType;
00314 typedef typename WeightsFunctionType::ContinuousIndexType
00315 ContinuousIndexType;
00317
00319 typedef Array<unsigned long> ParameterIndexArrayType;
00320
00328 virtual void TransformPoint( const InputPointType & inputPoint,
00329 OutputPointType & outputPoint,
00330 WeightsType & weights,
00331 ParameterIndexArrayType & indices,
00332 bool & inside ) const;
00333
00335 unsigned long GetNumberOfWeights() const
00336 { return m_WeightsFunction->GetNumberOfWeights(); }
00337
00340 virtual OutputVectorType TransformVector(const InputVectorType &) const
00341 {
00342 itkExceptionMacro(<< "Method not applicable for deformable transform." );
00343 return OutputVectorType();
00344 }
00346
00349 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
00350 {
00351 itkExceptionMacro(<< "Method not applicable for deformable transform. ");
00352 return OutputVnlVectorType();
00353 }
00355
00358 virtual OutputCovariantVectorType TransformCovariantVector(
00359 const InputCovariantVectorType &) const
00360 {
00361 itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
00362 return OutputCovariantVectorType();
00363 }
00365
00367 virtual const JacobianType& GetJacobian(const InputPointType &point ) const;
00368
00370 virtual unsigned int GetNumberOfParameters(void) const;
00371
00373 unsigned int GetNumberOfParametersPerDimension(void) const;
00374
00376 itkGetConstReferenceMacro( ValidRegion, RegionType );
00377
00383 virtual bool IsLinear() const { return false; }
00384
00385 protected:
00387 void PrintSelf(std::ostream &os, Indent indent) const;
00388
00389
00390 BSplineDeformableTransform();
00391 virtual ~BSplineDeformableTransform();
00392
00394 itkSetObjectMacro( WeightsFunction, WeightsFunctionType );
00395 itkGetObjectMacro( WeightsFunction, WeightsFunctionType );
00397
00399 void WrapAsImages();
00400
00401 private:
00402 BSplineDeformableTransform(const Self&);
00403 void operator=(const Self&);
00404
00406 BulkTransformPointer m_BulkTransform;
00407
00409 RegionType m_GridRegion;
00410 SpacingType m_GridSpacing;
00411 OriginType m_GridOrigin;
00412
00413 RegionType m_ValidRegion;
00414
00416 unsigned long m_Offset;
00417 bool m_SplineOrderOdd;
00418 SizeType m_SupportSize;
00419 IndexType m_ValidRegionLast;
00420
00422 ImagePointer m_WrappedImage[NDimensions];
00423
00426 ImagePointer m_CoefficientImage[NDimensions];
00427
00429 typedef typename JacobianType::ValueType JacobianPixelType;
00430 typedef Image<JacobianPixelType,
00431 itkGetStaticConstMacro(SpaceDimension)> JacobianImageType;
00432
00433 typename JacobianImageType::Pointer m_JacobianImage[NDimensions];
00434
00438 mutable IndexType m_LastJacobianIndex;
00439
00441 const ParametersType * m_InputParametersPointer;
00442
00444 ParametersType m_InternalParametersBuffer;
00445
00447 typename WeightsFunctionType::Pointer m_WeightsFunction;
00448
00450 bool InsideValidRegion( const ContinuousIndexType& index ) const;
00451
00452
00453 };
00454
00455
00456 }
00457
00458
00459 #define ITK_TEMPLATE_BSplineDeformableTransform(_, EXPORT, x, y) namespace itk { \
00460 _(3(class EXPORT BSplineDeformableTransform< ITK_TEMPLATE_3 x >)) \
00461 namespace Templates { typedef BSplineDeformableTransform< ITK_TEMPLATE_3 x > \
00462 BSplineDeformableTransform##y; } \
00463 }
00464
00465 #if ITK_TEMPLATE_EXPLICIT
00466 # include "Templates/itkBSplineDeformableTransform+-.h"
00467 #endif
00468
00469 #if ITK_TEMPLATE_TXX
00470 # include "itkBSplineDeformableTransform.txx"
00471 #endif
00472
00473 #endif
00474