Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkThreadSafeTransform.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkThreadSafeTransform.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/07/21 22:51:26 $
00007   Version:   $Revision: 1.2 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkThreadSafeTransform_h
00018 #define __itkThreadSafeTransform_h
00019 
00020 #include "itkTransformBase.h"
00021 #include "itkPoint.h"
00022 #include "itkVector.h"
00023 #include "itkCovariantVector.h"
00024 #include "vnl/vnl_vector_fixed.h"
00025 #include "itkArray.h"
00026 #include "itkArray2D.h"
00027 
00028 #include "itkObjectFactory.h"
00029 
00030 
00031 namespace itk
00032 {
00033   
00063 template <class TScalarType,
00064           unsigned int NInputDimensions=3, 
00065           unsigned int NOutputDimensions=3>
00066 class ITK_EXPORT  Transform  : public TransformBase
00067 {
00068 public:
00070   typedef Transform                     Self;
00071   typedef TransformBase                 Superclass;
00072   typedef SmartPointer< Self >          Pointer;
00073   typedef SmartPointer< const Self >    ConstPointer;
00074 
00075   /* Since this is an abstract class the itkNewMacro() has been removed.
00076    * Making this an abstract class will prevent in practice the inifinite 
00077    * recursion that may happen if the default implementation of the GetJacobian,
00078    * TransformPoint, TransformVector methods are invoked. The forward/backward
00079    * compatibility wraps in the default implementation would result in an
00080    * infinite recursion. The recurssion is avoided in derived classes by 
00081    * providing an overloaded implementation of the non-thread-safe or the 
00082    * thread-safe version of the methods listed above.
00083    * */
00084 
00086   itkTypeMacro( Transform, TransformBase );
00087 
00089   itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions);
00090   itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
00092 
00094   unsigned int GetInputSpaceDimension(void) const {return NInputDimensions;}
00095 
00097   unsigned int GetOutputSpaceDimension(void) const {return NOutputDimensions;}
00098 
00100   typedef  TScalarType     ScalarType;
00101 
00103   typedef  typename Superclass::ParametersType         ParametersType;
00104 
00106   typedef  Array2D< double >                           JacobianType;
00107 
00109   typedef Vector<TScalarType, NInputDimensions>  InputVectorType;
00110   typedef Vector<TScalarType, NOutputDimensions> OutputVectorType;
00111 
00113   typedef CovariantVector<TScalarType, NInputDimensions>  InputCovariantVectorType;
00114   typedef CovariantVector<TScalarType, NOutputDimensions> OutputCovariantVectorType;
00115 
00117   typedef vnl_vector_fixed<TScalarType, NInputDimensions>  InputVnlVectorType;
00118   typedef vnl_vector_fixed<TScalarType, NOutputDimensions> OutputVnlVectorType;
00119 
00121   typedef Point<TScalarType, NInputDimensions>   InputPointType;
00122   typedef Point<TScalarType, NOutputDimensions>  OutputPointType;
00123 
00125   virtual OutputPointType TransformPoint( const InputPointType  & inputPoint, 
00126                                           unsigned int itkNotUsed( threadId ) ) const
00127     { return this->TransformPoint( inputPoint ); } // Backward compatibility for non-thread-safe transforms.
00128   virtual OutputPointType TransformPoint(const InputPointType  & inputPoint ) const
00129     { return this->TransformPoint( inputPoint, 0 ); } // Forward compatibility for non-thread-safe transforms.
00131 
00133   virtual OutputVectorType    TransformVector( const InputVectorType & inputVector, 
00134                                                unsigned int itkNotUsed( threadId ) ) const
00135     { return this->TransformVector( inputVector ); } // Backward compatibility for non-thread-safe transforms.
00136   virtual OutputVectorType    TransformVector(const InputVectorType & inputVector ) const
00137     { return this->TransformVector( inputVector, 0 ); } // Forward compatibility for non-thread-safe transforms.
00139 
00141   virtual OutputVnlVectorType TransformVector( const InputVnlVectorType & inputVnlVector,
00142                                                unsigned int itkNotUsed( threadId ) ) const
00143     { return  this->TransformVector( inputVnlVector ); } // Backward compatibility for non-thread-safe transforms.
00144   virtual OutputVnlVectorType TransformVector(const InputVnlVectorType & inputVnlVector ) const
00145     { return TransformVector( inputVnlVector, 0 ); } // Forward compatibility for non-thread-safe transforms.
00147 
00149   virtual OutputCovariantVectorType TransformCovariantVector(
00150     const InputCovariantVectorType &inputCovariantVector, 
00151     unsigned int itkNotUsed( threadId ) ) const
00152     { return this->TransformCovariantVector( inputCovariantVector ); } // Backward compatibility for non-thread-safe transforms.
00153   virtual OutputCovariantVectorType TransformCovariantVector(
00154     const InputCovariantVectorType & inputCovariantVector ) const
00155     { return TransformCovariantVector( inputCovariantVector, 0 ); }  // Forward compatibility for non-thread-safe transforms.
00157 
00165   virtual void SetParameters( const ParametersType & ) 
00166     { itkExceptionMacro( << "Subclasses should override this method" ) }
00167 
00175   virtual void SetParametersByValue ( const ParametersType & p ) 
00176     { this->SetParameters ( p ); };
00177 
00179   virtual const ParametersType& GetParameters(void) const
00180     { itkExceptionMacro( << "Subclasses should override this method" );
00181       return m_Parameters; }
00183 
00185   virtual void SetFixedParameters( const ParametersType & ) 
00186     { itkExceptionMacro( << "Subclasses should override this method" ) };
00187 
00189   virtual const ParametersType& GetFixedParameters(void) const
00190     { itkExceptionMacro( << "Subclasses should override this method" );
00191       return m_Parameters; };
00193 
00221   virtual const JacobianType & GetJacobian( const InputPointType  & inputPoint, 
00222                                             unsigned int itkNotUsed( threadId ) ) const
00223     { return this->GetJacobian( inputPoint ); } // Backward compatibility for non-thread-safe.
00224   virtual const JacobianType & GetJacobian(const InputPointType  & inputPoint ) const
00225     { return this->GetJacobian( inputPoint, 0 ); } // Forward compatibility for non-thread-safe.
00227 
00228 
00230   virtual unsigned int GetNumberOfParameters(void) const 
00231                       { return m_Parameters.Size(); }
00232 
00235   bool GetInverse(Self*) const {return false;}
00236 
00238   virtual std::string GetTransformTypeAsString() const;
00239 
00253   virtual bool IsLinear() const { return false; }
00254 
00257   virtual void SetNumberOfThreads( unsigned int numberOfThreads ) const;
00258   itkGetConstReferenceMacro( NumberOfThreads, unsigned int );
00260 
00261 protected:
00262   Transform(); 
00263   Transform(unsigned int Dimension, unsigned int NumberOfParameters);
00264   virtual ~Transform() {};
00265   void PrintSelf(std::ostream& os, Indent indent) const;
00266 
00267 
00268   mutable ParametersType     m_Parameters;
00269   mutable ParametersType     m_FixedParameters;
00270   mutable JacobianType       m_Jacobian;
00271   mutable JacobianType     * m_ThreaderJacobian;
00272 
00273   virtual JacobianType * GetJacobianVariableForThread( unsigned int threadId=0 ) const;
00274 
00275 private:
00276   Transform(const Self&); //purposely not implemented
00277   void operator=(const Self&); //purposely not implemented
00278 
00279   mutable unsigned int       m_NumberOfThreads;
00280   
00281   unsigned int               m_JacobianDimensions;
00282   unsigned int               m_JacobianNumberOfParameters;
00283 
00284 };
00285 
00286 } // end namespace itk
00287 
00288 // Define instantiation macro for this template.
00289 #define ITK_TEMPLATE_Transform(_, EXPORT, x, y) namespace itk { \
00290   _(3(class EXPORT Transform< ITK_TEMPLATE_3 x >)) \
00291   namespace Templates { typedef Transform< ITK_TEMPLATE_3 x > Transform##y; } \
00292   }
00293 
00294 #if ITK_TEMPLATE_EXPLICIT
00295 # include "Templates/itkTransform+-.h"
00296 #endif
00297 
00298 #if ITK_TEMPLATE_TXX
00299 # include "itkThreadSafeTransform.txx"
00300 #endif
00301 
00302 #endif
00303 

Generated at Sun Sep 23 14:24:52 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000