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

This class represents different types of shapes and performs various calculations on them. More...

#include <shape.hpp>

Inheritance diagram for netdem::Shape:
netdem::CodedNetSDF netdem::Cylinder netdem::Ellipsoid netdem::LevelSet netdem::NetSDF netdem::Plane netdem::PointSphere netdem::PolySuperEllipsoid netdem::PolySuperQuadrics netdem::Polybezier netdem::Sphere netdem::SphericalHarmonics netdem::TriMesh netdem::Triangle

Public Types

enum  Type {
  none , point_sphere , sphere , spherical_harmonics ,
  trimesh , trimesh_convex , ellipsoid , polybezier ,
  triangle , plane , cylinder , poly_super_ellipsoid ,
  poly_super_quadrics , level_set , netsdf , coded_netsdf ,
  num_shapes
}
 Enumeration for different types of shapes. More...
 

Public Member Functions

virtual nlohmann::json PackJson ()
 Packs the data of the shape instance into a JSON object.
 
virtual void InitFromJson (nlohmann::json const &js)
 Initializes the shape instance from a JSON object.
 
virtual void InitFromJsonFile (std::string const &js_file)
 Initializes the shape instance from a JSON file.
 
virtual double GetSize () const
 Return shape size, which is defined as the diameter of equal-volume sphere.
 
virtual double GetVolume () const
 Return the volume of the shape.
 
virtual Mat3d const & GetInertia () const
 Return the inertia of the shape.
 
Vec3d GetInertiaPrincipal () const
 Return the principal inertia of the shape.
 
virtual double GetBoundSphereRadius () const
 Return the inertia of the shape.
 
virtual std::tuple< Vec3d, Vec3dGetBoundAABB () const
 Gets the boundary AABB of the shape instance.
 
virtual std::tuple< Vec3d, Vec3dGetBoundAABB (Vec3d const &pos, Vec4d const &quat) const
 Gets the boundary AABB of the shape instance.
 
virtual double GetSkin () const
 Return skin size of the shape.
 
virtual double GetSkinFactor () const
 Return skin factor of the shape.
 
virtual double GetSurfaceNodeNum () const
 Return number of surface nodes of the shape.
 
virtual VecXT< Vec3d > const & GetSurfaceNodes () const
 Return surface nodes of the shape.
 
virtual VecXT< double > const & GetSurfaceNodeAreas () const
 Return surface area associated with each surface node.
 
virtual double GetSurfaceNodeSpacing () const
 Return spacing of surface nodes.
 
const STLModelGetRenderMesh () const
 Return the surface mesh for rendering.
 
bool CheckConvexity ()
 Return the convexity of the shape.
 
virtual void Translate (Vec3d const &pos)
 Translates the shape instance to a new position.
 
virtual void UpdateSurfaceNodes ()
 Initializes the surface nodes of the shape instance.
 
virtual void UpdateRenderMesh (int num_nodes=200)
 Initializes the surface mesh for rendering.
 
virtual void UpdateShapeProperties ()
 Initializes the shape properties of the shape instance.
 
virtual void SetSize (double d)
 Sets the size of the shape instance.
 
virtual void SetSkin (double sk)
 Set skin size of the shape.
 
virtual void SetSkinFactor (double sk_factor)
 Set skin size factor (skin = size by skin size factor) of the shape.
 
virtual void EnableSurfaceNodes ()
 Enable the use of surface nodes.
 
virtual void DisableSurfaceNodes ()
 Disable the use of surface nodes.
 
virtual bool IsSurfaceNodesEnabled ()
 Check if the use of surface nodes is enabled.
 
virtual void SetSurfaceNodeNum (int num)
 Set number of surface nodes of the shape.
 
virtual void SetSurfaceNodes (VecXT< Vec3d > const &nodes)
 Set the surface nodes of the shape.
 
virtual void SetSurfaceNodes (STLModel const &surf_stl)
 Set the surface nodes of the shape.
 
virtual ShapeClone () const
 Clones the shape instance.
 
