Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

circ.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "prm.h"
#include "circ.h"
#include "cd.h"
#include "wd.h"
#include "dsp.h"

Include dependency graph for circ.c:

Include dependency graph

Go to the source code of this file.

Compounds

struct  _circ
 Circle primitive structure:. More...


Circle primitive module

Date:
11-Sep-2005
Author:
Luiz F. Martha
Version:
1.0
This file contains the implementation of the circle primitive module of the current project, which includes the implementation of public and private functions.

See definitions of public data types and public functions in hearder file "circ.h".

For specification see class notes of course CIV-2801 "Fundamentos de Computacao Grafica Aplicada", period 2005.2.

Revisions:

  • On 08-nov-05 by Luiz F. Martha Added functions circDisplaySolid, circHighltSolid, and circDisplayZbuffer. Incomplete source code file. Part of the objectives of the third course assignment is to complete the source code in this file (see COMPLETE HERE: XX comments). The solution of the second course assignment should be copied to this file. Additional parts should be completed.


#define CIRC_SEGS   32
#define M_PI   3.141592654
void circGetLateralNormal (Circ *circ, Coord *p, Coord *normal)
CirccircCreate (void)
 This function creates a new circle primitive.

void circDelete (Circ *circ)
 This function releases memory that is used by a circle primitive.

void circRead (Circ *circ, FILE *fd)
 This function reads geometry data of a given circle primitive (given by its pointer) from a file (given by its pointer) and loads the data into the primitive attributes.

void circWrite (Circ *circ, FILE *fd)
 This function writes the geometry attribute data of a given circle primitive (given by its pointer) to a file (given by its pointer).

int circGetNPts (Circ *circ)
 This function returns (as its value) the number of vertices of the given circle primitive (given by its pointer).

void circSetCoords (Circ *circ, int id, double x, double y)
 This function recomputes the radius of the given circle primitive (given by its pointer) based on the given point location and on the circle center point.

void circGetCoords (Circ *circ, int id, double *x, double *y)
 This function returns the x and y coordinates of a point of the given circle primitive (given by its pointer).

void circSet1stPt (Circ *circ, double x, double y)
 This function is used during interactive construction of a circle primitive.

void circSet2ndPt (Circ *circ, double x, double y)
 This function is used during interactive construction of a circle primitive.

int circPickArea (Circ *circ, double x, double y)
 This function checks whether a given point is inside a given circle primitive (given by its pointer).

int circPickVertex (Circ *circ, double x, double y, double tol, int *id)
 This function selects a vertex on the boundary of a given circle primitive based on the given point position.

int circPickSide (Circ *circ, double x, double y, double tol, int *id)
 This is a dummy function that does not do anything.

void circTranslate (Circ *circ, double dx, double dy)
 This function translates the given circle primitive (given by its pointer).

void circTranslateVertex (Circ *circ, int id, double dx, double dy)
 This function translates a vertex on the boundary of a given circle primitive (given by its pointer) using the given translation factors.

void circTranslateSide (Circ *circ, int id, double dx, double dy)
 This is a dummy function that does not do anything.

void circGetBox (Circ *circ, double *xmin, double *xmax, double *ymin, double *ymax)
 This function returns the limiting rectangle that involves the given circle primitive (given by its pointer).

void circDisplayBoundary (Circ *circ)
 This function displays the boundary of the given circle primitive (given by its pointer).

void circDisplayInterior (Circ *circ)
 This function displays the interior of the given circle primitive (given by its pointer).

void circDisplaySolid (Circ *circ, double height)
 Function to display a solid version of a circle primitive.

void circHighltSolid (Circ *circ, double height)
 Function to highlight a solid version of a circle primitive.

void circDisplayZbuffer (Circ *circ, double height, long int color)
 Function to send a solid version of a circle primitive to the zbuffer module to be projected and displayed.


Define Documentation

#define CIRC_SEGS   32
 

Definition at line 62 of file circ.c.

Referenced by circDisplayZbuffer().

#define M_PI   3.141592654
 

Definition at line 65 of file circ.c.

Referenced by circDisplayZbuffer().


Function Documentation

Circ* circCreate void   
 

This function creates a new circle primitive.

It only allocates memory for a circle primitive, sets its default center coordinates - (0.0,0.0) - and radius (1.0), and returns a pointer to the allocated circle primitive.

Returns:
The function returns a pointer to the created primitive, or a null pointer if the primitive could not be created.

Definition at line 105 of file circ.c.

References _circ::c, _circ::r, _Coord::x, and _Coord::y.

Referenced by prmCreateBack(), and prmCreateFront().

void circDelete Circ   circ
 

This function releases memory that is used by a circle primitive.

It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to primitive to delete (in)

Definition at line 126 of file circ.c.

