15#ifndef EBGeometry_AnalyticDistanceFunctions
16#define EBGeometry_AnalyticDistanceFunctions
36clamp(
const T& v,
const T& lo,
const T& hi)
38 return (v < lo) ? lo : (v > hi) ? hi : v;
58constexpr static std::array<int, 256> s_perlinPermutationTable = {
59 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142,
60 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203,
61 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165,
62 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41,
63 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89,
64 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250,
65 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189,
66 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
67 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34,
68 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31,
69 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114,
70 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
513 T d = std::numeric_limits<T>::infinity();
525 constexpr T zero =
T(0.0);
527 if (
w <= zero &&
h <= zero) {
528 d = (std::abs(
w) < std::abs(
h)) ?
w :
h;
533 else if (
w > zero &&
h < zero) {
713 constexpr T pi = 3.14159265358979323846;
737 const T d2 =
d1 * ((
q.x *
m_c.y -
q.y *
m_c.x < 0.0) ? -1.0 : 1.0);
774 constexpr T pi = 3.14159265358979323846;
799 constexpr T zero =
T(0.0);
800 constexpr T one =
T(1.0);
807 auto sign = [](
const T& x) {
return (x > zero) - (x < zero); };
811 const T s = std::max(
k * (
w.x *
q.y -
w.y *
q.x),
k * (
w.y -
q.y));
911 for (
int i = 0;
i < 256;
i++) {
917 std::random_device
rd;
960 template <
class URNG>
965 for (
unsigned int i = 0;
i < 256;
i++) {
971 for (
int i = 0;
i < 256;
i++) {
980 std::array<int, 512>&
1021 return a +
t * (
b -
a);
1031 return t *
t *
t * (
t * (
t * 6 - 15) + 10);
1044 const int h =
hash & 15;
1045 const T u =
h < 8 ? x : y;
1046 const T v =
h < 4 ? y :
h == 12 ||
h == 14 ? x : y;
1047 return ((
h & 1) == 0 ?
u : -
u) + ((
h & 2) == 0 ?
v : -
v);
1058 const int X =
static_cast<int>(std::floor(
a_point[0])) & 255;
1059 const int Y =
static_cast<int>(std::floor(
a_point[1])) & 255;
1060 const int Z =
static_cast<int>(std::floor(
a_point[2])) & 255;
1068 const double u =
fade(x);
1069 const double v =
fade(y);
1070 const double w =
fade(
z);
constexpr const T clamp(const T &v, const T &lo, const T &hi)
Clamp function. Returns lo if v < lo and hi if v > hi. Otherwise returns v.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:36
Declaration of a various bounding volumes used for bounding volume hierarchy.
Abstract base class for representing a signed distance function.
Vec2T< T > max(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Maximum function. Returns new vector with component-wise minimums.
T length(const Vec2T< T > &v) noexcept
Length function.
T dot(const Vec2T< T > &u, const Vec2T< T > &v) noexcept
Dot product function.
Signed distance field for an axis-aligned box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:217
const Vec3T< T > & getHighCorner() const noexcept
Get upper-right corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:266
Vec3T< T > & getLowCorner() noexcept
Get lower-left corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:256
BoxSDF()=delete
Disallowed default constructor.
Vec3T< T > & getHighCorner() noexcept
Get upper-right corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:276
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function for sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:286
Vec3T< T > m_loCorner
Low box corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:310
Vec3T< T > m_hiCorner
High box corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:315
const Vec3T< T > & getLowCorner() const noexcept
Get lower-left corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:246
BoxSDF(const Vec3T< T > &a_loCorner, const Vec3T< T > &a_hiCorner) noexcept
Full constructor. Sets the low and high corner.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:229
virtual ~BoxSDF() noexcept
Destructor (does nothing).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:238
Capsulate/pill SDF. Basically a cylinder with spherical endcaps, oriented along the specified axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:640
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Implementation of the signed distance function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:666
Vec3T< T > m_center1
Capsule center1.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:681
CapsuleSDF(const Vec3T< T > &a_tip1, const Vec3T< T > a_tip2, const T &a_radius) noexcept
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:653
T m_radius
Capsule radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:691
Vec3T< T > m_center2
Capsule center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:686
CapsuleSDF()=delete
No weak construction.
Signed distance field for an finite cone. Oriented along +z.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:759
T m_height
Cone height.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:830
virtual ~ConeSDF()
Destructor – does nothing.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:785
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Implementation of the signed distance function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:793
Vec3T< T > m_tip
Tip position.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:820
Vec2T< T > m_c
Sine/cosine of angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:825
ConeSDF(const Vec3T< T > &a_tip, const T &a_height, const T &a_angle) noexcept
Finite cone function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:772
ConeSDF()=delete
Disallowed weak construction.
Signed distance field for a cylinder.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:445
Vec3T< T > m_center2
The other endpoint.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:554
Vec3T< T > m_axis
"Axis", pointing from m_center1 to m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:564
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function for a torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:511
const Vec3T< T > & getCenter1() const noexcept
Get one endpoint.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:481
Vec3T< T > m_center
Halfway between center1 and m_center2.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:559
const Vec3T< T > & getCenter2() const noexcept
Get the other endpoint.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:491
CylinderSDF()=delete
Disallowed weak construction. Use one of the full constructors.
CylinderSDF(const Vec3T< T > &a_center1, const Vec3T< T > &a_center2, const T &a_radius) noexcept
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:458
T m_length
Cylinder length.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:569
virtual ~CylinderSDF() noexcept
Destructor (does nothing).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:473
Vec3T< T > m_center1
One endpoint.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:549
T m_radius
radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:574
const T & getRadius() const noexcept
Get radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:501
Signed distance field for an infinite cone. Oriented along +z.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:699
Vec2T< T > m_c
Sine/cosine of angle.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:751
InfiniteConeSDF()=delete
Disallowed weak construction.
InfiniteConeSDF(const Vec3T< T > &a_tip, const T &a_angle) noexcept
Infinite cone function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:711
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Implementation of the signed distance function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:731
virtual ~InfiniteConeSDF()
Destructor – does nothing.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:723
Vec3T< T > m_tip
Tip position.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:746
Inifinitely long cylinder class. Oriented along the y-axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:582
Vec3T< T > m_center
Cylinder center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:621
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:607
InfiniteCylinderSDF(const Vec3T< T > &a_center, const T &a_radius, const size_t a_axis) noexcept
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:595
T m_radius
Cylinder radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:626
InfiniteCylinderSDF()=delete
No weak construction.
size_t m_axis
Axis.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:631
Ken Perlins gradient noise function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:891
void shuffle(URNG &g) noexcept
Shuffle the permutation with the input RNG.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:962
unsigned int m_noiseOctaves
Number of noise octaves.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1010
T m_noisePersistence
Noise persistence.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1000
virtual T fade(const T t) const noexcept
Ken Perlin's fade function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1029
virtual ~PerlinSDF() noexcept
Destructor (does nothing)
Definition EBGeometry_AnalyticDistanceFunctions.hpp:927
PerlinSDF(const T a_noiseAmplitude, const Vec3T< T > a_noiseFrequency, const T a_noisePersistence, const unsigned int a_noiseOctaves) noexcept
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:900
T noise(const Vec3T< T > &a_point) const noexcept
Octave noise function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1055
T grad(const int hash, const T x, const T y, const T z) const noexcept
Ken Perlins grad function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1042
std::array< T, 512 > m_permutationTable
Permutation table.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1005
virtual T lerp(const T t, const T a, const T b) const noexcept
Ken Perlin's lerp function.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:1019
std::array< int, 512 > & getPermutationTable() noexcept
Get the internal permutation table.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:981
Vec3T< T > m_noiseFrequency
Noise frequency.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:990
T m_noiseAmplitude
Noise amplitude.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:995
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function. Generates a distance on [0,curAmplitude].
Definition EBGeometry_AnalyticDistanceFunctions.hpp:935
Signed distance function for a plane.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:77
Vec3T< T > m_normal
Plane normal vector.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:114
PlaneSDF(const Vec3T< T > &a_point, const Vec3T< T > &a_normal) noexcept
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:89
Vec3T< T > m_point
Point on plane.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:109
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function for sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:100
PlaneSDF()=delete
Disallowed weak construction.
Box of arbitrary dimensions centered at the origin, with rounded corners.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:838
std::shared_ptr< SphereSDF< T > > m_sphere
Sphere at origin with radius a_curvature.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:878
RoundedBoxSDF(const Vec3T< T > &a_dimensions, const T a_curvature) noexcept
Full constructor. User inputs dimensions and corner curvature.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:852
RoundedBoxSDF()=delete
Disallowed default constructor.
virtual ~RoundedBoxSDF() noexcept
Destructor (does nothing).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:862
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function for the rounded box.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:869
Vec3T< T > m_dimensions
Box dimensions.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:883
Abstract representation of a signed distance function.
Definition EBGeometry_SignedDistanceFunction.hpp:32
Signed distance field for sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:122
const T & getRadius() const noexcept
Get radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:176
virtual ~SphereSDF() noexcept=default
Destructor.
SphereSDF(const Vec3T< T > &a_center, const T &a_radius) noexcept
Default constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:134
Vec3T< T > & getCenter() noexcept
Get center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:167
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function for sphere.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:195
SphereSDF(const SphereSDF &a_other) noexcept
Copy constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:143
Vec3T< T > m_center
Sphere center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:204
const Vec3T< T > & getCenter() const noexcept
Get center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:158
T m_radius
Sphere radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:209
SphereSDF()=delete
Disallowed weak construction.
T & getRadius() noexcept
Get radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:185
Signed distance field for a torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:324
Vec3T< T > & getCenter() noexcept
Get torus center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:365
T m_majorRadius
Major torus radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:432
virtual T signedDistance(const Vec3T< T > &a_point) const noexcept override
Signed distance function for a torus.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:414
TorusSDF()=delete
Disallowed weak construction.
const Vec3T< T > & getCenter() const noexcept
Get torus center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:355
const T & getMajorRadius() const noexcept
Get major radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:375
T & getMajorRadius() noexcept
Get major radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:385
TorusSDF(const Vec3T< T > &a_center, const T &a_majorRadius, const T &a_minorRadius) noexcept
Full constructor.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:337
Vec3T< T > m_center
Torus center.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:427
const T & getMinorRadius() const noexcept
Get minor radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:395
virtual ~TorusSDF() noexcept
Destructor (does nothing).
Definition EBGeometry_AnalyticDistanceFunctions.hpp:347
T & getMinorRadius() noexcept
Get minor radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:405
T m_minorRadius
Minor torus radius.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:437
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:218
constexpr T length() const noexcept
Compute vector length.
size_t maxDir(const bool a_doAbs) const noexcept
Return the direction which has the largest component (can be absolute)
static constexpr Vec3T< T > zero() noexcept
Return av vector with x = y = z = 0.