00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 *caller, const itk::EventObject & event){};
00160
00162 typedef itk::MemberCommand<PivotCalibration> TransformAcquiredCommand;
00163 TransformAcquiredCommand::Pointer m_TransformAcquiredObserver;
00164
00165 igstkObserverMacro( TransformToTracker,
00166 igstk::CoordinateSystemTransformToEvent,
00167 CoordinateSystemTransformToResult )
00168 TransformToTrackerObserver::Pointer m_TransformObserver;
00169 unsigned long m_TransformToTrackerObserverID;
00170
00171 void AcquireTransformsAndCalibrate(itk::Object *caller,
00172 const itk::EventObject & event);
00173
00174 class ErrorObserver : public itk::Command
00175 {
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
00223 ErrorObserver(const Self&);
00224 void operator=(const Self&);
00225 };
00226
00227
00228
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
00248 std::vector< PivotCalibrationAlgorithm::TransformType > m_Transforms;
00249
00250
00251 TrackerTool::Pointer m_TmpTrackerTool;
00252 TrackerTool::Pointer m_TrackerTool;
00253
00254 unsigned int m_TmpRequiredNumberOfTransformations;
00255 unsigned int m_RequiredNumberOfTransformations;
00256
00257
00258 PivotCalibrationAlgorithm::Pointer m_PivotCalibrationAlgorithm;
00259 };
00260
00261 }
00262
00263 #endif //__igstkPivotCalibration_h