Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

vl::Geometry Class Reference

The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points. More...

#include <Geometry.hpp>

Inheritance diagram for vl::Geometry:
vl::Renderable vl::IVertexAttribSet vl::Object vl::BezierSurface

List of all members.

Classes

class  TextureArray

Public Member Functions

virtual const char * className ()
 Returns the name of the class.
 Geometry ()
 Constructor.
virtual ~Geometry ()
 Destructor.
ref< GeometryshallowCopy ()
 Performs a shallow copy (as opposed to a deep copy) of the specified Geometry.
void shallowCopy (Geometry *)
 Performs a shallow copy (as opposed to a deep copy) of the specified Geometry.
ref< GeometrydeepCopy () const
 Performs a deep copy (as opposed to a shallow copy) of the specified Geometry.
void deepCopy (Geometry *) const
 Performs a deep copy (as opposed to a shallow copy) of the specified Geometry.
Geometryoperator= (const Geometry &other)
 Performs a shallowCopy() of the Geometry.
Collection< DrawCall > * drawCalls ()
 Returns the list of DrawCall objects bound to a Geometry.
const Collection< DrawCall > * drawCalls () const
 Returns the list of DrawCall objects bound to a Geometry.
void setNormal (const fvec3 &normal)
 Geometry normal used when no normal array is defined.
const fvec3normal ()
 Geometry normal used when no normal array is defined.
void setColor (const fvec4 &color)
 Geometry color used when no color array is defined.
const fvec4color ()
 Geometry color used when no color array is defined.
void setSecondaryColor (const fvec4 &color)
 Geometry color used when no color array is defined.
const fvec4secondaryColor ()
 Geometry color used when no color array is defined.
void toGenericVertexAttribs ()
 Converts the fixed function pipeline arrays (vertex array, normal arrays) into the generic ones.
void computeNormals (bool verbose=false)
 Computes the normals in a "smooth" way, i.e.
bool flipNormals ()
 Inverts the orientation of the normals.
void transform (const mat4 &matr, bool normalize=true)
 Transforms vertices and normals belonging to this geometry.
virtual void clearArrays (bool clear_draw_calls=true)
 Removes all the previously installed arrays.
void updateVBOs (bool discard_local_data=false, bool force_update=false)
 Updates all the vertex buffer objects of both vertex arrays and draw calls.
void deleteVBOs ()
 Deletes all the vertex buffer objects of both vertex arrays and draw calls.
void mergeTriangleStrips ()
 Merges all the PT_TRIANGLE_STRIP DrawElementsUInt objects into one single PT_TRIANGLE_STRIP DrawElementsUInt.
void convertDrawCallToDrawArrays ()
 Converts all the DrawCall objects bound to a Geometry into DrawArrays.
bool sortVertices ()
 Sorts the vertices of the geometry to maximize vertex-cache coherency.
void colorizePrimitives ()
 Assigns a random color to each vertex of each DrawCall object. If a vertex is shared among more than one DrawCall object its color is undefined.
void regenerateVertices (const std::vector< size_t > &map_new_to_old)
void setVertexArray (ArrayAbstract *data)
 Conventional vertex array.
const ArrayAbstractvertexArray () const
 Conventional vertex array.
ArrayAbstractvertexArray ()
 Conventional vertex array.
void setNormalArray (ArrayAbstract *data)
 Conventional normal array.
const ArrayAbstractnormalArray () const
 Conventional normal array.
ArrayAbstractnormalArray ()
 Conventional normal array.
void setColorArray (ArrayAbstract *data)
 Conventional color array.
const ArrayAbstractcolorArray () const
 Conventional color array.
ArrayAbstractcolorArray ()
 Conventional color array.
void setSecondaryColorArray (ArrayAbstract *data)
 Conventional secondary color array.
const ArrayAbstractsecondaryColorArray () const
 Conventional secondary color array.
ArrayAbstractsecondaryColorArray ()
 Conventional secondary color array.
