From 5e0111f7be00e0783985033237528a4a2a77ed2e Mon Sep 17 00:00:00 2001 From: Csaba Pinter Date: Thu, 15 Jun 2023 09:25:58 +0100 Subject: [PATCH] BUG: Fixed widget texture update in VR view A workaround was implemented, a better solution will be needed in the long run. Re KitwareMedical#43 --- .../vtkSlicerQWidgetRepresentation.cxx | 29 +++++++++++++++++-- .../VTKWidgets/vtkSlicerQWidgetTexture.cxx | 2 +- .../VTKWidgets/vtkSlicerQWidgetWidget.cxx | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx index a034987..3aae8d5 100644 --- a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx +++ b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx @@ -28,6 +28,9 @@ #include "vtkMRMLGUIWidgetNode.h" #include "vtkMRMLGUIWidgetDisplayNode.h" +// MRML includes +#include + // VTK includes #include #include @@ -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 + } + } } } diff --git a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx index 689716a..e4fc835 100644 --- a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx +++ b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx @@ -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) { diff --git a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx index 0cd25dd..5baf6cf 100644 --- a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx +++ b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx @@ -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 rep; this->SetRenderer(renderer);