0

I have just built VTK from source with Qt support. One of the things I'm interested is the PBR (physically based rendering), which was introduced in v9.0.

I would like to interact with various parameters such as metallic, color, roughness etc. components using QScrollBar and other Qt widgets.

There are multiple VTK examples available here. However none show the behaviour I'm looking for but instead concentrate on just rendering things on the screen without any interaction outside of what the widget offers out of the box.

Give an instance of vtkActor (for example a sphere) I would like to access SetMetallic(double), SetRoughness(double) etc. (through vtkActor::GetProperty()) and connect those to let's say QScrollBar::valueChanged(int) (yes, I'm aware that it emits int) to allow changing the properties of the surface of the object.

My issue is mostly on how to access the actors through the VTK Qt widget. Of course due to my lack of knowledge in VTK it is also possible that this question is a more general in nature namely how to access the actors in any type of GUI environment, where VTK is integrated into.

UPDATE:

Here is what I have so far:

vtkWidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActors()->GetNextActor()->GetProperty()->SetColor(0.7, 0.1, 0.4);

For a given instance of QVTKOpenGLNativeWidget called vtkWidget I retrieve the render window, then for example retrieve the first renderer (in case there are more a slightly different approach is required). From there a renderer provides me with all the actors. If I iterate (using GetNextActor() in a loop that checks if there are any actors left in the collection) I can access an actor. Here the problem is that I am not sure how to distinguish between several actors but this is a purely VTK-related question. Once I have the actor I can get the property and set it accordingly (in the example above I have manually set the Color property of the actor).

Looking at this I am seeing 5-6 function calls, which sounds like a lot of work so the interesting question is if there is a more direct approach.

rbaleksandar
  • 8,713
  • 7
  • 76
  • 161
  • The GUI examples bundled with the VTK source shows examples, where Qt buttons are used for modifying a VTK pipeline. You can simple change a property inside a Qt slot.. – Jens Munk Aug 13 '21 at 15:17
  • My problem is how to get to the `vtkActor` through the VTK Qt widget. While I do have experience with Qt that's not the case with VTK. What I was hoping for is that the widget or the associated rendering window will give me a collection of all actors that are present and thus give me an easy access to a specific actor. – rbaleksandar Aug 14 '21 at 13:22
  • It doesn't work this way. You add an actor to a renderer of a render window and you need to keep track of the actors yourself. The vtkRenderWindow you can get from the QVTOpenGLNativeWidget – Jens Munk Aug 15 '21 at 14:27
  • @JensMunk Hm, so I guess retrieving all the actors is just when you want to apply some global change? – rbaleksandar Aug 15 '21 at 17:24
  • You can keep your actors as members variables using `vtkSmartPointer` and add and remove them from the renderer(s), apply properties etc. – Jens Munk Aug 15 '21 at 20:38

0 Answers0