void setFogCoordArray (ArrayAbstract *data)
 Conventional fog array.
const ArrayAbstractfogCoordArray () const
 Conventional fog array.
ArrayAbstractfogCoordArray ()
 Conventional fog array.
void setTexCoordArray (int tex_unit, ArrayAbstract *data)
 Conventional texture coords arrays.
const ArrayAbstracttexCoordArray (int tex_unit) const
 Conventional texture coords arrays.
ArrayAbstracttexCoordArray (int tex_unit)
 Conventional texture coords arrays.
int texCoordArrayCount () const
void getTexCoordArrayAt (int i, int &out_tex_unit, const ArrayAbstract *&tex_array) const
void setVertexAttribArray (unsigned int attrib_idx, ArrayAbstract *data, bool normalize=true, EVertexAttribBehavior data_behav=VAB_NORMAL)
void setVertexAttribArray (const VertexAttribInfo &info)
 Binds a generic vertex attribute.
const ArrayAbstractvertexAttrib (unsigned int attrib_idx) const
 Returns a generic vertex attribute.
ArrayAbstractvertexAttrib (unsigned int attrib_idx)
 Returns a generic vertex attribute.
const VertexAttribInfovertexAttribInfo (unsigned int attrib_idx) const
 Returns a generic vertex attribute's info.
VertexAttribInfovertexAttribInfo (unsigned int attrib_idx)
 Returns a generic vertex attribute's info.
ref< VertexAttribInfoeraseVertexAttrib (unsigned int attrib_idx)
int vertexAttribInfoCount () const
 Returns the number of generic vertex attribute arrays bound.
const VertexAttribInfogetVertexAttribInfoAt (int i) const
 Returns i-th VertexAttribInfo, where i is not out_attrib_info.attribIndex().
Collection< VertexAttribInfo > * vertexAttribArrays ()
 The list of VertexAttribInfo objects bound to a Geometry.
const Collection
< VertexAttribInfo > * 
vertexAttribArrays () const
 The list of VertexAttribInfo objects bound to a Geometry.

Static Public Member Functions

static void computeTangentSpace (size_t vert_count, const vl::fvec3 *vertex, const vl::fvec3 *normal, const vl::fvec2 *texcoord, const vl::DrawCall *primitives, vl::fvec3 *tangent, vl::fvec3 *bitangent)
 Computes the tangent (and optionally bitangent) vectors used to form a TBN matrix to be used for bumpmapping.

Protected Member Functions

virtual void computeBounds_Implementation ()
virtual void render_Implementation (const Actor *actor, const Shader *shader, const Camera *camera, OpenGLContext *gl_context) const

Protected Attributes

Collection< DrawCallmDrawCalls
fvec4 mColor
fvec4 mSecondaryColor
fvec3 mNormal
ref< ArrayAbstractmVertexArray
ref< ArrayAbstractmNormalArray
ref< ArrayAbstractmColorArray
ref< ArrayAbstractmSecondaryColorArray
ref< ArrayAbstractmFogCoordArray
Collection< TextureArray > mTexCoordArrays
Collection< VertexAttribInfomVertexAttribArrays

Detailed Description

The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.

See also:

Definition at line 67 of file Geometry.hpp.


Constructor & Destructor Documentation

Geometry::Geometry (  )
Geometry::~Geometry (  ) [virtual]

Destructor.

Definition at line 53 of file Geometry.cpp.


Member Function Documentation

virtual const char* vl::Geometry::className (  ) [inline, virtual]

Returns the name of the class.

Reimplemented from vl::Renderable.

Reimplemented in vl::BezierSurface.

Definition at line 81 of file Geometry.hpp.

ref< Geometry > Geometry::shallowCopy (  )

Performs a shallow copy (as opposed to a deep copy) of the specified Geometry.

See also:
deepCopy()

Definition at line 146 of file Geometry.cpp.

References Geometry().

Referenced by vl::MorphingCallback::init().

void Geometry::shallowCopy ( Geometry geom )

