KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
kjb::Polymesh Class Reference

Abstract class of connected polygons (faces) forming a mesh. We assume that each edge is shared between exactly two faces, that is to say the mesh has to be fully connected. More...

#include <gr_polymesh.h>

Inheritance diagram for kjb::Polymesh:
kjb::Abstract_renderable kjb::Rigid_object kjb::Readable kjb::Writeable kjb::Renderable kjb::Solid_renderable kjb::Wire_renderable kjb::Wire_occlude_renderable kjb::Transformable kjb::Cloneable kjb::Frustum kjb::Parapiped kjb::Triangular_mesh

Public Member Functions

 Polymesh ()
 Constructs a triangular mesh. More...
 
 Polymesh (unsigned int n)
 
 Polymesh (const char *fname) throw (kjb::Illegal_argument, kjb::IO_error)
 Reads a triangular mesh from an input file. More...
 
 Polymesh (std::istream &in) throw (kjb::Illegal_argument, kjb::IO_error)
 Reads a triangular mesh from an input file. More...
 
 Polymesh (const Polymesh &t)
 Copy constructor. More...
 
virtual Polymeshoperator= (const Polymesh &t)
 Copies a triangular mesh into this one. More...
 
virtual Polymeshclone () const
 Clones this mesh. More...
 
virtual ~Polymesh ()
 Deletes this Polymesh. More...
 
unsigned int num_faces () const
 Returns the number of faces in this mesh. More...
 
const std::vector< kjb::Polygon > & get_faces () const
 Returns the faces of this mesh. More...
 
const kjb::Polygonget_face (unsigned int i) const throw (kjb::Index_out_of_bounds)
 Returns an indexed face. More...
 
kjb::Polygonget_face_ref (unsigned int i) throw (kjb::Index_out_of_bounds)
 Returns an indexed face. More...
 
virtual void add_face (const Polygon &face) throw (kjb::Illegal_argument)
 
virtual void read (std::istream &in) throw (kjb::IO_error,kjb::Illegal_argument)
 Reads this polymesh from an input stream. More...
 
virtual void write (std::ostream &ost) const throw (kjb::IO_error)
 Writes this mesh to an output stream. More...
 
virtual void write (const char *filename) const throw (IO_error)
 Writes this mesh to an output stream. More...
 
virtual void transform (const kjb::Matrix &) throw (kjb::Illegal_argument)
 Applies a linear transformation to this parallelepiped. More...
 
virtual void translate (double x, double y, double z)
 Translates this rigid object. More...
 
virtual void rotate (double phi, double x, double y, double z)
 
