Skip to content

Commit

Permalink
BUG: Fix embedded transform errors in vtkPlusOpenIGTLinkVideoSource
Browse files Browse the repository at this point in the history
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 PlusToolkit#873
  • Loading branch information
Sunderlandkyl committed Dec 9, 2021
1 parent 8e042f2 commit c07ec27
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,25 @@ 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;
}
}
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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c07ec27

Please sign in to comment.