JWS C++ Library
C++ language utility library
jwscxx::graphics::Polygon_d Class Reference

3D polygon in double precision floating point. More...

#include <polygon.h>

Inheritance diagram for jwscxx::graphics::Polygon_d:
Collaboration diagram for jwscxx::graphics::Polygon_d:

List of all members.

Public Member Functions

 Polygon_d ()
 Constructs a polygon.
 Polygon_d (uint32_t N)
 Constructs a polygon.
 Polygon_d (const Polygon_d &p)
 Constructs a polygon by copying another.
 Polygon_d (const char *fname) throw (jwscxx::base::Arg_error, jwscxx::base::IO_error)
 Reads a polygon from an input file.
 Polygon_d (std::istream &in) throw (jwscxx::base::Arg_error, jwscxx::base::IO_error)
 Reads a polygon from an input stream.
virtual ~Polygon_d ()
 Deletes this polygon.
virtual Polygon_doperator= (const Polygon_d &p)
 Copies a polygon into this polygon.
virtual Polygon_dclone () const
 Clones this polygon.
virtual void read (std::istream &in) throw (jwscxx::base::IO_error, jwscxx::base::Arg_error)
 Reads this polygon from an input stream.
virtual void write (std::ostream &out) const throw (jwscxx::base::IO_error)
 Writes this polygon to an output stream.
virtual void transform (const jwsc::Matrix_d *M) throw (jwscxx::base::Arg_error)
 Applies a linear transformation to this polygon.
virtual void wire_render () const
 Renders this polygon with the GL as a wire-frame.
virtual void wire_occlude_render () const
 Renders this polygon with the GL as an occluded wire-frame into the depth buffer, to hide unseen lines.
virtual void wire_occluded_silhouette_render (std::vector< bool > &iVector, bool &iBool) const
 Renders this polygon with the GL as a part of the silhouette, into the depth buffer, to hide unseen lines. The only edges that need to be rendered are those that are atually part of the silhouette. iVector contains a boolean for each edge, specifying whether that edge is part of the silhouette or not. iBool is set to true when the face is visible and needs to be taken into account for occlusions.
virtual void solid_render () const
 Renders this polygon with the GL as a solid.
void add_point (jwsc::Vector_d *pt) throw (jwscxx::base::Arg_error)
 Adds a point to the end of the collection of this polygon's points.
void add_point (double x, double y, double z) throw (jwscxx::base::Arg_error)
 Adds a point to the end of the collection of this polygon's points.
const jwsc::Vector_d * get_normal () const
 Returns the normal vector for this polygon.
const jwsc::Vector_d * get_centroid () const
 Returns the centroid vector for this polygon.
size_t get_num_points () const
 Returns the number of points in this polygon.
const jwsc::Vector_d * get_point (size_t i) const throw (jwscxx::base::Arg_error)
 Returns an indexed polygon point.
void flip_normal ()
 Flips the direction of the normal vector.
void project ()
 Projects this polygon into the current GL view.
uint8_t is_visible (const Camera_d *camera) const
 Returns whether this polygon is visible under a camera.
uint8_t is_visible_up_to_epsilon (const Camera_d *camera, double &epsilon) const
 Returns whether this polygon is visible under a camera. This function returns true if the dot product between the view vector and the surface normal is bigger than epsilon. This is useful for determining polygons very close to the silhouette that may occlude it.
uint32_t get_id () const
 Returns the ID of the polygon.
void set_id (uint32_t id)
 Sets the ID of the polygon.

Protected Member Functions

void update_normal ()
 Updates the normal vector of this polygon.
void update_centroid ()
 Updates the centroid vector of this polygon.

Protected Attributes

std::vector< jwsc::Vector_d * > pts
 3D points defining the polygon.
jwsc::Vector_d * normal
 Normal vector for orientation.
jwsc::Vector_d * centroid
 Center of mass of the polygon (assuming uniform density).
uint8_t normal_flipped
 Indicates whether or not to flip the direction of the normal.
uint32_t id
 Unique ID.

Static Private Member Functions

static uint32_t generate_id ()
 Generates a unique ID for a polygon.

Detailed Description

3D polygon in double precision floating point.

Base configuration of the polygon is centered on the origin of the xy-plane with normal vector aligned on the +z-axis.

Definition at line 276 of file polygon.h.


Constructor & Destructor Documentation

Polygon_d::Polygon_d ( )

Constructs a polygon.

The constructed polygon has no points.

Definition at line 1127 of file polygon.cpp.

Polygon_d::Polygon_d ( uint32_t  N)

Constructs a polygon.

The constructed polygon has no points, but space is reserved for N of them.

Parameters:
NNumber of points that the polygon will contain.

Definition at line 1142 of file polygon.cpp.

Polygon_d::Polygon_d ( const Polygon_d p)

Constructs a polygon by copying another.

Parameters:
pPolygon to copy into this one.