Performs a shallow copy (as opposed to a deep copy) of the specified Geometry.

See also:
deepCopy()

Definition at line 153 of file Geometry.cpp.

ref< Geometry > Geometry::deepCopy (  ) const

Performs a deep copy (as opposed to a shallow copy) of the specified Geometry.

See also:
shallowCopy()

Definition at line 89 of file Geometry.cpp.

References Geometry(), and vl::ref< T >::get().

void Geometry::deepCopy ( Geometry geom ) const
Geometry & Geometry::operator= ( const Geometry other )
Collection<DrawCall>* vl::Geometry::drawCalls (  ) [inline]
const Collection<DrawCall>* vl::Geometry::drawCalls (  ) const [inline]

Returns the list of DrawCall objects bound to a Geometry.

Definition at line 116 of file Geometry.hpp.

void vl::Geometry::setNormal ( const fvec3 normal ) [inline]

Geometry normal used when no normal array is defined.

Definition at line 119 of file Geometry.hpp.

const fvec3& vl::Geometry::normal (  ) [inline]

Geometry normal used when no normal array is defined.

Definition at line 122 of file Geometry.hpp.

void vl::Geometry::setColor ( const fvec4 color ) [inline]

Geometry color used when no color array is defined.

Definition at line 125 of file Geometry.hpp.

const fvec4& vl::Geometry::color (  ) [inline]

Geometry color used when no color array is defined.

Definition at line 128 of file Geometry.hpp.

void vl::Geometry::setSecondaryColor ( const fvec4 color ) [inline]

Geometry color used when no color array is defined.

Definition at line 131 of file Geometry.hpp.

const fvec4& vl::Geometry::secondaryColor (  ) [inline]

Geometry color used when no color array is defined.

Definition at line 134 of file Geometry.hpp.

void Geometry::toGenericVertexAttribs (  )

Converts the fixed function pipeline arrays (vertex array, normal arrays) into the generic ones.

The generic attribute indices are allocated in the following order:

  • vertex array
  • normal array
  • color array
  • texture array 0 .. N
  • secondary color array
  • fog coord array
Remarks:
The previously installed generic vertex attributes are removed. The fixed function attributes are set to NULL.

Definition at line 282 of file Geometry.cpp.

References vl::Collection< T >::clear(), colorArray(), fogCoordArray(), mTexCoordArrays, normalArray(), secondaryColorArray(), setColorArray(), setFogCoordArray(), setNormalArray(), setSecondaryColorArray(), setVertexArray(), setVertexAttribArray(), vl::Collection< T >::size(), vertexArray(), and vertexAttribArrays().

void Geometry::computeNormals ( bool  verbose = false )

Computes the normals in a "smooth" way, i.e.

averaging the normals of those polygons that share one or more vertices.

This function computes smoothed normals for triangle primitives and leaves unchanged the normals of line and point primitives when possible, i.e. when they don't share vertices with the polygonal primitives.

Note:
This function modifies the local buffers. After calling this you might want to update the buffers allocated on the GPU.

Definition at line 322 of file Geometry.cpp.

References vl::cross(), drawCalls(), vl::ref< T >::get(), vl::Vector3< T_Scalar >::length(), mDrawCalls, vl::Vector3< T_Scalar >::normalize(), setNormalArray(), vl::Collection< T >::size(), vl::ArrayAbstract::size(), vl::ArrayAbstract::vectorAsVec4(), vertexArray(), vertexAttrib(), VL_CHECK, vl::Log::warning(), and vl::Vector4< T_Scalar >::xyz().

bool Geometry::flipNormals (  )

Inverts the orientation of the normals.

Returns true if the normals could be flipped. The function fails if the normals are defined in a format other than ArrayFloat3.

Definition at line 265 of file Geometry.cpp.

References vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::at(), normalArray(), and vl::Array< T_VectorType, T_Scalar, T_GL_Size, T_GL_Type >::size().

void Geometry::transform ( const mat4 matr,
bool  normalize = true 
)

