I’m using VTK-8.2.0 on ubuntu 18.04.5.
I’ve implemented rendering of VTK data with QtQuick via QQuickFramebufferObject, using the C++ approach described here; I subclass QQuickFramebufferObject (I call it QVtkItem) and QQuickFramebufferOject::Renderer (I call it QVtkRenderer). QVtkRenderer creates a VTK pipeline which loads a vtkPolyData object and communicates with a QVtkItem; the QVtkItem is specified in QML. But for some reason my code renders the VTK data reveresed and upside down. Here is a test case adapted from the VTK TextOrigin example. This case loads vtkPolyData from 3D text and maps it to a vtkFollower, and the original example displays it like this:
Here is the result of my software, where the same pipeline logic is implemented by my QVtkRenderer:
Here’s code from the VTK TextOrigin example:
int main(int, char*[])
{
vtkNew<vtkNamedColors> colors;
// Create the axes and the associated mapper and actor.
vtkNew<vtkAxes> axes;
axes->SetOrigin(0, 0, 0);
vtkNew<vtkPolyDataMapper> axesMapper;
axesMapper->SetInputConnection(axes->GetOutputPort());
vtkNew<vtkActor> axesActor;
axesActor->SetMapper(axesMapper);
// Create the 3D text and the associated mapper and follower (a type of
// actor). Position the text so it is displayed over the origin of the
// axes.
vtkNew<vtkVectorText> atext;
atext->SetText("Origin");
vtkNew<vtkPolyDataMapper> textMapper;
textMapper->SetInputConnection(atext->GetOutputPort());
vtkNew<vtkFollower> textActor;
textActor->SetMapper(textMapper);
textActor->SetScale(0.2, 0.2, 0.2);
textActor->AddPosition(0, -0.1, 0);
textActor->GetProperty()->SetColor(colors->GetColor3d("Peacock").GetData());
// Create the Renderer, RenderWindow, and RenderWindowInteractor.
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(640, 480);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow);
vtkNew<vtkInteractorStyleTrackballCamera> style;
interactor->SetInteractorStyle(style);
// Add the actors to the renderer.
renderer->AddActor(axesActor);
renderer->AddActor(textActor);
renderer->SetBackground(colors->GetColor3d("Silver").GetData());
// Zoom in closer.
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.6);
// Reset the clipping range of the camera; set the camera of the
// follower; render.
renderer->ResetCameraClippingRange();
textActor->SetCamera(renderer->GetActiveCamera());
interactor->Initialize();
renderWindow->SetWindowName("TextOrigin");
renderWindow->Render();
interactor->Start();
return EXIT_SUCCESS;
}
And here is the “equivalent” code from my QVtkRenderer:
bool QVtkRenderer::assembleTestPipeline(
vtkRenderer *renderer,
vtkGenericOpenGLRenderWindow *renderWindow,
vtkGenericRenderWindowInteractor *interactor,
PickerInteractorStyle *style) {
vtkNew<vtkNamedColors> colors;
// Create the axes and the associated mapper and actor.
vtkNew<vtkAxes> axes;
axes->SetOrigin(0, 0, 0);
vtkNew<vtkPolyDataMapper> axesMapper;
axesMapper->SetInputConnection(axes->GetOutputPort());
vtkNew<vtkActor> axesActor;
axesActor->SetMapper(axesMapper);
// Create the 3D text and the associated mapper and follower (a type of
// actor). Position the text so it is displayed over the origin of the
// axes.
vtkNew<vtkVectorText> atext;
atext->SetText("Origin");
vtkNew<vtkPolyDataMapper> textMapper;
textMapper->SetInputConnection(atext->GetOutputPort());
vtkNew<vtkFollower> textActor;
textActor->SetMapper(textMapper);
textActor->SetScale(0.2, 0.2, 0.2);
textActor->AddPosition(0, -0.1, 0);
textActor->GetProperty()->SetColor(colors->GetColor3d("Peacock").GetData());
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(640, 480);
interactor->SetRenderWindow(renderWindow);
interactor->SetInteractorStyle(style);
// Per QtVTK example
interactor->EnableRenderOff();
// Add the actors to the renderer.
renderer->AddActor(axesActor);
renderer->AddActor(textActor);
renderer->SetBackground(colors->GetColor3d("Silver").GetData());
// Zoom in closer.
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.6);
// Reset the clipping range of the camera; set the camera of the
// follower; render.
renderer->ResetCameraClippingRange();
textActor->SetCamera(renderer->GetActiveCamera());
// Initialize the OpenGL context for the renderer
renderWindow->OpenGLInitContext();
return true;
}
What can cause this? I’ve been trying to solve this for a while, with no luck yet. How can I debug this? Any suggestions are greatly appreciated!