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

Class for working with STL models. More...

#include <stl_model.hpp>

Public Member Functions

 STLModel ()
 
 STLModel (const VecXT< Vec3d > &vv, const VecXT< Vec3i > &ff)
 
void InitFromSTL (std::string const &file)
 Initialize the model from an STL file.
 
void InitFromOFF (std::string const &file)
 Initialize the model from an OFF file.
 
void Translate (Vec3d const &disp)
 Translate the model by a given displacement.
 
void Rotate (Vec4d const &quat)
 Rotate the model by a given quaternion.
 
void CopyPose (STLModel const &stl_model)
 Set the center and rotation to those of another STL model.
 
void CopyPoseDev (STLModel const &stl_model, STLModel const &stl_model_reset)
 A workaround that uses stl_model_reset to reset the pose.
 
void SaveAsVTK (std::string const &file) const
 Save the model as a VTK file.
 
void SaveAsSTL (std::string const &file) const
 Save the model as an STL file.
 
void RemoveUnreferencedVertices ()
 Remove any unreferenced vertices from the model.
 
void RemoveDuplicateVertices ()
 Remove any duplicate vertices from the model.
 
void ReorientFacets ()
 Reorient the facets of the model.
 
void Decimate (int num_nodes)
 Decimate the model by a given number of nodes.
 
void Standardize ()
 Standardize the model.
 
void SetSize (double size)
 Set the size of the model.
 
void MakeConvex ()
 Make the model convex.
 
void Refine (int num_refines=1)
 Refine the mesh of the model.
 
void SmoothMesh (int num_trials=1)
 Smooth the vertices of the model.
 
void MergeSTLModel (STLModel const &stl_model)
 Merge another STL model into this one.
 
double GetSize () const
 Get the size of the model.
 
VecXT< int > GetTriangleStrips () const
 Get the triangle strip for VTK visualization.
 
bool IsFaceOutside (bool flip_outside=true)
 Check if a face is outside the model.
 
bool CheckConvexity ()
 Check if the model is convex.
 
bool CheckEnclose (Vec3d const &pos) const
 Check if a point is enclosed by the model.
 
void Print ()
 Print information about the model to stdout.
 
std::tuple< Vec3d, Vec3dGetBoundAABB () const
 Get the axis-aligned bounding box of the model.
 
Vec3d GetCenter () const
 Get the center of mass of the model.
 
double GetSurfaceArea () const
 Get the surface area of the model.
 
double GetVolume () const
 Get the volume of the model.
 
Mat3d GetInertia () const
 Get the inertia tensor of the model.
 

Static Public Member Functions

static Vec3d GetCenter (const VecXT< Vec3d > &v, const VecXT< Vec3i > &f)
 Get the center of mass of a set of vertices and facets.
 
static double GetSurfaceArea (const VecXT< Vec3d > &v, const VecXT< Vec3i > &f)
 Get the surface area of a set of vertices and facets.
 
static double GetVolume (const VecXT< Vec3d > &v, const VecXT< Vec3i > &f)
 Get the volume of a set of vertices and facets.
 
static Mat3d GetInertia (const VecXT< Vec3d > &v, const VecXT< Vec3i > &f)
 Get the inertia tensor of a set of vertices and facets.
 
static bool CheckConvexity (const VecXT< Vec3d > &v, const VecXT< Vec3i > &f)
 Check if a set of vertices and facets is convex.
 

Public Attributes

VecXT< Vec3dvertices
 A N by 3 matrix that defines the points on the 3D model surface.
 
VecXT< Vec3ifacets
 A M by 3 matrix. Each row defines a facet, with the row elements being the indices of the vertices.
 

Detailed Description

Class for working with STL models.

A class representing a 3D model in STL format.

This class provides methods for working with STL models, including loading and saving models in various formats, manipulating the orientation and position of the model, and computing geometric properties such as surface area and volume. It also provides methods for refining the mesh, smoothing the vertices, and merging models together.

This class represents a 3D model in STL (STereoLithography) format, which is commonly used in 3D printing and computer-aided design.

Examples
01_contact_test_trimesh.cpp, 02_ev_morphology.cpp, 03_simplify_cobble.cpp, 04_demo_normal_patches.cpp, 05_ave_num_linked_patches.cpp, 11_contact_test_trimesh.cpp, 15_test_coded_shape.cpp, 81_voronoi_packing.cpp, 91_triaixal_comp_trimesh.cpp, 92_angle_repose_trimesh.cpp, 93_triaixal_comp_trimesh.cpp, 94_angle_repose_trimesh.cpp, blade_mixing_main.cpp, and landslide_main.cpp.

Constructor & Destructor Documentation

◆ STLModel() [1/2]

STLModel::STLModel ( )

◆ STLModel() [2/2]

STLModel::STLModel ( const VecXT< Vec3d > & vv,
const VecXT< Vec3i > & ff )

Member Function Documentation

◆ CheckConvexity() [1/2]

bool STLModel::CheckConvexity ( )

Check if the model is convex.

This method checks if the model is convex by testing each facet to see if it is visible from the origin.

Returns
A boolean value indicating whether the model is convex.

◆ CheckConvexity() [2/2]

bool STLModel::CheckConvexity ( const VecXT< Vec3d > & v,
const VecXT< Vec3i > & f )
static

Check if a set of vertices and facets is convex.

This static method checks if a given set of vertices and facets is convex by testing each facet to see if it is visible from the origin.

Parameters
vThe vertices of the mesh.
fThe facets of the mesh.
Returns
A boolean value indicating whether the mesh is convex.

◆ CheckEnclose()

bool STLModel::CheckEnclose ( Vec3d const & pos) const

Check if a point is enclosed by the model.

only for convex mesh

This method checks if a given point is enclosed by the model by casting a ray from the point to infinity and counting the number of times it intersects the facets of the model. If the number of intersections is odd, the point is inside the model; otherwise, it is outside.

Parameters
posThe position of the point to check.
Returns
A boolean value indicating whether the point is enclosed by the model.
Examples
81_voronoi_packing.cpp.

◆ CopyPose()

void STLModel::CopyPose ( STLModel const & stl_model)

Set the center and rotation to those of another STL model.

This method sets the center and rotation of the current model to those of another STL model.

Parameters
stl_modelThe other STL model.

◆ CopyPoseDev()

void STLModel::CopyPoseDev ( STLModel const & stl_model,
STLModel const & stl_model_reset )

A workaround that uses stl_model_reset to reset the pose.

This method is a workaround that uses stl_model_reset to reset the pose of the current model.

Parameters
stl_modelThe other STL model.
stl_model_resetThe reset STL model.

◆ Decimate()

void STLModel::Decimate ( int num_nodes)

Decimate the model by a given number of nodes.

This method decimates the model by removing a given number of nodes while preserving its overall shape.

Parameters
num_nodesThe number of nodes remaining.
Examples
03_simplify_cobble.cpp.

◆ GetBoundAABB()

tuple< Vec3d, Vec3d > STLModel::GetBoundAABB ( ) const

Get the axis-aligned bounding box of the model.

This method computes the axis-aligned bounding box (AABB) of the model, which is the smallest rectangular box that contains all of its vertices.

Returns
A tuple containing the minimum and maximum coordinates of the AABB.
Examples
02_ev_morphology.cpp.

◆ GetCenter() [1/2]

Vec3d STLModel::GetCenter ( ) const

Get the center of mass of the model.

This method computes the center of mass of the model, which is defined as the weighted average of its vertices.

Returns
The center of mass of the model.

◆ GetCenter() [2/2]

Vec3d STLModel::GetCenter ( const VecXT< Vec3d > & v,
const VecXT< Vec3i > & f )
static

Get the center of mass of a set of vertices and facets.

This static method computes the center of mass of a given set of vertices and facets.

Parameters
vThe vertices of the mesh.
fThe facets of the mesh.
Returns
The center of mass of the mesh.

◆ GetInertia() [1/2]

Mat3d STLModel::GetInertia ( ) const

Get the inertia tensor of the model.

This method computes the inertia tensor of the model with respect to its center of mass. Note that this value is only valid if the mesh is watertight and has consistent orientation.

Returns
The inertia tensor of the model.

◆ GetInertia() [2/2]

