NetDEM v1.0
Loading...
Searching...
No Matches
shape_spherical_harmonics.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "shape.hpp"
4#include "stl_model.hpp"
5#include "stl_reader.hpp"
6#include <cmath>
7#include <iostream>
8#include <string>
9
10namespace netdem {
11
24class SphericalHarmonics : public Shape {
25public:
26 int degree{8};
30
35
41 SphericalHarmonics(int n);
42
51 nlohmann::json PackJson() override;
52
61 void InitFromJson(nlohmann::json const &js) override;
62
71 void InitFromSTL(std::string const &file);
72
81 void InitFromSTL(STLModel const &stl_model);
82
93 void InitFromSurfacePoints(VecXT<Vec3d> const surf_points);
94
101 void Init();
102
109 void UpdateSurfaceNodes() override;
110
117 void UpdateShapeProperties() override;
118
127 void SetSize(double d) override;
128
140 STLModel GetSTLModel(int num_nodes = 200) override;
141
148 Shape *Clone() const override;
149
162 double SignedDistance(Vec3d const &pos) const override;
163
175 Vec3d SurfacePoint(Vec3d const &pos) override;
176
178
180
181 Vec3d SurfaceNormal(double theta, double phi);
182
183 Vec2d SurfaceCurvature(double theta, double phi);
184
197 static VecXT<double> CalculateYnm(double theta, double phi, int deg);
198
212 const VecXT<double> &phi, int deg);
213
226 static VecXT<double> CalculateYnm_Fast(double theta, double phi, int deg);
227
242 const VecXT<double> &phi,
243 int deg);
244
255 double CalculateRho(double theta, double phi) const;
256
257 // another fast option by using unit VecXT as direction (thus to avoid sin
258 // and cos)
259 static VecXT<double> CalculateYnm_Fast(Vec3d const &dir, int deg);
260 static VecXT<VecXT<double>> CalculateYnm_Fast(const VecXT<Vec3d> &dir_list,
261 int deg);
262
272 double CalculateRho(Vec3d const &dir) const;
273
274private:
286 static VecXT<VecXT<double>> sph_legendre_fast(double theta, int deg);
287
299 static VecXT<VecXT<double>> sph_legendre_fast(Vec3d const &dir, int deg);
300
301 double d_rho_d_theta(double theta, double phi);
302
303 double d_rho_d_phi(double theta, double phi);
304
305 Vec3d d_xyz_d_theta(double theta, double phi);
306
307 Vec3d d_xyz_d_phi(double theta, double phi);
308
309 Vec3d d_normal_d_theta(double theta, double phi);
310
311 Vec3d d_normal_d_phi(double theta, double phi);
312};
313
314} // namespace netdem
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
A class representing a spherical harmonics object.
Definition shape_spherical_harmonics.hpp:24
Vec2d SurfaceCurvature(Vec3d const &pos)
Definition shape_spherical_harmonics.cpp:269
static VecXT< double > CalculateYnm(double theta, double phi, int deg)
Calculate the spherical harmonics terms for a given theta, phi, and degree.
Definition shape_spherical_harmonics.cpp:333
Shape * Clone() const override
Clone the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:234
Vec3d SurfacePoint(Vec3d const &pos) override
Compute the surface point of the SphericalHarmonics object closest to a given point.
Definition shape_spherical_harmonics.cpp:248
void InitFromSTL(std::string const &file)
Initialize the SphericalHarmonics object from an STL file.
void SetSize(double d) override
Set the size of the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:175
STLModel GetSTLModel(int num_nodes=200) override
Generate an STL model for the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:184
int degree
The degree of the SphericalHarmonics object.
Definition shape_spherical_harmonics.hpp:26
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 value...
Definition shape_spherical_harmonics.cpp:380
double CalculateRho(double theta, double phi) const
Calculate the rho value for a given theta and phi.
Definition shape_spherical_harmonics.cpp:429
void UpdateSurfaceNodes() override
Update the surface nodes of the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:107
SphericalHarmonics()
Default constructor.
Definition shape_spherical_harmonics.cpp:22
VecXT< double > a_nm
Definition shape_spherical_harmonics.hpp:27
void InitFromJson(nlohmann::json const &js) override
Initialize the SphericalHarmonics object from a JSON structure.
Definition shape_spherical_harmonics.cpp:44
double SignedDistance(Vec3d const &pos) const override
Compute the signed distance between a point and the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:238
void Init()
Initialize the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:100
void UpdateShapeProperties() override
Update the shape properties of the SphericalHarmonics object.
Definition shape_spherical_harmonics.cpp:129
nlohmann::json PackJson() override
Pack the SphericalHarmonics object into a JSON structure.
Definition shape_spherical_harmonics.cpp:36
Vec3d SurfaceNormal(Vec3d const &pos)
Definition shape_spherical_harmonics.cpp:261
void InitFromSurfacePoints(VecXT< Vec3d > const surf_points)
Initialize the SphericalHarmonics object from a list of surface points.
Definition shape_spherical_harmonics.cpp:81
Definition bond_entry.hpp:7
std::array< double, 2 > Vec2d
Definition utils_macros.hpp:17
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