00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __igstkTracker_h
00019 #define __igstkTracker_h
00020
00021 #include <vector>
00022 #include <map>
00023
00024 #include "itkMutexLock.h"
00025 #include "itkConditionVariable.h"
00026 #include "itkMultiThreader.h"
00027
00028 #include "igstkObject.h"
00029 #include "igstkStateMachine.h"
00030 #include "igstkTransform.h"
00031 #include "igstkPulseGenerator.h"
00032 #include "igstkTrackerTool.h"
00033
00034 #include "igstkCoordinateSystemInterfaceMacros.h"
00035
00036
00037 namespace igstk
00038 {
00039
00040 igstkEventMacro( TrackerEvent, StringEvent);
00041 igstkEventMacro( TrackerErrorEvent, IGSTKErrorWithStringEvent);
00042
00043 igstkEventMacro( TrackerOpenEvent, TrackerEvent);
00044 igstkEventMacro( TrackerOpenErrorEvent, TrackerErrorEvent);
00045
00046 igstkEventMacro( TrackerCloseEvent, TrackerEvent);
00047 igstkEventMacro( TrackerCloseErrorEvent, TrackerErrorEvent);
00048
00049 igstkEventMacro( TrackerInitializeEvent, TrackerEvent);
00050 igstkEventMacro( TrackerInitializeErrorEvent, TrackerErrorEvent);
00051
00052 igstkEventMacro( TrackerStartTrackingEvent, TrackerEvent);
00053 igstkEventMacro( TrackerStartTrackingErrorEvent, TrackerErrorEvent);
00054
00055 igstkEventMacro( TrackerStopTrackingEvent, TrackerEvent);
00056 igstkEventMacro( TrackerStopTrackingErrorEvent, TrackerErrorEvent);
00057
00058 igstkEventMacro( TrackerUpdateStatusEvent, TrackerEvent);
00059 igstkEventMacro( TrackerUpdateStatusErrorEvent, TrackerErrorEvent);
00060
00061 igstkEventMacro( TrackerToolTransformUpdateEvent, TrackerEvent);
00062
00063
00096 class Tracker : public Object
00097 {
00098
00099 public:
00101 igstkStandardAbstractClassTraitsMacro( Tracker, Object )
00102
00103 public:
00104
00105 igstkFriendClassMacro( TrackerTool );
00106
00108 typedef TrackerTool TrackerToolType;
00109
00113 void RequestOpen( void );
00114
00118 void RequestClose( void );
00119
00122 void RequestReset( void );
00123
00126 void RequestStartTracking( void );
00127
00129 void RequestStopTracking( void );
00130
00131
00137 void RequestSetFrequency( double frequencyInHz );
00138
00140 void RequestSetReferenceTool( TrackerToolType * trackerTool );
00141
00142 protected:
00143
00144 Tracker(void);
00145
00146 virtual ~Tracker(void);
00147
00149 igstkSetMacro( ThreadingEnabled, bool );
00150
00152 igstkGetMacro( ThreadingEnabled, bool );
00153
00155 typedef Transform::TimePeriodType TimePeriodType;
00156
00158 igstkGetMacro( ValidityTime, TimePeriodType );
00159
00160 typedef enum
00161 {
00162 FAILURE=0,
00163 SUCCESS
00164 } ResultType;
00165
00167 typedef Transform TransformType;
00168
00172 virtual ResultType InternalOpen( void ) = 0;
00173
00177 virtual ResultType InternalClose( void ) = 0;
00178
00182 virtual ResultType InternalReset( void ) = 0;
00183
00187 virtual ResultType InternalStartTracking( void ) = 0;
00188
00192 virtual ResultType InternalStopTracking( void ) = 0;
00193
00194
00198 virtual ResultType InternalUpdateStatus( void ) = 0;
00199
00204 virtual ResultType InternalThreadedUpdateStatus( void ) = 0;
00205
00207 virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
00208
00221 virtual ResultType
00222 VerifyTrackerToolInformation( const TrackerToolType * ) = 0;
00223
00230 virtual ResultType ValidateSpecifiedFrequency( double frequencyInHz );
00231
00234 virtual ResultType RemoveTrackerToolFromInternalDataContainers(
00235 const TrackerToolType * trackerTool ) = 0;
00236
00238 virtual ResultType AddTrackerToolToInternalDataContainers(
00239 const TrackerToolType * trackerTool ) = 0;
00240
00242 typedef std::map< std::string, TrackerToolType *> TrackerToolsContainerType;
00243
00247 const TrackerToolsContainerType & GetTrackerToolContainer() const;
00248
00250 void ReportTrackingToolNotAvailable( TrackerToolType * trackerTool ) const;
00251
00253 void ReportTrackingToolVisible( TrackerToolType * trackerTool ) const;
00254
00256 void SetTrackerToolRawTransform( TrackerToolType * trackerTool,
00257 const TransformType transform );
00258
00260 void SetTrackerToolTransformUpdate( TrackerToolType * trackerTool,
00261 bool flag ) const;
00262
00272 void ExitTrackingStateProcessing( void );
00273
00275 void ExitTrackingWithoutTerminatingTrackingThread();
00276
00278 void ExitTrackingTerminatingTrackingThread();
00279
00280
00281 private:
00282 Tracker(const Self&);
00283 void operator=(const Self&);
00284
00286 PulseGenerator::Pointer m_PulseGenerator;
00287
00289 typedef itk::SimpleMemberCommand< Self > ObserverType;
00290 ObserverType::Pointer m_PulseObserver;
00291
00292
00293
00294 TrackerToolsContainerType m_TrackerTools;
00295
00297 typedef TrackerToolType::Pointer TrackerToolPointer;
00298
00300 bool m_ApplyingReferenceTool;
00301 TrackerToolPointer m_ReferenceTool;
00302
00304 TimePeriodType m_ValidityTime;
00305
00308 bool m_ThreadingEnabled;
00309
00312 bool m_TrackingThreadStarted;
00313
00315 itk::MultiThreader::Pointer m_Threader;
00316
00318 int m_ThreadID;
00319
00322 itk::ConditionVariable::Pointer m_ConditionNextTransformReceived;
00323
00326 itk::SimpleMutexLock m_LockForConditionNextTransformReceived;
00327
00329 igstkDeclareStateMacro( Idle );
00330 igstkDeclareStateMacro( AttemptingToEstablishCommunication );
00331 igstkDeclareStateMacro( AttemptingToCloseCommunication );
00332 igstkDeclareStateMacro( CommunicationEstablished );
00333 igstkDeclareStateMacro( AttemptingToAttachTrackerTool );
00334 igstkDeclareStateMacro( TrackerToolAttached );
00335 igstkDeclareStateMacro( AttemptingToTrack );
00336 igstkDeclareStateMacro( Tracking );
00337 igstkDeclareStateMacro( AttemptingToUpdate );
00338 igstkDeclareStateMacro( AttemptingToStopTracking );
00339
00341 igstkDeclareInputMacro( EstablishCommunication );
00342 igstkDeclareInputMacro( StartTracking );
00343 igstkDeclareInputMacro( AttachTrackerTool );
00344 igstkDeclareInputMacro( UpdateStatus );
00345 igstkDeclareInputMacro( StopTracking );
00346 igstkDeclareInputMacro( Reset );
00347 igstkDeclareInputMacro( CloseCommunication );
00348 igstkDeclareInputMacro( ValidFrequency );
00349
00350 igstkDeclareInputMacro( Success );
00351 igstkDeclareInputMacro( Failure );
00352
00355 void RequestAttachTool( TrackerToolType * trackerTool );
00356
00358 ResultType RequestRemoveTool( TrackerToolType * trackerTool );
00359
00361 static ITK_THREAD_RETURN_TYPE TrackingThreadFunction(void* pInfoStruct);
00362
00366 void UpdateStatus( void );
00367
00370 void AttemptToOpenProcessing( void );
00371
00374 void AttemptToStartTrackingProcessing( void );
00375
00377 void AttemptToStopTrackingProcessing( void );
00378
00381 void AttemptToAttachTrackerToolProcessing( void );
00382
00385 void AttemptToUpdateStatusProcessing( void );
00386
00389 void UpdateStatusSuccessProcessing( void );
00390
00393 void UpdateStatusFailureProcessing( void );
00394
00397 void CloseFromTrackingStateProcessing( void );
00398
00401 void CloseFromCommunicatingStateProcessing( void );
00402
00405 void ResetFromTrackingStateProcessing( void );
00406
00409 void ResetFromToolsActiveStateProcessing( void);
00410
00413 void ResetFromCommunicatingStateProcessing( void );
00414
00416 void CommunicationEstablishmentSuccessProcessing( void );
00417
00419 void CommunicationEstablishmentFailureProcessing( void );
00420
00422 void ToolsActivationSuccessProcessing( void );
00423
00425 void ToolsActivationFailureProcessing( void );
00426
00428 void StartTrackingSuccessProcessing( void );
00429
00431 void StartTrackingFailureProcessing( void );
00432
00435 void AttachingTrackerToolSuccessProcessing( void );
00436
00439 void AttachingTrackerToolFailureProcessing( void );
00440
00442 void StopTrackingSuccessProcessing( void );
00443
00445 void StopTrackingFailureProcessing( void );
00446
00448 void CloseCommunicationSuccessProcessing( void );
00449
00451 void CloseCommunicationFailureProcessing( void );
00452
00454 void EnterTrackingStateProcessing( void );
00455
00457 void DetachAllTrackerToolsFromTracker();
00458
00460 void ReportInvalidRequestProcessing( void );
00461
00463 void SetFrequencyProcessing( void );
00464
00467 igstkCoordinateSystemClassInterfaceMacro();
00468
00469 TrackerToolType * m_TrackerToolToBeAttached;
00470
00471 double m_FrequencyToBeSet;
00472 };
00473
00474 }
00475
00476 #endif //__igstk_Tracker_h_