Mat3d STLModel::GetInertia ( const VecXT< Vec3d > & v,
const VecXT< Vec3i > & f )
static

Get the inertia tensor of a set of vertices and facets.

This static method computes the inertia tensor of a given set of vertices and facets with respect to its center of mass.

Parameters
vThe vertices of the mesh.
fThe facets of the mesh.
Returns
The inertia tensor of the mesh.

◆ GetSize()

double STLModel::GetSize ( ) const

Get the size of the model.

Returns
size The desired size of the model.

◆ GetSurfaceArea() [1/2]

double STLModel::GetSurfaceArea ( ) const

Get the surface area of the model.

This method computes the surface area of the model by summing the areas of all of its facets.

Returns
The surface area of the model.
Examples
02_ev_morphology.cpp.

◆ GetSurfaceArea() [2/2]

double STLModel::GetSurfaceArea ( const VecXT< Vec3d > & v,
const VecXT< Vec3i > & f )
static

Get the surface area of a set of vertices and facets.

This static method computes the surface area of a given set of vertices and facets.

Parameters
vThe vertices of the mesh.
fThe facets of the mesh.
Returns
The surface area of the mesh.

◆ GetTriangleStrips()

VecXT< int > STLModel::GetTriangleStrips ( ) const

Get the triangle strip for VTK visualization.

This method computes a triangle strip for the current model that can be used for visualization in ParaView or another software package.

Returns
An array containing the indices of the vertices of the triangle strip.

◆ GetVolume() [1/2]

double STLModel::GetVolume ( ) const

Get the volume of the model.

This method computes the volume of the model by summing the volumes of all of its tetrahedra.

Returns
The volume of the model.
Examples
02_ev_morphology.cpp.

◆ GetVolume() [2/2]

double STLModel::GetVolume ( const VecXT< Vec3d > & v,
const VecXT< Vec3i > & f )
static

Get the volume of a set of vertices and facets.

This static method computes the volume of a given set of vertices and facets.

Parameters
vThe vertices of the mesh.
fThe facets of the mesh.
Returns
The volume of the mesh.

◆ InitFromOFF()

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

Initialize the model from an OFF file.

This method initializes the model from an OFF file. The vertices and facets are extracted and stored in the appropriate member variables.

Parameters
fileThe name of the input OFF file.

◆ InitFromSTL()

void STLModel::InitFromSTL ( std::string const & file)

Initialize the model from an STL file.

This method initializes the model from an STL file. The vertices and facets are extracted and stored in the appropriate member variables.

Parameters
fileThe name of the input STL file.
Examples
02_ev_morphology.cpp, 03_simplify_cobble.cpp, 05_ave_num_linked_patches.cpp, 81_voronoi_packing.cpp, 91_triaixal_comp_trimesh.cpp, 92_angle_repose_trimesh.cpp, 93_triaixal_comp_trimesh.cpp, 94_angle_repose_trimesh.cpp, and blade_mixing_main.cpp.

◆ IsFaceOutside()

bool STLModel::IsFaceOutside ( bool flip_outside = true)

Check if a face is outside the model.

This method checks if a given face is outside the model by computing the normal vector of the face and checking its orientation relative to the rest of the model.

Parameters
flip_outsideWhether to invert the normal if it points outside the model. Defaults to true.
Returns
A boolean value indicating whether the face is outside the model.

◆ MakeConvex()

void STLModel::MakeConvex ( )

Make the model convex.

This method makes the model convex by replacing each concave facet with a set of smaller triangles that fill in the gaps. It assumes that the mesh is closed and that the original orientation was consistent.

Examples
03_simplify_cobble.cpp, 91_triaixal_comp_trimesh.cpp, 92_angle_repose_trimesh.cpp, 93_triaixal_comp_trimesh.cpp, and 94_angle_repose_trimesh.cpp.

◆ MergeSTLModel()

void STLModel::MergeSTLModel ( STLModel const & stl_model)

Merge another STL model into this one.

This method merges another STL model into the current one by appending its vertices and facets to those of the current model.

Parameters
stl_modelThe other STL model to merge.

◆ Print()

void STLModel::Print ( )

Print information about the model to stdout.

