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
53 const Vec3f& center =
Vec3f(0.0f),
54 float voxelSize = 0.1f,
56 InterruptT* interrupt =
nullptr);
70 template<
typename Gr
idType>
71 typename GridType::Ptr
76 float voxelSize = 0.1f,
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.1f,
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.1f,
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.1f,
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.1f,
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.1f,
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.1f,
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.1f,
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.1f,
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.1f,
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.1f,
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)
317 static_assert(std::is_floating_point<typename GridType::ValueType>::value,
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.0f, 1.0f, 0.0f) );
329 vtx.push_back(
Vec3f(-0.942810297f, -0.333329707f, 0.0f) );
330 vtx.push_back(
Vec3f( 0.471405149f, -0.333329707f, 0.816497624f) );
331 vtx.push_back(
Vec3f( 0.471405149f, -0.333329707f, -0.816497624f) );
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.5f, -0.5f, -0.5f) );
341 vtx.push_back(
Vec3f( 0.5f, -0.5f, -0.5f) );
342 vtx.push_back(
Vec3f( 0.5f, -0.5f, 0.5f) );
343 vtx.push_back(
Vec3f(-0.5f, -0.5f, 0.5f) );
344 vtx.push_back(
Vec3f(-0.5f, 0.5f, -0.5f) );
345 vtx.push_back(
Vec3f( 0.5f, 0.5f, -0.5f) );
346 vtx.push_back(
Vec3f( 0.5f, 0.5f, 0.5f) );
347 vtx.push_back(
Vec3f(-0.5f, 0.5f, 0.5f) );
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.0f, 0.0f, -1.0f) );
359 vtx.push_back(
Vec3f( 1.0f, 0.0f, 0.0f) );
360 vtx.push_back(
Vec3f( 0.0f, 0.0f, 1.0f) );
361 vtx.push_back(
Vec3f(-1.0f, 0.0f, 0.0f) );
362 vtx.push_back(
Vec3f( 0.0f,-1.0f, 0.0f) );
363 vtx.push_back(
Vec3f( 0.0f, 1.0f, 0.0f) );
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.354437858f, 0.487842113f, -0.789344311f) );
377 vtx.push_back(
Vec3f( 0.573492587f, -0.186338872f, -0.78934437f) );
378 vtx.push_back(
Vec3f( 0.0f, -0.603005826f, -0.78934443f) );
379 vtx.push_back(
Vec3f(-0.573492587f, -0.186338872f, -0.78934437f) );
380 vtx.push_back(
Vec3f(-0.354437858f, 0.487842113f, -0.789344311f) );
381 vtx.push_back(
Vec3f(-0.573492587f, 0.789345026f, -0.186338797f) );
382 vtx.push_back(
Vec3f(-0.927930415f, -0.301502913f, -0.186338872f) );
383 vtx.push_back(
Vec3f( 0.0f, -0.975683928f, -0.186338902f) );
384 vtx.push_back(
Vec3f( 0.927930415f, -0.301502913f, -0.186338872f) );
385 vtx.push_back(
Vec3f( 0.573492587f, 0.789345026f, -0.186338797f) );
386 vtx.push_back(
Vec3f( 0.0f, 0.975683868f, 0.186338902f) );
387 vtx.push_back(
Vec3f(-0.927930415f, 0.301502913f, 0.186338872f) );
388 vtx.push_back(
Vec3f(-0.573492587f, -0.789345026f, 0.186338797f) );
389 vtx.push_back(
Vec3f( 0.573492587f, -0.789345026f, 0.186338797f) );
390 vtx.push_back(
Vec3f( 0.927930415f, 0.301502913f, 0.186338872f) );
391 vtx.push_back(
Vec3f( 0.0f, 0.603005826f, 0.78934443f) );
392 vtx.push_back(
Vec3f( 0.573492587f, 0.186338872f, 0.78934437f) );
393 vtx.push_back(
Vec3f( 0.354437858f, -0.487842113f, 0.789344311f) );
394 vtx.push_back(
Vec3f(-0.354437858f, -0.487842113f, 0.789344311f) );
395 vtx.push_back(
Vec3f(-0.573492587f, 0.186338872f, 0.78934437f) );
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.0f, 0.0f, -1.0f) );
425 vtx.push_back(
Vec3f(0.0f, 0.894427359f, -0.447213143f) );
426 vtx.push_back(
Vec3f(0.850650847f, 0.276393682f, -0.447213203f) );
427 vtx.push_back(
Vec3f(0.525731206f, -0.723606944f, -0.447213262f) );
428 vtx.push_back(
Vec3f(-0.525731206f, -0.723606944f, -0.447213262f) );
429 vtx.push_back(
Vec3f(-0.850650847f, 0.276393682f, -0.447213203f) );
430 vtx.push_back(
Vec3f(-0.525731206f, 0.723606944f, 0.447213262f) );
431 vtx.push_back(
Vec3f(-0.850650847f, -0.276393682f, 0.447213203f) );
432 vtx.push_back(
Vec3f(0.0f, -0.894427359f, 0.447213143f) );
433 vtx.push_back(
Vec3f(0.850650847f, -0.276393682f, 0.447213203f) );
434 vtx.push_back(
Vec3f(0.525731206f, 0.723606944f, 0.447213262f) );
435 vtx.push_back(
Vec3f(0.0f, 0.0f, 1.0f) );
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
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Base class for interrupters.
Definition: NullInterrupter.h:25
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:461
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:615
Convert polygonal meshes that consist of quads and/or triangles into signed or unsigned distance fiel...
Definition: Exceptions.h:13
math::Vec3< float > Vec3f
Definition: Types.h:74
math::Vec3< Index32 > Vec3I
Definition: Types.h:73
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition: version.h.in:162
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
math::Vec4< Index32 > Vec4I
Definition: Types.h:88
Definition: Exceptions.h:63