## surfaces surfaces — Supports loading of .surf files and drawing of surfaces through OpenGL. |

## Synopsis

    #define             ISOSURFACES_PROPERTY_POTENTIAL
    typedef             SurfaceResource;
    struct              SurfacesOrder_struct;
    typedef             SurfacesOrder;
    struct              Surfaces_struct;
    typedef             Surfaces;

    Surfaces*           isosurfacesNew                      (int bufferSize);
    void                isosurfacesAllocate                 (Surfaces *surf,
                                                             int nsurf,
                                                             int npolys,
                                                             int npoints);
    void                isosurfacesFree                     (Surfaces *surf);
    void                isosurfacesFree_resource            (SurfaceResource *res);
    gboolean            isosurfacesHide                     (Surfaces *surf,
                                                             Plane **planes);
    gboolean            isosurfacesRemove                   (Surfaces *surf,
                                                             int idSurf);
    void                isosurfacesDuplicate                (int totalList,
                                                             int simpleBlockList,
                                                             VisuData *dataObj,
                                                             gboolean reorder);
    gboolean            isosurfacesLoad_file                (const char *file,
                                                             Surfaces **surf,
                                                             GError **error);
    void                isosurfacesDraw_surfaces            (int openGLId,
                                                             Surfaces *surf[],
                                                             SurfacesOrder *order);
    void                isosurfacesSet_box                  (Surfaces *surf,
                                                             double box[6]);
    void                isosurfacesCopy_resource            (SurfaceResource *res,
                                                             SurfaceResource *res_old);
    void                isosurfacesAddSurfaces              (Surfaces *surf,
                                                             int nsurf,
                                                             int npolys,
                                                             int npoints);
    void                isosurfacesResourcesInit            ();

    void                isoSurfacesSet_fitToBox             (VisuData *data,
                                                             Surfaces *surf);
    void                isosurfacesSet_showAll              (Surfaces *surf,
                                                             gboolean show);
    void                isosurfacesSet_surfaceResource      (Surfaces *surf,
                                                             int surf_index,
                                                             SurfaceResource *res);
    gboolean            isosurfacesSet_drawIntra            (gboolean status);

    double*             isosurfacesGet_box                  (Surfaces *surf);
    int                 isosurfacesGet_nbSurfaces           (Surfaces *surf);
    int                 isosurfacesGet_surfaceId            (Surfaces *surf,
                                                             int i);
    int                 isosurfacesGet_surfacePosition      (Surfaces *surf,
                                                             int id);
    gboolean            isosurfacesGet_surfaceRendered      (Surfaces *surf,
                                                             int surf_index);
    SurfaceResource*    isosurfacesGet_surfaceResource      (Surfaces *surf,
                                                             int surf_index);
    const gchar*        isosurfacesGet_surfaceName          (Surfaces *surf,
                                                             int surf_index);
    int*                isosurfacesGet_surfaceSortedById    (Surfaces *surf);
    SurfaceResource*    isosurfacesGet_resourceFromName     (const gchar *surf_name,
                                                             gboolean *nw);
    int                 isosurfacesGet_newId                (Surfaces *surf);
    gboolean            isosurfacesGet_drawIntra            ();

    float*              isosurfacesGet_floatProperty        (Surfaces *surf,
                                                             const gchar *name);
    float*              isosurfacesAdd_floatProperty        (Surfaces *surf,
                                                             const gchar *name);
    gboolean            isosurfacesGet_floatPropertyValue   (Surfaces *surf,
                                                             int idSurf,
                                                             const gchar *name,
                                                             float *value);

    SurfacesOrder*      isosurfacesOrder_new                ();
    void                isosurfacesOrder_free               (SurfacesOrder *order);
    void                isosurfacesOrder_polygons           (SurfacesOrder *order,
                                                             Surfaces *surf[]);

    #define             VISU_ERROR_ISOSURFACES
    void                isosurfacesInit                     ();
    void                isosurfacesCheck_consistency        (Surfaces *surf);
    GQuark              isosurfacesGet_quark                ();

## Description

Originally written by Luc Billard for his Visualize program. This module allows loading of .surf files to draw scalar fields on top of the current display scene. .surf files are text files which specs are the following :

- 1st line is arbitrary

- 2nd line must contain 3 real (float) values: dxx dyx dyy

- 3rd line must contain 3 real (float) values: dzx dzy dzz

- 4th line must contain 3 positive integers which represents respectively the number of surfaces, the total number of polys, and the total number of points

