I’m working on a project where I can interact with different 3D models, one per vtkRenderer (a maximum of 4 vtkRenderers can be opened/loaded with models in the vtkRenderWindow, splitting the screen/RenderWindow viewport among all renderers).
I’m using a custom interactor style that allows me to select nodes of any model clicking with the right mouse button (removing the default functionality for that button). Selection works just fine. I also display (with a vtkActor2D) the name of that node’s ID right next to the selected node… and that’s where the problem is: this label is displayed only on half of my vtkRenderers.
Initially I only have 1 vtkRenderer, and can then add 1-3 more vtkRenderers to the same window. Regardless of the number of renderers loaded with models, my node labels only appear on the odd renderers (1st and 3rd, if there is a 3rd), whereas my even renderers (2nd and 4th) don’t display the labels.
The logic is the same for each View (container of vtkRenderer) and doesn’t seem like the fault is in my code, making me think it’s some unexpected behavior of VTK.
The same happens after removing a vtkRenderer: for instance, I may have 2 vtkRenderers, each with its own 3D model loaded. Only the first renderer would display the node ID labels. If I remove/delete the first renderer, the previously second renderer would then occupy the whole vtkRenderWindow, as it’s now the only vtkRenderer, and it would display the labels correctly.
The code related to the creation and addition of the vtkActor2D to the vtkRenderer is as follows, although I don’t think there’s any problem with it, as it works every time on the 1st and 3rd renderer.
// Extract indices using the seletion vtkExtractSelection extractSelection = vtkExtractSelection.New(); extractSelection.SetInputData(0, ids1.GetOutput()); extractSelection.SetInputData(1, selection); extractSelection.Update(); vtkPointSetToLabelHierarchy psH = vtkPointSetToLabelHierarchy.New(); psH.SetLabelArrayName("nodeids"); psH.SetInputConnection(extractSelection.GetOutputPort()); vtkLabelPlacementMapper lblMapper = vtkLabelPlacementMapper.New(); lblMapper.SetInputConnection(psH.GetOutputPort()); vtkActor2D lblActor = vtkActor2D.New(); lblActor = vtkActor2D.New(); lblActor.SetMapper(lblMapper); m_renderer.AddActor(lblActor);
Any help or insight would be highly appreciated.
Thanks a bunch in advance!