Referenced by prmDelete().

void circDisplayBoundary Circ   circ
 

This function displays the boundary of the given circle primitive (given by its pointer).

Marks are used to display the four vertices of the circle as indicated below:

(id = 1) . + . . . . .

(id = 2) + + (id = 0) . . . . . . + (id = 3)

The Canvas Draw (CD) graphics library is used to display the boundary of the primitive. Please refer to CD documentation for additional information. The function only deals with the geometric attributes of the primitive. This means that other attributes such as foreground color, line style are specified outside this function. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)

Definition at line 237 of file circ.c.

Referenced by prmDisplayBoundary().

void circDisplayInterior Circ   circ
 

This function displays the interior of the given circle primitive (given by its pointer).

The interior area is filled with the currently specified background color. The Canvas Draw (CD) graphics library is used to display the boundary of the primitive. Please refer to CD documentation for additional information. The function only deals with the geometric attributes of the primitive. This means that other attributes such as background color or interior style are specified outside this function. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)

Definition at line 244 of file circ.c.

Referenced by prmDisplayInterior().

void circDisplaySolid Circ   circ,
double    height
 

Function to display a solid version of a circle primitive.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height. This function creates a facet prism that approximates the resulting cylinder and fills the facets of the solid prism faces with the current color. It uses OpenGL display functions.

Parameters:
circ  - pointer to target circle primitive (in)
height  - primitive height (in)

Definition at line 251 of file circ.c.

Referenced by prmDisplaySolid().

void circDisplayZbuffer Circ   circ,
double    height,
long int    color
 

Function to send a solid version of a circle primitive to the zbuffer module to be projected and displayed.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height.

Parameters:
circ  - pointer to target circle primitive (in)
height  - primitive height (in)
color  - primitive coded color (in)

Definition at line 268 of file circ.c.

References _circ::c, CIRC_SEGS, circGetLateralNormal(), dspZbfBeginPoly(), dspZbfEndPoly(), dspZbfVertex(), M_PI, _circ::r, _Coord::x, and _Coord::y.

Referenced by prmDisplayZbuffer().

void circGetBox Circ   circ,
double *    xmin,
double *    xmax,
double *    ymin,
double *    ymax
 

This function returns the limiting rectangle that involves the given circle primitive (given by its pointer).

This rectangle is the primitive bounding box, which is parallel to the x and y axes, with the minimum and maximum x and y coordinates of the primitive's vertices. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
xmin, xmax  - limiting x coordinates of primitive (out)
ymin, ymax  - limiting y coordinates of primitive (out)

Definition at line 229 of file circ.c.

Referenced by prmGetBox().

void circGetCoords Circ   circ,
int    id,
double *    x,
double *    y
 

This function returns the x and y coordinates of a point of the given circle primitive (given by its pointer).

The returned point coordinates correspond to a point on the circle boundary, with x coordinate equal to the x coordinate of the center plus the radius value and with y coordinate equals to the y coordinate of the center. The given index (id) is not used. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
id  - index of target point (not used) (in)
x  - point x coordinate (out)
y  - point y coordinate (out)

Definition at line 161 of file circ.c.

Referenced by prmGetCoords().

void circGetLateralNormal Circ   circ,
Coord   p,
Coord   normal
[static]
 

Definition at line 88 of file circ.c.

References _circ::c, _Coord::x, and _Coord::y.

Referenced by circDisplayZbuffer().

int circGetNPts Circ   circ
 

This function returns (as its value) the number of vertices of the given circle primitive (given by its pointer).

In this program it is assumed that a circle has four vertices: the four limiting points on its boundary. It is assumed that the given pointer is really a valid pointer to an existing circle primitive. The circle vertices are ordered in counter-clockwise order as shown below:

(id = 1) . + . . . . .

(id = 2) + + (id = 0) . . . . . . + (id = 3)

Parameters:
circ  - pointer to target primitive (in)
Returns:
The number 4.

Definition at line 147 of file circ.c.

Referenced by prmGetNPts().

void circHighltSolid Circ   circ,
double    height
 

Function to highlight a solid version of a circle primitive.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height. This function creates a facet prism that approximates the resulting cylinder, displays the edges of the prism, and draws marks at its vertices, all with the current color. It uses OpenGL display functions.

Parameters:
circ  - pointer to target circle primitive (in)
height  - primitive height (in)

Definition at line 260 of file circ.c.

Referenced by prmHighltSolid().

int circPickArea Circ   circ,
double    x,
double    y
 

This function checks whether a given point is inside a given circle primitive (given by its pointer).

It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
x  - x coordinate of given point (in)
y  - y coordinate of given point (in)
Returns:
In case the given point is inside the given primitive, a true (1) status is returned. Otherwise, a false (0) status is returned.

Definition at line 182 of file circ.c.

