Basic Geometry, Numerical Algorithms and Interfaces
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CgMesh Class Reference

Detailed Description

Mesh container for visualization.

CgMesh stores a triangle mesh in a format suitable for efficient rendering using OpenGL. It is much less useful for anything else.

Compared to MxMesh and TriMesh, this class uses single-precision floating point data in order to save space.

Rewrite the color handling stuff for 3DXML import.
See Also
CgStrip, Color

#include <cgmesh.h>

Collaboration diagram for CgMesh:

Public Member Functions

 CgMesh ()
 empty mesh
 CgMesh (PointList3f &&points, Indices &&tris)
 common case: transfer ownership from vertex and index sets
 CgMesh (PointList3f &&points, Indices &&tris, Indices &&lns)
 common case: transfer ownership from vertex and index sets
virtual ~CgMesh ()
 virtual destructor
void tag (int t)
 change id tag
int tag () const
 retrieve id tag
uint ntriangles () const
 total number of triangles to render
const uint * triVertices (uint i) const
 vertex indices of triangle i of non-stripped triangles
uint nlines () const
 number of lines to render
const PointList< 3, float > & vertices () const
 access vertices
PointList< 3, float > & vertices ()
 access vertices; note that changing indexing will invalidate elements
const PointList< 3, float > & normals () const
 access normals
PointList< 3, float > & normals ()
 access normals
const ColorArray & colors () const
 access normals
ColorArray & colors ()
 access normals
const Indices & triangles () const
 access triangles stored as elements (not strips)
Indices & triangles ()
 access triangles stored as elements (not strips)
const Indices & lines () const
 access lines stored as elements (not strips)
Indices & lines ()
 access lines stored as elements (not strips)
const Vct3fvertex (uint vix) const
 access single vertex
const Vct3fnormal (uint vix) const
 access single normal
uint append (const Vct3f &v, const Vct3f &n)
 append vertex and normal, return index
uint append (const Vct3f &v, const Vct3f &n, const Color &c)
 append vertex, normal, and color return index
const Colorcolor (uint vix) const
 access color for one vertex
Colorcolor (uint vix)
 set color for one vertex
void fitColorBuffer (const Color &dfc)
 make color array match vertex array size and set default
void transform (const SMatrix< 4, 4, float > &t)
 transform coordinates explicitly
void boundingBox (float plo[], float phi[]) const
 extend bounding box to include this mesh
float meanEdgeLength () const
 compute mean edge length
float meanTriangleArea () const
 compute mean triangle area
template<class FloatType , class IntType >
void importMesh (int nv, const FloatType *pvtx, const FloatType *pnrm, int nt, const IntType *ptri)
 import triangle mesh with nv 3D vertices and normals and nt triangles
template<class FloatType , class IntType >
void importMesh (const PointList< 3, FloatType > &vtx, const PointList< 3, FloatType > &nrm, const std::vector< IntType > &tri)
 import triangle mesh
void importMesh (const TriMesh &tm)
 import from TriMesh (does not compute strips)
void exportMesh (TriMesh &tm) const
 export to TriMesh
void reserve (size_t nvert, size_t ntriangles, size_t nlines)
 reserve space for known number of vertices and primitives
void merge (const CgMesh &msub)
 merge in another CgMesh
void merge (const CgMesh &msub, const Mtx44f &tsub)
 merge in another CgMesh while applying transformation
void mergeTriangles (size_t nm, const PointList3f mv[], const Indices mt[])
 merge with multiple other meshes, do not use normals and lines
void mergeTriangles (const CgMesh &msub)
 merge with other mesh, do not use normals and lines
template<typename VertexType >
size_t appendVertex (const VertexType &v)
 append a single vertex (best to reserve() first)
void appendTriangles (const Indices &tri)
 append a number of triangles
void replaceTriangles (const Indices &tri)
 replace triangles
void appendCircle (const Vct3f &ctr, const Vct3f &cn, float r, int nt=16)
 Generate a triangle fan to draw a circle with radius r centered at ctr and normal to cn, approximated with nt triangles.
void appendCross (const Vct3f &ctr, float s)
 Generate lines to draw a coordinate-aligned cross centered at ctr and with edge lengths s.
void appendLine (const Vct3f &p1, const Vct3f &p2)
 append a single line segment
void appendLine (const PointList< 3, float > &pts)
 append a single polyline
void appendLine (uint a, uint b)
 append a single line segment, indexed into vertex buffer
void appendLines (const Indices &lns)
 append multiple line segments (not a polyline!)
void appendLines (const PointList< 3, float > &pts)
 append multiple line segments (not a polyline!)
void removeLines (size_t lbegin, size_t lend)
 remove a range of line elements
void toTriangles (Indices &tri) const
 convert everything to indexed triangles
void toLines (Indices &lns) const
 convert all line elements to simple indexed lines
void expandStrips ()
 expand strips and fans to plain triangles
void splitTriangles ()
 draw each triangle separately with its own normal
void freeLines (PointList3f &plines) const
 extract lines that do not reference triangle vertices
void reorderElements (const Indices &perm)
 apply a new vertex order to lines and triangles
uint dropUnusedVertices (Indices *pvm=0)
 remove unreferenced vertices (expands strips as well)
void detectEdges (float mergeTol, float minAngle)
 split mesh to identify sharp edges (merges vertices as well)
void dropInvalidTriangles (float mergetol)
 drop ill-defined triangles with zero area after node merging
void quadRefine ()
 split each triangle into 4 new ones by inserting mid-edge nodes
void repairNormals ()
 flip triangles to achieve a consistent normal orientation
Vct3f areaCenter () const
 determine area center from triangles
int checkValidity () const
 check whether elements references invalid vertices or normals
float megabytes () const
 size in memory (for information only)
void clearMesh ()
 clear mesh
void swap (CgMesh &a)
 swap contents
virtual XmlElement toXml (bool share=false) const
 xml representation
virtual void fromXml (const XmlElement &xe)
 retrieve from xml representation

Static Public Member Functions

static void importColor (bool flag)
 import vertex colors from 3dxml?
static void excludeColor (const Color &c)
 exclude faces of specified color when reading 3dxml
static void includeColor (const Color &c)
 include faces of specified color when reading 3dxml
static void ignoreColor ()
 ignore colors (default)

Protected Member Functions

void importNode3Dxml (const XmlElement &xe)
 import 3DXML node 'PolygonalRepType'
bool testColorNode3Dxml (const XmlElement &xe, Color &faceCol) const
 determine whether to read face node at all (based on signal color)
void importFile3Dxml (const XmlElement &xe)
 import all polygonal components of a whole 3DRep file
void setVertexColor (const Color &fc, const Indices &idx)
 distribute face color to affected vertices
void estimateNormals ()
 estimate normal vectors from triangle vertices

Protected Attributes

PointList< 3, float > m_vtx
 vertices and normals, polyline vertices
CgStrip m_tristrips
 triangle strips and fans
CgStrip m_lnstrips
 line strips offset pointer
Indices m_triangles
 plain triangles and lines indexed into vtx
ColorArray m_vtxcol
 vertex colors
int m_itag
 integer id

Static Protected Attributes

static Color s_sigcolor
 color which indicates that surface is to be excluded/included
static ColorImportMode s_sigcolormode = CgMesh::IgnoreColor
 signal color excluded or included?

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