This method prints information about the model to stdout, including the number of vertices and facets, the bounds of the model, and various geometric properties such as surface area and volume.

◆ Refine()

void STLModel::Refine ( int num_refines = 1)

Refine the mesh of the model.

This method refines the mesh of the model by splitting each facet into four sub-facets. The refinement process can be repeated multiple times by calling this method with increasing values of num_refines.

Parameters
num_refinesThe number of times to refine the mesh.
Examples
91_triaixal_comp_trimesh.cpp, 92_angle_repose_trimesh.cpp, 93_triaixal_comp_trimesh.cpp, and 94_angle_repose_trimesh.cpp.

◆ RemoveDuplicateVertices()

void STLModel::RemoveDuplicateVertices ( )

Remove any duplicate vertices from the model.

This method removes any duplicate vertices from the model, leaving only one copy of each distinct vertex.

◆ RemoveUnreferencedVertices()

void STLModel::RemoveUnreferencedVertices ( )

Remove any unreferenced vertices from the model.

This method removes any vertices from the model that are not referenced by any facets.

Examples
landslide_main.cpp.

◆ ReorientFacets()

void STLModel::ReorientFacets ( )

Reorient the facets of the model.

This method reorients the facets of the model so that their normals point outward. It assumes that the original orientation was consistent and that the mesh is closed.

◆ Rotate()

void STLModel::Rotate ( Vec4d const & quat)

Rotate the model by a given quaternion.

This method rotates the model by a given quaternion. The quaternion is assumed to be of unit length.

Parameters
quatThe rotation quaternion.

◆ SaveAsSTL()

void STLModel::SaveAsSTL ( std::string const & file) const

Save the model as an STL file.

This method saves the current model as an STL file for use in 3D printing or other applications.

Parameters
fileThe name of the output file.
Examples
01_random_generation.cpp, 03_simplify_cobble.cpp, 15_test_coded_shape.cpp, 16_test_latent_space.cpp, 81_voronoi_packing.cpp, and blade_mixing_main.cpp.

◆ SaveAsVTK()

void STLModel::SaveAsVTK ( std::string const & file) const

Save the model as a VTK file.

This method saves the current model as a VTK file for visualization in ParaView or another software package.

Parameters
fileThe name of the output file.
Examples
01_sdf_error.cpp.

◆ SetSize()

void STLModel::SetSize ( double size)

Set the size of the model.

This method sets the size of the model by uniformly scaling it such that its longest dimension is equal to a given value.

Parameters
sizeThe desired size of the model.

◆ SmoothMesh()

void STLModel::SmoothMesh ( int num_trials = 1)

Smooth the vertices of the model.

This method smooths the vertices of the model by averaging the positions of neighboring vertices. The smoothing process can be repeated multiple times by calling this method with increasing values of num_trials.

Parameters
num_trialsThe number of smoothing iterations to perform.
Examples
91_triaixal_comp_trimesh.cpp, 92_angle_repose_trimesh.cpp, 93_triaixal_comp_trimesh.cpp, and 94_angle_repose_trimesh.cpp.

◆ Standardize()

void STLModel::Standardize ( )

Standardize the model.

This method standardizes the model by centering it at the origin and scaling it to have unit volume.

Examples
02_ev_morphology.cpp, 03_simplify_cobble.cpp, and blade_mixing_main.cpp.

◆ Translate()

void STLModel::Translate ( Vec3d const & disp)

Translate the model by a given displacement.

This method translates the model by a given displacement vector.

Parameters
dispThe displacement vector.

Member Data Documentation

◆ facets

VecXT<Vec3i> netdem::STLModel::facets

A M by 3 matrix. Each row defines a facet, with the row elements being the indices of the vertices.

Examples
01_contact_test_trimesh.cpp, 11_contact_test_trimesh.cpp, 15_test_coded_shape.cpp, blade_mixing_main.cpp, and landslide_main.cpp.

◆ vertices

VecXT<Vec3d> netdem::STLModel::vertices

A N by 3 matrix that defines the points on the 3D model surface.

Examples
01_contact_test_trimesh.cpp, 11_contact_test_trimesh.cpp, 15_test_coded_shape.cpp, blade_mixing_main.cpp, and landslide_main.cpp.

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