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

Prm Class Reference

#include <prm.h>

List of all members.
Date:
03-Jun-2010
Author:
Luiz F. Martha
Version:
1.0
This file contains the implementation of the primitive class the current project.

See class definition in hearder file "prm.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 03-Jun-2010: Initial version. Stolen from Trab2 of CIV2801-2005.2 and modified.


 Prm ()
 This function creates a new primitive, puts it at the beginning of the list of primitives.
 Prm (int back)
 This function creates a new primitive, puts it at the end of the list of primitives if the "back" argument is true (1).
virtual ~Prm ()
 This function removes a primitive from the current list of primitives and releases memory that is used by it.
PrmNext (void)
 This function returns a pointer to the next primitive in relation to the current primitive.
PrmPrevious (void)
 This function returns a pointer to the previous primitive in relation to the given current primitive.
void MoveFront (void)
 This function moves the current primitive to the first position in the list of primitives.
void MoveBack (void)
 This function moves the current primitive to the last position in the list of primitives.
Prm::Type GetType (void)
 This function returns (as its value) a code indicating the type of the current primitive.
void Select (void)
 This function selects the current primitive, i.e.
void Unselect (void)
 This function unselects the given current primitive, i.e.
int CheckSelected (void)
 This function returns the selection status (false = 0; true = 1) of the current primitive.
void SetColor (long int color)
 This function sets the color of the current primitive.
long int GetColor (void)
 This function returns the color of the current primitive.
void SetHeight (double height)
 This function sets the height of the current primitive.
double GetHeight (void)
 This function returns the height of the given primitive.
static void DeleteList (void)
 This function realeases the memory that is used by the current list of primitives and resets the list.
static PrmFirst (void)
 This function returns a pointer to the first primitive of the current list.
static PrmLast (void)
 This function returns a pointer to the last primitive of the current list.
static void SelectAll (void)
 This function selects all the primitives in the current list of primitives, i.e.
static void UnselectAll (void)
 This function unselects all the primitives in the current list of primitives, i.e.
static int GetGlobalBox (double *xmin, double *xmax, double *ymin, double *ymax)
 This function returns the limiting rectangle that involves all the primitives in the current list.
static const double COORD_TOL = 0.001
 Coordinate tolerance value.
void Reset (void)
 This function sets a null value for the next and previous pointers, sets an undefined primitive type, and sets a null color, selection flag, and height values.
void InsertFront (void)
 This function inserts the current primitive at the beginning of the list of primitives.
void InsertBack (void)
 This function inserts the current primitive at the end of the list of primitives.
void RemoveFromList (void)
 This function removes the current primitive from the list.
static Prmprm_head = 0L
 Head of doubly-linked list of primitives.

Public Types

enum  Type { PRM_UNDEF, PRM_QUAD, PRM_CIRC, NumPrmTypes }
 Primitive types. More...

Public Member Functions

virtual void Read (FILE *fd)=0
 This function reads geometry data of a primitive from a file (given by its pointer) and loads the data into the primitive attributes.
virtual void Write (FILE *fd)=0
 This function writes the geometry attribute data of a primitive to a file (given by its pointer).
virtual int GetNPts (void)=0
 This function returns (as its value) the number of vertices of the current primitive.
virtual void SetCoords (int id, double x, double y)=0
 This function replaces the x and y coordinates of a vertex of the current primitive by the given pair of coordinates.
virtual void GetCoords (int id, double *x, double *y)=0
 This function returns the x and y coordinates of a vertex of the current primitive.
virtual void Set1stPt (double x, double y)=0
 This function is used during interactive construction of a primitive.
virtual void Set2ndPt (double x, double y)=0
 This function is used during interactive construction of a primitive.
virtual int PickArea (double x, double y)=0
 This function checks whether a given point is in the interior of a primitive.
virtual int PickVertex (double x, double y, double tol, int *id)=0
 This function selects a vertex on the boundary of a primitive based on the given point position.
virtual int PickSide (double x, double y, double tol, int *id)=0
 This function selects a side on the boundary of a primitive based on the given point position.
