Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright Contributors to the OpenVDB Project |
2 |
|
|
// SPDX-License-Identifier: MPL-2.0 |
3 |
|
|
|
4 |
|
|
/// @author Ken Museth |
5 |
|
|
/// |
6 |
|
|
/// @file LevelSetPlatonic.h |
7 |
|
|
/// |
8 |
|
|
/// @brief Generate a narrow-band level sets of the five platonic solids. |
9 |
|
|
/// |
10 |
|
|
/// @note By definition a level set has a fixed narrow band width |
11 |
|
|
/// (the half width is defined by LEVEL_SET_HALF_WIDTH in Types.h), |
12 |
|
|
/// whereas an SDF can have a variable narrow band width. |
13 |
|
|
|
14 |
|
|
#ifndef OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED |
15 |
|
|
#define OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED |
16 |
|
|
|
17 |
|
|
#include <openvdb/Grid.h> |
18 |
|
|
#include <openvdb/Types.h> |
19 |
|
|
#include <openvdb/math/Math.h> |
20 |
|
|
#include <openvdb/math/Transform.h> |
21 |
|
|
#include <openvdb/tools/MeshToVolume.h> |
22 |
|
|
#include <openvdb/util/NullInterrupter.h> |
23 |
|
|
#include <openvdb/openvdb.h> |
24 |
|
|
#include <type_traits> |
25 |
|
|
#include <vector> |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
namespace openvdb { |
29 |
|
|
OPENVDB_USE_VERSION_NAMESPACE |
30 |
|
|
namespace OPENVDB_VERSION_NAME { |
31 |
|
|
namespace tools { |
32 |
|
|
|
33 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
34 |
|
|
/// representation of a platonic solid. |
35 |
|
|
/// |
36 |
|
|
/// @param faceCount number of faces of the platonic solid, i.e. 4, 6, 8, 12 or 20 |
37 |
|
|
/// @param scale scale of the platonic solid in world units |
38 |
|
|
/// @param center center of the platonic solid in world units |
39 |
|
|
/// @param voxelSize voxel size in world units |
40 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
41 |
|
|
/// @param interrupt a pointer adhering to the util::NullInterrupter interface |
42 |
|
|
/// |
43 |
|
|
/// @details Faces: TETRAHEDRON=4, CUBE=6, OCTAHEDRON=8, DODECAHEDRON=12, ICOSAHEDRON=20 |
44 |
|
|
/// |
45 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
46 |
|
|
template<typename GridType, typename InterruptT> |
47 |
|
|
typename GridType::Ptr |
48 |
|
|
createLevelSetPlatonic( |
49 |
|
|
int faceCount, // 4, 6, 8, 12 or 20 |
50 |
|
|
float scale = 1.0f, |
51 |
|
|
const Vec3f& center = Vec3f(0.0f), |
52 |
|
|
float voxelSize = 0.1f, |
53 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH), |
54 |
|
|
InterruptT* interrupt = nullptr); |
55 |
|
|
|
56 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
57 |
|
|
/// representation of a platonic solid. |
58 |
|
|
/// |
59 |
|
|
/// @param faceCount number of faces of the platonic solid, i.e. 4, 6, 8, 12 or 20 |
60 |
|
|
/// @param scale scale of the platonic solid in world units |
61 |
|
|
/// @param center center of the platonic solid in world units |
62 |
|
|
/// @param voxelSize voxel size in world units |
63 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
64 |
|
|
/// |
65 |
|
|
/// @details Faces: TETRAHEDRON=4, CUBE=6, OCTAHEDRON=8, DODECAHEDRON=12, ICOSAHEDRON=20 |
66 |
|
|
/// |
67 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
68 |
|
|
template<typename GridType> |
69 |
|
|
typename GridType::Ptr |
70 |
|
|
createLevelSetPlatonic( |
71 |
|
|
int faceCount,// 4, 6, 8, 12 or 20 |
72 |
|
|
float scale = 1.0f, |
73 |
|
|
const Vec3f& center = Vec3f(0.0f), |
74 |
|
|
float voxelSize = 0.1f, |
75 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH)) |
76 |
|
|
{ |
77 |
|
|
util::NullInterrupter tmp; |
78 |
|
|
return createLevelSetPlatonic<GridType>(faceCount, scale, center, voxelSize, halfWidth, &tmp); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
82 |
|
|
|
83 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
84 |
|
|
/// representation of a tetrahedron. |
85 |
|
|
/// |
86 |
|
|
/// @param scale scale of the platonic solid in world units |
87 |
|
|
/// @param center center of the platonic solid in world units |
88 |
|
|
/// @param voxelSize voxel size in world units |
89 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
90 |
|
|
/// @param interrupt a pointer adhering to the util::NullInterrupter interface |
91 |
|
|
/// |
92 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
93 |
|
|
template<typename GridType, typename InterruptT> |
94 |
|
|
typename GridType::Ptr |
95 |
|
✗ |
createLevelSetTetrahedron( |
96 |
|
|
float scale = 1.0f, |
97 |
|
|
const Vec3f& center = Vec3f(0.0f), |
98 |
|
|
float voxelSize = 0.1f, |
99 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH), |
100 |
|
|
InterruptT* interrupt = nullptr) |
101 |
|
|
{ |
102 |
|
|
return createLevelSetPlatonic<GridType, InterruptT>( |
103 |
|
✗ |
4, scale, center, voxelSize, halfWidth, interrupt); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
107 |
|
|
/// representation of a tetrahedron. |
108 |
|
|
/// |
109 |
|
|
/// @param scale scale of the platonic solid in world units |
110 |
|
|
/// @param center center of the platonic solid in world units |
111 |
|
|
/// @param voxelSize voxel size in world units |
112 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
113 |
|
|
/// |
114 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
115 |
|
|
template<typename GridType> |
116 |
|
|
typename GridType::Ptr |
117 |
|
1 |
createLevelSetTetrahedron( |
118 |
|
|
float scale = 1.0f, |
119 |
|
|
const Vec3f& center = Vec3f(0.0f), |
120 |
|
|
float voxelSize = 0.1f, |
121 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH)) |
122 |
|
|
{ |
123 |
|
1 |
util::NullInterrupter tmp; |
124 |
|
1 |
return createLevelSetPlatonic<GridType>(4, scale, center, voxelSize, halfWidth, &tmp); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
128 |
|
|
|
129 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
130 |
|
|
/// representation of a cube. |
131 |
|
|
/// |
132 |
|
|
/// @param scale scale of the platonic solid in world units |
133 |
|
|
/// @param center center of the platonic solid in world units |
134 |
|
|
/// @param voxelSize voxel size in world units |
135 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
136 |
|
|
/// @param interrupt a pointer adhering to the util::NullInterrupter interface |
137 |
|
|
/// |
138 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
139 |
|
|
template<typename GridType, typename InterruptT> |
140 |
|
|
typename GridType::Ptr |
141 |
|
✗ |
createLevelSetCube( |
142 |
|
|
float scale = 1.0f, |
143 |
|
|
const Vec3f& center = Vec3f(0.0f), |
144 |
|
|
float voxelSize = 0.1f, |
145 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH), |
146 |
|
|
InterruptT* interrupt = nullptr) |
147 |
|
|
{ |
148 |
|
✗ |
return createLevelSetPlatonic<GridType>(6, scale, center, voxelSize, halfWidth, interrupt); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
152 |
|
|
/// representation of a cube. |
153 |
|
|
/// |
154 |
|
|
/// @param scale scale of the platonic solid in world units |
155 |
|
|
/// @param center center of the platonic solid in world units |
156 |
|
|
/// @param voxelSize voxel size in world units |
157 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
158 |
|
|
/// |
159 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
160 |
|
|
template<typename GridType> |
161 |
|
|
typename GridType::Ptr |
162 |
|
9 |
createLevelSetCube( |
163 |
|
|
float scale = 1.0f, |
164 |
|
|
const Vec3f& center = Vec3f(0.0f), |
165 |
|
|
float voxelSize = 0.1f, |
166 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH)) |
167 |
|
|
{ |
168 |
|
9 |
util::NullInterrupter tmp; |
169 |
|
9 |
return createLevelSetPlatonic<GridType>(6, scale, center, voxelSize, halfWidth, &tmp); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
173 |
|
|
|
174 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
175 |
|
|
/// representation of an octahedron. |
176 |
|
|
/// |
177 |
|
|
/// @param scale scale of the platonic solid in world units |
178 |
|
|
/// @param center center of the platonic solid in world units |
179 |
|
|
/// @param voxelSize voxel size in world units |
180 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
181 |
|
|
/// @param interrupt a pointer adhering to the util::NullInterrupter interface |
182 |
|
|
/// |
183 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
184 |
|
|
template<typename GridType, typename InterruptT> |
185 |
|
|
typename GridType::Ptr |
186 |
|
✗ |
createLevelSetOctahedron( |
187 |
|
|
float scale = 1.0f, |
188 |
|
|
const Vec3f& center = Vec3f(0.0f), |
189 |
|
|
float voxelSize = 0.1f, |
190 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH), |
191 |
|
|
InterruptT* interrupt = nullptr) |
192 |
|
|
{ |
193 |
|
✗ |
return createLevelSetPlatonic<GridType>(8, scale, center, voxelSize, halfWidth, interrupt); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
197 |
|
|
/// representation of an octahedron. |
198 |
|
|
/// |
199 |
|
|
/// @param scale scale of the platonic solid in world units |
200 |
|
|
/// @param center center of the platonic solid in world units |
201 |
|
|
/// @param voxelSize voxel size in world units |
202 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
203 |
|
|
/// |
204 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
205 |
|
|
template<typename GridType> |
206 |
|
|
typename GridType::Ptr |
207 |
|
1 |
createLevelSetOctahedron( |
208 |
|
|
float scale = 1.0f, |
209 |
|
|
const Vec3f& center = Vec3f(0.0f), |
210 |
|
|
float voxelSize = 0.1f, |
211 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH)) |
212 |
|
|
{ |
213 |
|
1 |
util::NullInterrupter tmp; |
214 |
|
1 |
return createLevelSetPlatonic<GridType>(8, scale, center, voxelSize, halfWidth, &tmp); |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
218 |
|
|
|
219 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
220 |
|
|
/// representation of a dodecahedron. |
221 |
|
|
/// |
222 |
|
|
/// @param scale scale of the platonic solid in world units |
223 |
|
|
/// @param center center of the platonic solid in world units |
224 |
|
|
/// @param voxelSize voxel size in world units |
225 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
226 |
|
|
/// @param interrupt a pointer adhering to the util::NullInterrupter interface |
227 |
|
|
/// |
228 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
229 |
|
|
template<typename GridType, typename InterruptT> |
230 |
|
|
typename GridType::Ptr |
231 |
|
✗ |
createLevelSetDodecahedron( |
232 |
|
|
float scale = 1.0f, |
233 |
|
|
const Vec3f& center = Vec3f(0.0f), |
234 |
|
|
float voxelSize = 0.1f, |
235 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH), |
236 |
|
|
InterruptT* interrupt = nullptr) |
237 |
|
|
{ |
238 |
|
✗ |
return createLevelSetPlatonic<GridType>(12, scale, center, voxelSize, halfWidth, interrupt); |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
242 |
|
|
/// representation of a dodecahedron. |
243 |
|
|
/// |
244 |
|
|
/// @param scale scale of the platonic solid in world units |
245 |
|
|
/// @param center center of the platonic solid in world units |
246 |
|
|
/// @param voxelSize voxel size in world units |
247 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
248 |
|
|
/// |
249 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
250 |
|
|
template<typename GridType> |
251 |
|
|
typename GridType::Ptr |
252 |
|
2 |
createLevelSetDodecahedron( |
253 |
|
|
float scale = 1.0f, |
254 |
|
|
const Vec3f& center = Vec3f(0.0f), |
255 |
|
|
float voxelSize = 0.1f, |
256 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH)) |
257 |
|
|
{ |
258 |
|
2 |
util::NullInterrupter tmp; |
259 |
|
2 |
return createLevelSetPlatonic<GridType>(12, scale, center, voxelSize, halfWidth, &tmp); |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
263 |
|
|
|
264 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
265 |
|
|
/// representation of an icosahedron. |
266 |
|
|
/// |
267 |
|
|
/// @param scale scale of the platonic solid in world units |
268 |
|
|
/// @param center center of the platonic solid in world units |
269 |
|
|
/// @param voxelSize voxel size in world units |
270 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
271 |
|
|
/// @param interrupt a pointer adhering to the util::NullInterrupter interface |
272 |
|
|
/// |
273 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
274 |
|
|
template<typename GridType, typename InterruptT> |
275 |
|
|
typename GridType::Ptr |
276 |
|
✗ |
createLevelSetIcosahedron( |
277 |
|
|
float scale = 1.0f, |
278 |
|
|
const Vec3f& center = Vec3f(0.0f), |
279 |
|
|
float voxelSize = 0.1f, |
280 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH), |
281 |
|
|
InterruptT* interrupt = nullptr) |
282 |
|
|
{ |
283 |
|
✗ |
return createLevelSetPlatonic<GridType>(20, scale, center, voxelSize, halfWidth, interrupt); |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
/// @brief Return a grid of type @c GridType containing a narrow-band level set |
287 |
|
|
/// representation of an icosahedron. |
288 |
|
|
/// |
289 |
|
|
/// @param scale scale of the platonic solid in world units |
290 |
|
|
/// @param center center of the platonic solid in world units |
291 |
|
|
/// @param voxelSize voxel size in world units |
292 |
|
|
/// @param halfWidth half the width of the narrow band, in voxel units |
293 |
|
|
/// |
294 |
|
|
/// @note @c GridType::ValueType must be a floating-point scalar. |
295 |
|
|
template<typename GridType> |
296 |
|
|
typename GridType::Ptr |
297 |
|
1 |
createLevelSetIcosahedron( |
298 |
|
|
float scale = 1.0f, |
299 |
|
|
const Vec3f& center = Vec3f(0.0f), |
300 |
|
|
float voxelSize = 0.1f, |
301 |
|
|
float halfWidth = float(LEVEL_SET_HALF_WIDTH)) |
302 |
|
|
{ |
303 |
|
1 |
util::NullInterrupter tmp; |
304 |
|
1 |
return createLevelSetPlatonic<GridType>(20, scale, center, voxelSize, halfWidth, &tmp); |
305 |
|
|
} |
306 |
|
|
|
307 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
308 |
|
|
|
309 |
|
|
template<typename GridType, typename InterruptT> |
310 |
|
|
typename GridType::Ptr |
311 |
|
14 |
createLevelSetPlatonic(int faceCount,float scale, const Vec3f& center, |
312 |
|
|
float voxelSize, float halfWidth, InterruptT *interrupt) |
313 |
|
|
{ |
314 |
|
|
// GridType::ValueType is required to be a floating-point scalar. |
315 |
|
|
static_assert(std::is_floating_point<typename GridType::ValueType>::value, |
316 |
|
|
"level set grids must have scalar, floating-point value types"); |
317 |
|
|
|
318 |
|
14 |
const math::Transform::Ptr xform = math::Transform::createLinearTransform( voxelSize ); |
319 |
|
|
|
320 |
|
|
std::vector<Vec3f> vtx; |
321 |
|
|
std::vector<Vec3I> tri; |
322 |
|
|
std::vector<Vec4I> qua; |
323 |
|
|
|
324 |
|
14 |
if (faceCount == 4) {// Tetrahedron |
325 |
|
|
|
326 |
|
1 |
vtx.push_back( Vec3f( 0.0f, 1.0f, 0.0f) ); |
327 |
|
1 |
vtx.push_back( Vec3f(-0.942810297f, -0.333329707f, 0.0f) ); |
328 |
|
1 |
vtx.push_back( Vec3f( 0.471405149f, -0.333329707f, 0.816497624f) ); |
329 |
|
1 |
vtx.push_back( Vec3f( 0.471405149f, -0.333329707f, -0.816497624f) ); |
330 |
|
|
|
331 |
|
1 |
tri.push_back( Vec3I(0, 2, 3) ); |
332 |
|
1 |
tri.push_back( Vec3I(0, 3, 1) ); |
333 |
|
1 |
tri.push_back( Vec3I(0, 1, 2) ); |
334 |
|
1 |
tri.push_back( Vec3I(1, 3, 2) ); |
335 |
|
|
|
336 |
|
13 |
} else if (faceCount == 6) {// Cube |
337 |
|
|
|
338 |
|
9 |
vtx.push_back( Vec3f(-0.5f, -0.5f, -0.5f) ); |
339 |
|
9 |
vtx.push_back( Vec3f( 0.5f, -0.5f, -0.5f) ); |
340 |
|
9 |
vtx.push_back( Vec3f( 0.5f, -0.5f, 0.5f) ); |
341 |
|
9 |
vtx.push_back( Vec3f(-0.5f, -0.5f, 0.5f) ); |
342 |
|
9 |
vtx.push_back( Vec3f(-0.5f, 0.5f, -0.5f) ); |
343 |
|
9 |
vtx.push_back( Vec3f( 0.5f, 0.5f, -0.5f) ); |
344 |
|
9 |
vtx.push_back( Vec3f( 0.5f, 0.5f, 0.5f) ); |
345 |
|
9 |
vtx.push_back( Vec3f(-0.5f, 0.5f, 0.5f) ); |
346 |
|
|
|
347 |
|
9 |
qua.push_back( Vec4I(1, 0, 4, 5) ); |
348 |
|
9 |
qua.push_back( Vec4I(2, 1, 5, 6) ); |
349 |
|
9 |
qua.push_back( Vec4I(3, 2, 6, 7) ); |
350 |
|
9 |
qua.push_back( Vec4I(0, 3, 7, 4) ); |
351 |
|
9 |
qua.push_back( Vec4I(2, 3, 0, 1) ); |
352 |
|
9 |
qua.push_back( Vec4I(5, 4, 7, 6) ); |
353 |
|
|
|
354 |
|
4 |
} else if (faceCount == 8) {// Octahedron |
355 |
|
|
|
356 |
|
1 |
vtx.push_back( Vec3f( 0.0f, 0.0f, -1.0f) ); |
357 |
|
1 |
vtx.push_back( Vec3f( 1.0f, 0.0f, 0.0f) ); |
358 |
|
1 |
vtx.push_back( Vec3f( 0.0f, 0.0f, 1.0f) ); |
359 |
|
1 |
vtx.push_back( Vec3f(-1.0f, 0.0f, 0.0f) ); |
360 |
|
1 |
vtx.push_back( Vec3f( 0.0f,-1.0f, 0.0f) ); |
361 |
|
1 |
vtx.push_back( Vec3f( 0.0f, 1.0f, 0.0f) ); |
362 |
|
|
|
363 |
|
1 |
tri.push_back( Vec3I(0, 4, 3) ); |
364 |
|
1 |
tri.push_back( Vec3I(0, 1, 4) ); |
365 |
|
1 |
tri.push_back( Vec3I(1, 2, 4) ); |
366 |
|
1 |
tri.push_back( Vec3I(2, 3, 4) ); |
367 |
|
1 |
tri.push_back( Vec3I(0, 3, 5) ); |
368 |
|
1 |
tri.push_back( Vec3I(0, 5, 1) ); |
369 |
|
1 |
tri.push_back( Vec3I(1, 5, 2) ); |
370 |
|
1 |
tri.push_back( Vec3I(2, 5, 3) ); |
371 |
|
|
|
372 |
|
3 |
} else if (faceCount == 12) {// Dodecahedron |
373 |
|
|
|
374 |
|
2 |
vtx.push_back( Vec3f( 0.354437858f, 0.487842113f, -0.789344311f) ); |
375 |
|
2 |
vtx.push_back( Vec3f( 0.573492587f, -0.186338872f, -0.78934437f) ); |
376 |
|
2 |
vtx.push_back( Vec3f( 0.0f, -0.603005826f, -0.78934443f) ); |
377 |
|
2 |
vtx.push_back( Vec3f(-0.573492587f, -0.186338872f, -0.78934437f) ); |
378 |
|
2 |
vtx.push_back( Vec3f(-0.354437858f, 0.487842113f, -0.789344311f) ); |
379 |
|
2 |
vtx.push_back( Vec3f(-0.573492587f, 0.789345026f, -0.186338797f) ); |
380 |
|
2 |
vtx.push_back( Vec3f(-0.927930415f, -0.301502913f, -0.186338872f) ); |
381 |
|
2 |
vtx.push_back( Vec3f( 0.0f, -0.975683928f, -0.186338902f) ); |
382 |
|
2 |
vtx.push_back( Vec3f( 0.927930415f, -0.301502913f, -0.186338872f) ); |
383 |
|
2 |
vtx.push_back( Vec3f( 0.573492587f, 0.789345026f, -0.186338797f) ); |
384 |
|
2 |
vtx.push_back( Vec3f( 0.0f, 0.975683868f, 0.186338902f) ); |
385 |
|
2 |
vtx.push_back( Vec3f(-0.927930415f, 0.301502913f, 0.186338872f) ); |
386 |
|
2 |
vtx.push_back( Vec3f(-0.573492587f, -0.789345026f, 0.186338797f) ); |
387 |
|
2 |
vtx.push_back( Vec3f( 0.573492587f, -0.789345026f, 0.186338797f) ); |
388 |
|
2 |
vtx.push_back( Vec3f( 0.927930415f, 0.301502913f, 0.186338872f) ); |
389 |
|
2 |
vtx.push_back( Vec3f( 0.0f, 0.603005826f, 0.78934443f) ); |
390 |
|
2 |
vtx.push_back( Vec3f( 0.573492587f, 0.186338872f, 0.78934437f) ); |
391 |
|
2 |
vtx.push_back( Vec3f( 0.354437858f, -0.487842113f, 0.789344311f) ); |
392 |
|
2 |
vtx.push_back( Vec3f(-0.354437858f, -0.487842113f, 0.789344311f) ); |
393 |
|
2 |
vtx.push_back( Vec3f(-0.573492587f, 0.186338872f, 0.78934437f) ); |
394 |
|
|
|
395 |
|
2 |
qua.push_back( Vec4I(0, 1, 2, 3) ); |
396 |
|
2 |
tri.push_back( Vec3I(0, 3, 4) ); |
397 |
|
2 |
qua.push_back( Vec4I(0, 4, 5, 10) ); |
398 |
|
2 |
tri.push_back( Vec3I(0, 10, 9) ); |
399 |
|
2 |
qua.push_back( Vec4I(0, 9, 14, 8) ); |
400 |
|
2 |
tri.push_back( Vec3I(0, 8, 1) ); |
401 |
|
2 |
qua.push_back( Vec4I(1, 8, 13, 7) ); |
402 |
|
2 |
tri.push_back( Vec3I(1, 7, 2) ); |
403 |
|
2 |
qua.push_back( Vec4I(2, 7, 12, 6) ); |
404 |
|
2 |
tri.push_back( Vec3I(2, 6, 3) ); |
405 |
|
2 |
qua.push_back( Vec4I(3, 6, 11, 5) ); |
406 |
|
2 |
tri.push_back( Vec3I(3, 5, 4) ); |
407 |
|
2 |
qua.push_back( Vec4I(5, 11, 19, 15) ); |
408 |
|
2 |
tri.push_back( Vec3I(5, 15, 10) ); |
409 |
|
2 |
qua.push_back( Vec4I(6, 12, 18, 19) ); |
410 |
|
2 |
tri.push_back( Vec3I(6, 19, 11) ); |
411 |
|
2 |
qua.push_back( Vec4I(7, 13, 17, 18) ); |
412 |
|
2 |
tri.push_back( Vec3I(7, 18, 12) ); |
413 |
|
2 |
qua.push_back( Vec4I(8, 14, 16, 17) ); |
414 |
|
2 |
tri.push_back( Vec3I(8, 17, 13) ); |
415 |
|
2 |
qua.push_back( Vec4I(9, 10, 15, 16) ); |
416 |
|
2 |
tri.push_back( Vec3I(9, 16, 14) ); |
417 |
|
2 |
qua.push_back( Vec4I(15, 19, 18, 17) ); |
418 |
|
2 |
tri.push_back( Vec3I(15, 17, 16) ); |
419 |
|
|
|
420 |
|
1 |
} else if (faceCount == 20) {// Icosahedron |
421 |
|
|
|
422 |
|
1 |
vtx.push_back( Vec3f(0.0f, 0.0f, -1.0f) ); |
423 |
|
1 |
vtx.push_back( Vec3f(0.0f, 0.894427359f, -0.447213143f) ); |
424 |
|
1 |
vtx.push_back( Vec3f(0.850650847f, 0.276393682f, -0.447213203f) ); |
425 |
|
1 |
vtx.push_back( Vec3f(0.525731206f, -0.723606944f, -0.447213262f) ); |
426 |
|
1 |
vtx.push_back( Vec3f(-0.525731206f, -0.723606944f, -0.447213262f) ); |
427 |
|
1 |
vtx.push_back( Vec3f(-0.850650847f, 0.276393682f, -0.447213203f) ); |
428 |
|
1 |
vtx.push_back( Vec3f(-0.525731206f, 0.723606944f, 0.447213262f) ); |
429 |
|
1 |
vtx.push_back( Vec3f(-0.850650847f, -0.276393682f, 0.447213203f) ); |
430 |
|
1 |
vtx.push_back( Vec3f(0.0f, -0.894427359f, 0.447213143f) ); |
431 |
|
1 |
vtx.push_back( Vec3f(0.850650847f, -0.276393682f, 0.447213203f) ); |
432 |
|
1 |
vtx.push_back( Vec3f(0.525731206f, 0.723606944f, 0.447213262f) ); |
433 |
|
1 |
vtx.push_back( Vec3f(0.0f, 0.0f, 1.0f) ); |
434 |
|
|
|
435 |
|
1 |
tri.push_back( Vec3I( 2, 0, 1) ); |
436 |
|
1 |
tri.push_back( Vec3I( 3, 0, 2) ); |
437 |
|
1 |
tri.push_back( Vec3I( 4, 0, 3) ); |
438 |
|
1 |
tri.push_back( Vec3I( 5, 0, 4) ); |
439 |
|
1 |
tri.push_back( Vec3I( 1, 0, 5) ); |
440 |
|
1 |
tri.push_back( Vec3I( 6, 1, 5) ); |
441 |
|
1 |
tri.push_back( Vec3I( 7, 5, 4) ); |
442 |
|
1 |
tri.push_back( Vec3I( 8, 4, 3) ); |
443 |
|
1 |
tri.push_back( Vec3I( 9, 3, 2) ); |
444 |
|
1 |
tri.push_back( Vec3I(10, 2, 1) ); |
445 |
|
1 |
tri.push_back( Vec3I(10, 1, 6) ); |
446 |
|
1 |
tri.push_back( Vec3I( 6, 5, 7) ); |
447 |
|
1 |
tri.push_back( Vec3I( 7, 4, 8) ); |
448 |
|
1 |
tri.push_back( Vec3I( 8, 3, 9) ); |
449 |
|
1 |
tri.push_back( Vec3I( 9, 2, 10) ); |
450 |
|
1 |
tri.push_back( Vec3I( 6, 11, 10) ); |
451 |
|
1 |
tri.push_back( Vec3I(10, 11, 9) ); |
452 |
|
1 |
tri.push_back( Vec3I( 9, 11, 8) ); |
453 |
|
1 |
tri.push_back( Vec3I( 8, 11, 7) ); |
454 |
|
1 |
tri.push_back( Vec3I( 7, 11, 6) ); |
455 |
|
|
|
456 |
|
|
} else { |
457 |
|
✗ |
OPENVDB_THROW(RuntimeError, "Invalid face count"); |
458 |
|
|
} |
459 |
|
|
|
460 |
|
|
// Apply scale and translation to all the vertices |
461 |
|
148 |
for ( size_t i = 0; i<vtx.size(); ++i ) vtx[i] = scale * vtx[i] + center; |
462 |
|
|
|
463 |
|
14 |
typename GridType::Ptr grid; |
464 |
|
|
|
465 |
|
14 |
if (interrupt == nullptr) { |
466 |
|
✗ |
util::NullInterrupter tmp; |
467 |
|
✗ |
grid = meshToLevelSet<GridType>(tmp, *xform, vtx, tri, qua, halfWidth); |
468 |
|
|
} else { |
469 |
|
28 |
grid = meshToLevelSet<GridType>(*interrupt, *xform, vtx, tri, qua, halfWidth); |
470 |
|
|
} |
471 |
|
|
|
472 |
|
14 |
return grid; |
473 |
|
|
} |
474 |
|
|
|
475 |
|
|
|
476 |
|
|
//////////////////////////////////////// |
477 |
|
|
|
478 |
|
|
|
479 |
|
|
// Explicit Template Instantiation |
480 |
|
|
|
481 |
|
|
#ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION |
482 |
|
|
|
483 |
|
|
#ifdef OPENVDB_INSTANTIATE_LEVELSETPLATONIC |
484 |
|
|
#include <openvdb/util/ExplicitInstantiation.h> |
485 |
|
|
#endif |
486 |
|
|
|
487 |
|
|
#define _FUNCTION(TreeT) \ |
488 |
|
|
Grid<TreeT>::Ptr createLevelSetPlatonic<Grid<TreeT>>(int, float, const Vec3f&, float, float, \ |
489 |
|
|
util::NullInterrupter*) |
490 |
|
|
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION) |
491 |
|
|
#undef _FUNCTION |
492 |
|
|
|
493 |
|
|
#define _FUNCTION(TreeT) \ |
494 |
|
|
Grid<TreeT>::Ptr createLevelSetTetrahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \ |
495 |
|
|
util::NullInterrupter*) |
496 |
|
|
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION) |
497 |
|
|
#undef _FUNCTION |
498 |
|
|
|
499 |
|
|
#define _FUNCTION(TreeT) \ |
500 |
|
|
Grid<TreeT>::Ptr createLevelSetCube<Grid<TreeT>>(float, const Vec3f&, float, float, \ |
501 |
|
|
util::NullInterrupter*) |
502 |
|
|
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION) |
503 |
|
|
#undef _FUNCTION |
504 |
|
|
|
505 |
|
|
#define _FUNCTION(TreeT) \ |
506 |
|
|
Grid<TreeT>::Ptr createLevelSetOctahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \ |
507 |
|
|
util::NullInterrupter*) |
508 |
|
|
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION) |
509 |
|
|
#undef _FUNCTION |
510 |
|
|
|
511 |
|
|
#define _FUNCTION(TreeT) \ |
512 |
|
|
Grid<TreeT>::Ptr createLevelSetDodecahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \ |
513 |
|
|
util::NullInterrupter*) |
514 |
|
|
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION) |
515 |
|
|
#undef _FUNCTION |
516 |
|
|
|
517 |
|
|
#define _FUNCTION(TreeT) \ |
518 |
|
|
Grid<TreeT>::Ptr createLevelSetIcosahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \ |
519 |
|
|
util::NullInterrupter*) |
520 |
|
|
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION) |
521 |
|
|
#undef _FUNCTION |
522 |
|
|
|
523 |
|
|
#endif // OPENVDB_USE_EXPLICIT_INSTANTIATION |
524 |
|
|
|
525 |
|
|
|
526 |
|
|
} // namespace tools |
527 |
|
|
} // namespace OPENVDB_VERSION_NAME |
528 |
|
|
} // namespace openvdb |
529 |
|
|
|
530 |
|
|
#endif // OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED |
531 |
|
|
|