virtual STLModel GetSTLModel (int num_nodes=200)
 Gets the STL model of the shape instance.
 
virtual void SaveAsVTK (std::string const &filename)
 Saves the shape instance as a VTK file.
 
virtual void SaveAsSTL (std::string const &filename)
 Saves the shape instance as an STL file.
 
virtual Vec3d SupportPoint (Vec3d const &dir)
 Gets the support point in a given direction for the shape instance.
 
virtual VecXT< Vec3dSupportPoints (Vec3d const &dir)
 Gets the set of support points in a given direction for the shape instance.
 
virtual double SignedDistance (Vec3d const &pos) const
 Calculates the signed distance between a point and the shape instance.
 
virtual Vec3d SurfacePoint (Vec3d const &pos)
 Calculates the surface point corresponding to an intruding node.
 
virtual bool CheckEnclose (Vec3d const &pos) const
 Determines whether a given point is enclosed within the shape instance.
 
virtual bool CheckPrincipal () const
 Determines whether the shape is in principal configuration.
 
virtual void Print ()
 Prints the properties of the shape instance.
 
virtual ~Shape ()
 Destructor for the Shape class.
 

Static Public Member Functions

static MatNd< 8, 3 > VerticesOfAABB (Vec3d const &bmin, Vec3d const &bmax)
 Gets the vertices of the boundary AABB of the shape instance.
 

Public Attributes

int id {0}
 ID of the shape instance.
 
std::string label {"default"}
 Label of the shape instance.
 
Type shape_type {Type::none}
 Type of the shape instance.
 
std::string shape_name {"shape"}
 Name of the shape instance.
 
bool use_customized_solver {false}
 Determines whether to use a customized contact solver or not.
 
STLModel render_mesh
 Surface mesh for rendering.
 

Protected Attributes

double size {1.0}
 Size and volume of the shape instance.
 
double volume {0.5236}
 Volume of the shape instance.
 
Mat3d inertia {{{0.05236, 0, 0}, {0, 0.05236, 0}, {0, 0, 0.05236}}}
 Inertia tensor of the shape instance.
 
double bound_sphere_radius {0.5}
 Radius of the bounding sphere used for broad-phase contact detection.
 
double skin {0.025}
 Skin thickness used for broad-phase contact detection.
 
double skin_factor {0.05}
 Factor used to adjust the skin thickness.
 
Vec3d bound_aabb_min {-0.5, -0.5, -0.5}
 Minimum bounds of the AABB used for broad-phase contact detection.
 
Vec3d bound_aabb_max {0.5, 0.5, 0.5}
 Maximum bounds of the AABB used for broad-phase contact detection.
 
bool is_convex {true}
 Determines whether the shape instance is convex or not.
 
bool use_surface_nodes {false}
 Determines whether to use nodes for the contact solver.
 
int surface_node_num {1000}
 Number of nodes used for the contact solver.
 
double surface_node_spacing {std::sqrt(Math::PI / 1000.0)}
 Spacing between nodes used for the contact solver.
 
VecXT< Vec3dsurface_nodes
 Surface nodes of the shape instance used for the contact solver.
 
VecXT< double > surface_node_areas
 Area associated with each surface node.
 

Detailed Description

This class represents different types of shapes and performs various calculations on them.

Examples
00_sdf_demo.cpp.

Member Enumeration Documentation

◆ Type

Enumeration for different types of shapes.

Enumerator
none 
point_sphere 
sphere 
spherical_harmonics 
trimesh 
trimesh_convex 
ellipsoid 
polybezier 
triangle 
plane 
cylinder 
poly_super_ellipsoid 
poly_super_quadrics 
level_set 
netsdf 
coded_netsdf 
num_shapes 

Constructor & Destructor Documentation

◆ ~Shape()

Shape::~Shape ( )
virtual

Destructor for the Shape class.

Member Function Documentation

◆ CheckConvexity()

bool Shape::CheckConvexity ( )

Return the convexity of the shape.