virtual void Translate (double dx, double dy)=0
 This function translates the current primitive All the vertices of the primitive are translated by the given translation factors.
virtual void TranslateVertex (int id, double dx, double dy)=0
 This function translates a vertex of a primitive using the given translation factors.
virtual void TranslateSide (int id, double dx, double dy)=0
 This function translates the two vertices of a side of a primitive using the given translation factors.
virtual void GetBox (double *xmin, double *xmax, double *ymin, double *ymax)=0
 This function returns the limiting rectangle that involves the current primitive.
virtual void DisplayBoundary (void)=0
 This function displays the boundary of the current primitive.
virtual void DisplayInterior (void)=0
 This function displays the interior of the current primitive The interior area is filled with the currently specified background color.
virtual void DisplaySolid (void)=0
 Function to display a solid version of the current primitive.
virtual void HighltSolid (void)=0
 Function to highlight a solid version of the current primitive.
virtual void DisplayZbuffer (void)=0
 Function to send a solid version of the current primitive to the zbuffer module to be projected and displayed.

Static Public Member Functions

static double ABS (double x)
 This function returns the absolute value of a double.

Protected Attributes

Type type
 Primitive type.
int sel
 Flag for selected primitive.
long int color
 Coded RGB color.
double height
 Height of primitive (only used in 3D).

Private Attributes

Prmnext
 Next primitive in linked list.
Prmprev
 Previous primitive in linked list.

Classes

struct  Coord
 Primitive vertex coordinate structure. More...


Member Enumeration Documentation

enum Prm::Type
 

Primitive types.

Enumeration values:
PRM_UNDEF  Undefined primitive.
PRM_QUAD  Quadrilateral primitive.
PRM_CIRC  Circle primitive.
NumPrmTypes  Total number of primitives.

Definition at line 77 of file prm.h.


Constructor & Destructor Documentation

Prm::Prm  ) 
 

This function creates a new primitive, 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.

Definition at line 57 of file prm.cpp.

References InsertFront(), and Reset().

Prm::Prm int  back  ) 
 

This function creates a new primitive, 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 65 of file prm.cpp.

References InsertBack(), InsertFront(), and Reset().

Prm::~Prm  )  [virtual]
 

This function removes a 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 76 of file prm.cpp.

References RemoveFromList().


Member Function Documentation

static double Prm::ABS double  x  )  [inline, static]
 

This function returns the absolute value of a double.

Definition at line 123 of file prm.h.

Referenced by Quad::PickVertex(), Circ::PickVertex(), and Dsp::ShadeColor().

int Prm::CheckSelected void   ) 
 

This function returns the selection status (false = 0; true = 1) of the current primitive.

Returns:
Selection flag (false = 0; true = 1) of the given primitive.

Definition at line 340 of file prm.cpp.

References sel.

Referenced by Dsp::Model().

void Prm::DeleteList void   )  [static]
 

This function realeases the memory that is used by the current list of primitives and resets the list.

The function sets a null value for its head pointer.

Definition at line 88 of file prm.cpp.

References prm_head.

Referenced by Prj::OpenModel(), and Prj::Quit().

virtual void Prm::DisplayBoundary void   )  [pure virtual]
 

This function displays the boundary of the current primitive.

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.

Implemented in Circ, and Quad.

virtual void Prm::DisplayInterior void   )  [pure virtual]
 

This function displays the interior of the current primitive The interior area is filled with the currently specified background color.

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.

Implemented in Circ, and Quad.

virtual void Prm::DisplaySolid void   )  [pure virtual]
 

Function to display a solid version of the current 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 solid prism faces with the current color. It uses OpenGL display functions.

Implemented in Circ, and Quad.

Referenced by Dsp::DisplayPrm().

virtual void Prm::DisplayZbuffer void   )  [pure virtual]
 

Function to send a solid version of the current 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.

Implemented in Circ, and Quad.

Referenced by Dsp::ZbfModel().

Prm * Prm::First void   )  [static]
 

This function returns a pointer to the first primitive of the current list.

Returns:
Pointer to first primitive. If the list is empty, it returns a null pointer.

Definition at line 98 of file prm.cpp.

