PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusFakeTracker.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 #include "PlusConfigure.h"
8 
9 #include "vtkPlusFakeTracker.h"
10 #include "vtkMatrix4x4.h"
11 #include "vtkMinimalStandardRandomSequence.h"
12 #include "vtkObjectFactory.h"
13 #include "vtkPlusDataSource.h"
14 #include "vtkTransform.h"
15 
17 
18 //----------------------------------------------------------------------------
20  : Frame(0)
21  , InternalTransform(vtkTransform::New())
23  , TransformRepository(NULL)
24  , RandomSeed(0)
25  , Counter(-1)
26  , PhantomLandmarks(NULL)
27 {
28  vtkSmartPointer<vtkPoints> phantomLandmarks = vtkSmartPointer<vtkPoints>::New();
29  this->SetPhantomLandmarks(phantomLandmarks);
30 
32 
33  // No callback function provided by the device, so the data capture thread will be used to poll the hardware and add new items to the buffer
34  this->StartThreadForInternalUpdates = true;
35  this->AcquisitionRate = 30;
36 }
37 
38 //----------------------------------------------------------------------------
40 {
41  this->InternalTransform->Delete();
42 
43  // Remove reference from the transform repository
44  this->SetTransformRepository(NULL);
45 
46  this->SetPhantomLandmarks(NULL);
47 }
48 
49 //----------------------------------------------------------------------------
51 {
52  LOG_TRACE("vtkPlusFakeTracker::SetMode(" << mode << ")");
53 
54  this->Mode = mode;
55 }
56 
57 //----------------------------------------------------------------------------
59 {
60  LOG_TRACE("vtkPlusFakeTracker::InternalConnect");
61 
62  vtkPlusDataSource* tool = NULL;
63  switch (this->Mode)
64  {
66 
67  {
68  //*************************************************************
69  // Check Reference
70  igsioTransformName sourceId("Reference", this->GetToolReferenceFrameName());
71  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
72  {
73  LOG_ERROR("Failed to get tool: Reference in FakeTracker Default mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
74  return PLUS_FAIL;
75  }
76  tool->SetCustomProperty("PartNumber", "Stationary");
77  }
78  {
79  //*************************************************************
80  // Check Stylus
81  igsioTransformName sourceId("Stylus", this->GetToolReferenceFrameName());
82  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
83  {
84  LOG_ERROR("Failed to get tool: Stylus in FakeTracker Default mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
85  return PLUS_FAIL;
86  }
87  tool->SetCustomProperty("PartNumber", "Rotate");
88  }
89  {
90  //*************************************************************
91  // Check Stlyus-2
92  igsioTransformName sourceId("Stylus-2", this->GetToolReferenceFrameName());
93  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
94  {
95  LOG_ERROR("Failed to get tool: Stylus-2 in FakeTracker Default mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
96  return PLUS_FAIL;
97  }
98  tool->SetCustomProperty("PartNumber", "Rotate");
99  }
100  {
101  //*************************************************************
102  // Check Stlyus-3
103  igsioTransformName sourceId("Stylus-3", this->GetToolReferenceFrameName());
104  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
105  {
106  LOG_ERROR("Failed to get tool: Stylus-3 in FakeTracker Default mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
107  return PLUS_FAIL;
108  }
109  tool->SetCustomProperty("PartNumber", "Spin");
110  }
111  break;
112 
114  {
115  //*************************************************************
116  // Check Probe
117  igsioTransformName sourceId("Probe", this->GetToolReferenceFrameName());
118  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
119  {
120  LOG_ERROR("Failed to get tool: Probe in FakeTracker SmoothMove mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
121  return PLUS_FAIL;
122  }
123  }
124  {
125  //*************************************************************
126  // Check Reference
127  igsioTransformName sourceId("Reference", this->GetToolReferenceFrameName());
128  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
129  {
130  LOG_ERROR("Failed to get tool: Reference in FakeTracker SmoothMove mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
131  return PLUS_FAIL;
132  }
133  }
134  {
135  //*************************************************************
136  // Check MissingTool
137  igsioTransformName sourceId("MissingTool", this->GetToolReferenceFrameName());
138  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
139  {
140  LOG_ERROR("Failed to get tool: MissingTool in FakeTracker SmoothMove mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
141  return PLUS_FAIL;
142  }
143  break;
144  }
146  {
147  //*************************************************************
148  // Check Reference
149  igsioTransformName sourceId("Reference", this->GetToolReferenceFrameName());
150  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
151  {
152  LOG_ERROR("Failed to get tool: Reference in FakeTracker PivotCalibration mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
153  return PLUS_FAIL;
154  }
155 
156  tool->SetCustomProperty("PartNumber", "Stationary");
157  }
158  {
159  //*************************************************************
160  // Check Stylus
161  igsioTransformName sourceId("Stylus", this->GetToolReferenceFrameName());
162  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
163  {
164  LOG_ERROR("Failed to get tool: Stylus in FakeTracker PivotCalibration mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
165  return PLUS_FAIL;
166  }
167 
168  tool->SetCustomProperty("PartNumber", "Stylus");
169  }
170  break;
171 
173  {
174  //*************************************************************
175  // Check Reference
176  igsioTransformName sourceId("Reference", this->GetToolReferenceFrameName());
177  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
178  {
179  LOG_ERROR("Failed to get tool: Reference in FakeTracker RecordPhantomLandmarks mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
180  return PLUS_FAIL;
181  }
182 
183  tool->SetCustomProperty("PartNumber", "Stationary");
184  }
185  {
186  //*************************************************************
187  // Check Stylus
188  igsioTransformName sourceId("Stylus", this->GetToolReferenceFrameName());
189  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
190  {
191  LOG_ERROR("Failed to get tool: Stylus in FakeTracker RecordPhantomLandmarks mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
192  return PLUS_FAIL;
193  }
194 
195  tool->SetCustomProperty("PartNumber", "Stylus");
196  }
197 
198  this->Counter = -1;
199 
200  break;
202  {
203  //*************************************************************
204  // Check Test
205  igsioTransformName sourceId("Test", this->GetToolReferenceFrameName());
206  if (this->GetTool(sourceId.GetTransformName(), tool) != PLUS_SUCCESS)
207  {
208  LOG_ERROR("Failed to get tool: Test in FakeTracker ToolState mode, please add to config file: " << vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
209  return PLUS_FAIL;
210  }
211 
212  tool->SetCustomProperty("PartNumber", "Stationary");
213  }
214 
215  this->Counter = 0;
216 
217  break;
218  default:
219  break;
220  }
221 
222 
223  return PLUS_SUCCESS;
224 }
225 
226 //----------------------------------------------------------------------------
228 {
229  LOG_TRACE("vtkPlusFakeTracker::InternalDisconnect");
230 
231  return this->StopRecording();
232 }
233 
234 //----------------------------------------------------------------------------
236 {
237  LOG_TRACE("vtkPlusFakeTracker::Probe");
238 
239  return PLUS_SUCCESS;
240 }
241 
242 //----------------------------------------------------------------------------
244 {
245  LOG_TRACE("vtkPlusFakeTracker::InternalStartRecording");
246 
247  this->RandomSeed = 0;
248 
249  return PLUS_SUCCESS;
250 }
251 
252 //----------------------------------------------------------------------------
254 {
255  LOG_TRACE("vtkPlusFakeTracker::InternalStopRecording");
256 
257  return PLUS_SUCCESS;
258 }
259 
260 //----------------------------------------------------------------------------
262 {
263  //LOG_TRACE("vtkPlusFakeTracker::InternalUpdate");
264 
265  if (!this->IsRecording())
266  {
267  LOG_TRACE("vtkPlusFakeTracker::InternalUpdate is called while not tracking any more");
268  return PLUS_SUCCESS;
269  }
270 
271  if (this->Frame++ > 355559)
272  {
273  this->Frame = 0;
274  }
275 
276  switch (this->Mode)
277  {
278  case (FakeTrackerMode_Default): // Spins the tools around different axis to fake movement
279  {
280  const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
281  for (DataSourceContainerConstIterator it = this->GetToolIteratorBegin(); it != this->GetToolIteratorEnd(); ++it)
282  {
283  ToolStatus toolStatus = TOOL_OK;
284 
285  int rotation = this->Frame / 1000;
286 
287  if (it->second->GetPortName() == "0")
288  {
289  // This tool is stationary
290  this->InternalTransform->Identity();
291  this->InternalTransform->Translate(0, 150, 200);
292  }
293  else if (it->second->GetPortName() == "1")
294  {
295  // This tool rotates about a path on the Y axis
296  this->InternalTransform->Identity();
297  this->InternalTransform->RotateY(rotation);
298  this->InternalTransform->Translate(0, 300, 0);
299  }
300  else if (it->second->GetPortName() == "2")
301  {
302  // This tool rotates about a path on the X axis
303  this->InternalTransform->Identity();
304  this->InternalTransform->RotateX(rotation);
305  this->InternalTransform->Translate(0, 300, 200);
306  }
307  else if (it->second->GetPortName() == "3")
308  {
309  // This tool spins on the X axis
310  this->InternalTransform->Identity();
311  this->InternalTransform->Translate(100, 300, 0);
312  this->InternalTransform->RotateX(rotation);
313  }
314 
315  this->ToolTimeStampedUpdate(it->second->GetId(), this->InternalTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
316  }
317  }
318  break;
319 
321  {
322  ToolStatus toolStatus = TOOL_OK;
323  if (this->Frame % 10 == 0)
324  {
325  toolStatus = TOOL_MISSING;
326  }
327 
328  const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
329  double tx = (this->Frame % 100); // 0 - 99
330  double ty = (this->Frame % 100) + 100; // 100 - 199
331  double tz = (this->Frame % 100) + 200; // 200 - 299
332 
333  double ry = (this->Frame % 100) / 2.0; // 0 - 50
334 
335  this->InternalTransform->Identity();
336  this->InternalTransform->Translate(tx, ty, tz);
337  this->InternalTransform->RotateY(ry);
338  // Probe transform
339  {
340  igsioTransformName name("Probe", this->GetToolReferenceFrameName());
341  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), this->InternalTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
342  }
343 
344  this->InternalTransform->Identity();
345  this->InternalTransform->Translate(0, 0, 50);
346  // Reference transform
347  {
348  igsioTransformName name("Reference", this->GetToolReferenceFrameName());
349  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), this->InternalTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
350  }
351  {
352  igsioTransformName name("MissingTool", this->GetToolReferenceFrameName());
353  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), this->InternalTransform->GetMatrix(), TOOL_MISSING, this->Frame, unfilteredTimestamp);
354  }
355 
356  }
357  break;
358 
360  {
361  ToolStatus toolStatus = TOOL_OK;
362  if (this->Frame % 50 == 0)
363  {
364  toolStatus = TOOL_MISSING;
365  }
366 
367  const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
368  double tx = sin(this->Frame / 100.0) * 20; // -20 - +20
369  double ty = cos(this->Frame / 50.0) * 10 + 50; // 40 - 60
370  double tz = abs(this->Frame % 100 - 50.0) + 100; // 100 - 150
371 
372  this->InternalTransform->Identity();
373  this->InternalTransform->Translate(tx, ty, tz);
374  // Probe transform
375  {
376  igsioTransformName name("Probe", this->GetToolReferenceFrameName());
377  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), this->InternalTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
378  }
379 
380  this->InternalTransform->Identity();
381  this->InternalTransform->Translate(5, -10, 1.5);
382  // Reference transform
383  {
384  igsioTransformName name("Reference", this->GetToolReferenceFrameName());
385  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), this->InternalTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
386  }
387  {
388  igsioTransformName name("MissingTool", this->GetToolReferenceFrameName());
389  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), this->InternalTransform->GetMatrix(), TOOL_MISSING, this->Frame, unfilteredTimestamp);
390  }
391 
392  }
393  break;
394 
395  case (FakeTrackerMode_PivotCalibration): // Moves around a stylus with the tip fixed to a position
396  {
397  vtkMinimalStandardRandomSequence* random = vtkMinimalStandardRandomSequence::New();
398  random->SetSeed(RandomSeed++); // To get completely random numbers, timestamp should use instead of constant seed
399 
400  // Set flags
401  ToolStatus toolStatus = TOOL_OK;
402 
403  // Once in every 50 request, the tracker provides 'out of view' flag - FOR TEST PURPOSES
404  /*
405  random->Next();
406  double outOfView = random->GetValue();
407  if (outOfView < 0.02) {
408  toolStatus = TOOL_OUT_OF_VIEW;
409  }
410  */
411 
412  const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
413 
414  // create stationary position for reference (tool 0)
415  vtkSmartPointer<vtkTransform> referenceToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
416  referenceToTrackerTransform->Identity();
417  referenceToTrackerTransform->Translate(300, 400, 700);
418  referenceToTrackerTransform->RotateZ(90);
419 
420  {
421  igsioTransformName name("Reference", this->GetToolReferenceFrameName());
422  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), referenceToTrackerTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
423  }
424  // create random positions along a sphere (with built-in error)
425  double exactRadius = 210.0;
426  double deltaTheta = 60.0;
427  double deltaPhi = 60.0;
428  double variance = 1.0;
429 
430  random->Next();
431  double theta = random->GetRangeValue(-deltaTheta, deltaTheta);
432 
433  random->Next();
434  double phi = random->GetRangeValue(-deltaPhi, deltaPhi);
435 
436  random->Next();
437  double radius = random->GetRangeValue(exactRadius - variance, exactRadius + variance);
438 
439  vtkSmartPointer<vtkTransform> stylusToReferenceTransform = vtkSmartPointer<vtkTransform>::New();
440  stylusToReferenceTransform->Identity();
441  stylusToReferenceTransform->Translate(205.0, 305.0, 55.0); // Some distance from the reference
442  stylusToReferenceTransform->RotateY(phi);
443  stylusToReferenceTransform->RotateZ(theta);
444  stylusToReferenceTransform->Translate(-radius, 0.0, 0.0);
445 
446  vtkSmartPointer<vtkTransform> stylusToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
447  stylusToTrackerTransform->Identity();
448  stylusToTrackerTransform->Concatenate(referenceToTrackerTransform);
449  stylusToTrackerTransform->Concatenate(stylusToReferenceTransform);
450 
451  random->Delete();
452  {
453  igsioTransformName name("Stylus", this->GetToolReferenceFrameName());
454  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), stylusToTrackerTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
455  }
456  break;
457  }
458  case (FakeTrackerMode_RecordPhantomLandmarks): // Touches some positions with 1 sec difference
459  {
460  ToolStatus toolStatus = TOOL_OK;
461  const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
462 
463  // create stationary position for phantom reference (tool 0)
464  vtkSmartPointer<vtkTransform> referenceToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
465  referenceToTrackerTransform->Identity();
466 
467  referenceToTrackerTransform->Translate(300, 400, 700);
468  referenceToTrackerTransform->RotateZ(90);
469 
470  {
471  igsioTransformName name("Reference", this->GetToolReferenceFrameName());
472  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), referenceToTrackerTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
473  }
474  // touch landmark points
475  vtkSmartPointer<vtkTransform> landmarkToPhantomTransform = vtkSmartPointer<vtkTransform>::New();
476  landmarkToPhantomTransform->Identity();
477 
478  // Translate to actual landmark point
479  if (this->Counter >= 0 && this->Counter < this->PhantomLandmarks->GetNumberOfPoints())
480  {
481  double currentLandmarkPosition[3];
482  this->PhantomLandmarks->GetPoint(this->Counter, currentLandmarkPosition);
483  landmarkToPhantomTransform->Translate(currentLandmarkPosition[0], currentLandmarkPosition[1], currentLandmarkPosition[2]);
484  }
485 
486  // Get stylus calibration inverse transform
487  vtkSmartPointer<vtkTransform> stylusToStylusTipTransform = vtkSmartPointer<vtkTransform>::New();
488  stylusToStylusTipTransform->Identity();
489  if (this->TransformRepository)
490  {
491  vtkSmartPointer<vtkMatrix4x4> stylusToStylusTipTransformMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
492  igsioTransformName stylusToStylusTipTransformName("Stylus", "StylusTip");
493  if (this->TransformRepository->GetTransform(stylusToStylusTipTransformName, stylusToStylusTipTransformMatrix) == PLUS_SUCCESS)
494  {
495  stylusToStylusTipTransform->Concatenate(stylusToStylusTipTransformMatrix);
496  }
497  }
498 
499  // Rotate to make motion visible even if the camera is reset every time
500  if (this->Counter < 7)
501  {
502  landmarkToPhantomTransform->RotateY(this->Counter * 5.0);
503  }
504  else
505  {
506  landmarkToPhantomTransform->RotateY(180.0);
507  }
508  landmarkToPhantomTransform->RotateZ(this->Counter * 5.0);
509  vtkSmartPointer<vtkTransform> phantomToReferenceTransform = vtkSmartPointer<vtkTransform>::New();
510  phantomToReferenceTransform->Identity();
511  phantomToReferenceTransform->Translate(-75, -50, -150);
512 
513  vtkSmartPointer<vtkTransform> stylusToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
514  stylusToTrackerTransform->Concatenate(referenceToTrackerTransform);
515  stylusToTrackerTransform->Concatenate(phantomToReferenceTransform);
516  stylusToTrackerTransform->Concatenate(landmarkToPhantomTransform);
517  stylusToTrackerTransform->Concatenate(stylusToStylusTipTransform); // Un-calibrate it
518 
519  {
520  igsioTransformName name("Stylus", this->GetToolReferenceFrameName());
521  this->ToolTimeStampedUpdate(name.GetTransformName().c_str(), stylusToTrackerTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
522  }
523  }
524  break;
525 
526  case (FakeTrackerMode_ToolState): // Changes the state of the tool from time to time
527  {
528  // Set flags
529  ToolStatus toolStatus = TOOL_OK;
530 
531  const int state = (this->Counter / 100) % 3;
532  switch (state)
533  {
534  case 1:
535  toolStatus = TOOL_OUT_OF_VIEW;
536  break;
537  case 2:
538  toolStatus = TOOL_MISSING;
539  break;
540  default:
541  break;
542  }
543  const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
544 
545  // create stationary position for phantom reference (tool 0)
546  vtkSmartPointer<vtkTransform> identityTransform = vtkSmartPointer<vtkTransform>::New();
547  identityTransform->Identity();
548 
549  this->ToolTimeStampedUpdate("Test", identityTransform->GetMatrix(), toolStatus, this->Frame, unfilteredTimestamp);
550 
551  this->Counter++;
552  }
553  break;
554  default:
555  break;
556  }
557 
558  return PLUS_SUCCESS;
559 }
560 
561 //----------------------------------------------------------------------------
562 PlusStatus vtkPlusFakeTracker::ReadConfiguration(vtkXMLDataElement* rootConfigElement)
563 {
564  LOG_TRACE("vtkPlusFakeTracker::ReadConfiguration");
565 
566  XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement);
567 
568  if (!this->Recording)
569  {
570  // Read mode
571 
572  const char* mode = deviceConfig->GetAttribute("Mode");
573  if (mode != NULL)
574  {
575  if (STRCASECMP(mode, "Default") == 0)
576  {
578  }
579  else if (STRCASECMP(mode, "SmoothMove") == 0)
580  {
582  }
583  else if (STRCASECMP(mode, "SmoothTranslation") == 0)
584  {
586  }
587  else if (STRCASECMP(mode, "PivotCalibration") == 0)
588  {
590  }
591  else if (STRCASECMP(mode, "RecordPhantomLandmarks") == 0)
592  {
594  }
595  else if (STRCASECMP(mode, "ToolState") == 0)
596  {
598  }
599  else
600  {
602  }
603  }
604 
605  // Read landmarks for RecordPhantomLandmarks mode
606  bool phantomLandmarksFound = true;
607  vtkXMLDataElement* landmarks = NULL;
608  vtkXMLDataElement* phantomDefinition = rootConfigElement->FindNestedElementWithName("PhantomDefinition");
609  if (phantomDefinition == NULL)
610  {
611  phantomLandmarksFound = false;
612  }
613  else
614  {
615  vtkXMLDataElement* geometry = phantomDefinition->FindNestedElementWithName("Geometry");
616  if (geometry == NULL)
617  {
618  phantomLandmarksFound = false;
619  }
620  else
621  {
622  landmarks = geometry->FindNestedElementWithName("Landmarks");
623  if (landmarks == NULL)
624  {
625  phantomLandmarksFound = false;
626  }
627  }
628  }
629 
630  if (!phantomLandmarksFound)
631  {
633  {
634  LOG_ERROR("Phantom landmarks cannot be found in the configuration XML tree - FakeTracker in RecordPhantomLandmarks mode cannot be started!");
635  return PLUS_FAIL;
636  }
637  else
638  {
639  LOG_DEBUG("Phantom landmarks cannot be found in the configuration XML tree - FakeTracker in RecordPhantomLandmarks mode cannot be started.");
640  }
641  }
642  else
643  {
644  this->PhantomLandmarks->Reset();
645  int numberOfLandmarks = landmarks->GetNumberOfNestedElements();
646  for (int i = 0; i < numberOfLandmarks; ++i)
647  {
648  vtkXMLDataElement* landmark = landmarks->GetNestedElement(i);
649 
650  if ((landmark == NULL) || (STRCASECMP("Landmark", landmark->GetName())))
651  {
652  LOG_WARNING("Invalid landmark definition found!");
653  continue;
654  }
655 
656  double landmarkPosition[3];
657  if (! landmark->GetVectorAttribute("Position", 3, landmarkPosition))
658  {
659  LOG_WARNING("Invalid landmark position!");
660  continue;
661  }
662 
663  this->PhantomLandmarks->InsertPoint(i, landmarkPosition);
664  }
665  }
666  }
667 
668  return PLUS_SUCCESS;
669 }
DataSourceContainer::const_iterator DataSourceContainerConstIterator
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)
vtkPoints * PhantomLandmarks
PlusStatus InternalStartRecording()
Phidget_MeshMode mode
Definition: phidget22.h:1332
vtkStandardNewMacro(vtkPlusFakeTracker)
vtkTransform * InternalTransform
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
virtual void SetTransformRepository(vtkIGSIOTransformRepository *)
bool RequirePortNameInDeviceSetConfiguration
for i
double AcquisitionRate
#define PLUS_FAIL
Definition: PlusCommon.h:43
Represents a fake tracking system as a simulator.
static vtkPlusConfig * GetInstance()
PlusStatus InternalConnect()
void SetCustomProperty(const std::string &propertyName, const std::string &propertyValue)
FakeTrackerMode Mode
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
FakeTrackerMode
int * state
Definition: phidget22.h:3207
virtual PlusStatus StopRecording()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
void SetMode(FakeTrackerMode)
virtual bool IsRecording() const
bool StartThreadForInternalUpdates
DataSourceContainerConstIterator GetToolIteratorBegin() const
vtkIGSIOTransformRepository * TransformRepository
PlusStatus InternalStopRecording()
std::string GetToolReferenceFrameName() const
virtual void SetPhantomLandmarks(vtkPoints *)
PlusStatus InternalDisconnect()
PlusStatus GetTool(const char *aToolSourceId, vtkPlusDataSource *&aTool) const
DataSourceContainerConstIterator GetToolIteratorEnd() const
Interface to a 3D positioning tool, video source, or generalized data stream.