Tutorial > 3D Plotting > Lesson 3: Simple VTK Examples
  

Lesson 3: Simple VTK Examples
Here are some examples of using the PV‑WAVE VTK Integration routines that show how VTK can be accessed in a manner very similar to existing PV‑WAVE graphic routines. This lesson demonstrates the following:
* Create a Surface Plot
* Display a Cube With a Different Color at Each Vertex
* Adding an Annotation to a Scene
* Debugging VTK
Create a Surface Plot
Use the following command to create a surface plot:
vtkSURFACE, DIST(10), Shades='slate_blue'
This one command automatically invokes vtkINIT and vtkWINDOW to open a window. Since only one color was specified (in this case using a named color), the entire surface is shaded using that color.
 
note
In VTK, X, Y and Z scaling are always identical, therefore you may need to scale your raw data in order to change the scaling of one direction. For example when using vtkSURFACE multiply your Z array by a scale factor so that the height of the surface is appropriate.
Display a Cube With a Different Color at Each Vertex
This example shows how we can use a vertex/polygon list to create a plot in much the same way as with POLYSHADE. Since the colors we specify are short integers, the colors used are from the current PV‑WAVE colortable, which was loaded using TEK_COLOR in this case.
vertex_list = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], $
[1.0, 1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], $
[1.0, 0.0, 1.0], [1.0, 1.0, 1.0], [0.0, 1.0, 1.0]]
polygon_list = [4, 0, 1, 2, 3, 4, 4, 5, 6, 7, $
4, 0, 1, 5, 4, 4, 2, 3, 7, 6, 4, 0, 4, 7, 3, 4, 1, 2, 6, 5]
TEK_COLOR
vertex_colors = [2,3,4,5,6,7,8,9]
vtkPOLYSHADE, vertex_list, polygon_list, Color=vertex_colors
Adding an Annotation to a Scene
To add annotations to a scene in VTK, do the following:
1. Draw the scene:
vtkWINDOW, /Free, Background='000077'XL, /NoRender
vtkSURFACE, HANNING(20,20)*20.0, Shades=[1.0, 0.0, 0.0, 0.5]
2. Add your annotations:
vtkTEXT, 'Transparent Surface', Position=[10, 10, 20], $
/Follow, Color='green'
3. Display the results:
vtkRENDERWINDOW
 
note
Use /NoRender to suppress rendering until everything has been added to the scene (the surface and text annotation). Also note that we specify colors in three different ways:
*‘000077’XL—A long integer specifying a dark blue color
*[1.0, 0.0, 0.0, 0.5]—A four element array specifying the color red with a 50% transparency
*'green'—A string specifying a named color, as defined in vtkcolornames.pro.
Debugging VTK
In this example we explicitly call vtkINIT so that we can turn on logging of all Tcl commands. We also manage the window creation and deletion and rendering ourselves.
1. Enter the following to draw a scatter plot while logging the Tcl commands:
vtkINIT, /Print
vtkWINDOW, /NoRender
vtkSCATTER, RANDOMN(seed, 3, 100), Color='blue'
vtkRENDERWINDOW
HAK, /Mesg
2. Enter the following to delete the contents and close the window:
vtkWDELETE
vtkCLOSE
More examples are provided with the PV‑WAVE distribution.
For additional examples see the procedures in the directory
<RW_DIR>/vtk-3_2/demo (where <RW_DIR> is your PV-WAVE installation directory).

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.