Skip to content

Commit

Permalink
BUG: Fixed widget texture update in VR view
Browse files Browse the repository at this point in the history
A workaround was implemented, a better solution will be needed in the long run.

Re KitwareMedical#43
  • Loading branch information
cpinter committed Aug 22, 2023
1 parent d8cc5c2 commit 856efa5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
29 changes: 27 additions & 2 deletions GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "vtkMRMLGUIWidgetNode.h"
#include "vtkMRMLGUIWidgetDisplayNode.h"

// MRML includes
#include <vtkMRMLScene.h>

// VTK includes
#include <vtkActor.h>
#include <vtkCallbackCommand.h>
Expand Down Expand Up @@ -270,8 +273,30 @@ void vtkSlicerQWidgetRepresentation::OnTextureModified(
self->PlaceWidget(bounds);

// Trigger rendering in view
if (self->GetViewNode()->GetSelectable())
vtkMRMLNode* vrViewNode = self->GetViewNode()->GetScene()->GetSingletonNode("Active", "vtkMRMLVirtualRealityViewNode");
if (vrViewNode)
{
self->GetViewNode()->Modified();
if (self->GetViewNode()->GetSelectable()) //TODO: Workaround for stack overflow, see vtkSlicerQWidgetWidget::CreateDefaultRepresentation
{
self->GetViewNode()->Modified();

//TODO: Workaround for fixing the texture update in the VR view.
// Apparently the QGraphicsScene::changed signal is not emitted for the widget representation in the VR view.
// However, a connection was added for testing to the QObject::objectNameChanged signal, which does work.
// Need to fix the graphics scene changed signal connection.
if (self->GetViewNode() != vrViewNode)
{
if (!vrViewNode->GetAttribute("WaitingForTextureUpdate") || strcmp(vrViewNode->GetAttribute("WaitingForTextureUpdate"), "1"))
{
vrViewNode->SetAttribute("WaitingForTextureUpdate", "1");

widget->setObjectName(widget->objectName().compare("AlternateObjectName1") ? "AlternateObjectName1" : "AlternateObjectName2");
}
}
else
{
vrViewNode->SetAttribute("WaitingForTextureUpdate", "0"); // Indicate that VR view has updated the texture
}
}
}
}
2 changes: 1 addition & 1 deletion GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void vtkSlicerQWidgetTexture::SetupWidget()
this->Scene->addWidget(this->Widget);

QObject::connect(this->Scene, &QGraphicsScene::changed, this->UpdateTextureMethod);
QObject::connect(this->Widget, &QObject::objectNameChanged, this->UpdateTextureMethod); //TODO: For debugging
QObject::connect(this->Widget, &QObject::objectNameChanged, this->UpdateTextureMethod); //TODO: Workaround, see vtkSlicerQWidgetRepresentation::OnTextureModified

if (this->TextureImageData.GetPointer() == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void vtkSlicerQWidgetWidget::CreateDefaultRepresentation(
}

bool wasSelectable = viewNode->GetSelectable();
viewNode->SetSelectable(false); // Workaround to disable texture updates until setup is completed
viewNode->SetSelectable(false); //TODO: Workaround to disable texture updates until setup is completed

vtkNew<vtkSlicerQWidgetRepresentation> rep;
this->SetRenderer(renderer);
Expand Down

0 comments on commit 856efa5

Please sign in to comment.