chrono::geometry::ChTriangleMeshConnected Class Reference

Description

A triangle mesh with connectivity info: vertices can be shared between faces.

#include <ChTriangleMeshConnected.h>

Inheritance diagram for chrono::geometry::ChTriangleMeshConnected:
Collaboration diagram for chrono::geometry::ChTriangleMeshConnected:

Classes

class  ChRefineEdgeCriterion
 Class to be used optionally in RefineMeshEdges() More...
 

Public Member Functions

 ChTriangleMeshConnected (const ChTriangleMeshConnected &source)
 
virtual ChTriangleMeshConnectedClone () const override
 "Virtual" copy constructor (covariant return type).
 
std::vector< ChVector< double > > & getCoordsVertices ()
 
std::vector< ChVector< double > > & getCoordsNormals ()
 
std::vector< ChVector< double > > & getCoordsUV ()
 
std::vector< ChVector< float > > & getCoordsColors ()
 
std::vector< ChVector< int > > & getIndicesVertexes ()
 
std::vector< ChVector< int > > & getIndicesNormals ()
 
std::vector< ChVector< int > > & getIndicesUV ()
 
std::vector< ChVector< int > > & getIndicesColors ()
 
bool LoadWavefrontMesh (std::string filename, bool load_normals=true, bool load_uv=false)
 Load a triangle mesh saved as a Wavefront .obj file.
 
virtual void addTriangle (const ChVector<> &vertex0, const ChVector<> &vertex1, const ChVector<> &vertex2) override
 Add a triangle to this triangle mesh, by specifying the three coordinates. More...
 
virtual void addTriangle (const ChTriangle &atriangle) override
 Add a triangle to this triangle mesh, by specifying a ChTriangle.
 
virtual int getNumTriangles () const override
 Get the number of triangles already added to this mesh.
 
virtual ChTriangle getTriangle (int index) const override
 Access the n-th triangle in mesh.
 
virtual void Clear () override
 Clear all data.
 
void ComputeMassProperties (bool bodyCoords, double &mass, ChVector<> &center, ChMatrix33<> &inertia)
 Compute barycenter, mass, inertia tensor.
 
std::string GetFileName ()
 Get the filename of the triangle mesh.
 
virtual void Transform (const ChVector<> displ, const ChMatrix33<> rotscale) override
 Transform all vertexes, by displacing and rotating (rotation via matrix, so also scaling if needed)
 
bool ComputeNeighbouringTriangleMap (std::vector< std::array< int, 4 >> &tri_map) const
 Create a map of neighboring triangles, vector of: [Ti TieA TieB TieC] (the free sides have triangle id = -1). More...
 
bool ComputeWingedEdges (std::map< std::pair< int, int >, std::pair< int, int >> &winged_edges, bool allow_single_wing=true) const
 Create a winged edge structure, map of {key, value} as {{edgevertexA, edgevertexB}, {triangleA, triangleB}} If allow_single_wing = false, only edges with at least 2 triangles are returned. More...
 
int RepairDuplicateVertexes (const double tolerance=1e-18)
 Connect overlapping vertexes. More...
 
bool MakeOffset (const double offset)
 Offset the mesh, by a specified value, orthogonally to the faces. More...
 
std::pair< int, int > GetTriangleEdgeIndexes (const std::vector< ChVector< int >> &indexes, int it, int nedge, bool unique)
 Return the indexes of the two vertexes of the i-th edge of the triangle. More...
 
bool SplitEdge (int itA, int itB, int neA, int neB, int &itA_1, int &itA_2, int &itB_1, int &itB_2, std::vector< std::array< int, 4 >> &tri_map, std::vector< std::vector< double > * > &aux_data_double, std::vector< std::vector< int > * > &aux_data_int, std::vector< std::vector< bool > * > &aux_data_bool, std::vector< std::vector< ChVector<>> * > &aux_data_vect)
 Split a given edge by inserting a vertex in the middle: from two triangles one gets four triangles. More...
 
void RefineMeshEdges (std::vector< int > &marked_tris, double edge_maxlen, ChRefineEdgeCriterion *criterion, std::vector< std::array< int, 4 >> *atri_map, std::vector< std::vector< double > * > &aux_data_double, std::vector< std::vector< int > * > &aux_data_int, std::vector< std::vector< bool > * > &aux_data_bool, std::vector< std::vector< ChVector<>> * > &aux_data_vect)
 Performs mesh refinement using Rivara LEPP long-edge bisection algorithm. More...
 
virtual GeometryType GetClassType () const override
 Get the class type as unique numerical ID (faster than using ChronoRTTI mechanism). More...
 
virtual void ArchiveOUT (ChArchiveOut &marchive) override
 Method to allow serialization of transient data to archives.
 
virtual void ArchiveIN (ChArchiveIn &marchive) override
 Method to allow de-serialization of transient data from archives.
 
