next up previous contents
Next: Vizualisation of a function Up: LESSON on freefem and Previous: Read a Triangulation file

Display a Triangulation with gnuplot

We do not describe the public domain program gnuplot in details but show how to use it in this context.

For instance, if the file "ex.gnu" contains

0.0 0.0
0.0 0.1
0.1 0.05

0.1 0.05
0.0 0.0

then the command

gnuplot  
plot [-0.2,0,0.2][-0.2,0.2] "ex.gnu" w l
quit

will display in a separate window a rectangle. of length 0.1 and size 0.05. The plot is performed by drawing first a polygonal line made by the first 3 sides and then the last side is drawn as a segment.

More precisely, a blank line creates a "moveto" to the point of the next line; otherwise the next line is a "lineto".

The directive[-0.2,0.2]x[-0.2,0.2] indicates that we wish to display only whatever falls in this square. This is useful to make "zoom".

Obviously our triangulation files and our gnuplot files are different. Let us write a translator from the first to the second. This is very helpful to display a file created by freefem

void Triangulation::gnu(const char* filename) const
{
  ofstream f(filename);
  for(int i=0; i<nt; i++)
    {
       f << v[t[i].v[0]].x << "\t" << v[t[i].v[0]].y << endl 
         << v[t[i].v[1]].x << "\t" << v[t[i].v[1]].y << endl 
         << v[t[i].v[2]].x << "\t" << v[t[i].v[2]].y << endl 
         << v[t[i].v[0]].x << "\t" << v[t[i].v[0]].y << endl 
         <<endl;
    }   
  f.close();
}


remarque318
For a function the type "const" (at the end of its declaration) means that the function does not modify the fields of the class.

We mustn't forget also to add to the class definition the line

void Triangulation::gnu(const char* filename) const

Therefore the main function will be

void main()
{
  Triangulation g("micro.msh");
  g.gnu("micro.gnu");
}


remarque318
There is another public domain plotting program "plotmtv" which also reads gnuplot formats.


exer332
Write a program which reads a triangulation file in the format freefem and generate a file in the gnuplot format.


exer332


next up previous contents
Next: Vizualisation of a function Up: LESSON on freefem and Previous: Read a Triangulation file

Pironneau Olivier
Jeudi 12 mars 1998 16:06:41