Transforms vertices and normals belonging to this geometry.

If 'normalize' == true the normals are normalized after being transformed

Note:
This functions supports every possible vertex format, type and layout.
See also:

Definition at line 495 of file Geometry.cpp.

References vl::Matrix4< T_Scalar >::as3x3(), vl::Matrix4< T_Scalar >::getInverse(), normalArray(), vl::ArrayAbstract::normalize(), vl::ArrayAbstract::transform(), vertexArray(), and vertexAttrib().

void Geometry::clearArrays ( bool  clear_draw_calls = true ) [virtual]

Removes all the previously installed arrays.

Definition at line 252 of file Geometry.cpp.

References vl::Collection< T >::clear(), mColorArray, mDrawCalls, mFogCoordArray, mNormalArray, mSecondaryColorArray, mTexCoordArrays, mVertexArray, and mVertexAttribArrays.

void Geometry::updateVBOs ( bool  discard_local_data = false,
bool  force_update = false 
) [virtual]
void Geometry::deleteVBOs (  ) [virtual]
void Geometry::mergeTriangleStrips (  )
void Geometry::convertDrawCallToDrawArrays (  )
bool Geometry::sortVertices (  )
void Geometry::colorizePrimitives (  )

Assigns a random color to each vertex of each DrawCall object. If a vertex is shared among more than one DrawCall object its color is undefined.

Definition at line 746 of file Geometry.cpp.

References vl::Vector4< T_Scalar >::a(), vl::Vector4< T_Scalar >::b(), drawCalls(), vl::Vector4< T_Scalar >::g(), vl::ref< T >::get(), vl::Vector4< T_Scalar >::r(), setColorArray(), vl::Collection< T >::size(), and vertexArray().

void Geometry::regenerateVertices ( const std::vector< size_t > &  map_new_to_old )
void Geometry::computeTangentSpace ( size_t  vert_count,
const vl::fvec3 vertex,
const vl::fvec3 normal,
const vl::fvec2 texcoord,
const vl::DrawCall primitives,
vl::fvec3 tangent,
vl::fvec3 bitangent 
) [static]

Computes the tangent (and optionally bitangent) vectors used to form a TBN matrix to be used for bumpmapping.

Parameters:
vert_countThe number of elements stored in vertex, normal, texcoord, tangent and bitangent.
vertexArray containing the vertex positions.
normalArray containing the normals of the vertices.
texcoordArray containing the 2d texture coordinates of the bumpmap.
primitivesThe triangles, quads etc. defining the geometry of the object.
tangent[out] Returns the tangent vector of the vertices. This parameter is mandatory.
bitangent[out] Returns the bitangent vector of the vertics. This parameter can be NULL.

Definition at line 765 of file Geometry.cpp.

References vl::cross(), vl::dot(), vl::TriangleIterator::isEnd(), vl::normalize(), vl::DrawCall::triangleIterator(), VL_CHECK, vl::Vector2< T_Scalar >::x(), vl::Vector3< T_Scalar >::x(), vl::Vector2< T_Scalar >::y(), vl::Vector3< T_Scalar >::y(), and vl::Vector3< T_Scalar >::z().

void Geometry::setVertexArray ( ArrayAbstract data ) [virtual]

Conventional vertex array.

Implements vl::IVertexAttribSet.

Definition at line 158 of file Geometry.cpp.

References vl::ArrayAbstract::glSize(), mVertexArray, and VL_CHECK.

Referenced by regenerateVertices(), toGenericVertexAttribs(), and vl::BezierSurface::updateBezierSurface().

const ArrayAbstract* vl::Geometry::vertexArray (  ) const [inline, virtual]
ArrayAbstract* vl::Geometry::vertexArray (  ) [inline, virtual]

Conventional vertex array.

Implements vl::IVertexAttribSet.

Definition at line 243 of file Geometry.hpp.

void Geometry::setNormalArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::normalArray (  ) const [inline, virtual]
ArrayAbstract* vl::Geometry::normalArray (  ) [inline, virtual]