- Public Member Functions inherited from chrono::geometry::ChTriangleMesh
virtual void Transform (const ChVector<> displ, const ChQuaternion<> mquat=ChQuaternion<>(1, 0, 0, 0))
 Transform all vertexes, by displacing and rotating (rotation via matrix, so also scaling if needed)
 
virtual void GetBoundingBox (double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax, ChMatrix33<> *Rot=NULL) const override
 Compute bounding box. More...
 
virtual void CovarianceMatrix (ChMatrix33<> &C) const override
 Compute the 3x3 covariance matrix (only the diagonal and upper part) It should be overridden by inherited classes.
 
virtual int GetManifoldDimension () const override
 This is a surface.
 
- Public Member Functions inherited from chrono::geometry::ChGeometry
 ChGeometry (const ChGeometry &source)
 
virtual void InflateBoundingBox (double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax, ChMatrix33<> *Rot=NULL) const
 Enlarge a previous existing bounding box. More...
 
virtual double Size () const
 Returns the radius of the sphere which can enclose the geometry.
 
virtual ChVector Baricenter () const
 Compute center of mass It should be overridden by inherited classes.
 
virtual void Update ()
 Generic update of internal data. More...
 

Static Public Member Functions

static void WriteWavefront (const std::string &filename, std::vector< ChTriangleMeshConnected > &meshes)
 Write the specified meshes in a Wavefront .obj file.
 
static ChTriangleMeshConnected Merge (std::vector< ChTriangleMeshConnected > &meshes)
 Utility function for merging multiple meshes.
 

Public Attributes

std::vector< ChVector< double > > m_vertices
 
std::vector< ChVector< double > > m_normals
 
std::vector< ChVector< double > > m_UV
 
std::vector< ChVector< float > > m_colors
 
std::vector< ChVector< int > > m_face_v_indices
 
std::vector< ChVector< int > > m_face_n_indices
 
std::vector< ChVector< int > > m_face_uv_indices
 
std::vector< ChVector< int > > m_face_col_indices
 
std::string m_filename
 file string if loading an obj file
 

Additional Inherited Members

- Public Types inherited from chrono::geometry::ChGeometry
enum  GeometryType {
  NONE, SPHERE, BOX, CYLINDER,
  TRIANGLE, CAPSULE, CONE, LINE,
  LINE_ARC, LINE_BEZIER, LINE_CAM, LINE_PATH,
  LINE_POLY, LINE_SEGMENT, ROUNDED_BOX, ROUNDED_CYLINDER,
  ROUNDED_CONE, TRIANGLEMESH, TRIANGLEMESH_CONNECTED, TRIANGLEMESH_SOUP
}
 Enumeration of geometric objects.
 

Member Function Documentation

◆ addTriangle()

virtual void chrono::geometry::ChTriangleMeshConnected::addTriangle ( const ChVector<> &  vertex0,
const ChVector<> &  vertex1,
const ChVector<> &  vertex2 
)
inlineoverridevirtual

Add a triangle to this triangle mesh, by specifying the three coordinates.

This is disconnected - no vertex sharing is used even if it could be..

Implements chrono::geometry::ChTriangleMesh.

◆ ComputeNeighbouringTriangleMap()

bool chrono::geometry::ChTriangleMeshConnected::ComputeNeighbouringTriangleMap ( std::vector< std::array< int, 4 >> &  tri_map) const

Create a map of neighboring triangles, vector of: [Ti TieA TieB TieC] (the free sides have triangle id = -1).

Return false if some edge has more than 2 neighboring triangles

◆ ComputeWingedEdges()

bool chrono::geometry::ChTriangleMeshConnected::ComputeWingedEdges ( std::map< std::pair< int, int >, std::pair< int, int >> &  winged_edges,
bool  allow_single_wing = true 
) const

Create a winged edge structure, map of {key, value} as {{edgevertexA, edgevertexB}, {triangleA, triangleB}} If allow_single_wing = false, only edges with at least 2 triangles are returned.

Else, also boundary edges with 1 triangle (the free side has triangle id = -1). Return false if some edge has more than 2 neighboring triangles.

◆ GetClassType()

virtual GeometryType chrono::geometry::ChTriangleMeshConnected::GetClassType ( ) const
inlineoverridevirtual

Get the class type as unique numerical ID (faster than using ChronoRTTI mechanism).

Each inherited class must return an unique ID.

Reimplemented from chrono::geometry::ChTriangleMesh.

◆ GetTriangleEdgeIndexes()

std::pair< int, int > chrono::geometry::ChTriangleMeshConnected::GetTriangleEdgeIndexes ( const std::vector< ChVector< int >> &  indexes,
int  it,
int  nedge,
bool  unique 
)

Return the indexes of the two vertexes of the i-th edge of the triangle.