virtual void rotate (double dpitch, double dyaw, double droll)
 rotate this object around its x-axis by dpitch, the y-axis by dyaw, and its z-axis by droll (in this order, starting from the object's current position) More...
 
virtual void scale (double scale_x, double scale_y, double scale_z)
 
virtual unsigned int adjacent_face (unsigned int f, unsigned int e) const throw (Index_out_of_bounds,KJB_error)
 returns the index of the face adjacent to face f along edge e This is a very inefficient implementation, class derived from this one should implement their own version, possibly storing the adjacency information and not computing it every time. Not thoroughly tested More...
 
void get_faces (std::vector< const Polygon * > &ifaces) const
 
virtual void wire_render () const
 Renders this mesh as a wire frame. More...
 
unsigned int wire_render_with_sequential_ids (unsigned int start_id=1) const
 Render each edge of this polymesh with a different color. The first edge will be rendered using the input id as a color, the following edges will be rendered with an id sequentially increasing. Returns the id (color) used to render the last edge of the polygon. More...
 
unsigned int solid_render_with_sequential_ids (unsigned int start_id=1) const
 Render each polygon of this polymesh with a different color. The first polygon will be rendered using the input id as a color, the following ones will be rendered with an id sequentially increasing. Returns the id (color) used to render the last polygon. More...
 
virtual void wire_occlude_render () const
 Renders this mesh as a wire frame into the depth buffer. Use wire_render after this to render this mesh as a wire frame by not drawing occluded edges. More...
 
virtual void solid_render () const
 Renders this object with GL as a wire-frame. More...
 
virtual void silhouette_render (const kjb::Base_gl_interface &camera, double iwidth=1.0) const
 
virtual void project ()
 
double compute_surface_area () const
 Returns the surface area of the mesh. More...
 
void get_all_vertices (std::vector< Vector > &vertices) const
 Stores the vertices of the mesh in a vector. More...
 
void get_all_edges (std::vector< std::vector< Vector > > &edges) const
 Stores all of the unique pairs of points that make up the edges of the polymesh in a vector. More...
 
void get_lines (std::vector< Line3d > &lines)
 
void find_bounds ()
 
kjb::Vector get_center ()
 
double get_largest_z_bound ()
 
kjb::Vector get_largest_bounds () const
 
kjb::Vector get_smallest_bounds () const
 
- Public Member Functions inherited from kjb::Abstract_renderable
virtual ~Abstract_renderable ()
 Deletes this Solid_renderable. More...
 
virtual void render () const
 Renders this object with GL. More...
 
virtual void render_occluded_wireframe () const
 Renders this object with GL as an occluded wire-frame into the depth buffer, to hide unseen lines. More...
 
- Public Member Functions inherited from kjb::Renderable
virtual ~Renderable ()
 Deletes this Renderable. More...
 
- Public Member Functions inherited from kjb::Solid_renderable
virtual ~Solid_renderable ()
 Deletes this Wire_renderable. More...
 
- Public Member Functions inherited from kjb::Wire_renderable
virtual ~Wire_renderable ()
 Deletes this Wire_renderable. More...
 
- Public Member Functions inherited from kjb::Wire_occlude_renderable
virtual ~Wire_occlude_renderable ()
 Deletes this Wire_occlude_renderable. More...
 
- Public Member Functions inherited from kjb::Rigid_object
 Rigid_object ()
 
 Rigid_object (const Rigid_object &ro)
 
virtual Rigid_objectoperator= (const Rigid_object &src)
 
virtual ~Rigid_object ()
 
virtual void swap (Self &other)
 
virtual void compute_new_euler_angles_on_rotations (double dpitch, double dyaw, double droll, kjb::Vector &angles) const
 computes the new values for the object's euler angles, after a rotation of dpitch around the object's x-axis, a rotation of dyaw around the object's y axis, and a rotation of droll around the object's z axis (in this order, starting from the object's current position). The state of this rigid object is not changed More...
 
virtual void set_rotations (double pitch, double yaw, double roll)
 rotate this object so that its pitch, yaw and roll match the input values More...
 
virtual void set_rotations_and_translate (double pitch, double yaw, double roll, double dx, double dy, double dz)
 rotate this object so that its pitch, yaw and roll match the input values, and translates it More...
 
const Matrixget_rotations () const
 Returns the current transformation matrix, that is used to store the rotation to be applied to the object. More...
 
const Vectorget_euler_angles () const
 returns vector [pitch, yaw, roll] More...
 
void set_rotation_mode (kjb::Quaternion::Euler_mode imode)
 
const kjb::Quaternionget_orientation () const
 returns the quaternion defining this object's orientation More...
 
void set_orientation (const Quaternion &orientation)
 sets the orientation of this object from an input quaternion More...
 
- Public Member Functions inherited from kjb::Transformable
virtual ~Transformable ()
 Deletes this Transformable. More...
 
virtual ~Transformable ()
 Deletes this Transformable_d. More...
 
- Public Member Functions inherited from kjb::Cloneable
virtual ~Cloneable ()
 Deletes this Cloneable. More...
 
- Public Member Functions inherited from kjb::Readable
virtual ~Readable ()
 Deletes this Readable. More...
 
virtual void read (const char *fname)
 Reads this Readable from a file. More...
 
- Public Member Functions inherited from kjb::Writeable
virtual ~Writeable ()
 Deletes this Writeable. More...
 

Protected Member Functions

bool is_same_vertex (const kjb::Vector &p1, const kjb::Vector &p2) const
 Compares two points. More...
 
bool is_shared_edge (const Polygon &f1, unsigned int e1, const Polygon &f2, unsigned int e2) const throw (Index_out_of_bounds)
 Checks whether edge e1 on face f1 is the same as edge e2 on face f2. More...
 
bool edge_index_in_polygon (const Polygon &f1, unsigned int e, const Polygon &f2, unsigned int &index) throw (Index_out_of_bounds)
 

Protected Attributes

std::vector< kjb::Polygon_faces
 Polygons defining the mesh. More...
 
Vector smallest_bounds
 
Vector largest_bounds
 

Friends

class GL_Polymesh_Renderer
 

Additional Inherited Members

- Static Public Member Functions inherited from kjb::Abstract_renderable
static double get_rendering_framework ()
 returns the rendering framework used to render. The only one implemented up to now is OpenGL More...
 
static void set_rendering_framework (unsigned int irf)
 sets the rendering framework used to render. The only one implemented up to now is OpenGL More...
 
- Static Public Member Functions inherited from kjb::Readable
static const char * read_field_value (std::istream &in, const char *field_name, char *field_buf, size_t buf_len, char separator=':')
 Reads a line off in into a buffer and returns a pointer to the field value in the buffer. More...
 
static const char * read_field_value (std::istream &in, const char *field_name, char separator=':')
 Reads a line off in into an internal buffer and returns a pointer to the field value in the buffer. More...
 
- Protected Types inherited from kjb::Abstract_renderable
enum  Rendering_frameworks { RI_OPENGL }
 
- Static Protected Attributes inherited from kjb::Abstract_renderable
static unsigned int _rendering_framework = kjb::Abstract_renderable::RI_OPENGL
 

Detailed Description

Abstract class of connected polygons (faces) forming a mesh. We assume that each edge is shared between exactly two faces, that is to say the mesh has to be fully connected.

Constructor & Destructor Documentation

kjb::Polymesh::Polymesh ( )
inline

Constructs a triangular mesh.

Polymesh::Polymesh ( unsigned int  n)

Constructs a polymesh with n empty polygons

Parameters
nthe number of polygons This creates a polymesh containing n polygons
Polymesh::Polymesh ( const char *  fname)
throw (kjb::Illegal_argument,
kjb::IO_error
)

Reads a triangular mesh from an input file.

The file format is big-endian binary.

Parameters
fnameInput file to read this mesh from.
Exceptions
kjb::IO_errorCould not read from in.
kjb::Illegal_argumentInvalid arguments in file to read from.
Polymesh::Polymesh ( std::istream &  in)
throw (kjb::Illegal_argument,
kjb::IO_error
)

Reads a triangular mesh from an input file.

The file format is big-endian binary.

Parameters
inInput stream to read this mesh from.
Exceptions
kjb::IO_errorCould not read from in.
kjb::Illegal_argumentInvalid arguments in file to read from.
Polymesh::Polymesh ( const Polymesh src)

Copy constructor.

Parameters
tMesh to copy into this one.
Polymesh::~Polymesh ( )
virtual

Deletes this Polymesh.

Frees all space allocated by this mesh.

Member Function Documentation

void Polymesh::add_face ( const Polygon face)
throw (kjb::Illegal_argument
)
virtual
Parameters
faceThe face to be added.
iThe index of the face
faceThe face to be added. The index to the face will be set to the index of the last face + 1

Reimplemented in kjb::Parapiped, kjb::Frustum, and kjb::Triangular_mesh.

unsigned int Polymesh::adjacent_face ( unsigned int  f,
unsigned int  e 
) const
throw (Index_out_of_bounds,
KJB_error
)
virtual

returns the index of the face adjacent to face f along edge e This is a very inefficient implementation, class derived from this one should implement their own version, possibly storing the adjacency information and not computing it every time. Not thoroughly tested

returns the index of the face adjacent to face f along edge e

This functions finds the index of the face adjacent to face f along edge e. The face point index must be in the range [0,num_faces]. To specify the edge formed by the 0th and nth point, set p = n.

Parameters
fFace index to get the adjacent face of.
eFirst point index in face of the shared edge. If set to num_faces, the other point forming the edge will be 0.
Exceptions
kjb::Illegal_argumentIf i or p are not valid indices.

Reimplemented in kjb::Parapiped, and kjb::Frustum.

Polymesh * Polymesh::clone ( ) const
virtual

Clones this mesh.

Returns
A new copy of this polymesh.

Implements kjb::Rigid_object.

Reimplemented in kjb::Triangular_mesh, kjb::Parapiped, and kjb::Frustum.

double Polymesh::compute_surface_area ( ) const

Returns the surface area of the mesh.

Computes the surface area of the mesh by adding together the areas of each polygon in the mesh.

Returns
the surface area of the mesh.
bool Polymesh::edge_index_in_polygon ( const Polygon f1,
unsigned int  e,
const Polygon f2,
unsigned int &  index 
)
throw (Index_out_of_bounds
)
protected
void Polymesh::find_bounds ( )

Finds the smallest and largest x, y, and z values and stores them in the class members smallest_bounds and largest_bounds.

void Polymesh::get_all_edges ( std::vector< std::vector< Vector > > &  edges) const

Stores all of the unique pairs of points that make up the edges of the polymesh in a vector.

edges a vector of pairs of Vectors to store the vertices of the edges of the mesh in (points represented as Vectors).

void Polymesh::get_all_vertices ( std::vector< Vector > &  vertices) const

Stores the vertices of the mesh in a vector.

vertices a vector of Vectors to store the vertices of the mesh in (points represented as Vectors).

Vector Polymesh::get_center ( )
Returns
a Vector representing the point in the center of the mesh.
const Polygon & Polymesh::get_face ( unsigned int  i) const
throw (kjb::Index_out_of_bounds
)

Returns an indexed face.

Parameters
iIndex of the face to get; ranges 0 to N-1.
Returns
The specified face.
Exceptions
kjb::Illegal_argumentInvalid face index.
Parameters
iIndex of the face to get.
Returns
The specified mesh face.
Exceptions
kjb::Illegal_argumentInvalid face index.
Polygon & Polymesh::get_face_ref ( unsigned int  i)
throw (kjb::Index_out_of_bounds
)

Returns an indexed face.

Parameters
iIndex of the face to get; ranges 0 to N-1.
Returns
The specified face.
Exceptions
kjb::Illegal_argumentInvalid face index.
Parameters
iIndex of the face to get.
Returns
The specified mesh face.
Exceptions
kjb::Illegal_argumentInvalid face index.
const std::vector< kjb::Polygon > & Polymesh::get_faces ( ) const

Returns the faces of this mesh.

void Polymesh::get_faces ( std::vector< const Polygon * > &  ifaces) const
Vector Polymesh::get_largest_bounds ( ) const
Returns
a Vector representing the largest x, y, and z-values in the polymesh.
double Polymesh::get_largest_z_bound ( )
Returns
a double representing the value of the largest z-value in the polymesh.
void Polymesh::get_lines ( std::vector< Line3d > &  lines)
Vector Polymesh::get_smallest_bounds ( ) const
Returns
a Vector representing the smallest x, y, and z-values in the polymesh.
bool kjb::Polymesh::is_same_vertex ( const kjb::Vector p1,
const kjb::Vector p2 
) const
inlineprotected

Compares two points.

bool Polymesh::is_shared_edge ( const Polygon f1,
unsigned int  e1,
const Polygon f2,
unsigned int  e2 
) const
throw (Index_out_of_bounds
)
protected

Checks whether edge e1 on face f1 is the same as edge e2 on face f2.

unsigned int Polymesh::num_faces ( ) const

Returns the number of faces in this mesh.

Polymesh & Polymesh::operator= ( const Polymesh src)
virtual

Copies a triangular mesh into this one.

Performs a deep copy of the faces in the parallelepiped.

Parameters
tTriangular mesh to copy into this one.
Returns
A reference to this mesh
void Polymesh::project ( )
virtual

Projects this polymesh onto the image plane using the current graphics transformation

void Polymesh::read ( std::istream &  in)
throw (kjb::IO_error,
kjb::Illegal_argument
)
virtual

Reads this polymesh from an input stream.

Parameters
inInput stream to read the members of this parallelepiped from.
Exceptions
kjb::IO_errorCould not read from in.
kjb::Illegal_argumentInvalid argument to read from file.

Implements kjb::Readable.

Reimplemented in kjb::Parapiped, kjb::Frustum, and kjb::Triangular_mesh.

void Polymesh::rotate ( double  phi,
double  x,
double  y,
double  z 
)
virtual
virtual void kjb::Polymesh::rotate ( double  dpitch,
double  dyaw,
double  droll 
)
inlinevirtual

rotate this object around its x-axis by dpitch, the y-axis by dyaw, and its z-axis by droll (in this order, starting from the object's current position)

Rotates this object around its x-axis by the input angle dpitch, around its y-axis by the input angle dyaw, around its z-axis by the input angle droll. The rotations will add to the current state of the object, ie if the inputs are dpitch = 0.1, dyaw =0.0 and, droll = 0.2, the object will be rotated around the object's x-axis by dpitch, and then around the object's z axis (that moved after the first rotation by dpitch) by 0.2

Parameters
dpitchthe amount of rotation around the object's x-axis
dyawthe amount of rotation around the object's y-axis
drollthe amount of rotation around the object's z-axis

Reimplemented from kjb::Rigid_object.

void Polymesh::scale ( double  scale_x,
double  scale_y,
double  scale_z 
)
virtual
void Polymesh::silhouette_render ( const kjb::Base_gl_interface camera,
double  iwidth = 1.0 
) const
virtual

@ brief Renders the silhouette of this mesh

Renders the silhouette (contour) of this mesh. The current implementation works for convex meshes, and produces reasonable results for concave ones

Parameters
cameraThe camera used for rendering this mesh
iwidhtThe width (in pixel) to use when drawing the silhouette

Reimplemented from kjb::Abstract_renderable.

void Polymesh::solid_render ( ) const
virtual

Renders this object with GL as a wire-frame.

Implements kjb::Solid_renderable.

unsigned int Polymesh::solid_render_with_sequential_ids ( unsigned int  start_id = 1) const

Render each polygon of this polymesh with a different color. The first polygon will be rendered using the input id as a color, the following ones will be rendered with an id sequentially increasing. Returns the id (color) used to render the last polygon.

void Polymesh::transform ( const kjb::Matrix M)
throw (kjb::Illegal_argument
)
virtual

Applies a linear transformation to this parallelepiped.

Set the indexes of the faces using their order in the faces vector

Parameters
MHomogeneous transformation matrix to transform this parallelepiped by.
Exceptions
kjb::Illegal_argumentThe matrix is not in 4x4 homogeneous coordinates.

Implements kjb::Rigid_object.

Reimplemented in kjb::Parapiped, and kjb::Frustum.

void Polymesh::translate ( double  dx,
double  dy,
double  dz 
)
virtual

Translates this rigid object.

Translates this rigid object

Parameters
dxThe amount of translation along the world's x axis
dyThe amount of translation along the world's y axis
dzThe amount of translation along the world's z axis

Reimplemented from kjb::Rigid_object.

void Polymesh::wire_occlude_render ( ) const
virtual

Renders this mesh as a wire frame into the depth buffer. Use wire_render after this to render this mesh as a wire frame by not drawing occluded edges.

Implements kjb::Wire_occlude_renderable.

void Polymesh::wire_render ( ) const
virtual

Renders this mesh as a wire frame.

Rendering

Implements kjb::Wire_renderable.

unsigned int Polymesh::wire_render_with_sequential_ids ( unsigned int  start_id = 1) const

Render each edge of this polymesh with a different color. The first edge will be rendered using the input id as a color, the following edges will be rendered with an id sequentially increasing. Returns the id (color) used to render the last edge of the polygon.

Render each edge of this polymesh with a different color. The first edge will be rendered using the input id as a color, the following edges will be rendered with an id sequentially increasing

Parameters
pThe polymesh to render
start_idThe color for the first edge of the polymesh
Returns
The last id used
void Polymesh::write ( std::ostream &  out) const
throw (kjb::IO_error
)
virtual

Writes this mesh to an output stream.

The file format is big-endian binary.

Parameters
outOutput stream to write the members of this parallelepiped to.
Exceptions
kjb::IO_errorCould not write to out.

Implements kjb::Writeable.

Reimplemented in kjb::Parapiped, kjb::Frustum, and kjb::Triangular_mesh.

void Polymesh::write ( const char *  filename) const
throw (IO_error
)
virtual

Writes this mesh to an output stream.

The file format is big-endian binary.

Parameters
outOutput stream to write the members of this parallelepiped to.
Exceptions
kjb::IO_errorCould not write to out.

Reimplemented from kjb::Writeable.

Reimplemented in kjb::Triangular_mesh.

Friends And Related Function Documentation

friend class GL_Polymesh_Renderer
friend

Member Data Documentation

std::vector<kjb::Polygon> kjb::Polymesh::_faces
protected

Polygons defining the mesh.

Vector kjb::Polymesh::largest_bounds
protected
Vector kjb::Polymesh::smallest_bounds
protected

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