References prm_head.

Referenced by Prj::BuildDisplayList(), drvRedisplay(), GetGlobalBox(), Prj::GetHeightFac(), Dsp::Model(), Prj::PckPrm(), SelectAll(), Prj::SetHeightFac(), UnselectAll(), PrmIO::WriteList(), Dsp::ZbfModel(), and Prj::ZbufferSnapShot().

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

This function returns the limiting rectangle that involves the current 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)

Implemented in Circ, and Quad.

Referenced by GetGlobalBox().

long int Prm::GetColor void   ) 
 

This function returns the color of the current primitive.

The color is returned in a long integer with a coded RGB color (adopted in the CD graphics system).

Returns:
Coded RGB color of given primitive.

Definition at line 354 of file prm.cpp.

References color.

Referenced by Dsp::DisplayPrm(), and PrmIO::WriteList().

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

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

The vertex is indicated by an index to the local array of vertices of the primitive. Nothing will happen if the given index is outside the range of valid indices of vertices.

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

Implemented in Circ, and Quad.

int Prm::GetGlobalBox double *  xmin,
double *  xmax,
double *  ymin,
double *  ymax
[static]
 

This function returns the limiting rectangle that involves all the primitives in the current list.

This rectangle is the bounding box of the current set of primitives, which is parallel to the x and y axes, with the minimum and maximum x and y coordinates of all primitive's vertices.

Parameters:
xmin,xmax - limiting x coordinates of all primitives (out)
ymin,ymax - limiting y coordinates of all primitives (out)
Returns:
If the list of primitives is empty, a false (0) status is returned. Otherwise, a true (1) status is returned.

Definition at line 139 of file prm.cpp.

References First(), GetBox(), Next(), next, and prm_head.

Referenced by Prj::OpenModel().

double Prm::GetHeight void   ) 
 

This function returns the height of the given primitive.

The height is used only in 3D applications.

Returns:
Height of given primitive (3D only).

Definition at line 368 of file prm.cpp.

References height.

Referenced by Prj::GetHeightFac(), and PrmIO::WriteList().

virtual int Prm::GetNPts void   )  [pure virtual]
 

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

Returns:
The number of vertices of the given primitive.

Implemented in Circ, and Quad.

Prm::Type Prm::GetType void   ) 
 

This function returns (as its value) a code indicating the type of the current primitive.

Returns:
The type the given primitive.

Definition at line 319 of file prm.cpp.

References type.

Referenced by PrmIO::WriteList().

virtual void Prm::HighltSolid void   )  [pure virtual]
 

Function to highlight a solid version of the current 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.

Implemented in Circ, and Quad.

Referenced by Dsp::HighltPrm().

void Prm::InsertBack void   )  [private]
 

This function inserts the current primitive at the end of the list of primitives.

It handles the case of an empty list (this is indicated by a null head pointer). In this case, it sets the previous and next pointers of the current primitive pointing to itself. Otherwise, it sets the next pointer of the current primitive to point to the first primitive, sets the previous pointer of the current primitive to point to the last primitive, sets the previous pointer of the first primitive to point to the current primitive, and sets the next pointer of the last primitive to point to the current primitive. If the list is not empty, the list head pointer is not changed.

Definition at line 207 of file prm.cpp.

References next, prev, and prm_head.

Referenced by MoveBack(), and Prm().

void Prm::InsertFront void   )  [private]
 

This function inserts the current primitive at the beginning of the list of primitives.

It handles the case of an empty list (this is indicated by a null head pointer). In this case, it sets the previous and next pointers of the current primitive pointing to itself. Otherwise, it sets the next pointer of the current primitive to point to the first primitive, sets the previous pointer of the current primitive to point to the last primitive, sets the previous pointer of the first primitive to point to the current primitive, and sets the next pointer of the last primitive to point to the current primitive. In any case, the list head pointer will point to the current primitive.

Definition at line 186 of file prm.cpp.

References next, prev, and prm_head.

Referenced by MoveFront(), and Prm().

Prm * Prm::Last void   )  [static]
 

This function returns a pointer to the last primitive of the current list.

