IGSTK
igstkPivotCalibration.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkPivotCalibration.h,v $
5  Language: C++
6  Date: $Date: 2011-01-18 21:40:17 $
7  Version: $Revision: 1.14 $
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 __igstkPivotCalibration_h
19 #define __igstkPivotCalibration_h
20 
21 #include "igstkStateMachine.h"
22 #include "igstkMacros.h"
23 #include "igstkEvents.h"
24 #include "igstkObject.h"
25 #include "igstkTracker.h"
26 #include "igstkTrackerTool.h"
28 #include "igstkTransformObserver.h"
29 
30 namespace igstk
31 {
32 
46 class PivotCalibration : public Object
47 {
48 
49 public:
50 
54 
55 
56 
61  void RequestInitialize( unsigned int n,
63 
73 
80 
85  void RequestPivotPoint();
86 
93 
95  igstkEventMacro( InitializationSuccessEvent, IGSTKEvent );
96 
99  igstkEventMacro( InitializationFailureEvent, IGSTKEvent );
100 
102  igstkEventMacro( CalibrationSuccessEvent, IGSTKEvent );
103 
107  igstkLoadedEventMacro( CalibrationFailureEvent,
108  IGSTKEvent,
110 
112  igstkEventMacro( DataAcquisitionStartEvent, IGSTKEvent );
113 
116  igstkEventMacro( DataAcquisitionEvent, DoubleTypeEvent );
117 
119  igstkEventMacro( DataAcquisitionEndEvent, IGSTKEvent );
120 
121 protected:
122 
123  PivotCalibration( void );
124  ~PivotCalibration( void );
125 
127  void PrintSelf( std::ostream& os, itk::Indent indent ) const;
128 
129 private:
130 
132  igstkDeclareStateMacro( Idle );
133  igstkDeclareStateMacro( AttemptingToInitialize );
134  igstkDeclareStateMacro( Initialized );
135  igstkDeclareStateMacro( AttemptingToComputeCalibration );
136  igstkDeclareStateMacro( CalibrationComputed );
137 
138 
140  igstkDeclareInputMacro( Initialize );
141  igstkDeclareInputMacro( Failed );
142  igstkDeclareInputMacro( Succeeded );
143  igstkDeclareInputMacro( ComputeCalibration );
144  igstkDeclareInputMacro( GetTransform );
145  igstkDeclareInputMacro( GetPivotPoint );
146  igstkDeclareInputMacro( GetRMSE );
147 
149  void ReportInvalidRequestProcessing();
150  void InitializeProcessing();
151  void ReportInitializationFailureProcessing();
152  void ReportInitializationSuccessProcessing();
153  void ComputeCalibrationProcessing();
154  void ReportCalibrationComputationSuccessProcessing();
155  void ReportCalibrationComputationFailureProcessing();
156  void GetTransformProcessing();
157  void GetPivotPointProcessing();
158  void GetRMSEProcessing();
159  void EmptyCallBack( itk::Object * itkNotUsed(caller),
160  const itk::EventObject & itkNotUsed(event)){};
161 
163  typedef itk::MemberCommand<PivotCalibration> TransformAcquiredCommand;
164  TransformAcquiredCommand::Pointer m_TransformAcquiredObserver;
165 
166  igstkObserverMacro( TransformToTracker,
167  igstk::CoordinateSystemTransformToEvent,
169  TransformToTrackerObserver::Pointer m_TransformObserver;
170  unsigned long m_TransformToTrackerObserverID;
171 
172  void AcquireTransformsAndCalibrate(itk::Object *caller,
173  const itk::EventObject & event);
174 
175  class ErrorObserver : public itk::Command
176  {
177  public:
178 
179  typedef ErrorObserver Self;
180  typedef ::itk::Command Superclass;
181  typedef ::itk::SmartPointer<Self> Pointer;
182  typedef ::itk::SmartPointer<const Self> ConstPointer;
183 
184  igstkNewMacro(Self)
185  igstkTypeMacro(ErrorObserver, itk::Command)
186 
189  virtual void Execute(itk::Object *caller,
190  const itk::EventObject & event) throw (std::exception);
191 
194  virtual void Execute(const itk::Object *caller,
195  const itk::EventObject & event) throw (std::exception);
196 
198  void ClearError() {this->m_ErrorOccured = false;
199  this->m_ErrorMessage.clear();}
202  bool ErrorOccured() {return this->m_ErrorOccured;}
204  void GetErrorMessage(std::string &errorMessage)
205  {
206  errorMessage = this->m_ErrorMessage;
207  }
208 
209  protected:
210 
213  ErrorObserver();
214  virtual ~ErrorObserver(){}
215 
216  private:
217 
218  bool m_ErrorOccured;
219  std::string m_ErrorMessage;
220  std::map<std::string,std::string> m_ErrorEvent2ErrorMessage;
221 
222  //purposely not implemented
223  ErrorObserver(const Self&);
224  void operator=(const Self&);
225  };
226 
227  //definitions of the observer classes of events generated by the
228  //PivotCalibrationAlgorithm
229  igstkObserverMacro( CalibrationTransform,
230  CoordinateSystemTransformToEvent,
231  CoordinateSystemTransformToResult )
232 
233  igstkObserverMacro( PivotPoint, PointEvent, EventHelperType::PointType )
234 
235  igstkObserverMacro( CalibrationRMSE,
236  DoubleTypeEvent,
237  EventHelperType::DoubleType )
238 
239 
240  CalibrationTransformObserver::Pointer m_GetCalibrationTransformObserver;
241  PivotPointObserver::Pointer m_GetPivotPointObserver;
242  CalibrationRMSEObserver::Pointer m_GetCalibrationRMSEObserver;
243 
244  ErrorObserver::Pointer m_ErrorObserver;
245  std::string m_ReasonForCalibrationFailure;
246 
247  //transformations used for pivot calibration
248  std::vector< PivotCalibrationAlgorithm::TransformType > m_Transforms;
249 
250  //tool we want to calibrate
251  TrackerTool::Pointer m_TmpTrackerTool;
252  TrackerTool::Pointer m_TrackerTool;
253  //number of transformation we want to acquire
254  unsigned int m_TmpRequiredNumberOfTransformations;
255  unsigned int m_RequiredNumberOfTransformations;
256 
257  //the object that actually does all the work
258  PivotCalibrationAlgorithm::Pointer m_PivotCalibrationAlgorithm;
259 };
260 
261 } // end namespace igstk
262 
263 #endif //__igstkPivotCalibration_h