IGSTK
|
00001 /*========================================================================= 00002 00003 Program: Image Guided Surgery Software Toolkit 00004 Module: $RCSfile: igstkVideoImager.h,v $ 00005 Language: C++ 00006 Date: $Date: 2009-06-18 18:40:55 $ 00007 Version: $Revision: 1.1 $ 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 __igstkVideoImager_h 00019 #define __igstkVideoImager_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 "igstkFrame.h" 00032 #include "igstkPulseGenerator.h" 00033 #include "igstkVideoImagerTool.h" 00034 00035 #include "igstkCoordinateSystemInterfaceMacros.h" 00036 00037 namespace igstk 00038 { 00039 00040 igstkEventMacro( VideoImagerEvent, StringEvent); 00041 igstkEventMacro( VideoImagerErrorEvent, IGSTKErrorWithStringEvent); 00042 00043 igstkEventMacro( VideoImagerOpenEvent, VideoImagerEvent); 00044 igstkEventMacro( VideoImagerOpenErrorEvent, VideoImagerErrorEvent); 00045 00046 igstkEventMacro( VideoImagerCloseEvent, VideoImagerEvent); 00047 igstkEventMacro( VideoImagerCloseErrorEvent, VideoImagerErrorEvent); 00048 00049 igstkEventMacro( VideoImagerInitializeEvent, VideoImagerEvent); 00050 igstkEventMacro( VideoImagerInitializeErrorEvent, VideoImagerErrorEvent); 00051 00052 igstkEventMacro( VideoImagerStartImagingEvent, VideoImagerEvent); 00053 igstkEventMacro( VideoImagerStartImagingErrorEvent, VideoImagerErrorEvent); 00054 00055 igstkEventMacro( VideoImagerStopImagingEvent, VideoImagerEvent); 00056 igstkEventMacro( VideoImagerStopImagingErrorEvent, VideoImagerErrorEvent); 00057 00058 igstkEventMacro( VideoImagerUpdateStatusEvent, VideoImagerEvent); 00059 igstkEventMacro( VideoImagerUpdateStatusErrorEvent, VideoImagerErrorEvent); 00060 00084 class VideoImager : public Object 00085 { 00086 00087 public: 00089 igstkStandardAbstractClassTraitsMacro( VideoImager, Object ) 00090 00091 public: 00092 00093 igstkFriendClassMacro( VideoImagerTool ); 00094 00096 typedef VideoImagerTool VideoImagerToolType; 00097 00101 void RequestOpen( void ); 00102 00106 void RequestClose( void ); 00107 00110 void RequestReset( void ); 00111 00114 void RequestStartImaging( void ); 00115 00117 void RequestStopImaging( void ); 00118 00124 void RequestSetFrequency( double frequencyInHz ); 00125 00126 protected: 00127 00128 VideoImager(void); 00129 virtual ~VideoImager(void); 00130 00132 igstkSetMacro( ThreadingEnabled, bool ); 00133 00135 igstkGetMacro( ThreadingEnabled, bool ); 00136 00138 typedef Transform::TimePeriodType TimePeriodType; 00139 00141 igstkGetMacro( ValidityTime, TimePeriodType ); 00142 00143 typedef enum 00144 { 00145 FAILURE=0, 00146 SUCCESS 00147 } ResultType; 00148 00150 typedef Transform TransformType; 00151 00153 typedef Frame FrameType; 00154 00158 virtual ResultType InternalOpen( void ) = 0; 00159 00163 virtual ResultType InternalClose( void ) = 0; 00164 00168 virtual ResultType InternalReset( void ) = 0; 00169 00173 virtual ResultType InternalStartImaging( void ) = 0; 00174 00178 virtual ResultType InternalStopImaging( void ) = 0; 00179 00180 00184 virtual ResultType InternalUpdateStatus( void ) = 0; 00185 00190 virtual ResultType InternalThreadedUpdateStatus( void ) = 0; 00191 00193 virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const; 00194 00200 virtual ResultType 00201 VerifyVideoImagerToolInformation( const VideoImagerToolType * ) = 0; 00202 00208 virtual ResultType ValidateSpecifiedFrequency( double frequencyInHz ); 00209 00212 virtual ResultType RemoveVideoImagerToolFromInternalDataContainers( 00213 const VideoImagerToolType * videoImagerTool ) = 0; 00214 00216 virtual ResultType AddVideoImagerToolToInternalDataContainers( 00217 const VideoImagerToolType * videoImagerTool ) = 0; 00218 00220 typedef std::map< std::string, VideoImagerToolType *> 00221 VideoImagerToolsContainerType; 00222 00226 const VideoImagerToolsContainerType & GetVideoImagerToolContainer() const; 00227 00229 void ReportImagingToolNotAvailable( 00230 VideoImagerToolType * VideoImagerTool ) const; 00231 00233 void ReportImagingToolStreaming( 00234 VideoImagerToolType * videoImagerTool ) const; 00235 00236 void SetVideoImagerToolFrame( VideoImagerToolType * videoImagerTool, 00237 FrameType* frame ); 00238 00239 FrameType* GetVideoImagerToolFrame( VideoImagerToolType * videoImagerTool); 00240 00242 void SetVideoImagerToolUpdate( VideoImagerToolType * videoImagerTool, 00243 bool flag ) const; 00244 00247 void ExitImagingStateProcessing( void ); 00248 00250 void ExitImagingWithoutTerminatingImagingThread(); 00251 00253 void ExitImagingTerminatingImagingThread(); 00254 00255 private: 00256 VideoImager(const Self&); //purposely not implemented 00257 void operator=(const Self&); //purposely not implemented 00258 00260 PulseGenerator::Pointer m_PulseGenerator; 00261 00263 typedef itk::SimpleMemberCommand< Self > ObserverType; 00264 ObserverType::Pointer m_PulseObserver; 00265 00268 VideoImagerToolsContainerType m_VideoImagerTools; 00269 00271 typedef VideoImagerToolType::Pointer VideoImagerToolPointer; 00272 00274 TimePeriodType m_ValidityTime; 00275 00278 bool m_ThreadingEnabled; 00279 00282 bool m_ImagingThreadStarted; 00283 00285 itk::MultiThreader::Pointer m_Threader; 00286 00288 int m_ThreadID; 00289 00292 itk::ConditionVariable::Pointer m_ConditionNextFrameReceived; 00293 00296 itk::SimpleMutexLock m_LockForConditionNextFrameReceived; 00297 00299 igstkDeclareStateMacro( Idle ); 00300 igstkDeclareStateMacro( AttemptingToEstablishCommunication ); 00301 igstkDeclareStateMacro( AttemptingToCloseCommunication ); 00302 igstkDeclareStateMacro( CommunicationEstablished ); 00303 igstkDeclareStateMacro( AttemptingToAttachVideoImagerTool ); 00304 igstkDeclareStateMacro( VideoImagerToolAttached ); 00305 igstkDeclareStateMacro( AttemptingToImaging ); 00306 igstkDeclareStateMacro( Imaging ); 00307 igstkDeclareStateMacro( AttemptingToUpdate ); 00308 igstkDeclareStateMacro( AttemptingToStopImaging ); 00309 00311 igstkDeclareInputMacro( EstablishCommunication ); 00312 igstkDeclareInputMacro( StartImaging ); 00313 igstkDeclareInputMacro( AttachVideoImagerTool ); 00314 igstkDeclareInputMacro( UpdateStatus ); 00315 igstkDeclareInputMacro( StopImaging ); 00316 igstkDeclareInputMacro( Reset ); 00317 igstkDeclareInputMacro( CloseCommunication ); 00318 igstkDeclareInputMacro( ValidFrequency ); 00319 00320 igstkDeclareInputMacro( Success ); 00321 igstkDeclareInputMacro( Failure ); 00322 00325 void RequestAttachTool( VideoImagerToolType * videoImagerTool ); 00326 00328 ResultType RequestRemoveTool( VideoImagerToolType * videoImagerTool ); 00329 00331 static ITK_THREAD_RETURN_TYPE ImagingThreadFunction(void* pInfoStruct); 00332 00336 void UpdateStatus( void ); 00337 00340 void AttemptToOpenProcessing( void ); 00341 00344 void AttemptToStartImagingProcessing( void ); 00345 00347 void AttemptToStopImagingProcessing( void ); 00348 00351 void AttemptToAttachVideoImagerToolProcessing( void ); 00352 00355 void AttemptToUpdateStatusProcessing( void ); 00356 00359 void UpdateStatusSuccessProcessing( void ); 00360 00363 void UpdateStatusFailureProcessing( void ); 00364 00367 void CloseFromImagingStateProcessing( void ); 00368 00371 void CloseFromCommunicatingStateProcessing( void ); 00372 00375 void ResetFromImagingStateProcessing( void ); 00376 00379 void ResetFromToolsActiveStateProcessing( void); 00380 00383 void ResetFromCommunicatingStateProcessing( void ); 00384 00386 void CommunicationEstablishmentSuccessProcessing( void ); 00387 00389 void CommunicationEstablishmentFailureProcessing( void ); 00390 00392 void ToolsActivationSuccessProcessing( void ); 00393 00395 void ToolsActivationFailureProcessing( void ); 00396 00398 void StartImagingSuccessProcessing( void ); 00399 00401 void StartImagingFailureProcessing( void ); 00402 00405 void AttachingVideoImagerToolSuccessProcessing( void ); 00406 00409 void AttachingVideoImagerToolFailureProcessing( void ); 00410 00412 void StopImagingSuccessProcessing( void ); 00413 00415 void StopImagingFailureProcessing( void ); 00416 00418 void CloseCommunicationSuccessProcessing( void ); 00419 00421 void CloseCommunicationFailureProcessing( void ); 00422 00424 void EnterImagingStateProcessing( void ); 00425 00427 void DetachAllVideoImagerToolsFromVideoImager(); 00428 00430 void ReportInvalidRequestProcessing( void ); 00431 00433 void SetFrequencyProcessing( void ); 00434 00437 igstkCoordinateSystemClassInterfaceMacro(); 00438 00439 VideoImagerToolType * m_VideoImagerToolToBeAttached; 00440 00441 double m_FrequencyToBeSet; 00442 }; 00443 00444 } 00445 00446 #endif //__igstk_VideoImager_h_