IGSTK
igstkCoordinateSystemInterfaceMacros.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Image Guided Surgery Software Toolkit
4 Module: $RCSfile: igstkCoordinateSystemInterfaceMacros.h,v $
5 Language: C++
6 Date: $Date: 2009-08-31 20:34:48 $
7 Version: $Revision: 1.9 $
8 
9 Copyright (c) ISC Insight Software Consortium. All rights reserved.
10 See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
11 
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __igstkCoordinateSystemInterfaceMacros_h
19 #define __igstkCoordinateSystemInterfaceMacros_h
20 
25 #include "igstkConfigure.h"
26 
27 #ifdef IGSTK_USE_SceneGraphVisualization
28 #include "igstkSceneGraphObserver.h"
29 #endif
30 
31 namespace igstk
32 {
33 
46 #ifdef IGSTK_USE_SceneGraphVisualization
47 #define igstkCoordinateSystemClassInterfaceMacro() \
48 public: \
49  template <class TTargetPointer> \
50  void RequestComputeTransformTo(const TTargetPointer & target) \
51  { \
52  m_CoordinateSystemDelegator->RequestComputeTransformTo(target);\
53  } \
54  void RequestGetTransformToParent() \
55  { \
56  m_CoordinateSystemDelegator->RequestGetTransformToParent(); \
57  } \
58  void RequestDetachFromParent()\
59  { \
60  m_CoordinateSystemDelegator->RequestDetachFromParent();\
61  } \
62  template < class TParentPointer > \
63  void RequestSetTransformAndParent( const ::igstk::Transform & transformToParent,\
64  TParentPointer parent ) \
65  { \
66  if ( this->IsInternalTransformRequired() == false ) \
67  { \
68  m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
69  transformToParent, parent); \
70  } \
71  else \
72  { \
73  ::igstk::Transform internalTransform = this->GetInternalTransform(); \
74  ::igstk::Transform transformToParentWithInternalTransform = \
75  ::igstk::Transform::TransformCompose( \
76  transformToParent, \
77  internalTransform ); \
78  m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
79  transformToParentWithInternalTransform, parent); \
80  }\
81  } \
82  void RequestUpdateTransformToParent( const ::igstk::Transform & transformToParent )\
83  { \
84  if ( this->IsInternalTransformRequired() == false ) \
85  { \
86  m_CoordinateSystemDelegator->RequestUpdateTransformToParent( transformToParent );\
87  } \
88  else \
89  { \
90  ::igstk::Transform internalTransform = this->GetInternalTransform(); \
91  ::igstk::Transform transformToParentWithInternalTransform = \
92  ::igstk::Transform::TransformCompose( \
93  transformToParent, \
94  internalTransform ); \
95  m_CoordinateSystemDelegator->RequestUpdateTransformToParent( \
96  transformToParentWithInternalTransform); \
97  }\
98  } \
99  bool IsCoordinateSystem(const ::igstk::CoordinateSystem* inCS) const \
100  { \
101  return m_CoordinateSystemDelegator-> \
102  IsCoordinateSystem( inCS ); \
103  } \
104  void RequestSetCoordinateSystemName(const char * name) \
105  { \
106  m_CoordinateSystemDelegator->SetName( name ); \
107  } \
108  const char * RequestGetCoordinateSystemName() const \
109  { \
110  return m_CoordinateSystemDelegator->GetName(); \
111  } \
112 protected: \
113  virtual bool IsInternalTransformRequired() \
114  { \
115  return false; \
116  } \
117  virtual ::igstk::Transform GetInternalTransform() const \
118  { \
119  ::igstk::Transform identity; \
120  identity.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() ); \
121  return identity; \
122  } \
123  const ::igstk::CoordinateSystem* GetCoordinateSystem() const \
124  { \
125  return \
126  igstk::Friends::CoordinateSystemHelper:: \
127  GetCoordinateSystem( \
128  m_CoordinateSystemDelegator.GetPointer() ); \
129  } \
130 private: \
131  ::igstk::CoordinateSystemDelegator::Pointer \
132  m_CoordinateSystemDelegator; \
133  typedef ::itk::ReceptorMemberCommand< Self > CoordinateSystemObserverType; \
134  CoordinateSystemObserverType::Pointer m_CoordinateSystemObserver; \
135  SceneGraphObserver::Pointer m_SceneGraphObserver; \
136  void ObserverCallback(const ::itk::EventObject & eventvar) \
137  { \
138  this->InvokeEvent( eventvar ); \
139  } \
140  igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper );
141 
142 #else
143 
144 #define igstkCoordinateSystemClassInterfaceMacro() \
145 public: \
146  template <class TTargetPointer> \
147  void RequestComputeTransformTo(const TTargetPointer & target) \
148  { \
149  m_CoordinateSystemDelegator->RequestComputeTransformTo(target);\
150  } \
151  void RequestGetTransformToParent() \
152  { \
153  m_CoordinateSystemDelegator->RequestGetTransformToParent(); \
154  } \
155  void RequestDetachFromParent()\
156  { \
157  m_CoordinateSystemDelegator->RequestDetachFromParent();\
158  } \
159  template < class TParentPointer > \
160  void RequestSetTransformAndParent( const ::igstk::Transform & transformToParent,\
161  TParentPointer parent ) \
162  { \
163  std::stringstream tempStream; \
164  tempStream << this->GetNameOfClass() << " 0x"; \
165  tempStream << static_cast<void*>(this); \
166  std::string name = tempStream.str(); \
167  m_CoordinateSystemDelegator->SetName( name.c_str() );\
168  if ( this->IsInternalTransformRequired() == false ) \
169  { \
170  m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
171  transformToParent, parent); \
172  } \
173  else \
174  { \
175  ::igstk::Transform internalTransform = this->GetInternalTransform(); \
176  ::igstk::Transform transformToParentWithInternalTransform = \
177  ::igstk::Transform::TransformCompose( \
178  transformToParent, \
179  internalTransform ); \
180  m_CoordinateSystemDelegator->RequestSetTransformAndParent( \
181  transformToParentWithInternalTransform, parent); \
182  }\
183  } \
184  void RequestUpdateTransformToParent( const ::igstk::Transform & transformToParent )\
185  { \
186  if ( this->IsInternalTransformRequired() == false ) \
187  { \
188  m_CoordinateSystemDelegator->RequestUpdateTransformToParent( transformToParent );\
189  } \
190  else \
191  { \
192  ::igstk::Transform internalTransform = this->GetInternalTransform(); \
193  ::igstk::Transform transformToParentWithInternalTransform = \
194  ::igstk::Transform::TransformCompose( \
195  transformToParent, \
196  internalTransform ); \
197  m_CoordinateSystemDelegator->RequestUpdateTransformToParent( \
198  transformToParentWithInternalTransform); \
199  }\
200  } \
201  bool IsCoordinateSystem(const ::igstk::CoordinateSystem* inCS) const \
202  { \
203  return m_CoordinateSystemDelegator-> \
204  IsCoordinateSystem( inCS ); \
205  } \
206 protected: \
207  virtual bool IsInternalTransformRequired() \
208  { \
209  return false; \
210  } \
211  virtual ::igstk::Transform GetInternalTransform() const \
212  { \
213  ::igstk::Transform identity; \
214  identity.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() ); \
215  return identity; \
216  } \
217  const ::igstk::CoordinateSystem* GetCoordinateSystem() const \
218  { \
219  return \
220  igstk::Friends::CoordinateSystemHelper:: \
221  GetCoordinateSystem( \
222  m_CoordinateSystemDelegator.GetPointer() ); \
223  } \
224 private: \
225  ::igstk::CoordinateSystemDelegator::Pointer \
226  m_CoordinateSystemDelegator; \
227  typedef ::itk::ReceptorMemberCommand< Self > CoordinateSystemObserverType; \
228  CoordinateSystemObserverType::Pointer m_CoordinateSystemObserver; \
229  void ObserverCallback(const ::itk::EventObject & eventvar) \
230  { \
231  this->InvokeEvent( eventvar ); \
232  } \
233  igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper );
234 
235 #endif
236 
242 #ifdef IGSTK_USE_SceneGraphVisualization
243 #define igstkCoordinateSystemClassInterfaceConstructorMacro() \
244  m_CoordinateSystemObserver = CoordinateSystemObserverType::New(); \
245  m_CoordinateSystemObserver->SetCallbackFunction(this, \
246  &Self::ObserverCallback); \
247  m_CoordinateSystemDelegator = \
248  ::igstk::CoordinateSystemDelegator::New(); \
249  m_SceneGraphObserver = SceneGraphObserver::New(); \
250  m_CoordinateSystemDelegator->AddObserver( \
251  ::igstk::CoordinateSystemTransformToNullTargetEvent() \
252  , m_CoordinateSystemObserver ); \
253  m_CoordinateSystemDelegator->AddObserver( \
254  ::igstk::CoordinateSystemSetTransformEvent() \
255  , m_CoordinateSystemObserver); \
256  m_SceneGraphObserver->ObserveTransformEventsFrom(this);\
257  m_CoordinateSystemDelegator->AddObserver( \
258  ::igstk::CoordinateSystemTransformToDisconnectedEvent() \
259  , m_CoordinateSystemObserver ); \
260  m_CoordinateSystemDelegator->AddObserver( \
261  ::igstk::CoordinateSystemNullParentEvent() \
262  , m_CoordinateSystemObserver ); \
263  m_CoordinateSystemDelegator->AddObserver( \
264  ::igstk::CoordinateSystemThisParentEvent() \
265  , m_CoordinateSystemObserver ); \
266  m_CoordinateSystemDelegator->AddObserver( \
267  ::igstk::CoordinateSystemParentCycleEvent() \
268  , m_CoordinateSystemObserver ); \
269  m_CoordinateSystemDelegator->AddObserver( \
270  ::igstk::CoordinateSystemTransformToEvent() \
271  , m_CoordinateSystemObserver ); \
272  std::stringstream tempStream; \
273  tempStream << this->GetNameOfClass() << " 0x"; \
274  tempStream << static_cast<void*>(this); \
275  std::string name = tempStream.str(); \
276  m_CoordinateSystemDelegator->SetType( this->GetNameOfClass() );\
277  m_CoordinateSystemDelegator->SetName( name.c_str() );
278 
279 #else
280 
281 #define igstkCoordinateSystemClassInterfaceConstructorMacro() \
282  m_CoordinateSystemObserver = CoordinateSystemObserverType::New(); \
283  m_CoordinateSystemObserver->SetCallbackFunction(this, \
284  &Self::ObserverCallback); \
285  m_CoordinateSystemDelegator = \
286  ::igstk::CoordinateSystemDelegator::New(); \
287  m_CoordinateSystemDelegator->AddObserver( \
288  ::igstk::CoordinateSystemTransformToNullTargetEvent() \
289  , m_CoordinateSystemObserver ); \
290  m_CoordinateSystemDelegator->AddObserver( \
291  ::igstk::CoordinateSystemSetTransformEvent() \
292  , m_CoordinateSystemObserver); \
293  m_CoordinateSystemDelegator->AddObserver( \
294  ::igstk::CoordinateSystemTransformToDisconnectedEvent() \
295  , m_CoordinateSystemObserver ); \
296  m_CoordinateSystemDelegator->AddObserver( \
297  ::igstk::CoordinateSystemNullParentEvent() \
298  , m_CoordinateSystemObserver ); \
299  m_CoordinateSystemDelegator->AddObserver( \
300  ::igstk::CoordinateSystemThisParentEvent() \
301  , m_CoordinateSystemObserver ); \
302  m_CoordinateSystemDelegator->AddObserver( \
303  ::igstk::CoordinateSystemParentCycleEvent() \
304  , m_CoordinateSystemObserver ); \
305  m_CoordinateSystemDelegator->AddObserver( \
306  ::igstk::CoordinateSystemTransformToEvent() \
307  , m_CoordinateSystemObserver ); \
308  std::stringstream tempStream; \
309  tempStream << this->GetNameOfClass() << " 0x"; \
310  tempStream << static_cast<void*>(this); \
311  std::string name = tempStream.str(); \
312  m_CoordinateSystemDelegator->SetType( this->GetNameOfClass() );\
313  m_CoordinateSystemDelegator->SetName( name.c_str() );
314 #endif
315 
316 } // end namespace igstk
317 
318 #endif // #ifndef __igstkCoordinateSystemInterfaceMacros_h