I want to visualize a mesh structure in front of a video stream. To achieve this, I want to do this in a way similar to the background image example provided by the official docs. This means that I will use a separate actor and renderer for the background image and the mesh structure. The renderers are then added to a single render window.
I’ve modified this example to use Qt, namely a QVTKOpenGLNativeWidget
containing the render window. This is used as the main widget then.
To disable any possible interaction with the background video stream, I used the method InteractiveOff
on the background image renderer. However, this has no effect - I can still interact with the renderer.
I’ve written a very short example which will give you a small demonstration of the issue. In this example, I am using a png image loaded via a certain file path to be used for the background image.
#include <QApplication>
#include <QMainWindow>
#include <QVTKOpenGLNativeWidget.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkImageActor.h>
#include <vtkImageReader2.h>
#include <vtkImageReader2Factory.h>
#include <vtkRenderer.h>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
vtkNew<vtkImageReader2Factory> readerFactory;
vtkSmartPointer<vtkImageReader2> imageReader;
imageReader.TakeReference(readerFactory->CreateImageReader2("/home/Documents/test.png"));
imageReader->SetFileName("/home/Documents/test.png");
imageReader->Update();
const auto imageData = imageReader->GetOutput();
auto actor = vtkSmartPointer<vtkImageActor>::New();
actor->SetInputData(imageData);
auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->InteractiveOff();
auto renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
renderWindow->AddRenderer(renderer);
auto* const vtkRenderWidget = new QVTKOpenGLNativeWidget;
vtkRenderWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
vtkRenderWidget->setRenderWindow(renderWindow.Get());
auto* const mainWindow = new QMainWindow;
mainWindow->setCentralWidget(vtkRenderWidget);
mainWindow->show();
renderWindow->Render();
return app.exec();
}
You can just use a certain png file and replace the file path in the code then.
The CMakeLists.txt looks like the following:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(BackgroundImage)
find_package(QT NAMES Qt5 COMPONENTS Core Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
find_package(VTK COMPONENTS
GUISupportQt
IOImage
)
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(BackgroundImage MACOSX_BUNDLE BackgroundImage.cpp )
target_link_libraries(BackgroundImage PRIVATE Qt::Widgets ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS BackgroundImage
MODULES ${VTK_LIBRARIES}
)
I don’t exactly understand what I am doing wrong. Is the InteractiveOff
function maybe called at the wrong spot, which means too early/late in the pipeline? Or is it something related to the vtkGenericOpenGLRenderWindow
instance?
Any help would be very welcome. Thanks in advance!