Referenced by prmPickArea().

int circPickSide Circ   circ,
double    x,
double    y,
double    tol,
int *    id
 

This is a dummy function that does not do anything.

It exists just for compatibility with other primitive types.

Returns:
The function returns a false (0) status.

Definition at line 201 of file circ.c.

Referenced by prmPickSide().

int circPickVertex Circ   circ,
double    x,
double    y,
double    tol,
int *    id
 

This function selects a vertex on the boundary of a given circle primitive based on the given point position.

The circle vertices are ordered in counter-clockwise order as shown below:

(id = 1) . + . . . . .

(id = 2) + + (id = 0) . . . . . . + (id = 3)

Parameters:
circ  - pointer to target circle primitive (in)
x  - x coordinate of given point (in)
y  - y coordinate of given point (in)
tol  - tolerance value to check proximity (in)
id  - returned vertex index (out)
Returns:
In case the given point is close one of the vertices on the boundary of the circle, the function returns a true (1) status and index (id) of the found vertex. Otherwise, the function returns a false (0) status.

Definition at line 191 of file circ.c.

Referenced by prmPickVertex().

void circRead Circ   circ,
FILE *    fd
 

This function reads geometry data of a given circle primitive (given by its pointer) from a file (given by its pointer) and loads the data into the primitive attributes.

It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target primitive (in)
fd  - ponter to file descriptor (in)

Definition at line 133 of file circ.c.

Referenced by prmRead().

void circSet1stPt Circ   circ,
double    x,
double    y
 

This function is used during interactive construction of a circle primitive.

It sets the x and y coordinates of the first construction point of the given circle primitive (given by its pointer) by the given pair of coordinates. The first construction point corresponds to the center point of the circle primitive. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
x  - first point x coordinate (in)
y  - first point y coordinate (in)

Definition at line 168 of file circ.c.

Referenced by prmSet1stPt().

void circSet2ndPt Circ   circ,
double    x,
double    y
 

This function is used during interactive construction of a circle primitive.

It sets the x and y coordinates of the second construction point of the given circle primitive (given by its pointer) by the given pair of coordinates. The second construction point corresponds to any point on the boundary of the circle primitive. The given point coordinates are used to compute the new circle radius based on the current center point. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
x  - second point x coordinate (in)
y  - second point y coordinate (in)

Definition at line 175 of file circ.c.

Referenced by prmSet2ndPt().

void circSetCoords Circ   circ,
int    id,
double    x,
double    y
 

This function recomputes the radius of the given circle primitive (given by its pointer) based on the given point location and on the circle center point.

The given index (id) is not used. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
id  - index of target point (not used) (in)
x  - new point x coordinate (in)
y  - new point y coordinate (in)

Definition at line 154 of file circ.c.

Referenced by prmSetCoords().

void circTranslate Circ   circ,
double    dx,
double    dy
 

This function translates the given circle primitive (given by its pointer).

The center point of the circle is translated by the given translation factors. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
dx, dy  - translation factors in x & y directions (in)

Definition at line 209 of file circ.c.

Referenced by prmTranslate().

void circTranslateSide Circ   circ,
int    id,
double    dx,
double    dy
 

This is a dummy function that does not do anything.

It exists just for compatibility with other primitive types.

Definition at line 223 of file circ.c.

Referenced by prmTranslateSide().

void circTranslateVertex Circ   circ,
int    id,
double    dx,
double    dy
 

This function translates a vertex on the boundary of a given circle primitive (given by its pointer) using the given translation factors.

The given translation factors are used to compute the new coordinates of the target vertex of the circle. The circle vertices are ordered in counter-clockwise order as shown below:

(id = 1) . + . . . . .

(id = 2) + + (id = 0) . . . . . . + (id = 3)

For vertices with id = 0 or id = 2, only the horizontal translation parameter (dx) is considered to compute the new position of the vertex. For vertices with id = 1 or id = 3, only the vertical translation parameter (dy) is considered to compute the new position of the vertex. The circle radius is recomputed based on the translated vertex coordinates and on the current center point. It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target circle primitive (in)
id  - index of point to translate (1) (in)
dx, dy  - translation factors in x & y directions (in)

Definition at line 216 of file circ.c.

Referenced by prmTranslateVertex().

void circWrite Circ   circ,
FILE *    fd
 

This function writes the geometry attribute data of a given circle primitive (given by its pointer) to a file (given by its pointer).

It is assumed that the given pointer is really a valid pointer to an existing circle primitive.

Parameters:
circ  - pointer to target primitive (in)
fd  - ponter to file descriptor (in)

Definition at line 140 of file circ.c.

Referenced by prmWrite().


Generated on Tue Nov 8 10:58:01 2005 for Trab3 by doxygen1.2.18