In [1]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/2014_Session_4.png')
Out[1]:

Introduction to visualization

During this laboratory session you will acquaint with basic capabilities of the Visualization Toolkit (VTK) library. The VTK is an open-source, freely available software system for 3D computer graphics, image processing and visualization. VTK is cross-platform and runs on Linux, Windows, Mac and Unix platforms.

Rendering

Process of generation of 2D and 3D images using the computers is called rendering. At first, a data are transformed into a graphical form and then rendered. Physical generation of an image is based on the reflection of light rays from the surface of objects. The object will be visible only when the reflected rays hit the eye. In reality this may work because light sources are generating enormous amount of light. Simulation of this process is almost impossible to implement, so we use other rendering techniques that can be divided into two types:

During the image-order rendering each pixel of object is painted separately (e.g. ray-tracing, where each ray of light is traced separately). In the object-order thype the whole objects (actors) are rendered in the scene at the same time (simultaneously) in a certain order: left to right, top to bottom. We should also pay attention to the objects that don't have surface, such as clouds or fog. In this case we have to consider the changing light properties inside of this objects.

We can distinguish 3 primary rendering process components: sources of light, rendered objects (that we referred to as actors) and camera. The simplest type of light sources is the infinitely distant, point light source that emits parallel light rays in all directions.

The way that the 3D scene can be seen depends on: camera:

There are two projection methods:

In orthographic method rays of light entering the camera are parallel to the projection vector. In the second case light rays go through a common point. Front clipping plane is used to eliminate objects that are too close to the camera and back clipping plane to eliminate to far objects.

An actor to be shown in scene has to be modeled. In practice, objects are represented by combination of primitives forms like points, lines, polygons, curves and splines of various forms.

There are seven basic objects that we use to render a scene. Documentation of all objects and classes used in vtk library is available on the webpage: http://www.vtk.org/doc/release/6.1/html/classes.html.

  1. vtkRenderWindow — manages a window on the display device; it is possible to draw one or more renderers into an instance of vtkRenderWindow.
  2. vtkRenderer — coordinates the rendering process involving lights, cameras, and actors.
  3. vtkLight — a source of light to illuminate the scene.
  4. vtkCamera — defines the view position, focal point and other viewing properties of the scene.
  5. vtkActor — represents an object rendered in the scene, including its properties (color, shading type, etc.) and position in the words coordinate system. (Note: vtkActor is a subclass of vktProp. vtkProp is a more general form of actor that includes annotation and 2D drawing classes.)
  6. vtkProperty — defines the appearance properties of an actor including color, transparency, and lighting properties such as specular and diffuse. Also representational properties like wireframe and solid surface.
  7. vtkMapper — the geometric representation for an actor. More than one actor may refer to the same mapper.

Tasks

  1. Run script cone.py with a cone model and added a light source. Change roll and azimuth parameters of camera.
In [2]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_cone.png')
Out[2]:
  1. Run scrypt triangle1.py that draws triangle on the black background. Pay attention to used pipeline of the basic vtk objects in the graphic model.
In [3]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_triangle1.png')
Out[3]:
  1. Run script triangle2.py Notice how to set colors to each triangle node.
In [5]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_triangle2.png')
Out[5]:
  1. Draw a sphere, use vtkSphereSource class (script sphere1.py) Change some of the parameters:
In [6]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_sphere.png')
Out[6]:
  1. Change some of the surface properties of the sphere with the use of GetProperty() object:
  1. With the use of vtkCylinderSource object draw cylinder. Use additional vtkPolyDataMapper and vtkActor for this purpose (script sphere1_and_cylinder.py)
In [7]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_sphere_and_cylinder.png')
Out[7]:
  1. It is possible to divide RenderWindow among few Renderers (script renderers.py).
In [8]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_renderers.png')
Out[8]:
  1. VTK has implemented many components and methods to image processing. To read and display 2D image it is enough to run code as in the scirpt vtk_image_2D.py. Check the implemented functionality of mouse buttons.
In [9]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_blood1.png')
Out[9]:
  1. It is easy to warp image in the direction perpendicular to the image plane using the visualization filter vtkWartScalr. Test few values for SetScaleFactor (script vtk_image_2D_warp_image).
In [11]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_warp_image.png')
Out[11]:
  1. Iso-surface extraction is possible with the use of vtkMarchingCubes algorithm (script marching_cubes_3D.py). Play with SetValue(...) method in range (10–255).
In [12]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_marching_cubes.png')
Out[12]:
  1. To bind vtk and wxWidget run scirpy vtk_wx.py. Modify this script to change e.g. rotation, light properties.
In [1]:
from IPython.display import Image
Image(filename='Figs_ipandcg_2014/4_vtk_wx.png')
Out[1]: