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< ChVector2< double > > & getCoordsUV ()
 
std::vector< ChColor > & getCoordsColors ()
 
std::vector< ChVector< int > > & getIndicesVertexes ()
 
std::vector< ChVector< int > > & getIndicesNormals ()
 
std::vector< ChVector< int > > & getIndicesUV ()
 
std::vector< ChVector< int > > & getIndicesColors ()
 
std::vector< int > & getIndicesMaterials ()
 
bool LoadWavefrontMesh (const std::string &filename, bool load_normals=true, bool load_uv=false)
 Load a Wavefront OBJ file into this triangle mesh.
 
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.
 
const std::string & GetFileName () const
 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 [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}}. 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 ChVector< int > &face_indices, 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 std::shared_ptr< ChTriangleMeshConnectedCreateFromWavefrontFile (const std::string &filename, bool load_normals=true, bool load_uv=false)
 Create and return a ChTriangleMeshConnected from a Wavefront OBJ file. More...
 
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< ChVector2< double > > m_UV
 
std::vector< ChColorm_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::vector< int > m_face_mat_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()

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

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 [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.

◆ CreateFromWavefrontFile()

std::shared_ptr< ChTriangleMeshConnected > chrono::geometry::ChTriangleMeshConnected::CreateFromWavefrontFile ( const std::string &  filename,
bool  load_normals = true,
bool  load_uv = false 
)
static

Create and return a ChTriangleMeshConnected from a Wavefront OBJ file.

If an error occurrs during loading, an empty shared pointer is returned.

◆ 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 ChVector< int > &  face_indices,
int  nedge,
bool  unique 
)

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

If unique=true, swap the pair so that 1st < 2nd, to permit test sharing with other triangle.

Parameters
face_indicesindices of a triangular face
nedgenumber of edge: 0, 1, 2
uniqueswap?

◆ 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) 473488 The auxiliary buffers are used for refinement and assumed to be indexed like the vertex buffer.

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 null uses default (euclidean length)
atri_mapoptional triangle connectivity map
aux_data_doubleauxiliary buffer
aux_data_intauxiliary buffer
aux_data_boolauxiliary buffer
aux_data_vectauxiliary 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. The auxiliary buffers are used for interpolation and assumed to be indexed like the vertex buffer.

Parameters
itAtriangle A index,
itBtriangle B index, -1 if not present (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
aux_data_intauxiliary buffers
aux_data_boolauxiliary buffers
aux_data_vectauxiliary buffers

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