You are here: Foswiki>Main/Cimec Web>MarioStorti>SomeVTKExamples (05 Sep 2014, MarioStorti)Edit Attach

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: 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:

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 manage 15 K 09 Jul 2009 - 18:29 UnknownUser Python VTK script for visualization of the elastic tube manage 4 K 06 Aug 2010 - 16:43 MarioStorti Script for animation of sorting algorithms manage 7 K 11 Nov 2009 - 22:54 UnknownUser Hanoi Tower problem solver with VTK visualization manage 4 K 13 Nov 2009 - 22:36 UnknownUser Pancake sorting algorithm with Python VTK manage 7 K 09 Jul 2009 - 19:12 UnknownUser VTK Python script for visualization of a movinc mesh with a plane cut
worm-data.tgztgz worm-data.tgz manage 36 K 07 Jan 2009 - 01:44 UnknownUser Data files for script
Topic revision: r15 - 05 Sep 2014, MarioStorti
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback