14 #ifndef OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED
15 #define OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED
26 #include <type_traits>
48 template<
typename Gr
idType,
typename InterruptT>
49 typename GridType::Ptr
54 float voxelSize = 0.1
f,
55 float halfWidth =
float(LEVEL_SET_HALF_WIDTH),
56 InterruptT* interrupt =
nullptr);
70 template<
typename Gr
idType>
71 typename GridType::Ptr
76 float voxelSize = 0.1
f,
77 float halfWidth =
float(LEVEL_SET_HALF_WIDTH))
80 return createLevelSetPlatonic<GridType>(faceCount,
scale,
center, voxelSize, halfWidth, &tmp);
95 template<
typename Gr
idType,
typename InterruptT>
96 typename GridType::Ptr
100 float voxelSize = 0.1
f,
101 float halfWidth =
float(LEVEL_SET_HALF_WIDTH),
102 InterruptT* interrupt =
nullptr)
104 return createLevelSetPlatonic<GridType, InterruptT>(
105 4,
scale,
center, voxelSize, halfWidth, interrupt);
117 template<
typename Gr
idType>
118 typename GridType::Ptr
122 float voxelSize = 0.1
f,
123 float halfWidth =
float(LEVEL_SET_HALF_WIDTH))
126 return createLevelSetPlatonic<GridType>(4,
scale,
center, voxelSize, halfWidth, &tmp);
141 template<
typename Gr
idType,
typename InterruptT>
142 typename GridType::Ptr
146 float voxelSize = 0.1
f,
147 float halfWidth =
float(LEVEL_SET_HALF_WIDTH),
148 InterruptT* interrupt =
nullptr)
150 return createLevelSetPlatonic<GridType>(6,
scale,
center, voxelSize, halfWidth, interrupt);
162 template<
typename Gr
idType>
163 typename GridType::Ptr
167 float voxelSize = 0.1
f,
168 float halfWidth =
float(LEVEL_SET_HALF_WIDTH))
171 return createLevelSetPlatonic<GridType>(6,
scale,
center, voxelSize, halfWidth, &tmp);
186 template<
typename Gr
idType,
typename InterruptT>
187 typename GridType::Ptr
191 float voxelSize = 0.1
f,
192 float halfWidth =
float(LEVEL_SET_HALF_WIDTH),
193 InterruptT* interrupt =
nullptr)
195 return createLevelSetPlatonic<GridType>(8,
scale,
center, voxelSize, halfWidth, interrupt);
207 template<
typename Gr
idType>
208 typename GridType::Ptr
212 float voxelSize = 0.1
f,
213 float halfWidth =
float(LEVEL_SET_HALF_WIDTH))
216 return createLevelSetPlatonic<GridType>(8,
scale,
center, voxelSize, halfWidth, &tmp);
231 template<
typename Gr
idType,
typename InterruptT>
232 typename GridType::Ptr
236 float voxelSize = 0.1
f,
237 float halfWidth =
float(LEVEL_SET_HALF_WIDTH),
238 InterruptT* interrupt =
nullptr)
240 return createLevelSetPlatonic<GridType>(12,
scale,
center, voxelSize, halfWidth, interrupt);
252 template<
typename Gr
idType>
253 typename GridType::Ptr
257 float voxelSize = 0.1
f,
258 float halfWidth =
float(LEVEL_SET_HALF_WIDTH))
261 return createLevelSetPlatonic<GridType>(12,
scale,
center, voxelSize, halfWidth, &tmp);
276 template<
typename Gr
idType,
typename InterruptT>
277 typename GridType::Ptr
281 float voxelSize = 0.1
f,
282 float halfWidth =
float(LEVEL_SET_HALF_WIDTH),
283 InterruptT* interrupt =
nullptr)
285 return createLevelSetPlatonic<GridType>(20,
scale,
center, voxelSize, halfWidth, interrupt);
297 template<
typename Gr
idType>
298 typename GridType::Ptr
302 float voxelSize = 0.1
f,
303 float halfWidth =
float(LEVEL_SET_HALF_WIDTH))
306 return createLevelSetPlatonic<GridType>(20,
scale,
center, voxelSize, halfWidth, &tmp);
311 template<
typename Gr
idType,
typename InterruptT>
312 typename GridType::Ptr
314 float voxelSize,
float halfWidth, InterruptT *interrupt)
318 "level set grids must have scalar, floating-point value types");
322 std::vector<Vec3f> vtx;
323 std::vector<Vec3I> tri;
324 std::vector<Vec4I> qua;
326 if (faceCount == 4) {
328 vtx.push_back(
Vec3f( 0.0
f, 1.0
f, 0.0
f) );
329 vtx.push_back(
Vec3f(-0.942810297
f, -0.333329707
f, 0.0
f) );
330 vtx.push_back(
Vec3f( 0.471405149
f, -0.333329707
f, 0.816497624
f) );
331 vtx.push_back(
Vec3f( 0.471405149
f, -0.333329707
f, -0.816497624
f) );
333 tri.push_back(
Vec3I(0, 2, 3) );
334 tri.push_back(
Vec3I(0, 3, 1) );
335 tri.push_back(
Vec3I(0, 1, 2) );
336 tri.push_back(
Vec3I(1, 3, 2) );
338 }
else if (faceCount == 6) {
340 vtx.push_back(
Vec3f(-0.5
f, -0.5
f, -0.5
f) );
341 vtx.push_back(
Vec3f( 0.5
f, -0.5
f, -0.5
f) );
342 vtx.push_back(
Vec3f( 0.5
f, -0.5
f, 0.5
f) );
343 vtx.push_back(
Vec3f(-0.5
f, -0.5
f, 0.5
f) );
344 vtx.push_back(
Vec3f(-0.5
f, 0.5
f, -0.5
f) );
345 vtx.push_back(
Vec3f( 0.5
f, 0.5
f, -0.5
f) );
346 vtx.push_back(
Vec3f( 0.5
f, 0.5
f, 0.5
f) );
347 vtx.push_back(
Vec3f(-0.5
f, 0.5
f, 0.5
f) );
349 qua.push_back(
Vec4I(1, 0, 4, 5) );
350 qua.push_back(
Vec4I(2, 1, 5, 6) );
351 qua.push_back(
Vec4I(3, 2, 6, 7) );
352 qua.push_back(
Vec4I(0, 3, 7, 4) );
353 qua.push_back(
Vec4I(2, 3, 0, 1) );
354 qua.push_back(
Vec4I(5, 4, 7, 6) );
356 }
else if (faceCount == 8) {
358 vtx.push_back(
Vec3f( 0.0
f, 0.0
f, -1.0
f) );
359 vtx.push_back(
Vec3f( 1.0
f, 0.0
f, 0.0
f) );
360 vtx.push_back(
Vec3f( 0.0
f, 0.0
f, 1.0
f) );
361 vtx.push_back(
Vec3f(-1.0
f, 0.0
f, 0.0
f) );
362 vtx.push_back(
Vec3f( 0.0
f,-1.0
f, 0.0
f) );
363 vtx.push_back(
Vec3f( 0.0
f, 1.0
f, 0.0
f) );
365 tri.push_back(
Vec3I(0, 4, 3) );
366 tri.push_back(
Vec3I(0, 1, 4) );
367 tri.push_back(
Vec3I(1, 2, 4) );
368 tri.push_back(
Vec3I(2, 3, 4) );
369 tri.push_back(
Vec3I(0, 3, 5) );
370 tri.push_back(
Vec3I(0, 5, 1) );
371 tri.push_back(
Vec3I(1, 5, 2) );
372 tri.push_back(
Vec3I(2, 5, 3) );
374 }
else if (faceCount == 12) {
376 vtx.push_back(
Vec3f( 0.354437858
f, 0.487842113
f, -0.789344311
f) );
377 vtx.push_back(
Vec3f( 0.573492587
f, -0.186338872
f, -0.78934437
f) );
378 vtx.push_back(
Vec3f( 0.0
f, -0.603005826
f, -0.78934443
f) );
379 vtx.push_back(
Vec3f(-0.573492587
f, -0.186338872
f, -0.78934437
f) );
380 vtx.push_back(
Vec3f(-0.354437858
f, 0.487842113
f, -0.789344311
f) );
381 vtx.push_back(
Vec3f(-0.573492587
f, 0.789345026
f, -0.186338797
f) );
382 vtx.push_back(
Vec3f(-0.927930415
f, -0.301502913
f, -0.186338872
f) );
383 vtx.push_back(
Vec3f( 0.0
f, -0.975683928
f, -0.186338902
f) );
384 vtx.push_back(
Vec3f( 0.927930415
f, -0.301502913
f, -0.186338872
f) );
385 vtx.push_back(
Vec3f( 0.573492587
f, 0.789345026
f, -0.186338797
f) );
386 vtx.push_back(
Vec3f( 0.0
f, 0.975683868
f, 0.186338902
f) );
387 vtx.push_back(
Vec3f(-0.927930415
f, 0.301502913
f, 0.186338872
f) );
388 vtx.push_back(
Vec3f(-0.573492587
f, -0.789345026
f, 0.186338797
f) );
389 vtx.push_back(
Vec3f( 0.573492587
f, -0.789345026
f, 0.186338797
f) );
390 vtx.push_back(
Vec3f( 0.927930415
f, 0.301502913
f, 0.186338872
f) );
391 vtx.push_back(
Vec3f( 0.0
f, 0.603005826
f, 0.78934443
f) );
392 vtx.push_back(
Vec3f( 0.573492587
f, 0.186338872
f, 0.78934437
f) );
393 vtx.push_back(
Vec3f( 0.354437858
f, -0.487842113
f, 0.789344311
f) );
394 vtx.push_back(
Vec3f(-0.354437858
f, -0.487842113
f, 0.789344311
f) );
395 vtx.push_back(
Vec3f(-0.573492587
f, 0.186338872
f, 0.78934437
f) );
397 qua.push_back(
Vec4I(0, 1, 2, 3) );
398 tri.push_back(
Vec3I(0, 3, 4) );
399 qua.push_back(
Vec4I(0, 4, 5, 10) );
400 tri.push_back(
Vec3I(0, 10, 9) );
401 qua.push_back(
Vec4I(0, 9, 14, 8) );
402 tri.push_back(
Vec3I(0, 8, 1) );
403 qua.push_back(
Vec4I(1, 8, 13, 7) );
404 tri.push_back(
Vec3I(1, 7, 2) );
405 qua.push_back(
Vec4I(2, 7, 12, 6) );
406 tri.push_back(
Vec3I(2, 6, 3) );
407 qua.push_back(
Vec4I(3, 6, 11, 5) );
408 tri.push_back(
Vec3I(3, 5, 4) );
409 qua.push_back(
Vec4I(5, 11, 19, 15) );
410 tri.push_back(
Vec3I(5, 15, 10) );
411 qua.push_back(
Vec4I(6, 12, 18, 19) );
412 tri.push_back(
Vec3I(6, 19, 11) );
413 qua.push_back(
Vec4I(7, 13, 17, 18) );
414 tri.push_back(
Vec3I(7, 18, 12) );
415 qua.push_back(
Vec4I(8, 14, 16, 17) );
416 tri.push_back(
Vec3I(8, 17, 13) );
417 qua.push_back(
Vec4I(9, 10, 15, 16) );
418 tri.push_back(
Vec3I(9, 16, 14) );
419 qua.push_back(
Vec4I(15, 19, 18, 17) );
420 tri.push_back(
Vec3I(15, 17, 16) );
422 }
else if (faceCount == 20) {
424 vtx.push_back(
Vec3f(0.0
f, 0.0
f, -1.0
f) );
425 vtx.push_back(
Vec3f(0.0
f, 0.894427359
f, -0.447213143
f) );
426 vtx.push_back(
Vec3f(0.850650847
f, 0.276393682
f, -0.447213203
f) );
427 vtx.push_back(
Vec3f(0.525731206
f, -0.723606944
f, -0.447213262
f) );
428 vtx.push_back(
Vec3f(-0.525731206
f, -0.723606944
f, -0.447213262
f) );
429 vtx.push_back(
Vec3f(-0.850650847
f, 0.276393682
f, -0.447213203
f) );
430 vtx.push_back(
Vec3f(-0.525731206
f, 0.723606944
f, 0.447213262
f) );
431 vtx.push_back(
Vec3f(-0.850650847
f, -0.276393682
f, 0.447213203
f) );
432 vtx.push_back(
Vec3f(0.0
f, -0.894427359
f, 0.447213143
f) );
433 vtx.push_back(
Vec3f(0.850650847
f, -0.276393682
f, 0.447213203
f) );
434 vtx.push_back(
Vec3f(0.525731206
f, 0.723606944
f, 0.447213262
f) );
435 vtx.push_back(
Vec3f(0.0
f, 0.0
f, 1.0
f) );
437 tri.push_back(
Vec3I( 2, 0, 1) );
438 tri.push_back(
Vec3I( 3, 0, 2) );
439 tri.push_back(
Vec3I( 4, 0, 3) );
440 tri.push_back(
Vec3I( 5, 0, 4) );
441 tri.push_back(
Vec3I( 1, 0, 5) );
442 tri.push_back(
Vec3I( 6, 1, 5) );
443 tri.push_back(
Vec3I( 7, 5, 4) );
444 tri.push_back(
Vec3I( 8, 4, 3) );
445 tri.push_back(
Vec3I( 9, 3, 2) );
446 tri.push_back(
Vec3I(10, 2, 1) );
447 tri.push_back(
Vec3I(10, 1, 6) );
448 tri.push_back(
Vec3I( 6, 5, 7) );
449 tri.push_back(
Vec3I( 7, 4, 8) );
450 tri.push_back(
Vec3I( 8, 3, 9) );
451 tri.push_back(
Vec3I( 9, 2, 10) );
452 tri.push_back(
Vec3I( 6, 11, 10) );
453 tri.push_back(
Vec3I(10, 11, 9) );
454 tri.push_back(
Vec3I( 9, 11, 8) );
455 tri.push_back(
Vec3I( 8, 11, 7) );
456 tri.push_back(
Vec3I( 7, 11, 6) );
463 for (
size_t i = 0; i<vtx.size(); ++i ) vtx[i] = scale * vtx[i] + center;
465 typename GridType::Ptr grid;
467 if (interrupt ==
nullptr) {
469 grid = meshToLevelSet<GridType>(tmp, *xform, vtx, tri, qua, halfWidth);
471 grid = meshToLevelSet<GridType>(*interrupt, *xform, vtx, tri, qua, halfWidth);
483 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
485 #ifdef OPENVDB_INSTANTIATE_LEVELSETPLATONIC
489 #define _FUNCTION(TreeT) \
490 Grid<TreeT>::Ptr createLevelSetPlatonic<Grid<TreeT>>(int, float, const Vec3f&, float, float, \
491 util::NullInterrupter*)
495 #define _FUNCTION(TreeT) \
496 Grid<TreeT>::Ptr createLevelSetTetrahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \
497 util::NullInterrupter*)
501 #define _FUNCTION(TreeT) \
502 Grid<TreeT>::Ptr createLevelSetCube<Grid<TreeT>>(float, const Vec3f&, float, float, \
503 util::NullInterrupter*)
507 #define _FUNCTION(TreeT) \
508 Grid<TreeT>::Ptr createLevelSetOctahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \
509 util::NullInterrupter*)
513 #define _FUNCTION(TreeT) \
514 Grid<TreeT>::Ptr createLevelSetDodecahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \
515 util::NullInterrupter*)
519 #define _FUNCTION(TreeT) \
520 Grid<TreeT>::Ptr createLevelSetIcosahedron<Grid<TreeT>>(float, const Vec3f&, float, float, \
521 util::NullInterrupter*)
525 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
532 #endif // OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED
GLsizei const GLfloat * value
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
#define OPENVDB_USE_VERSION_NAMESPACE
Base class for interrupters.
GA_API const UT_StringHolder scale
math::Vec4< Index32 > Vec4I
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
math::Vec3< Index32 > Vec3I
Convert polygonal meshes that consist of quads and/or triangles into signed or unsigned distance fiel...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
#define OPENVDB_THROW(exception, message)