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

Detailed Description

Specialized triangular surface mesh.

TriMesh serves as a mesh container for triangular surface mesh generation. It supports more advanced face/edge/vertex connectivity queries and permits hence more straightforward iteration through the mesh. Edges and faces are full objects and faces can be assigned tags.

For meshes which contain not only triangles, consider MxMesh. When visualization is the primary purpose, perfer CgMesh, which has a smaller memory footprint.

See Also
TriFace, TriEdge, CgMesh, MxMesh

#include <trimesh.h>

Collaboration diagram for TriMesh:

Public Member Functions

 TriMesh ()
 create empty mesh
 TriMesh (const TriMesh &msh)
 copy mesh
TriMeshoperator= (const TriMesh &msh)
 copy mesh
virtual ~TriMesh ()
 destroy mesh
void reserve (size_t nv, size_t nf)
 reserve space before adding stuff
uint addVertex (const Vct3 &p)
 add a vertex, return its index
uint addVertex (const Vct3 &p, const Vct3 &n)
 add vertex and normal, return index
uint addFace (uint a, uint b, uint c, int t=0)
 add a triangle, return its index
uint addFace (const uint vi[], int t=0)
 add a triangle, return its index
void triangulate (const PointGrid< 3 > &pg, GridPattern gpt=XPattern)
 triangulate a point matrix
void merge (const TriMesh &msh)
 add another mesh to this one, do not fixate (!)
void merge (const Triangulation &t)
 for porting only: merge old triangle mesh object
void importMesh (const PointList< 3 > &pts, const Indices &tri, bool udrop=false)
 import mesh data
void importMesh (const PointList< 3 > &pts, const PointList< 3 > &nmv, const Indices &tri, bool udrop=false)
 import mesh data, including normal vectors
void exportMesh (PointList< 3 > &pts, Indices &tri) const
 export in simplest form
void exportMesh (PointList< 3 > &pts, PointList< 3 > &nmv, Indices &tri) const
 export in simplest form, including normal vectors
void buildConnectivity (bool udrop=false)
 compute connectivity, optionally drop unreferenced vertices
void fixate (bool udrop=false)
 compute connectivity and estimate vertex normals if not present
uint nvertices () const
 access number of vertices
uint nfaces () const
 access number of triangles
uint nedges () const
 access number of edges
const Vct3vertex (uint i) const
 access vertex position
Vct3vertex (uint i)
 access vertex position
const Vct3normal (uint i) const
 access discrete surface normal
Vct3normal (uint i)
 access discrete surface normal
const PointList< 3 > & vertices () const
 access all vertices
PointList< 3 > & vertices ()
 access all vertices
const PointList< 3 > & normals () const
 access all normal vectors
PointList< 3 > & normals ()
 access all normal vectors
const TriFaceface (uint i) const
 access face
TriFaceface (uint i)
 access face
const TriEdge & edge (uint i) const
 access edge
TriEdge & edge (uint i)
 access edge
uint vdegree (uint i) const
 number of edges coincident in vertex i
uint edegree (uint i) const
 number of faces coincident in edge i
const uint * firstEdgeIndex (uint iface) const
 convenience : fetch three edge indices of a face
const uint * firstFaceIndex (uint iedge) const
 convenience : fetch face indices of an edge
void boundaries (Indices &bde) const
 collect indices for edges with degree != 2
void gradient (uint i, SpMatrix &gmx) const
 assemble a linear gradient stencil around vertex i
Vct3 gradient (uint i, const Vector &x) const
 compute surface gradient of x at node i
CpxVct3 gradient (uint i, const CpxVector &x) const
 compute surface gradient of x at node i
bool isClosedManifold () const
 check whether all edges have exactly two neighbor faces
bool findInternalPoints (PointList< 3 > &holes) const
 presuming *this is manifold, locate points inside the enclosed volume
uint findFlippedFaces (Indices &fflip, Real maxphi=PI) const
 locate faces which have >= 2 nb faces with opposed normals
Real area () const
 compute total area (sum of face areas)
Real volume () const
 compute the enclosed volume (for manifolds)
Vct3 volumeCenter () const
 center of the enclosed volume (for manifolds)
Real shortestEdgeLength () const
 return length of shortest edge
Real solidAngle (uint i) const
 compute the solid angle at vertex i
uint mergeNodes (Real threshold=gmepsilon, Real dphimax=M_PI)
 merge duplicate nodes
uint cleanup (Real threshold=gmepsilon)
 Remove duplicate vertices. More...
void detectEdges (Real ridgeLimitAngle, Real mergeThreshold=gmepsilon)
 merge nodes first, then create patches separated by ridges
void reverse ()
 change direction of all faces
virtual void reorder (const Indices &perm)
 change vertex index ordering
virtual void swap (TriMesh &a)
 swap contents with other mesh
virtual Real megabytes () const
 compute memory requirements
virtual void clear ()
 delete all contents
virtual XmlElement toXml (bool share=false) const
 convert to xml representation
virtual void fromXml (const XmlElement &xe)
 read from xml representation
virtual void writeBin (std::ostream &os) const
 write to binary stream
