IGSTK
igstkVideoImager.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkVideoImager.h,v $
5  Language: C++
6  Date: $Date: 2009-06-18 18:40:55 $
7  Version: $Revision: 1.1 $
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 __igstkVideoImager_h
19 #define __igstkVideoImager_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 "igstkFrame.h"
32 #include "igstkPulseGenerator.h"
33 #include "igstkVideoImagerTool.h"
34 
36 
37 namespace igstk
38 {
39 
40 igstkEventMacro( VideoImagerEvent, StringEvent);
41 igstkEventMacro( VideoImagerErrorEvent, IGSTKErrorWithStringEvent);
42 
43 igstkEventMacro( VideoImagerOpenEvent, VideoImagerEvent);
44 igstkEventMacro( VideoImagerOpenErrorEvent, VideoImagerErrorEvent);
45 
46 igstkEventMacro( VideoImagerCloseEvent, VideoImagerEvent);
47 igstkEventMacro( VideoImagerCloseErrorEvent, VideoImagerErrorEvent);
48 
49 igstkEventMacro( VideoImagerInitializeEvent, VideoImagerEvent);
50 igstkEventMacro( VideoImagerInitializeErrorEvent, VideoImagerErrorEvent);
51 
52 igstkEventMacro( VideoImagerStartImagingEvent, VideoImagerEvent);
53 igstkEventMacro( VideoImagerStartImagingErrorEvent, VideoImagerErrorEvent);
54 
55 igstkEventMacro( VideoImagerStopImagingEvent, VideoImagerEvent);
56 igstkEventMacro( VideoImagerStopImagingErrorEvent, VideoImagerErrorEvent);
57 
58 igstkEventMacro( VideoImagerUpdateStatusEvent, VideoImagerEvent);
59 igstkEventMacro( VideoImagerUpdateStatusErrorEvent, VideoImagerErrorEvent);
60 
84 class VideoImager : public Object
85 {
86 
87 public:
90 
91 public:
92 
94 
96  typedef VideoImagerTool VideoImagerToolType;
97 
101  void RequestOpen( void );
102 
106  void RequestClose( void );
107 
110  void RequestReset( void );
111 
114  void RequestStartImaging( void );
115 
117  void RequestStopImaging( void );
118 
124  void RequestSetFrequency( double frequencyInHz );
125 
126 protected:
127 
128  VideoImager(void);
129  virtual ~VideoImager(void);
130 
132  igstkSetMacro( ThreadingEnabled, bool );
133 
135  igstkGetMacro( ThreadingEnabled, bool );
136 
139 
141  igstkGetMacro( ValidityTime, TimePeriodType );
142 
143  typedef enum
144  {
147  } ResultType;
148 
151 
153  typedef Frame FrameType;
154 
158  virtual ResultType InternalOpen( void ) = 0;
159 
163  virtual ResultType InternalClose( void ) = 0;
164 
168  virtual ResultType InternalReset( void ) = 0;
169 
173  virtual ResultType InternalStartImaging( void ) = 0;
174 
178  virtual ResultType InternalStopImaging( void ) = 0;
179 
180 
184  virtual ResultType InternalUpdateStatus( void ) = 0;
185 
190  virtual ResultType InternalThreadedUpdateStatus( void ) = 0;
191 
193  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
194 
200  virtual ResultType
202 
208  virtual ResultType ValidateSpecifiedFrequency( double frequencyInHz );
209 
213  const VideoImagerToolType * videoImagerTool ) = 0;
214 
217  const VideoImagerToolType * videoImagerTool ) = 0;
218 
220  typedef std::map< std::string, VideoImagerToolType *>
222 
227 
231 
234  VideoImagerToolType * videoImagerTool ) const;
235 
236  void SetVideoImagerToolFrame( VideoImagerToolType * videoImagerTool,
237  FrameType* frame );
238 
240 
242  void SetVideoImagerToolUpdate( VideoImagerToolType * videoImagerTool,
243  bool flag ) const;
244 
247  void ExitImagingStateProcessing( void );
248 
251 
254 
255 private:
256  VideoImager(const Self&); //purposely not implemented
257  void operator=(const Self&); //purposely not implemented
258 
260  PulseGenerator::Pointer m_PulseGenerator;
261 
263  typedef itk::SimpleMemberCommand< Self > ObserverType;
264  ObserverType::Pointer m_PulseObserver;
265 
268  VideoImagerToolsContainerType m_VideoImagerTools;
269 
271  typedef VideoImagerToolType::Pointer VideoImagerToolPointer;
272 
274  TimePeriodType m_ValidityTime;
275 
278  bool m_ThreadingEnabled;
279 
282  bool m_ImagingThreadStarted;
283 
285  itk::MultiThreader::Pointer m_Threader;
286 
288  int m_ThreadID;
289 
292  itk::ConditionVariable::Pointer m_ConditionNextFrameReceived;
293 
296  itk::SimpleMutexLock m_LockForConditionNextFrameReceived;
297 
299  igstkDeclareStateMacro( Idle );
300  igstkDeclareStateMacro( AttemptingToEstablishCommunication );
301  igstkDeclareStateMacro( AttemptingToCloseCommunication );
302  igstkDeclareStateMacro( CommunicationEstablished );
303  igstkDeclareStateMacro( AttemptingToAttachVideoImagerTool );
304  igstkDeclareStateMacro( VideoImagerToolAttached );
305  igstkDeclareStateMacro( AttemptingToImaging );
306  igstkDeclareStateMacro( Imaging );
307  igstkDeclareStateMacro( AttemptingToUpdate );
308  igstkDeclareStateMacro( AttemptingToStopImaging );
309 
311  igstkDeclareInputMacro( EstablishCommunication );
312  igstkDeclareInputMacro( StartImaging );
313  igstkDeclareInputMacro( AttachVideoImagerTool );
314  igstkDeclareInputMacro( UpdateStatus );
315  igstkDeclareInputMacro( StopImaging );
316  igstkDeclareInputMacro( Reset );
317  igstkDeclareInputMacro( CloseCommunication );
318  igstkDeclareInputMacro( ValidFrequency );
319 
320  igstkDeclareInputMacro( Success );
321  igstkDeclareInputMacro( Failure );
322 
325  void RequestAttachTool( VideoImagerToolType * videoImagerTool );
326 
328  ResultType RequestRemoveTool( VideoImagerToolType * videoImagerTool );
329 
331  static ITK_THREAD_RETURN_TYPE ImagingThreadFunction(void* pInfoStruct);
332 
336  void UpdateStatus( void );
337 
340  void AttemptToOpenProcessing( void );
341 
344  void AttemptToStartImagingProcessing( void );
345 
347  void AttemptToStopImagingProcessing( void );
348 
351  void AttemptToAttachVideoImagerToolProcessing( void );
352 
355  void AttemptToUpdateStatusProcessing( void );
356 
359  void UpdateStatusSuccessProcessing( void );
360 
363  void UpdateStatusFailureProcessing( void );
364 
367  void CloseFromImagingStateProcessing( void );
368 
371  void CloseFromCommunicatingStateProcessing( void );
372 
375  void ResetFromImagingStateProcessing( void );
376 
379  void ResetFromToolsActiveStateProcessing( void);
380 
383  void ResetFromCommunicatingStateProcessing( void );
384 
386  void CommunicationEstablishmentSuccessProcessing( void );
387 
389  void CommunicationEstablishmentFailureProcessing( void );
390 
392  void ToolsActivationSuccessProcessing( void );
393 
395  void ToolsActivationFailureProcessing( void );
396 
398  void StartImagingSuccessProcessing( void );
399 
401  void StartImagingFailureProcessing( void );
402 
405  void AttachingVideoImagerToolSuccessProcessing( void );
406 
409  void AttachingVideoImagerToolFailureProcessing( void );
410 
412  void StopImagingSuccessProcessing( void );
413 
415  void StopImagingFailureProcessing( void );
416 
418  void CloseCommunicationSuccessProcessing( void );
419 
421  void CloseCommunicationFailureProcessing( void );
422 
424  void EnterImagingStateProcessing( void );
425 
427  void DetachAllVideoImagerToolsFromVideoImager();
428 
430  void ReportInvalidRequestProcessing( void );
431 
433  void SetFrequencyProcessing( void );
434 
437  igstkCoordinateSystemClassInterfaceMacro();
438 
439  VideoImagerToolType * m_VideoImagerToolToBeAttached;
440 
441  double m_FrequencyToBeSet;
442 };
443 
444 }
445 
446 #endif //__igstk_VideoImager_h_