PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
AtracsysTracker.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4 See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #ifndef __AtracsysTracker_h
8 #define __AtracsysTracker_h
9 
10 #include <string>
11 #include <vector>
12 #include <vtkNew.h>
13 #include <vtkMatrix4x4.h>
14 #include <map>
15 
16 struct ftkOptionsInfo;
17 
18 namespace Atracsys
19 {
20  // Functions to safely convert string to int32 or float
21  bool strToInt32(const std::string& str, int& var);
22  bool strToFloat32(const std::string& str, float& var);
23 
24  // Class to hold the 3D and 2D coordinates in mm and pixel respectively of
25  // a single fiducial in the view of the camera
26  class Fiducial
27  {
28  public:
29  Fiducial() {};
30  // Overloaded operators, only for 3D coordinates
31  // override equality operator to make fids less than EQUALITY_DISTANCE_MM considered equal
32  bool operator==(const Fiducial& f) const;
33  // compare fiducials on distance from the origin
34  bool operator<(const Fiducial& f) const;
35  uint32_t id = 0;
36  // 3D
37  uint32_t Fid3dStatus = 0;
38  float xMm = 0;
39  float yMm = 0;
40  float zMm = 0;
41  float epipolarErrorPx = 0;
42  float probability = -1;
43  float triangulErrorMm = 0;
44  // 2D left
45  uint32_t Fid2dLeftStatus = 0;
46  float xLeftPx = 0;
47  float yLeftPx = 0;
48  uint16_t heightLeftPx = 0;
49  uint16_t widthLeftPx = 0;
50  uint32_t pixCountLeft = 0;
51  // 2D right
52  uint32_t Fid2dRightStatus = 0;
53  float xRightPx = 0;
54  float yRightPx = 0;
55  uint16_t heightRightPx = 0;
56  uint16_t widthRightPx = 0;
57  uint32_t pixCountRight = 0;
58  };
59 
60  typedef std::vector<Fiducial> Fiducials;
61 
62  // Class to hold position and metadata of a marker in the camera's field of view
63  class Marker
64  {
65  public:
66  Marker();
67  // toolToTracker is deep copied in this constructor
68  Marker(int status, int trackingId, int geometryId,
69  vtkMatrix4x4* toolToTracker, int geometryPresenceMask, float registrationErrorMM);
70  Marker(const Marker&);
71  bool AddFiducial(Fiducial fid);
72  uint32_t GetMarkerStatus() { return MarkerStatus; }
73  uint32_t GetTrackingID() { return TrackingId; }
74  uint32_t GetGeometryID() { return GeometryId; }
75  vtkMatrix4x4* GetTransformToTracker() { return this->ToolToTracker.GetPointer(); }
76  uint32_t GetGeometryPresenceMask() { return GeometryPresenceMask; }
77  float GetFiducialRegistrationErrorMm() { return RegistrationErrorMm; }
78  const Fiducials& GetFiducials() { return fiducials; }
79 
80  private:
81  uint32_t MarkerStatus;
82  uint32_t TrackingId;
83  uint32_t GeometryId;
84  vtkNew<vtkMatrix4x4> ToolToTracker;
85  uint32_t GeometryPresenceMask; // presence mask of fiducials expressed as their numerical indices
86  float RegistrationErrorMm; // mean fiducial registration error (unit mm)
87  Fiducials fiducials; // fiducial coordinates
88  };
89 
90  class Tracker
91  {
92  public:
93  /* Constructor & destructor */
94  Tracker();
95  virtual ~Tracker();
96 
97  enum RESULT
98  {
99  SUCCESS = 0,
129  };
130 
132  {
138  };
139 
141  {
144  };
145 
146  /* Is onboard/embedded processing on ?*/
147  bool IsOnboardProcessing();
148 
150  bool IsVirtual();
151 
153  void Pause(bool tof);
154 
156  RESULT Connect();
157 
159  RESULT Disconnect();
160 
162  RESULT GetSDKversion(std::string& version);
163 
165  RESULT GetCalibrationDate(std::string& date);
166 
168  RESULT GetDeviceType(DEVICE_TYPE& deviceType);
169 
171  RESULT GetDeviceId(uint64_t& id);
172 
179  RESULT GetCamerasCalibration(std::array<float,10>& leftIntrinsic, std::array<float, 10>& rightIntrinsic,
180  std::array<float, 3>& rightPosition, std::array<float, 3>& rightOrientation);
181 
183  RESULT LoadMarkerGeometryFromFile(std::string filePath, int& geometryId);
184 
186  RESULT LoadMarkerGeometryFromString(std::string filePath, int& geometryId);
187 
189  RESULT GetMarkerInfo(std::string& markerInfo);
190 
192  RESULT GetLoadedGeometries(std::map<int, std::vector<std::array<float,3>>>& geometries);
193 
195  std::string ResultToString(RESULT result);
196 
198  RESULT GetFiducialsInFrame(std::vector<Fiducial>& fiducials,
199  std::map<std::string, std::string>& events, uint64_t& sdkTimestamp);
200 
202  RESULT GetMarkersInFrame(std::vector<Marker>& markers,
203  std::map<std::string, std::string>& events, uint64_t& sdkTimestamp);
204 
206  RESULT SetUserLEDState(int red, int green, int blue, int frequency, bool enabled = true);
207 
210 
213 
216 
219 
222 
223  // ------------------------------------------
224  // frame options
225  // ------------------------------------------
229  int GetMaxAdditionalEventsNumber() { return MaxAdditionalEventsNumber; }
230 
233  int GetMax2dFiducialsNumber() { return Max2dFiducialsNumber; }
234 
237  int GetMax3dFiducialsNumber() { return Max3dFiducialsNumber; }
238 
241  int GetMaxMarkersNumber() { return MaxMarkersNumber; }
242 
243  // ------------------------------------------
244  // spryTrack only options
245  // ------------------------------------------
246 
249 
252 
255 
256  // ------------------------------------------
257  // fusionTrack only options
258  // ------------------------------------------
259 
261  RESULT GetDroppedFrameCount(int& droppedFrameCount);
262 
265 
266  RESULT SetOption(const std::string&, const std::string&);
267 
268  protected:
269  bool GetOptionInfo(const std::string&, const ftkOptionsInfo*&);
270 
271  private:
272  DEVICE_TYPE DeviceType = UNKNOWN_DEVICE;
273 
274  int MaxAdditionalEventsNumber = 0; // beyond the default allocation of 20 events
275  int Max2dFiducialsNumber = 256;
276  int Max3dFiducialsNumber = 256;
277  int MaxMarkersNumber = 16;
278 
279  bool isOnboardProcessing = false;
280 
281  class Internal;
282  Internal* InternalObj;
283  };
284 } // namespace Atracsys
285 #endif
bool operator<(const Fiducial &f) const
uint32_t GetGeometryPresenceMask()
const Fiducials & GetFiducials()
RESULT SetUserLEDState(int red, int green, int blue, int frequency, bool enabled=true)
void Pause(bool tof)
bool operator==(const Fiducial &f) const
RESULT EnableOnboardProcessing(bool enabled)
std::vector< Fiducial > Fiducials
RESULT EnableUserLED(bool enabled)
RESULT GetLoadedGeometries(std::map< int, std::vector< std::array< float, 3 >>> &geometries)
int GetMaxAdditionalEventsNumber()
RESULT SetMaxAdditionalEventsNumber(int n)
RESULT SetMaxMarkersNumber(int n)
float GetFiducialRegistrationErrorMm()
RESULT EnableWirelessMarkerStatusStreaming(bool enabled)
RESULT SetSpryTrackProcessingType(SPRYTRACK_IMAGE_PROCESSING_TYPE processingType)
RESULT LoadMarkerGeometryFromString(std::string filePath, int &geometryId)
RESULT EnableWirelessMarkerBatteryStreaming(bool enabled)
vtkMatrix4x4 * GetTransformToTracker()
RESULT SetMax2dFiducialsNumber(int n)
int enabled
Definition: phidget22.h:3369
bool strToFloat32(const std::string &str, float &var)
RESULT GetCamerasCalibration(std::array< float, 10 > &leftIntrinsic, std::array< float, 10 > &rightIntrinsic, std::array< float, 3 > &rightPosition, std::array< float, 3 > &rightOrientation)
RESULT GetMarkerInfo(std::string &markerInfo)
RESULT SetMax3dFiducialsNumber(int n)
RESULT LoadMarkerGeometryFromFile(std::string filePath, int &geometryId)
bool strToInt32(const std::string &str, int &var)
RESULT SetLaserEnabled(bool enabled)
RESULT GetSDKversion(std::string &version)
RESULT EnableImageStreaming(bool enabled)
RESULT GetDeviceType(DEVICE_TYPE &deviceType)
uint32_t GetMarkerStatus()
RESULT EnableWirelessMarkerPairing(bool enabled)
uint32_t GetGeometryID()
PhidgetGPS_Date * date
Definition: phidget22.h:3617
RESULT SetOption(const std::string &, const std::string &)
bool AddFiducial(Fiducial fid)
RESULT GetFiducialsInFrame(std::vector< Fiducial > &fiducials, std::map< std::string, std::string > &events, uint64_t &sdkTimestamp)
RESULT GetMarkersInFrame(std::vector< Marker > &markers, std::map< std::string, std::string > &events, uint64_t &sdkTimestamp)
RESULT GetDroppedFrameCount(int &droppedFrameCount)
double frequency
Definition: phidget22.h:3246
bool GetOptionInfo(const std::string &, const ftkOptionsInfo *&)
RESULT GetCalibrationDate(std::string &date)
RESULT GetDeviceId(uint64_t &id)
uint32_t GetTrackingID()
std::string ResultToString(RESULT result)