41 #ifndef OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED 42 #define OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED 44 #include <openvdb/Grid.h> 45 #include <openvdb/Types.h> 46 #include <openvdb/math/Math.h> 47 #include <openvdb/math/Transform.h> 48 #include <openvdb/tools/MeshToVolume.h> 49 #include <openvdb/util/NullInterrupter.h> 50 #include <type_traits> 72 template<
typename Gr
idType,
typename InterruptT>
73 typename GridType::Ptr
78 float voxelSize = 0.1f,
80 InterruptT* interrupt =
nullptr);
94 template<
typename Gr
idType>
95 typename GridType::Ptr
100 float voxelSize = 0.1f,
104 return createLevelSetPlatonic<GridType>(faceCount,
scale, center, voxelSize, halfWidth, &tmp);
119 template<
typename Gr
idType,
typename InterruptT>
120 typename GridType::Ptr
124 float voxelSize = 0.1f,
126 InterruptT* interrupt =
nullptr)
128 return createLevelSetPlatonic<GridType, InterruptT>(
129 4,
scale, center, voxelSize, halfWidth, interrupt);
141 template<
typename Gr
idType>
142 typename GridType::Ptr
146 float voxelSize = 0.1f,
150 return createLevelSetPlatonic<GridType>(4,
scale, center, voxelSize, halfWidth, &tmp);
165 template<
typename Gr
idType,
typename InterruptT>
166 typename GridType::Ptr
170 float voxelSize = 0.1f,
172 InterruptT* interrupt =
nullptr)
174 return createLevelSetPlatonic<GridType>(6,
scale, center, voxelSize, halfWidth, interrupt);
186 template<
typename Gr
idType>
187 typename GridType::Ptr
191 float voxelSize = 0.1f,
195 return createLevelSetPlatonic<GridType>(6,
scale, center, voxelSize, halfWidth, &tmp);
210 template<
typename Gr
idType,
typename InterruptT>
211 typename GridType::Ptr
215 float voxelSize = 0.1f,
217 InterruptT* interrupt =
nullptr)
219 return createLevelSetPlatonic<GridType>(8,
scale, center, voxelSize, halfWidth, interrupt);
231 template<
typename Gr
idType>
232 typename GridType::Ptr
236 float voxelSize = 0.1f,
240 return createLevelSetPlatonic<GridType>(8,
scale, center, voxelSize, halfWidth, &tmp);
255 template<
typename Gr
idType,
typename InterruptT>
256 typename GridType::Ptr
260 float voxelSize = 0.1f,
262 InterruptT* interrupt =
nullptr)
264 return createLevelSetPlatonic<GridType>(12,
scale, center, voxelSize, halfWidth, interrupt);
276 template<
typename Gr
idType>
277 typename GridType::Ptr
281 float voxelSize = 0.1f,
285 return createLevelSetPlatonic<GridType>(12,
scale, center, voxelSize, halfWidth, &tmp);
300 template<
typename Gr
idType,
typename InterruptT>
301 typename GridType::Ptr
305 float voxelSize = 0.1f,
307 InterruptT* interrupt =
nullptr)
309 return createLevelSetPlatonic<GridType>(20,
scale, center, voxelSize, halfWidth, interrupt);
321 template<
typename Gr
idType>
322 typename GridType::Ptr
326 float voxelSize = 0.1f,
330 return createLevelSetPlatonic<GridType>(20,
scale, center, voxelSize, halfWidth, &tmp);
335 template<
typename Gr
idType,
typename InterruptT>
336 typename GridType::Ptr
338 float voxelSize,
float halfWidth, InterruptT *interrupt)
341 static_assert(std::is_floating_point<typename GridType::ValueType>::value,
342 "level set grids must have scalar, floating-point value types");
346 std::vector<Vec3f> vtx;
347 std::vector<Vec3I> tri;
348 std::vector<Vec4I> qua;
350 if (faceCount == 4) {
352 vtx.push_back(
Vec3f( 0.0f, 1.0f, 0.0f) );
353 vtx.push_back(
Vec3f(-0.942810297f, -0.333329707f, 0.0f) );
354 vtx.push_back(
Vec3f( 0.471405149f, -0.333329707f, 0.816497624f) );
355 vtx.push_back(
Vec3f( 0.471405149f, -0.333329707f, -0.816497624f) );
357 tri.push_back(
Vec3I(0, 2, 3) );
358 tri.push_back(
Vec3I(0, 3, 1) );
359 tri.push_back(
Vec3I(0, 1, 2) );
360 tri.push_back(
Vec3I(1, 3, 2) );
362 }
else if (faceCount == 6) {
364 vtx.push_back(
Vec3f(-0.5f, -0.5f, -0.5f) );
365 vtx.push_back(
Vec3f( 0.5f, -0.5f, -0.5f) );
366 vtx.push_back(
Vec3f( 0.5f, -0.5f, 0.5f) );
367 vtx.push_back(
Vec3f(-0.5f, -0.5f, 0.5f) );
368 vtx.push_back(
Vec3f(-0.5f, 0.5f, -0.5f) );
369 vtx.push_back(
Vec3f( 0.5f, 0.5f, -0.5f) );
370 vtx.push_back(
Vec3f( 0.5f, 0.5f, 0.5f) );
371 vtx.push_back(
Vec3f(-0.5f, 0.5f, 0.5f) );
373 qua.push_back(
Vec4I(1, 0, 4, 5) );
374 qua.push_back(
Vec4I(2, 1, 5, 6) );
375 qua.push_back(
Vec4I(3, 2, 6, 7) );
376 qua.push_back(
Vec4I(0, 3, 7, 4) );
377 qua.push_back(
Vec4I(2, 3, 0, 1) );
378 qua.push_back(
Vec4I(5, 4, 7, 6) );
380 }
else if (faceCount == 8) {
382 vtx.push_back(
Vec3f( 0.0f, 0.0f, -1.0f) );
383 vtx.push_back(
Vec3f( 1.0f, 0.0f, 0.0f) );
384 vtx.push_back(
Vec3f( 0.0f, 0.0f, 1.0f) );
385 vtx.push_back(
Vec3f(-1.0f, 0.0f, 0.0f) );
386 vtx.push_back(
Vec3f( 0.0f,-1.0f, 0.0f) );
387 vtx.push_back(
Vec3f( 0.0f, 1.0f, 0.0f) );
389 tri.push_back(
Vec3I(0, 4, 3) );
390 tri.push_back(
Vec3I(0, 1, 4) );
391 tri.push_back(
Vec3I(1, 2, 4) );
392 tri.push_back(
Vec3I(2, 3, 4) );
393 tri.push_back(
Vec3I(0, 3, 5) );
394 tri.push_back(
Vec3I(0, 5, 1) );
395 tri.push_back(
Vec3I(1, 5, 2) );
396 tri.push_back(
Vec3I(2, 5, 3) );
398 }
else if (faceCount == 12) {
400 vtx.push_back(
Vec3f( 0.354437858f, 0.487842113f, -0.789344311f) );
401 vtx.push_back(
Vec3f( 0.573492587f, -0.186338872f, -0.78934437f) );
402 vtx.push_back(
Vec3f( 0.0f, -0.603005826f, -0.78934443f) );
403 vtx.push_back(
Vec3f(-0.573492587f, -0.186338872f, -0.78934437f) );
404 vtx.push_back(
Vec3f(-0.354437858f, 0.487842113f, -0.789344311f) );
405 vtx.push_back(
Vec3f(-0.573492587f, 0.789345026f, -0.186338797f) );
406 vtx.push_back(
Vec3f(-0.927930415f, -0.301502913f, -0.186338872f) );
407 vtx.push_back(
Vec3f( 0.0f, -0.975683928f, -0.186338902f) );
408 vtx.push_back(
Vec3f( 0.927930415f, -0.301502913f, -0.186338872f) );
409 vtx.push_back(
Vec3f( 0.573492587f, 0.789345026f, -0.186338797f) );
410 vtx.push_back(
Vec3f( 0.0f, 0.975683868f, 0.186338902f) );
411 vtx.push_back(
Vec3f(-0.927930415f, 0.301502913f, 0.186338872f) );
412 vtx.push_back(
Vec3f(-0.573492587f, -0.789345026f, 0.186338797f) );
413 vtx.push_back(
Vec3f( 0.573492587f, -0.789345026f, 0.186338797f) );
414 vtx.push_back(
Vec3f( 0.927930415f, 0.301502913f, 0.186338872f) );
415 vtx.push_back(
Vec3f( 0.0f, 0.603005826f, 0.78934443f) );
416 vtx.push_back(
Vec3f( 0.573492587f, 0.186338872f, 0.78934437f) );
417 vtx.push_back(
Vec3f( 0.354437858f, -0.487842113f, 0.789344311f) );
418 vtx.push_back(
Vec3f(-0.354437858f, -0.487842113f, 0.789344311f) );
419 vtx.push_back(
Vec3f(-0.573492587f, 0.186338872f, 0.78934437f) );
421 qua.push_back(
Vec4I(0, 1, 2, 3) );
422 tri.push_back(
Vec3I(0, 3, 4) );
423 qua.push_back(
Vec4I(0, 4, 5, 10) );
424 tri.push_back(
Vec3I(0, 10, 9) );
425 qua.push_back(
Vec4I(0, 9, 14, 8) );
426 tri.push_back(
Vec3I(0, 8, 1) );
427 qua.push_back(
Vec4I(1, 8, 13, 7) );
428 tri.push_back(
Vec3I(1, 7, 2) );
429 qua.push_back(
Vec4I(2, 7, 12, 6) );
430 tri.push_back(
Vec3I(2, 6, 3) );
431 qua.push_back(
Vec4I(3, 6, 11, 5) );
432 tri.push_back(
Vec3I(3, 5, 4) );
433 qua.push_back(
Vec4I(5, 11, 19, 15) );
434 tri.push_back(
Vec3I(5, 15, 10) );
435 qua.push_back(
Vec4I(6, 12, 18, 19) );
436 tri.push_back(
Vec3I(6, 19, 11) );
437 qua.push_back(
Vec4I(7, 13, 17, 18) );
438 tri.push_back(
Vec3I(7, 18, 12) );
439 qua.push_back(
Vec4I(8, 14, 16, 17) );
440 tri.push_back(
Vec3I(8, 17, 13) );
441 qua.push_back(
Vec4I(9, 10, 15, 16) );
442 tri.push_back(
Vec3I(9, 16, 14) );
443 qua.push_back(
Vec4I(15, 19, 18, 17) );
444 tri.push_back(
Vec3I(15, 17, 16) );
446 }
else if (faceCount == 20) {
448 vtx.push_back(
Vec3f(0.0f, 0.0f, -1.0f) );
449 vtx.push_back(
Vec3f(0.0f, 0.894427359f, -0.447213143f) );
450 vtx.push_back(
Vec3f(0.850650847f, 0.276393682f, -0.447213203f) );
451 vtx.push_back(
Vec3f(0.525731206f, -0.723606944f, -0.447213262f) );
452 vtx.push_back(
Vec3f(-0.525731206f, -0.723606944f, -0.447213262f) );
453 vtx.push_back(
Vec3f(-0.850650847f, 0.276393682f, -0.447213203f) );
454 vtx.push_back(
Vec3f(-0.525731206f, 0.723606944f, 0.447213262f) );
455 vtx.push_back(
Vec3f(-0.850650847f, -0.276393682f, 0.447213203f) );
456 vtx.push_back(
Vec3f(0.0f, -0.894427359f, 0.447213143f) );
457 vtx.push_back(
Vec3f(0.850650847f, -0.276393682f, 0.447213203f) );
458 vtx.push_back(
Vec3f(0.525731206f, 0.723606944f, 0.447213262f) );
459 vtx.push_back(
Vec3f(0.0f, 0.0f, 1.0f) );
461 tri.push_back(
Vec3I( 2, 0, 1) );
462 tri.push_back(
Vec3I( 3, 0, 2) );
463 tri.push_back(
Vec3I( 4, 0, 3) );
464 tri.push_back(
Vec3I( 5, 0, 4) );
465 tri.push_back(
Vec3I( 1, 0, 5) );
466 tri.push_back(
Vec3I( 6, 1, 5) );
467 tri.push_back(
Vec3I( 7, 5, 4) );
468 tri.push_back(
Vec3I( 8, 4, 3) );
469 tri.push_back(
Vec3I( 9, 3, 2) );
470 tri.push_back(
Vec3I(10, 2, 1) );
471 tri.push_back(
Vec3I(10, 1, 6) );
472 tri.push_back(
Vec3I( 6, 5, 7) );
473 tri.push_back(
Vec3I( 7, 4, 8) );
474 tri.push_back(
Vec3I( 8, 3, 9) );
475 tri.push_back(
Vec3I( 9, 2, 10) );
476 tri.push_back(
Vec3I( 6, 11, 10) );
477 tri.push_back(
Vec3I(10, 11, 9) );
478 tri.push_back(
Vec3I( 9, 11, 8) );
479 tri.push_back(
Vec3I( 8, 11, 7) );
480 tri.push_back(
Vec3I( 7, 11, 6) );
487 for (
size_t i = 0; i<vtx.size(); ++i ) vtx[i] = scale * vtx[i] + center;
489 typename GridType::Ptr grid;
491 if (interrupt ==
nullptr) {
493 grid = meshToLevelSet<GridType>(tmp, *xform, vtx, tri, qua, halfWidth);
495 grid = meshToLevelSet<GridType>(*interrupt, *xform, vtx, tri, qua, halfWidth);
505 #endif // OPENVDB_TOOLS_LEVELSETPLATONIC_HAS_BEEN_INCLUDED
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
math::Vec3< float > Vec3f
Definition: Types.h:81
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:283
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:647
Definition: Exceptions.h:40
Definition: Exceptions.h:90
math::Vec4< Index32 > Vec4I
Definition: Types.h:95
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52
math::Vec3< Index32 > Vec3I
Definition: Types.h:80