From c07ec278b7e3efb1bc62f08a0d3fbd36a953e829 Mon Sep 17 00:00:00 2001 From: Kyle Sunderland Date: Thu, 9 Dec 2021 02:33:43 -0500 Subject: [PATCH] BUG: Fix embedded transform errors in vtkPlusOpenIGTLinkVideoSource When receiving messages with embedded transforms from vtkPlusOpenIGTLinkVideoSource, several errors occurred. - If the From and To coordinate frames of the embedded transform are the same, the Transform repository will log an error ("Setting a transform to itself is not allowed") when sending any images using vtkPlusOpenIGTLinkServer. Fixed by not unpacking the transform when From == To. - If an incoming image message has no status set for the embedded transform, the transform is considered invalid. Fixed by marking incoming embedded transforms with no status as OK. Re #873 --- .../vtkPlusOpenIGTLinkVideoSource.cxx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/PlusDataCollection/OpenIGTLink/vtkPlusOpenIGTLinkVideoSource.cxx b/src/PlusDataCollection/OpenIGTLink/vtkPlusOpenIGTLinkVideoSource.cxx index f66914b6a..9d583f8f9 100644 --- a/src/PlusDataCollection/OpenIGTLink/vtkPlusOpenIGTLinkVideoSource.cxx +++ b/src/PlusDataCollection/OpenIGTLink/vtkPlusOpenIGTLinkVideoSource.cxx @@ -74,9 +74,17 @@ PlusStatus vtkPlusOpenIGTLinkVideoSource::InternalUpdate() igsioTrackedFrame trackedFrame; igtl::MessageBase::Pointer bodyMsg = this->MessageFactory->CreateReceiveMessage(headerMsg); + igsioTransformName embeddedTransformName = this->ImageMessageEmbeddedTransformName; + if (this->ImageMessageEmbeddedTransformName.From() == this->ImageMessageEmbeddedTransformName.To()) + { + // If the From and To coordinate frames are the same, then don't unpack the transform. + // Unpacking the transform would cause errors such as "Setting a transform to itself is not allowed" in vtkIGSIOTransformRepository. + embeddedTransformName = igsioTransformName(); + } + if (typeid(*bodyMsg) == typeid(igtl::ImageMessage)) { - if (vtkPlusIgtlMessageCommon::UnpackImageMessage(bodyMsg, this->ClientSocket, trackedFrame, this->ImageMessageEmbeddedTransformName, this->IgtlMessageCrcCheckEnabled) != PLUS_SUCCESS) + if (vtkPlusIgtlMessageCommon::UnpackImageMessage(bodyMsg, this->ClientSocket, trackedFrame, embeddedTransformName, this->IgtlMessageCrcCheckEnabled) != PLUS_SUCCESS) { LOG_ERROR("Couldn't get image from OpenIGTLink server!"); return PLUS_FAIL; @@ -84,7 +92,7 @@ PlusStatus vtkPlusOpenIGTLinkVideoSource::InternalUpdate() } else if (typeid(*bodyMsg) == typeid(igtl::PlusTrackedFrameMessage)) { - if (vtkPlusIgtlMessageCommon::UnpackTrackedFrameMessage(bodyMsg, this->ClientSocket, trackedFrame, this->ImageMessageEmbeddedTransformName, this->IgtlMessageCrcCheckEnabled) != PLUS_SUCCESS) + if (vtkPlusIgtlMessageCommon::UnpackTrackedFrameMessage(bodyMsg, this->ClientSocket, trackedFrame, embeddedTransformName, this->IgtlMessageCrcCheckEnabled) != PLUS_SUCCESS) { LOG_ERROR("Couldn't get tracked frame from OpenIGTLink server!"); return PLUS_FAIL; @@ -140,6 +148,18 @@ PlusStatus vtkPlusOpenIGTLinkVideoSource::InternalUpdate() aSource->SetImageType(videoFrame->GetImageType()); aSource->SetInputFrameSize(trackedFrame.GetFrameSize()); } + + if (embeddedTransformName.IsValid()) + { + std::string transformStatusField = embeddedTransformName.GetTransformName() + igsioTrackedFrame::TransformStatusPostfix; + std::string strStatus = trackedFrame.GetFrameField(transformStatusField); + if (strStatus.empty()) + { + // Transform status has not been set on the frame, and is assumed to be OK. + trackedFrame.SetFrameTransformStatus(embeddedTransformName, TOOL_OK); + } + } + igsioFieldMapType customFields = trackedFrame.GetCustomFields(); PlusStatus status = aSource->AddItem(trackedFrame.GetImageData(), this->FrameNumber, unfilteredTimestamp, filteredTimestamp, &customFields); this->Modified();