ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkCompositeTransform.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 __itkCompositeTransform_h
00019 #define __itkCompositeTransform_h
00020 
00021 #include "itkTransform.h"
00022 
00023 #include <deque>
00024 
00025 namespace itk
00026 {
00027 
00100 template
00101 <class TScalar = double, unsigned int NDimensions = 3>
00102 class ITK_EXPORT CompositeTransform :
00103   public Transform<TScalar, NDimensions, NDimensions>
00104 {
00105 public:
00107   typedef CompositeTransform                           Self;
00108   typedef Transform<TScalar, NDimensions, NDimensions> Superclass;
00109   typedef SmartPointer<Self>                           Pointer;
00110   typedef SmartPointer<const Self>                     ConstPointer;
00111 
00113   itkTypeMacro( CompositeTransform, Transform );
00114 
00116   itkNewMacro( Self );
00117 
00119   typedef Superclass                   TransformType;
00120   typedef typename Superclass::Pointer TransformTypePointer;
00121 
00123   typedef typename Superclass::InverseTransformBasePointer
00124   InverseTransformBasePointer;
00125 
00127   typedef typename Superclass::ScalarType ScalarType;
00128 
00130   typedef typename Superclass::ParametersType      ParametersType;
00131   typedef typename Superclass::ParametersValueType ParametersValueType;
00132 
00134   typedef typename Superclass::DerivativeType DerivativeType;
00135 
00137   typedef typename Superclass::JacobianType JacobianType;
00138 
00140   typedef typename Superclass::InputPointType  InputPointType;
00141   typedef typename Superclass::OutputPointType OutputPointType;
00142 
00144   typedef typename Superclass::InputVectorType  InputVectorType;
00145   typedef typename Superclass::OutputVectorType OutputVectorType;
00146 
00148   typedef typename Superclass::InputCovariantVectorType
00149   InputCovariantVectorType;
00150   typedef typename Superclass::OutputCovariantVectorType
00151   OutputCovariantVectorType;
00152 
00154   typedef typename Superclass::InputVnlVectorType  InputVnlVectorType;
00155   typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
00156 
00158   typedef typename Superclass::InputVectorPixelType  InputVectorPixelType;
00159   typedef typename Superclass::OutputVectorPixelType OutputVectorPixelType;
00160 
00162   typedef typename Superclass::InputDiffusionTensor3DType  InputDiffusionTensor3DType;
00163   typedef typename Superclass::OutputDiffusionTensor3DType OutputDiffusionTensor3DType;
00164 
00166   typedef typename Superclass::InputSymmetricSecondRankTensorType
00167     InputSymmetricSecondRankTensorType;
00168   typedef typename Superclass::OutputSymmetricSecondRankTensorType
00169     OutputSymmetricSecondRankTensorType;
00170 
00172   typedef std::deque<TransformTypePointer> TransformQueueType;
00173 
00175   typedef std::deque<bool> TransformsToOptimizeFlagsType;
00176 
00178   typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
00179 
00181   itkStaticConstMacro( InputDimension, unsigned int, NDimensions );
00182   itkStaticConstMacro( OutputDimension, unsigned int, NDimensions );
00184 
00190   void AddTransform( TransformType *t  )
00191   {
00192     this->PushBackTransform( t ); /* Also adds to TransformsToOptimize list */
00193   }
00194 
00195   void RemoveTransform()
00196   {
00197     this->PopBackTransform(); /* Also removes to TransformsToOptimize list */
00198   }
00199 
00201   const
00202   TransformTypePointer GetFrontTransform()
00203   {
00204     return this->m_TransformQueue.front();
00205   }
00206 
00207   const
00208   TransformTypePointer GetBackTransform()
00209   {
00210     return this->m_TransformQueue.back();
00211   }
00212 
00213   const
00214   TransformTypePointer GetNthTransform( size_t n ) const
00215   {
00216     return this->m_TransformQueue[n];
00217   }
00218 
00221   void SetNthTransformToOptimize( size_t i, bool state )
00222   {
00223     this->m_TransformsToOptimizeFlags.at(i) = state;
00224     this->Modified();
00225   }
00226 
00227   void SetNthTransformToOptimizeOn( size_t i )
00228   {
00229     this->SetNthTransformToOptimize( i, true );
00230   }
00231 
00232   void SetNthTransformToOptimizeOff( size_t i )
00233   {
00234     this->SetNthTransformToOptimize( i, false );
00235   }
00236 
00237   void SetAllTransformsToOptimize( bool state )
00238   {
00239     this->m_TransformsToOptimizeFlags.assign(
00240       this->m_TransformsToOptimizeFlags.size(), state );
00241     this->Modified();
00242   }
00243 
00244   void SetAllTransformsToOptimizeOn()
00245   {
00246     this->SetAllTransformsToOptimize( true );
00247   }
00248 
00249   void SetAllTransformsToOptimizeOff()
00250   {
00251     this->SetAllTransformsToOptimize( false );
00252   }
00253 
00254   /* With AddTransform() as the only way to add a transform, we
00255    * can have this method to easily allow user to optimize only
00256    * the transform added most recenlty. */
00257   void SetOnlyMostRecentTransformToOptimizeOn()
00258   {
00259     this->SetAllTransformsToOptimize( false );
00260     this->SetNthTransformToOptimizeOn( this->GetNumberOfTransforms() - 1 );
00261   }
00262 
00263   /* Get whether the Nth transform is set to be optimzied */
00264   /* NOTE: ambiguous function name here - are we getting if the Nth transform
00265       is set to be optimized, or the Nth of the transforms that are set to be
00266       optimized? */
00267   bool GetNthTransformToOptimize( size_t i ) const
00268   {
00269     return this->m_TransformsToOptimizeFlags.at(i);
00270   }
00271 
00273   const TransformQueueType & GetTransformQueue() const
00274   {
00275     return this->m_TransformQueue;
00276   }
00277 
00279   const TransformsToOptimizeFlagsType & GetTransformsToOptimizeFlags() const
00280   {
00281     return this->m_TransformsToOptimizeFlags;
00282   }
00283 
00285   bool IsTransformQueueEmpty()
00286   {
00287     return this->m_TransformQueue.empty();
00288   }
00289 
00290   size_t GetNumberOfTransforms() const
00291   {
00292     return this->m_TransformQueue.size();
00293   }
00294 
00295   void ClearTransformQueue()
00296   {
00297     this->m_TransformQueue.clear();
00298     this->m_TransformsToOptimizeFlags.clear();
00299     this->Modified();
00300   }
00301 
00303   bool GetInverse( Self *inverse ) const;
00304 
00305   virtual InverseTransformBasePointer GetInverseTransform() const;
00306 
00321   virtual OutputPointType TransformPoint( const InputPointType & inputPoint ) const;
00322 
00323   /* Note: why was the 'isInsideTransformRegion' flag used below?
00324   {
00325     bool isInside = true;
00326 
00327     return this->TransformPoint( inputPoint, isInside );
00328   }
00329   virtual OutputPointType TransformPoint( const InputPointType& thisPoint,
00330                                           bool &isInsideTransformRegion ) const;
00331   */
00333   using Superclass::TransformVector;
00334   virtual OutputVectorType TransformVector(const InputVectorType &) const;
00335 
00336   virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector) const;
00337 
00338   virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector ) const;
00339 
00340   virtual OutputVectorType TransformVector(const InputVectorType & inputVector,
00341                                            const InputPointType & inputPoint ) const;
00342 
00343   virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVector,
00344                                               const InputPointType & inputPoint ) const;
00345 
00346   virtual OutputVectorPixelType TransformVector(const InputVectorPixelType & inputVector,
00347                                                 const InputPointType & inputPoint ) const;
00348 
00350   using Superclass::TransformCovariantVector;
00351   virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const;
00352 
00353   virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &) const;
00354 
00355   virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType & inputVector,
00356                                                              const InputPointType & inputPoint ) const;
00357 
00358   virtual OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType & inputVector,
00359                                                          const InputPointType & inputPoint ) const;
00360 
00362   using Superclass::TransformDiffusionTensor3D;
00363   virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
00364     const InputDiffusionTensor3DType & inputTensor) const;
00365 
00366   virtual OutputVectorPixelType TransformDiffusionTensor3D(
00367     const InputVectorPixelType & inputTensor) const;
00368 
00369   virtual OutputDiffusionTensor3DType TransformDiffusionTensor3D(
00370     const InputDiffusionTensor3DType & inputTensor,
00371     const InputPointType & inputPoint ) const;
00372 
00373   virtual OutputVectorPixelType TransformDiffusionTensor3D(
00374     const InputVectorPixelType & inputTensor,
00375     const InputPointType & inputPoint ) const;
00376 
00378   using Superclass::TransformSymmetricSecondRankTensor;
00379   virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
00380     const InputSymmetricSecondRankTensorType & inputTensor) const;
00381 
00382   virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
00383     const InputVectorPixelType & inputTensor) const;
00384 
00385   virtual OutputSymmetricSecondRankTensorType TransformSymmetricSecondRankTensor(
00386     const InputSymmetricSecondRankTensorType & inputTensor,
00387     const InputPointType & inputPoint ) const;
00388 
00389   virtual OutputVectorPixelType TransformSymmetricSecondRankTensor(
00390     const InputVectorPixelType & inputTensor,
00391     const InputPointType & inputPoint ) const;
00392 
00393   virtual bool IsLinear() const;
00394 
00400   virtual const ParametersType & GetParameters(void) const;
00401 
00402   /* SetParameters only for transforms that are set to be optimized */
00403   virtual void  SetParameters(const ParametersType & p);
00404 
00405   /* GetFixedParameters only for transforms that are set to be optimized */
00406   virtual const ParametersType & GetFixedParameters(void) const;
00407 
00408   /* SetFixedParameters only for transforms that are set to be optimized */
00409   virtual void  SetFixedParameters(const ParametersType & fixedParameters);
00410 
00411   /* Get total number of parameters for transforms that are set to be
00412    * optimized */
00413   virtual NumberOfParametersType GetNumberOfParameters(void) const;
00414 
00415   /* Get total number of local parameters for transforms that are set
00416    * to be optimized */
00417   virtual NumberOfParametersType GetNumberOfLocalParameters(void) const;
00418 
00419   /* Get total number of fixed parameters for transforms that are set
00420    * to be optimized */
00421   virtual NumberOfParametersType GetNumberOfFixedParameters(void) const;
00422 
00423   /* Prepare the transform for use, e.g. in registration framework.
00424    * Must be called before registration to optimize parameter storage
00425    * for more efficient operation, particularly with high-dimensionality
00426    * sub-transforms. */
00427   // virtual void PrepareForUse(void);
00428 
00437   virtual void UpdateTransformParameters( DerivativeType & update, ScalarType  factor = 1.0 );
00438 
00444   virtual bool HasLocalSupport() const;
00445 
00450   virtual void ComputeJacobianWithRespectToParameters(const InputPointType  & p, JacobianType & j) const;
00451 
00452   virtual void ComputeJacobianWithRespectToPosition(const InputPointType &,
00453                                                     JacobianType &) const
00454   {
00455     itkExceptionMacro( "ComputeJacobianWithRespectToPosition not yet implemented "
00456                        "for " << this->GetNameOfClass() );
00457   }
00458 
00459 protected:
00460   CompositeTransform();
00461   virtual ~CompositeTransform();
00462   void PrintSelf( std::ostream& os, Indent indent ) const;
00463 
00465   virtual typename LightObject::Pointer InternalClone() const;
00466 
00467   void PushFrontTransform( TransformTypePointer t  )
00468   {
00469     this->m_TransformQueue.push_front( t );
00470     /* Add element to list of flags, and set true by default */
00471     this->m_TransformsToOptimizeFlags.push_front( true );
00472     this->Modified();
00473   }
00474 
00475   void PushBackTransform( TransformTypePointer t  )
00476   {
00477     this->m_TransformQueue.push_back( t );
00478     /* Add element to list of flags, and set true by default */
00479     this->m_TransformsToOptimizeFlags.push_back( true );
00480     this->Modified();
00481   }
00482 
00483   void PopFrontTransform()
00484   {
00485     this->m_TransformQueue.pop_front();
00486     this->m_TransformsToOptimizeFlags.pop_front();
00487     this->Modified();
00488   }
00489 
00490   void PopBackTransform()
00491   {
00492     this->m_TransformQueue.pop_back();
00493     this->m_TransformsToOptimizeFlags.pop_back();
00494     this->Modified();
00495   }
00496 
00502   // void UnifyParameterMemory(void);
00503 
00505   mutable TransformQueueType m_TransformQueue;
00506 
00508   TransformQueueType & GetTransformsToOptimizeQueue() const;
00509 
00510   mutable TransformQueueType            m_TransformsToOptimizeQueue;
00511   mutable TransformsToOptimizeFlagsType m_TransformsToOptimizeFlags;
00512 private:
00513   CompositeTransform( const Self & ); // purposely not implemented
00514   void operator=( const Self & );     // purposely not implemented
00515 
00516   mutable unsigned long m_PreviousTransformsToOptimizeUpdateTime;
00517 };
00518 
00519 } // end namespace itk
00520 
00521 #if ITK_TEMPLATE_EXPLICIT
00522 #include "Templates/itkCompositeTransform+-.h"
00523 #endif
00524 
00525 #if ITK_TEMPLATE_TXX
00526 #include "itkCompositeTransform.hxx"
00527 #endif
00528 
00529 #endif // __itkCompositeTransform_h
00530