visu_pairs

visu_pairs — V_Sim can draw link between nodes. This part defines a pair object and interface to draw pairs.

Synopsis

#define             PAIRS_MIN
#define             PAIRS_MAX
#define             PAIRS_COLOR_R
#define             PAIRS_COLOR_G
#define             PAIRS_COLOR_B
void                (*foreachPairsFunc)                 (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data,
                                                         gpointer userData);
typedef             VisuPair;
struct              VisuPair_struct;
typedef             VisuPairData;
typedef             VisuPairDistribution;

void                (*initEndOpenGlPairsFunc)           ();
void                (*startEndPairsFunc)                (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data);
void                (*pairDefinitionFunc)               (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data,
                                                         OpenGLView *view,
                                                         double x1,
                                                         double y1,
                                                         double z1,
                                                         double x2,
                                                         double y2,
                                                         double z2,
                                                         float d2,
                                                         float alpha);
struct              PairsExtension_struct;
typedef             PairsExtension;
PairsExtension*     (*PairsExtensionInitFunc)           (void);
PairsExtension*     visuPairExtensionNew                (const char *name,
                                                         const char *printName,
                                                         const char *description,
                                                         gboolean sensitive,
                                                         initEndOpenGlPairsFunc init,
                                                         initEndOpenGlPairsFunc stop,
                                                         startEndPairsFunc start,
                                                         startEndPairsFunc end,
                                                         pairDefinitionFunc draw);
void                visuPairExtensionFree               (PairsExtension *extension);
void                visuPairExtensionAdd                (PairsExtension *extension);
GList*              visuPairExtensionGet_allMethods     ();
PairsExtension*     visuPairExtensionGet_current        ();
gboolean            visuPairExtensionSet                (PairsExtension *extension);

gboolean            visuPairBuild                       (VisuData *dataObj);
void                visuPairForeach                     (foreachPairsFunc whatToDo,
                                                         gpointer userData);
gboolean            visuPairGet_status                  ();
float               visuPairGet_distance                (VisuPairData *data,
                                                         int minOrMax);
VisuPairDistribution* visuPairGet_distanceDistribution  (VisuPair *pair,
                                                         VisuData *dataObj,
                                                         float step,
                                                         float max);
gboolean            visuPairGet_drawn                   (VisuPairData *data);
VisuPairData*       visuPairGet_link                    (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         float minMax[2]);
VisuPairData*       visuPairGet_linkFromId              (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         guint pos);
GList*              visuPairGet_links                   (VisuElement *ele1,
                                                         VisuElement *ele2);
gpointer            visuPairGet_linkProperty            (VisuPairData *data,
                                                         const gchar *key);
VisuPair*           visuPairGet_pair                    (VisuElement *ele1,
                                                         VisuElement *ele2);
gboolean            visuPairGet_printLength             (VisuPairData *data);
gpointer            visuPairGet_property                (VisuPair *pair,
                                                         const gchar *key);
gboolean            visuPairRead_linkFromTokens         (gchar **tokens,
                                                         int *index,
                                                         VisuPairData **data,
                                                         int position,
                                                         GError **error);
gboolean            visuPairRemove_link                 (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data);
gboolean            visuPairSet_status                  (gboolean onOff);
void                visuPairSet_outOfDate               ();
gboolean            visuPairSet_color                   (VisuPairData *data,
                                                         Color *destColor);
gboolean            visuPairSet_distance                (VisuPairData *data,
                                                         float val,
                                                         int minOrMax);
gboolean            visuPairSet_drawn                   (VisuPairData *data,
                                                         gboolean drawn);
gboolean            visuPairSet_printLength             (VisuPairData *data,
                                                         gboolean status);
void                visuPairSet_property                (VisuPair *pair,
                                                         const gchar *key,
                                                         gpointer value,
                                                         GDestroyNotify freeFunc);
void                visuPairSet_linkProperty            (VisuPairData *data,
                                                         const gchar *key,
                                                         gpointer value);

int                 initPairsModule                     ();

Description

The visu_pairs.c defines only general methods to draw pairs. It introduces a new object called PairsData. This stores some characteristics on links between two VisuElement. The main characteristic is that pairs are drawn only if the length between two nodes is in a specific range. Use setPairsDistance() and getPairsDistance() to tune this range.

This file does not draw any pairs. But it gives some interface to create rendering capabilities. To create a new pair rendering module, called PairsExtension, use pairsExtension_new(). Basically, a PairsExtension is characterized by it drawing method. But it can have other methods that are called in different cases. See initEndOpenGlPairsFunc() and startEndPairsFunc() prototypes to have more informations.

Details

PAIRS_MIN

#define PAIRS_MIN 0

Flag used to define the minimum length to draw pair. This is useful with the getPairsDistance() and the getPairsDistance() methods.


PAIRS_MAX

#define PAIRS_MAX 1

Flag used to define the maximum length to draw pair. This is useful with the getPairsDistance() and the getPairsDistance() methods.


PAIRS_COLOR_R

#define PAIRS_COLOR_R 0

Flag used to define the red color of a pair. This is useful to access the rgba array of the Color object return by setPairsColor().


PAIRS_COLOR_G

#define PAIRS_COLOR_G 1

Flag used to define the green color of a pair. This is useful to access the rgba array of the Color object return by setPairsColor().


PAIRS_COLOR_B

#define PAIRS_COLOR_B 2

Flag used to define the blue color of a pair. This is useful to access the rgba array of the Color object return by setPairsColor().


foreachPairsFunc ()

void                (*foreachPairsFunc)                 (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data,
                                                         gpointer userData);

Prototype of functions called with the foreach method apply to each pairs.

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object ;

data :

a VisuPairData object ;

userData :

some user defined data.

VisuPair

typedef struct VisuPair_struct VisuPair;

A common way to name pairsData_struct objects.


struct VisuPair_struct

struct VisuPair_struct;

An opaque structure to store informations about links between two elements.


VisuPairData

typedef struct pairsData_struct VisuPairData;

A common way to name pairsData_struct objects.


VisuPairDistribution

typedef struct VisuPairDistribution_struct VisuPairDistribution;

A convenient name for VisuPairDistribution_struct objects.


initEndOpenGlPairsFunc ()

void                (*initEndOpenGlPairsFunc)           ();

Prototype of functions called at the beginning and the end of opengl pairs drawing. Such methods are useful to change some OpenGL variables such as lighting or blending...


startEndPairsFunc ()

void                (*startEndPairsFunc)                (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data);

Prototype of functions called at the beginning and the end of drawing of each pairs types. ele1 and ele2 arguments are the two elements between the pair defined by data is drawn. This is useful to set some OpenGL definition specific to each pair, such as the color for example.

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object ;

data :

a VisuPairData object.

pairDefinitionFunc ()

void                (*pairDefinitionFunc)               (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data,
                                                         OpenGLView *view,
                                                         double x1,
                                                         double y1,
                                                         double z1,
                                                         double x2,
                                                         double y2,
                                                         double z2,
                                                         float d2,
                                                         float alpha);

Prototype of function to draw a pair. Such function are called each time a pair is drawn between the two points (x1, y1, z1) and (x2, y2, z2). The d2 argument is the square distance between the two points. The alpha argument is a proposed alpha colour from the main program, its value is in [0;1].

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object ;

data :

a VisuPairData object ;

view :

a OpenGLView object, giving some constants describing the OpenGL scene ;

x1 :

a floating point value ;

y1 :

a floating point value ;

z1 :

a floating point value ;

x2 :

a floating point value ;

y2 :

a floating point value ;

z2 :

a floating point value ;

d2 :

a floating point value ;

alpha :

a floating point value.

struct PairsExtension_struct

struct PairsExtension_struct;

Structure to store pairs extensions. All fields are private and should not be accessed directly. This structure will not be public in near future, do not use it.


PairsExtension

typedef struct PairsExtension_struct PairsExtension;

Common naming for PairsExtension_struct objects.


PairsExtensionInitFunc ()

PairsExtension*     (*PairsExtensionInitFunc)           (void);

Prototype of the functions used to initialise a new pair models.

Returns :

a newly allocated pair model.

visuPairExtensionNew ()

PairsExtension*     visuPairExtensionNew                (const char *name,
                                                         const char *printName,
                                                         const char *description,
                                                         gboolean sensitive,
                                                         initEndOpenGlPairsFunc init,
                                                         initEndOpenGlPairsFunc stop,
                                                         startEndPairsFunc start,
                                                         startEndPairsFunc end,
                                                         pairDefinitionFunc draw);

This creates a new pairs extension. Such an extension describes how to draw links (called pairs) between elements. The sensitive argument is to inform if pairs must be redrawn when the OpenGL engine sends the OpenGLFacetteChanged signal.

name :

name of the extension (must be non null) ;

printName :

a string to label the method that can be safely translated ;

description :

a brief description of the extension (can be null) ;

sensitive :

a boolean 0 or 1 ;

init :

a initEndOpenGlPairsFunc() method or NULL ;

stop :

a initEndOpenGlPairsFunc() method or NULL ;

start :

a startEndPairsFunc() method or NULL ;

end :

a startEndPairsFunc() method or NULL ;

draw :

a pairDefinitionFunc() method (not NULL).

Returns :

the new PairsExtension or null if something wrong happens.

visuPairExtensionFree ()

void                visuPairExtensionFree               (PairsExtension *extension);

Free all the allocated attributes of the specified method.

extension :

the extension to delete.

visuPairExtensionAdd ()

void                visuPairExtensionAdd                (PairsExtension *extension);

A method used by user to registered a new extension.

extension :

an extension.

visuPairExtensionGet_allMethods ()

GList*              visuPairExtensionGet_allMethods     ();

Useful to know all PairsExtension.

Returns :

a list of all the known PairsExtension. This list should be considered read-only.

visuPairExtensionGet_current ()

PairsExtension*     visuPairExtensionGet_current        ();

If some process need to know the current PairsExtension. Such extension has been set with setPairsMethod().

Returns :

the current PairsExtension, NULL if none has been set.

visuPairExtensionSet ()

gboolean            visuPairExtensionSet                (PairsExtension *extension);

Choose the method used to draw pairs. If necessary, visuPairBuild() are called.

extension :

a PairsExtension object.

Returns :

TRUE if the OpenGLAskForReDraw signal show be emitted or not.

visuPairBuild ()

gboolean            visuPairBuild                       (VisuData *dataObj);

This methods recreates the OpenGL list of the OpenGLExtension associated to the pairs. Thus it is the heart of the pairs drawing. When called, if a valid PairsExtension has been set with setPairsMethod(), it takes all the nodes and compute all the distances between two different nodes. If this distance is compatible with the distance of drawn pairs for the two elements it calls the pairDefinitionFunc() for these two nodes. WARNING! this method is very expensive in computing cost.

dataObj :

the VisuData object to create pairs for.

Returns :

TRUE if the OpenGLAskForReDraw signal show be emitted or not.

visuPairForeach ()

void                visuPairForeach                     (foreachPairsFunc whatToDo,
                                                         gpointer userData);

The way PairsData are stored in V_Sim is private and could changed between version. This method is used to apply some method each pairs.

whatToDo :

a foreachPairsFunc() method ;

userData :

some user defined data.

visuPairGet_status ()

gboolean            visuPairGet_status                  ();

Get the status of pairs, drawn or not.

Returns :

TRUE if pairs are drawn.

visuPairGet_distance ()

float               visuPairGet_distance                (VisuPairData *data,
                                                         int minOrMax);

A pair between ele1 and ele2 is drawn only if its length is between a minimum and a maximum value. This method can get these values.

data :

a PairsData object ;

minOrMax :

PAIRS_MIN or PAIRS_MAX.

Returns :

the minimum or the maximum value for the pair between ele1 and ele2.

visuPairGet_distanceDistribution ()

VisuPairDistribution* visuPairGet_distanceDistribution  (VisuPair *pair,
                                                         VisuData *dataObj,
                                                         float step,
                                                         float max);

This will compute the distnace distribution of nodes for the given pair.

pair :

a VisuPair ;

dataObj :

a VisuData ;

step :

a float for the distance mesh (negative value to use built-in default) ;

max :

a float for the maximum scanning value (negative value to use built-in default).

Returns :

a structure defining the distance distribution. This structure is private and should not be freed.

visuPairGet_drawn ()

gboolean            visuPairGet_drawn                   (VisuPairData *data);

A pair can or cannot be drawn, use this method to retrieve its state.

data :

a PairsData object ;

Returns :

TRUE if pairs can be drawn.

visuPairGet_link ()

VisuPairData*       visuPairGet_link                    (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         float minMax[2]);

A link between two elements is characterized by its boundary distances.

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object ;

minMax :

the two min and max distances.

Returns :

the VisuPairData object associated to the given two elements and distances. If none exists it is created. The returned value should not be freed.

visuPairGet_linkFromId ()

VisuPairData*       visuPairGet_linkFromId              (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         guint pos);

A link can also be retrieved by its position.

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object ;

pos :

the position in the list of links.

Returns :

the VisuPairData object associated to the given two elements and distances. If none exists NULL is returned.

visuPairGet_links ()

GList*              visuPairGet_links                   (VisuElement *ele1,
                                                         VisuElement *ele2);

There can be one or several links between elements, retrieve them with this routine.

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object.

Returns :

a list of VisuPairData. The list is owned by V_Sim and should not be freed.

visuPairGet_linkProperty ()

gpointer            visuPairGet_linkProperty            (VisuPairData *data,
                                                         const gchar *key);

Each pair can store some informations that can be retrieve by a string key. This method is used to retrieve a stored value associated to the key key.

data :

a PairsData object ;

key :

a static string.

Returns :

a found value, or NULL if nothing is associated to the key. If something is returned it should not be freed.

visuPairGet_pair ()

VisuPair*           visuPairGet_pair                    (VisuElement *ele1,
                                                         VisuElement *ele2);

The object VisuPair is used to characterized links between two elements.

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object.

Returns :

the VisuPair object associated to the given two elements. If none exists it is created. The returned value should not be freed.

visuPairGet_printLength ()

gboolean            visuPairGet_printLength             (VisuPairData *data);

Get the print length parameter of a pair. This parameter is used to tell if length should be drawn near pairs of this kind.

data :

a PairsData object.

Returns :

TRUE if length are printed.

visuPairGet_property ()

gpointer            visuPairGet_property                (VisuPair *pair,
                                                         const gchar *key);

Retrieve the property associated to the key or NULL if none exist.

pair :

a VisuPair object ;

key :

a string.

Returns :

the associated data.

visuPairRead_linkFromTokens ()

gboolean            visuPairRead_linkFromTokens         (gchar **tokens,
                                                         int *index,
                                                         VisuPairData **data,
                                                         int position,
                                                         GError **error);

This routine is used to read the resource file. Given tokens, it associate a link object by reading the two elements and the two distances that characterised this link.

tokens :

array of tokens resulting from a call to g_strsplit() with " " as separator ;

index :

IN, the position of the beginning in tokens ; OUT, one token after the last read ;

data :

a pointer to return an allocated link object ;

position :

the number of the line of the config file which the line argument is taken from ;

error :

a location to store a possible reading error.

Returns :

TRUE if succeed.

visuPairRemove_link ()

gboolean            visuPairRemove_link                 (VisuElement *ele1,
                                                         VisuElement *ele2,
                                                         VisuPairData *data);

Delete the given link.

ele1 :

a VisuElement object ;

ele2 :

a VisuElement object ;

data :

a link object.

Returns :

TRUE if the link exists and has been successfully removed.

visuPairSet_status ()

gboolean            visuPairSet_status                  (gboolean onOff);

Turn on or off the pairs.

onOff :

a boolean 0 or 1.

Returns :

TRUE if visuPairBuild() should be called and then the 'OpenGLAskForReDraw' signal be emitted.

visuPairSet_outOfDate ()

void                visuPairSet_outOfDate               ();

Use this method to change the internal flag that pairs should be rebuilt. It is useful when an extension of pairs has one of its parameters that has changed.


visuPairSet_color ()

gboolean            visuPairSet_color                   (VisuPairData *data,
                                                         Color *destColor);

Set the color of the given pair.

data :

a PairsData object ;

destColor :

a Color object.

Returns :

TRUE if visuPairBuild() should be called or not.

visuPairSet_distance ()

gboolean            visuPairSet_distance                (VisuPairData *data,
                                                         float val,
                                                         int minOrMax);

Set the minimum or the maximum length for the given pair.

data :

a PairsData object ;

val :

a floating point value ;

minOrMax :

PAIRS_MAX or PAIRS_MIN.

Returns :

TRUE if visuPairBuild() should be called or not.

visuPairSet_drawn ()

gboolean            visuPairSet_drawn                   (VisuPairData *data,
                                                         gboolean drawn);

A pair can or cannot be drawn, use this method to tune it.

data :

a PairsData object ;

drawn :

a boolean.

Returns :

TRUE if visuPairBuild() should be called.

visuPairSet_printLength ()

gboolean            visuPairSet_printLength             (VisuPairData *data,
                                                         gboolean status);

Set the attribute that controls if the length of pairs are drawn near pairs.

data :

a PairsData object ;

status :

TRUE to print length near pairs.

Returns :

TRUE if visuPairBuild() should be called or not.

visuPairSet_property ()

void                visuPairSet_property                (VisuPair *pair,
                                                         const gchar *key,
                                                         gpointer value,
                                                         GDestroyNotify freeFunc);

Each element/element can have associated data.

pair :

a Pairs object ;

key :

a static string ;

value :

a pointer to some allocated data ;

freeFunc :

a destroying method (can be NULL).

visuPairSet_linkProperty ()

void                visuPairSet_linkProperty            (VisuPairData *data,
                                                         const gchar *key,
                                                         gpointer value);

Each pair can store some informations that can be retrieve by a string key. This method is used to registered a new value associated to the key key.

data :

a PairsData object ;

key :

a static string ;

value :

a pointer to some allocated data.

initPairsModule ()

int                 initPairsModule                     ();

Initialise all the variable of this part. It calls all the elements in listInitPairsFunc (that stores the init function of the pairs extensions). If these elements return valid PairsExtension, they are registered through a call to registerPairsExtension(). This method is called by the main program at the initialisation stage and should not be called in others circonstempses.

Returns :

1 if everything goes allright during the initialisation.