Conventional normal array.

Implements vl::IVertexAttribSet.

Definition at line 249 of file Geometry.hpp.

void Geometry::setColorArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::colorArray (  ) const [inline, virtual]

Conventional color array.

Implements vl::IVertexAttribSet.

Definition at line 253 of file Geometry.hpp.

Referenced by regenerateVertices(), render_Implementation(), vl::PolygonSimplifier::simplify(), and toGenericVertexAttribs().

ArrayAbstract* vl::Geometry::colorArray (  ) [inline, virtual]

Conventional color array.

Implements vl::IVertexAttribSet.

Definition at line 255 of file Geometry.hpp.

void Geometry::setSecondaryColorArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::secondaryColorArray (  ) const [inline, virtual]

Conventional secondary color array.

Implements vl::IVertexAttribSet.

Definition at line 259 of file Geometry.hpp.

Referenced by regenerateVertices(), render_Implementation(), vl::PolygonSimplifier::simplify(), and toGenericVertexAttribs().

ArrayAbstract* vl::Geometry::secondaryColorArray (  ) [inline, virtual]

Conventional secondary color array.

Implements vl::IVertexAttribSet.

Definition at line 261 of file Geometry.hpp.

void Geometry::setFogCoordArray ( ArrayAbstract data ) [virtual]
const ArrayAbstract* vl::Geometry::fogCoordArray (  ) const [inline, virtual]

Conventional fog array.

Implements vl::IVertexAttribSet.

Definition at line 265 of file Geometry.hpp.

Referenced by regenerateVertices(), vl::PolygonSimplifier::simplify(), and toGenericVertexAttribs().

ArrayAbstract* vl::Geometry::fogCoordArray (  ) [inline, virtual]

Conventional fog array.

Implements vl::IVertexAttribSet.

Definition at line 267 of file Geometry.hpp.

void Geometry::setTexCoordArray ( int  tex_unit,
ArrayAbstract data 
) [virtual]
const ArrayAbstract* vl::Geometry::texCoordArray ( int  tex_unit ) const [inline, virtual]

Conventional texture coords arrays.

Implements vl::IVertexAttribSet.

Definition at line 271 of file Geometry.hpp.

Referenced by regenerateVertices(), vl::PolygonSimplifier::simplify(), and vl::BezierSurface::updateBezierSurface().

ArrayAbstract* vl::Geometry::texCoordArray ( int  tex_unit ) [inline, virtual]

Conventional texture coords arrays.

Implements vl::IVertexAttribSet.

Definition at line 279 of file Geometry.hpp.

int vl::Geometry::texCoordArrayCount (  ) const [inline, virtual]

Implements vl::IVertexAttribSet.

Definition at line 287 of file Geometry.hpp.

void vl::Geometry::getTexCoordArrayAt ( int  i,
int &  out_tex_unit,
const ArrayAbstract *&  tex_array 
) const [inline, virtual]

Implements vl::IVertexAttribSet.

Definition at line 289 of file Geometry.hpp.

References VL_CHECK.

void vl::Geometry::setVertexAttribArray ( unsigned int  attrib_idx,
ArrayAbstract data,
bool  normalize = true,
EVertexAttribBehavior  data_behav = VAB_NORMAL 
) [inline]

Definition at line 296 of file Geometry.hpp.

References vl::normalize(), and setVertexAttribArray().

Referenced by setVertexAttribArray(), and toGenericVertexAttribs().

void Geometry::setVertexAttribArray ( const VertexAttribInfo info ) [virtual]
const ArrayAbstract * Geometry::vertexAttrib ( unsigned int  attrib_idx ) const [virtual]

Returns a generic vertex attribute.

Implements vl::IVertexAttribSet.

Definition at line 524 of file Geometry.cpp.

References vl::VertexAttribInfo::data(), and vertexAttribInfo().

Referenced by computeNormals(), and transform().

