Blue Brain BioExplorer
SDFGeometry.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  * Responsible Author: Jonas Karlsson <jonas.karlsson@epfl.ch>
5  *
6  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 3.0 as published
10  * by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
24 #include "CommonDefines.h"
25 
27 
28 #include <Defines.h>
29 
30 namespace core
31 {
32 enum class SDFType : uint8_t
33 {
34  sdf_sphere = 0,
35  sdf_pill = 1,
36  sdf_cone_pill = 2,
38  sdf_cone = 4,
39  sdf_torus = 5,
40  sdf_cut_sphere = 6,
41  sdf_vesica = 7,
42  sdf_ellipsoid = 8
43 };
44 
46 {
47  uint64_t userData;
48  Vector3f userParams; // Currently used exclusively for displacement
51  float r0 = -1.f;
52  float r1 = -1.f;
53  uint64_t neighboursIndex = 0;
54  uint8_t numNeighbours = 0;
56  __MEMORY_ALIGNMENT__
57 };
58 
59 inline SDFGeometry createSDFSphere(const Vector3f& center, const float radius, const uint64_t data = 0,
60  const Vector3f& userParams = Vector3f(0.f))
61 {
62  SDFGeometry geom;
63  geom.userData = data;
64  geom.userParams = userParams;
65  geom.p0 = center;
66  geom.r0 = radius;
68  return geom;
69 }
70 
71 inline SDFGeometry createSDFCutSphere(const Vector3f& center, const float radius, const float cutRadius,
72  const uint64_t data = 0, const Vector3f& userParams = Vector3f(0.f))
73 {
74  SDFGeometry geom;
75  geom.userData = data;
76  geom.userParams = userParams;
77  geom.p0 = center;
78  geom.r0 = radius;
79  geom.r1 = cutRadius;
81  return geom;
82 }
83 
84 inline SDFGeometry createSDFPill(const Vector3f& p0, const Vector3f& p1, const float radius, const uint64_t data = 0,
85  const Vector3f& userParams = Vector3f(0.f))
86 {
87  SDFGeometry geom;
88  geom.userData = data;
89  geom.userParams = userParams;
90  geom.p0 = p0;
91  geom.p1 = p1;
92  geom.r0 = radius;
93  geom.type = SDFType::sdf_pill;
94  return geom;
95 }
96 
97 inline SDFGeometry createSDFConePill(const Vector3f& p0, const Vector3f& p1, const float r0, const float r1,
98  const uint64_t data = 0, const Vector3f& userParams = Vector3f(0.f))
99 {
100  SDFGeometry geom;
101  geom.userData = data;
102  geom.userParams = userParams;
103  geom.p0 = p0;
104  geom.p1 = p1;
105  geom.r0 = r0;
106  geom.r1 = r1;
107 
108  if (r0 < r1)
109  {
110  std::swap(geom.p0, geom.p1);
111  std::swap(geom.r0, geom.r1);
112  }
113 
115  return geom;
116 }
117 
118 inline SDFGeometry createSDFConePillSigmoid(const Vector3f& p0, const Vector3f& p1, const float r0, const float r1,
119  const uint64_t data = 0, const Vector3f& userParams = Vector3f(0.f))
120 {
121  SDFGeometry geom = createSDFConePill(p0, p1, r0, r1, data, userParams);
123  return geom;
124 }
125 
126 inline SDFGeometry createSDFTorus(const Vector3f& p0, const float r0, const float r1, const uint64_t data = 0,
127  const Vector3f& userParams = Vector3f(0.f))
128 {
129  SDFGeometry geom;
130  geom.userData = data;
131  geom.userParams = userParams;
132  geom.p0 = p0;
133  geom.r0 = r0;
134  geom.r1 = r1;
135  geom.type = SDFType::sdf_torus;
136  return geom;
137 }
138 
139 inline SDFGeometry createSDFVesica(const Vector3f& p0, const Vector3f& p1, const float r0, const uint64_t data = 0,
140  const Vector3f& userParams = Vector3f(0.f))
141 {
142  SDFGeometry geom;
143  geom.userData = data;
144  geom.userParams = userParams;
145  geom.p0 = p0;
146  geom.p1 = p1;
147  geom.r0 = r0;
148  geom.type = SDFType::sdf_vesica;
149  return geom;
150 }
151 
152 inline SDFGeometry createSDFEllipsoid(const Vector3f& p0, const Vector3f& r, const uint64_t data = 0,
153  const Vector3f& userParams = Vector3f(0.f))
154 {
155  SDFGeometry geom;
156  geom.userData = data;
157  geom.userParams = userParams;
158  geom.p0 = p0;
159  geom.p1 = r;
161  return geom;
162 }
163 
164 inline Boxd getSDFBoundingBox(const SDFGeometry& geom)
165 {
166  Boxd bounds;
167  switch (geom.type)
168  {
169  case SDFType::sdf_sphere:
171  {
172  bounds.merge(geom.p0 - Vector3f(geom.r0));
173  bounds.merge(geom.p0 + Vector3f(geom.r0));
174  break;
175  }
176  case SDFType::sdf_pill:
177  case SDFType::sdf_vesica:
178  {
179  bounds.merge(geom.p0 - Vector3f(geom.r0));
180  bounds.merge(geom.p0 + Vector3f(geom.r0));
181  bounds.merge(geom.p1 - Vector3f(geom.r0));
182  bounds.merge(geom.p1 + Vector3f(geom.r0));
183  break;
184  }
185  case SDFType::sdf_cone:
188  {
189  bounds.merge(geom.p0 - Vector3f(geom.r0));
190  bounds.merge(geom.p0 + Vector3f(geom.r0));
191  bounds.merge(geom.p1 - Vector3f(geom.r1));
192  bounds.merge(geom.p1 + Vector3f(geom.r1));
193  break;
194  }
195  case SDFType::sdf_torus:
196  {
197  bounds.merge(geom.p0 - Vector3f(geom.r0 + geom.r1));
198  bounds.merge(geom.p0 + Vector3f(geom.r0 + geom.r1));
199  break;
200  }
202  {
203  bounds.merge(geom.p0 - geom.p1);
204  bounds.merge(geom.p0 + geom.p1);
205  break;
206  }
207  default:
208  throw std::runtime_error("No bounds found for SDF type.");
209  }
210  return bounds;
211 }
212 } // namespace core
void merge(const Box< T > &aabb)
Definition: MathTypes.h:64
SDFGeometry createSDFEllipsoid(const Vector3f &p0, const Vector3f &r, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:152
glm::vec3 Vector3f
Definition: MathTypes.h:137
SDFGeometry createSDFCutSphere(const Vector3f &center, const float radius, const float cutRadius, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:71
SDFGeometry createSDFPill(const Vector3f &p0, const Vector3f &p1, const float radius, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:84
SDFGeometry createSDFSphere(const Vector3f &center, const float radius, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:59
Boxd getSDFBoundingBox(const SDFGeometry &geom)
Definition: SDFGeometry.h:164
SDFGeometry createSDFTorus(const Vector3f &p0, const float r0, const float r1, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:126
SDFGeometry createSDFConePillSigmoid(const Vector3f &p0, const Vector3f &p1, const float r0, const float r1, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:118
SDFGeometry createSDFVesica(const Vector3f &p0, const Vector3f &p1, const float r0, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:139
SDFGeometry createSDFConePill(const Vector3f &p0, const Vector3f &p1, const float r0, const float r1, const uint64_t data=0, const Vector3f &userParams=Vector3f(0.f))
Definition: SDFGeometry.h:97
uint64_t userData
Definition: SDFGeometry.h:47
uint64_t neighboursIndex
Definition: SDFGeometry.h:53
uint8_t numNeighbours
Definition: SDFGeometry.h:54
Vector3f userParams
Definition: SDFGeometry.h:48