virtual void readBin (std::istream &is)
 read from binary stream
virtual void toCgns (CgnsFile &file) const
 save to CGNS file zone
virtual void fromCgns (CgnsZone &zone)
 retrieve from CGNS file section (throws when file incompatible)
void writeCgns (const std::string &fname) const
 write to cgns file
void readCgns (const std::string &fname)
 read from cgns file
void readSTL (const std::string &fname)
 determine whether fname is binary or ascii STL
void readAsciiSTL (const std::string &fname)
 read ascii STL file
void readBinarySTL (const std::string &fname)
 read binary STL
void writeBinarySTL (const std::string &fname) const
 write binary STL file
void writeAsciiSTL (const std::string &fname, const std::string &solid="") const
 write ascii STL file
edge_iterator edgeBegin () const
 iterate over all edges
edge_iterator edgeEnd () const
 iterate over all edges
face_iterator faceBegin () const
 iterate over all faces
face_iterator faceEnd () const
 iterate over all faces
nb_face_iterator v2fBegin (uint i) const
 iterate over neighborhood
nb_face_iterator v2fEnd (uint i) const
 iterate over neighborhood
nb_face_iterator e2fBegin (uint i) const
 iterate over neighborhood
nb_face_iterator e2fEnd (uint i) const
 iterate over neighborhood
nb_edge_iterator v2eBegin (uint i) const
 iterate over neighborhood
nb_edge_iterator v2eEnd (uint i) const
 iterate over neighborhood
nb_edge_iterator f2eBegin (uint i) const
 iterate over neighborhood
nb_edge_iterator f2eEnd (uint i) const
 iterate over neighborhood
void bind ()
 bind newly copied faces and edges to this object
void estimateNormals ()
 estimate vertex normal vectors
uint tsearchEdge (uint s, uint t) const
 find edge by traversing connectivity
uint bsearchEdge (uint s, uint t) const
 find edge in sorted edge array
void faceTag (int t)
 set tag of all faces to t
void allTags (Indices &tgs) const
 find all tags in this mesh
std::string tagName (int t) const
 retrieve name associated with tag t
void tagName (int t, const std::string &s)
 set name associated with tag t
void submesh (int t, TriMesh &sub) const
 create a submesh containing only tag t
bool enclosedTriangles (const Indices &vloop, Indices &t) const
 find triangles which are enclosed by vertex loop
void icosahedron (const Vct3 &ctr, Real r)
 generate a regular icosahedron with radius r
void tetrahedron (const Vct3 &ctr, Real r)
 generate an axis-aligned tetrahedron with radius r
void sphere (const Vct3 &ctr, Real r, int nrefp)
 Generate approximation to sphere with radius r centered at ctr. More...
void tsphere (const Vct3 &ctr, Real r, int nrefp)
 Generate approximation to sphere by splitting tetrahedron.
void quadSplit (int npass=1)
 quadruple split: divide each triangle in four
void dropDuplicates ()
 remove triangles which share the same vertices
uint dropInternalTriangles (uint itx, bool usetags=false)
 drop triangles which are identified as lying inside a closed manifold
uint dropInternalTriangles (const Indices &idx, bool usetags=false)
 drop triangles which are identified as lying inside a closed manifold
uint dropOrphanRidges (const Indices &killtags)
 drop triangle which can be reached from a singly connected edge
bool mergeAndDrop (uint itx, Real thrstart, Real thrend)
 cleanup and drop internals until no triply connected edges remain
void joinSingleEdges (Real threshold)
 try to join open (singly-connected) edges
uint dropStretchedTriangles (Real maxstretch, Real maxphi)
 try to remove extremely thin (stretched) triangles
uint dropTriStars ()
 remove vertices with edge degree 3
void splitRidges (Indices &ridges, Real cosphi=0.5)
 split mesh along ridges

Protected Attributes

PointList< 3 > vtx
 mesh vertices and normal vectors
TriFaceArray faces
 vector of triangles
TriEdgeArray edges
 vector of edges
ConnectMap v2f
 connectivity data
TagMap tagnames
 tag to component name map

Private Member Functions

bool flipEdge (uint ei, Real mincphi, Indices &vmod)
 try to flip edge ei
void marchOrphanFront (uint f, const Indices &killtags, Indices &forphan) const
 extend orphan front
uint nextExternalTriangle (uint fcur, uint ei, bool usetags) const
 choose next triangle across edge ei
uint countMultipleEdges (uint fcur) const
 count the number of multiple edges connected to triangle f
void findEnclosedGroup (uint fcur, Indices &ftri) const
 starting from a given edge, find triangles bounded by triple edges
bool triInternalPoint (uint fix, Vct3 &hole) const
 determine a point on the inside of triangle fix

Member Function Documentation

uint TriMesh::cleanup ( Real  threshold = gmepsilon)

Remove duplicate vertices.

Check face validity, rebuild edge list and connectivity. Does only process identical vertices (i.e. where distance smaller threshold) not connected by an edge.

void TriMesh::sphere ( const Vct3 ctr,
Real  r,
int  nrefp 

Generate approximation to sphere with radius r centered at ctr.

Number of faces will be 20*4^npass

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