ArrayAbstract * Geometry::vertexAttrib ( unsigned int  attrib_idx ) [virtual]

Returns a generic vertex attribute.

Implements vl::IVertexAttribSet.

Definition at line 533 of file Geometry.cpp.

References vl::VertexAttribInfo::data(), and vertexAttribInfo().

const VertexAttribInfo * Geometry::vertexAttribInfo ( unsigned int  attrib_idx ) const [virtual]

Returns a generic vertex attribute's info.

Implements vl::IVertexAttribSet.

Definition at line 542 of file Geometry.cpp.

References vl::Collection< T >::at(), vl::VertexAttribInfo::attribIndex(), vl::Collection< T >::size(), and vertexAttribArrays().

Referenced by computeBounds_Implementation(), and vertexAttrib().

VertexAttribInfo * Geometry::vertexAttribInfo ( unsigned int  attrib_idx ) [virtual]

Returns a generic vertex attribute's info.

Implements vl::IVertexAttribSet.

Definition at line 550 of file Geometry.cpp.

References vl::Collection< T >::at(), vl::VertexAttribInfo::attribIndex(), vl::Collection< T >::size(), and vertexAttribArrays().

ref< VertexAttribInfo > Geometry::eraseVertexAttrib ( unsigned int  attrib_idx ) [virtual]
int vl::Geometry::vertexAttribInfoCount (  ) const [inline, virtual]

Returns the number of generic vertex attribute arrays bound.

Implements vl::IVertexAttribSet.

Definition at line 310 of file Geometry.hpp.

const VertexAttribInfo* vl::Geometry::getVertexAttribInfoAt ( int  i ) const [inline, virtual]

Returns i-th VertexAttribInfo, where i is not out_attrib_info.attribIndex().

Implements vl::IVertexAttribSet.

Definition at line 312 of file Geometry.hpp.

Collection<VertexAttribInfo>* vl::Geometry::vertexAttribArrays (  ) [inline]
const Collection<VertexAttribInfo>* vl::Geometry::vertexAttribArrays (  ) const [inline]

The list of VertexAttribInfo objects bound to a Geometry.

Definition at line 318 of file Geometry.hpp.

void Geometry::computeBounds_Implementation (  ) [protected, virtual]
void Geometry::render_Implementation ( const Actor actor,
const Shader shader,
const Camera camera,
OpenGLContext gl_context 
) const [protected, virtual]

Member Data Documentation

Definition at line 326 of file Geometry.hpp.

Referenced by clearArrays(), computeNormals(), deepCopy(), Geometry(), and operator=().

Definition at line 329 of file Geometry.hpp.

Referenced by deepCopy(), Geometry(), operator=(), and render_Implementation().

Definition at line 332 of file Geometry.hpp.

Referenced by deepCopy(), Geometry(), operator=(), and render_Implementation().

Definition at line 335 of file Geometry.hpp.

Referenced by deepCopy(), Geometry(), operator=(), and render_Implementation().

Definition at line 340 of file Geometry.hpp.

Referenced by clearArrays(), deepCopy(), deleteVBOs(), operator=(), setVertexArray(), and updateVBOs().

Definition at line 341 of file Geometry.hpp.

Referenced by clearArrays(), deepCopy(), deleteVBOs(), operator=(), setNormalArray(), and updateVBOs().

Definition at line 342 of file Geometry.hpp.

Referenced by clearArrays(), deepCopy(), deleteVBOs(), operator=(), setColorArray(), and updateVBOs().

Definition at line 344 of file Geometry.hpp.

Referenced by clearArrays(), deepCopy(), deleteVBOs(), operator=(), setFogCoordArray(), and updateVBOs().

Collection<TextureArray> vl::Geometry::mTexCoordArrays [protected]

Definition at line 347 of file Geometry.hpp.

Referenced by clearArrays(), deepCopy(), Geometry(), operator=(), and setVertexAttribArray().


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

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:41.
Permission is granted to use this page to write and publish articles regarding Visualization Library.