Returns:
Pointer to last primitive. If the list is empty, it returns a null pointer.

Definition at line 105 of file prm.cpp.

References prev, and prm_head.

void Prm::MoveBack void   ) 
 

This function moves the current primitive to the last position in the list of primitives.

Nothing will happen if the given primitive is already the last of the list.

Definition at line 298 of file prm.cpp.

References InsertBack(), prev, prm_head, and RemoveFromList().

Referenced by PrmIO::Interpret().

void Prm::MoveFront void   ) 
 

This function moves the current primitive to the first position in the list of primitives.

The head pointer to the list is modified accordingly. Nothing will happen if the given primitive is already the first of the list.

Definition at line 277 of file prm.cpp.

References InsertFront(), prm_head, and RemoveFromList().

Referenced by PrmIO::Interpret().

Prm * Prm::Next void   ) 
 

This function returns a pointer to the next primitive in relation to the current primitive.

Returns:
Pointer to next primitive. If the given primitive is the last in the list, a null pointer is returned.

Definition at line 257 of file prm.cpp.

References next, prev, and prm_head.

Referenced by GetGlobalBox(), Dsp::Model(), Prj::PckPrm(), SelectAll(), UnselectAll(), PrmIO::WriteList(), and Dsp::ZbfModel().

virtual int Prm::PickArea double  x,
double  y
[pure virtual]
 

This function checks whether a given point is in the interior of a primitive.

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.

Implemented in Circ, and Quad.

Referenced by Prj::PckPrm().

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

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

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 target 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.

Implemented in Circ, and Quad.

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

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

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 on the boundary of the primitive, the function returns a true (1) status and returns the index of the found vertex. Otherwise, the function returns a false (0) status.

Implemented in Circ, and Quad.

Prm * Prm::Previous void   ) 
 

This function returns a pointer to the previous primitive in relation to the given current primitive.

Returns:
Pointer to previous primitive. If the given primitive is the first in the list, a null pointer is returned.

Definition at line 267 of file prm.cpp.

References prev, and prm_head.

virtual void Prm::Read FILE *  fd  )  [pure virtual]
 

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

Parameters:
fd - ponter to file descriptor (in)

Implemented in Circ, and Quad.

Referenced by PrmIO::Interpret().

void Prm::RemoveFromList void   )  [private]
 

This function removes the current primitive from the list.

The primitive removal from list modifies the next pointer of the previous primitive in the list and modifies the previous pointer of the next primitive in the list. This function also treates the situation of a single primitive list, in which case the list head pointer is reset to a null value. Otherwise, the list head pointer will be affected only in the case in which the primitive being removed is at the beginning of the list: the new list head pointer will point to the primitive next to the primitive being removed.

Definition at line 228 of file prm.cpp.

References next, prev, and prm_head.

Referenced by MoveBack(), MoveFront(), and ~Prm().

void Prm::Reset void   )  [private]
 

This function sets a null value for the next and previous pointers, sets an undefined primitive type, and sets a null color, selection flag, and height values.

Definition at line 172 of file prm.cpp.

References color, height, next, prev, PRM_UNDEF, sel, and type.

Referenced by Prm().

void Prm::Select void   ) 
 

This function selects the current primitive, i.e.

, it sets the selection flag of the primitive.

Definition at line 326 of file prm.cpp.

References sel.

Referenced by Prj::SelectPrm().

void Prm::SelectAll void   )  [static]
 

This function selects all the primitives in the current list of primitives, i.e.

, it sets the selection flag of all the primitives.

Definition at line 115 of file prm.cpp.

References First(), Next(), and sel.

virtual void Prm::Set1stPt double  x,
double  y
[pure virtual]
 

This function is used during interactive construction of a primitive.

It sets the x and y coordinates of the first construction point of the current primitive by the given pair of coordinates.

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

Implemented in Circ, and Quad.

virtual void Prm::Set2ndPt double  x,
double  y
[pure virtual]
 

This function is used during interactive construction of a primitive.

It sets the x and y coordinates of the second construction point of the current primitive by the given pair of coordinates.

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

Implemented in Circ, and Quad.

