NetDEM v1.0
|
A class representing a spherical harmonics object. More...
#include <shape_spherical_harmonics.hpp>
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. | |
Shape * | Clone () 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, Vec3d > | GetBoundAABB () const |
Gets the boundary AABB of the shape instance. | |
virtual std::tuple< Vec3d, Vec3d > | GetBoundAABB (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 STLModel & | GetRenderMesh () 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< Vec3d > | SupportPoints (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< Vec3d > | surface_nodes |
Surface nodes of the shape instance used for the contact solver. | |
VecXT< double > | surface_node_areas |
Area associated with each surface node. | |
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.
SphericalHarmonics::SphericalHarmonics | ( | ) |
Default constructor.
SphericalHarmonics::SphericalHarmonics | ( | int | n | ) |
Constructor with specified degree.
n | The degree of the SphericalHarmonics object. |
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.
theta | The polar angle theta. |
phi | The azimuthal angle phi. |
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.
dir | The direction vector to compute the rho value for. |
|
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.
theta | A vector of polar angles theta. |
phi | A vector of azimuthal angles phi. |
deg | The degree of the expansion. |
|
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.
theta | The polar angle theta. |
phi | The azimuthal angle phi. |
deg | The degree of the expansion. |
|
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.
theta | A vector of polar angles theta. |
phi | A vector of azimuthal angles phi. |
deg | The degree of the expansion. |
|
static |
|
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.
theta | The polar angle theta. |
phi | The azimuthal angle phi. |
deg | The degree of the expansion. |
|
overridevirtual |
Clone the SphericalHarmonics object.
This method creates a copy of the SphericalHarmonics object.
Reimplemented from netdem::Shape.
|
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.
num_nodes | The number of nodes to use for each surface triangle (default: 200). |
Reimplemented from netdem::Shape.
void SphericalHarmonics::Init | ( | ) |
Initialize the SphericalHarmonics object.
This method initializes the SphericalHarmonics object by updating its nodes and shape properties.
|
overridevirtual |
Initialize the SphericalHarmonics object from a JSON structure.
This method initializes the SphericalHarmonics object from a JSON structure previously generated by PackJson().
js | The JSON structure to load. |
Reimplemented from netdem::Shape.
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().
file | The path to the STL file to load. |
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().
stl_model | The STLModel object to load. |
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.
surf_points | The list of surface points to use. |
|
overridevirtual |
Pack the SphericalHarmonics object into a JSON structure.
This method packs the SphericalHarmonics object into a JSON structure for serialization and storage.
Reimplemented from netdem::Shape.
|
overridevirtual |
Set the size of the SphericalHarmonics object.
This method sets the radius of the SphericalHarmonics object to a new value.
d | The new radius to use. |
Reimplemented from netdem::Shape.
|
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.
pos | The point to compute the signed distance from. |
Reimplemented from netdem::Shape.
Vec2d SphericalHarmonics::SurfaceCurvature | ( | double | theta, |
double | phi ) |
Vec3d SphericalHarmonics::SurfaceNormal | ( | double | theta, |
double | phi ) |
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.
pos | The point to find the closest surface point to. |
Reimplemented from netdem::Shape.
|
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.
|
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.
VecXT<double> netdem::SphericalHarmonics::a_nm |
The coefficients of each term in the SphericalHarmonics expansion. Please run Init() if a_nm is modified.
int netdem::SphericalHarmonics::degree {8} |
The degree of the SphericalHarmonics object.