IGSTK
/tmp/buildd/igstk-4.4.0/Source/igstkCoordinateSystem.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Image Guided Surgery Software Toolkit
00004   Module:    $RCSfile: igstkCoordinateSystem.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-02 17:32:03 $
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 __igstkCoordinateSystem_h
00019 #define __igstkCoordinateSystem_h
00020 
00021 #include "igstkObject.h"
00022 #include "igstkStateMachine.h"
00023 #include "igstkTransform.h"
00024 
00025 namespace igstk
00026 {
00027 
00052 class CoordinateSystem;
00053 
00054 namespace Friends 
00055 {
00056 
00067 class CoordinateSystemHelper
00068 {
00069 public:
00074   template <class T>
00075   static const CoordinateSystem* 
00076     GetCoordinateSystem( const T & input )
00077     {
00078     return input->GetCoordinateSystem();  // private
00079     }
00080 };
00081 
00082 } // end of Friends namespace 
00083 
00084 
00085 class CoordinateSystem : public Object
00086 {
00087 public: 
00088 
00090   igstkStandardClassTraitsMacro( CoordinateSystem, Object )
00091 
00092   
00096   void RequestSetTransformAndParent(const Transform & t,
00097                                     const CoordinateSystem* parent);
00098 
00099   // Tries to update the transform to its parents   
00100   void RequestUpdateTransformToParent(const Transform & t);
00101 
00103   void RequestGetTransformToParent();
00104 
00115   void RequestComputeTransformTo(const 
00116                                  CoordinateSystem* targetCoordSys);
00117 
00120   void RequestDetachFromParent();
00121   
00126   igstkSetStringMacro( Name );
00127   igstkGetStringMacro( Name );
00128 
00130   igstkSetStringMacro( Type );
00131   igstkGetStringMacro( Type ); 
00132 
00133 protected:
00134 
00136   CoordinateSystem( void );
00137 
00139   ~CoordinateSystem( void );
00140 
00142   virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const; 
00143 
00144 private: 
00146   CoordinateSystem(const Self&);
00147 
00149   void operator=(const Self&);
00150 
00152   Self::ConstPointer  m_Parent;
00153 
00158   Transform           m_TransformToParent;
00159 
00161   std::string         m_Name;
00162 
00164   std::string      m_Type;
00165 
00171   igstkDeclareStateMacro( Initialized );
00172 
00174   igstkDeclareStateMacro( ParentSet );
00175 
00177   igstkDeclareStateMacro( AttemptingComputeTransformTo );
00178   igstkDeclareStateMacro( AttemptingComputeTransformToInInitialized );
00179 
00185   igstkDeclareInputMacro( NullCoordinateSystem  );
00186   igstkDeclareInputMacro( ThisCoordinateSystem  );
00187   igstkDeclareInputMacro( ValidCoordinateSystem );
00188 
00190   igstkDeclareInputMacro( NullParent                     ); 
00191   igstkDeclareInputMacro( ThisParent                     );
00192   igstkDeclareInputMacro( ValidParent                    );
00193   igstkDeclareInputMacro( ParentCausesCycle              );
00194   
00198   igstkDeclareInputMacro( AncestorFound                  );
00199   igstkDeclareInputMacro( Disconnected                   );
00200 
00203   igstkDeclareInputMacro( DetachFromParent               );
00204   
00206   igstkDeclareInputMacro( UpdateTransformToParent        );
00207 
00211   Transform                        m_TransformFromRequestSetTransformAndParent;
00212   Self::ConstPointer               m_ParentFromRequestSetTransformAndParent;
00213 
00215   void SetTransformAndParentNullParentProcessing();
00216 
00218   void SetTransformAndParentThisParentProcessing();
00219 
00223   void SetTransformAndParentCycleProcessing(); 
00224 
00226   void SetTransformAndParentProcessing();
00227 
00229   void UpdateTransformToParentProcessing();
00230 
00235   Self::ConstPointer               m_TargetFromRequestComputeTransformTo;
00236 
00240   void ComputeTransformToThisTargetProcessing();
00241 
00245   void ComputeTransformToNullTargetProcessing();
00246 
00250   void ComputeTransformToValidTargetProcessing();
00251 
00255   void ComputeTransformToDisconnectedProcessing();
00256 
00261   void ComputeTransformToAncestorFoundProcessing();
00262 
00268   void FindLowestCommonAncestor(const Self* targetCoordinateSystem);
00269 
00276   Self::ConstPointer                m_LowestCommonAncestor;
00277 
00282   Transform ComputeTransformTo(const CoordinateSystem* ancestor) const;
00283 
00288   bool CanReach(const CoordinateSystem* target) const;
00289 
00293   void InvalidRequestProcessing();
00294 
00296   void DoNothingProcessing();
00297 
00299   void DetachFromParentProcessing();
00300 
00304   const CoordinateSystem* GetCoordinateSystem() const;
00305 
00307   igstkFriendClassMacro( igstk::Friends::CoordinateSystemHelper ); 
00308 
00309 }; // class CoordinateSystem
00310 
00311 
00312 //  
00313 //   Macros defining events related to the CoordinateSystem.
00314 //
00315 igstkEventMacro( CoordinateSystemErrorEvent, IGSTKErrorEvent );
00316 igstkEventMacro( CoordinateSystemSetParentError, CoordinateSystemErrorEvent );
00317 
00321 igstkEventMacro( CoordinateSystemNullParentEvent, 
00322                  CoordinateSystemSetParentError );
00323 
00327 igstkEventMacro( CoordinateSystemThisParentEvent, 
00328                  CoordinateSystemSetParentError );
00329 
00333 igstkLoadedConstObjectEventMacro( CoordinateSystemParentCycleEvent,
00334                                   CoordinateSystemSetParentError, 
00335                                   CoordinateSystem );
00336 
00337 } // end namespace igstk
00338 
00339 #endif // __igstkCoordinateSystem_h