Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Quad Class Reference

#include <quad.h>

List of all members.
Date:
20-Jun-2010
Author:
Luiz F. Martha
Version:
1.1
This file contains the implementation of the quadrilateral primitive of current project. This class is derived from primitive base class (see header file "prm.h").

See class definition in hearder file "quad.h".

For specification see class notes of course CIV-2802 "Sistemas Graficos para Engenharia", period 2010.1.

Revisions:

  • Version 1.0 by L.F. Martha on 02-Jun-2010: Initial version. Stolen from Trab2 of CIV2801-2005.2 and modified.
  • Version 1.1 by L.F. Martha on 20-Jun-2010: Added object functions DisplaySolid, HighltSolid, and DisplayZbuffer.


 Quad ()
 This function creates a new quadrilateral primitive.
 Quad (int back)
 This function creates a new quadrilateral primitive.
virtual ~Quad ()
 This function removes a quadrileral primitive from the current list of primitives and releases memory that is used by it.
void Read (FILE *fd)
 This function reads geometry data of current quadrilateral primitive from a file (given by its pointer) and loads the data into the primitive attributes.
void Write (FILE *fd)
 This function writes the geometry attribute data of current quadrilateral primitive to a file (given by its pointer).
int GetNPts (void)
 This function returns (as its value) the number of vertices of the current quadrilateral primitive.
void SetCoords (int id, double x, double y)
 This function replaces the x and y coordinates of a vertex of the current quadrilateral primitive by the given pair of coordinates.
void GetCoords (int id, double *x, double *y)
 This function returns the x and y coordinates of a vertex of the current quadrilateral primitive.
void Set1stPt (double x, double y)
 This function is used during interactive construction of a quadrilateral primitive.
void Set2ndPt (double x, double y)
 This function is used during interactive construction of a quadrilateral primitive.
int PickArea (double x, double y)
 This function checks whether a given point is inside the current quadrilateral primitive.
int PickVertex (double x, double y, double tol, int *id)
 This function selects a vertex of the current quadrilateral primitive based on the given point position.
int PickSide (double x, double y, double tol, int *id)
 This function selects a side of the current quadrilateral primitive based on the given point position.
void Translate (double dx, double dy)
 This function translates the current quadrilateral primitive.
void TranslateVertex (int id, double dx, double dy)
 This function translates a vertex of the current quadrilateral primitive using the given translation factors.
void TranslateSide (int id, double dx, double dy)
 This function translates the two vertices of a side of the current quadrilateral primitive using the given translation factors.
void GetBox (double *xmin, double *xmax, double *ymin, double *ymax)
 This function returns the limiting rectangle that involves the current quadrilateral primitive.
void DisplayBoundary (void)
 This function displays the boundary of the current quadrilateral primitive).
void DisplayInterior (void)
 This function displays the interior of the current quadrilateral primitive.
void DisplaySolid (void)
 Function to display a solid version of a quadrilateral primitive.
void HighltSolid (void)
 Function to highlight a solid version of a quadrilateral primitive.
void DisplayZbuffer (void)
 Function to send a solid version of a quadrilateral primitive to the zbuffer module to be projected and displayed.
void BuildSolidPrm (Pnt3d *solid_prm)
 This function returns an array of points that represents the solid version of a quadrilateral primitive.
static void PickCode (double x, double y, double xmin, double xmax, double ymin, double ymax, int cod[4])
 This function computes a code vector for a picking point with respect to a window (rectangle given by its limiting coordinates).
static int PickLine (double x, double y, double pick_tol, double x0, double y0, double x1, double y1)
 This function checks to see whether a given point (x,y) is close to a line (x0, y0, x1, y1).
static void FaceNormal (Pnt3d *p0, Pnt3d *p1, Pnt3d *p2, Pnt3d *p3, Vec3d *normal)
 This function computes the normal vector of a quadrilateral polygon.

Protected Attributes

Coord p [4]
 Primitive vertices.

Classes

struct  Pnt3d
 3D point struct More...
struct  Vec3d
 3D vector struct More...


Constructor & Destructor Documentation

Quad::Quad  ) 
 

This function creates a new quadrilateral primitive.

It sets its default vertex coordinates and puts it at the beginning of the list of primitives. The head pointer to the list is modified accordingly. The special case of a current empty list is also treated.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

Default vertex coordinates: id = 0 ==> (x0 = 0.0, y0 = 0.0) id = 1 ==> (x1 = 1.0, y1 = 0.0) id = 2 ==> (x2 = 1.0, y2 = 1.0) id = 3 ==> (x3 = 0.0, y3 = 1.0)

