IGSTK

/build/buildd/igstk-4.2.0/Source/igstkCoordinateSystemDelegator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Image Guided Surgery Software Toolkit
00004   Module:    $RCSfile: igstkCoordinateSystemDelegator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-02 21:00:06 $
00007   Version:   $Revision: 1.5 $
00008 
00009   Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
00010   See IGSTKCopyright.txt or http://www.igstk.org/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 
00018 #ifndef __igstkCoordinateSystemDelegator_h
00019 #define __igstkCoordinateSystemDelegator_h
00020 
00021 #include "igstkCoordinateSystem.h"
00022 #include "igstkCoordinateSystemTransformToResult.h"
00023 #include "igstkCoordinateSystemTransformToErrorResult.h"
00024 #include "igstkCoordinateSystemSetTransformResult.h"
00025 
00026 namespace igstk
00027 {
00028 
00048 class CoordinateSystemDelegator : public Object
00049 {
00050 public: 
00051 
00053   igstkStandardClassTraitsMacro( CoordinateSystemDelegator, Object )
00054   
00055   
00058   template < class TParentPointer >
00059   void RequestSetTransformAndParent( const Transform & transformToParent, 
00060                                      TParentPointer parent )
00061     {
00062     if( !(parent) ) // This expression must be suitable for both 
00063                     // Smart and Raw pointers.
00064       {
00065       igstkPushInputMacro( NullParent );
00066       m_StateMachine.ProcessInputs();
00067       return;
00068       }
00069     else
00070       {
00071       const CoordinateSystem* parentReferenceSystem = 
00072       igstk::Friends::CoordinateSystemHelper
00073                                     ::GetCoordinateSystem( parent );
00074 
00076       this->m_CoordinateSystem->RequestSetTransformAndParent(
00077                                                       transformToParent,
00078                                                       parentReferenceSystem);
00079 
00080       return;
00081       }
00082     }
00083 
00084   // This method updates the transform between this object and its parent 
00085   void RequestUpdateTransformToParent( const Transform & transformToParent )
00086     {
00087     this->m_CoordinateSystem->RequestUpdateTransformToParent(
00088                                                          transformToParent);
00089     }
00090 
00092   void RequestGetTransformToParent();
00093 
00095   void RequestDetachFromParent()
00096     {
00097     this->m_CoordinateSystem->RequestDetachFromParent();
00098     }
00099 
00111   template <class TTarget>
00112   void RequestComputeTransformTo(const TTarget & target)
00113     {
00114     if( !(target) )
00115       {
00116       igstkPushInputMacro( NullTarget );
00117       m_StateMachine.ProcessInputs();
00118       return;
00119       }
00120 
00122     const CoordinateSystem* targetCoordSys = 
00123       igstk::Friends::CoordinateSystemHelper::
00124                                       GetCoordinateSystem( target );
00125 
00127     this->m_CoordinateSystem->RequestComputeTransformTo(
00128                                                              targetCoordSys);
00129     }
00130 
00132   typedef igstk::CoordinateSystem              CoordinateSystemType;
00133 
00139   bool IsCoordinateSystem( const CoordinateSystemType* ) const;
00140 
00142   void PrintSelf( std::ostream& os, itk::Indent indent ) const;
00143 
00145   void SetName( const char* name );
00146   void SetName( const std::string& name );
00147   const char* GetName() const;
00148 
00150   void SetType( const char* type );
00151   void SetType( const std::string& type );
00152   const char* GetType() const;
00153   
00154 protected:
00155   CoordinateSystemDelegator();
00156   ~CoordinateSystemDelegator();
00157 
00158 private:
00160   CoordinateSystemDelegator(const CoordinateSystemDelegator& );
00161 
00163   CoordinateSystemDelegator& operator=(const CoordinateSystemDelegator&);
00164 
00166   igstkDeclareStateMacro( Idle );
00167 
00169   igstkDeclareInputMacro( NullParent );
00170   igstkDeclareInputMacro( NullTarget );
00171 
00175   igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper );
00176 
00182   const CoordinateSystem * GetCoordinateSystem() const;
00183 
00187   CoordinateSystem::Pointer      m_CoordinateSystem;
00188 
00190   void NullParentProcessing();
00191 
00193   void NullTargetProcessing();
00194 
00198   typedef ::itk::ReceptorMemberCommand< Self > CoordinateSystemObserverType;
00199 
00201   CoordinateSystemObserverType::Pointer m_CoordinateSystemObserver;
00202 
00206   void ObserverCallback(const ::itk::EventObject & eventvar);
00207 
00208 }; // class CoordinateSystemDelegator
00209 
00210 }
00211 
00212 #endif