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

A class representing a spherical harmonics object. More...

#include <shape_spherical_harmonics.hpp>

Inheritance diagram for netdem::SphericalHarmonics:
netdem::Shape

Public Member Functions

 SphericalHarmonics ()
 Default constructor.
 
 SphericalHarmonics (int n)
 Constructor with specified degree.
 
nlohmann::json PackJson () override
 Pack the SphericalHarmonics object into a JSON structure.
 
void InitFromJson (nlohmann::json const &js) override
 Initialize the SphericalHarmonics object from a JSON structure.
 
void InitFromSTL (std::string const &file)
 Initialize the SphericalHarmonics object from an STL file.
 
void InitFromSTL (STLModel const &stl_model)
 Initialize the SphericalHarmonics object from an STL model.
 
void InitFromSurfacePoints (VecXT< Vec3d > const surf_points)
 Initialize the SphericalHarmonics object from a list of surface points.
 
void Init ()
 Initialize the SphericalHarmonics object.
 
void UpdateSurfaceNodes () override
 Update the surface nodes of the SphericalHarmonics object.
 
void UpdateShapeProperties () override
 Update the shape properties of the SphericalHarmonics object.
 
void SetSize (double d) override
 Set the size of the SphericalHarmonics object.
 
STLModel GetSTLModel (int num_nodes=200) override
 Generate an STL model for the SphericalHarmonics object.
 
ShapeClone () const override
 Clone the SphericalHarmonics object.
 
double SignedDistance (Vec3d const &pos) const override
 Compute the signed distance between a point and the SphericalHarmonics object.
 
Vec3d SurfacePoint (Vec3d const &pos) override
 Compute the surface point of the SphericalHarmonics object closest to a given point.
 
Vec3d SurfaceNormal (Vec3d const &pos)
 
Vec2d SurfaceCurvature (Vec3d const &pos)
 
Vec3d SurfaceNormal (double theta, double phi)
 
Vec2d SurfaceCurvature (double theta, double phi)
 
double CalculateRho (double theta, double phi) const
 Calculate the rho value for a given theta and phi.
 
double CalculateRho (Vec3d const &dir) const
 Calculate the rho value for a given direction vector.
 
- 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 void Print ()
 Prints the properties of the shape instance.
 
virtual ~Shape ()
 Destructor for the Shape class.
 

Static Public Member Functions

static VecXT< double > CalculateYnm (double theta, double phi, int deg)
 Calculate the spherical harmonics terms for a given theta, phi, and degree.
 
static VecXT< VecXT< double > > CalculateYnm (const VecXT< double > &theta, const VecXT< double > &phi, int deg)
 Calculate the spherical harmonics terms for given theta, phi vectors, and degree.
 
static VecXT< double > CalculateYnm_Fast (double theta, double phi, int deg)
 Calculate the spherical harmonics terms for a given theta, phi, and degree using pre-calculated values.
 
static VecXT< VecXT< double > > CalculateYnm_Fast (const VecXT< double > &theta, const VecXT< double > &phi, int deg)
 Calculate the spherical harmonics terms for given theta, phi vectors, and degree using pre-calculated values.
 
static VecXT< double > CalculateYnm_Fast (Vec3d const &dir, int deg)
 
static VecXT< VecXT< double > > CalculateYnm_Fast (const VecXT< Vec3d > &dir_list, int deg)
 
- 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

int degree {8}
 The degree of the SphericalHarmonics object.
 
VecXT< double > a_nm
 
- 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.
 

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...
 
- 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 representing a spherical harmonics object.

This class provides methods for generating, initializing, and computing operations on a SphericalHarmonics object. The object is defined by its degree, radius, and coefficients for each term in the harmonics expansion. In particular, it provides methods for computing signed distance, surface point, and generating an STL model. It also provides various options for calculating the spherical harmonics terms, including basic, fast, and with pre-calculated values.

Examples
00_contact_test_sphere.cpp, 00_sdf_demo.cpp, 01_contact_test_trimesh.cpp, 02_energy_test.cpp, 03_friction_test_sphere.cpp, 04_friction_test_trimesh.cpp, 10_contact_test_sphere.cpp, 11_contact_test_trimesh.cpp, 16_test_latent_space.cpp, 2_sdf_solver.cpp, 3_hybrid_solver.cpp, 90_packing_demo.cpp, 91_triaixal_comp_trimesh.cpp, 92_angle_repose_trimesh.cpp, 93_triaixal_comp_trimesh.cpp, and 94_angle_repose_trimesh.cpp.

Constructor & Destructor Documentation

◆ SphericalHarmonics() [1/2]

SphericalHarmonics::SphericalHarmonics ( )

Default constructor.

◆ SphericalHarmonics() [2/2]

SphericalHarmonics::SphericalHarmonics ( int n)

Constructor with specified degree.

Parameters
nThe degree of the SphericalHarmonics object.

Member Function Documentation

◆ CalculateRho() [1/2]

double SphericalHarmonics::CalculateRho ( double theta,
double phi ) const

Calculate the rho value for a given theta and phi.

This method calculates the rho value for a given theta and phi using the SphericalHarmonics expansion coefficients.

Parameters
thetaThe polar angle theta.
phiThe azimuthal angle phi.
Returns
The rho value for the given input.

◆ CalculateRho() [2/2]

double SphericalHarmonics::CalculateRho ( Vec3d const & dir) const

Calculate the rho value for a given direction vector.

This method calculates the rho value for a given direction vector using the SphericalHarmonics expansion coefficients.

Parameters
dirThe direction vector to compute the rho value for.
Returns
The rho value for the given input.

◆ CalculateYnm() [1/2]

VecXT< VecXT< double > > SphericalHarmonics::CalculateYnm ( const VecXT< double > & theta,
const VecXT< double > & phi,
int deg )
static

Calculate the spherical harmonics terms for given theta, phi vectors, and degree.

This method calculates the spherical harmonics expansion terms for given theta, phi vectors, and degree using the basic method.

Parameters
thetaA vector of polar angles theta.
phiA vector of azimuthal angles phi.
degThe degree of the expansion.
Returns
A matrix containing the expansion terms for the given input.

◆ CalculateYnm() [2/2]

VecXT< double > SphericalHarmonics::CalculateYnm ( double theta,
double phi,
int deg )
static

Calculate the spherical harmonics terms for a given theta, phi, and degree.

This method calculates the spherical harmonics expansion terms for a given theta, phi, and degree using the basic method.

Parameters
thetaThe polar angle theta.
phiThe azimuthal angle phi.
degThe degree of the expansion.
Returns
A vector containing the expansion terms for the given input.

◆ CalculateYnm_Fast() [1/4]

VecXT< VecXT< double > > SphericalHarmonics::CalculateYnm_Fast ( const VecXT< double > & theta,
const VecXT< double > & phi,
int deg )
static

Calculate the spherical harmonics terms for given theta, phi vectors, and degree using pre-calculated values.

This method calculates the spherical harmonics expansion terms for given theta, phi vectors, and degree using pre-calculated values to speed up computation.

Parameters
thetaA vector of polar angles theta.
phiA vector of azimuthal angles phi.
degThe degree of the expansion.
Returns
A matrix containing the expansion terms for the given input.

◆ CalculateYnm_Fast() [2/4]

VecXT< VecXT< double > > SphericalHarmonics::CalculateYnm_Fast ( const VecXT< Vec3d > & dir_list,
int deg )
static

◆ CalculateYnm_Fast() [3/4]

VecXT< double > SphericalHarmonics::CalculateYnm_Fast ( double theta,
double phi,
int deg )
static

Calculate the spherical harmonics terms for a given theta, phi, and degree using pre-calculated values.

This method calculates the spherical harmonics expansion terms for a given theta, phi, and degree using pre-calculated values to speed up computation.

Parameters
thetaThe polar angle theta.
phiThe azimuthal angle phi.
degThe degree of the expansion.
Returns
A vector containing the expansion terms for the given input.

◆ CalculateYnm_Fast() [4/4]

VecXT< double > SphericalHarmonics::CalculateYnm_Fast ( Vec3d const & dir,
int deg )
static

◆ Clone()

Shape * SphericalHarmonics::Clone ( ) const
overridevirtual

Clone the SphericalHarmonics object.

This method creates a copy of the SphericalHarmonics object.

Returns
A pointer to the cloned SphericalHarmonics object.

Reimplemented from netdem::Shape.

◆ GetSTLModel()

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

Generate an STL model for the SphericalHarmonics object.

This method generates an STLModel object representing the SphericalHarmonics object with 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 SphericalHarmonics object.

Reimplemented from netdem::Shape.

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

◆ Init()

void SphericalHarmonics::Init ( )

Initialize the SphericalHarmonics object.

This method initializes the SphericalHarmonics object by updating its nodes and shape properties.

◆ InitFromJson()

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

Initialize the SphericalHarmonics object from a JSON structure.

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

Parameters
jsThe JSON structure to load.

Reimplemented from netdem::Shape.

◆ InitFromSTL() [1/2]

void netdem::SphericalHarmonics::InitFromSTL ( std::string const & file)

Initialize the SphericalHarmonics object from an STL file.

This method initializes the SphericalHarmonics object from an STL file by generating surface points and calling InitFromSurfacePoints().

Parameters
fileThe path to the STL file to load.
Examples
01_contact_test_trimesh.cpp, 02_energy_test.cpp, 04_friction_test_trimesh.cpp, 11_contact_test_trimesh.cpp, 2_sdf_solver.cpp, 3_hybrid_solver.cpp, 90_packing_demo.cpp, 91_triaixal_comp_trimesh.cpp, 92_angle_repose_trimesh.cpp, 93_triaixal_comp_trimesh.cpp, and 94_angle_repose_trimesh.cpp.

◆ InitFromSTL() [2/2]

void SphericalHarmonics::InitFromSTL ( STLModel const & stl_model)

Initialize the SphericalHarmonics object from an STL model.

This method initializes the SphericalHarmonics object from an STL model by generating surface points and calling InitFromSurfacePoints().

Parameters
stl_modelThe STLModel object to load.

◆ InitFromSurfacePoints()

void SphericalHarmonics::InitFromSurfacePoints ( VecXT< Vec3d > const surf_points)

Initialize the SphericalHarmonics object from a list of surface points.

This method initializes the SphericalHarmonics object from a list of surface points by computing the coefficients for each term in the SphericalHarmonics expansion.

Parameters
surf_pointsThe list of surface points to use.
Examples
16_test_latent_space.cpp.

◆ PackJson()

nlohmann::json SphericalHarmonics::PackJson ( )
overridevirtual

Pack the SphericalHarmonics object into a JSON structure.

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

Returns
The packed JSON structure.

Reimplemented from netdem::Shape.

◆ SetSize()

void SphericalHarmonics::SetSize ( double d)
overridevirtual

◆ SignedDistance()

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

Compute the signed distance between a point and the SphericalHarmonics object.

This method computes the signed distance between a point and the SphericalHarmonics object, which is positive if the point is outside the object and negative if it is inside.

Parameters
posThe point to compute the signed distance from.
Returns
The signed distance between the point and the SphericalHarmonics object.

Reimplemented from netdem::Shape.

◆ SurfaceCurvature() [1/2]

Vec2d SphericalHarmonics::SurfaceCurvature ( double theta,
double phi )

◆ SurfaceCurvature() [2/2]

Vec2d SphericalHarmonics::SurfaceCurvature ( Vec3d const & pos)

◆ SurfaceNormal() [1/2]

Vec3d SphericalHarmonics::SurfaceNormal ( double theta,
double phi )

◆ SurfaceNormal() [2/2]

Vec3d SphericalHarmonics::SurfaceNormal ( Vec3d const & pos)

◆ SurfacePoint()

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

Compute the surface point of the SphericalHarmonics object closest to a given point.

This method computes the surface point of the SphericalHarmonics object closest to a given point using a binary search algorithm.

Parameters
posThe point to find the closest surface point to.
Returns
The surface point of the SphericalHarmonics object closest to the specified point.

Reimplemented from netdem::Shape.

◆ UpdateShapeProperties()

void SphericalHarmonics::UpdateShapeProperties ( )
overridevirtual

Update the shape properties of the SphericalHarmonics object.

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

Reimplemented from netdem::Shape.

Examples
00_contact_test_sphere.cpp, 02_energy_test.cpp, 03_friction_test_sphere.cpp, and 10_contact_test_sphere.cpp.

◆ UpdateSurfaceNodes()

void SphericalHarmonics::UpdateSurfaceNodes ( )
overridevirtual

Update the surface nodes of the SphericalHarmonics object.

This method updates the surface nodes of the SphericalHarmonics object based on its radius and center position.

Reimplemented from netdem::Shape.

Member Data Documentation

◆ a_nm

VecXT<double> netdem::SphericalHarmonics::a_nm

The coefficients of each term in the SphericalHarmonics expansion. Please run Init() if a_nm is modified.

Examples
00_contact_test_sphere.cpp, 02_energy_test.cpp, 03_friction_test_sphere.cpp, and 10_contact_test_sphere.cpp.

◆ degree

int netdem::SphericalHarmonics::degree {8}

The degree of the SphericalHarmonics object.


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