IGSTK

/build/buildd/igstk-4.2.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-02-02 21:00:06 $
00007 Version:   $Revision: 1.8 $
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       std::stringstream tempStream; \
00067     tempStream << this->GetNameOfClass() << " 0x"; \
00068     tempStream << static_cast<void*>(this); \
00069     std::string name = tempStream.str(); \
00070     m_CoordinateSystemDelegator->SetName( name.c_str() );\
00071     if ( this->IsInternalTransformRequired() == false ) \
00072       { \
00073       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00074                                      transformToParent, parent); \
00075       } \
00076     else \
00077       { \
00078       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00079       ::igstk::Transform transformToParentWithInternalTransform = \
00080                                ::igstk::Transform::TransformCompose( \
00081                                               transformToParent, \
00082                                               internalTransform ); \
00083       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00084                           transformToParentWithInternalTransform, parent); \
00085       }\
00086     } \
00087   void RequestUpdateTransformToParent( const ::igstk::Transform & transformToParent )\
00088     { \
00089     if ( this->IsInternalTransformRequired() == false ) \
00090       { \
00091       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( transformToParent );\
00092       } \
00093     else \
00094       { \
00095       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00096       ::igstk::Transform transformToParentWithInternalTransform = \
00097       ::igstk::Transform::TransformCompose( \
00098                                            transformToParent, \
00099                                            internalTransform ); \
00100       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( \
00101                                    transformToParentWithInternalTransform); \
00102       }\
00103     } \
00104   bool IsCoordinateSystem(const ::igstk::CoordinateSystem* inCS) const  \
00105     { \
00106     return m_CoordinateSystemDelegator-> \
00107       IsCoordinateSystem( inCS ); \
00108     } \
00109 protected: \
00110   virtual bool IsInternalTransformRequired() \
00111     { \
00112     return false; \
00113     } \
00114   virtual ::igstk::Transform GetInternalTransform() const \
00115     { \
00116     ::igstk::Transform identity; \
00117     identity.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() ); \
00118     return identity; \
00119     } \
00120   const ::igstk::CoordinateSystem* GetCoordinateSystem() const  \
00121     { \
00122     return \
00123       igstk::Friends::CoordinateSystemHelper:: \
00124         GetCoordinateSystem(  \
00125                        m_CoordinateSystemDelegator.GetPointer() ); \
00126     } \
00127 private: \
00128   ::igstk::CoordinateSystemDelegator::Pointer \
00129                                   m_CoordinateSystemDelegator; \
00130   typedef ::itk::ReceptorMemberCommand< Self > CoordinateSystemObserverType; \
00131   CoordinateSystemObserverType::Pointer m_CoordinateSystemObserver; \
00132   SceneGraphObserver::Pointer    m_SceneGraphObserver; \
00133   void ObserverCallback(const ::itk::EventObject & eventvar) \
00134     { \
00135     this->InvokeEvent( eventvar ); \
00136     } \
00137   igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper ); 
00138 
00139 #else
00140 
00141 #define igstkCoordinateSystemClassInterfaceMacro() \
00142 public: \
00143   template <class TTargetPointer> \
00144   void RequestComputeTransformTo(const TTargetPointer & target) \
00145     { \
00146     m_CoordinateSystemDelegator->RequestComputeTransformTo(target);\
00147     } \
00148     void RequestGetTransformToParent() \
00149     { \
00150     m_CoordinateSystemDelegator->RequestGetTransformToParent(); \
00151     } \
00152     void RequestDetachFromParent()\
00153     { \
00154     m_CoordinateSystemDelegator->RequestDetachFromParent();\
00155     } \
00156     template < class TParentPointer > \
00157     void RequestSetTransformAndParent( const ::igstk::Transform & transformToParent,\
00158     TParentPointer parent ) \
00159     { \
00160     std::stringstream tempStream; \
00161     tempStream << this->GetNameOfClass() << " 0x"; \
00162     tempStream << static_cast<void*>(this); \
00163     std::string name = tempStream.str(); \
00164     m_CoordinateSystemDelegator->SetName( name.c_str() );\
00165     if ( this->IsInternalTransformRequired() == false ) \
00166       { \
00167       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00168       transformToParent, parent); \
00169       } \
00170     else \
00171       { \
00172       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00173       ::igstk::Transform transformToParentWithInternalTransform = \
00174       ::igstk::Transform::TransformCompose( \
00175       transformToParent, \
00176       internalTransform ); \
00177       m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
00178       transformToParentWithInternalTransform, parent); \
00179       }\
00180     } \
00181     void RequestUpdateTransformToParent( const ::igstk::Transform & transformToParent )\
00182     { \
00183     if ( this->IsInternalTransformRequired() == false ) \
00184       { \
00185       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( transformToParent );\
00186       } \
00187     else \
00188       { \
00189       ::igstk::Transform internalTransform = this->GetInternalTransform(); \
00190       ::igstk::Transform transformToParentWithInternalTransform = \
00191       ::igstk::Transform::TransformCompose( \
00192       transformToParent, \
00193       internalTransform ); \
00194       m_CoordinateSystemDelegator->RequestUpdateTransformToParent( \
00195       transformToParentWithInternalTransform); \
00196       }\
00197     } \
00198     bool IsCoordinateSystem(const ::igstk::CoordinateSystem* inCS) const  \
00199     { \
00200     return m_CoordinateSystemDelegator-> \
00201     IsCoordinateSystem( inCS ); \
00202     } \
00203 protected: \
00204   virtual bool IsInternalTransformRequired() \
00205     { \
00206     return false; \
00207     } \
00208     virtual ::igstk::Transform GetInternalTransform() const \
00209     { \
00210     ::igstk::Transform identity; \
00211     identity.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() ); \
00212     return identity; \
00213     } \
00214     const ::igstk::CoordinateSystem* GetCoordinateSystem() const  \
00215     { \
00216     return \
00217     igstk::Friends::CoordinateSystemHelper:: \
00218     GetCoordinateSystem(  \
00219     m_CoordinateSystemDelegator.GetPointer() ); \
00220     } \
00221 private: \
00222   ::igstk::CoordinateSystemDelegator::Pointer \
00223   m_CoordinateSystemDelegator; \
00224   typedef ::itk::ReceptorMemberCommand< Self > CoordinateSystemObserverType; \
00225   CoordinateSystemObserverType::Pointer m_CoordinateSystemObserver; \
00226   void ObserverCallback(const ::itk::EventObject & eventvar) \
00227     { \
00228     this->InvokeEvent( eventvar ); \
00229     } \
00230     igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper ); 
00231 
00232 #endif
00233 
00239 #ifdef IGSTK_USE_SceneGraphVisualization
00240 #define igstkCoordinateSystemClassInterfaceConstructorMacro() \
00241   m_CoordinateSystemObserver = CoordinateSystemObserverType::New(); \
00242   m_CoordinateSystemObserver->SetCallbackFunction(this, \
00243                                                    &Self::ObserverCallback); \
00244   m_CoordinateSystemDelegator = \
00245                           ::igstk::CoordinateSystemDelegator::New(); \
00246   m_SceneGraphObserver = SceneGraphObserver::New(); \
00247   m_CoordinateSystemDelegator->AddObserver( \
00248     ::igstk::CoordinateSystemTransformToNullTargetEvent()   \
00249     , m_CoordinateSystemObserver ); \
00250   m_CoordinateSystemDelegator->AddObserver( \
00251     ::igstk::CoordinateSystemSetTransformEvent() \
00252     , m_CoordinateSystemObserver); \
00253   m_SceneGraphObserver->ObserveTransformEventsFrom(this);\
00254   m_CoordinateSystemDelegator->AddObserver( \
00255     ::igstk::CoordinateSystemTransformToDisconnectedEvent() \
00256     , m_CoordinateSystemObserver ); \
00257   m_CoordinateSystemDelegator->AddObserver( \
00258     ::igstk::CoordinateSystemNullParentEvent() \
00259     , m_CoordinateSystemObserver ); \
00260   m_CoordinateSystemDelegator->AddObserver( \
00261     ::igstk::CoordinateSystemThisParentEvent() \
00262     , m_CoordinateSystemObserver ); \
00263   m_CoordinateSystemDelegator->AddObserver( \
00264     ::igstk::CoordinateSystemParentCycleEvent() \
00265     , m_CoordinateSystemObserver ); \
00266   m_CoordinateSystemDelegator->AddObserver( \
00267     ::igstk::CoordinateSystemTransformToEvent() \
00268     , m_CoordinateSystemObserver ); \
00269   std::stringstream tempStream; \
00270   tempStream << this->GetNameOfClass() << " 0x"; \
00271   tempStream << static_cast<void*>(this); \
00272   std::string name = tempStream.str(); \
00273   m_CoordinateSystemDelegator->SetType( this->GetNameOfClass() );\
00274   m_CoordinateSystemDelegator->SetName( name.c_str() );
00275 
00276 #else
00277 
00278 #define igstkCoordinateSystemClassInterfaceConstructorMacro() \
00279   m_CoordinateSystemObserver = CoordinateSystemObserverType::New(); \
00280   m_CoordinateSystemObserver->SetCallbackFunction(this, \
00281   &Self::ObserverCallback); \
00282   m_CoordinateSystemDelegator = \
00283   ::igstk::CoordinateSystemDelegator::New(); \
00284   m_CoordinateSystemDelegator->AddObserver( \
00285   ::igstk::CoordinateSystemTransformToNullTargetEvent()   \
00286   , m_CoordinateSystemObserver ); \
00287   m_CoordinateSystemDelegator->AddObserver( \
00288   ::igstk::CoordinateSystemSetTransformEvent() \
00289   , m_CoordinateSystemObserver); \
00290   m_CoordinateSystemDelegator->AddObserver( \
00291   ::igstk::CoordinateSystemTransformToDisconnectedEvent() \
00292   , m_CoordinateSystemObserver ); \
00293   m_CoordinateSystemDelegator->AddObserver( \
00294   ::igstk::CoordinateSystemNullParentEvent() \
00295   , m_CoordinateSystemObserver ); \
00296   m_CoordinateSystemDelegator->AddObserver( \
00297   ::igstk::CoordinateSystemThisParentEvent() \
00298   , m_CoordinateSystemObserver ); \
00299   m_CoordinateSystemDelegator->AddObserver( \
00300   ::igstk::CoordinateSystemParentCycleEvent() \
00301   , m_CoordinateSystemObserver ); \
00302   m_CoordinateSystemDelegator->AddObserver( \
00303   ::igstk::CoordinateSystemTransformToEvent() \
00304   , m_CoordinateSystemObserver ); \
00305   std::stringstream tempStream; \
00306   tempStream << this->GetNameOfClass() << " 0x"; \
00307   tempStream << static_cast<void*>(this); \
00308   std::string name = tempStream.str(); \
00309   m_CoordinateSystemDelegator->SetType( this->GetNameOfClass() );\
00310   m_CoordinateSystemDelegator->SetName( name.c_str() );
00311 #endif
00312 
00313 } // end namespace igstk
00314 
00315 #endif // #ifndef __igstkCoordinateSystemInterfaceMacros_h