Visualization Toolkit (VTK) Installation and usage: Difference between revisions
(Created page with "Main Page -> Documentation -> Visualization Toolkit (VTK) Installation and usage == Installation == === Source code === The Gate github repository can be cloned l...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Main Page]] -> [[Documentation]] -> [[Visualization Toolkit (VTK) Installation and usage]] | [[Main Page]] -> [[Documentation]] -> [[Visualization Toolkit (VTK) Installation and usage]] | ||
== Installation == | == Installation == | ||
=== Package === | |||
Most packages are available in the package install systems, e.g. on Ubuntu | |||
`vtk6`, `vtk6-examples`, `libvtk6.2`, `libvtk6-dev`, `vtkdata` | |||
Downloads are also available from the [https://www.vtk.org/download/ VTK home page]. | |||
=== Source code === | === Source code === | ||
Line 42: | Line 47: | ||
=== Interactive Python === | === Interactive Python === | ||
Run either `python` or `ipython` without arguments to come to the prompt. `ipython` can be recommended for interactive sessions. | Run either `python` or `ipython` without arguments to come to the prompt. `ipython` can be recommended for interactive sessions. | ||
`ipython` keeps a nice history of the commands, try `history`, option `-g` displays also entries from previous sessions. | |||
Example: run command sequence in interactive mode (simple copy & paste) | |||
source = vtk.vtkPlaneSource() | |||
mapper = vtk.vtkPolyDataMapper() | |||
mapper.SetInputConnection(source.GetOutputPort()) | |||
actor = vtk.vtkActor() | |||
actor.SetMapper(mapper) | |||
renderer = vtk.vtkRenderer() | |||
renderer.SetBackground(0.0, 0.0, 0.0) | |||
renderer.AddActor(actor) | |||
render_window = vtk.vtkRenderWindow() | |||
render_window.SetWindowName("Simple VTK scene") | |||
render_window.SetSize(400, 400) | |||
render_window.AddRenderer(renderer) | |||
# Create an interactor | |||
interactor = vtk.vtkRenderWindowInteractor() | |||
interactor.SetRenderWindow(render_window) | |||
# Initialize the interactor and start the | |||
# rendering loop | |||
interactor.Initialize() | |||
render_window.Render() | |||
interactor.Start() |
Latest revision as of 14:44, 27 October 2017
Main Page -> Documentation -> Visualization Toolkit (VTK) Installation and usage
Installation
Package
Most packages are available in the package install systems, e.g. on Ubuntu `vtk6`, `vtk6-examples`, `libvtk6.2`, `libvtk6-dev`, `vtkdata`
Downloads are also available from the VTK home page.
Source code
The Gate github repository can be cloned like that
https://github.com/Kitware/VTK
This will bring you to the master branch, tags can be checked out like this
git checkout v8.0.1
Compilation
Make a build directory and execute in this directory `cmake <SOURCEDIR>`. Some interesting switches can be added with `-DSWITCH`
- `CMAKE_INSTALL_PREFIX`
- `VTK_WRAP_TCL` wrapper code for TCL
- `VTK_WRAP_PYTHON` wrapper code for Python
- `VTK_FORBID_DOWNLOADS` skip downloading of test data
- `VTK_RENDERING_BACKEND` default OpenGL2
- `BUILD_EXAMPLES` set to `ON` if examples should be built
Example session
mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=../install -DVTK_WRAP_PYTHON=ON -DVTK_FORBID_DOWNLOADS=ON make install
Running
Make sure that the `bin` and `lib` directories of the installation are part of `PATH` and `LD_LIBRARY_PATH` respectively, e.g.
export PATH=/the_installation_directory/bin:$PATH export LD_LIBRARY_PATH=/the_installation_directory/lib:$LD_LIBRARY_PATH
TCL bindings
Start `vtk` and get the interactive prompt. Or run one script of the examples directly, e.g.
vtk Examples/Tutorial/Step1/Tcl/Cone.tcl
Python bindings
Set `PYTHONPATH` to enable Python to find the available modules
PYTHONPATH=$VTK_install/lib/pythonx.x/site-packages
Run a script directly
python Examples/Tutorial/Step1/Python/Cone.py
Interactive Python
Run either `python` or `ipython` without arguments to come to the prompt. `ipython` can be recommended for interactive sessions.
`ipython` keeps a nice history of the commands, try `history`, option `-g` displays also entries from previous sessions.
Example: run command sequence in interactive mode (simple copy & paste)
source = vtk.vtkPlaneSource() mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(source.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) renderer = vtk.vtkRenderer() renderer.SetBackground(0.0, 0.0, 0.0) renderer.AddActor(actor) render_window = vtk.vtkRenderWindow() render_window.SetWindowName("Simple VTK scene") render_window.SetSize(400, 400) render_window.AddRenderer(renderer) # Create an interactor interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(render_window) # Initialize the interactor and start the # rendering loop interactor.Initialize() render_window.Render() interactor.Start()