Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxIgstkTool.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXIGSTKTOOL_H_
34 #define CXIGSTKTOOL_H_
35 
36 #include "org_custusx_core_tracking_system_igstk_Export.h"
37 
38 #include <QObject>
39 #include "cxToolUsingIGSTK.h"
40 
41 #include <limits.h>
42 #include <boost/shared_ptr.hpp>
43 #include <igstkPolarisTrackerTool.h>
44 #include <igstkAuroraTrackerTool.h>
45 #include <igstkTransform.h>
46 #include <igstkLogger.h>
47 #include <itkStdStreamLogOutput.h>
48 #include "cxTransform3D.h"
49 #include "cxIgstkTracker.h"
50 #include "vtkForwardDeclarations.h"
51 #include "igstkNDITracker.h"
52 
53 namespace cx
54 {
61 class IgstkTool;
62 typedef boost::shared_ptr<IgstkTool> IgstkToolPtr;
63 typedef boost::weak_ptr<IgstkTool> IgstkToolWeakPtr;
64 
73 class org_custusx_core_tracking_system_igstk_EXPORT IgstkTool: public QObject
74 {
75 Q_OBJECT
76 
77 public:
78  static igstk::Transform toIgstkTransform(Transform3D transform);
79  static Transform3D toTransform3D(igstk::Transform transform);
80 
82  virtual ~IgstkTool();
83 
84  ToolFileParser::ToolInternalStructure getInternalStructure();
85  QString getUid();
86 
87  igstk::TrackerTool::Pointer getPointer() const;
88  TRACKING_SYSTEM getTrackerType();
89 // Tool::Type getType() const;
90  bool isReference() const
91  {
92  return mInternalStructure.mIsReference;
93  }
94 
95  bool isValid() const;
96  bool isInitialized() const;
97  bool isTracked() const;
98  bool isVisible() const;
99 
100  void setReference(IgstkToolPtr);
101  void setTracker(TrackerPtr tracker);
102  void setCalibrationTransform(Transform3D calibration);
103  void updateCalibration(const Transform3D& sMt);
104 
105  void printInternalStructure();
106 
107 signals:
108  void attachedToTracker(bool);
109  void tracked(bool);
110  void toolVisible(bool);
111  void toolTransformAndTimestamp(Transform3D matrix, double timestamp, ToolPositionMetadata metadata);
112 
113 private:
114  void toolTransformCallback(const itk::EventObject &event);
115  igstk::TrackerTool::Pointer buildInternalTool();
116  void determineToolsCalibration();
117  void internalAttachedToTracker(bool value);
118  void internalTracked(bool value);
119  void internalVisible(bool value);
120  void addLogging();
121  igstk::NDITracker::TrackingSampleInfo getSampleInfo();
122  bool validReferenceForResult(igstk::CoordinateSystemTransformToResult result);
123 
124  ToolFileParser::ToolInternalStructure mInternalStructure;
125  igstk::TrackerTool::Pointer mTool;
126  IgstkToolWeakPtr mReferenceTool;
127  TrackerWeakPtr mTracker;
128  itk::ReceptorMemberCommand<IgstkTool>::Pointer mToolObserver;
129  igstk::Logger::Pointer mLogger;
130  itk::StdStreamLogOutput::Pointer mLogOutput;
131 
132  double mLatestEmittedTimestamp;
133  //internal states
134  //TODO is volatile enough for thread safety?
135  volatile bool mValid;
136  volatile bool mVisible;
137  volatile bool mAttachedToTracker;
138  volatile bool mTracked;
139 
140  Transform3D igstk2Transform3D(const igstk::Transform &input) const;
141  void processReceivedTransformResult(igstk::CoordinateSystemTransformToResult result);
142 };
143 
147 }
148 
149 #endif /* CXIGSTKTOOL_H_ */
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
bool isReference() const
Definition: cxIgstkTool.h:90
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class IgstkTool > IgstkToolPtr
boost::weak_ptr< IgstkTracker > TrackerWeakPtr
boost::weak_ptr< IgstkTool > IgstkToolWeakPtr
Definition: cxIgstkTool.h:63
Class for controlling the igstk tracking (hardware) interface.
Definition: cxIgstkTool.h:73
boost::shared_ptr< IgstkTracker > TrackerPtr