QVKTWdiget and Interactors

I’ve been working for hours trying to get the orientation marker from the OrientationMarkerWidget example to work with the QVTKWidget in the SimpleView example – with no success. I’ve looked at a number of the the other VTK examples for both interactors and Qt and I can’t find anything that seems to be of much help.

I found a comment on the web from something on public.kitware.com that says that the qvtkwidget is suppose to handle the interactor. So, at this point I’m totally confused.

Can someone explain how to set / get the interactor for the qvtkwidget and how to set it for the orientation marker? I gather from what I’ve seen so far that the order of operations for this is important w.r.t. initializing and starting the interactor.

Okay. So, a number of people viewing, but no response.

I’ve be beating my head against the wall on this over days. No web searches yield any working examples.

Here is how I’ve modified the SimpleView code to add the orientation marker from the DisplayCoordinateAxes example.

// Actor in scene
vtkNew actor;
actor->SetMapper(mapper);

// VTK Renderer
vtkNew ren;
ren->SetBackground(0.8, 0.8, 0.8);

// Add Actor to renderer
ren->AddActor(actor);

// VTK/Qt wedded
vtkNew renderWindow;
this->ui->qvtkWidget->setRenderWindow(renderWindow);
this->ui->qvtkWidget->renderWindow()->AddRenderer(ren);

vtkRenderWindowInteractor *iren = renderWindow->GetInteractor();

vtkNew axes;

vtkNew widget;
double rgba[4]{0.0, 0.0, 0.0, 0.0};
colors->GetColor(“Carrot”, rgba);
widget->SetOutlineColor(rgba[0], rgba[1], rgba[2]);
widget->SetOrientationMarker(axes);
widget->SetViewport(0.0, 0.0, 0.4, 0.4);

widget->SetInteractor(iren);
widget->SetEnabled(1);
widget->InteractiveOn();

ren->ResetCamera();
renderWindow->Render();


This program executes, but the axes actor is never displayed and there are no execution error messages.

Does anyone have any idea why this doesn’t work? In theory, this should be fairly straight forward.

I’m going to answer my own query, just in case someone in the future encounters the same problem. For novice users just starting out on the vtk leaning curve, this may be helpful.

The issue is one of scope.

The examples on the vtk.org website are a nice introduction to features, but one must remember that the cxx code that is displayed is really just c code with one main function. No one writes anything but demonstration code that way. Well, at least no one who is a serious developer. :slightly_smiling_face:

When I moved the vtkNew<vtkAxesActor> axes declarations out of the class function to the class header file – that is moved them from being local to being owned by the class – it all worked.