NetDEM v1.0
|
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, Vec3d > | GetBoundAABB () 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< Vec3d > | vertices |
A N by 3 matrix that defines the points on the 3D model surface. | |
VecXT< Vec3i > | facets |
A M by 3 matrix. Each row defines a facet, with the row elements being the indices of the vertices. | |
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.
STLModel::STLModel | ( | ) |
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.
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.
v | The vertices of the mesh. |
f | The facets of the mesh. |
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.
pos | The position of the point to check. |
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.
stl_model | The other STL model. |
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.
stl_model | The other STL model. |
stl_model_reset | The reset STL model. |
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.
num_nodes | The number of nodes remaining. |
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.
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.
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.
v | The vertices of the mesh. |
f | The facets of the mesh. |
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.
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.
v | The vertices of the mesh. |
f | The facets of the mesh. |
double STLModel::GetSize | ( | ) | const |
Get the size of the model.
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.
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.
v | The vertices of the mesh. |
f | The facets of the mesh. |
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.
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.
Get the volume of a set of vertices and facets.
This static method computes the volume of a given set of vertices and facets.
v | The vertices of the mesh. |
f | The facets of the mesh. |
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.
file | The name of the input OFF file. |
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.
file | The name of the input STL file. |
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.
flip_outside | Whether to invert the normal if it points outside the model. Defaults to true. |
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.
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.
stl_model | The other STL model to merge. |
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.
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
.
num_refines | The number of times to refine the mesh. |
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.
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.
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.
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.
quat | The rotation quaternion. |
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.
file | The name of the output file. |
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.
file | The name of the output file. |
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.
size | The desired size of the model. |
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
.
num_trials | The number of smoothing iterations to perform. |
void STLModel::Standardize | ( | ) |
Standardize the model.
This method standardizes the model by centering it at the origin and scaling it to have unit volume.
void STLModel::Translate | ( | Vec3d const & | disp | ) |
Translate the model by a given displacement.
This method translates the model by a given displacement vector.
disp | The displacement vector. |
A M by 3 matrix. Each row defines a facet, with the row elements being the indices of the vertices.
A N by 3 matrix that defines the points on the 3D model surface.