ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkBSplineDeformableTransform.h
Go to the documentation of this file.
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 __itkBSplineDeformableTransform_h
00019 #define __itkBSplineDeformableTransform_h
00020 
00021 #include "itkConfigure.h" // Needed to determine value of ITKV3_COMPATIBILITY
00022 #include "itkBSplineBaseTransform.h"
00023 
00024 namespace itk
00025 {
00107 template <class TScalarType = double, unsigned int NDimensions = 3,
00108           unsigned int VSplineOrder = 3>
00109 class ITK_EXPORT BSplineDeformableTransform :
00110   public BSplineBaseTransform<TScalarType,NDimensions,VSplineOrder>
00111 {
00112 public:
00114   typedef BSplineDeformableTransform                                 Self;
00115   typedef BSplineBaseTransform<TScalarType,NDimensions,VSplineOrder> Superclass;
00116   typedef SmartPointer<Self>                                         Pointer;
00117   typedef SmartPointer<const Self>                                   ConstPointer;
00118 
00120   // Explicit New() method, used here because we need to split the itkNewMacro()
00121   // in order to overload the CreateAnother() method so that we can copy the m_BulkTransform
00122   // explicitly.
00123   itkSimpleNewMacro(Self);
00124   virtual ::itk::LightObject::Pointer CreateAnother(void) const
00125     {
00126     ::itk::LightObject::Pointer smartPtr;
00127     Pointer copyPtr = Self::New().GetPointer();
00128     //THE FOLLOWING LINE IS DIFFERENT FROM THE DEFAULT MACRO!
00129     copyPtr->m_BulkTransform =  this->GetBulkTransform();
00130     smartPtr = static_cast<Pointer>( copyPtr );
00131     return smartPtr;
00132     }
00134 
00136   itkTypeMacro( BSplineDeformableTransform, BSplineBaseTransform );
00137 
00139   itkStaticConstMacro( SpaceDimension, unsigned int, NDimensions );
00140 
00142   itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
00143 
00145   typedef typename Superclass::ScalarType ScalarType;
00146 
00148   typedef typename Superclass::ParametersType ParametersType;
00149 
00151   typedef typename Superclass::JacobianType JacobianType;
00152 
00154   typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
00155 
00157   typedef typename Superclass::InputVectorType  InputVectorType;
00158   typedef typename Superclass::OutputVectorType OutputVectorType;
00159 
00161   typedef typename Superclass::InputCovariantVectorType  InputCovariantVectorType;
00162   typedef typename Superclass::OutputCovariantVectorType OutputCovariantVectorType;
00163 
00165   typedef typename Superclass::InputVnlVectorType  InputVnlVectorType;
00166   typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
00167 
00169   typedef Point <TScalarType, itkGetStaticConstMacro( SpaceDimension )> InputPointType;
00170   typedef Point <TScalarType, itkGetStaticConstMacro( SpaceDimension )> OutputPointType;
00172 
00173 
00190   virtual void SetFixedParameters( const ParametersType & parameters );
00192 
00194   typedef typename Superclass::ParametersValueType   ParametersValueType;
00195   typedef typename Superclass::ImageType             ImageType;
00196   typedef typename Superclass::ImagePointer          ImagePointer;
00197   typedef typename Superclass::CoefficientImageArray CoefficientImageArray;
00198 
00210   virtual void SetCoefficientImages( const CoefficientImageArray & images );
00211 
00212 #ifdef ITKV3_COMPATIBILITY
00213   virtual void SetCoefficientImage( const CoefficientImageArray & images )
00214     {
00215     this->SetCoefficientImages( images );
00216     }
00217   /* Only for backwards compatibility with ITKv3. */
00218   CoefficientImageArray GetCoefficientImage()
00219     {
00220     return this->GetCoefficientImages();
00221     }
00222 #endif
00223 
00225   typedef typename Superclass::RegionType    RegionType;
00226 
00227   typedef typename Superclass::IndexType     IndexType;
00228   typedef typename Superclass::SizeType      SizeType;
00229   typedef typename Superclass::SpacingType   SpacingType;
00230   typedef typename Superclass::DirectionType DirectionType;
00231   typedef typename Superclass::OriginType    OriginType;
00232 
00234   typedef typename Superclass::WeightsFunctionType WeightsFunctionType;
00235 
00236   typedef typename Superclass::WeightsType         WeightsType;
00237   typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
00238 
00240   typedef typename Superclass::ParameterIndexArrayType ParameterIndexArrayType;
00241 
00250   using Superclass::TransformPoint;
00251   virtual void TransformPoint( const InputPointType & inputPoint, OutputPointType & outputPoint,
00252     WeightsType & weights, ParameterIndexArrayType & indices, bool & inside ) const;
00254 
00255   virtual void ComputeJacobianWithRespectToParameters( const InputPointType &, JacobianType & ) const;
00256 
00258   virtual NumberOfParametersType GetNumberOfParameters() const;
00259 
00261   NumberOfParametersType GetNumberOfParametersPerDimension() const;
00262 
00263   typedef typename Superclass::SpacingType   PhysicalDimensionsType;
00264   typedef typename Superclass::PixelType     PixelType;
00265 
00266   typedef typename Superclass::MeshSizeType MeshSizeType;
00267 
00269   virtual void SetGridOrigin( const OriginType & );
00270 
00272   itkGetConstMacro( GridOrigin, OriginType );
00273 
00275   virtual void SetGridSpacing( const SpacingType & );
00276 
00278   itkGetConstMacro( GridSpacing, SpacingType );
00279 
00281   virtual void SetGridDirection( const DirectionType & );
00282 
00284   itkGetConstMacro( GridDirection, DirectionType );
00285 
00287   virtual void SetGridRegion( const RegionType & );
00288 
00290   itkGetConstMacro( GridRegion, RegionType );
00291 
00292   typedef Transform<ScalarType, itkGetStaticConstMacro(SpaceDimension),
00293                     itkGetStaticConstMacro(SpaceDimension)> BulkTransformType;
00294   typedef typename BulkTransformType::ConstPointer BulkTransformPointer;
00298   itkSetConstObjectMacro(BulkTransform, BulkTransformType);
00299   itkGetConstObjectMacro(BulkTransform, BulkTransformType);
00301 
00303   itkGetConstReferenceMacro(ValidRegion, RegionType);
00304 
00306   virtual NumberOfParametersType GetNumberOfLocalParameters() const
00307   {
00308     itkExceptionMacro("GetNumberOfLocalParameters not yet implemented.");
00309   }
00310 
00311 protected:
00313   void PrintSelf( std::ostream & os, Indent indent ) const;
00314 
00315   BSplineDeformableTransform();
00316   virtual ~BSplineDeformableTransform();
00317 
00318 private:
00319 
00321   virtual void SetFixedParametersGridSizeFromTransformDomainInformation() const;
00322 
00324   virtual void SetFixedParametersGridOriginFromTransformDomainInformation() const;
00325 
00327   virtual void SetFixedParametersGridSpacingFromTransformDomainInformation() const;
00328 
00330   virtual void SetFixedParametersGridDirectionFromTransformDomainInformation() const;
00331 
00333   virtual void SetCoefficientImageInformationFromFixedParameters();
00334 
00335   BSplineDeformableTransform( const Self & ); // purposely not implemented
00336   void operator=( const Self & );   // purposely not implemented
00337 
00339   virtual bool InsideValidRegion( ContinuousIndexType & ) const;
00340 
00349   const RegionType &    m_GridRegion;
00350   const OriginType &    m_GridOrigin;
00351   const SpacingType &   m_GridSpacing;
00352   const DirectionType & m_GridDirection;
00353 
00355   BulkTransformPointer m_BulkTransform;
00356 
00357   RegionType m_ValidRegion;
00358 
00360   unsigned long m_Offset;
00361   bool          m_SplineOrderOdd;
00362   IndexType     m_ValidRegionLast;
00363   IndexType     m_ValidRegionFirst;
00364 
00365   void UpdateValidGridRegion();
00366 
00367 }; // class BSplineDeformableTransform
00368 }  // namespace itk
00369 
00370 // Define instantiation macro for this template.
00371 #define ITK_TEMPLATE_BSplineDeformableTransform(_, EXPORT, TypeX, TypeY)     \
00372   namespace itk                                                              \
00373   {                                                                          \
00374   _( 3 ( class EXPORT BSplineDeformableTransform<ITK_TEMPLATE_3 TypeX> ) ) \
00375   namespace Templates                                                        \
00376   {                                                                          \
00377   typedef BSplineDeformableTransform<ITK_TEMPLATE_3 TypeX>                 \
00378   BSplineDeformableTransform##TypeY;                                       \
00379   }                                                                          \
00380   }
00381 
00382 #if ITK_TEMPLATE_EXPLICIT
00383 // template < class TScalarType, unsigned int NDimensions, unsigned int
00384 // VSplineOrder >
00385 //   const unsigned int itk::BSplineDeformableTransform<TScalarType,
00386 // NDimensions, VSplineOrder >::SpaceDimension;
00387 // template < class TScalarType, unsigned int NDimensions, unsigned int
00388 // VSplineOrder >
00389 //   const unsigned int itk::BSplineDeformableTransform<TScalarType,
00390 // NDimensions, VSplineOrder >::SplineOrder;
00391 #include "Templates/itkBSplineDeformableTransform+-.h"
00392 #endif
00393 
00394 #if ITK_TEMPLATE_TXX
00395 #include "itkBSplineDeformableTransform.hxx"
00396 #endif
00397 
00398 #endif /* __itkBSplineDeformableTransform_h */
00399