Definition at line 60 of file quad.cpp.

References p, Prm::PRM_QUAD, and Prm::type.

Quad::Quad int  back  ) 
 

This function creates a new quadrilateral primitive.

It sets its default vertex coordinates and puts it at the end of the list of primitives if the "back" argument is true (1). If the "back" is false (0), the primitive is put at the beginning of the list of primitives. The head pointer to the list is modified accordingly. The special case of a current empty list is also treated.

Parameters:
back - back status (1 => end, 0 => beginning) (in)

Definition at line 79 of file quad.cpp.

References p, Prm::PRM_QUAD, and Prm::type.

Quad::~Quad  )  [virtual]
 

This function removes a quadrileral primitive from the current list of primitives and releases memory that is used by it.

The head pointer to the list of primitives may be modified accordingly. The special case of a resulting empty list is also treated.

Definition at line 99 of file quad.cpp.


Member Function Documentation

void Quad::BuildSolidPrm Pnt3d solid_prm  )  [protected]
 

This function returns an array of points that represents the solid version of a quadrilateral primitive.

The solid version is a prism that has the 2D primitive as its base and height equal to the primitive height. The solid prism is built in such a way that each of its base faces has a normal vector pointing outwards the prism when traversing its vertices in counter-clockwise order and following the right-hand rule.

Parameters:
solid_prm - array of solid primitive points (out)

Definition at line 218 of file quad.cpp.

References FaceNormal(), Prm::height, p, Quad::Pnt3d::x, Quad::Pnt3d::y, Quad::Vec3d::z, and Quad::Pnt3d::z.

Referenced by DisplaySolid(), DisplayZbuffer(), and HighltSolid().

void Quad::DisplayBoundary void   )  [virtual]
 

This function displays the boundary of the current quadrilateral primitive).

Straight lines are used used to display the primitive edges and marks are used to display its vertices. 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, or mark type are specified outside this function.

Implements Prm.

Definition at line 504 of file quad.cpp.

References GetCoords().

void Quad::DisplayInterior void   )  [virtual]
 

This function displays the interior of the current quadrilateral primitive.

The interior area is filled with the currently specified foreground color. The Canvas Draw (CD) graphics library is used to display the interior 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.

Implements Prm.

Definition at line 522 of file quad.cpp.

References GetCoords().

void Quad::DisplaySolid void   )  [virtual]
 

Function to display a solid version of a quadrilateral primitive.

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

Parameters:
quad - pointer to target quadrilateral primitive(in)
height - primitive height (in)

Implements Prm.

Definition at line 539 of file quad.cpp.

References BuildSolidPrm(), FaceNormal(), Prm::height, p, Quad::Vec3d::x, Quad::Vec3d::y, and Quad::Vec3d::z.

void Quad::DisplayZbuffer void   )  [virtual]
 

Function to send a solid version of a quadrilateral 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:
quad - pointer to target quadrilateral primitive(in)
height - primitive height (in)
color - primitive coded color (in)

Implements Prm.

Definition at line 687 of file quad.cpp.

References BuildSolidPrm(), Prm::color, FaceNormal(), Prm::height, p, Quad::Vec3d::x, Quad::Vec3d::y, Quad::Vec3d::z, Dsp::ZbfBeginPoly(), Dsp::ZbfEndPoly(), and Dsp::ZbfVertex().

void Quad::FaceNormal Pnt3d p0,
Pnt3d p1,
Pnt3d p2,
Pnt3d p3,
Vec3d normal
[static, protected]
 

This function computes the normal vector of a quadrilateral polygon.

It uses the cross product of the polygon edges.

Parameters:
p0 - first quadrilateral point (in)
p1 - second quadrilateral point (in)
p2 - third quadrilateral point (in)
p4 - fourth quadrilateral point (in)
normal - quadrilateral normalized normal vector (out)

Definition at line 178 of file quad.cpp.

References Quad::Pnt3d::x, Quad::Vec3d::x, Quad::Pnt3d::y, Quad::Vec3d::y, Quad::Pnt3d::z, and Quad::Vec3d::z.

Referenced by BuildSolidPrm(), DisplaySolid(), and DisplayZbuffer().

void Quad::GetBox double *  xmin,
double *  xmax,
double *  ymin,
double *  ymax
[virtual]
 

This function returns the limiting rectangle that involves the current quadrilateral primitive.

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.

Parameters:
xmin,xmax - limiting x coordinates of primitive (out)
ymin,ymax - limiting y coordinates of primitive (out)

