CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxIgstkTracker.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 CXIGSTKTRACKER_H_
34 #define CXIGSTKTRACKER_H_
35 
36 #include "org_custusx_core_tracking_Export.h"
37 
38 #include <QObject>
39 
40 #include <map>
41 #include <boost/shared_ptr.hpp>
42 #include <igstkLogger.h>
43 #include <igstkTracker.h>
44 #include <igstkPolarisTracker.h>
45 #include <igstkAuroraTracker.h>
46 #include <itkStdStreamLogOutput.h>
47 #ifdef WIN32
48 #include "igstkSerialCommunicationForWindows.h"
49 #else
50 #include "igstkSerialCommunicationForPosix.h"
51 #endif
52 #include "cxTool.h"
53 #include "cxDefinitions.h"
54 #include "cxForwardDeclarations.h"
55 
56 namespace cx
57 {
64 typedef std::map<QString, ToolPtr> ToolMap;
65 
66 class IgstkTool;
67 typedef boost::shared_ptr<IgstkTool> IgstkToolPtr;
68 typedef boost::weak_ptr<IgstkTool> IgstkToolWeakPtr;
69 
77 class org_custusx_core_tracking_EXPORT IgstkTracker: public QObject
78 {
79 Q_OBJECT
80 public:
81  static QStringList getSupportedTrackingSystems();
82 
83 #ifdef WIN32
84 
85  typedef igstk::SerialCommunicationForWindows CommunicationType;
86 #else
87 
88  typedef igstk::SerialCommunicationForPosix CommunicationType;
89 #endif
90  typedef igstk::Tracker TrackerType;
91  typedef igstk::PolarisTracker PolarisTrackerType;
92  typedef igstk::AuroraTracker AuroraTrackerType;
93 
94  /*only used for documentation purposes
95  enum TRACKING_SYSTEM
96  {
97  tsNONE, ///< Not specified
98  tsPOLARIS, ///< NDIs Polaris tracker
99  tsPOLARIS_SPECTRA, ///< NDIs Polaris Spectra tracker
100  tsPOLARIS_VICRA, ///< NDIs Polaris Vicra tracker
101  tsPOLARIS_CLASSIC, ///< NDIs Polaris Classic tracker
102  tsAURORA, ///< NDIs Aurora tracker
103  tsMICRON, ///< Claron Technologys Micron tracker
104  tsCOUNT
105  };*/
106 
107  /*only used for documentation purposes
108  TRACKER_INVALID_REQUEST, ///< internal state machine didn't accept the request
109  TRACKER_OPEN, ///< hardware accepted the tracker as open
110  TRACKER_INITIALIZED, ///< hardware accepted the tracker as initialized
111  TRACKER_TRACKING, ///< tracker is tracking
112  TRACKER_UPDATE_STATUS, ///< tracker got an update event
113  TRACKER_TOOL_TRANSFORM_UPDATED, ///< a tool attached to the tracker got a new transform
114  TRACKER_COMMUNICATION_COMPLETE, ///< communication port completed a task successfully
115  TRACKER_COMMUNICATION_INPUT_OUTPUT_ERROR, ///< communication port failed at completing a task
116  TRACKER_COMMUNICATION_INPUT_OUTPUT_TIMEOUT, ///< communication port timed out
117  TRACKER_COMMUNICATION_OPEN_PORT_ERROR ///< communication port tried to open or close
118  */
119 
122  {
123  TRACKING_SYSTEM mType;
126  mType(tsNONE),
127  mLoggingFolderName("")
128  {}
129  };
130 
131  IgstkTracker(InternalStructure internalStructure);
132  ~IgstkTracker();
133 
134  TRACKING_SYSTEM getType() const;
135  QString getName() const;
136  QString getUid() const;
137  TrackerType* getPointer() const;
138  void open();
139  void close();
140  void attachTools(std::map<QString, IgstkToolPtr> tools);
141  void detachTools(std::map<QString, IgstkToolPtr> tools);
142  void startTracking();
143  void stopTracking();
144 
145  bool isValid() const;
146  bool isOpen() const;
147  bool isInitialized() const;
148  bool isTracking() const;
149 
150 signals:
151  void initialized(bool);
152  void open(bool);
153  void tracking(bool);
154  void error();
155 
156 protected:
157  typedef itk::ReceptorMemberCommand<IgstkTracker> ObserverType;
158 
159  void trackerTransformCallback(const itk::EventObject &eventVar);
160  void addLogging();
161 
162  void internalOpen(bool value);
163  void internalInitialized(bool value);
164  void internalTracking(bool value);
165  void internalError(bool value);
166 
167  void shutdown();
168 
170  bool mValid;
171  QString mUid;
172  QString mName;
174 
175  PolarisTrackerType::Pointer mTempPolarisTracker;
176  AuroraTrackerType::Pointer mTempAuroraTracker;
177 
178  CommunicationType::Pointer mCommunication;
179  ObserverType::Pointer mTrackerObserver;
180  igstk::Logger::Pointer mTrackerLogger;
181  itk::StdStreamLogOutput::Pointer mTrackerLogOutput;
182 
183  bool mOpen;
185  bool mTracking;
186 
187 private:
188  IgstkTracker() {}
189 };
190 typedef boost::shared_ptr<IgstkTracker> TrackerPtr;
191 typedef boost::weak_ptr<IgstkTracker> TrackerWeakPtr;
192 
196 } //namespace cx
197 
198 #endif /* CXIGSTKTRACKER_H_ */
boost::weak_ptr< IgstkTool > IgstkToolWeakPtr
Definition: cxIgstkTool.h:62
bool mTracking
whether or not the tracker is tracking
boost::shared_ptr< IgstkTracker > TrackerPtr
tsNONE
Not specified.
InternalStructure mInternalStructure
the trackers type
igstk::SerialCommunicationForPosix CommunicationType
PolarisTrackerType::Pointer mTempPolarisTracker
pointer to a temp polaris tracker
bool mValid
whether this tracker is constructed correctly or not
boost::shared_ptr< IgstkTool > IgstkToolPtr
Definition: cxIgstkTool.h:60
Class representing the navigation system.
ObserverType::Pointer mTrackerObserver
observer listening for igstk events
std::map< QString, ToolPtr > ToolMap
boost::weak_ptr< IgstkTracker > TrackerWeakPtr
bool mOpen
whether or not the tracker is open
QString mLoggingFolderName
path to where log should be saved
TrackerType * mTracker
pointer to the base class of the internal igstk tracker
QString mUid
the trackers unique id
igstk::Tracker TrackerType
itk::ReceptorMemberCommand< IgstkTracker > ObserverType
CommunicationType::Pointer mCommunication
pointer to the serial communication used to communicate with the NDI trackers
igstk::Logger::Pointer mTrackerLogger
logging the internal igstk behavior
Class for controlling the igstk tracking (hardware) interface.
Definition: cxIgstkTool.h:72
bool mInitialized
whether or not the tracker is initialized
igstk::AuroraTracker AuroraTrackerType
TRACKING_SYSTEM mType
the trackers type
AuroraTrackerType::Pointer mTempAuroraTracker
pointer to a temp aurora tracker
itk::StdStreamLogOutput::Pointer mTrackerLogOutput
output to write the log to
QString mName
the trackers name
InternalStructure()
set default values for the internal structure
igstk::PolarisTracker PolarisTrackerType