Definition at line 1153 of file polygon.cpp.

Polygon_d::Polygon_d ( const char *  fname) throw (jwscxx::base::Arg_error, jwscxx::base::IO_error)

Reads a polygon from an input file.

The file format is big-endian binary.

Parameters:
fnameInput file to read this polygon from.
Exceptions:
jwscxx::base::IO_errorCould not read from in.
jwscxx::base::Arg_errorInvalid arguments in file to read from.

Definition at line 1170 of file polygon.cpp.

Polygon_d::Polygon_d ( std::istream &  in) throw (jwscxx::base::Arg_error, jwscxx::base::IO_error)

Reads a polygon from an input stream.

The file format is big-endian binary.

Parameters:
inInput stream to read this polygon from.
Exceptions:
jwscxx::base::IO_errorCould not read from in.
jwscxx::base::Arg_errorInvalid arguments in file to read from.

Definition at line 1189 of file polygon.cpp.

Polygon_d::~Polygon_d ( ) [virtual]

Deletes this polygon.

Frees all space allocated by this polygon.

Definition at line 1201 of file polygon.cpp.


Member Function Documentation

Polygon_d & Polygon_d::operator= ( const Polygon_d p) [virtual]

Copies a polygon into this polygon.

Performs a deep copy of the points in p into this polygon.

Parameters:
pPolygon to copy into this one.
Returns:
A reference to this polygon.

Definition at line 1220 of file polygon.cpp.

Polygon_d * Polygon_d::clone ( ) const [virtual]

Clones this polygon.

Returns:
A new copy of this polygon.

Implements jwscxx::base::Cloneable.

Definition at line 1273 of file polygon.cpp.

void Polygon_d::read ( std::istream &  in) throw (jwscxx::base::IO_error, jwscxx::base::Arg_error) [virtual]

Reads this polygon from an input stream.

Parameters:
inInput stream to read the members of this polygon from.
Exceptions:
jwscxx::base::IO_errorCould not read from in.
jwscxx::base::Arg_errorInvalid arguments to read from the file.

Implements jwscxx::base::Readable.

Definition at line 1285 of file polygon.cpp.

void Polygon_d::write ( std::ostream &  out) const throw (jwscxx::base::IO_error) [virtual]

Writes this polygon to an output stream.

The file format is big-endian binary.

Parameters:
outOutput stream to write the members of this polygon to.
Exceptions:
jwscxx::base::IO_errorCould not write to out.

Implements jwscxx::base::Writeable.

Definition at line 1438 of file polygon.cpp.

void Polygon_d::transform ( const jwsc::Matrix_d *  M) throw (jwscxx::base::Arg_error) [virtual]

Applies a linear transformation to this polygon.

Parameters:
MHomogeneous transformation matrix to transform this polygon by.
Exceptions:
jwscxx::base::Arg_errorThe matrix is not in 4x4 homogeneous coordinates.

Implements jwscxx::graphics::Transformable_d.

Definition at line 1563 of file polygon.cpp.

void Polygon_d::wire_render ( ) const [virtual]

Renders this polygon with the GL as a wire-frame.

Does not set color or material effects.

Implements jwscxx::graphics::Wire_renderable.

Definition at line 1591 of file polygon.cpp.

void Polygon_d::wire_occlude_render ( ) const [virtual]

Renders this polygon with the GL as an occluded wire-frame into the depth buffer, to hide unseen lines.

Does not render into the color buffer, only the depth buffer.

After calling this method, call wire_render() to render the polygon with hidden lines occluded.

Implements jwscxx::graphics::Wire_occlude_renderable.

Definition at line 1625 of file polygon.cpp.

void Polygon_d::wire_occluded_silhouette_render ( std::vector< bool > &  iVector,
bool &  visible 
) const [virtual]

Renders this polygon with the GL as a part of the silhouette, into the depth buffer, to hide unseen lines. The only edges that need to be rendered are those that are atually part of the silhouette. iVector contains a boolean for each edge, specifying whether that edge is part of the silhouette or not. iBool is set to true when the face is visible and needs to be taken into account for occlusions.

Does not render into the color buffer, only the depth buffer.

After calling this method, call wire_render() to render the silhouette of the polygon.

Parameters:
iVectorinput vector containing a boolean for each edge, that must be set to true if the edge is visible
iVisibleset it to true if the polygon is visibile

Definition at line 1683 of file polygon.cpp.

void Polygon_d::solid_render ( ) const [virtual]

Renders this polygon with the GL as a solid.

Does not set color or material effects.

Implements jwscxx::graphics::Solid_renderable.

Definition at line 1738 of file polygon.cpp.

void Polygon_d::add_point ( jwsc::Vector_d *  pt) throw (jwscxx::base::Arg_error)

Adds a point to the end of the collection of this polygon's points.

The point to add must be in homogeneous coordinates (x,y,z,w) and be in the plane containing the points already in the polygon.