Implements Prm.

Definition at line 488 of file quad.cpp.

References p.

void Quad::GetCoords int  id,
double *  x,
double *  y
[virtual]
 

This function returns the x and y coordinates of a vertex of the current quadrilateral primitive.

The vertex is indicated by an index between 0 and 3. Nothing will happen if the given index is outside this range.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

Parameters:
id - index of target vertex in primitive (in)
x - vertex x coordinate (out)
y - vertex y coordinate (out)

Implements Prm.

Definition at line 329 of file quad.cpp.

References p.

Referenced by DisplayBoundary(), DisplayInterior(), PickArea(), PickSide(), and PickVertex().

int Quad::GetNPts void   )  [virtual]
 

This function returns (as its value) the number of vertices of the current quadrilateral primitive.

Returns:
The number of vertices of quadrilateral: 4.

Implements Prm.

Definition at line 311 of file quad.cpp.

void Quad::HighltSolid void   )  [virtual]
 

Function to highlight a solid version of a quadrilateral primitive.

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

Parameters:
quad - pointer to target quadrilateral primitive(in)
height - primitive height (in)

Implements Prm.

Definition at line 618 of file quad.cpp.

References BuildSolidPrm(), Prm::height, and p.

int Quad::PickArea double  x,
double  y
[virtual]
 

This function checks whether a given point is inside the current quadrilateral primitive.

The adopted algorithm is the so called semi-infinite ray algorithm that starts at the given point and goes in the horizontal direction to positive infinity. If the number of intersections of the ray with the polygon boundary is odd, the point is inside the polygon. If the number of intersections is even, the point is outside. Please refer to class notes of course CIV 2802 - Sistemas Graficos para Engenharia - PUC-Rio.

Parameters:
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.

Implements Prm.

Definition at line 356 of file quad.cpp.

References GetCoords().

void Quad::PickCode double  x,
double  y,
double  xmin,
double  xmax,
double  ymin,
double  ymax,
int  cod[4]
[static, protected]
 

This function computes a code vector for a picking point with respect to a window (rectangle given by its limiting coordinates).

This code vector is used in function quadPickLine below.

Parameters:
x - x coordinate of given point (in)
y - y coordinate of given point (in)
xmin - left limit of window (in)
xmax - right limit of window (in)
ymin - bottom limit of window (in)
ymax - top limit of window (in)
cod - returned code vector (out)

Definition at line 110 of file quad.cpp.

Referenced by PickLine().

int Quad::PickLine double  x,
double  y,
double  pick_tol,
double  x0,
double  y0,
double  x1,
double  y1
[static, protected]
 

This function checks to see whether a given point (x,y) is close to a line (x0, y0, x1, y1).

The adopted algorithm is based on clipping the given line by a tolerance window that is defined by the given point and the current tolerance value. Please refer to class notes of course CIV 2802 - Sistemas Graficos para Engenharia - PUC-Rio.

Parameters:
x - x coordinate of given point (in)
y - y coordinate of given point (in)
pick_tol - tolerance value for check proximity (in)
x0 - x coordinate of first line vertex (in)
y0 - y coordinate of first line vertex (in)
x1 - x coordinate of second line vertex (in)
y1 - y coordinate of second line vertex (in)
Returns:
Status: true (1) if point is close to line; false (0) if not.

Definition at line 121 of file quad.cpp.

References PickCode().

Referenced by PickSide().

int Quad::PickSide double  x,
double  y,
double  tol,
int *  id
[virtual]
 

This function selects a side of the current quadrilateral primitive based on the given point position.

The target side is indicated by an index, which has a value between 0 and 3.

The quadrilateral sides are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

Parameters:
x - x coordinate of given point (in)
y - y coordinate of given point (in)
tol - tolerance value to check proximity (in)
id - returned primitive side index (out)
Returns:
In case the given point is close to a side of the current primitive, the function returns a true (1) status and the index of the selected side is returned as a parameter. In case no side if found close to the given point, the function returns a false (0) status.

Implements Prm.

Definition at line 429 of file quad.cpp.

References GetCoords(), and PickLine().

int Quad::PickVertex double  x,
double  y,
double  tol,
int *  id
[virtual]
 

This function selects a vertex of the current quadrilateral primitive based on the given point position.

In case the given point is close to a vertex of the primitive, the index of the found vertex is returned. The index is a value between 0 and 3.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

