NetDEM v1.0
Loading...
Searching...
No Matches
shape.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "stl_model.hpp"
4#include "utils_math.hpp"
5#include <iostream>
6#include <nlohmann/json.hpp>
7#include <string>
8
9namespace netdem {
10
15class Shape {
16public:
42 int id{0};
43
47 std::string label{"default"};
48
53
57 std::string shape_name{"shape"};
58
59protected:
63 double size{1.0};
64
68 double volume{0.5236};
69
73 Mat3d inertia{{{0.05236, 0, 0}, {0, 0.05236, 0}, {0, 0, 0.05236}}};
74
80
84 double skin{0.025};
85
89 double skin_factor{0.05};
90
94 Vec3d bound_aabb_min{-0.5, -0.5, -0.5};
95
99 Vec3d bound_aabb_max{0.5, 0.5, 0.5};
100
104 bool is_convex{true};
105
106public:
111
112protected:
116 bool use_surface_nodes{false};
117
122
126 double surface_node_spacing{std::sqrt(Math::PI / 1000.0)};
127
132
137
138public:
143
144public:
149 virtual nlohmann::json PackJson();
150
155 virtual void InitFromJson(nlohmann::json const &js);
156
161 virtual void InitFromJsonFile(std::string const &js_file);
162
167 virtual double GetSize() const;
168
172 virtual double GetVolume() const;
173
177 virtual Mat3d const &GetInertia() const;
178
183
187 virtual double GetBoundSphereRadius() const;
188
193 virtual std::tuple<Vec3d, Vec3d> GetBoundAABB() const;
194
201 virtual std::tuple<Vec3d, Vec3d> GetBoundAABB(Vec3d const &pos,
202 Vec4d const &quat) const;
203
207 virtual double GetSkin() const;
208
212 virtual double GetSkinFactor() const;
213
217 virtual double GetSurfaceNodeNum() const;
218
222 virtual VecXT<Vec3d> const &GetSurfaceNodes() const;
223
227 virtual VecXT<double> const &GetSurfaceNodeAreas() const;
228
232 virtual double GetSurfaceNodeSpacing() const;
233
237 const STLModel &GetRenderMesh() const;
238
242 bool CheckConvexity();
243
248 virtual void Translate(Vec3d const &pos);
249
253 virtual void UpdateSurfaceNodes();
254
259 virtual void UpdateRenderMesh(int num_nodes = 200);
260
264 virtual void UpdateShapeProperties();
265
270 virtual void SetSize(double d);
271
275 virtual void SetSkin(double sk);
276
280 virtual void SetSkinFactor(double sk_factor);
281
285 virtual void EnableSurfaceNodes();
286
290 virtual void DisableSurfaceNodes();
291
296 virtual bool IsSurfaceNodesEnabled();
297
301 virtual void SetSurfaceNodeNum(int num);
302
306 virtual void SetSurfaceNodes(VecXT<Vec3d> const &nodes);
307
311 virtual void SetSurfaceNodes(STLModel const &surf_stl);
312
317 virtual Shape *Clone() const;
318
324 virtual STLModel GetSTLModel(int num_nodes = 200);
325
330 virtual void SaveAsVTK(std::string const &filename);
331
336 virtual void SaveAsSTL(std::string const &filename);
337
343 virtual Vec3d SupportPoint(Vec3d const &dir);
344
352 virtual VecXT<Vec3d> SupportPoints(Vec3d const &dir);
353
360 virtual double SignedDistance(Vec3d const &pos) const;
361
368 virtual Vec3d SurfacePoint(Vec3d const &pos);
369
377 virtual bool CheckEnclose(Vec3d const &pos) const;
378
383 virtual bool CheckPrincipal() const;
384
388 virtual void Print();
389
393 virtual ~Shape();
394
399 static MatNd<8, 3> VerticesOfAABB(Vec3d const &bmin, Vec3d const &bmax);
400};
401
402} // namespace netdem
static constexpr double PI
Definition utils_math.hpp:15
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
virtual STLModel GetSTLModel(int num_nodes=200)
Gets the STL model of the shape instance.
Definition shape.cpp:342
virtual void InitFromJson(nlohmann::json const &js)
Initializes the shape instance from a JSON object.
Definition shape.cpp:34
virtual Vec3d SupportPoint(Vec3d const &dir)
Gets the support point in a given direction for the shape instance.
Definition shape.cpp:358
virtual VecXT< Vec3d > SupportPoints(Vec3d const &dir)
Gets the set of support points in a given direction for the shape instance.
Definition shape.cpp:365
std::string shape_name
Name of the shape instance.
Definition shape.hpp:57
double volume
Volume of the shape instance.
Definition shape.hpp:68
virtual void UpdateSurfaceNodes()
Initializes the surface nodes of the shape instance.
Definition shape.cpp:214
int surface_node_num
Number of nodes used for the contact solver.
Definition shape.hpp:121
virtual void UpdateRenderMesh(int num_nodes=200)
Initializes the surface mesh for rendering.
Definition shape.cpp:219
Vec3d bound_aabb_max
Maximum bounds of the AABB used for broad-phase contact detection.
Definition shape.hpp:99
virtual void SaveAsSTL(std::string const &filename)
Saves the shape instance as an STL file.
Definition shape.cpp:353
virtual double GetSkinFactor() const
Return skin factor of the shape.
Definition shape.cpp:170
bool use_surface_nodes
Determines whether to use nodes for the contact solver.
Definition shape.hpp:116
bool CheckConvexity()
Return the convexity of the shape.
Definition shape.cpp:207
virtual double GetBoundSphereRadius() const
Return the inertia of the shape.
Definition shape.cpp:126
std::string label
Label of the shape instance.
Definition shape.hpp:47
virtual void UpdateShapeProperties()
Initializes the shape properties of the shape instance.
Definition shape.cpp:223
bool is_convex
Determines whether the shape instance is convex or not.
Definition shape.hpp:104
virtual void Translate(Vec3d const &pos)
Translates the shape instance to a new position.
Definition shape.cpp:209
virtual double GetSkin() const
Return skin size of the shape.
Definition shape.cpp:168
virtual void DisableSurfaceNodes()
Disable the use of surface nodes.
Definition shape.cpp:294
virtual bool CheckPrincipal() const
Determines whether the shape is in principal configuration.
Definition shape.cpp:393
virtual double GetSurfaceNodeSpacing() const
Return spacing of surface nodes.
Definition shape.cpp:180
virtual void SetSurfaceNodes(VecXT< Vec3d > const &nodes)
Set the surface nodes of the shape.
Definition shape.cpp:308
virtual void Print()
Prints the properties of the shape instance.
Definition shape.cpp:402
double surface_node_spacing
Spacing between nodes used for the contact solver.
Definition shape.hpp:126
double skin_factor
Factor used to adjust the skin thickness.
Definition shape.hpp:89
virtual void EnableSurfaceNodes()
Enable the use of surface nodes.
Definition shape.cpp:284
virtual bool IsSurfaceNodesEnabled()
Check if the use of surface nodes is enabled.
Definition shape.cpp:296
bool use_customized_solver
Determines whether to use a customized contact solver or not.
Definition shape.hpp:110
virtual void SetSize(double d)
Sets the size of the shape instance.
Definition shape.cpp:228
virtual Vec3d SurfacePoint(Vec3d const &pos)
Calculates the surface point corresponding to an intruding node.
Definition shape.cpp:382
virtual void SetSkinFactor(double sk_factor)
Set skin size factor (skin = size by skin size factor) of the shape.
Definition shape.cpp:279
virtual double GetVolume() const
Return the volume of the shape.
Definition shape.cpp:118
virtual ~Shape()
Destructor for the Shape class.
Definition shape.cpp:412
virtual void SaveAsVTK(std::string const &filename)
Saves the shape instance as a VTK file.
Definition shape.cpp:348
double bound_sphere_radius
Radius of the bounding sphere used for broad-phase contact detection.
Definition shape.hpp:79
virtual double SignedDistance(Vec3d const &pos) const
Calculates the signed distance between a point and the shape instance.
Definition shape.cpp:373
virtual Shape * Clone() const
Clones the shape instance.
Definition shape.cpp:340
virtual bool CheckEnclose(Vec3d const &pos) const
Determines whether a given point is enclosed within the shape instance.
Definition shape.cpp:389
virtual void SetSkin(double sk)
Set skin size of the shape.
Definition shape.cpp:274
virtual double GetSurfaceNodeNum() const
Return number of surface nodes of the shape.
Definition shape.cpp:172
Type
Enumeration for different types of shapes.
Definition shape.hpp:20
@ coded_netsdf
Definition shape.hpp:36
@ num_shapes
Definition shape.hpp:37
@ plane
Definition shape.hpp:30
@ sphere
Definition shape.hpp:23
@ poly_super_quadrics
Definition shape.hpp:33
@ triangle
Definition shape.hpp:29
@ trimesh
Definition shape.hpp:25
@ spherical_harmonics
Definition shape.hpp:24
@ trimesh_convex
Definition shape.hpp:26
@ point_sphere
Definition shape.hpp:22
@ level_set
Definition shape.hpp:34
@ netsdf
Definition shape.hpp:35
@ ellipsoid
Definition shape.hpp:27
@ cylinder
Definition shape.hpp:31
@ poly_super_ellipsoid
Definition shape.hpp:32
@ polybezier
Definition shape.hpp:28
@ none
Definition shape.hpp:21
virtual std::tuple< Vec3d, Vec3d > GetBoundAABB() const
Gets the boundary AABB of the shape instance.
Definition shape.cpp:128
virtual nlohmann::json PackJson()
Packs the data of the shape instance into a JSON object.
Definition shape.cpp:7
const STLModel & GetRenderMesh() const
Return the surface mesh for rendering.
Definition shape.cpp:205
Vec3d GetInertiaPrincipal() const
Return the principal inertia of the shape.
Definition shape.cpp:122
Mat3d inertia
Inertia tensor of the shape instance.
Definition shape.hpp:73
static MatNd< 8, 3 > VerticesOfAABB(Vec3d const &bmin, Vec3d const &bmax)
Gets the vertices of the boundary AABB of the shape instance.
Definition shape.cpp:414
virtual void SetSurfaceNodeNum(int num)
Set number of surface nodes of the shape.
Definition shape.cpp:298
double skin
Skin thickness used for broad-phase contact detection.
Definition shape.hpp:84
VecXT< Vec3d > surface_nodes
Surface nodes of the shape instance used for the contact solver.
Definition shape.hpp:131
virtual VecXT< double > const & GetSurfaceNodeAreas() const
Return surface area associated with each surface node.
Definition shape.cpp:197
STLModel render_mesh
Surface mesh for rendering.
Definition shape.hpp:142
Vec3d bound_aabb_min
Minimum bounds of the AABB used for broad-phase contact detection.
Definition shape.hpp:94
Type shape_type
Type of the shape instance.
Definition shape.hpp:52
virtual VecXT< Vec3d > const & GetSurfaceNodes() const
Return surface nodes of the shape.
Definition shape.cpp:189
virtual void InitFromJsonFile(std::string const &js_file)
Initializes the shape instance from a JSON file.
Definition shape.cpp:102
virtual double GetSize() const
Return shape size, which is defined as the diameter of equal-volume sphere.
Definition shape.cpp:116
VecXT< double > surface_node_areas
Area associated with each surface node.
Definition shape.hpp:136
double size
Size and volume of the shape instance.
Definition shape.hpp:63
virtual Mat3d const & GetInertia() const
Return the inertia of the shape.
Definition shape.cpp:120
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< std::array< double, Nc >, Nr > MatNd
Definition utils_macros.hpp:27
std::array< double, 4 > Vec4d
Definition utils_macros.hpp:19