◆ CheckEnclose()

bool Shape::CheckEnclose ( Vec3d const & pos) const
virtual

Determines whether a given point is enclosed within the shape instance.

Parameters
posThe point to test for enclosure.
Returns
True if the point is enclosed within the shape instance, false otherwise.

Reimplemented in netdem::Triangle.

◆ CheckPrincipal()

bool Shape::CheckPrincipal ( ) const
virtual

Determines whether the shape is in principal configuration.

Returns
True if the shape is in principal configuration, false otherwise.

◆ Clone()

◆ DisableSurfaceNodes()

void Shape::DisableSurfaceNodes ( )
virtual

Disable the use of surface nodes.

◆ EnableSurfaceNodes()

◆ GetBoundAABB() [1/2]

tuple< Vec3d, Vec3d > Shape::GetBoundAABB ( ) const
virtual

Gets the boundary AABB of the shape instance.

Returns
A tuple containing the minimum and maximum bounds of the AABB.

Reimplemented in netdem::Triangle.

Examples
81_voronoi_packing.cpp.

◆ GetBoundAABB() [2/2]

tuple< Vec3d, Vec3d > Shape::GetBoundAABB ( Vec3d const & pos,
Vec4d const & quat ) const
virtual

Gets the boundary AABB of the shape instance.

Parameters
posPosition of the shape instance.
quatQuaternion orientation of the shape instance.
Returns
A tuple containing the minimum and maximum bounds of the AABB.

Reimplemented in netdem::Plane, and netdem::Triangle.

◆ GetBoundSphereRadius()

◆ GetInertia()

Mat3d const & Shape::GetInertia ( ) const
virtual

Return the inertia of the shape.

◆ GetInertiaPrincipal()

Vec3d Shape::GetInertiaPrincipal ( ) const

Return the principal inertia of the shape.

◆ GetRenderMesh()

STLModel const & Shape::GetRenderMesh ( ) const

Return the surface mesh for rendering.

◆ GetSize()

◆ GetSkin()

double Shape::GetSkin ( ) const
virtual

Return skin size of the shape.

◆ GetSkinFactor()

double Shape::GetSkinFactor ( ) const
virtual

Return skin factor of the shape.

◆ GetSTLModel()

STLModel Shape::GetSTLModel ( int num_nodes = 200)
virtual

Gets the STL model of the shape instance.

Parameters
num_nodesNumber of nodes to use for the STL model (default: 200).
Returns
An STLModel object representing the shape instance.

Reimplemented in netdem::CodedNetSDF, netdem::Cylinder, netdem::Ellipsoid, netdem::LevelSet, netdem::NetSDF, netdem::Plane, netdem::PointSphere, netdem::Polybezier, netdem::PolySuperEllipsoid, netdem::PolySuperQuadrics, netdem::Sphere, netdem::SphericalHarmonics, netdem::Triangle, and netdem::TriMesh.

◆ GetSurfaceNodeAreas()

VecXT< double > const & Shape::GetSurfaceNodeAreas ( ) const
virtual

Return surface area associated with each surface node.

◆ GetSurfaceNodeNum()

double Shape::GetSurfaceNodeNum ( ) const
virtual

Return number of surface nodes of the shape.

◆ GetSurfaceNodes()

VecXT< Vec3d > const & Shape::GetSurfaceNodes ( ) const
virtual

Return surface nodes of the shape.

Examples
01_contact_test_trimesh.cpp, and 11_contact_test_trimesh.cpp.

◆ GetSurfaceNodeSpacing()

double Shape::GetSurfaceNodeSpacing ( ) const
virtual

Return spacing of surface nodes.

◆ GetVolume()

double Shape::GetVolume ( ) const
virtual

Return the volume of the shape.

◆ InitFromJson()

void Shape::InitFromJson ( nlohmann::json const & js)
virtual

◆ InitFromJsonFile()

void Shape::InitFromJsonFile ( std::string const & js_file)
virtual

Initializes the shape instance from a JSON file.

