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
void RequestPivotPoint()
This method is used to request the pivot point, given in the coordinate system in which the user supp...
#define igstkTypeMacro(thisClass, superclass)
Type Macro defines the GetNameOfClass() method for every class where it is invoked.
Definition: igstkMacros.h:128
igstkEventMacro(InitializationSuccessEvent, IGSTKEvent)
This event is generated if the initialization succeeds.
igstkStandardClassTraitsMacro(PivotCalibration, Object) void RequestInitialize(unsigned int n
Macro with standard traits declarations (Self, SuperClass, State Machine etc.).
igstkLoadedEventMacro(CalibrationFailureEvent, IGSTKEvent, EventHelperType::StringType)
This event is generated if the pivot calibration fails, either due to data acquisition problems or co...
std::string StringType
Definition: igstkEvents.h:60
Base class for all the IGSTK classes.
Definition: igstkObject.h:40
Object Self
General Typedefs.
Definition: igstkObject.h:48
void RequestComputeCalibration()
This method performs the data acquisition and calibration.
void PrintSelf(std::ostream &os, itk::Indent indent) const
Print the object information in a stream.
defines standard system-wide macros, constants, and other common parameters in the IGSTK Library...
#define igstkNewMacro(x)
New Macro creates a new object of a class that is using SmartPointers.
Definition: igstkMacros.h:115
::itk::SmartPointer< Self > Pointer
Definition: igstkObject.h:50
This class encapsulates the pivot calibration algorithm and tracking data acquistion for performing t...
itk::Point< double, 3 > PointType
Definition: igstkEvents.h:59
void RequestCalibrationRMSE()
This method is used to request the Root Mean Square Error (RMSE) of the overdetermined equation syste...
::itk::Object Superclass
Definition: igstkObject.h:49
igstk::TrackerTool::Pointer trackerTool
::itk::SmartPointer< const Self > ConstPointer
Definition: igstkObject.h:51
This class encapsulates the results of asking the coordinate reference system for a transform to anot...
void RequestCalibrationTransform()
This method is used to request the calibration transformation.