Parameters:
x - x coordinate of given point (in)
y - y coordinate of given point (in)
tol - tolerance value to check proximity (in)
id - returned primitive vertex index (out)
Returns:
In case the given point is close to a vertex of the current primitive, the function returns a true (1) status and the index of the selected vertex is returned as a parameter. In case no vertex if found close to the given point, the function returns a false (0) status.

Implements Prm.

Definition at line 408 of file quad.cpp.

References Prm::ABS(), and GetCoords().

void Quad::Read FILE *  fd  )  [virtual]
 

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

Parameters:
fd - ponter to file descriptor (in)

Implements Prm.

Definition at line 287 of file quad.cpp.

References p.

void Quad::Set1stPt double  x,
double  y
[virtual]
 

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

It sets the x and y coordinates of the first construction point of the current quadrilateral primitive by the given pair of coordinates. The first construction point corresponds to the first corner vertex of the quadrilateral primitive (with id = 0).

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

The coordinates of vertices with id = 1 and id = 3 are set in such a way the quadrilateral will have horizontal and vertical sides. That is, the following is set: x0 = x3 = x and y0 = y1 = y.

Parameters:
x - first point x coordinate (in)
y - first point y coordinate (in)

Implements Prm.

Definition at line 340 of file quad.cpp.

References p.

void Quad::Set2ndPt double  x,
double  y
[virtual]
 

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

It sets the x and y coordinates of the second construction point of the current quadrilateral primitive by the given pair of coordinates. The second construction point corresponds to the third corner vertex of the quadrilateral primitive (with id = 2).

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

The coordinates of vertices with id = 1 and id = 3 are set in such a way the quadrilateral will have horizontal and vertical sides. That is, the following is set: x2 = x1 = x and y2 = y3 = y.

Parameters:
x - second point x coordinate (in)
y - second point y coordinate (in)

Implements Prm.

Definition at line 348 of file quad.cpp.

References p.

void Quad::SetCoords int  id,
double  x,
double  y
[virtual]
 

This function replaces the x and y coordinates of a vertex of the current quadrilateral primitive by the given pair of coordinates.

The vertex is indicated by an index between 0 and 3. Nothing will happen if the given index is outside this range.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

Parameters:
id - index of target vertex in primitive (in)
x - new vertex x coordinate (in)
y - new vertex y coordinate (in)

Implements Prm.

Definition at line 318 of file quad.cpp.

References p.

void Quad::Translate double  dx,
double  dy
[virtual]
 

This function translates the current quadrilateral primitive.

All the vertices of the primitive are translated by the given translation factors.

Parameters:
dx,dy - translation factors in x & y directions (in)

Implements Prm.

Definition at line 451 of file quad.cpp.

References p.

void Quad::TranslateSide int  id,
double  dx,
double  dy
[virtual]
 

This function translates the two vertices of a side of the current quadrilateral primitive using the given translation factors.

The target side is indicated by an index, which should have a value between 0 and 3. Nothing will happen if the given index is outside this range. The index of a side corresponds to the index of its first vertex.

The quadrilateral sides are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

Parameters:
id - index of side to translate (0..3) (in)
dx,dy - translation factors in x & y directions (in)

Implements Prm.

Definition at line 475 of file quad.cpp.

References p.

void Quad::TranslateVertex int  id,
double  dx,
double  dy
[virtual]
 

This function translates a vertex of the current quadrilateral primitive using the given translation factors.

The target vertex is indicated by an index between 0 and 3. Nothing will happen if the given index is outside this range.

The quadrilateral vertices are ordered in counter-clockwise order:

(id = 3)   (id = 2)
+------------+
 |                |
 |                |
 |                |
 |                |
+------------+
(id = 0)   (id = 1)

Parameters:
id - index of vertex to translate (0..3) (in)
dx,dy - translation factors in x & y directions (in)

Implements Prm.

Definition at line 464 of file quad.cpp.

References p.

void Quad::Write FILE *  fd  )  [virtual]
 

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

Parameters:
fd - ponter to file descriptor (in)

Implements Prm.

Definition at line 299 of file quad.cpp.

References p.


Member Data Documentation

Coord Quad::p[4] [protected]
 

Primitive vertices.

Definition at line 83 of file quad.h.

Referenced by BuildSolidPrm(), DisplaySolid(), DisplayZbuffer(), GetBox(), GetCoords(), HighltSolid(), Quad(), Read(), Set1stPt(), Set2ndPt(), SetCoords(), Translate(), TranslateSide(), TranslateVertex(), and Write().


The documentation for this class was generated from the following files:
Generated on Mon Jun 21 12:45:21 2010 for Trab4 by  doxygen 1.4.2-20050421