- Then, for each of these surfaces :

  - next line must contain the name of the surface : it is a string which should match the pattern surface_*

  - next line must contain 2 positive integer values: the number of polys (num_polys) and the number of points (num_points) used by the surface

  - each of the following num_polys lines must match the pattern [n i_1 i_2 i_3 ... i_n] where n is the number of vertices in the poly (n >= 3) and [i_1 i_2 i_3 ... i_n] are the numbering of these vertices (vertices numbered from 1 to num_points)

  - each of the following num_points lines must contain 6 real values for the successive (1 to num_points) points : [x y z nx ny nz], where x y z are the coordinates of the point and nx ny nz are the coordinates of the unit normal at the point

It is the responsibility of the user to guarantee that dxx, dyx, dyy, dzx, dzy, dzz match the one currently loaded in V_Sim's current context. Though if you use panelSurfaces you can ask to resize the surfaces so that they fit in the current loaded box.

## Details

### ISOSURFACES_PROPERTY_POTENTIAL

    #define ISOSURFACES_PROPERTY_POTENTIAL "potential_values"

Flag used in an ASCII surf file to give informations on the value the surface is built from.

### SurfaceResource

    typedef struct SurfaceResource_struct SurfaceResource;

Short name to adress SurfaceResource_struct objects.

### struct SurfacesOrder_struct

    struct SurfacesOrder_struct;

An opaque structure to store the order of drawn polygons when surfaces are involved.

### SurfacesOrder

    typedef struct SurfacesOrder_struct SurfacesOrder;

Short name to adress SurfacesOrder_struct objects.

### struct Surfaces_struct

    struct Surfaces_struct;

This structure stores surfaces. Several surfaces are stored in a single structure for improved performences.

### Surfaces

    typedef struct Surfaces_struct Surfaces;

Short name to adress Surfaces_struct objects.

### isosurfacesNew ()

    Surfaces*           isosurfacesNew                      (int bufferSize);

Create a new (with unallocated internal arrays) structure to store surfaces. The buffer size is used to store other values than the position and the normal on each point.

`bufferSize` : | an integer.
Returns : | a newly allocated Surfaces structure.

### isosurfacesAllocate ()

    void                isosurfacesAllocate                 (Surfaces *surf,
                                                             int nsurf,
                                                             int npolys,
                                                             int npoints);

Allocate internal arrays to store surfaces having the given description.

`surf` : | a Surfaces structure ;
`nsurf` : | the number of surfaces to store ;
`npolys` : | the number of polygons (in total) ;
`npoints` : | the total number of vertices.

### isosurfacesFree ()

    void                isosurfacesFree                     (Surfaces *surf);

Free all memory associated to the given surfaces.

`surf` : | a Surfaces structure.

### isosurfacesFree_resource ()

    void                isosurfacesFree_resource            (SurfaceResource *res);

This method frees the memory used by the given resource.

`res` : | an allocated SurfaceResource object to be freed.

### isosurfacesHide ()

    gboolean            isosurfacesHide                     (Surfaces *surf,
                                                             Plane **planes);

Change the visibility of polygons stored in `surf`, following the masking scheme defined by the given list of `planes` (see Plane).

`surf` : | a Surfaces object ;
`planes` : | an array of planes (NULL terminated).
Returns : | TRUE if the surfaces should be rebuilt (see `isosurfacesDraw_surfaces()`).

### isosurfacesRemove ()

    gboolean            isosurfacesRemove                   (Surfaces *surf,
                                                             int idSurf);

Remove from memory all polygons from the given surface.

`surf` : | a Surfaces object ;
`idSurf` : | the id of the surf to remove.
Returns : | TRUE if the surface list is reduced to zero (and `surf` to be freed).

### isosurfacesDuplicate ()

    void                isosurfacesDuplicate                (int totalList,
                                                             int simpleBlockList,
                                                             VisuData *dataObj,
                                                             gboolean reorder);

Duplicate the list `simpleBlockList` using the extension of the given `dataObj`.

`totalList` : | an OpenGL identifier for the global list to create ;
`simpleBlockList` : | an OpenGL identifier for the list with the surfaces in the primitive cell ;
`dataObj` : | the corresponding VisuData object ;
`reorder` : | if TRUE the blocks are drawn from back to front.

### isosurfacesLoad_file ()

    gboolean            isosurfacesLoad_file                (const char *file,
                                                             Surfaces **surf,
                                                             GError **error);

This loads a surface file and set default material properties for it. See surf file specifications.

`file` : | target file to load ;
`surf` : | a set of surfaces (location) ;
`error` : | a location to store errors.
Returns : | TRUE in case of success, FALSE otherwise. Even in case of success `error` may have been set.

