NetDEM v1.0
Loading...
Searching...
No Matches
shape_trimesh.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "igl_wrapper.hpp"
4#include "sdf_calculator.hpp"
5#include "shape.hpp"
6#include "stl_model.hpp"
7#include "stl_reader.hpp"
8#include <iostream>
9#include <string>
10
11namespace netdem {
12
23class TriMesh : public Shape {
24public:
29
34
40
45 bool use_linked_patches{false};
46
51 int num_cells{8};
52
57
62
66 bool enable_debugging{false};
67
71 TriMesh();
72
81 nlohmann::json PackJson() override;
82
91 void InitFromJson(nlohmann::json const &js) override;
92
100 void InitFromSTL(std::string const &file);
101
109 void InitFromOFF(std::string const &file);
110
118 void InitFromSTL(STLModel const &stl_model);
119
126 void Init();
127
134 void AlignAxes();
135
145 void Decimate(int num_nodes);
146
153 void MakeConvex();
154
161 void UpdateSurfaceNodes() override;
162
169 void UpdateShapeProperties() override;
170
178 void SetSize(double d) override;
179
187 Shape *Clone() const override;
188
198 STLModel GetSTLModel(int num_nodes = 200) override;
199
211 Vec3d SupportPoint(Vec3d const &dir) override;
212
225 VecXT<Vec3d> SupportPoints(Vec3d const &dir) override;
226
239
253
266 void SupportPoints_HillClimbCheckCoplane(int vert_id, Vec3d const &max_pos,
267 VecXT<int> *const vert_id_list,
268 Vec3d const &dir);
269
281 Vec3d SupportPoint_Sweep(Vec3d const &dir);
282
296
309
323
333 double SignedDistance(Vec3d const &pos) const override;
334
346 Vec3d SurfacePoint(Vec3d const &pos) override;
347
358 int ClosestFacet(Vec3d const &pos);
359
366 void Print() override;
367
376 void SaveNormalPatchesSpherical(std::string const &file);
377
386 void SaveNormalPatchesCubic(std::string const &file);
387
388private:
396 void UpdateVerticesNeighs();
397
405 void UpdateLinkedVertices();
406
417 void UpdateLinkedVerticesSub(int vid);
418
428 VecXT<Vec3d> ComputeNormalPatch(int vid);
429
439 void SortNormalPatchVertices(VecXT<Vec3d> *const normals);
440
451 VecXT<Vec3d> ComputeCartesianProject(const VecXT<Vec3d> &normals);
452
463 VecXT<Vec3d> ComputeCartesianProject(const Vec3d &v1, const Vec3d &v2);
464
476 bool ContainCorner(Vec3d const &corner, const VecXT<Vec3d> &normals);
477
487 bool Find(const VecXT<int> &vert_id_list, int id);
488};
489
490} // namespace netdem
Class for computing signed distance fields from triangle meshes.
Definition sdf_calculator.hpp:20
Class for working with STL models.
Definition stl_model.hpp:17
This class represents different types of shapes and performs various calculations on them.
Definition shape.hpp:15
A class representing a triangular mesh in 3D space.
Definition shape_trimesh.hpp:23
void MakeConvex()
Make the TriMesh object convex.
Definition shape_trimesh.cpp:128
void InitFromSTL(std::string const &file)
Initialize the TriMesh object from an STL file.
void UpdateShapeProperties() override
Update the shape properties of the TriMesh object.
Definition shape_trimesh.cpp:158
double SignedDistance(Vec3d const &pos) const override
Calculate the signed distance from a point to the TriMesh object.
Definition shape_trimesh.cpp:513
VecXT< VecXT< int > > vertices_neighs
The neighboring vertices of each vertex for hill climbing support point calculation.
Definition shape_trimesh.hpp:39
void SaveNormalPatchesCubic(std::string const &file)
Save cubic normal patches for the TriMesh object to a file.
Definition shape_trimesh.cpp:588
VecXT< Vec3d > SupportPoints_Sweep(Vec3d const &dir)
Calculate the support points of the TriMesh object using the sweeping algorithm in the specified dire...
Definition shape_trimesh.cpp:358
bool use_linked_patches
Flag indicating whether to use the linked-patches algorithm for support point calculation.
Definition shape_trimesh.hpp:45
void InitFromJson(nlohmann::json const &js) override
Initialize the TriMesh object from a JSON structure.
Definition shape_trimesh.cpp:27
void Init()
Initialize the TriMesh object.
Definition shape_trimesh.cpp:65
Vec3d SupportPoint_LinkedVertices(Vec3d const &dir)
Calculate the support point of the TriMesh object using the linked-patches algorithm in the specified...
Definition shape_trimesh.cpp:390
SDFCalculator sdf_calculator
The signed distance function calculator for the TriMesh object.
Definition shape_trimesh.hpp:61
void Decimate(int num_nodes)
Decimate the TriMesh object.
Definition shape_trimesh.cpp:121
bool enable_debugging
Flag indicating whether to output debugging data.
Definition shape_trimesh.hpp:66
nlohmann::json PackJson() override
Pack the TriMesh object into a JSON structure.
Definition shape_trimesh.cpp:15
Vec3d SupportPoint_Sweep(Vec3d const &dir)
Calculate the support point of the TriMesh object using the sweeping algorithm in the specified direc...
Definition shape_trimesh.cpp:343
void UpdateSurfaceNodes() override
Update the surface nodes of the TriMesh object.
Definition shape_trimesh.cpp:135
Vec3d SurfacePoint(Vec3d const &pos) override
Calculate the surface point on the TriMesh object nearest to a given position.
Definition shape_trimesh.cpp:517
TriMesh()
Default constructor.
Definition shape_trimesh.cpp:10
VecXT< Vec3d > SupportPoints_HillClimb(Vec3d const &dir)
Calculate the support points of the TriMesh object using the hill climbing algorithm in the specified...
Definition shape_trimesh.cpp:292
int num_cells
The number of cells for the linked-patches algorithm (should be even).
Definition shape_trimesh.hpp:51
void SaveNormalPatchesSpherical(std::string const &file)
Save spherical normal patches for the TriMesh object to a file.
Definition shape_trimesh.cpp:556
void AlignAxes()
Align the axes of the TriMesh object.
Definition shape_trimesh.cpp:107
void SetSize(double d) override
Set the size of the TriMesh object.
Definition shape_trimesh.cpp:207
VecXT< Vec3i > facets
The faces (triangles) of the triangular mesh.
Definition shape_trimesh.hpp:33
void InitFromOFF(std::string const &file)
Initialize the TriMesh object from an OFF file.
Definition shape_trimesh.cpp:51
int ClosestFacet(Vec3d const &pos)
Find the closest facet on the TriMesh object to a given position.
Definition shape_trimesh.cpp:521
void Print() override
Print information about the TriMesh object.
Definition shape_trimesh.cpp:525
VecXT< Vec3d > vertices
The vertices of the triangular mesh.
Definition shape_trimesh.hpp:28
STLModel GetSTLModel(int num_nodes=200) override
Generate an STL model from the TriMesh object.
Definition shape_trimesh.cpp:222
VecXT< Vec3d > SupportPoints_LinkedVertices(Vec3d const &dir)
Calculate the support points of the TriMesh object using the linked-patches algorithm in the specifie...
Definition shape_trimesh.cpp:452
Vec3d SupportPoint_HillClimb(Vec3d const &dir)
Calculate the support point of the TriMesh object using the hill climbing algorithm in the specified ...
Definition shape_trimesh.cpp:246
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.
Definition shape_trimesh.cpp:327
VecXT< VecXT< int > > linked_vertices
The vertices in each cell for the linked-patches algorithm.
Definition shape_trimesh.hpp:56
VecXT< Vec3d > SupportPoints(Vec3d const &dir) override
Calculate the support points of the TriMesh object in the specified direction.
Definition shape_trimesh.cpp:238
Shape * Clone() const override
Clone the TriMesh object.
Definition shape_trimesh.cpp:220
Vec3d SupportPoint(Vec3d const &dir) override
Calculate the support point of the TriMesh object in the specified direction.
Definition shape_trimesh.cpp:230
Definition bond_entry.hpp:7
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