7 #include "PlusConfigure.h" 10 #include "vtkMatrix4x4.h" 11 #include "vtkMinimalStandardRandomSequence.h" 12 #include "vtkObjectFactory.h" 14 #include "vtkTransform.h" 21 , InternalTransform(vtkTransform::New())
23 , TransformRepository(NULL)
26 , PhantomLandmarks(NULL)
28 vtkSmartPointer<vtkPoints> phantomLandmarks = vtkSmartPointer<vtkPoints>::New();
52 LOG_TRACE(
"vtkPlusFakeTracker::SetMode(" <<
mode <<
")");
60 LOG_TRACE(
"vtkPlusFakeTracker::InternalConnect");
73 LOG_ERROR(
"Failed to get tool: Reference in FakeTracker Default mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
84 LOG_ERROR(
"Failed to get tool: Stylus in FakeTracker Default mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
95 LOG_ERROR(
"Failed to get tool: Stylus-2 in FakeTracker Default mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
106 LOG_ERROR(
"Failed to get tool: Stylus-3 in FakeTracker Default mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
120 LOG_ERROR(
"Failed to get tool: Probe in FakeTracker SmoothMove mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
130 LOG_ERROR(
"Failed to get tool: Reference in FakeTracker SmoothMove mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
140 LOG_ERROR(
"Failed to get tool: MissingTool in FakeTracker SmoothMove mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
152 LOG_ERROR(
"Failed to get tool: Reference in FakeTracker PivotCalibration mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
164 LOG_ERROR(
"Failed to get tool: Stylus in FakeTracker PivotCalibration mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
179 LOG_ERROR(
"Failed to get tool: Reference in FakeTracker RecordPhantomLandmarks mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
191 LOG_ERROR(
"Failed to get tool: Stylus in FakeTracker RecordPhantomLandmarks mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
208 LOG_ERROR(
"Failed to get tool: Test in FakeTracker ToolState mode, please add to config file: " <<
vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationFileName());
229 LOG_TRACE(
"vtkPlusFakeTracker::InternalDisconnect");
237 LOG_TRACE(
"vtkPlusFakeTracker::Probe");
245 LOG_TRACE(
"vtkPlusFakeTracker::InternalStartRecording");
255 LOG_TRACE(
"vtkPlusFakeTracker::InternalStopRecording");
267 LOG_TRACE(
"vtkPlusFakeTracker::InternalUpdate is called while not tracking any more");
271 if (this->
Frame++ > 355559)
280 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
283 ToolStatus toolStatus = TOOL_OK;
285 int rotation = this->
Frame / 1000;
287 if (it->second->GetPortName() ==
"0")
293 else if (it->second->GetPortName() ==
"1")
300 else if (it->second->GetPortName() ==
"2")
307 else if (it->second->GetPortName() ==
"3")
322 ToolStatus toolStatus = TOOL_OK;
323 if (this->
Frame % 10 == 0)
325 toolStatus = TOOL_MISSING;
328 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
329 double tx = (this->
Frame % 100);
330 double ty = (this->
Frame % 100) + 100;
331 double tz = (this->
Frame % 100) + 200;
333 double ry = (this->
Frame % 100) / 2.0;
361 ToolStatus toolStatus = TOOL_OK;
362 if (this->
Frame % 50 == 0)
364 toolStatus = TOOL_MISSING;
367 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
368 double tx = sin(this->
Frame / 100.0) * 20;
369 double ty = cos(this->
Frame / 50.0) * 10 + 50;
370 double tz = abs(this->
Frame % 100 - 50.0) + 100;
397 vtkMinimalStandardRandomSequence* random = vtkMinimalStandardRandomSequence::New();
401 ToolStatus toolStatus = TOOL_OK;
412 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
415 vtkSmartPointer<vtkTransform> referenceToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
416 referenceToTrackerTransform->Identity();
417 referenceToTrackerTransform->Translate(300, 400, 700);
418 referenceToTrackerTransform->RotateZ(90);
422 this->
ToolTimeStampedUpdate(name.GetTransformName().c_str(), referenceToTrackerTransform->GetMatrix(), toolStatus, this->
Frame, unfilteredTimestamp);
425 double exactRadius = 210.0;
426 double deltaTheta = 60.0;
427 double deltaPhi = 60.0;
428 double variance = 1.0;
431 double theta = random->GetRangeValue(-deltaTheta, deltaTheta);
434 double phi = random->GetRangeValue(-deltaPhi, deltaPhi);
437 double radius = random->GetRangeValue(exactRadius - variance, exactRadius + variance);
439 vtkSmartPointer<vtkTransform> stylusToReferenceTransform = vtkSmartPointer<vtkTransform>::New();
440 stylusToReferenceTransform->Identity();
441 stylusToReferenceTransform->Translate(205.0, 305.0, 55.0);
442 stylusToReferenceTransform->RotateY(phi);
443 stylusToReferenceTransform->RotateZ(theta);
444 stylusToReferenceTransform->Translate(-radius, 0.0, 0.0);
446 vtkSmartPointer<vtkTransform> stylusToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
447 stylusToTrackerTransform->Identity();
448 stylusToTrackerTransform->Concatenate(referenceToTrackerTransform);
449 stylusToTrackerTransform->Concatenate(stylusToReferenceTransform);
454 this->
ToolTimeStampedUpdate(name.GetTransformName().c_str(), stylusToTrackerTransform->GetMatrix(), toolStatus, this->
Frame, unfilteredTimestamp);
460 ToolStatus toolStatus = TOOL_OK;
461 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
464 vtkSmartPointer<vtkTransform> referenceToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
465 referenceToTrackerTransform->Identity();
467 referenceToTrackerTransform->Translate(300, 400, 700);
468 referenceToTrackerTransform->RotateZ(90);
472 this->
ToolTimeStampedUpdate(name.GetTransformName().c_str(), referenceToTrackerTransform->GetMatrix(), toolStatus, this->
Frame, unfilteredTimestamp);
475 vtkSmartPointer<vtkTransform> landmarkToPhantomTransform = vtkSmartPointer<vtkTransform>::New();
476 landmarkToPhantomTransform->Identity();
481 double currentLandmarkPosition[3];
483 landmarkToPhantomTransform->Translate(currentLandmarkPosition[0], currentLandmarkPosition[1], currentLandmarkPosition[2]);
487 vtkSmartPointer<vtkTransform> stylusToStylusTipTransform = vtkSmartPointer<vtkTransform>::New();
488 stylusToStylusTipTransform->Identity();
491 vtkSmartPointer<vtkMatrix4x4> stylusToStylusTipTransformMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
492 igsioTransformName stylusToStylusTipTransformName(
"Stylus",
"StylusTip");
495 stylusToStylusTipTransform->Concatenate(stylusToStylusTipTransformMatrix);
502 landmarkToPhantomTransform->RotateY(this->
Counter * 5.0);
506 landmarkToPhantomTransform->RotateY(180.0);
508 landmarkToPhantomTransform->RotateZ(this->
Counter * 5.0);
509 vtkSmartPointer<vtkTransform> phantomToReferenceTransform = vtkSmartPointer<vtkTransform>::New();
510 phantomToReferenceTransform->Identity();
511 phantomToReferenceTransform->Translate(-75, -50, -150);
513 vtkSmartPointer<vtkTransform> stylusToTrackerTransform = vtkSmartPointer<vtkTransform>::New();
514 stylusToTrackerTransform->Concatenate(referenceToTrackerTransform);
515 stylusToTrackerTransform->Concatenate(phantomToReferenceTransform);
516 stylusToTrackerTransform->Concatenate(landmarkToPhantomTransform);
517 stylusToTrackerTransform->Concatenate(stylusToStylusTipTransform);
521 this->
ToolTimeStampedUpdate(name.GetTransformName().c_str(), stylusToTrackerTransform->GetMatrix(), toolStatus, this->
Frame, unfilteredTimestamp);
529 ToolStatus toolStatus = TOOL_OK;
535 toolStatus = TOOL_OUT_OF_VIEW;
538 toolStatus = TOOL_MISSING;
543 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
546 vtkSmartPointer<vtkTransform> identityTransform = vtkSmartPointer<vtkTransform>::New();
547 identityTransform->Identity();
564 LOG_TRACE(
"vtkPlusFakeTracker::ReadConfiguration");
572 const char*
mode = deviceConfig->GetAttribute(
"Mode");
575 if (STRCASECMP(
mode,
"Default") == 0)
579 else if (STRCASECMP(
mode,
"SmoothMove") == 0)
583 else if (STRCASECMP(
mode,
"SmoothTranslation") == 0)
587 else if (STRCASECMP(
mode,
"PivotCalibration") == 0)
591 else if (STRCASECMP(
mode,
"RecordPhantomLandmarks") == 0)
595 else if (STRCASECMP(
mode,
"ToolState") == 0)
606 bool phantomLandmarksFound =
true;
607 vtkXMLDataElement* landmarks = NULL;
608 vtkXMLDataElement* phantomDefinition = rootConfigElement->FindNestedElementWithName(
"PhantomDefinition");
609 if (phantomDefinition == NULL)
611 phantomLandmarksFound =
false;
615 vtkXMLDataElement* geometry = phantomDefinition->FindNestedElementWithName(
"Geometry");
616 if (geometry == NULL)
618 phantomLandmarksFound =
false;
622 landmarks = geometry->FindNestedElementWithName(
"Landmarks");
623 if (landmarks == NULL)
625 phantomLandmarksFound =
false;
630 if (!phantomLandmarksFound)
634 LOG_ERROR(
"Phantom landmarks cannot be found in the configuration XML tree - FakeTracker in RecordPhantomLandmarks mode cannot be started!");
639 LOG_DEBUG(
"Phantom landmarks cannot be found in the configuration XML tree - FakeTracker in RecordPhantomLandmarks mode cannot be started.");
645 int numberOfLandmarks = landmarks->GetNumberOfNestedElements();
646 for (
int i = 0;
i < numberOfLandmarks; ++
i)
648 vtkXMLDataElement* landmark = landmarks->GetNestedElement(
i);
650 if ((landmark == NULL) || (STRCASECMP(
"Landmark", landmark->GetName())))
652 LOG_WARNING(
"Invalid landmark definition found!");
656 double landmarkPosition[3];
657 if (! landmark->GetVectorAttribute(
"Position", 3, landmarkPosition))
659 LOG_WARNING(
"Invalid landmark position!");
DataSourceContainer::const_iterator DataSourceContainerConstIterator
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)
vtkPoints * PhantomLandmarks
PlusStatus InternalStartRecording()
vtkStandardNewMacro(vtkPlusFakeTracker)
vtkTransform * InternalTransform
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
Represents a fake tracking system as a simulator.
static vtkPlusConfig * GetInstance()
PlusStatus InternalConnect()
void SetCustomProperty(const std::string &propertyName, const std::string &propertyValue)
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 InternalUpdate()
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.