IGSTK
/tmp/buildd/igstk-4.4.0/Source/igstkPivotCalibration.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Image Guided Surgery Software Toolkit
00004   Module:    $RCSfile: igstkPivotCalibration.h,v $
00005   Language:  C++
00006   Date:      $Date: 2011-01-18 21:40:17 $
00007   Version:   $Revision: 1.14 $
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 __igstkPivotCalibration_h
00019 #define __igstkPivotCalibration_h
00020 
00021 #include "igstkStateMachine.h"
00022 #include "igstkMacros.h"
00023 #include "igstkEvents.h"
00024 #include "igstkObject.h"
00025 #include "igstkTracker.h"
00026 #include "igstkTrackerTool.h"
00027 #include "igstkPivotCalibrationAlgorithm.h"
00028 #include "igstkTransformObserver.h"
00029 
00030 namespace igstk
00031 {
00032 
00046 class PivotCalibration : public Object
00047 {
00048   
00049 public:
00050   
00053   igstkStandardClassTraitsMacro( PivotCalibration, Object )
00054 
00055 
00056   
00061   void RequestInitialize( unsigned int n, 
00062                           igstk::TrackerTool::Pointer trackerTool );
00063 
00072   void RequestComputeCalibration();
00073 
00079   void RequestCalibrationTransform();
00080 
00085   void RequestPivotPoint();
00086 
00092   void RequestCalibrationRMSE();
00093 
00095   igstkEventMacro( InitializationSuccessEvent, IGSTKEvent );
00096 
00099   igstkEventMacro( InitializationFailureEvent, IGSTKEvent );
00100 
00102   igstkEventMacro( CalibrationSuccessEvent, IGSTKEvent );
00103 
00107   igstkLoadedEventMacro( CalibrationFailureEvent, 
00108                          IGSTKEvent, 
00109                          EventHelperType::StringType );
00110 
00112   igstkEventMacro( DataAcquisitionStartEvent, IGSTKEvent );
00113 
00116   igstkEventMacro( DataAcquisitionEvent, DoubleTypeEvent );
00117 
00119   igstkEventMacro( DataAcquisitionEndEvent, IGSTKEvent );
00120 
00121 protected:
00122 
00123   PivotCalibration( void );
00124   ~PivotCalibration( void );
00125 
00127   void PrintSelf( std::ostream& os, itk::Indent indent ) const;
00128 
00129 private:
00130 
00132   igstkDeclareStateMacro( Idle );
00133   igstkDeclareStateMacro( AttemptingToInitialize );
00134   igstkDeclareStateMacro( Initialized );
00135   igstkDeclareStateMacro( AttemptingToComputeCalibration );
00136   igstkDeclareStateMacro( CalibrationComputed );
00137 
00138 
00140   igstkDeclareInputMacro( Initialize );
00141   igstkDeclareInputMacro( Failed  );
00142   igstkDeclareInputMacro( Succeeded  );
00143   igstkDeclareInputMacro( ComputeCalibration );
00144   igstkDeclareInputMacro( GetTransform  );
00145   igstkDeclareInputMacro( GetPivotPoint  );
00146   igstkDeclareInputMacro( GetRMSE  );
00147 
00149   void ReportInvalidRequestProcessing();  
00150   void InitializeProcessing();
00151   void ReportInitializationFailureProcessing();
00152   void ReportInitializationSuccessProcessing();
00153   void ComputeCalibrationProcessing();
00154   void ReportCalibrationComputationSuccessProcessing();
00155   void ReportCalibrationComputationFailureProcessing();
00156   void GetTransformProcessing();
00157   void GetPivotPointProcessing();
00158   void GetRMSEProcessing();
00159   void EmptyCallBack( itk::Object * itkNotUsed(caller), 
00160                       const itk::EventObject & itkNotUsed(event)){};
00161 
00163   typedef itk::MemberCommand<PivotCalibration> TransformAcquiredCommand;
00164   TransformAcquiredCommand::Pointer m_TransformAcquiredObserver;
00165 
00166   igstkObserverMacro( TransformToTracker, 
00167                                         igstk::CoordinateSystemTransformToEvent,
00168                                              CoordinateSystemTransformToResult )
00169   TransformToTrackerObserver::Pointer m_TransformObserver; 
00170   unsigned long m_TransformToTrackerObserverID;
00171 
00172   void AcquireTransformsAndCalibrate(itk::Object *caller, 
00173                                      const itk::EventObject & event);
00174 
00175   class ErrorObserver : public itk::Command
00176     {
00177   public:
00178 
00179     typedef ErrorObserver                    Self;
00180     typedef ::itk::Command                   Superclass;
00181     typedef ::itk::SmartPointer<Self>        Pointer;
00182     typedef ::itk::SmartPointer<const Self>  ConstPointer;
00183 
00184     igstkNewMacro(Self)
00185     igstkTypeMacro(ErrorObserver, itk::Command)
00186 
00189     virtual void Execute(itk::Object *caller, 
00190                        const itk::EventObject & event) throw (std::exception);
00191 
00194     virtual void Execute(const itk::Object *caller, 
00195                        const itk::EventObject & event) throw (std::exception);
00196 
00198     void ClearError() {this->m_ErrorOccured = false; 
00199                        this->m_ErrorMessage.clear();}
00202     bool ErrorOccured() {return this->m_ErrorOccured;}
00204     void GetErrorMessage(std::string &errorMessage) 
00205       {
00206       errorMessage = this->m_ErrorMessage;
00207       }
00208 
00209   protected:
00210 
00213     ErrorObserver();
00214     virtual ~ErrorObserver(){}
00215 
00216   private:
00217 
00218     bool                               m_ErrorOccured;
00219     std::string                        m_ErrorMessage;
00220     std::map<std::string,std::string>  m_ErrorEvent2ErrorMessage;
00221 
00222     //purposely not implemented
00223     ErrorObserver(const Self&);
00224     void operator=(const Self&); 
00225     };
00226 
00227   //definitions of the observer classes of events generated by the 
00228   //PivotCalibrationAlgorithm
00229   igstkObserverMacro( CalibrationTransform, 
00230                       CoordinateSystemTransformToEvent, 
00231                       CoordinateSystemTransformToResult )
00232 
00233   igstkObserverMacro( PivotPoint, PointEvent, EventHelperType::PointType )
00234 
00235   igstkObserverMacro( CalibrationRMSE, 
00236                       DoubleTypeEvent, 
00237                       EventHelperType::DoubleType )
00238   
00239   
00240   CalibrationTransformObserver::Pointer m_GetCalibrationTransformObserver;
00241   PivotPointObserver::Pointer           m_GetPivotPointObserver;
00242   CalibrationRMSEObserver::Pointer      m_GetCalibrationRMSEObserver;
00243 
00244   ErrorObserver::Pointer                m_ErrorObserver;
00245   std::string                           m_ReasonForCalibrationFailure;
00246   
00247   //transformations used for pivot calibration
00248   std::vector< PivotCalibrationAlgorithm::TransformType > m_Transforms;
00249 
00250   //tool we want to calibrate
00251   TrackerTool::Pointer  m_TmpTrackerTool;
00252   TrackerTool::Pointer  m_TrackerTool;
00253   //number of transformation we want to acquire
00254   unsigned int m_TmpRequiredNumberOfTransformations;
00255   unsigned int m_RequiredNumberOfTransformations;
00256 
00257   //the object that actually does all the work
00258   PivotCalibrationAlgorithm::Pointer m_PivotCalibrationAlgorithm;
00259 };
00260 
00261 } // end namespace igstk
00262 
00263 #endif //__igstkPivotCalibration_h