Created
September 7, 2018 10:32
-
-
Save kor01/8aa982f59d39e43438c0fd3abca8232f to your computer and use it in GitHub Desktop.
[vtk_python] vtk python tutorial #vtk #opengl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vtk | |
# The colors module defines various useful colors. | |
from vtk.util.colors import tomato | |
cylinder = vtk.vtkCylinderSource() | |
# the side of the cylinder is made up with 100 edges polygon | |
cylinder.SetResolution(100) | |
# The mapper is responsible for pushing the geometry into the graphics | |
# library. It may also do color mapping, if scalars or other | |
# attributes are defined. | |
cylinderMapper = vtk.vtkPolyDataMapper() | |
cylinderMapper.SetInputConnection(cylinder.GetOutputPort()) | |
# The actor is a grouping mechanism: besides the geometry (mapper), it | |
# also has a property, transformation matrix, and/or texture map. | |
# Here we set its color and rotate it -22.5 degrees. | |
cylinderActor = vtk.vtkActor() | |
cylinderActor.SetMapper(cylinderMapper) | |
cylinderActor.GetProperty().SetColor(tomato) | |
cylinderActor.RotateX(30.0) | |
cylinderActor.RotateY(-45.0) | |
# Create the graphics structure. The renderer renders into the render | |
# window. The render window interactor captures mouse events and will | |
# perform appropriate camera or actor manipulation depending on the | |
# nature of the events. | |
ren = vtk.vtkRenderer() | |
renWin = vtk.vtkRenderWindow() | |
renWin.AddRenderer(ren) | |
iren = vtk.vtkRenderWindowInteractor() | |
iren.SetRenderWindow(renWin) | |
# Add the actors to the renderer, set the background and size | |
ren.AddActor(cylinderActor) | |
ren.SetBackground(0.1, 0.2, 0.4) | |
renWin.SetSize(200, 200) | |
# This allows the interactor to initalize itself. It has to be | |
# called before an event loop. | |
iren.Initialize() | |
# We'll zoom in a little by accessing the camera and invoking a "Zoom" | |
# method on it. | |
ren.ResetCamera() | |
ren.GetActiveCamera().Zoom(1.5) | |
renWin.Render() | |
# Start the event loop. | |
iren.Start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment