next up previous contents index
Next: Set of polygons Up: Polygon, a variant of Previous: Related file (external) types   Contents   Index


Functions Summary

The following is a description of all the functions related to the Polygon type. The list is in alphabetical order.

$ \bigcirc$Name


mw_alloc_polygon - Allocate the channels array




$ \bigcirc$Summary


Polygon mw_alloc_polygon(polygon,nc)

Polygon polygon;

int nc;




$ \bigcirc$Description


This function allocates the channels array of a Polygonstructure previously created using mw_new_polygon. The size of the array is given by nc, it is the number of different channels. A channel corresponds to a real parameter associated to the polygon. The meaning of such channel has to be defined by the user. For example, polygon->channel[0] may be the gray level of the polygon.

Do not use this function if polygon has already an allocated channels array: use the function mw_change_polygon instead.

The function mw_alloc_polygon returns NULL if not enough memory is available to allocate the structure or the channels array. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

See the example of the function mw_new_polygon.

$ \bigcirc$Name


mw_change_polygon - Change the number of channels




$ \bigcirc$Summary


Polygon mw_change_polygon(polygon,nc)

Polygon polygon;

int nc;




$ \bigcirc$Description


This function changes the memory allocation for the channels array of a Polygonstructure, even if no previously memory allocation was done.

The number of channels is given by nc; a channel corresponds to a real parameter associated to the polygon. The meaning of such channel has to be defined by the user. For example, polygon->channel[0] may be the gray level of the polygon.

This function can also create the structure if the input polygon = NULL. Therefore, this function can replace both mw_new_polygon and mw_alloc_polygon. It is the recommended function to set the number of channels for polygons which are input/output of a module. Since the function can set the address of polygon, the variable must be set to the return value of the function (See example below).

The function mw_change_polygon returns NULL if not enough memory is available to allocate the structure or the channels array. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Polygon polygon; /* Input of module */

polygon = mw_change_polygon(polygon,1);
if (polygon == NULL) mwerror(FATAL,1,"Not enough memory.\n");
polygon->channel[0] = 255.0;
...
(End of this example as for the mw_new_polygon function).

$ \bigcirc$Name


mw_delete_polygon - Deallocate a polygon




$ \bigcirc$Summary


void mw_delete_polygon(polygon)

Polygon polygon;




$ \bigcirc$Description


This function deallocates all the memory allocated by the polygon variable that is, all the points belonging to this chain, the channels array (if needed) and the Polygonstructure itself. You should set polygon = NULL after this call since the address pointed by polygon is no longer valid.




$ \bigcirc$Example

/* Remove the first polygon of an existing polygon set (polygons) */

Polygons polygons;/* Existing polygons set (e.g. Input of module) */
Polygon polygon;  /* Internal use */

polygon = polygons->first;
polygons->first=polygons->next;
polygons->next->previous = NULL;
mw_delete_polygon(polygon);
polygon = NULL;

$ \bigcirc$Name


mw_length_polygon - Return the number of points of a polygon




$ \bigcirc$Summary


unsigned int mw_length_polygon(poly);

Polygon poly;




$ \bigcirc$Description


This function return the number of points contained in the given polygon poly. It returns 0 if the structure is empty.




$ \bigcirc$Example

Polygon polygon; /* Internal use: no Input neither Output of module */
point_curve newp,oldp=NULL;
int i;

polygon = mw_new_polygon();
if (polygon == NULL) mwerror(FATAL,1,"Not enough memory.\n");

/* Define a polygon with 5 points */
for (i=1;i<=5;i++)
{
 newp = mw_new_point_curve();
 if (newp == NULL) mwerror(FATAL,1,"Not enough memory.\n");
 if (i=0) polygon->first = newp;
 newp->x = newp->y = i;
 newp->previous = oldp;
 if (oldp) oldp->next = newp;
 oldp=newp;
} 

/* The length is 5 */
printf("Length=%d\n",mw_length_polygon(polygon));
$ \bigcirc$Name


mw_new_polygon - Create a new polygon




$ \bigcirc$Summary


Polygon mw_new_polygon();




$ \bigcirc$Description


This function creates a new Polygonstructure with an empty channels array. It returns NULL if not enough memory is available to create the structure. Your code should check this value to send an error message in the NULL case, and do appropriate statement.

Since the MegaWave2 compiler allocates structures for input and output objects (See Volume one: ``MegaWave2 User's Guide''), this function is normally used only for internal objects. Do not forget to deallocate the internal structures before the end of the module, except if they are part of an input or output polygons set.




$ \bigcirc$Example

/* Define a polygon with 10 points which is the straight line (0,0)-(9,9) */

Polygon polygon; /* Internal use: no Input neither Output of module */
Point_curve newp,oldp=NULL;
int i;

polygon = mw_new_polygon();
if ((polygon == NULL) || (mw_alloc_polygon(polygon,1) == NULL))
    mwerror(FATAL,1,"Not enough memory.\n");
polygon->channel[0] = 255.0;

for (i=0;i<10;i++)
{
 newp = mw_new_point_curve();
 if (newp == NULL) mwerror(FATAL,1,"Not enough memory.\n");
 if (i=0) polygon->first = newp;
 newp->x = newp->y = i;
 newp->previous = oldp;
 if (oldp) oldp->next = newp;
 oldp=newp;
}


next up previous contents index
Next: Set of polygons Up: Polygon, a variant of Previous: Related file (external) types   Contents   Index
mw 2004-05-05