PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
NDICertusTest.cxx
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 Name: SAMPLE20.C
9 
10 Description:
11 
12 Optotrak Sample Program #20.
13 
14 - Set processing flags to generate system configuration externally.
15 - Generate the system configuration externally and load the processors code.
16 - Initiate communications with the Optotrak System.
17 - Load the appropriate camera parameters.
18 - Set up an Optotrak collection.
19 - Activate the markers.
20 - Request/receive/display 10 frames of real-time 3D data.
21 - De-activate the markers.
22 - Stop the Optotrak collection.
23 - Disconnect from the Optotrak System.
24 - Set processing flags to generate system configuration internally.
25 - Generate the system configuration internally and load the processors code.
26 - Initiate communications with the Optotrak System.
27 - Load the appropriate camera parameters.
28 - Set up an Optotrak collection.
29 - Activate the markers.
30 - Request/receive/display 10 frames of real-time 3D data.
31 - De-activate the markers.
32 - Stop the Optotrak collection.
33 - Disconnect from the Optotrak System.
34 - Set processing flags to perform data conversions on the host computer.
35 
36 *****************************************************************/
37 
38 /*****************************************************************
39 C Library Files Included
40 *****************************************************************/
41 #include "PlusConfigure.h"
42 #include <stdio.h>
43 #include <stdlib.h>
44 
45 #ifdef _MSC_VER
46 #include <string.h>
47 #elif __BORLANDC__
48 #include <dos.h>
49 extern unsigned _stklen = 16000;
50 #elif __WATCOMC__
51 #include <dos.h>
52 #endif
53 
54 #if defined(_WIN32) && !defined(__WINDOWS_H)
55 #define __WINDOWS_H
56 #include "Windows.h"
57 #endif
58 
59 /*****************************************************************
60 ND Library Files Included
61 *****************************************************************/
62 #include "ndtypes.h"
63 #include "ndpack.h"
64 #include "ndopto.h"
65 
66 /*****************************************************************
67 Application Files Included
68 *****************************************************************/
69 //#include "ot_aux.h"
70 
71 /*****************************************************************
72 Defines:
73 *****************************************************************/
74 #define NUM_MARKERS 6
75 
76 /*****************************************************************
77 Name: main
78 
79 Input Values:
80 int
81 argc :Number of command line parameters.
82 unsigned char
83 *argv[] :Pointer array to each parameter.
84 
85 Output Values:
86 None.
87 
88 Return Value:
89 None.
90 
91 Description:
92 
93 Main program routine performs all steps listed in the above
94 program description.
95 
96 *****************************************************************/
97 int main( int argc, unsigned char *argv[] )
98 {
99  char
100  pszLogFileName[] = "CfgLog.txt",
101  szNDErrorString[MAX_ERROR_STRING_LENGTH + 1];
102  unsigned int
103  uFrameCnt,
104  uFrameNumber,
105  uElements,
106  uFlags;
107  static Position3d
108  p3dData[NUM_MARKERS];
109 
110  std::cout << "Determining system configuration using system.nif." << std::endl;
111 
112  /*
113  * Determine the system configuration in the default manner
114  * without any error logging. This writes the file system.nif
115  * in the standard ndigital directory.
116  */
117 
118  /*
119  * Set optional processing flags (this overides the settings in Optotrak.INI).
120  */
121  std::cout << "...OptotrakSetProcessingFlags" << std::endl;
122 
123  if( OptotrakSetProcessingFlags( OPTO_LIB_POLL_REAL_DATA |
124  OPTO_CONVERT_ON_HOST |
125  OPTO_RIGID_ON_HOST ) )
126  {
127  goto ERROR_EXIT;
128  } /* if */
129 
130  std::cout << "...TransputerDetermineSystemCfg" << std::endl;
131  if( TransputerDetermineSystemCfg( NULL ) )
132  {
133  std::cerr << "Error in determining the system parameters." << std::endl;
134  goto ERROR_EXIT;
135  } /* if */
136 
137  vtkIGSIOAccurateTimer::Delay(1);
138 
139  /*
140  * Load the system of processors.
141  */
142  std::cout << "...TransputerLoadSystem" << std::endl;
143  if( TransputerLoadSystem( "system" ) != OPTO_NO_ERROR_CODE )
144  {
145  goto ERROR_EXIT;
146  } /* if */
147 
148  /*
149  * Wait one second to let the system finish loading.
150  */
151  vtkIGSIOAccurateTimer::Delay(1);
152 
153  /*
154  * Initialize the processors system.
155  */
156  std::cout << "...TransputerInitializeSystem" << std::endl;
157  if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG | OPTO_LOG_MESSAGES_FLAG ) )
158  {
159  goto ERROR_EXIT;
160  } /* if */
161 
162  /*
163  * Load the standard camera parameters.
164  */
165  std::cout << "...OptotrakLoadCameraParameters" << std::endl;
166  if( OptotrakLoadCameraParameters( "standard" ) )
167  {
168  goto ERROR_EXIT;
169  } /* if */
170 
171  /*
172  * Set up a collection for the Optotrak.
173  */
174  std::cout << "...OptotrakSetupCollection" << std::endl;
175  if( OptotrakSetupCollection(
176  NUM_MARKERS, /* Number of markers in the collection. */
177  (float)100.0, /* Frequency to collect data frames at. */
178  (float)2500.0, /* Marker frequency for marker maximum on-time. */
179  30, /* Dynamic or Static Threshold value to use. */
180  160, /* Minimum gain code amplification to use. */
181  0, /* Stream mode for the data buffers. */
182  (float)0.35, /* Marker Duty Cycle to use. */
183  (float)7.0, /* Voltage to use when turning on markers. */
184  (float)1.0, /* Number of seconds of data to collect. */
185  (float)0.0, /* Number of seconds to pre-trigger data by. */
186  OPTOTRAK_NO_FIRE_MARKERS_FLAG | OPTOTRAK_BUFFER_RAW_FLAG | OPTOTRAK_GET_NEXT_FRAME_FLAG ) )
187  {
188  goto ERROR_EXIT;
189  } /* if */
190 
191  /*
192  * Wait one second to let the camera adjust.
193  */
194  vtkIGSIOAccurateTimer::Delay(1);
195 
196  /*
197  * Activate the markers.
198  */
199  std::cout << "...OptotrakActivateMarkers" << std::endl;
200  if( OptotrakActivateMarkers() )
201  {
202  goto ERROR_EXIT;
203  } /* if */
204  vtkIGSIOAccurateTimer::Delay(1);
205 
206  /*
207  * Get and display ten frames of 3D data.
208  */
209  std::cout << std::endl << std::endl << "Sample Program Results:" << std::endl << std::endl;
210  std::cout << std::endl << std::endl << "3D Data Display" << std::endl;
211  for( uFrameCnt = 0; uFrameCnt < 10; ++uFrameCnt )
212  {
213  /*
214  * Get a frame of data.
215  */
216  std::cout << std::endl;
217  if( DataGetLatest3D( &uFrameNumber, &uElements, &uFlags, p3dData ) )
218  {
219  goto ERROR_EXIT;
220  } /* if */
221 
222  /*
223  * Print out the data.
224  */
225  std::cout << "Frame Number: " << uFrameNumber << std::endl;
226  std::cout << "Elements : " << uElements << std::endl;
227  std::cout << "Flags : " << std::hex << uFlags << std::endl;
228  // for( uMarkerCnt = 0; uMarkerCnt < NUM_MARKERS; ++uMarkerCnt )
229  // {
230  //DisplayMarker( uMarkerCnt + 1, p3dData[ uMarkerCnt] );
231  // } /* for */
232  } /* for */
233  std::cout << std::endl;
234 
235  /*
236  * De-activate the markers.
237  */
238  std::cout << "...OptotrakDeActivateMarkers" << std::endl;
239  if( OptotrakDeActivateMarkers() )
240  {
241  goto ERROR_EXIT;
242  } /* if */
243 
244  /*
245  * Stop the collection.
246  */
247  std::cout << "...OptotrakStopCollection" << std::endl;
248  OptotrakStopCollection( );
249 
250  /*
251  * Shutdown the processors message passing system.
252  */
253  std::cout << "...TransputerShutdownSystem" << std::endl;
254  if( TransputerShutdownSystem() )
255  {
256  goto ERROR_EXIT;
257  } /* if */
258 
259  vtkIGSIOAccurateTimer::Delay(1);
260 
261  /*
262  * Set the API to use internal storage for the system
263  * configuration.
264  */
265  std::cout << std::endl << "Determining system configuration using internal strings." << std::endl;
266 
267  /*
268  * Set optional processing flags (this overides the settings in Optotrak.INI).
269  */
270  std::cout << "...OptotrakSetProcessingFlags" << std::endl;
271  if( OptotrakSetProcessingFlags( OPTO_USE_INTERNAL_NIF |
272  OPTO_LIB_POLL_REAL_DATA |
273  OPTO_CONVERT_ON_HOST |
274  OPTO_RIGID_ON_HOST ) )
275  {
276  goto ERROR_EXIT;
277  } /* if */
278 
279 
280  /*
281  * Determine the system configuration again, but this time
282  * with error logging.
283  */
284  std::cout << "...TransputerDetermineSystemCfg" << std::endl;
285  if( TransputerDetermineSystemCfg( pszLogFileName ) )
286  {
287  std::cerr << "Error in determining the system parameters." << std::endl;
288  goto ERROR_EXIT;
289  }
290 
291  vtkIGSIOAccurateTimer::Delay(1);
292 
293  /*
294  * Load the system of processors.
295  */
296  std::cout << "...TransputerLoadSystem" << std::endl;
297  if( TransputerLoadSystem( "system" ) != OPTO_NO_ERROR_CODE )
298  {
299  goto ERROR_EXIT;
300  } /* if */
301 
302  vtkIGSIOAccurateTimer::Delay(1);
303 
304  /*
305  * Initialize the processors system again in the usual manner.
306  */
307  std::cout << "...TransputerInitializeSystem" << std::endl;
308  if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG | OPTO_LOG_MESSAGES_FLAG ) )
309  {
310  goto ERROR_EXIT;
311  } /* if */
312 
313  /*
314  * Load the standard camera parameters.
315  */
316  std::cout << "...OptotrakLoadCameraParameters" << std::endl;
317  if( OptotrakLoadCameraParameters( "standard" ) )
318  {
319  goto ERROR_EXIT;
320  } /* if */
321 
322  /*
323  * Set up a collection for the Optotrak.
324  */
325  std::cout << "...OptotrakSetupCollection" << std::endl;
326  if( OptotrakSetupCollection(
327  NUM_MARKERS, /* Number of markers in the collection. */
328  (float)100.0, /* Frequency to collect data frames at. */
329  (float)2500.0, /* Marker frequency for marker maximum on-time. */
330  30, /* Dynamic or Static Threshold value to use. */
331  160, /* Minimum gain code amplification to use. */
332  0, /* Stream mode for the data buffers. */
333  (float)0.35, /* Marker Duty Cycle to use. */
334  (float)7.0, /* Voltage to use when turning on markers. */
335  (float)1.0, /* Number of seconds of data to collect. */
336  (float)0.0, /* Number of seconds to pre-trigger data by. */
337  OPTOTRAK_NO_FIRE_MARKERS_FLAG | OPTOTRAK_BUFFER_RAW_FLAG | OPTOTRAK_GET_NEXT_FRAME_FLAG ) )
338  {
339  goto ERROR_EXIT;
340  } /* if */
341 
342  /*
343  * Wait one second to let the camera adjust.
344  */
345  vtkIGSIOAccurateTimer::Delay(1);
346 
347  /*
348  * Activate the markers.
349  */
350  std::cout << "...OptotrakActivateMarkers" << std::endl;
351  if( OptotrakActivateMarkers() )
352  {
353  goto ERROR_EXIT;
354  } /* if */
355 
356  vtkIGSIOAccurateTimer::Delay(1);
357 
358  /*
359  * Get and display ten frames of 3D data.
360  */
361  std::cout << std::endl << std::endl << "Sample Program Results:" << std::endl << std::endl;
362  std::cout << std::endl << std::endl << "3D Data Display" << std::endl;
363  for( uFrameCnt = 0; uFrameCnt < 10; ++uFrameCnt )
364  {
365  /*
366  * Get a frame of data.
367  */
368  std::cout << std::endl;
369  if( DataGetLatest3D( &uFrameNumber, &uElements, &uFlags, p3dData ) )
370  {
371  goto ERROR_EXIT;
372  } /* if */
373 
374  /*
375  * Print out the data.
376  */
377  std::cout << "Frame Number: " << uFrameNumber << std::endl;
378  std::cout << "Elements : " << uElements << std::endl;
379  std::cout << "Flags : " << std::hex << uFlags << std::endl;
380  }
381  std::cout << std::endl;
382 
383  /*
384  * De-activate the markers.
385  */
386  std::cout << "...OptotrakDeActivateMarkers" << std::endl;
387  if( OptotrakDeActivateMarkers() )
388  {
389  goto ERROR_EXIT;
390  } /* if */
391 
392  /*
393  * Stop the collection.
394  */
395  std::cout << "...OptotrakStopCollection" << std::endl;
396  OptotrakStopCollection( );
397 
398  /*
399  * Shutdown the processors message passing system.
400  */
401  std::cout << "...TransputerShutdownSystem" << std::endl;
402  if( TransputerShutdownSystem() )
403  {
404  goto ERROR_EXIT;
405  } /* if */
406 
407  /*
408  * Exit the program.
409  */
410  std::cout << std::endl << "Program execution complete." << std::endl;
411  exit( 0 );
412 
413 ERROR_EXIT:
414  /*
415  * Indicate that an error has occurred
416  */
417  std::cout << std::endl << "An error has occurred during execution of the program." << std::endl;
418  if( OptotrakGetErrorString( szNDErrorString,
419  MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
420  {
421  std::cout << szNDErrorString;
422  } /* if */
423 
424  std::cout << std::endl << std::endl << "...TransputerShutdownSystem" << std::endl;
425  TransputerShutdownSystem();
426 
427  return 1 ;
428 
429 }
430 
int main(int argc, unsigned char *argv[])
#define NUM_MARKERS