Parameters:
ptPoint to add.
Exceptions:
jwscxx::base::Arg_errorThe point to add is not in the plane already containing the polygon, or is not in homogeneous coordinates (length 4).

Definition at line 1797 of file polygon.cpp.

void Polygon_d::add_point ( double  x,
double  y,
double  z 
) throw (jwscxx::base::Arg_error)

Adds a point to the end of the collection of this polygon's points.

The point to add must be in the plane containing the points already in the polygon.

Parameters:
xX-coord of the point to add.
yY-coord of the point to add.
zY-coord of the point to add.
Exceptions:
jwscxx::base::Arg_errorThe point to add is not in the plane already containing the polygon.

Definition at line 1770 of file polygon.cpp.

const jwsc::Vector_d * Polygon_d::get_normal ( ) const

Returns the normal vector for this polygon.

The vector is in homogeneous coordinates x, y, z, w, normalized over x, y, z and w = 1.

Definition at line 1841 of file polygon.cpp.

const jwsc::Vector_d * Polygon_d::get_centroid ( ) const

Returns the centroid vector for this polygon.

The vector is in homogeneous coordinates x, y, z, w.

Definition at line 1850 of file polygon.cpp.

size_t Polygon_d::get_num_points ( ) const

Returns the number of points in this polygon.

Definition at line 1856 of file polygon.cpp.

const jwsc::Vector_d * Polygon_d::get_point ( size_t  i) const throw (jwscxx::base::Arg_error)

Returns an indexed polygon point.

Parameters:
iIndex of the point to get; indexing begins with zero.
Returns:
The specified polygon point.
Exceptions:
jwscxx::base::Arg_errorInvalid point index.

Definition at line 1869 of file polygon.cpp.

void Polygon_d::flip_normal ( )

Flips the direction of the normal vector.

The normal vector is created by crossing a vector made from the first two points with a vector made with the first and last points. This function flips ths order of that operation and reverses the direction of the normal.

Definition at line 1887 of file polygon.cpp.

void Polygon_d::project ( )

Projects this polygon into the current GL view.

The polygon points are transformed and projected onto the view plane by the current modelview and projection matrix on the GL stack.

The origin of the view plane coordinate system is in the lower left corner and its extents are defined by the current GL viewport size.

Definition at line 1901 of file polygon.cpp.

uint8_t Polygon_d::is_visible ( const Camera_d camera) const

Returns whether this polygon is visible under a camera.

Parameters:
cameraCamera to use to test visibility.
Returns:
1 if the polygon is visible; 0 otherwise.

Definition at line 1951 of file polygon.cpp.

uint8_t Polygon_d::is_visible_up_to_epsilon ( const Camera_d camera,
double &  epsilon 
) const

Returns whether this polygon is visible under a camera. This function returns true if the dot product between the view vector and the surface normal is bigger than epsilon. This is useful for determining polygons very close to the silhouette that may occlude it.

Parameters:
cameraCamera to use to test visibility.
epsilonThe positive constant determining when a poloygon is to be considered visible
Returns:
1 if the dot product between the view vector and the surface normal is bigger than epsilon; 0 otherwise.

Definition at line 1974 of file polygon.cpp.

uint32_t Polygon_d::get_id ( ) const

Returns the ID of the polygon.

Definition at line 1991 of file polygon.cpp.

void Polygon_d::set_id ( uint32_t  id)

Sets the ID of the polygon.

Definition at line 1997 of file polygon.cpp.

void Polygon_d::update_normal ( ) [protected]

Updates the normal vector of this polygon.

Does nothing if this polygon has fewer than 3 points. The update is done by crossing the vectors created from the first, second and last points in this polygon.

Definition at line 2008 of file polygon.cpp.

void Polygon_d::update_centroid ( ) [protected]

Updates the centroid vector of this polygon.

Does nothing if this polygon has zero points. The update is done with the following equation:

Definition at line 2070 of file polygon.cpp.

uint32_t Polygon_d::generate_id ( ) [static, private]

Generates a unique ID for a polygon.

Definition at line 2163 of file polygon.cpp.


Member Data Documentation

std::vector<jwsc::Vector_d*> jwscxx::graphics::Polygon_d::pts [protected]

3D points defining the polygon.

Definition at line 435 of file polygon.h.

jwsc::Vector_d* jwscxx::graphics::Polygon_d::normal [protected]

Normal vector for orientation.

Definition at line 438 of file polygon.h.

jwsc::Vector_d* jwscxx::graphics::Polygon_d::centroid [protected]

Center of mass of the polygon (assuming uniform density).

Definition at line 441 of file polygon.h.

Indicates whether or not to flip the direction of the normal.

Definition at line 447 of file polygon.h.

uint32_t jwscxx::graphics::Polygon_d::id [protected]

Unique ID.

Definition at line 450 of file polygon.h.


The documentation for this class was generated from the following files: