IGSTK
/build/buildd/igstk-4.4.0/Source/igstkPivotCalibrationAlgorithm.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Image Guided Surgery Software Toolkit
00004   Module:    $RCSfile: igstkPivotCalibrationAlgorithm.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-07-05 19:53:19 $
00007   Version:   $Revision: 1.5 $
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 __igstkPivotCalibrationAlgorithm_h
00019 #define __igstkPivotCalibrationAlgorithm_h
00020 
00021 #include <vector>
00022 #include "igstkStateMachine.h"
00023 #include "igstkMacros.h"
00024 #include "igstkObject.h"
00025 #include "igstkTransform.h"
00026 
00027 namespace igstk
00028 {
00029 
00069 class PivotCalibrationAlgorithm : public Object
00070 {
00071 
00072 public:
00073   
00076   igstkStandardClassTraitsMacro( PivotCalibrationAlgorithm, Object )
00077 
00078   typedef itk::Point< double, 3 >    PointType;
00079   typedef igstk::Transform           TransformType;
00080   typedef std::vector<TransformType> TransformContainerType;
00081 
00087    void RequestAddTransform( const TransformType & t );
00088   
00094   void RequestAddTransforms( std::vector< TransformType > & t );
00095 
00098   void RequestResetCalibration();
00099 
00107   void RequestComputeCalibration();
00108 
00114   void RequestCalibrationTransform();
00115 
00120   void RequestPivotPoint();
00121 
00128   void RequestCalibrationRMSE();
00129 
00137   void RequestSetSingularValueThreshold( double threshold );
00138 
00140   igstkEventMacro( CalibrationFailureEvent, IGSTKEvent );
00141 
00143   igstkEventMacro( CalibrationSuccessEvent, IGSTKEvent );
00144 
00147   static const double DEFAULT_SINGULAR_VALUE_THRESHOLD;
00148 
00149 protected:
00150 
00151   PivotCalibrationAlgorithm  ( void );
00152   virtual ~PivotCalibrationAlgorithm ( void );
00153 
00155   void PrintSelf( std::ostream& os, itk::Indent indent ) const;
00156 
00157 private:
00158 
00161   bool CheckCalibrationDataValidity();
00162 
00164   igstkDeclareStateMacro( Idle );
00165   igstkDeclareStateMacro( AttemptingToComputeCalibration );
00166   igstkDeclareStateMacro( CalibrationComputed );
00167 
00169   igstkDeclareInputMacro( AddTransform );
00170   igstkDeclareInputMacro( SetSingularValueThreshold );
00171   igstkDeclareInputMacro( ComputeCalibration );
00172   igstkDeclareInputMacro( GetTransform  );
00173   igstkDeclareInputMacro( GetPivotPoint  );
00174   igstkDeclareInputMacro( GetRMSE  );
00175   igstkDeclareInputMacro( ResetCalibration );
00176   igstkDeclareInputMacro( CalibrationComputationSuccess  );
00177   igstkDeclareInputMacro( CalibrationComputationFailure  );
00178 
00180   void ReportInvalidRequestProcessing();  
00181   void AddTransformProcessing();
00182   void SetSingularValueThresholdProcessing();
00183   void ComputeCalibrationProcessing();
00184   void ResetCalibrationProcessing();
00185   void ReportSuccessInCalibrationComputationProcessing();
00186   void ReportFailureInCalibrationComputationProcessing();
00187   void GetTransformProcessing();
00188   void GetPivotPointProcessing();
00189   void GetRMSEProcessing();
00190 
00191   //transformations used for pivot calibration
00192   TransformContainerType m_Transforms;
00193   //transformations the user wants to add, because of the way the 
00194   //state machine works we need to first store them in 
00195   //a temporary variable. They will be moved to the m_Transforms 
00196   //container only if the state machine is in a state that
00197   //enables adding transformations
00198   TransformContainerType m_TmpTransforms;
00199 
00200   //computed translation between tracked coordinate system and pivot 
00201   //point
00202   TransformType m_Transform;
00203 
00204   //computed pivot point in the tracker's coordinate system
00205   itk::Point< double,3 > m_PivotPoint;
00206 
00207   //root mean squared error of the vector [Ax-b]
00208   double m_RMSE;
00209 
00210   //below this threshold the singular values of SVD(A) are set to zero
00211   double m_SingularValueThreshold;
00212   double m_TmpSingularValueThreshold;
00213 
00214 };
00215 
00216 } // end namespace igstk
00217 
00218 #endif //__igstkPivotCalibrationAlgorithm_h