Parameters
indexesindexes, xyz per each face, ex. getIndicesVertexes()
ittriangle index
nedgenumber of edge: 0,1,2
uniqueif true, swaps the pair so that 1st is always < 2nd id, so can test sharing wiht other triangle

◆ MakeOffset()

bool chrono::geometry::ChTriangleMeshConnected::MakeOffset ( const double  offset)

Offset the mesh, by a specified value, orthogonally to the faces.

The offset can be inward or outward. Note: self-collisions and inverted faces resulting from excessive offsets are NOT trimmed; so this is mostly meant to be a fast tool for making small offsets.

◆ RefineMeshEdges()

void chrono::geometry::ChTriangleMeshConnected::RefineMeshEdges ( std::vector< int > &  marked_tris,
double  edge_maxlen,
ChRefineEdgeCriterion criterion,
std::vector< std::array< int, 4 >> *  atri_map,
std::vector< std::vector< double > * > &  aux_data_double,
std::vector< std::vector< int > * > &  aux_data_int,
std::vector< std::vector< bool > * > &  aux_data_bool,
std::vector< std::vector< ChVector<>> * > &  aux_data_vect 
)

Performs mesh refinement using Rivara LEPP long-edge bisection algorithm.

Given a conforming, non-degenerate triangulation, it construct a locally refined triangulation with a prescribed resolution. This algorithm, for increasing resolution, tends to produce triangles with bounded angles even if starting from skewed/skinny triangles in the coarse mesh. Based on "Multithread parallelization of Lepp-bisection algorithms" M.-C. Rivara et al., Applied Numerical Mathematics 62 (2012) 473�488

Parameters
marked_trisindexes of triangles to refine (also surrounding triangles might be affected by refinements)
edge_maxlenmaximum length of edge (small values give higher resolution)
criterioncriterion for computing lenght (or other merit function) of edge, if =0 uses default (euclidean length)
atri_maptriangle connectivity map: use and modify it. Optional. If =0, creates a temporary one just for life span of function.
aux_data_doubleauxiliary buffers to refine (assuming indexed as vertexes: each with same size as vertex buffer)
aux_data_intauxiliary buffers to refine (assuming indexed as vertexes: each with same size as vertex buffer)
aux_data_boolauxiliary buffers to refine (assuming indexed as vertexes: each with same size as vertex buffer)
aux_data_vectauxiliary buffers to refine (assuming indexed as vertexes: each with same size as vertex buffer)

◆ RepairDuplicateVertexes()

int chrono::geometry::ChTriangleMeshConnected::RepairDuplicateVertexes ( const double  tolerance = 1e-18)

Connect overlapping vertexes.

This can beused to attempt to repair a mesh with 'open edges' to transform it into a watertight mesh. Say, if a cube is modeled with 6 faces with 4 distinct vertexes each, it might display properly, but for some algorithms, ex. collision detection, topological information might be needed, hence adjacent faces must be connected. Return the number of merged vertexes.

Parameters
tolerancewhen vertexes are closer than this value, they are merged

◆ SplitEdge()

bool chrono::geometry::ChTriangleMeshConnected::SplitEdge ( int  itA,
int  itB,
int  neA,
int  neB,
int &  itA_1,
int &  itA_2,
int &  itB_1,
int &  itB_2,
std::vector< std::array< int, 4 >> &  tri_map,
std::vector< std::vector< double > * > &  aux_data_double,
std::vector< std::vector< int > * > &  aux_data_int,
std::vector< std::vector< bool > * > &  aux_data_bool,
std::vector< std::vector< ChVector<>> * > &  aux_data_vect 
)

Split a given edge by inserting a vertex in the middle: from two triangles one gets four triangles.

It also interpolate normals, colors, uv. It also used and modifies the triangle neighboring map. If the two triangles do not share an edge, returns false.

Parameters
itAtriangle A index,
itBtriangle B index, -1 if not existing (means free edge on A)
neAn.edge on tri A: 0,1,2
neBn.edge on tri B: 0,1,2
itA_1returns the index of split triangle A, part1
itA_2returns the index of split triangle A, part2
itB_1returns the index of split triangle B, part1
itB_2returns the index of split triangle B, part2
tri_maptriangle neighbouring map
aux_data_doubleauxiliary buffers to interpolate (assuming indexed as vertexes: each with same size as vertex buffer)
aux_data_intauxiliary buffers to interpolate (assuming indexed as vertexes: each with same size as vertex buffer)
aux_data_boolauxiliary buffers to interpolate (assuming indexed as vertexes: each with same size as vertex buffer)
aux_data_vectauxiliary buffers to interpolate (assuming indexed as vertexes: each with same size as vertex buffer)

The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono/geometry/ChTriangleMeshConnected.h
  • /builds/uwsbel/chrono/src/chrono/geometry/ChTriangleMeshConnected.cpp