catenoid cube45 ellipsoid rounded-cube45 sphere composition composition2 ring torus Klette-Ellipsoid

A little introduction to volgen/volcompose source code
How to add a new figure

The first thing to know is that currently, the source IS the documentation. :-) But anyway I'll try to introduce you to the source code.

Volgen and volcompose share almost every file, in fact only their respective main differs (Volcompose uses a lex/yacc parser, volgen its own command-line parse algorithm).
You can add a new figure in three steps : Note that you can choose the skip step B or C, and even both but in that case you'll have to make you own main().

Step A

Each figure inherits at least an abstract class called Figure (see src/figure.h). You must override some pure virtual methods to draw the figure and to generate the signature.
There are also three more abstract class defined, that inherit Figure, and make your work easier if your figure can be drawn by cartesian equation, parametric equation or both.

The diagram below may help you to find the parent class you need.
( = 0 means that the class is abstract)

                   +------------+
                   | Figure = 0 |<--------------------------+-------------+
                   +------------+                           |             |
                   ^         ^                              |             |
                  /           \                             |             |
              (virtual)     (virtual)                       |             |   
                /               \                           |             |
               /                 \                          |             |
    +---------------------+      +----------------------+   |        +-------------+
    | CartesianFigure = 0 |      | ParametricFigure = 0 |   |        | RoundedCube |
    +---------------------+      +----------------------+   |        +-------------+
      ^           ^                 ^             ^         |
      |            \               /              |         |
      |             \             /               |     +---------+
      |              \           /                |     | Cube    |
      |    +----------------------------------+   |     +---------+
      |    | ParametricAndCartesianFigure = 0 |   |
      |    +----------------------------------+   |
      |                     ^                     |
      |                     |                     |
 +-----------------+        |                     |
 | KletteEllipsoid |        |                     |
 +-----------------+        |                     |
                            |                +------------+
                    +------------+           | Catenoid   |
                    | Ellipsoid  |           +------------+
                    +------------+
                            ^
                            |
                    +------------+
                    | Sphere     |
                    +------------+


With each unederlined base class, you can see one or more figure classes that are already in Volgen. These figures are good examples to make your own classes. Except the Ellipsoid class which is bit complex, the source files are short and easy to understand. I suggest you to copy the header and the .cc files of a figure and edit them for your needs (rename the files, the class and change the bodies of the methods).

Step B : add the figure to volgen

Almost all the work is made by the main of volgen (src/gen-main.cc) ; you just have to provide a function that creates your figure. If you read the file src/gen-main.cc, you'll see that all these functions (like makeEllipsoid(), makeCatenoid(), ...) look the same. They get and check the parameters passed on the commande line, create the figure, possibly change its draw method and return the volume drawn by this figure. I suggest you to copy a such function, paste it and make the changes you want. You'll have to add your function in the volFactory array at the beggining of the file if you want it to be recognized by the main().
If you're smart, you'll update the help message and the man file (in src/man1/volgen.1).

Step C : add the figure to volcompose

Sorry but I simply cannot explain you how bison and lex work. However, I will tell you what you need to copy and paste in the src/desc.yacc and src/desc.lex files.

In the lex file : add a line which looks like that near the section where there are all the figures :
"FigureName"	{ cols += strlen("FigureName"); return lex_figurename; }

In the yacc file :
If you search the string "Example" in the src/desc.yacc file you will find where you need to add code for your figure. This code will look like the example.
Don't forget to include the header of your new figure at the beggining of the file.


See also :

The Vol tools, volgen/volcompose.
For any question send email !

Valid HTML 4.0! Edited with vim