NetDEM v1.0
Loading...
Searching...
No Matches
netdem::TriMesh Class Reference

A class representing a triangular mesh in 3D space. More...

#include <shape_trimesh.hpp>

Inheritance diagram for netdem::TriMesh:
netdem::Shape

Public Member Functions

 TriMesh ()
 Default constructor.
 
nlohmann::json PackJson () override
 Pack the TriMesh object into a JSON structure.
 
void InitFromJson (nlohmann::json const &js) override
 Initialize the TriMesh object from a JSON structure.
 
void InitFromSTL (std::string const &file)
 Initialize the TriMesh object from an STL file.
 
void InitFromOFF (std::string const &file)
 Initialize the TriMesh object from an OFF file.
 
void InitFromSTL (STLModel const &stl_model)
 Initialize the TriMesh object from an STLModel object.
 
void Init ()
 Initialize the TriMesh object.
 
void AlignAxes ()
 Align the axes of the TriMesh object.
 
void Decimate (int num_nodes)
 Decimate the TriMesh object.
 
void MakeConvex ()
 Make the TriMesh object convex.
 
void UpdateSurfaceNodes () override
 Update the surface nodes of the TriMesh object.
 
void UpdateShapeProperties () override
 Update the shape properties of the TriMesh object.
 
void SetSize (double d) override
 Set the size of the TriMesh object.
 
ShapeClone () const override
 Clone the TriMesh object.
 
STLModel GetSTLModel (int num_nodes=200) override
 Generate an STL model from the TriMesh object.
 
Vec3d SupportPoint (Vec3d const &dir) override
 Calculate the support point of the TriMesh object in the specified direction.
 
VecXT< Vec3dSupportPoints (Vec3d const &dir) override
 Calculate the support points of the TriMesh object in the specified direction.
 
Vec3d SupportPoint_HillClimb (Vec3d const &dir)
 Calculate the support point of the TriMesh object using the hill climbing algorithm in the specified direction.
 
VecXT< Vec3dSupportPoints_HillClimb (Vec3d const &dir)
 Calculate the support points of the TriMesh object using the hill climbing algorithm in the specified direction.
 
void SupportPoints_HillClimbCheckCoplane (int vert_id, Vec3d const &max_pos, VecXT< int > *const vert_id_list, Vec3d const &dir)
 Check whether a vertex is coplanar with the specified surface normal and direction.
 
Vec3d SupportPoint_Sweep (Vec3d const &dir)
 Calculate the support point of the TriMesh object using the sweeping algorithm in the specified direction.
 
VecXT< Vec3dSupportPoints_Sweep (Vec3d const &dir)
 Calculate the support points of the TriMesh object using the sweeping algorithm in the specified direction.
 
Vec3d SupportPoint_LinkedVertices (Vec3d const &dir)
 Calculate the support point of the TriMesh object using the linked-patches algorithm in the specified direction.
 
VecXT< Vec3dSupportPoints_LinkedVertices (Vec3d const &dir)
 Calculate the support points of the TriMesh object using the linked-patches algorithm in the specified direction.
 
double SignedDistance (Vec3d const &pos) const override
 Calculate the signed distance from a point to the TriMesh object.
 
Vec3d SurfacePoint (Vec3d const &pos) override
 Calculate the surface point on the TriMesh object nearest to a given position.
 
int ClosestFacet (Vec3d const &pos)
 Find the closest facet on the TriMesh object to a given position.
 
void Print () override
 Print information about the TriMesh object.
 
void SaveNormalPatchesSpherical (std::string const &file)
 Save spherical normal patches for the TriMesh object to a file.
 
void SaveNormalPatchesCubic (std::string const &file)
 Save cubic normal patches for the TriMesh object to a file.
 
- Public Member Functions inherited from netdem::Shape
virtual void InitFromJsonFile (std::string const &js_file)
 Initializes the shape instance from a JSON file.
 
virtual double GetSize () const
 Return shape size, which is defined as the diameter of equal-volume sphere.
 
virtual double GetVolume () const
 Return the volume of the shape.
 
virtual Mat3d const & GetInertia () const
 Return the inertia of the shape.
 
Vec3d GetInertiaPrincipal () const
 Return the principal inertia of the shape.
 
virtual double GetBoundSphereRadius () const
 Return the inertia of the shape.
 
virtual std::tuple< Vec3d, Vec3dGetBoundAABB () const
 Gets the boundary AABB of the shape instance.
 
virtual std::tuple< Vec3d, Vec3dGetBoundAABB (Vec3d const &pos, Vec4d const &quat) const
 Gets the boundary AABB of the shape instance.
 
virtual double GetSkin () const
 Return skin size of the shape.
 
virtual double GetSkinFactor () const
 Return skin factor of the shape.
 
virtual double GetSurfaceNodeNum () const
 Return number of surface nodes of the shape.
 
virtual VecXT< Vec3d > const & GetSurfaceNodes () const
 Return surface nodes of the shape.
 
virtual VecXT< double > const & GetSurfaceNodeAreas () const
 Return surface area associated with each surface node.
 
virtual double GetSurfaceNodeSpacing () const
 Return spacing of surface nodes.
 
const STLModelGetRenderMesh () const
 Return the surface mesh for rendering.
 
bool CheckConvexity ()
 Return the convexity of the shape.
 
virtual void Translate (Vec3d const &pos)
 Translates the shape instance to a new position.
 
virtual void UpdateRenderMesh (int num_nodes=200)
 Initializes the surface mesh for rendering.
 
virtual void SetSkin (double sk)
 Set skin size of the shape.
 
virtual void SetSkinFactor (double sk_factor)
 Set skin size factor (skin = size by skin size factor) of the shape.
 
virtual void EnableSurfaceNodes ()
 Enable the use of surface nodes.
 
virtual void DisableSurfaceNodes ()
 Disable the use of surface nodes.
 
virtual bool IsSurfaceNodesEnabled ()
 Check if the use of surface nodes is enabled.
 
virtual void SetSurfaceNodeNum (int num)
 Set number of surface nodes of the shape.
 
virtual void SetSurfaceNodes (VecXT< Vec3d > const &nodes)
 Set the surface nodes of the shape.
 
virtual void SetSurfaceNodes (STLModel const &surf_stl)
 Set the surface nodes of the shape.
 
virtual void SaveAsVTK (std::string const &filename)
 Saves the shape instance as a VTK file.
 
virtual void SaveAsSTL (std::string const &filename)
 Saves the shape instance as an STL file.
 
virtual bool CheckEnclose (Vec3d const &pos) const
 Determines whether a given point is enclosed within the shape instance.
 
virtual bool CheckPrincipal () const
 Determines whether the shape is in principal configuration.
 
virtual ~Shape ()
 Destructor for the Shape class.
 

Public Attributes

VecXT< Vec3dvertices
 The vertices of the triangular mesh.
 
VecXT< Vec3ifacets
 The faces (triangles) of the triangular mesh.
 
VecXT< VecXT< int > > vertices_neighs
 The neighboring vertices of each vertex for hill climbing support point calculation.
 
bool use_linked_patches {false}
 Flag indicating whether to use the linked-patches algorithm for support point calculation.
 
int num_cells {8}
 The number of cells for the linked-patches algorithm (should be even).
 
VecXT< VecXT< int > > linked_vertices
 The vertices in each cell for the linked-patches algorithm.
 
SDFCalculator sdf_calculator
 The signed distance function calculator for the TriMesh object.
 
bool enable_debugging {false}
 Flag indicating whether to output debugging data.
 
- Public Attributes inherited from netdem::Shape
int id {0}
 ID of the shape instance.
 
std::string label {"default"}
 Label of the shape instance.
 
Type shape_type {Type::none}
 Type of the shape instance.
 
std::string shape_name {"shape"}
 Name of the shape instance.
 
bool use_customized_solver {false}
 Determines whether to use a customized contact solver or not.
 
STLModel render_mesh
 Surface mesh for rendering.
 

Additional Inherited Members

- Public Types inherited from netdem::Shape
enum  Type {
  none , point_sphere , sphere , spherical_harmonics ,
  trimesh , trimesh_convex , ellipsoid , polybezier ,
  triangle , plane , cylinder , poly_super_ellipsoid ,
  poly_super_quadrics , level_set , netsdf , coded_netsdf ,
  num_shapes
}
 Enumeration for different types of shapes. More...
 
- Static Public Member Functions inherited from netdem::Shape
static MatNd< 8, 3 > VerticesOfAABB (Vec3d const &bmin, Vec3d const &bmax)
 Gets the vertices of the boundary AABB of the shape instance.
 
- Protected Attributes inherited from netdem::Shape
double size {1.0}
 Size and volume of the shape instance.
 
double volume {0.5236}
 Volume of the shape instance.
 
Mat3d inertia {{{0.05236, 0, 0}, {0, 0.05236, 0}, {0, 0, 0.05236}}}
 Inertia tensor of the shape instance.
 
double bound_sphere_radius {0.5}
 Radius of the bounding sphere used for broad-phase contact detection.
 
double skin {0.025}
 Skin thickness used for broad-phase contact detection.
 
double skin_factor {0.05}
 Factor used to adjust the skin thickness.
 
Vec3d bound_aabb_min {-0.5, -0.5, -0.5}
 Minimum bounds of the AABB used for broad-phase contact detection.
 
Vec3d bound_aabb_max {0.5, 0.5, 0.5}
 Maximum bounds of the AABB used for broad-phase contact detection.
 
bool is_convex {true}
 Determines whether the shape instance is convex or not.
 
bool use_surface_nodes {false}
 Determines whether to use nodes for the contact solver.
 
int surface_node_num {1000}
 Number of nodes used for the contact solver.
 
double surface_node_spacing {std::sqrt(Math::PI / 1000.0)}
 Spacing between nodes used for the contact solver.
 
VecXT< Vec3dsurface_nodes
 Surface nodes of the shape instance used for the contact solver.
 
VecXT< double > surface_node_areas
 Area associated with each surface node.
 

Detailed Description

A class representing a triangular mesh in 3D space.

This class provides methods for generating, initializing, and computing operations on a TriMesh object. The object is defined by its vertices and facets, and provides various options for calculating the support points of the mesh. It also provides methods for computing signed distance, surface point, and generating an STL model.

Examples
00_gen_dataset.cpp, 00_gen_dataset_trimesh_plane.cpp, 00_hertz_contact.cpp, 00_nut_in_bolt.cpp, 00_sdf_demo.cpp, 01_sdf_error.cpp, 01_test_dataset_trimesh_plane.cpp, 04_demo_normal_patches.cpp, 05_ave_num_linked_patches.cpp, 05_test_shape_netsdf.cpp, 06_test_ann_vs_geom_trimesh_plane.cpp, 10_gen_dataset_trimesh.cpp, 11_test_dataset_trimesh.cpp, 16_test_ann_vs_geom_trimesh.cpp, 17_test_ann_vs_geom_trimesh.cpp, 1_gjk_solver.cpp, 2_sdf_solver.cpp, 3_hybrid_solver.cpp, 81_golf_ball_impact.cpp, 81_voronoi_packing.cpp, 90_packing_demo.cpp, 90_random_packing_trimesh.cpp, 91_triaixal_comp.cpp, 92_angle_of_repose.cpp, and 92_nut_in_bolt.cpp.

Constructor & Destructor Documentation

◆ TriMesh()

TriMesh::TriMesh ( )

Default constructor.

Member Function Documentation

◆ AlignAxes()

◆ Clone()

Shape * TriMesh::Clone ( ) const
overridevirtual

Clone the TriMesh object.

This method creates and returns a deep copy of the TriMesh object.

Returns
A pointer to the cloned TriMesh object.

Reimplemented from netdem::Shape.

◆ ClosestFacet()

int TriMesh::ClosestFacet ( Vec3d const & pos)

Find the closest facet on the TriMesh object to a given position.

This method finds the closest facet on the TriMesh object to a given position by calculating the distance from the position to each facet and returning the ID of the closest one.

Parameters
posThe position to find the closest facet to.
Returns
The ID of the closest facet.

◆ Decimate()

◆ GetSTLModel()

STLModel TriMesh::GetSTLModel ( int num_nodes = 200)
overridevirtual

Generate an STL model from the TriMesh object.

This method generates an STLModel object from the TriMesh object with the specified number of nodes.

Parameters
num_nodesThe desired number of nodes in the generated STL model.
Returns
The generated STL model.

Reimplemented from netdem::Shape.

◆ Init()

void TriMesh::Init ( )

Initialize the TriMesh object.

This method initializes the TriMesh object by updating its nodes and shape properties.

◆ InitFromJson()

void TriMesh::InitFromJson ( nlohmann::json const & js)
overridevirtual

Initialize the TriMesh object from a JSON structure.

This method initializes the TriMesh object from a JSON structure previously generated by PackJson().

Parameters
jsThe JSON structure to load.

Reimplemented from netdem::Shape.

◆ InitFromOFF()

void TriMesh::InitFromOFF ( std::string const & file)

Initialize the TriMesh object from an OFF file.

This method initializes the TriMesh object from an OFF file.

Parameters
fileThe path to the OFF file.

◆ InitFromSTL() [1/2]

◆ InitFromSTL() [2/2]

void TriMesh::InitFromSTL ( STLModel const & stl_model)

Initialize the TriMesh object from an STLModel object.

This method initializes the TriMesh object from an STLModel object.

Parameters
stl_modelThe STLModel object to initialize from.

◆ MakeConvex()

void TriMesh::MakeConvex ( )

Make the TriMesh object convex.

This method modifies the TriMesh object to make it convex by removing all concavities.

Examples
1_gjk_solver.cpp, and 81_voronoi_packing.cpp.

◆ PackJson()

nlohmann::json TriMesh::PackJson ( )
overridevirtual

Pack the TriMesh object into a JSON structure.

This method packs the TriMesh object into a JSON structure for serialization and storage.

Returns
The packed JSON structure.

Reimplemented from netdem::Shape.

◆ Print()

void TriMesh::Print ( )
overridevirtual

Print information about the TriMesh object.

This method prints information about the TriMesh object, such as its vertices, facets, and shape properties.

Reimplemented from netdem::Shape.

◆ SaveNormalPatchesCubic()

void TriMesh::SaveNormalPatchesCubic ( std::string const & file)

Save cubic normal patches for the TriMesh object to a file.

This method saves cubic normal patches for the TriMesh object to a file in JSON format.

Parameters
fileThe path to the output file.
Examples
04_demo_normal_patches.cpp.

◆ SaveNormalPatchesSpherical()

void TriMesh::SaveNormalPatchesSpherical ( std::string const & file)

Save spherical normal patches for the TriMesh object to a file.

This method saves spherical normal patches for the TriMesh object to a file in JSON format.

Parameters
fileThe path to the output file.

◆ SetSize()

◆ SignedDistance()

double TriMesh::SignedDistance ( Vec3d const & pos) const
overridevirtual

Calculate the signed distance from a point to the TriMesh object.

This method calculates the signed distance from a point to the TriMesh object using the sdf calculator.

Parameters
posThe position to calculate the signed distance from.
Returns
The signed distance from the position to the TriMesh object.

Reimplemented from netdem::Shape.

Examples
00_gen_dataset.cpp, and 01_sdf_error.cpp.

◆ SupportPoint()

Vec3d TriMesh::SupportPoint ( Vec3d const & dir)
overridevirtual

Calculate the support point of the TriMesh object in the specified direction.

This method calculates the support point of the TriMesh object in the specified direction, which is the vertex that is farthest in that direction.

Parameters
dirThe direction vector to compute the support point for.
Returns
The support point of the TriMesh object in the specified direction.

Reimplemented from netdem::Shape.

◆ SupportPoint_HillClimb()

Vec3d TriMesh::SupportPoint_HillClimb ( Vec3d const & dir)

Calculate the support point of the TriMesh object using the hill climbing algorithm in the specified direction.

This method calculates the support point of the TriMesh object using the hill climbing algorithm in the specified direction, which is the vertex that is farthest in that direction.

Parameters
dirThe direction vector to compute the support point for.
Returns
The support point of the TriMesh object in the specified direction.

◆ SupportPoint_LinkedVertices()

Vec3d TriMesh::SupportPoint_LinkedVertices ( Vec3d const & dir)

Calculate the support point of the TriMesh object using the linked-patches algorithm in the specified direction.

This method calculates the support point of the TriMesh object using the linked-patches algorithm in the specified direction, which is the vertex that is farthest in that direction.

Parameters
dirThe direction vector to compute the support point for.
Returns
The support point of the TriMesh object in the specified direction.

◆ SupportPoint_Sweep()

Vec3d TriMesh::SupportPoint_Sweep ( Vec3d const & dir)

Calculate the support point of the TriMesh object using the sweeping algorithm in the specified direction.

This method calculates the support point of the TriMesh object using the sweeping algorithm in the specified direction, which is the vertex that is farthest in that direction.

Parameters
dirThe direction vector to compute the support point for.
Returns
The support point of the TriMesh object in the specified direction.

◆ SupportPoints()

VecXT< Vec3d > TriMesh::SupportPoints ( Vec3d const & dir)
overridevirtual

Calculate the support points of the TriMesh object in the specified direction.

This method calculates the support points of the TriMesh object in the specified direction, which are the vertices that are farthest in that direction.

Parameters
dirThe direction vector to compute the support points for.
Returns
A vector containing the support points of the TriMesh object in the specified direction.

Reimplemented from netdem::Shape.

◆ SupportPoints_HillClimb()

VecXT< Vec3d > TriMesh::SupportPoints_HillClimb ( Vec3d const & dir)

Calculate the support points of the TriMesh object using the hill climbing algorithm in the specified direction.

This method calculates the support points of the TriMesh object using the hill climbing algorithm in the specified direction, which are the vertices that are farthest in that direction.

Parameters
dirThe direction vector to compute the support points for.
Returns
A vector containing the support points of the TriMesh object in the specified direction.

◆ SupportPoints_HillClimbCheckCoplane()

void TriMesh::SupportPoints_HillClimbCheckCoplane ( int vert_id,
Vec3d const & max_pos,
VecXT< int > *const vert_id_list,
Vec3d const & dir )

Check whether a vertex is coplanar with the specified surface normal and direction.

This method checks whether a vertex is coplanar with the specified surface normal and direction.

Parameters
vert_idThe ID of the vertex to check.
max_posThe maximum position.
vert_id_listA list of vertex IDs.
dirThe direction vector.

◆ SupportPoints_LinkedVertices()

VecXT< Vec3d > TriMesh::SupportPoints_LinkedVertices ( Vec3d const & dir)

Calculate the support points of the TriMesh object using the linked-patches algorithm in the specified direction.

This method calculates the support points of the TriMesh object using the linked-patches algorithm in the specified direction, which are the vertices that are farthest in that direction.

Parameters
dirThe direction vector to compute the support points for.
Returns
A vector containing the support points of the TriMesh object in the specified direction.

◆ SupportPoints_Sweep()

VecXT< Vec3d > TriMesh::SupportPoints_Sweep ( Vec3d const & dir)

Calculate the support points of the TriMesh object using the sweeping algorithm in the specified direction.

This method calculates the support points of the TriMesh object using the sweeping algorithm in the specified direction, which are the vertices that are farthest in that direction.

Parameters
dirThe direction vector to compute the support points for.
Returns
A vector containing the support points of the TriMesh object in the specified direction.

◆ SurfacePoint()

Vec3d TriMesh::SurfacePoint ( Vec3d const & pos)
overridevirtual

Calculate the surface point on the TriMesh object nearest to a given position.

This method calculates the surface point on the TriMesh object nearest to a given position by finding the closest facet and calculating the intersection of a line between the position and the facet's plane.

Parameters
posThe position to find the nearest surface point to.
Returns
The surface point on the TriMesh object nearest to the position.

Reimplemented from netdem::Shape.

Examples
00_gen_dataset.cpp.

◆ UpdateShapeProperties()

void TriMesh::UpdateShapeProperties ( )
overridevirtual

Update the shape properties of the TriMesh object.

This method updates the shape properties of the TriMesh object, such as its surface area and volume.

Reimplemented from netdem::Shape.

◆ UpdateSurfaceNodes()

void TriMesh::UpdateSurfaceNodes ( )
overridevirtual

Update the surface nodes of the TriMesh object.

This method updates the surface nodes of the TriMesh object based on its current position and orientation.

Reimplemented from netdem::Shape.

Member Data Documentation

◆ enable_debugging

bool netdem::TriMesh::enable_debugging {false}

Flag indicating whether to output debugging data.

Examples
81_voronoi_packing.cpp.

◆ facets

VecXT<Vec3i> netdem::TriMesh::facets

The faces (triangles) of the triangular mesh.

◆ linked_vertices

VecXT<VecXT<int> > netdem::TriMesh::linked_vertices

The vertices in each cell for the linked-patches algorithm.

Examples
05_ave_num_linked_patches.cpp.

◆ num_cells

int netdem::TriMesh::num_cells {8}

The number of cells for the linked-patches algorithm (should be even).

Examples
05_ave_num_linked_patches.cpp.

◆ sdf_calculator

SDFCalculator netdem::TriMesh::sdf_calculator

The signed distance function calculator for the TriMesh object.

◆ use_linked_patches

bool netdem::TriMesh::use_linked_patches {false}

Flag indicating whether to use the linked-patches algorithm for support point calculation.

Examples
04_demo_normal_patches.cpp, and 05_ave_num_linked_patches.cpp.

◆ vertices

◆ vertices_neighs

VecXT<VecXT<int> > netdem::TriMesh::vertices_neighs

The neighboring vertices of each vertex for hill climbing support point calculation.


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