Parameters
js_filePath to the JSON file containing the shape data.

◆ IsSurfaceNodesEnabled()

bool Shape::IsSurfaceNodesEnabled ( )
virtual

Check if the use of surface nodes is enabled.

Returns
A flag whether the surface nodes is enabled.

◆ PackJson()

nlohmann::json Shape::PackJson ( )
virtual

◆ Print()

◆ SaveAsSTL()

void Shape::SaveAsSTL ( std::string const & filename)
virtual

Saves the shape instance as an STL file.

Parameters
filenamePath to the STL file to save.
Examples
00_gen_dataset.cpp, 02_energy_test.cpp, 04_demo_normal_patches.cpp, and 05_test_shape_netsdf.cpp.

◆ SaveAsVTK()

void Shape::SaveAsVTK ( std::string const & filename)
virtual

Saves the shape instance as a VTK file.

Parameters
filenamePath to the VTK file to save.

◆ SetSize()

void Shape::SetSize ( double d)
virtual

◆ SetSkin()

void Shape::SetSkin ( double sk)
virtual

Set skin size of the shape.

◆ SetSkinFactor()

void Shape::SetSkinFactor ( double sk_factor)
virtual

Set skin size factor (skin = size by skin size factor) of the shape.

Examples
blade_mixing_main.cpp.

◆ SetSurfaceNodeNum()

void Shape::SetSurfaceNodeNum ( int num)
virtual

Set number of surface nodes of the shape.

Examples
00_contact_test_sphere.cpp, and 10_contact_test_sphere.cpp.

◆ SetSurfaceNodes() [1/2]

void Shape::SetSurfaceNodes ( STLModel const & surf_stl)
virtual

Set the surface nodes of the shape.

◆ SetSurfaceNodes() [2/2]

void Shape::SetSurfaceNodes ( VecXT< Vec3d > const & nodes)
virtual

Set the surface nodes of the shape.

Examples
01_contact_test_trimesh.cpp, and 11_contact_test_trimesh.cpp.

◆ SignedDistance()

double Shape::SignedDistance ( Vec3d const & pos) const
virtual

Calculates the signed distance between a point and the shape instance.

Parameters
posThe point to calculate the distance from.
Returns
The signed distance between the point and the shape instance.

Reimplemented in netdem::CodedNetSDF, netdem::Cylinder, netdem::Ellipsoid, netdem::LevelSet, netdem::NetSDF, netdem::Plane, netdem::PointSphere, netdem::PolySuperEllipsoid, netdem::PolySuperQuadrics, netdem::Sphere, netdem::SphericalHarmonics, netdem::Triangle, and netdem::TriMesh.

◆ SupportPoint()

Vec3d Shape::SupportPoint ( Vec3d const & dir)
virtual

Gets the support point in a given direction for the shape instance.

Parameters
dirThe direction in which to find the support point.
Returns
The support point of the shape instance in the given direction.

Reimplemented in netdem::Cylinder, netdem::Ellipsoid, netdem::Plane, netdem::PointSphere, netdem::Polybezier, netdem::PolySuperEllipsoid, netdem::PolySuperQuadrics, netdem::Sphere, netdem::Triangle, and netdem::TriMesh.

◆ SupportPoints()

VecXT< Vec3d > Shape::SupportPoints ( Vec3d const & dir)
virtual

Gets the set of support points in a given direction for the shape instance.

Parameters
dirThe direction in which to find the support points.
Returns
The set of support points of the shape instance in the given direction.

Reimplemented in netdem::Cylinder, netdem::Ellipsoid, netdem::Plane, netdem::PointSphere, netdem::Polybezier, netdem::PolySuperEllipsoid, netdem::PolySuperQuadrics, netdem::Sphere, netdem::Triangle, and netdem::TriMesh.

◆ SurfacePoint()

Vec3d Shape::SurfacePoint ( Vec3d const & pos)
virtual

Calculates the surface point corresponding to an intruding node.

This method will be used to compute the contact point.

