8 #include "igsioCommon.h" 9 #include "PlusConfigure.h" 13 #include <vtkImageData.h> 15 #include <vtkMatrix4x4.h> 43 #ifdef USE_DAVINCI_TIMESTAMPS
44 , TrackerTimeToSystemTimeSec(0.0)
45 , TrackerTimeToSystemTimeComputed(false)
84 LOG_ERROR(
"vtkPlusIntuitiveDaVinciTracker::Probe should not be called while the device is already initialized");
90 LOG_ERROR(
"vtkPlusIntuitiveDaVinciTracker::Probe could not connect to the da Vinci!");
99 if (manipNames.size() == 0)
101 LOG_ERROR(
"Error in retrieving manipulator information. Zero manipulators found.");
105 for (
int i = 0;
i < manipNames.size();
i++)
107 LOG_DEBUG(
"Manipulator " <<
i <<
" name: " << manipNames[
i] <<
"\n");
122 LOG_ERROR(
"InternalStartRecording failed: da Vinci has not been initialized");
128 LOG_ERROR(
"InternalStartRecording failed: da Vinci is not connected");
134 LOG_ERROR(
"InternalStartRecording: Unable to start streaming.");
152 LOG_TRACE(
"vtkPlusIntuitiveDaVinciTracker::ReadConfiguration");
167 XML_READ_STRING_ATTRIBUTE_WARNING(
IpAddr, deviceConfig);
168 XML_READ_SCALAR_ATTRIBUTE_WARNING(
unsigned int,
Port, deviceConfig);
169 XML_READ_STRING_ATTRIBUTE_WARNING(
Password, deviceConfig);
179 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
IpAddr, trackerConfig);
180 trackerConfig->SetIntAttribute(
"Port", this->
Port);
181 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
Password, trackerConfig);
191 LOG_TRACE(
"vtkPlusIntuitiveDaVinciTracker::InternalConnect");
195 LOG_DEBUG(
"Already connected to da Vinci");
201 int connectionAttempts(0);
202 bool initCompleted(
false);
207 while (!initCompleted && connectionAttempts < MAX_ATTEMPTS)
211 LOG_DEBUG(
"Failed to connect to da Vinci. Retry: " << connectionAttempts);
212 vtkIGSIOAccurateTimer::Delay(1.0);
213 connectionAttempts++;
216 initCompleted =
true;
219 if (connectionAttempts == MAX_ATTEMPTS)
221 LOG_ERROR(
"Error in initializing da Vinci");
227 LOG_ERROR(
"Error in subscribing to events and stream! Stream not started!");
231 #ifdef USE_DAVINCI_TIMESTAMPS 232 this->TrackerTimeToSystemTimeSec = 0;
233 this->TrackerTimeToSystemTimeComputed =
false;
254 void vtkPlusIntuitiveDaVinciTracker::StreamCallback(
void)
258 LOG_ERROR(
"InternalUpdate failed: daVinci has not been initialized");
265 LOG_DEBUG(
"Dropped frame: daVinci is not recording");
274 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
276 #ifdef USE_DAVINCI_TIMESTAMPS 277 if (!this->TrackerTimeToSystemTimeComputed)
279 const double timeSystemSec = unfilteredTimestamp;
280 const double timeTrackerSec = this->
DaVinci->mtGetLatestFrameTime();
281 this->TrackerTimeToSystemTimeSec = timeSystemSec - timeTrackerSec;
282 this->TrackerTimeToSystemTimeComputed =
true;
284 const double timeTrackerSec = this->
DaVinci->mtGetLatestFrameTime();
285 const double timeSystemSec = timeTrackerSec + this->TrackerTimeToSystemTimeSec;
288 vtkNew<vtkMatrix4x4> transformMatrix;
290 ISI_TRANSFORM* transform(NULL);
291 ISI_STREAM_FIELD stream_data;
294 std::string toolName = it->second->GetPortName();
296 ISI_MANIP_INDEX manipIndex = getManipIndexFromName(toolName);
298 if (manipIndex == -1)
303 bool inverseTransform(
false);
304 if (toolName.find(
"_TIP") != std::string::npos)
307 isi_get_stream_field(manipIndex, ISI_TIP_TRANSFORM, &stream_data);
308 transform = (ISI_TRANSFORM*) stream_data.data;
310 else if (toolName.find(
"_EYE_FRAME") != std::string::npos)
315 isi_get_reference_frame(ISI_PSM2, ISI_EYE_FRAME, transform);
316 inverseTransform =
true;
320 if (transform == NULL)
325 setVtkMatrixFromISITransform(*transformMatrix, transform);
327 if (inverseTransform)
329 vtkMatrix4x4::Invert(transformMatrix, transformMatrix);
332 std::ostringstream transformStream;
333 transformMatrix->Print(transformStream);
334 LOG_TRACE(
"Updating toolname: " << toolName <<
" with transform:\n\t" << transformStream <<
"\n");
336 #ifdef USE_DAVINCI_TIMESTAMPS 343 LOG_TRACE(
"All subscribed fields from da Vinci have been updated");
347 ISI_MANIP_INDEX vtkPlusIntuitiveDaVinciTracker::getManipIndexFromName(
const std::string& toolName)
349 ISI_MANIP_INDEX manipIndex = ISI_PSM1;
351 toolName = toolName.substr(0, toolName.size() - 4);
353 if (igsioCommon::IsEqualInsensitive(
"ISI_PSM1", toolName))
355 manipIndex = ISI_PSM1;
357 else if (igsioCommon::IsEqualInsensitive(
"ISI_PSM2", toolName))
359 manipIndex = ISI_PSM2;
361 else if (igsioCommon::IsEqualInsensitive(
"ISI_ECM", toolName))
363 manipIndex = ISI_ECM;
365 else if (igsioCommon::IsEqualInsensitive(
"ISI_MTML1", toolName))
367 manipIndex = ISI_MTML1;
369 else if (igsioCommon::IsEqualInsensitive(
"ISI_MTMR1", toolName))
371 manipIndex = ISI_MTMR1;
373 else if (igsioCommon::IsEqualInsensitive(
"ISI_PSM3", toolName))
375 manipIndex = ISI_PSM3;
377 else if (igsioCommon::IsEqualInsensitive(
"ISI_GANTRY", toolName))
379 manipIndex = ISI_GANTRY;
381 else if (igsioCommon::IsEqualInsensitive(
"ISI_MTML2", toolName))
383 manipIndex = ISI_MTML2;
385 else if (igsioCommon::IsEqualInsensitive(
"ISI_MTMR2", toolName))
387 manipIndex = ISI_MTMR2;
389 else if (igsioCommon::IsEqualInsensitive(
"ISI_CONSOLE1", toolName))
391 manipIndex = ISI_CONSOLE1;
393 else if (igsioCommon::IsEqualInsensitive(
"ISI_CONSOLE2", toolName))
395 manipIndex = ISI_CONSOLE2;
397 else if (igsioCommon::IsEqualInsensitive(
"ISI_CORE", toolName))
399 manipIndex = ISI_CORE;
403 LOG_DEBUG(
"Could not set manipIndex. Defaulting to PSM1");
410 void vtkPlusIntuitiveDaVinciTracker::setVtkMatrixFromISITransform(vtkMatrix4x4& destVtkMatrix, ISI_TRANSFORM* srcIsiMatrix)
412 destVtkMatrix->Identity();
415 destVtkMatrix.SetElement(0, 0, srcIsiMatrix->rot.row0.x);
416 destVtkMatrix.SetElement(1, 0, srcIsiMatrix->rot.row0.y);
417 destVtkMatrix.SetElement(2, 0, srcIsiMatrix->rot.row0.z);
418 destVtkMatrix.SetElement(3, 0, 0);
420 destVtkMatrix.SetElement(0, 1, srcIsiMatrix->rot.row1.x);
421 destVtkMatrix.SetElement(1, 1, srcIsiMatrix->rot.row1.y);
422 destVtkMatrix.SetElement(2, 1, srcIsiMatrix->rot.row1.z);
423 destVtkMatrix.SetElement(3, 1, 0);
425 destVtkMatrix.SetElement(0, 2, srcIsiMatrix->rot.row2.x);
426 destVtkMatrix.SetElement(1, 2, srcIsiMatrix->rot.row2.y);
427 destVtkMatrix.SetElement(2, 2, srcIsiMatrix->rot.row2.z);
428 destVtkMatrix.SetElement(3, 2, 0);
430 destVtkMatrix.SetElement(0, 3, srcIsiMatrix->pos.x);
431 destVtkMatrix.SetElement(1, 3, srcIsiMatrix->pos.y);
432 destVtkMatrix.SetElement(2, 3, srcIsiMatrix->pos.z);
433 destVtkMatrix.SetElement(3, 3, 1);
441 void ISICALLBACK
eventCB(ISI_MANIP_INDEX mid, ISI_EVENT_ID event_id, ISI_INT args[ISI_NUM_EVENT_ARGS],
void* userdata)
443 LOG_INFO(isi_get_event_timestamp(mid, event_id) <<
" mid: " << isi_get_manip_name(mid) <<
",\tevent: " << isi_get_event_name(event_id) <<
", args: (" << args[0] <<
" " << args[1] <<
" " << args[2] <<
" " << args[3] <<
")");
452 trackerInstance->StreamCallback();
Abstract interface for tracker and video devices.
void ISICALLBACK eventCB(ISI_MANIP_INDEX mid, ISI_EVENT_ID event_id, ISI_INT args[ISI_NUM_EVENT_ARGS], void *userdata)
IntuitiveDaVinci * GetDaVinci() const
IntuitiveDaVinci * DaVinci
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
virtual PlusStatus ToolTimeStampedUpdateWithoutFiltering(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, double unfilteredtimestamp, double filteredtimestamp, const igsioFieldMapType *customFields=NULL)
virtual PlusStatus InternalDisconnect()
void setHostInfo(const std::string ip, const unsigned int port, const std::string pass)
virtual PlusStatus InternalStopRecording()
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
vtkPlusIntuitiveDaVinciTracker()
bool RequirePortNameInDeviceSetConfiguration
DataSourceContainer Tools
virtual std::string GetSdkVersion()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *rootConfigElement)
virtual PlusStatus Disconnect()
std::vector< std::string > getManipulatorNames()
vtkStandardNewMacro(vtkPlusIntuitiveDaVinciTracker)
ISI_STATUS subscribe(ISI_EVENT_CALLBACK eCB, ISI_STREAM_CALLBACK sCB, void *eventUserData, void *streamUserData)
virtual PlusStatus StopRecording()
void ISICALLBACK streamCB(void *userData)
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
DataSourceContainer::iterator DataSourceContainerIterator
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *rootConfigElement)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual PlusStatus Probe()
bool StartThreadForInternalUpdates
~vtkPlusIntuitiveDaVinciTracker()
virtual PlusStatus InternalStartRecording()
virtual PlusStatus InternalConnect()
std::string getLibraryVersion()