void Prm::SetColor long int  color  ) 
 

This function sets the color of the current primitive.

The color is given by a long integer with a coded RGB color (adopted in the CD graphics system).

Parameters:
color - coded RGB color (in)

Definition at line 347 of file prm.cpp.

Referenced by PrmIO::Interpret().

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

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

The vertex is indicated by an index to the local array of vertices of the primitive. Nothing will happen if the given index is outside the range of valid indices of vertices.

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

Implemented in Circ, and Quad.

void Prm::SetHeight double  height  ) 
 

This function sets the height of the current primitive.

The height is used only in 3D applications.

Parameters:
height - height of primitive (3D only) (in)

Definition at line 361 of file prm.cpp.

Referenced by PrmIO::Interpret(), and Prj::SetHeightFac().

virtual void Prm::Translate double  dx,
double  dy
[pure virtual]
 

This function translates the current primitive All the vertices of the primitive are translated by the given translation factors.

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

Implemented in Circ, and Quad.

Referenced by PrmIO::Interpret().

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

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

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

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

Implemented in Circ, and Quad.

Referenced by PrmIO::Interpret().

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

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

The target vertex is indicated by its index to the primitive coordinate vector, which should have a value between 0 and the number of vertices minus one. Nothing will happen if the given index is outside this range.

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

Implemented in Circ, and Quad.

Referenced by PrmIO::Interpret().

void Prm::Unselect void   ) 
 

This function unselects the given current primitive, i.e.

, it resets (sets to null) the selection flag of the primitive.

Definition at line 333 of file prm.cpp.

References sel.

void Prm::UnselectAll void   )  [static]
 

This function unselects all the primitives in the current list of primitives, i.e.

, it resets (sets to null) the selection flag of all the primitives.

Definition at line 127 of file prm.cpp.

References First(), Next(), and sel.

Referenced by Prj::SelectPrm().

virtual void Prm::Write FILE *  fd  )  [pure virtual]
 

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

Parameters:
fd - ponter to file descriptor (in)

Implemented in Circ, and Quad.

Referenced by PrmIO::WriteList().


Member Data Documentation

long int Prm::color [protected]
 

Coded RGB color.

Definition at line 158 of file prm.h.

Referenced by Quad::DisplayZbuffer(), Circ::DisplayZbuffer(), GetColor(), and Reset().

const double Prm::COORD_TOL = 0.001 [static]
 

Coordinate tolerance value.

Definition at line 48 of file prm.cpp.

Referenced by Circ::TranslateVertex().

double Prm::height [protected]
 

Height of primitive (only used in 3D).

Definition at line 161 of file prm.h.

Referenced by Quad::BuildSolidPrm(), Quad::DisplaySolid(), Circ::DisplaySolid(), Quad::DisplayZbuffer(), Circ::DisplayZbuffer(), GetHeight(), Quad::HighltSolid(), Circ::HighltSolid(), and Reset().

Prm* Prm::next [private]
 

Next primitive in linked list.

Definition at line 141 of file prm.h.

Referenced by GetGlobalBox(), InsertBack(), InsertFront(), Next(), RemoveFromList(), and Reset().

Prm* Prm::prev [private]
 

Previous primitive in linked list.

Definition at line 144 of file prm.h.

Referenced by InsertBack(), InsertFront(), Last(), MoveBack(), Next(), Previous(), RemoveFromList(), and Reset().

Prm * Prm::prm_head = 0L [static, private]
 

Head of doubly-linked list of primitives.

Definition at line 44 of file prm.cpp.

Referenced by DeleteList(), First(), GetGlobalBox(), InsertBack(), InsertFront(), Last(), MoveBack(), MoveFront(), Next(), Previous(), and RemoveFromList().

int Prm::sel [protected]
 

Flag for selected primitive.

Definition at line 155 of file prm.h.

Referenced by CheckSelected(), Reset(), Select(), SelectAll(), Unselect(), and UnselectAll().

Type Prm::type [protected]
 

Primitive type.

Definition at line 152 of file prm.h.

Referenced by Circ::Circ(), GetType(), Quad::Quad(), and Reset().


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