PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusNDITracker.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 /*=========================================================================
8 The following copyright notice is applicable to parts of this file:
9 
10 Copyright (c) 2000-2005 Atamai, Inc.
11 
12 Use, modification and redistribution of the software, in source or
13 binary forms, are permitted provided that the following terms and
14 conditions are met:
15 
16 1) Redistribution of the source code, in verbatim or modified
17  form, must retain the above copyright notice, this license,
18  the following disclaimer, and any notices that refer to this
19  license and/or the following disclaimer.
20 
21 2) Redistribution in binary form must include the above copyright
22  notice, a copy of this license and the following disclaimer
23  in the documentation or with other materials provided with the
24  distribution.
25 
26 3) Modified copies of the source code must be clearly marked as such,
27  and must not be misrepresented as verbatim copies of the source code.
28 
29 THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS"
30 WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO,
31 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 PURPOSE. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY
33 ODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE
34 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES
35 (INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE
36 OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
37 THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE
38 POSSIBILITY OF SUCH DAMAGES.
39 
40 =========================================================================*/
41 
42 #ifndef __vtkPlusNDITracker_h
43 #define __vtkPlusNDITracker_h
44 
45 #include "vtkPlusDataCollectionExport.h"
46 
47 #include "vtkPlusDevice.h"
48 
49 class vtkSocketCommunicator;
50 struct ndicapi;
51 
52 // the maximum size of an NDI reply (excluding new extended binary format)
53 #define VTK_NDI_REPLY_LEN 2048
54 
102 class vtkPlusDataCollectionExport vtkPlusNDITracker : public vtkPlusDevice
103 {
104  struct NdiToolDescriptor
105  {
106  int WiredPortNumber; // >= 0 for wired tools
107  unsigned char* VirtualSROM; // nonzero for wireless tools
108  bool PortEnabled; // true if the tool is successfully enabled in the tracker
109  int PortHandle; // this number identifies the tool in the tracker
110  };
111 
112  typedef std::map<std::string, NdiToolDescriptor> NdiToolDescriptorsType;
113  typedef std::map<int, std::map<std::string, std::string>> VolumeInformation;
114 
115 public:
116  static vtkPlusNDITracker* New();
118  void PrintSelf(ostream& os, vtkIndent indent);
119 
121  enum LedState
122  {
123  TR_LED_OFF = 0,
124  TR_LED_ON = 1,
125  TR_LED_FLASH = 2
126  };
127 
128  virtual bool IsTracker() const
129  {
130  return true;
131  }
132 
134  virtual std::string GetSdkVersion();
135 
141  PlusStatus Probe();
142 
150  std::string Command(const char* format, ...);
151 
153  vtkSetMacro(SerialPort, int);
154  vtkGetMacro(SerialPort, int);
155 
157  vtkSetMacro(BaudRate, int);
158  vtkGetMacro(BaudRate, int);
159 
167  vtkSetMacro(MeasurementVolumeNumber, int);
168  vtkGetMacro(MeasurementVolumeNumber, int);
169 
177  vtkSetMacro(TrackingFrequencyNumber, int);
178  vtkGetMacro(TrackingFrequencyNumber, int);
179 
185 
187  virtual PlusStatus ReadConfiguration(vtkXMLDataElement* config);
188 
190  virtual PlusStatus WriteConfiguration(vtkXMLDataElement* config);
191 
193  PlusStatus SetToolLED(const char* portName, int led, LedState state);
194 
195  vtkSetStdStringMacro(NetworkHostname);
196  vtkGetStdStringMacro(NetworkHostname);
197 
198  vtkSetMacro(NetworkPort, int);
199  vtkGetMacro(NetworkPort, int);
200 
201  vtkSetMacro(CheckDSR, bool);
202  vtkGetMacro(CheckDSR, bool);
203 
204  vtkSetMacro(HardwareDataAveragingDepth, int);
205  vtkGetMacro(HardwareDataAveragingDepth, int);
206 
207 protected:
210 
213 
214  PlusStatus InternalConnectNetwork();
215  PlusStatus InternalConnectSerial();
216 
219 
227 
233 
235  PlusStatus Beep(int n);
236 
238  PlusStatus ReadSromFromFile(NdiToolDescriptor& toolDescriptor, const char* filename);
239 
245  PlusStatus UpdatePortHandle(NdiToolDescriptor& toolDescriptor);
246 
253  PlusStatus SendSromToTracker(const NdiToolDescriptor& toolDescriptor);
259  PlusStatus ClearVirtualSromInTracker(NdiToolDescriptor& toolDescriptor);
260 
265  PlusStatus EnableToolPorts();
270  void DisableToolPorts();
271 
273  void LogVolumeList(int selectedVolume, vtkPlusLogger::LogLevelType logLevel);
274  void LogVolumeListSFLIST(unsigned int numVolumes, int selectedVolume, vtkPlusLogger::LogLevelType logLevel);
275 
279  PlusStatus CloseDevice(ndicapi*& device);
280 
284  PlusStatus SelectMeasurementVolume();
285 
290  PlusStatus SelectMeasurementVolumeDeprecated();
291 
295  PlusStatus SelectTrackingFrequency();
296 
300  PlusStatus GetFirmwareRevision();
301 
306  PlusStatus SelectTrackingFrequencyDeprecated();
307 
311  PlusStatus SelectDataAveraging();
312 
314  static int ConvertBaudToNDIEnum(int baudRate);
315 
317  PlusStatus DoBXUpdate();
318 
320  PlusStatus DoBX2Update();
321 
322 #if defined(HAVE_FUTURE)
323  PlusStatus ProbeSerialInternal();
324 #endif
325 
326  vtkGetMacro(FirmwareMajorRevision, uint32_t);
327  vtkGetMacro(FirmwareMinorRevision, uint32_t);
328 
329 protected:
330  unsigned long LastFrameNumber; // Index of the last frame number, used for providing a frame number when the tracker doesn't return any transform
331  ndicapi* Device;
332  std::string SerialDevice;
334  int BaudRate;
338  bool CheckDSR;
339  NdiToolDescriptorsType NdiToolDescriptors; // Maps Plus tool source IDs to NDI tool descriptors
340  vtkIGSIORecursiveCriticalSection* CommandMutex;
341  char CommandReply[VTK_NDI_REPLY_LEN];
345 
346  std::string NetworkHostname;
349 
350 private:
352  void operator=(const vtkPlusNDITracker&);
353 };
354 
355 #endif
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual PlusStatus InternalStopRecording()
Abstract interface for tracker and video devices.
Definition: vtkPlusDevice.h:60
NdiToolDescriptorsType NdiToolDescriptors
virtual PlusStatus InternalConnect()
igsioStatus PlusStatus
Definition: PlusCommon.h:40
std::string SerialDevice
virtual bool IsTracker() const
uint32_t FirmwareMajorRevision
virtual std::string GetSdkVersion()
virtual PlusStatus Probe()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *)
virtual PlusStatus InternalStartRecording()
int * state
Definition: phidget22.h:3207
std::string NetworkHostname
vtkIGSIORecursiveCriticalSection * CommandMutex
uint32_t FirmwareMinorRevision
virtual PlusStatus InternalDisconnect()
unsigned long LastFrameNumber
virtual PlusStatus InternalUpdate()
#define VTK_NDI_REPLY_LEN
Interface class for Northern Digital's tracking devices.
static vtkPlusDevice * New()