### isosurfacesDraw_surfaces ()

    void                isosurfacesDraw_surfaces            (int openGLId,
                                                             Surfaces *surf[],
                                                             SurfacesOrder *order);

Rebuild each visible surface's list. The order in which to draw the surfaces is given in the `order` argument. If the resource 'isosurfaces_drawIntra' is TRUE then, the interior of the surfaces is drawn as color inverse.

`openGLId` : | an id for the OpenGL list ;
`surf` : | an array of Surfaces object, must be NULL terminated.
`order` : | a SurfacesOrder object.

### isosurfacesSet_box ()

    void                isosurfacesSet_box                  (Surfaces *surf,
                                                             double box[6]);

Copy the given `box` to the box of surfaces.

`surf` : | a Surfaces object ;
`box` : | a box definition in reduced coordinates.

### isosurfacesCopy_resource ()

    void                isosurfacesCopy_resource            (SurfaceResource *res,
                                                             SurfaceResource *res_old);

This method copies all values from `res_old` to `res`.

`res` : | an allocated SurfaceResource object to receive values ;
`res_old` : | a SurfaceResource to read the values from.

### isosurfacesAddSurfaces ()

    void                isosurfacesAddSurfaces              (Surfaces *surf,
                                                             int nsurf,
                                                             int npolys,
                                                             int npoints);

Change the allocation of internal arrays to store the additional surfaces with the given description.

`surf` : | a Surfaces structure ;
`nsurf` : | the number of surfaces to add ;
`npolys` : | the number of polygons to add ;
`npoints` : | the number of vertices to add.

### isosurfacesResourcesInit ()

    void                isosurfacesResourcesInit            ();

Internal routine called by `isosurfacesInit()` at startup. Do not use it.

### isoSurfacesSet_fitToBox ()

    void                isoSurfacesSet_fitToBox             (VisuData *data,
                                                             Surfaces *surf);

This method changes the position of all vertices in the structure to match the box description given in `data`.

`data` : | a VisuData object ;
`surf` : | a set of surfaces.

### isosurfacesSet_showAll ()

    void                isosurfacesSet_showAll              (Surfaces *surf,
                                                             gboolean show);

Shows or hides all surfaces and check their "draw" status in the panel accordingly.

`surf` : | a Surfaces object ;
`show` : | TRUE to show all surfaces, FALSE to hide them.

### isosurfacesSet_surfaceResource ()

    void                isosurfacesSet_surfaceResource      (Surfaces *surf,
                                                             int surf_index,
                                                             SurfaceResource *res);

This method is used to change the resource of a surface.

`surf` : | the surface object ;
`surf_index` : | the number of the surface ;
`res` : | the new resource.

### isosurfacesSet_drawIntra ()

    gboolean            isosurfacesSet_drawIntra            (gboolean status);

Set if the interiors of surfaces are drawn with a colour inverse or not.

`status` : | a boolean.
Returns : | TRUE if calling routine should redraw the surfaces with `isosurfacesDraw_surfaces()`.

### isosurfacesGet_box ()

    double*             isosurfacesGet_box                  (Surfaces *surf);

Get the box of the surfaces.

`surf` : | a Surfaces object.
Returns : | 6 floats, private, read-only.

### isosurfacesGet_nbSurfaces ()

    int                 isosurfacesGet_nbSurfaces           (Surfaces *surf);

Retrieves th number of surfaces stired in a given `surf` object.

`surf` : | the surface object.
Returns : | number of surfaces.

### isosurfacesGet_surfaceId ()

    int                 isosurfacesGet_surfaceId            (Surfaces *surf,
                                                             int i);

This returns for the given `i` its id information.

`surf` : | the surface object ;
`i` : | the number of the surface.
Returns : | the id of the surface or 0, if `i` is invalid.

### isosurfacesGet_surfacePosition ()

    int                 isosurfacesGet_surfacePosition      (Surfaces *surf,
                                                             int id);

This returns for the given `id` its number.

`surf` : | the surface object ;
`id` : | the id of the surface.
Returns : | the number of the surface or 0, if `id` is invalid.

### isosurfacesGet_surfaceRendered ()

    gboolean            isosurfacesGet_surfaceRendered      (Surfaces *surf,
                                                             int surf_index);

This returns for the given `surf_index` its visibility.

`surf` : | the surface object ;
`surf_index` : | the number of the surface.
Returns : | the visibility of the surface or FALSE, if `surf_index` is invalid.

### isosurfacesGet_surfaceResource ()

    SurfaceResource*    isosurfacesGet_surfaceResource      (Surfaces *surf,
                                                             int surf_index);

