IGSTK
igstkTracker.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkTracker.h,v $
5  Language: C++
6  Date: $Date: 2009-06-11 21:53:53 $
7  Version: $Revision: 1.63 $
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 __igstkTracker_h
19 #define __igstkTracker_h
20 
21 #include <vector>
22 #include <map>
23 
24 #include "itkMutexLock.h"
25 #include "itkConditionVariable.h"
26 #include "itkMultiThreader.h"
27 
28 #include "igstkObject.h"
29 #include "igstkStateMachine.h"
30 #include "igstkTransform.h"
31 #include "igstkPulseGenerator.h"
32 #include "igstkTrackerTool.h"
33 
35 
36 
37 namespace igstk
38 {
39 
40 igstkEventMacro( TrackerEvent, StringEvent);
41 igstkEventMacro( TrackerErrorEvent, IGSTKErrorWithStringEvent);
42 
43 igstkEventMacro( TrackerOpenEvent, TrackerEvent);
44 igstkEventMacro( TrackerOpenErrorEvent, TrackerErrorEvent);
45 
46 igstkEventMacro( TrackerCloseEvent, TrackerEvent);
47 igstkEventMacro( TrackerCloseErrorEvent, TrackerErrorEvent);
48 
49 igstkEventMacro( TrackerInitializeEvent, TrackerEvent);
50 igstkEventMacro( TrackerInitializeErrorEvent, TrackerErrorEvent);
51 
52 igstkEventMacro( TrackerStartTrackingEvent, TrackerEvent);
53 igstkEventMacro( TrackerStartTrackingErrorEvent, TrackerErrorEvent);
54 
55 igstkEventMacro( TrackerStopTrackingEvent, TrackerEvent);
56 igstkEventMacro( TrackerStopTrackingErrorEvent, TrackerErrorEvent);
57 
58 igstkEventMacro( TrackerUpdateStatusEvent, TrackerEvent);
59 igstkEventMacro( TrackerUpdateStatusErrorEvent, TrackerErrorEvent);
60 
61 igstkEventMacro( TrackerToolTransformUpdateEvent, TrackerEvent);
62 
63 
96 class Tracker : public Object
97 {
98 
99 public:
102 
103 public:
104 
106 
108  typedef TrackerTool TrackerToolType;
109 
113  void RequestOpen( void );
114 
118  void RequestClose( void );
119 
122  void RequestReset( void );
123 
126  void RequestStartTracking( void );
127 
129  void RequestStopTracking( void );
130 
136  void RequestSetFrequency( double frequencyInHz );
137 
139  void RequestSetReferenceTool( TrackerToolType * trackerTool );
140 
142  igstkSetMacro( ThreadingEnabled, bool );
143 
145  igstkGetMacro( ThreadingEnabled, bool );
146 
147 protected:
148 
149  Tracker(void);
150 
151  virtual ~Tracker(void);
152 
155 
157  igstkGetMacro( ValidityTime, TimePeriodType );
158 
159  typedef enum
160  {
163  } ResultType;
164 
167 
171  virtual ResultType InternalOpen( void ) = 0;
172 
176  virtual ResultType InternalClose( void ) = 0;
177 
181  virtual ResultType InternalReset( void ) = 0;
182 
186  virtual ResultType InternalStartTracking( void ) = 0;
187 
191  virtual ResultType InternalStopTracking( void ) = 0;
192 
193 
197  virtual ResultType InternalUpdateStatus( void ) = 0;
198 
203  virtual ResultType InternalThreadedUpdateStatus( void ) = 0;
204 
206  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
207 
220  virtual ResultType
222 
229  virtual ResultType ValidateSpecifiedFrequency( double frequencyInHz );
230 
234  const TrackerToolType * trackerTool ) = 0;
235 
238  const TrackerToolType * trackerTool ) = 0;
239 
241  typedef std::map< std::string, TrackerToolType *> TrackerToolsContainerType;
242 
247 
249  void ReportTrackingToolNotAvailable( TrackerToolType * trackerTool ) const;
250 
252  void ReportTrackingToolVisible( TrackerToolType * trackerTool ) const;
253 
255  void SetTrackerToolRawTransform( TrackerToolType * trackerTool,
256  const TransformType transform );
257 
260  bool flag ) const;
261 
271  void ExitTrackingStateProcessing( void );
272 
275 
278 
279 
280 private:
281  Tracker(const Self&); //purposely not implemented
282  void operator=(const Self&); //purposely not implemented
283 
285  PulseGenerator::Pointer m_PulseGenerator;
286 
288  typedef itk::SimpleMemberCommand< Self > ObserverType;
289  ObserverType::Pointer m_PulseObserver;
290 
291  // An associative container of TrackerTool Pointer with
292  // TrackerTool identifier used as a Key
293  TrackerToolsContainerType m_TrackerTools;
294 
296  typedef TrackerToolType::Pointer TrackerToolPointer;
297 
299  bool m_ApplyingReferenceTool;
300  TrackerToolPointer m_ReferenceTool;
301 
303  TimePeriodType m_ValidityTime;
304 
307  bool m_ThreadingEnabled;
308 
311  bool m_TrackingThreadStarted;
312 
314  itk::MultiThreader::Pointer m_Threader;
315 
317  int m_ThreadID;
318 
321  itk::ConditionVariable::Pointer m_ConditionNextTransformReceived;
322 
325  itk::SimpleMutexLock m_LockForConditionNextTransformReceived;
326 
328  igstkDeclareStateMacro( Idle );
329  igstkDeclareStateMacro( AttemptingToEstablishCommunication );
330  igstkDeclareStateMacro( AttemptingToCloseCommunication );
331  igstkDeclareStateMacro( CommunicationEstablished );
332  igstkDeclareStateMacro( AttemptingToAttachTrackerTool );
333  igstkDeclareStateMacro( TrackerToolAttached );
334  igstkDeclareStateMacro( AttemptingToTrack );
335  igstkDeclareStateMacro( Tracking );
336  igstkDeclareStateMacro( AttemptingToUpdate );
337  igstkDeclareStateMacro( AttemptingToStopTracking );
338 
340  igstkDeclareInputMacro( EstablishCommunication );
341  igstkDeclareInputMacro( StartTracking );
342  igstkDeclareInputMacro( AttachTrackerTool );
343  igstkDeclareInputMacro( UpdateStatus );
344  igstkDeclareInputMacro( StopTracking );
345  igstkDeclareInputMacro( Reset );
346  igstkDeclareInputMacro( CloseCommunication );
347  igstkDeclareInputMacro( ValidFrequency );
348 
349  igstkDeclareInputMacro( Success );
350  igstkDeclareInputMacro( Failure );
351 
354  void RequestAttachTool( TrackerToolType * trackerTool );
355 
357  ResultType RequestRemoveTool( TrackerToolType * trackerTool );
358 
360  static ITK_THREAD_RETURN_TYPE TrackingThreadFunction(void* pInfoStruct);
361 
365  void UpdateStatus( void );
366 
369  void AttemptToOpenProcessing( void );
370 
373  void AttemptToStartTrackingProcessing( void );
374 
376  void AttemptToStopTrackingProcessing( void );
377 
380  void AttemptToAttachTrackerToolProcessing( void );
381 
384  void AttemptToUpdateStatusProcessing( void );
385 
388  void UpdateStatusSuccessProcessing( void );
389 
392  void UpdateStatusFailureProcessing( void );
393 
396  void CloseFromTrackingStateProcessing( void );
397 
400  void CloseFromCommunicatingStateProcessing( void );
401 
404  void ResetFromTrackingStateProcessing( void );
405 
408  void ResetFromToolsActiveStateProcessing( void);
409 
412  void ResetFromCommunicatingStateProcessing( void );
413 
415  void CommunicationEstablishmentSuccessProcessing( void );
416 
418  void CommunicationEstablishmentFailureProcessing( void );
419 
421  void ToolsActivationSuccessProcessing( void );
422 
424  void ToolsActivationFailureProcessing( void );
425 
427  void StartTrackingSuccessProcessing( void );
428 
430  void StartTrackingFailureProcessing( void );
431 
434  void AttachingTrackerToolSuccessProcessing( void );
435 
438  void AttachingTrackerToolFailureProcessing( void );
439 
441  void StopTrackingSuccessProcessing( void );
442 
444  void StopTrackingFailureProcessing( void );
445 
447  void CloseCommunicationSuccessProcessing( void );
448 
450  void CloseCommunicationFailureProcessing( void );
451 
453  void EnterTrackingStateProcessing( void );
454 
456  void DetachAllTrackerToolsFromTracker();
457 
459  void ReportInvalidRequestProcessing( void );
460 
462  void SetFrequencyProcessing( void );
463 
466  igstkCoordinateSystemClassInterfaceMacro();
467 
468  TrackerToolType * m_TrackerToolToBeAttached;
469 
470  double m_FrequencyToBeSet;
471 };
472 
473 }
474 
475 #endif //__igstk_Tracker_h_
#define igstkStandardAbstractClassTraitsMacro(classname, superclassname)
Convenience macro for traits of an abstract non-templated class.
Definition: igstkMacros.h:270
void ExitTrackingTerminatingTrackingThread()
Exit tracking after terminating tracking thread.
#define igstkFriendClassMacro(type)
Create a Macro for friend class.
Definition: igstkMacros.h:137
#define igstkGetMacro(name, type)
Get built-in type.
Definition: igstkMacros.h:105
virtual ResultType AddTrackerToolToInternalDataContainers(const TrackerToolType *trackerTool)=0
Add tracker tool entry to internal containers.
void RequestOpen(void)
The "RequestOpen" method attempts to open communication with the tracking device. ...
Transform TransformType
typedefs from Transform class
Definition: igstkTracker.h:166
void SetTrackerToolRawTransform(TrackerToolType *trackerTool, const TransformType transform)
Set tracker tool raw transform.
void ReportTrackingToolVisible(TrackerToolType *trackerTool) const
Report to tracker tool that it is visible.
Base class for all the IGSTK classes.
Definition: igstkObject.h:40
Transform::TimePeriodType TimePeriodType
typedef for times used by the tracker
Definition: igstkTracker.h:154
void RequestReset(void)
The "RequestReset" tracker method should be used to bring the tracker to some defined default state...
void ReportTrackingToolNotAvailable(TrackerToolType *trackerTool) const
Report to tracker tool that it is not available for tracking.
virtual ResultType InternalClose(void)=0
The "InternalClose" method closes communication with a tracking device.
void RequestSetFrequency(double frequencyInHz)
The "RequestSetFrequency" method defines the frequency at which the Transform information will be que...
igstkEventMacro(AuroraTrackerToolEvent, StringEvent)
virtual ResultType InternalStopTracking(void)=0
The "InternalStopTracking" method stops tracking.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
Print the object information in a stream.
Abstract superclass for concrete IGSTK TrackerTool classes.
virtual ResultType VerifyTrackerToolInformation(const TrackerToolType *)=0
Verify if a tracker tool information is correct before attaching it to the tracker.
::itk::SmartPointer< Self > Pointer
Definition: igstkObject.h:50
std::map< std::string, TrackerToolType * > TrackerToolsContainerType
typedefs from TrackerTool class
Definition: igstkTracker.h:241
const TrackerToolsContainerType & GetTrackerToolContainer() const
Access method for the tracker tool container.
virtual ResultType RemoveTrackerToolFromInternalDataContainers(const TrackerToolType *trackerTool)=0
This method will remove entries of the traceker tool from internal data containers.
virtual ResultType ValidateSpecifiedFrequency(double frequencyInHz)
The "ValidateSpecifiedFrequency" method checks if the specified frequency is valid for the tracking d...
void SetTrackerToolTransformUpdate(TrackerToolType *trackerTool, bool flag) const
Turn on/off update flag of the tracker tool.
void ExitTrackingStateProcessing(void)
Depending on the tracker type, the tracking thread should be terminated or left untouched when we sto...
Abstract superclass for concrete IGSTK Tracker classes.
Definition: igstkTracker.h:96
A class representing a 3D Rigid transform.
virtual ResultType InternalUpdateStatus(void)=0
The "InternalUpdateStatus" method updates tracker status.
void RequestSetReferenceTool(TrackerToolType *trackerTool)
Set a reference tracker tool.
void RequestClose(void)
The "RequestClose" method closes communication with the device.
void ExitTrackingWithoutTerminatingTrackingThread()
Exit tracking without terminating tracking thread.
virtual ResultType InternalReset(void)=0
The "InternalReset" method resets tracker to a known configuration.
igstkStandardAbstractClassTraitsMacro(Tracker, Object) public typedef TrackerTool TrackerToolType
Macro with standard traits declarations.
Definition: igstkTracker.h:101
#define igstkSetMacro(name, type)
Set built-in type.
Definition: igstkMacros.h:93
virtual ResultType InternalOpen(void)=0
The "InternalOpen" method opens communication with a tracking device.
void RequestStopTracking(void)
The "RequestStopTracking" stops tracker from tracking the tools.
virtual ResultType InternalStartTracking(void)=0
The "InternalStartTracking" method starts tracking.
virtual ResultType InternalThreadedUpdateStatus(void)=0
The "InternalThreadedUpdateStatus" method updates tracker status.
void RequestStartTracking(void)
The "RequestStartTracking" method readies the tracker for tracking the tools connected to the tracker...