Parameters
posThe position of the intruding node.
Returns
The surface point corresponding to the intruding node.

calculate the surface point corrsponding to a intruding node. It will be used to compute the contact point

Reimplemented in netdem::CodedNetSDF, netdem::Cylinder, netdem::Ellipsoid, netdem::LevelSet, netdem::NetSDF, netdem::Plane, netdem::PointSphere, netdem::PolySuperEllipsoid, netdem::PolySuperQuadrics, netdem::Sphere, netdem::SphericalHarmonics, netdem::Triangle, and netdem::TriMesh.

◆ Translate()

void Shape::Translate ( Vec3d const & pos)
virtual

Translates the shape instance to a new position.

Parameters
posThe new position of the shape instance.

Reimplemented in netdem::Triangle.

◆ UpdateRenderMesh()

void Shape::UpdateRenderMesh ( int num_nodes = 200)
virtual

Initializes the surface mesh for rendering.

Parameters
num_nodesNumber of nodes to use for the STL model (default: 200).

◆ UpdateShapeProperties()

◆ UpdateSurfaceNodes()

◆ VerticesOfAABB()

MatNd< 8, 3 > Shape::VerticesOfAABB ( Vec3d const & bmin,
Vec3d const & bmax )
static

Gets the vertices of the boundary AABB of the shape instance.

Returns
A MatNd object containing the vertices of the boundary AABB.

Member Data Documentation

◆ bound_aabb_max

Vec3d netdem::Shape::bound_aabb_max {0.5, 0.5, 0.5}
protected

Maximum bounds of the AABB used for broad-phase contact detection.

◆ bound_aabb_min

Vec3d netdem::Shape::bound_aabb_min {-0.5, -0.5, -0.5}
protected

Minimum bounds of the AABB used for broad-phase contact detection.

◆ bound_sphere_radius

double netdem::Shape::bound_sphere_radius {0.5}
protected

Radius of the bounding sphere used for broad-phase contact detection.

◆ id

int netdem::Shape::id {0}

ID of the shape instance.

◆ inertia

Mat3d netdem::Shape::inertia {{{0.05236, 0, 0}, {0, 0.05236, 0}, {0, 0, 0.05236}}}
protected

Inertia tensor of the shape instance.

◆ is_convex

bool netdem::Shape::is_convex {true}
protected

Determines whether the shape instance is convex or not.

◆ label

std::string netdem::Shape::label {"default"}

Label of the shape instance.

◆ render_mesh

STLModel netdem::Shape::render_mesh

Surface mesh for rendering.

◆ shape_name

std::string netdem::Shape::shape_name {"shape"}

Name of the shape instance.

◆ shape_type

Type netdem::Shape::shape_type {Type::none}

Type of the shape instance.

◆ size

double netdem::Shape::size {1.0}
protected

Size and volume of the shape instance.

◆ skin

double netdem::Shape::skin {0.025}
protected

Skin thickness used for broad-phase contact detection.

◆ skin_factor

double netdem::Shape::skin_factor {0.05}
protected

Factor used to adjust the skin thickness.

◆ surface_node_areas

VecXT<double> netdem::Shape::surface_node_areas
protected

Area associated with each surface node.

◆ surface_node_num

int netdem::Shape::surface_node_num {1000}
protected

Number of nodes used for the contact solver.

◆ surface_node_spacing

double netdem::Shape::surface_node_spacing {std::sqrt(Math::PI / 1000.0)}
protected

Spacing between nodes used for the contact solver.

◆ surface_nodes

VecXT<Vec3d> netdem::Shape::surface_nodes
protected

Surface nodes of the shape instance used for the contact solver.

◆ use_customized_solver

bool netdem::Shape::use_customized_solver {false}

Determines whether to use a customized contact solver or not.

◆ use_surface_nodes

bool netdem::Shape::use_surface_nodes {false}
protected

Determines whether to use nodes for the contact solver.

◆ volume

double netdem::Shape::volume {0.5236}
protected

Volume of the shape instance.


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