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

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

#include <polygon.h>

Inheritance diagram for jwscxx::graphics::Polygon_f:
Collaboration diagram for jwscxx::graphics::Polygon_f:

List of all members.

Public Member Functions

 Polygon_f ()
 Constructs a polygon.
 Polygon_f (uint32_t N)
 Constructs a polygon.
 Polygon_f (const Polygon_f &p)
 Constructs a polygon by copying another.
 Polygon_f (const char *fname) throw (jwscxx::base::Arg_error, jwscxx::base::IO_error)
 Reads a polygon from an input file.
 Polygon_f (std::istream &in) throw (jwscxx::base::Arg_error, jwscxx::base::IO_error)
 Reads a polygon from an input stream.
virtual ~Polygon_f ()
 Deletes this polygon.
virtual Polygon_foperator= (const Polygon_f &p)
 Copies a polygon into this polygon.
virtual Polygon_fclone () 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_f *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_f *pt) throw (jwscxx::base::Arg_error)
 Adds a point to the end of the collection of this polygon's points.
void add_point (float x, float y, float z) throw (jwscxx::base::Arg_error)
 Adds a point to the end of the collection of this polygon's points.
const jwsc::Vector_f * get_normal () const
 Returns the normal vector for this polygon.
const jwsc::Vector_f * 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_f * 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_f *camera) const
 Returns whether this polygon is visible under a camera.
uint8_t is_visible_up_to_epsilon (const Camera_d *camera, float &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_f * > pts
 3D points defining the polygon.
jwsc::Vector_f * normal
 Normal vector for orientation.
jwsc::Vector_f * 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 single 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 82 of file polygon.h.


Constructor & Destructor Documentation

Polygon_f::Polygon_f ( )

Constructs a polygon.

The constructed polygon has no points.

Definition at line 83 of file polygon.cpp.

Polygon_f::Polygon_f ( 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 98 of file polygon.cpp.

Polygon_f::Polygon_f ( const Polygon_f p)

Constructs a polygon by copying another.

Parameters:
pPolygon to copy into this one.

Definition at line 109 of file polygon.cpp.

Polygon_f::Polygon_f ( 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 126 of file polygon.cpp.

Polygon_f::Polygon_f ( 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 145 of file polygon.cpp.

Polygon_f::~Polygon_f ( ) [virtual]

Deletes this polygon.

Frees all space allocated by this polygon.

Definition at line 157 of file polygon.cpp.


Member Function Documentation

Polygon_f & Polygon_f::operator= ( const Polygon_f 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 176 of file polygon.cpp.

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

Clones this polygon.

Returns:
A new copy of this polygon.

Implements jwscxx::base::Cloneable.

Definition at line 229 of file polygon.cpp.

void Polygon_f::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 241 of file polygon.cpp.

void Polygon_f::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 394 of file polygon.cpp.

void Polygon_f::transform ( const jwsc::Matrix_f *  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_f.

Definition at line 519 of file polygon.cpp.

void Polygon_f::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 547 of file polygon.cpp.

void Polygon_f::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 581 of file polygon.cpp.

void Polygon_f::wire_occluded_silhouette_render ( std::vector< bool > &  iVector,
bool &  iVisible 
) 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 640 of file polygon.cpp.

void Polygon_f::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 694 of file polygon.cpp.

void Polygon_f::add_point ( jwsc::Vector_f *  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 753 of file polygon.cpp.

void Polygon_f::add_point ( float  x,
float  y,
float  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 726 of file polygon.cpp.

const jwsc::Vector_f * Polygon_f::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 797 of file polygon.cpp.

const jwsc::Vector_f * Polygon_f::get_centroid ( ) const

Returns the centroid vector for this polygon.

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

Definition at line 806 of file polygon.cpp.

size_t Polygon_f::get_num_points ( ) const

Returns the number of points in this polygon.

Definition at line 812 of file polygon.cpp.

const jwsc::Vector_f * Polygon_f::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 825 of file polygon.cpp.

void Polygon_f::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 843 of file polygon.cpp.

void Polygon_f::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 857 of file polygon.cpp.

uint8_t Polygon_f::is_visible ( const Camera_f 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 907 of file polygon.cpp.

uint8_t Polygon_f::is_visible_up_to_epsilon ( const Camera_d camera,
float &  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 930 of file polygon.cpp.

uint32_t Polygon_f::get_id ( ) const

Returns the ID of the polygon.

Definition at line 947 of file polygon.cpp.

void Polygon_f::set_id ( uint32_t  id)

Sets the ID of the polygon.

Definition at line 953 of file polygon.cpp.

void Polygon_f::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 964 of file polygon.cpp.

void Polygon_f::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 1026 of file polygon.cpp.

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

Generates a unique ID for a polygon.

Definition at line 1119 of file polygon.cpp.


Member Data Documentation

std::vector<jwsc::Vector_f*> jwscxx::graphics::Polygon_f::pts [protected]

3D points defining the polygon.

Definition at line 242 of file polygon.h.

jwsc::Vector_f* jwscxx::graphics::Polygon_f::normal [protected]

Normal vector for orientation.

Definition at line 245 of file polygon.h.

jwsc::Vector_f* jwscxx::graphics::Polygon_f::centroid [protected]

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

Definition at line 248 of file polygon.h.

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

Definition at line 254 of file polygon.h.

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

Unique ID.

Definition at line 257 of file polygon.h.


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