You are here: TWiki> Cimec Web>MarioStorti>SomeVTKExamples (2014-09-05, MarioStorti)

Some VTK Examples

Why use VTK?

I have been a fan of OpenDX since long time ago. (See some videos in PETScFEMResults page.) However it seems that OpenDX is no more being actively developed so I started playing with VTK. My feeling is that VTK is great, and also that is very programmable. I started using ParaView which is also great, but for creating good videos I think that one has to do it with programming. I started coding in C++ but I found that many examples are in Python so that I started to code in Python.

A first example: Walking worm

This example is interesting because it has some features I'm interested in: deformable meshes, flying cameras. The files needed for running the scripts can be found in the attachment below (worm-data.tgz). The script is largely commented and self explained.

FEM simulation of elastic tube with large displacement formulation

This video shows a Finite Element simulation of the deformation of a hollow tube of a soft material with a large displacement formulation. The VTK Python script is available here. Details of the physical and numerical problem are available in PETScFEMElastLDResults.

From the point of view of VTK the example features are:

  • Moving mesh of an elastic structure
  • Visualization in colormap of the deformation on the skin with colormap
  • Rotating camera
  • Particle trail at the upper tube end for visualization of the trajectory.

Finite element mesh movement (relocation of nodes) for subsequent fluid structure interaction

We show here the relocation of nodes for a CFD computation with PETSc-FEM. The geometry is the well known Ahmed body for a subsequent fluid-structure computation. We show the intersection of the FEM tetra mesh with horizontal planes at the center of the body and also at mid distance between the base of the body and the floor (the spacing between the base of the body and the floor is 5cm). The relocation is shown for a yaw movement of 30 degrees and a shift in the transverse direction of +/-0.6 (the length of the body is 1.044). The mesh movement is done with the technique described here.

The VTK Python script is available here. The From the point of view of VTK the example features are:

  • A cut of a moving mesh
  • The surface of the body is shown in transparency
  • A rotating camera with varying shot distance

The Tower of Hanoi Problem

The Towers of Hanoi problems consists in moving n discs from peg A to peg B using peg C as auxiliary, according to the following rules

  • Only one disc is moved at a time and,
  • A larger disc can never be above a smaller one.

The Python script is available here: hanoi.py. For further explanation you can look at the slides that we present in the Algorithms and Data Structures course that we give at FICH-UNL.

Pancake sorting

Pancake sorting is a variation of the sorting problem in which the only allowed operation is to reverse the elements of some prefix of the sequence. Unlike a traditional sorting algorithm, which attempts to sort with the least comparisons possible, the goal is to sort the sequence in as few reversals as possible. This operation can be visualized by thinking of a stack of pancakes in which one is allowed to take the top k pancakes and flip them.

Here we perform the visualization of a simple pancake sorting algorithm with VTK. The algorithm starts by flipping the top pancakes from the largest one to the top, so that the largest pancake goes to the top. Then, sorting the whole pancake stack we bring the largest pancake to the bottom. The subsequent move brings the second largest to the second position, and so on, recursively.

The VTK Python script is available here: pancake.py

For the burnt pancake problem the algorithm is described here.

Comparison of bubble-sort and quick-sort

Comparison of bubble sort (up) and quicksort algorithms (down) for sorting 30 items. The color represents the value of the item, so that once they are ordered they should be ranging from blue to red. Both algorithms are studied in basic computer science courses, here they are presented rather as an example of programming with Python-VTK. The python script is available here

Topic attachments
I Attachment Action Size Date Who Comment
txttxt animate.py.txt manage 15.0 K 2009-07-09 - 18:29 TWikiGuest Python VTK script for visualization of the elastic tube
txttxt animstb2.py.txt manage 4.3 K 2010-08-06 - 16:43 MarioStorti Script for animation of sorting algorithms
txttxt hanoi.py.txt manage 7.4 K 2009-11-11 - 22:54 TWikiGuest Hanoi Tower problem solver with VTK visualization
txttxt pancake.py.txt manage 4.9 K 2009-11-13 - 22:36 TWikiGuest Pancake sorting algorithm with Python VTK
txttxt viz.py.txt manage 7.9 K 2009-07-09 - 19:12 TWikiGuest VTK Python script for visualization of a movinc mesh with a plane cut
ziptgz worm-data.tgz manage 36.9 K 2009-01-07 - 01:44 TWikiGuest Data files for script worm.py
Topic revision: r15 - 2014-09-05 - 00:02:59 - MarioStorti
 

TWIKI.NET
This site is powered by the TWiki collaboration platformCopyright � by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback