From f1d39fc21d54ba5488e0a6c5bac3e576a5be1067 Mon Sep 17 00:00:00 2001 From: Alejandro Rodriguez Moreno Date: Fri, 26 Sep 2025 09:15:28 +0100 Subject: [PATCH] COMP: Fix extension with latest Slicer; Support new devices Squashed commits: ENH: Changed LookingGlassVTKModule repository to one with support for newer devices BUG: Fix LookingGlass not referencing the 3D view BUG: Fix crash when clicking connecting device COMP: Fixed interactor to work with new version COMP: Factory functions removed due to VTK_SINGLETON_CXX creating them COMP: Fetching newest commit that doesn't use the old VTK::Open-GL dependency Signed-off-by: Csaba Pinter --- FetchVTKRenderingLookingGlass.cmake | 4 +- .../Logic/vtkSlicerLookingGlassLogic.cxx | 21 +++++++++++ ...kingGlassViewDisplayableManagerFactory.cxx | 34 ----------------- .../Widgets/qMRMLLookingGlassView.cxx | 37 +++++++++++++------ 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/FetchVTKRenderingLookingGlass.cmake b/FetchVTKRenderingLookingGlass.cmake index 4aacfbf..04324eb 100644 --- a/FetchVTKRenderingLookingGlass.cmake +++ b/FetchVTKRenderingLookingGlass.cmake @@ -5,8 +5,8 @@ if(NOT DEFINED vtkRenderingLookingGlass_SOURCE_DIR) set(EP_SOURCE_DIR "${CMAKE_BINARY_DIR}/${proj}") FetchContent_Populate(${proj} SOURCE_DIR ${EP_SOURCE_DIR} - GIT_REPOSITORY https://github.com/KitwareMedical/LookingGlassVTKModule.git - GIT_TAG 23cd56032165848c60739898ccf613e35cbde62d # slicer-20221024-78cc2ce + GIT_REPOSITORY https://github.com/cpinter/LookingGlassVTKModule + GIT_TAG fd2b4611c28f2d019deaaeef58df8b35d44d7698 QUIET ) message(STATUS "Remote - ${proj} [OK]") diff --git a/LookingGlass/Logic/vtkSlicerLookingGlassLogic.cxx b/LookingGlass/Logic/vtkSlicerLookingGlassLogic.cxx index 9257afd..f0a3882 100644 --- a/LookingGlass/Logic/vtkSlicerLookingGlassLogic.cxx +++ b/LookingGlass/Logic/vtkSlicerLookingGlassLogic.cxx @@ -227,6 +227,27 @@ void vtkSlicerLookingGlassLogic::SetLookingGlassConnected(bool connect) if (this->ActiveViewNode) { this->ActiveViewNode->SetVisibility(1); + + // Always set the reference view node to the first visible 3D view node + vtkMRMLScene* scene = this->GetMRMLScene(); + if (scene) + { + vtkSmartPointer nodes = vtkSmartPointer::Take( + scene->GetNodesByClass("vtkMRMLViewNode")); + vtkMRMLViewNode* viewNode = nullptr; + vtkCollectionSimpleIterator it; + for (nodes->InitTraversal(it); (viewNode = vtkMRMLViewNode::SafeDownCast( + nodes->GetNextItemAsObject(it)));) + { + if (viewNode->GetVisibility() && viewNode->IsMappedInLayout()) + { + // Found a view node displayed in current layout, use this + break; + } + } + // Either use a view node displayed in current layout or just any 3D view node found in the scene + this->ActiveViewNode->SetAndObserveReferenceViewNode(viewNode); + } } else { diff --git a/LookingGlass/MRML/vtkMRMLLookingGlassViewDisplayableManagerFactory.cxx b/LookingGlass/MRML/vtkMRMLLookingGlassViewDisplayableManagerFactory.cxx index 917063c..7bd7765 100644 --- a/LookingGlass/MRML/vtkMRMLLookingGlassViewDisplayableManagerFactory.cxx +++ b/LookingGlass/MRML/vtkMRMLLookingGlassViewDisplayableManagerFactory.cxx @@ -24,40 +24,6 @@ // VTK includes #include -//---------------------------------------------------------------------------- -// vtkMRMLLookingGlassViewDisplayableManagerFactory methods - -//---------------------------------------------------------------------------- -// Up the reference count so it behaves like New -vtkMRMLLookingGlassViewDisplayableManagerFactory* vtkMRMLLookingGlassViewDisplayableManagerFactory::New() -{ - vtkMRMLLookingGlassViewDisplayableManagerFactory* instance = Self::GetInstance(); - instance->Register(0); - return instance; -} - -//---------------------------------------------------------------------------- -vtkMRMLLookingGlassViewDisplayableManagerFactory* vtkMRMLLookingGlassViewDisplayableManagerFactory::GetInstance() -{ - if(!Self::Instance) - { - // Try the factory first - Self::Instance = (vtkMRMLLookingGlassViewDisplayableManagerFactory*) - vtkObjectFactory::CreateInstance("vtkMRMLLookingGlassViewDisplayableManagerFactory"); - - // if the factory did not provide one, then create it here - if(!Self::Instance) - { - Self::Instance = new vtkMRMLLookingGlassViewDisplayableManagerFactory; -#ifdef VTK_HAS_INITIALIZE_OBJECT_BASE - Self::Instance->InitializeObjectBase(); -#endif - } - } - // return the instance - return Self::Instance; -} - //---------------------------------------------------------------------------- vtkMRMLLookingGlassViewDisplayableManagerFactory:: vtkMRMLLookingGlassViewDisplayableManagerFactory():Superclass() diff --git a/LookingGlass/Widgets/qMRMLLookingGlassView.cxx b/LookingGlass/Widgets/qMRMLLookingGlassView.cxx index 48b8442..4c93c35 100644 --- a/LookingGlass/Widgets/qMRMLLookingGlassView.cxx +++ b/LookingGlass/Widgets/qMRMLLookingGlassView.cxx @@ -167,29 +167,42 @@ void qMRMLLookingGlassViewPrivate::createRenderWindow() this->LastViewPosition[1] = 0.0; this->LastViewPosition[2] = 0.0; - this->RenderWindow = vtkSmartPointer::Take( - vtkLookingGlassInterface::CreateLookingGlassRenderWindow()); + // Ensure render window exists + if (!this->RenderWindow) + { + this->RenderWindow = vtkSmartPointer::New(); + } - this->Renderer = vtkSmartPointer::New(); + // Create render window interactor this->Interactor = vtkSmartPointer::New(); + this->RenderWindow->SetInteractor(this->Interactor); + + // Create MRML interactor style this->InteractorStyle = vtkSmartPointer::New(); - this->Interactor->SetInteractorStyle(this->InteractorStyle); - this->InteractorStyle->SetInteractor(this->Interactor); - this->InteractorStyle->SetCurrentRenderer(this->Renderer); + if (this->Interactor && this->InteractorStyle) + { + this->InteractorStyle->SetInteractor(this->Interactor); + } + // Now safe to continue this->Camera = vtkSmartPointer::New(); - this->Renderer->SetActiveCamera(this->Camera); - this->RenderWindow->SetMultiSamples(0); - this->RenderWindow->AddRenderer(this->Renderer); - this->RenderWindow->SetInteractor(this->Interactor); - // The interactor never calls Render() on the render window. + if (!this->Renderer) + { + this->Renderer = vtkSmartPointer::New(); + this->Renderer->SetBackground(0.1, 0.1, 0.1); + this->Renderer->SetActiveCamera(this->Camera); + this->RenderWindow->SetMultiSamples(0); + this->RenderWindow->AddRenderer(this->Renderer); // attach renderer to window + } + + // Interactor already attached above, no need to repeat this->Interactor->SetEnableRender(false); // Ensure this view catches all render requests and ensure the desired framerate this->qvtkReconnect(this->RenderWindow->GetInteractor(), this->Interactor, - vtkCommand::RenderEvent, q, SLOT(scheduleRender())); + vtkCommand::RenderEvent, q, SLOT(scheduleRender())); vtkMRMLLookingGlassViewDisplayableManagerFactory* factory = vtkMRMLLookingGlassViewDisplayableManagerFactory::GetInstance();