If you’re using python here’s a great for how the rendering pipeline works:
https://kitware.github.io/vtk-examples/site/Python/Rendering/DiffuseSpheres/
If you’re using C++, here’s the same example:
https://kitware.github.io/vtk-examples/site/Cxx/Rendering/AmbientSpheres/
Here’s another C++ example, but this one uses multiple actors for multiple datasets:
https://kitware.github.io/vtk-examples/site/Cxx/Visualization/MultipleActors/
The general concept is that you use the vtkActor class to group together parts for rendering, and then initialize the render.
Here’s my best Python example of what it seems you’re trying to do:
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersSources import vtkCylinderSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkLight,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer
)
from time import sleep
colors = vtkNamedColors()
colors.SetColor('background', [26, 51, 102, 255])
# This represents the "first part" you mentioned
first_part = vtkCylinderSource()
first_mapper = vtkPolyDataMapper()
first_mapper.SetInputConnection(first_part.GetOutputPort())
first_actor = vtkActor()
first_actor.SetMapper(first_mapper)
first_actor.GetProperty().SetColor(colors.GetColor3d('red'))
# This is the render window we make (we only make one)
renderer = vtkRenderer()
render_window = vtkRenderWindow()
render_window.AddRenderer(renderer)
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow(render_window)
# Here's where we add the "first part" to the view
renderer.AddActor(first_actor)
# All of this section is just making the render window look pretty
renderer.SetBackground(colors.GetColor3d('background'))
render_window.SetSize(640, 480) # size of render window in pixels
render_window.SetWindowName("Multi Step Render")
light = vtkLight()
light.SetFocalPoint(1.875, 0.6125, 0)
light.SetPosition(0.875, 1.6125, 1)
renderer.AddLight(light)
renderer.GetActiveCamera().SetFocalPoint(3,0,0)
renderer.GetActiveCamera().SetPosition(3,0,10)
renderer.GetActiveCamera().SetViewUp(0,1,0)
interactor.Initialize()
render_window.Render()
color_selection = ['blue', 'green', 'purple', 'yellow']
for i in range(4):
sleep(0.5) # this is just for illustration
# These represents the other parts you mentioned
nth_part = vtkCylinderSource()
nth_part.SetCenter((i + 1) * 1.5, 0, 0)
nth_mapper = vtkPolyDataMapper()
nth_mapper.SetInputConnection(nth_part.GetOutputPort())
nth_actor = vtkActor()
nth_actor.SetMapper(nth_mapper)
nth_actor.GetProperty().SetColor(colors.GetColor3d(color_selection[i]))
# This adds the nth part
renderer.AddActor(nth_actor)
render_window.Render()
interactor.Start()
Essentially, just add another actor to the renderer, and call Render() again.
P.S. If you’re newer to vtk and have questions, the vtk-examples are probably your best place to start looking; they really are good ways of learning your way around the library.