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
00106 template <
00107 class TScalarType = double,
00108 unsigned int NDimensions = 3,
00109 unsigned int VSplineOrder = 3 >
00110 class ITK_EXPORT BSplineDeformableTransform :
00111 public Transform< TScalarType, NDimensions, NDimensions >
00112 {
00113 public:
00115 typedef BSplineDeformableTransform Self;
00116 typedef Transform< TScalarType, NDimensions, NDimensions > Superclass;
00117 typedef SmartPointer<Self> Pointer;
00118 typedef SmartPointer<const Self> ConstPointer;
00119
00121 itkNewMacro( Self );
00122
00124 itkTypeMacro( BSplineDeformableTransform, Transform );
00125
00127 itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
00128
00130 itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
00131
00133 typedef typename Superclass::ScalarType ScalarType;
00134
00136 typedef typename Superclass::ParametersType ParametersType;
00137
00139 typedef typename Superclass::JacobianType JacobianType;
00140
00142 typedef Vector<TScalarType,
00143 itkGetStaticConstMacro(SpaceDimension)> InputVectorType;
00144 typedef Vector<TScalarType,
00145 itkGetStaticConstMacro(SpaceDimension)> OutputVectorType;
00146
00148 typedef CovariantVector<TScalarType,
00149 itkGetStaticConstMacro(SpaceDimension)> InputCovariantVectorType;
00150 typedef CovariantVector<TScalarType,
00151 itkGetStaticConstMacro(SpaceDimension)> OutputCovariantVectorType;
00152
00154 typedef vnl_vector_fixed<TScalarType,
00155 itkGetStaticConstMacro(SpaceDimension)> InputVnlVectorType;
00156 typedef vnl_vector_fixed<TScalarType,
00157 itkGetStaticConstMacro(SpaceDimension)> OutputVnlVectorType;
00158
00160 typedef Point<TScalarType,
00161 itkGetStaticConstMacro(SpaceDimension)> InputPointType;
00162 typedef Point<TScalarType,
00163 itkGetStaticConstMacro(SpaceDimension)> OutputPointType;
00164
00183 void SetParameters(const ParametersType & parameters);
00184
00193 void SetIdentity();
00194
00196 virtual const ParametersType& GetParameters(void) const;
00197
00199 typedef typename ParametersType::ValueType PixelType;
00200 typedef Image<PixelType,itkGetStaticConstMacro(SpaceDimension)> ImageType;
00201 typedef typename ImageType::Pointer ImagePointer;
00202
00204 virtual ImagePointer * GetCoefficientImage()
00205 { return m_CoefficientImage; }
00206
00219 virtual void SetCoefficientImage( ImagePointer images[] );
00220
00222 typedef ImageRegion<itkGetStaticConstMacro(SpaceDimension)> RegionType;
00223 typedef typename RegionType::IndexType IndexType;
00224 typedef typename RegionType::SizeType SizeType;
00225 typedef typename ImageType::SpacingType SpacingType;
00226 typedef typename ImageType::PointType OriginType;
00227
00229 virtual void SetGridRegion( const RegionType& region );
00230 itkGetMacro( GridRegion, RegionType );
00231
00233 virtual void SetGridSpacing( const SpacingType& spacing );
00234 itkGetMacro( GridSpacing, SpacingType );
00235
00237 virtual void SetGridOrigin( const OriginType& origin );
00238 itkGetMacro( GridOrigin, OriginType );
00239
00241 typedef Transform<ScalarType,itkGetStaticConstMacro(SpaceDimension),
00242 itkGetStaticConstMacro(SpaceDimension)> BulkTransformType;
00243 typedef typename BulkTransformType::ConstPointer BulkTransformPointer;
00244
00248 itkSetConstObjectMacro( BulkTransform, BulkTransformType );
00249 itkGetConstObjectMacro( BulkTransform, BulkTransformType );
00250
00252 OutputPointType TransformPoint(const InputPointType &point ) const;
00253
00255 typedef BSplineInterpolationWeightFunction<ScalarType,
00256 itkGetStaticConstMacro(SpaceDimension),
00257 itkGetStaticConstMacro(SplineOrder)> WeightsFunctionType;
00258 typedef typename WeightsFunctionType::WeightsType WeightsType;
00259 typedef typename WeightsFunctionType::ContinuousIndexType ContinuousIndexType;
00260
00262 typedef Array<unsigned long> ParameterIndexArrayType;
00263
00271 virtual void TransformPoint( const InputPointType & inputPoint,
00272 OutputPointType & outputPoint,
00273 WeightsType & weights,
00274 ParameterIndexArrayType & indices,
00275 bool & inside ) const;
00276
00278 unsigned long GetNumberOfWeights() const
00279 { return m_WeightsFunction->GetNumberOfWeights(); }
00280
00282 virtual OutputVectorType TransformVector(const InputVectorType &) const
00283 {
00284 itkExceptionMacro(<< "Method not applicable for deformable transform." );
00285 return OutputVectorType();
00286 }
00287
00289 virtual OutputVnlVectorType TransformVector(const InputVnlVectorType &) const
00290 {
00291 itkExceptionMacro(<< "Method not applicable for deformable transform. ");
00292 return OutputVnlVectorType();
00293 }
00294
00296 virtual OutputCovariantVectorType TransformCovariantVector(
00297 const InputCovariantVectorType &) const
00298 {
00299 itkExceptionMacro(<< "Method not applicable for deformable transfrom. ");
00300 return OutputCovariantVectorType();
00301 }
00302
00304 virtual const JacobianType& GetJacobian(const InputPointType &point ) const;
00305
00307 virtual unsigned int GetNumberOfParameters(void) const;
00308
00310 unsigned int GetNumberOfParametersPerDimension(void) const;
00311
00313 itkGetConstReferenceMacro( ValidRegion, RegionType );
00314
00315 protected:
00317 void PrintSelf(std::ostream &os, Indent indent) const;
00318
00319
00320 BSplineDeformableTransform();
00321 virtual ~BSplineDeformableTransform();
00322
00324 itkSetObjectMacro( WeightsFunction, WeightsFunctionType );
00325 itkGetObjectMacro( WeightsFunction, WeightsFunctionType );
00326
00327 private:
00328 BSplineDeformableTransform(const Self&);
00329 void operator=(const Self&);
00330
00332 BulkTransformPointer m_BulkTransform;
00333
00335 RegionType m_GridRegion;
00336 SpacingType m_GridSpacing;
00337 OriginType m_GridOrigin;
00338
00339 RegionType m_ValidRegion;
00340
00342 unsigned long m_Offset;
00343 bool m_SplineOrderOdd;
00344 SizeType m_SupportSize;
00345 IndexType m_ValidRegionLast;
00346
00348 ImagePointer m_WrappedImage[NDimensions];
00349
00351 ImagePointer m_CoefficientImage[NDimensions];
00352
00354 typedef typename JacobianType::ValueType JacobianPixelType;
00355 typedef Image<JacobianPixelType,
00356 itkGetStaticConstMacro(SpaceDimension)> JacobianImageType;
00357
00358 typename JacobianImageType::Pointer m_JacobianImage[NDimensions];
00359
00363 mutable IndexType m_LastJacobianIndex;
00364
00366 const ParametersType * m_InputParametersPointer;
00367
00369 typename WeightsFunctionType::Pointer m_WeightsFunction;
00370
00372 bool InsideValidRegion( const ContinuousIndexType& index ) const;
00373
00374
00375 };
00376
00377
00378 }
00379
00380
00381 #ifndef ITK_MANUAL_INSTANTIATION
00382 #include "itkBSplineDeformableTransform.txx"
00383 #endif
00384
00385 #endif