NetDEM v1.0
Loading...
Searching...
No Matches
stl_model.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "utils_math.hpp"
4
5namespace netdem {
6
17class STLModel {
18public:
23
29
30 STLModel();
31 STLModel(const VecXT<Vec3d> &vv, const VecXT<Vec3i> &ff);
32
41 void InitFromSTL(std::string const &file);
42
51 void InitFromOFF(std::string const &file);
52
60 void Translate(Vec3d const &disp);
61
70 void Rotate(Vec4d const &quat);
71
80 void CopyPose(STLModel const &stl_model);
81
91 void CopyPoseDev(STLModel const &stl_model, STLModel const &stl_model_reset);
92
101 void SaveAsVTK(std::string const &file) const;
102
111 void SaveAsSTL(std::string const &file) const;
112
120
128
136 void ReorientFacets();
137
146 void Decimate(int num_nodes);
147
154 void Standardize();
155
164 void SetSize(double size);
165
173 void MakeConvex();
174
184 void Refine(int num_refines = 1);
185
195 void SmoothMesh(int num_trials = 1);
196
205 void MergeSTLModel(STLModel const &stl_model);
206
212 double GetSize() const;
213
224
236 bool IsFaceOutside(bool flip_outside = true);
237
246 bool CheckConvexity();
247
260 bool CheckEnclose(Vec3d const &pos) const;
261
269 void Print();
270
279 std::tuple<Vec3d, Vec3d> GetBoundAABB() const;
280
289 Vec3d GetCenter() const;
290
299 double GetSurfaceArea() const;
300
309 double GetVolume() const;
310
320 Mat3d GetInertia() const;
321
332 static Vec3d GetCenter(const VecXT<Vec3d> &v, const VecXT<Vec3i> &f);
333
344 static double GetSurfaceArea(const VecXT<Vec3d> &v, const VecXT<Vec3i> &f);
345
356 static double GetVolume(const VecXT<Vec3d> &v, const VecXT<Vec3i> &f);
357
368 static Mat3d GetInertia(const VecXT<Vec3d> &v, const VecXT<Vec3i> &f);
369
380 static bool CheckConvexity(const VecXT<Vec3d> &v, const VecXT<Vec3i> &f);
381
382private:
393 int VertexIndexInFacet(const Vec3d &facet, int vertex_id);
394};
395
396} // namespace netdem
Class for working with STL models.
Definition stl_model.hpp:17
void SmoothMesh(int num_trials=1)
Smooth the vertices of the model.
Definition stl_model.cpp:373
bool CheckConvexity()
Check if the model is convex.
Definition stl_model.cpp:425
void MakeConvex()
Make the model convex.
Definition stl_model.cpp:341
void SaveAsVTK(std::string const &file) const
Save the model as a VTK file.
Definition stl_model.cpp:170
std::tuple< Vec3d, Vec3d > GetBoundAABB() const
Get the axis-aligned bounding box of the model.
Definition stl_model.cpp:453
void Print()
Print information about the model to stdout.
Definition stl_model.cpp:447
VecXT< int > GetTriangleStrips() const
Get the triangle strip for VTK visualization.
Definition stl_model.cpp:391
STLModel()
Definition stl_model.cpp:20
void InitFromOFF(std::string const &file)
Initialize the model from an OFF file.
Definition stl_model.cpp:35
Mat3d GetInertia() const
Get the inertia tensor of the model.
Definition stl_model.cpp:478
double GetVolume() const
Get the volume of the model.
Definition stl_model.cpp:476
void CopyPoseDev(STLModel const &stl_model, STLModel const &stl_model_reset)
A workaround that uses stl_model_reset to reset the pose.
Definition stl_model.cpp:127
void Translate(Vec3d const &disp)
Translate the model by a given displacement.
Definition stl_model.cpp:71
Vec3d GetCenter() const
Get the center of mass of the model.
Definition stl_model.cpp:470
void RemoveDuplicateVertices()
Remove any duplicate vertices from the model.
Definition stl_model.cpp:251
VecXT< Vec3i > facets
A M by 3 matrix. Each row defines a facet, with the row elements being the indices of the vertices.
Definition stl_model.hpp:28
void RemoveUnreferencedVertices()
Remove any unreferenced vertices from the model.
Definition stl_model.cpp:241
VecXT< Vec3d > vertices
A N by 3 matrix that defines the points on the 3D model surface.
Definition stl_model.hpp:22
void Decimate(int num_nodes)
Decimate the model by a given number of nodes.
Definition stl_model.cpp:280
double GetSurfaceArea() const
Get the surface area of the model.
Definition stl_model.cpp:472
double GetSize() const
Get the size of the model.
Definition stl_model.cpp:387
bool IsFaceOutside(bool flip_outside=true)
Check if a face is outside the model.
Definition stl_model.cpp:404
void Standardize()
Standardize the model.
Definition stl_model.cpp:290
void InitFromSTL(std::string const &file)
Initialize the model from an STL file.
Definition stl_model.cpp:25
void ReorientFacets()
Reorient the facets of the model.
Definition stl_model.cpp:260
void SaveAsSTL(std::string const &file) const
Save the model as an STL file.
Definition stl_model.cpp:205
void Refine(int num_refines=1)
Refine the mesh of the model.
Definition stl_model.cpp:361
void Rotate(Vec4d const &quat)
Rotate the model by a given quaternion.
Definition stl_model.cpp:79
void CopyPose(STLModel const &stl_model)
Set the center and rotation to those of another STL model.
Definition stl_model.cpp:85
bool CheckEnclose(Vec3d const &pos) const
Check if a point is enclosed by the model.
Definition stl_model.cpp:437
void MergeSTLModel(STLModel const &stl_model)
Merge another STL model into this one.
Definition stl_model.cpp:351
void SetSize(double size)
Set the size of the model.
Definition stl_model.cpp:321
Definition bond_entry.hpp:7
std::array< std::array< double, 3 >, 3 > Mat3d
Definition utils_macros.hpp:22
std::vector< T > VecXT
Definition utils_macros.hpp:31
pos
Definition json_serilization.hpp:19
std::array< double, 3 > Vec3d
Definition utils_macros.hpp:18
std::array< double, 4 > Vec4d
Definition utils_macros.hpp:19