NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkNDICAPITracker.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 /*=Plus=header=begin======================================================
16 The Plus license below is a BSD style license, with extensions
17 to cover contributions and other issues specific to Plus.
18 
19 For more information, please see:
20 http://www.plustoolkit.org
21 ______________________________________________________________
22 
23 How to cite Plus:
24 
25 Andras Lasso, Tamas Heffter, Adam Rankin, Csaba Pinter, Tamas Ungi, and Gabor Fichtinger, "PLUS: Open-source toolkit for ultrasound-guided intervention systems", IEEE Trans Biomed Eng. 2014 Oct;61(10):2527-37. doi: 10.1109/TBME.2014.2322864
26 
27 @ARTICLE{Lasso2014a,
28  title = {PLUS: Open-source toolkit for ultrasound-guided intervention systems},
29  author = {Andras Lasso and Tamas Heffter and Adam Rankin and Csaba Pinter and Tamas Ungi and Gabor Fichtinger},
30  journal = {IEEE Transactions on Biomedical Engineering},
31  year = {2014},
32  month = {Oct},
33  number = {10},
34  pages = {2527-2537},
35  doi = {10.1109/TBME.2014.2322864},
36  pmid = {24833412},
37  url = {http://perk.cs.queensu.ca/contents/plus-open-source-toolkit-ultrasound-guided-intervention-systems}
38 }
39 ______________________________________________________________
40 
41 Plus Contribution and Software License Agreement ("Agreement")
42 Version 1.0 (October 24, 2011)
43 
44 This Agreement covers contributions to and downloads from the Plus
45 project ("Plus") maintained by the Laboratory for Percutaneous
46 Surgery ("PerkLab"). Part A of this Agreement applies to
47 contributions of software and/or data to Plus (including making
48 revisions of or additions to code and/or data already in Plus). Part
49 B of this Agreement applies to downloads of software and/or data from
50 Plus. If you distribute Software (as defined below) downloaded from
51 Plus, all of the paragraphs of Part B of this Agreement must be
52 included with and apply to such Software.
53 
54 Your contribution of software and/or data to Plus (including prior
55 to the date of the first publication of this Agreement, each a
56 "Contribution") and/or downloading, copying, modifying, displaying,
57 distributing or use of any software and/or data from Plus
58 (collectively, the "Software") constitutes acceptance of all of the
59 terms and conditions of this Agreement. If you do not agree to such
60 terms and conditions, you have no right to contribute your
61 Contribution, or to download, copy, modify, display, distribute or use
62 the Software.
63 
64 PART A. CONTRIBUTION AGREEMENT - License to PerkLab with Right to
65 Sublicense ("Contribution Agreement").
66 
67 1. As used in this Contribution Agreement, "you" means the individual
68  contributing the Contribution to Plus and the institution or
69  entity which employs or is otherwise affiliated with such
70  individual in connection with such Contribution.
71 
72 2. This Contribution Agreement applies to all Contributions made to
73  Plus, including without limitation Contributions made prior to
74  the date of first publication of this Agreement. If at any time you
75  make a Contribution to Plus, you represent that (i) you are
76  legally authorized and entitled to make such Contribution and to
77  grant all licenses granted in this Contribution Agreement with
78  respect to such Contribution; (ii) if your Contribution includes
79  any patient data, all such data is de-identified in accordance with
80  U.S. confidentiality and security laws and requirements, including
81  but not limited to the Health Insurance Portability and
82  Accountability Act (HIPAA) and its regulations, and your disclosure
83  of such data for the purposes contemplated by this Agreement is
84  properly authorized and in compliance with all applicable laws and
85  regulations; and (iii) you have preserved in the Contribution all
86  applicable attributions, copyright notices and licenses for any
87  third party software or data included in the Contribution.
88 
89 3. Except for the licenses granted in this Agreement, you reserve all
90  right, title and interest in your Contribution.
91 
92 4. You hereby grant to PerkLab, with the right to sublicense, a
93  perpetual, worldwide, non-exclusive, no charge, royalty-free,
94  irrevocable license to use, reproduce, make derivative works of,
95  display and distribute the Contribution. If your Contribution is
96  protected by patent, you hereby grant to PerkLab, with the right to
97  sublicense, a perpetual, worldwide, non-exclusive, no-charge,
98  royalty-free, irrevocable license under your interest in patent
99  rights covering the Contribution, to make, have made, use, sell and
100  otherwise transfer your Contribution, alone or in combination with
101  any other code.
102 
103 5. You acknowledge and agree that PerkLab may incorporate your
104  Contribution into Plus and may make Plus available to members
105  of the public on an open source basis under terms substantially in
106  accordance with the Software License set forth in Part B of this
107  Agreement. You further acknowledge and agree that PerkLab shall
108  have no liability arising in connection with claims resulting from
109  your breach of any of the terms of this Agreement.
110 
111 6. YOU WARRANT THAT TO THE BEST OF YOUR KNOWLEDGE YOUR CONTRIBUTION
112  DOES NOT CONTAIN ANY CODE THAT REQURES OR PRESCRIBES AN "OPEN
113  SOURCE LICENSE" FOR DERIVATIVE WORKS (by way of non-limiting
114  example, the GNU General Public License or other so-called
115  "reciprocal" license that requires any derived work to be licensed
116  under the GNU General Public License or other "open source
117  license").
118 
119 PART B. DOWNLOADING AGREEMENT - License from PerkLab with Right to
120 Sublicense ("Software License").
121 
122 1. As used in this Software License, "you" means the individual
123  downloading and/or using, reproducing, modifying, displaying and/or
124  distributing the Software and the institution or entity which
125  employs or is otherwise affiliated with such individual in
126  connection therewith. The Laboratory for Percutanous Surgery
127  ("PerkLab") hereby grants you, with right to sublicense, with
128  respect to PerkLab's rights in the software, and data, if any,
129  which is the subject of this Software License (collectively, the
130  "Software"), a royalty-free, non-exclusive license to use,
131  reproduce, make derivative works of, display and distribute the
132  Software, provided that:
133 
134 (a) you accept and adhere to all of the terms and conditions of this
135 Software License;
136 
137 (b) in connection with any copy of or sublicense of all or any portion
138 of the Software, all of the terms and conditions in this Software
139 License shall appear in and shall apply to such copy and such
140 sublicense, including without limitation all source and executable
141 forms and on any user documentation, prefaced with the following
142 words: "All or portions of this licensed product (such portions are
143 the "Software") have been obtained under license from the Laboratory
144 for Percutaneous Surgery and are subject to the following terms and
145 conditions:"
146 
147 (c) you preserve and maintain all applicable attributions, copyright
148 notices and licenses included in or applicable to the Software;
149 
150 (d) modified versions of the Software must be clearly identified and
151 marked as such, and must not be misrepresented as being the original
152 Software; and
153 
154 (e) you consider making, but are under no obligation to make, the
155 source code of any of your modifications to the Software freely
156 available to others on an open source basis.
157 
158 2. The license granted in this Software License includes without
159  limitation the right to (i) incorporate the Software into
160  proprietary programs (subject to any restrictions applicable to
161  such programs), (ii) add your own copyright statement to your
162  modifications of the Software, and (iii) provide additional or
163  different license terms and conditions in your sublicenses of
164  modifications of the Software; provided that in each case your use,
165  reproduction or distribution of such modifications otherwise
166  complies with the conditions stated in this Software License.
167 
168 3. This Software License does not grant any rights with respect to
169  third party software, except those rights that PerkLab has been
170  authorized by a third party to grant to you, and accordingly you
171  are solely responsible for (i) obtaining any permissions from third
172  parties that you need to use, reproduce, make derivative works of,
173  display and distribute the Software, and (ii) informing your
174  sublicensees, including without limitation your end-users, of their
175  obligations to secure any such required permissions.
176 
177 4. The Software has been designed for research purposes only and has
178  not been reviewed or approved by the Food and Drug Administration
179  or by any other agency. YOU ACKNOWLEDGE AND AGREE THAT CLINICAL
180  APPLICATIONS ARE NEITHER RECOMMENDED NOR ADVISED. Any
181  commercialization of the Software is at the sole risk of the party
182  or parties engaged in such commercialization. You further agree to
183  use, reproduce, make derivative works of, display and distribute
184  the Software in compliance with all applicable governmental laws,
185  regulations and orders, including without limitation those relating
186  to export and import control.
187 
188 5. The Software is provided "AS IS" and neither PerkLab nor any
189  contributor to the software (each a "Contributor") shall have any
190  obligation to provide maintenance, support, updates, enhancements
191  or modifications thereto. PERKLAB AND ALL CONTRIBUTORS SPECIFICALLY
192  DISCLAIM ALL EXPRESS AND IMPLIED WARRANTIES OF ANY KIND INCLUDING,
193  BUT NOT LIMITED TO, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR
194  A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
195  PERKLAB OR ANY CONTRIBUTOR BE LIABLE TO ANY PARTY FOR DIRECT,
196  INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
197  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY ARISING IN ANY WAY
198  RELATED TO THE SOFTWARE, EVEN IF PERKLAB OR ANY CONTRIBUTOR HAS
199  BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. TO THE MAXIMUM
200  EXTENT NOT PROHIBITED BY LAW OR REGULATION, YOU FURTHER ASSUME ALL
201  LIABILITY FOR YOUR USE, REPRODUCTION, MAKING OF DERIVATIVE WORKS,
202  DISPLAY, LICENSE OR DISTRIBUTION OF THE SOFTWARE AND AGREE TO
203  INDEMNIFY AND HOLD HARMLESS PERKLAB AND ALL CONTRIBUTORS FROM AND
204  AGAINST ANY AND ALL CLAIMS, SUITS, ACTIONS, DEMANDS AND JUDGMENTS
205  ARISING THEREFROM.
206 
207 6. None of the names, logos or trademarks of PerkLab or any of
208  PerkLab's affiliates or any of the Contributors, or any funding
209  agency, may be used to endorse or promote products produced in
210  whole or in part by operation of the Software or derived from or
211  based on the Software without specific prior written permission
212  from the applicable party.
213 
214 7. Any use, reproduction or distribution of the Software which is not
215  in accordance with this Software License shall automatically revoke
216  all rights granted to you under this Software License and render
217  Paragraphs 1 and 2 of this Software License null and void.
218 
219 8. This Software License does not grant any rights in or to any
220  intellectual property owned by PerkLab or any Contributor except
221  those rights expressly granted hereunder.
222 =========================================================Plus=header=end*/
223 
224 /*=========================================================================
225 The following copyright notice is applicable to parts of this file:
226 
227 Copyright (c) 2000-2005 Atamai, Inc.
228 
229 Use, modification and redistribution of the software, in source or
230 binary forms, are permitted provided that the following terms and
231 conditions are met:
232 
233 1) Redistribution of the source code, in verbatim or modified
234  form, must retain the above copyright notice, this license,
235  the following disclaimer, and any notices that refer to this
236  license and/or the following disclaimer.
237 
238 2) Redistribution in binary form must include the above copyright
239  notice, a copy of this license and the following disclaimer
240  in the documentation or with other materials provided with the
241  distribution.
242 
243 3) Modified copies of the source code must be clearly marked as such,
244  and must not be misrepresented as verbatim copies of the source code.
245 
246 THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS"
247 WITHOUT EXPRESSED OR IMPLIED WARRANTY INCLUDING, BUT NOT LIMITED TO,
248 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
249 PURPOSE. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR OTHER PARTY WHO MAY
250 ODIFY AND/OR REDISTRIBUTE THE SOFTWARE UNDER THE TERMS OF THIS LICENSE
251 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES
252 (INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BECOMING INACCURATE
253 OR LOSS OF PROFIT OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF
254 THE USE OR INABILITY TO USE THE SOFTWARE, EVEN IF ADVISED OF THE
255 POSSIBILITY OF SUCH DAMAGES.
256 
257 =========================================================================*/
258 
259 #ifndef niftkNDICAPITracker_h
260 #define niftkNDICAPITracker_h
261 
262 #include "niftkNDICAPIExports.h"
263 #include <cstring>
264 #include <string>
265 #include <map>
266 #include <vector>
267 
268 struct ndicapi;
269 
270 namespace niftk {
271 
272 // the number of tools the polaris can handle
273 #define VTK_NDI_REPLY_LEN 2048
274 
320 class NIFTKNDICAPI_EXPORT NDICAPITracker
321 {
322 public:
323 
324  NDICAPITracker();
325  ~NDICAPITracker();
326 
328  {
329  PLUS_FAIL=0,
330  PLUS_SUCCESS=1
331  };
332 
334  enum LedState
335  {
336  TR_LED_OFF = 0,
337  TR_LED_ON = 1,
338  TR_LED_FLASH = 2
339  };
340 
341  virtual bool IsTracker() const { return true; }
342 
344  virtual std::string GetSdkVersion();
345 
351  PlusStatus Probe();
352 
360  char *Command(const char *command);
361 
366  char* GetVersion() const { return this->Version; }
367 
369  void SetSerialPort(int i) { this->SerialPort = i; }
370  int GetSerialPort() const { return this->SerialPort; }
371 
373  void SetBaudRate(int i) { this->BaudRate = i; }
374  int GetBaudRate() const { return this->BaudRate; }
375 
383  void SetMeasurementVolumeNumber(int i) { this->MeasurementVolumeNumber = i; }
384  int GetMeasurementVolumeNumber() const { return this->MeasurementVolumeNumber; }
385 
390  PlusStatus InternalUpdate();
391  std::map<std::string, std::vector<double> > GetTrackerMatrices();
392 
394  // NifTK commented out: virtual PlusStatus ReadConfiguration(vtkXMLDataElement* config);
395  // (because PLUS reads config from an .xml file).
396 
398  // NifTK commented out: virtual PlusStatus WriteConfiguration(vtkXMLDataElement* config);
399  // (because PLUS reads config from an .xml file).
400 
402  PlusStatus SetToolLED(const char* portName, int led, LedState state);
403 
404 // NifTK commented out: protected:
405 public:
406 
408  {
409  int WiredPortNumber; // >=0 for wired tools
410  unsigned char *VirtualSROM; // nonzero for wireless tools
411  bool PortEnabled; // true if the tool is successfully enabled in the tracker
412  int PortHandle; // this number identifies the tool in the tracker
413  };
414 
416  void SetVersion (const char* v)
417  {
418  if (this->Version && v && (!strcmp(this->Version,v))) { return; }
419  if (this->Version) { delete [] this->Version; }
420  if (v)
421  {
422  this->Version = new char[strlen(v)+1];
423  strcpy(this->Version, v);
424  }
425  else
426  {
427  this->Version = nullptr;
428  }
429  }
430 
432  PlusStatus InternalConnect();
433 
435  PlusStatus InternalDisconnect();
436 
443  PlusStatus InternalStartRecording();
444 
449  PlusStatus InternalStopRecording();
450 
452  PlusStatus Beep(int n);
453 
455  PlusStatus ReadSromFromFile(NdiToolDescriptor& toolDescriptor, const char *filename);
456 
462  PlusStatus UpdatePortHandle(NdiToolDescriptor& toolDescriptor);
463 
470  PlusStatus SendSromToTracker(const NdiToolDescriptor& toolDescriptor);
471 
477  PlusStatus ClearVirtualSromInTracker(NdiToolDescriptor& toolDescriptor);
478 
483  PlusStatus EnableToolPorts();
484 
489  void DisableToolPorts();
490 
492  // NifTK commented out: void LogVolumeList(const char* ndiVolumeListCommandReply, int selectedVolume, vtkPlusLogger::LogLevelType logLevel);
493  // (just so I can use std::cerr/std::cout logging, which is basic... )
494  void LogVolumeList(const char* ndiVolumeListCommandReply, int selectedVolume);
495 
497  unsigned long LastFrameNumber;
498 
500  char *Version;
502 
504  int BaudRate;
506 
508 
509  typedef std::map<std::string, NdiToolDescriptor> NdiToolDescriptorsType;
510 
512  NdiToolDescriptorsType NdiToolDescriptors;
513 
514  char CommandReply[VTK_NDI_REPLY_LEN];
515 
516 private:
517 
518  NDICAPITracker(const NDICAPITracker&); /* Purposefully not implemented. */
519  void operator=(const NDICAPITracker&); /* Purposefully not implemented. */
520 
521  std::map<std::string, std::vector<double> > m_TrackerMatrices;
522 };
523 
524 } // end namespace
525 
526 #endif
LedState
Definition: niftkNDICAPITracker.h:334
int BaudRate
Definition: niftkNDICAPITracker.h:504
int WiredPortNumber
Definition: niftkNDICAPITracker.h:409
unsigned char * VirtualSROM
Definition: niftkNDICAPITracker.h:410
int GetBaudRate() const
Definition: niftkNDICAPITracker.h:374
ndicapi * Device
Definition: niftkNDICAPITracker.h:499
void SetSerialPort(int i)
Definition: niftkNDICAPITracker.h:369
unsigned long LastFrameNumber
Definition: niftkNDICAPITracker.h:497
int GetSerialPort() const
Definition: niftkNDICAPITracker.h:370
char * Version
Definition: niftkNDICAPITracker.h:500
int GetMeasurementVolumeNumber() const
Definition: niftkNDICAPITracker.h:384
int PortHandle
Definition: niftkNDICAPITracker.h:412
const GLdouble * v
Definition: glew.h:1375
struct ndicapi ndicapi
Definition: ndicapi.h:65
std::map< std::string, NdiToolDescriptor > NdiToolDescriptorsType
Definition: niftkNDICAPITracker.h:509
NdiToolDescriptorsType NdiToolDescriptors
Definition: niftkNDICAPITracker.h:512
void SetBaudRate(int i)
Definition: niftkNDICAPITracker.h:373
char * GetVersion() const
Definition: niftkNDICAPITracker.h:366
PlusStatus
Definition: niftkNDICAPITracker.h:327
int SerialPort
Definition: niftkNDICAPITracker.h:503
bool PortEnabled
Definition: niftkNDICAPITracker.h:411
GLclampd n
Definition: glew.h:6789
int MeasurementVolumeNumber
Definition: niftkNDICAPITracker.h:507
Interface class for Northern Digital's tracking devices.
Definition: niftkNDICAPITracker.h:320
virtual bool IsTracker() const
Definition: niftkNDICAPITracker.h:341
#define VTK_NDI_REPLY_LEN
Definition: niftkNDICAPITracker.h:273
int IsDeviceTracking
Definition: niftkNDICAPITracker.h:505
char * SerialDevice
Definition: niftkNDICAPITracker.h:501
Definition: niftkNDICAPITracker.h:407
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194
void SetMeasurementVolumeNumber(int i)
Definition: niftkNDICAPITracker.h:383
void SetVersion(const char *v)
Definition: niftkNDICAPITracker.h:416