This returns for the given `surf_index` its resource information.

`surf` : | the surface object ;
`surf_index` : | the number of the surface.
Returns : | the resource of the surface or NULL, if `surf_index` is invalid.

### isosurfacesGet_surfaceName ()

    const gchar*        isosurfacesGet_surfaceName          (Surfaces *surf,
                                                             int surf_index);

This returns for the given `surf_index` its name (1 <= surf_index <= surfaces_number)

`surf` : | the surface object ;
`surf_index` : | the number of the surface.
Returns : | the name of the surface or empty name or NULL, if `surf_index` is invalid.

### isosurfacesGet_surfaceSortedById ()

    int*                isosurfacesGet_surfaceSortedById    (Surfaces *surf);

This returns the surface numbers sorted using their ids.

`surf` : | the surface object.
Returns : | a newly allocated array with surface numbers.

### isosurfacesGet_resourceFromName ()

    SurfaceResource*    isosurfacesGet_resourceFromName     (const gchar *surf_name,
                                                             gboolean *nw);

This returns the resource information matching the given `surf_name`. If the resource doesn't exist, it is created and `new` is set to TRUE. If the given name (`surf_name`) is NULL, then a new resource is created, but it is not stored and will not be shared by surfaces.

`surf_name` : | the name of the surface (can be NULL) ;
`new` : | a location to store a boolean value (can be NULL).
Returns : | the resource (created or retrieved).

### isosurfacesGet_newId ()

    int                 isosurfacesGet_newId                (Surfaces *surf);

This returns a unique id to create a new surface.

`surf` : | the surface object.
Returns : | a value suitable to create a new surface in this set of surfaces.

### isosurfacesGet_drawIntra ()

    gboolean            isosurfacesGet_drawIntra            ();

Retrieve if the interiors of surfaces are drawn with a colour inverse or not.

Returns : | TRUE if the interior is painted in colour inverse.

### isosurfacesGet_floatProperty ()

    float*              isosurfacesGet_floatProperty        (Surfaces *surf,
                                                             const gchar *name);

Some properties can be associated to the surfaces stored in `surf`. This method is used to retrieve floating point values properties.

`surf` : | a Surfaces object ;
`name` : | the name of the property to look for.
Returns : | a table with the values if the property is found, NULL otherwise.

### isosurfacesAdd_floatProperty ()

    float*              isosurfacesAdd_floatProperty        (Surfaces *surf,
                                                             const gchar *name);

Some properties can be associated to the surfaces stored in `surf`. This method is add a new property.

`surf` : | a Surfaces object ;
`name` : | the name of the property to add.
Returns : | a newly allocated array that can be populated.

### isosurfacesGet_floatPropertyValue ()

    gboolean            isosurfacesGet_floatPropertyValue   (Surfaces *surf,
                                                             int idSurf,
                                                             const gchar *name,
                                                             float *value);

This method retrieves a float value stored as a property called `name` for the surface defined by its number `idSurf`.

`surf` : | a Surfaces object ;
`idSurf` : | a surface number ;
`name` : | the name of the property to get the value from ;
`value` : | a location to store the value.
Returns : | TRUE if a value is indeed found.

### isosurfacesOrder_new ()

    SurfacesOrder*      isosurfacesOrder_new                ();

Create an object to hold the order in which the surfaces must be drawn. See `isosurfacesOrder_polygons()` to set this object.

Returns : | a newly created SurfacesOrder object without any values.

### isosurfacesOrder_free ()

    void                isosurfacesOrder_free               (SurfacesOrder *order);

Free memory used by a SurfacesOrder object.

`order` : | the object to be freed.

### isosurfacesOrder_polygons ()

    void                isosurfacesOrder_polygons           (SurfacesOrder *order,
                                                             Surfaces *surf[]);

Re-orders the polygons in back to front order. This function should be called everytime a redraw is needed.

`order` : | the description of the polygons order ;
`surf` : | an array of Surfaces object, must be NULL terminated.

### VISU_ERROR_ISOSURFACES

    #define VISU_ERROR_ISOSURFACES isosurfacesGet_quark()

### isosurfacesInit ()

    void                isosurfacesInit                     ();

Method used to initialised the surface handling, should not be called.

### isosurfacesCheck_consistency ()

    void                isosurfacesCheck_consistency        (Surfaces *surf);

Check if all arrays in the structures are consistent (without overflow).

`surf` : | a Surfaces object.

### isosurfacesGet_quark ()

    GQuark              isosurfacesGet_quark                ();