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

A class for representing a level set function as a Shape object. More...

#include <shape_level_set.hpp>

Inheritance diagram for netdem::LevelSet:
netdem::LevelSetFunction netdem::Shape

Public Member Functions

 LevelSet ()
 Default constructor.
 
nlohmann::json PackJson () override
 Pack the LevelSet object into a JSON structure.
 
void InitFromJson (nlohmann::json const &js) override
 Initialize the LevelSet object from a JSON structure.
 
void InitFromSTL (std::string const &file, int mesh_res=40)
 Initialize the LevelSet object from an STL file.
 
void InitFromSTL (STLModel const &stl_model, int mesh_res=40)
 Initialize the LevelSet object from an STL model.
 
void InitFromDistanceMap (double c_0, double c_1, double c_2, double sp, const VecXT< VecXT< VecXT< double > > > &dist_map)
 Initialize the LevelSet object from a distance map.
 
void Init ()
 Initialize the LevelSet object.
 
void AlignAxes ()
 Align the axes of the LevelSet object.
 
void UpdateSurfaceNodes () override
 Update the surface nodes of the LevelSet object.
 
void UpdateShapeProperties () override
 Update the shape properties of the LevelSet object.
 
void SetSize (double d) override
 Set the size of the LevelSet object.
 
ShapeClone () const override
 Clone the LevelSet object.
 
STLModel GetSTLModel (int num_nodes=200) override
 Generate an STL model of the LevelSet object.
 
double SignedDistance (Vec3d const &pos) const override
 Compute the signed distance from a given position to the surface of the LevelSet object.
 
Vec3d SurfacePoint (Vec3d const &pos) override
 Compute the surface point closest to a given position on the LevelSet object.
 
void Print () override
 Print information about the LevelSet object.
 
- Public Member Functions inherited from netdem::LevelSetFunction
 LevelSetFunction ()
 Default constructor.
 
Vec3d const & GetCorner () const
 
double GetSpacing () const
 
Vec3i const & GetDimensions () const
 
double GetSignedDistance (int id_x, int id_y, int id_z)
 Get the signed distance value of a certian cell of the grid.
 
VecXT< VecXT< VecXT< double > > > const & GetSignedDistanceTable () const
 
void SetCorner (double corner_x, double corner_y, double corner_z)
 Set the corner of the grid.
 
void SetSpacing (double sp)
 Set the spacing between grid points.
 
void SetDimension (double dim_x, double dim_y, double dim_z)
 Set the dimensions of the grid.
 
void SetSignedDistance (int id_x, int id_y, int id_z, double sdf)
 Set the signed distance value of a certian cell of the grid.
 
void InitFromSDFCalculator (const SDFCalculator &sdf_calculator)
 Initialize from a signed distance field.
 
double SignedDistance (Vec3d const &pos) const
 Compute the signed distance at a point in space.
 
Vec3d GradientInterpolate (Vec3d const &pos)
 Compute the gradient at a point in space using interpolation.
 
Vec3d GradientMinus (int i, int j, int k)
 Compute the gradient at the grid point (i, j, k) using backward differences.
 
Vec3d GradientPlus (int i, int j, int k)
 Compute the gradient at the grid point (i, j, k) using forward differences.
 
void Reinitialization (int iter, double dt)
 Perform reinitialization to maintain properties of the level set function.
 
void Reinitialization ()
 Perform reinitialization with default parameters.
 
- Public Member Functions inherited from netdem::Shape
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 UpdateRenderMesh (int num_nodes=200)
 Initializes the surface mesh for rendering.
 
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 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 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 ~Shape ()
 Destructor for the Shape class.
 

Additional Inherited Members

- Public Types inherited from netdem::Shape
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...
 
- Static Public Member Functions inherited from netdem::Shape
static MatNd< 8, 3 > VerticesOfAABB (Vec3d const &bmin, Vec3d const &bmax)
 Gets the vertices of the boundary AABB of the shape instance.
 
- Public Attributes inherited from netdem::Shape
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 inherited from netdem::LevelSetFunction
Vec3d corner {-0.5, -0.5, -0.5}
 Coordinates of the corner of the grid.
 
double spacing {0.05}
 Spacing between grid points.
 
Vec3i dim {21, 21, 21}
 Dimensions of the grid.
 
VecXT< VecXT< VecXT< double > > > signed_distance_table
 Table containing the signed distance values.
 
- Protected Attributes inherited from netdem::Shape
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

A class for representing a level set function as a Shape object.

This class provides methods for initializing a level set function from an STL file or distance map, computing signed distances and surface points, and generating STL models for visualization.

Additionally, the LevelSet class is a subclass of the Shape class, which allows it to be used in combination with other shapes in compound objects.

Examples
00_sdf_demo.cpp, and 90_packing_demo.cpp.

Constructor & Destructor Documentation

◆ LevelSet()

LevelSet::LevelSet ( )

Default constructor.

Member Function Documentation

◆ AlignAxes()

void LevelSet::AlignAxes ( )

Align the axes of the LevelSet object.

This method aligns the axes of the LevelSet object with the principal components of its surface points.

Examples
90_packing_demo.cpp.

◆ Clone()

Shape * LevelSet::Clone ( ) const
overridevirtual

Clone the LevelSet object.

This method creates a copy of the LevelSet object.

Returns
A pointer to the cloned LevelSet object.

Reimplemented from netdem::Shape.

◆ GetSTLModel()

STLModel LevelSet::GetSTLModel ( int num_nodes = 200)
overridevirtual

Generate an STL model of the LevelSet object.

This method generates an STL model of the LevelSet object using the specified number of nodes for each surface triangle.

Parameters
num_nodesThe number of nodes to use for each surface triangle (default: 200).
Returns
An STLModel object representing the LevelSet object.

Reimplemented from netdem::Shape.

◆ Init()

void LevelSet::Init ( )

Initialize the LevelSet object.

This method initializes the LevelSet object by aligning its axes and updating its nodes and shape properties.

◆ InitFromDistanceMap()

void LevelSet::InitFromDistanceMap ( double c_0,
double c_1,
double c_2,
double sp,
const VecXT< VecXT< VecXT< double > > > & dist_map )

Initialize the LevelSet object from a distance map.

This method initializes the LevelSet object from a distance map computed externally.

Parameters
c_0The x coordinate of the center of the bounding box containing the distance map.
c_1The y coordinate of the center of the bounding box containing the distance map.
c_2The z coordinate of the center of the bounding box containing the distance map.
spThe spacing between grid points in the distance map.
dist_mapThe distance map as a 3D array of double values.

◆ InitFromJson()

void LevelSet::InitFromJson ( nlohmann::json const & js)
overridevirtual

Initialize the LevelSet object from a JSON structure.

This method initializes the LevelSet object from a JSON structure previously generated by PackJson().

Parameters
jsThe JSON structure to load.

Reimplemented from netdem::Shape.

◆ InitFromSTL() [1/2]

void netdem::LevelSet::InitFromSTL ( std::string const & file,
int mesh_res = 40 )

Initialize the LevelSet object from an STL file.

This method initializes the LevelSet object from an STL file by converting it to a distance map and then computing its level set function.

Parameters
fileThe name of the STL file to load.
mesh_resThe resolution of the mesh used in the conversion to a distance map (default: 40).
Examples
90_packing_demo.cpp.

◆ InitFromSTL() [2/2]

void LevelSet::InitFromSTL ( STLModel const & stl_model,
int mesh_res = 40 )

Initialize the LevelSet object from an STL model.

This method initializes the LevelSet object from an STL model by converting it to a distance map and then computing its level set function.

Parameters
stl_modelThe STL model to load.
mesh_resThe resolution of the mesh used in the conversion to a distance map (default: 40).

◆ PackJson()

nlohmann::json LevelSet::PackJson ( )
overridevirtual

Pack the LevelSet object into a JSON structure.

This method packs the LevelSet object into a JSON structure for serialization and storage.

Returns
The packed JSON structure.

Reimplemented from netdem::Shape.

◆ Print()

void LevelSet::Print ( )
overridevirtual

Print information about the LevelSet object.

This method prints basic information about the LevelSet object, including its position, rotation, size, volume, and surface area.

Reimplemented from netdem::Shape.

◆ SetSize()

void LevelSet::SetSize ( double d)
overridevirtual

Set the size of the LevelSet object.

This method sets the size of the LevelSet object by scaling it uniformly in all dimensions.

Parameters
dThe new size of the LevelSet object.

Reimplemented from netdem::Shape.

Examples
90_packing_demo.cpp.

◆ SignedDistance()

double LevelSet::SignedDistance ( Vec3d const & pos) const
overridevirtual

Compute the signed distance from a given position to the surface of the LevelSet object.

This method computes the signed distance from a given position to the surface of the LevelSet object by evaluating its level set function.

Parameters
posThe position for which to compute the signed distance.
Returns
The signed distance from the specified position to the surface of the LevelSet object.

Reimplemented from netdem::Shape.

◆ SurfacePoint()

Vec3d LevelSet::SurfacePoint ( Vec3d const & pos)
overridevirtual

Compute the surface point closest to a given position on the LevelSet object.

This method computes the surface point closest to a given position on the LevelSet object by finding the intersection of a line passing through the specified position and perpendicular to the level set surface with the level set surface.

Parameters
posThe position for which to compute the closest surface point.
Returns
The surface point closest to the specified position on the LevelSet object.

Reimplemented from netdem::Shape.

◆ UpdateShapeProperties()

void LevelSet::UpdateShapeProperties ( )
overridevirtual

Update the shape properties of the LevelSet object.

This method updates the shape properties of the LevelSet object, such as its volume and surface area.

Reimplemented from netdem::Shape.

◆ UpdateSurfaceNodes()

void LevelSet::UpdateSurfaceNodes ( )
overridevirtual

Update the surface nodes of the LevelSet object.

This method updates the surface nodes of the LevelSet object based on its current position and rotation.

Reimplemented from netdem::Shape.


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