Draw an actor always on top of the secene.

Little context
I pick faces of polydata with a custom interactor style and want to display as a highlighted. To do this I create a temporary actor with different color, larger line width, reduce opacity on other actors etc. But the pick is not always clear. Currently I try these properties,

                pPickedActor->GetProperty()->SetDiffuseColor(1.0, 1.0, 0.0);
                pPickedActor->GetProperty()->SetDiffuse(1.0);
                pPickedActor->GetProperty()->SetSpecular(0.0);
                pPickedActor->GetProperty()->SetLineWidth(3.0);

Is it possible to draw this actor last or on top of all the other actors so that the picking is clearly visible?
Note : I cannot change the property of the entire actor as the cells of faces are subset of the actor.

Thanks!

On the mappers, you can set these properties to make one appear on top of another.

ActiveMapper->SetRelativeCoincidentTopologyLineOffsetParameters(0, -66000);
ActiveMapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(0, -66000);
ActiveMapper->SetRelativeCoincidentTopologyPointOffsetParameter(-66000);
LinesMapper->SetRelativeCoincidentTopologyLineOffsetParameters(-1, -1);
LinesMapper->SetRelativeCoincidentTopologyPolygonOffsetParameters(-1, -1);
LinesMapper->SetRelativeCoincidentTopologyPointOffsetParameter(-1);

Hello,

Alternativelly, you can try using two renderers and set one of them to be the topmost:

   m_rendererMainScene->SetLayer( 0 ); //the renderer of layer 0 has background and is rendered first.
   m_rendererForeground->SetLayer( 1 ); //layers greater than zero have no background and are rendered afterwards.

regards,

PC

1 Like

@Paulo_Carvalho Interesting suggestion. Could this be used to draw an opaque actor after a transparent one (breaking the usual order of rendering)?

Thanks for this! @Paulo_Carvalho

Code snippet for future users

vtkSmartPointer<vtkRenderer> pDefaultRenderer = vtkSmartPointer<vtkRenderer>::New();
pDefaultRenderer ->SetBackground(0.1, 0.2, 0.3);
pDefaultRenderer ->SetLayer(0);

// Add actors to be rendered on top in pvtkForgroundRenderer 
vtkSmartPointer<vtkRenderer> pvtkForgroundRenderer = vtkSmartPointer<vtkRenderer>::New();
pvtkForgroundRenderer->SetActiveCamera(pDefaultRenderer ->GetActiveCamera()); // Set same camera as default render
pvtkForgroundRenderer->SetLayer(1);

vtkSmartPointer<vtkRenderWindow>  pVtkRenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
pVtkRenderWindow->SetNumberOfLayers(2);

pVtkRenderWindow->AddRenderer(pDefaultRenderer);
pVtkRenderWindow->AddRenderer(pvtkForgroundRenderer);
pVtkRenderWindow->Render();
2 Likes

Yes, it can:

In the example above, the label actor is rendered with a foreground renderer. The pilars, containing translucent segments, are rendered in a background renderer. The white text is rendered after all the background renderer’s scene completes rendering, thus it appears unaffected by the alpha blending.

take care,

PC

1 Like