IGSTK
/build/buildd/igstk-4.4.0/Source/igstkCoordinateSystemInterfaceMacros.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   Image Guided Surgery Software Toolkit
00004 Module:    $RCSfile: igstkCoordinateSystemInterfaceMacros.h,v $
00005 Language:  C++
00006 Date:      $Date: 2009-08-31 20:34:48 $
00007 Version:   $Revision: 1.9 $
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 __igstkCoordinateSystemInterfaceMacros_h
00019 #define __igstkCoordinateSystemInterfaceMacros_h
00020 
00021 #include "igstkCoordinateSystemTransformToResult.h"
00022 #include "igstkCoordinateSystemTransformToErrorResult.h"
00023 #include "igstkCoordinateSystemSetTransformResult.h"
00024 #include "igstkCoordinateSystemDelegator.h"
00025 #include "igstkConfigure.h"
00026 
00027 #ifdef IGSTK_USE_SceneGraphVisualization
00028 #include "igstkSceneGraphObserver.h"
00029 #endif
00030 
00031 namespace igstk 
00032 {
00033 
00046 #ifdef IGSTK_USE_SceneGraphVisualization
00047 #define igstkCoordinateSystemClassInterfaceMacro() \
00048 public: \
00049   template <class TTargetPointer> \
00050   void RequestComputeTransformTo(const TTargetPointer & target) \
00051     { \
00052     m_CoordinateSystemDelegator->RequestComputeTransformTo(target);\
00053     } \
00054   void RequestGetTransformToParent() \
00055     { \
00056     m_CoordinateSystemDelegator->RequestGetTransformToParent(); \
00057     } \
00058   void RequestDetachFromParent()\
00059     { \
00060     m_CoordinateSystemDelegator->RequestDetachFromParent();\
00061     } \
00062   template < class TParentPointer > \
00063   void RequestSetTransformAndParent( const ::igstk::Transform & transformToParent,\
00064                                      TParentPointer parent ) \
00065     { \
00066     if ( this->IsInternalTransformRequired() == false ) \
00067       { \
00068       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00069                                      transformToParent, parent); \
00070       } \
00071     else \
00072       { \
00073       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00074       ::igstk::Transform transformToParentWithInternalTransform = \
00075                                ::igstk::Transform::TransformCompose( \
00076                                               transformToParent, \
00077                                               internalTransform ); \
00078       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00079                           transformToParentWithInternalTransform, parent); \
00080       }\
00081     } \
00082   void RequestUpdateTransformToParent( const ::igstk::Transform & transformToParent )\
00083     { \
00084     if ( this->IsInternalTransformRequired() == false ) \
00085       { \
00086       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( transformToParent );\
00087       } \
00088     else \
00089       { \
00090       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00091       ::igstk::Transform transformToParentWithInternalTransform = \
00092       ::igstk::Transform::TransformCompose( \
00093                                            transformToParent, \
00094                                            internalTransform ); \
00095       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( \
00096                                    transformToParentWithInternalTransform); \
00097       }\
00098     } \
00099   bool IsCoordinateSystem(const ::igstk::CoordinateSystem* inCS) const  \
00100     { \
00101     return m_CoordinateSystemDelegator-> \
00102       IsCoordinateSystem( inCS ); \
00103     } \
00104   void RequestSetCoordinateSystemName(const char * name) \
00105     { \
00106     m_CoordinateSystemDelegator->SetName( name ); \
00107     } \
00108   const char * RequestGetCoordinateSystemName() const \
00109     { \
00110     return m_CoordinateSystemDelegator->GetName(); \
00111     } \
00112 protected: \
00113   virtual bool IsInternalTransformRequired() \
00114     { \
00115     return false; \
00116     } \
00117   virtual ::igstk::Transform GetInternalTransform() const \
00118     { \
00119     ::igstk::Transform identity; \
00120     identity.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() ); \
00121     return identity; \
00122     } \
00123   const ::igstk::CoordinateSystem* GetCoordinateSystem() const  \
00124     { \
00125     return \
00126       igstk::Friends::CoordinateSystemHelper:: \
00127         GetCoordinateSystem(  \
00128                        m_CoordinateSystemDelegator.GetPointer() ); \
00129     } \
00130 private: \
00131   ::igstk::CoordinateSystemDelegator::Pointer \
00132                                   m_CoordinateSystemDelegator; \
00133   typedef ::itk::ReceptorMemberCommand< Self > CoordinateSystemObserverType; \
00134   CoordinateSystemObserverType::Pointer m_CoordinateSystemObserver; \
00135   SceneGraphObserver::Pointer    m_SceneGraphObserver; \
00136   void ObserverCallback(const ::itk::EventObject & eventvar) \
00137     { \
00138     this->InvokeEvent( eventvar ); \
00139     } \
00140   igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper ); 
00141 
00142 #else
00143 
00144 #define igstkCoordinateSystemClassInterfaceMacro() \
00145 public: \
00146   template <class TTargetPointer> \
00147   void RequestComputeTransformTo(const TTargetPointer & target) \
00148     { \
00149     m_CoordinateSystemDelegator->RequestComputeTransformTo(target);\
00150     } \
00151     void RequestGetTransformToParent() \
00152     { \
00153     m_CoordinateSystemDelegator->RequestGetTransformToParent(); \
00154     } \
00155     void RequestDetachFromParent()\
00156     { \
00157     m_CoordinateSystemDelegator->RequestDetachFromParent();\
00158     } \
00159     template < class TParentPointer > \
00160     void RequestSetTransformAndParent( const ::igstk::Transform & transformToParent,\
00161     TParentPointer parent ) \
00162     { \
00163     std::stringstream tempStream; \
00164     tempStream << this->GetNameOfClass() << " 0x"; \
00165     tempStream << static_cast<void*>(this); \
00166     std::string name = tempStream.str(); \
00167     m_CoordinateSystemDelegator->SetName( name.c_str() );\
00168     if ( this->IsInternalTransformRequired() == false ) \
00169       { \
00170       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00171       transformToParent, parent); \
00172       } \
00173     else \
00174       { \
00175       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00176       ::igstk::Transform transformToParentWithInternalTransform = \
00177       ::igstk::Transform::TransformCompose( \
00178       transformToParent, \
00179       internalTransform ); \
00180       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00181       transformToParentWithInternalTransform, parent); \
00182       }\
00183     } \
00184     void RequestUpdateTransformToParent( const ::igstk::Transform & transformToParent )\
00185     { \
00186     if ( this->IsInternalTransformRequired() == false ) \
00187       { \
00188       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( transformToParent );\
00189       } \
00190     else \
00191       { \
00192       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00193       ::igstk::Transform transformToParentWithInternalTransform = \
00194       ::igstk::Transform::TransformCompose( \
00195       transformToParent, \
00196       internalTransform ); \
00197       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( \
00198       transformToParentWithInternalTransform); \
00199       }\
00200     } \
00201     bool IsCoordinateSystem(const ::igstk::CoordinateSystem* inCS) const  \
00202     { \
00203     return m_CoordinateSystemDelegator-> \
00204     IsCoordinateSystem( inCS ); \
00205     } \
00206 protected: \
00207   virtual bool IsInternalTransformRequired() \
00208     { \
00209     return false; \
00210     } \
00211     virtual ::igstk::Transform GetInternalTransform() const \
00212     { \
00213     ::igstk::Transform identity; \
00214     identity.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() ); \
00215     return identity; \
00216     } \
00217     const ::igstk::CoordinateSystem* GetCoordinateSystem() const  \
00218     { \
00219     return \
00220     igstk::Friends::CoordinateSystemHelper:: \
00221     GetCoordinateSystem(  \
00222     m_CoordinateSystemDelegator.GetPointer() ); \
00223     } \
00224 private: \
00225   ::igstk::CoordinateSystemDelegator::Pointer \
00226   m_CoordinateSystemDelegator; \
00227   typedef ::itk::ReceptorMemberCommand< Self > CoordinateSystemObserverType; \
00228   CoordinateSystemObserverType::Pointer m_CoordinateSystemObserver; \
00229   void ObserverCallback(const ::itk::EventObject & eventvar) \
00230     { \
00231     this->InvokeEvent( eventvar ); \
00232     } \
00233     igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper ); 
00234 
00235 #endif
00236 
00242 #ifdef IGSTK_USE_SceneGraphVisualization
00243 #define igstkCoordinateSystemClassInterfaceConstructorMacro() \
00244   m_CoordinateSystemObserver = CoordinateSystemObserverType::New(); \
00245   m_CoordinateSystemObserver->SetCallbackFunction(this, \
00246                                                    &Self::ObserverCallback); \
00247   m_CoordinateSystemDelegator = \
00248                           ::igstk::CoordinateSystemDelegator::New(); \
00249   m_SceneGraphObserver = SceneGraphObserver::New(); \
00250   m_CoordinateSystemDelegator->AddObserver( \
00251     ::igstk::CoordinateSystemTransformToNullTargetEvent()   \
00252     , m_CoordinateSystemObserver ); \
00253   m_CoordinateSystemDelegator->AddObserver( \
00254     ::igstk::CoordinateSystemSetTransformEvent() \
00255     , m_CoordinateSystemObserver); \
00256   m_SceneGraphObserver->ObserveTransformEventsFrom(this);\
00257   m_CoordinateSystemDelegator->AddObserver( \
00258     ::igstk::CoordinateSystemTransformToDisconnectedEvent() \
00259     , m_CoordinateSystemObserver ); \
00260   m_CoordinateSystemDelegator->AddObserver( \
00261     ::igstk::CoordinateSystemNullParentEvent() \
00262     , m_CoordinateSystemObserver ); \
00263   m_CoordinateSystemDelegator->AddObserver( \
00264     ::igstk::CoordinateSystemThisParentEvent() \
00265     , m_CoordinateSystemObserver ); \
00266   m_CoordinateSystemDelegator->AddObserver( \
00267     ::igstk::CoordinateSystemParentCycleEvent() \
00268     , m_CoordinateSystemObserver ); \
00269   m_CoordinateSystemDelegator->AddObserver( \
00270     ::igstk::CoordinateSystemTransformToEvent() \
00271     , m_CoordinateSystemObserver ); \
00272   std::stringstream tempStream; \
00273   tempStream << this->GetNameOfClass() << " 0x"; \
00274   tempStream << static_cast<void*>(this); \
00275   std::string name = tempStream.str(); \
00276   m_CoordinateSystemDelegator->SetType( this->GetNameOfClass() );\
00277   m_CoordinateSystemDelegator->SetName( name.c_str() );
00278 
00279 #else
00280 
00281 #define igstkCoordinateSystemClassInterfaceConstructorMacro() \
00282   m_CoordinateSystemObserver = CoordinateSystemObserverType::New(); \
00283   m_CoordinateSystemObserver->SetCallbackFunction(this, \
00284   &Self::ObserverCallback); \
00285   m_CoordinateSystemDelegator = \
00286   ::igstk::CoordinateSystemDelegator::New(); \
00287   m_CoordinateSystemDelegator->AddObserver( \
00288   ::igstk::CoordinateSystemTransformToNullTargetEvent()   \
00289   , m_CoordinateSystemObserver ); \
00290   m_CoordinateSystemDelegator->AddObserver( \
00291   ::igstk::CoordinateSystemSetTransformEvent() \
00292   , m_CoordinateSystemObserver); \
00293   m_CoordinateSystemDelegator->AddObserver( \
00294   ::igstk::CoordinateSystemTransformToDisconnectedEvent() \
00295   , m_CoordinateSystemObserver ); \
00296   m_CoordinateSystemDelegator->AddObserver( \
00297   ::igstk::CoordinateSystemNullParentEvent() \
00298   , m_CoordinateSystemObserver ); \
00299   m_CoordinateSystemDelegator->AddObserver( \
00300   ::igstk::CoordinateSystemThisParentEvent() \
00301   , m_CoordinateSystemObserver ); \
00302   m_CoordinateSystemDelegator->AddObserver( \
00303   ::igstk::CoordinateSystemParentCycleEvent() \
00304   , m_CoordinateSystemObserver ); \
00305   m_CoordinateSystemDelegator->AddObserver( \
00306   ::igstk::CoordinateSystemTransformToEvent() \
00307   , m_CoordinateSystemObserver ); \
00308   std::stringstream tempStream; \
00309   tempStream << this->GetNameOfClass() << " 0x"; \
00310   tempStream << static_cast<void*>(this); \
00311   std::string name = tempStream.str(); \
00312   m_CoordinateSystemDelegator->SetType( this->GetNameOfClass() );\
00313   m_CoordinateSystemDelegator->SetName( name.c_str() );
00314 #endif
00315 
00316 } // end namespace igstk
00317 
00318 #endif // #ifndef __igstkCoordinateSystemInterfaceMacros_h