8 #ifndef __UT_VDBUtils__
9 #define __UT_VDBUtils__
45 using namespace openvdb;
46 using namespace openvdb::tools;
102 return "invalid type";
143 template <
typename T>
159 template <
typename Gr
idType>
164 template <
typename Gr
idType>
169 template <
typename Gr
idType>
174 template <
typename Gr
idType>
179 template <
typename Gr
idType>
180 inline typename GridType::ConstPtr
182 {
return openvdb::gridConstPtrCast<GridType>(grid); }
184 template <
typename Gr
idType>
185 inline typename GridType::Ptr
187 {
return openvdb::gridPtrCast<GridType>(grid); }
192 namespace UT_VDBUtils {
197 template<
typename Gr
idType,
typename OpType,
typename Gr
idBaseType>
201 op.template operator()<
GridType>(UTvdbGridCast<GridType>(grid));
237 #define UT_VDB_DECL_PROCESS_TYPED_GRID(GRID_BASE_T) \
238 template<typename OpType> \
240 UTvdbProcessTypedGrid(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
242 using namespace openvdb; \
243 using namespace UT_VDBUtils; \
246 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
247 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
248 case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
249 case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
250 case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
251 case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
252 case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
253 default: return false; \
257 template<typename OpType> \
259 UTvdbProcessTypedGridTopology(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
261 using namespace openvdb; \
262 using namespace UT_VDBUtils; \
265 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
266 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
267 case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
268 case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
269 case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
270 case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
271 case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
272 case UT_VDB_BOOL: callTypedGrid<BoolGrid>(grid, op); break; \
273 default: return false; \
277 template<typename OpType> \
279 UTvdbProcessTypedGridVec3(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
281 using namespace openvdb; \
282 using namespace UT_VDBUtils; \
285 case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
286 case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
287 case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
288 default: return false; \
292 template<typename OpType> \
294 UTvdbProcessTypedGridScalar(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
296 using namespace openvdb; \
297 using namespace UT_VDBUtils; \
300 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
301 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
302 case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
303 case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
304 default: return false; \
308 template<typename OpType> \
310 UTvdbProcessTypedGridReal(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
312 using namespace openvdb; \
313 using namespace UT_VDBUtils; \
316 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
317 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
318 default: return false; \
322 template<typename OpType> \
324 UTvdbProcessTypedGridPoint(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
326 using namespace openvdb; \
327 using namespace openvdb::tools; \
328 using namespace openvdb::points; \
329 using namespace UT_VDBUtils; \
332 case UT_VDB_POINTINDEX: callTypedGrid<PointIndexGrid>(grid, op); break; \
333 case UT_VDB_POINTDATA: callTypedGrid<PointDataGrid>(grid, op); break; \
334 default: return false; \
350 #define UT_VDB_CALL(GRIDT, RETURN, FNAME, GRIDBASE, ...) \
352 RETURN FNAME <GRIDT> (UTvdbGridCast<GRIDT>(GRIDBASE), __VA_ARGS__ ); \
370 #define UTvdbCallRealType(TYPE, FNAME, GRIDBASE, ...) \
371 if (TYPE == UT_VDB_FLOAT) \
372 UT_VDB_CALL(openvdb::FloatGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
373 else if (TYPE == UT_VDB_DOUBLE) \
374 UT_VDB_CALL(openvdb::DoubleGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
376 #define UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, ...) \
377 UTvdbCallRealType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
378 else if (TYPE == UT_VDB_INT32) \
379 UT_VDB_CALL(openvdb::Int32Grid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
380 else if (TYPE == UT_VDB_INT64) \
381 UT_VDB_CALL(openvdb::Int64Grid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
383 #define UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, ...) \
384 if (TYPE == UT_VDB_VEC3F) \
385 UT_VDB_CALL(openvdb::Vec3fGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
386 else if (TYPE == UT_VDB_VEC3D) \
387 UT_VDB_CALL(openvdb::Vec3dGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
388 else if (TYPE == UT_VDB_VEC3I) \
389 UT_VDB_CALL(openvdb::Vec3IGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
391 #define UTvdbCallPointType(TYPE, FNAME, GRIDBASE, ...) \
392 if (TYPE == UT_VDB_POINTINDEX) \
393 UT_VDB_CALL(openvdb::tools::PointIndexGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
394 else if (TYPE == UT_VDB_POINTDATA) \
395 UT_VDB_CALL(openvdb::points::PointDataGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
397 #define UTvdbCallBoolType(TYPE, FNAME, GRIDBASE, ...) \
398 if (TYPE == UT_VDB_BOOL) \
399 UT_VDB_CALL(openvdb::BoolGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
401 #define UTvdbCallAllType(TYPE, FNAME, GRIDBASE, ...) \
402 UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
403 else UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__); \
405 #define UTvdbCallAllTopology(TYPE, FNAME, GRIDBASE, ...) \
406 UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
407 else UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
408 else UTvdbCallBoolType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
430 #define UTvdbReturnRealType(TYPE, FNAME, GRIDBASE, ...) \
431 if (TYPE == UT_VDB_FLOAT) \
432 UT_VDB_CALL(openvdb::FloatGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
433 else if (TYPE == UT_VDB_DOUBLE) \
434 UT_VDB_CALL(openvdb::DoubleGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
436 #define UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, ...) \
437 UTvdbReturnRealType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
438 else if (TYPE == UT_VDB_INT32) \
439 UT_VDB_CALL(openvdb::Int32Grid,return,FNAME,GRIDBASE,__VA_ARGS__) \
440 else if (TYPE == UT_VDB_INT64) \
441 UT_VDB_CALL(openvdb::Int64Grid,return,FNAME,GRIDBASE,__VA_ARGS__) \
443 #define UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, ...) \
444 if (TYPE == UT_VDB_VEC3F) \
445 UT_VDB_CALL(openvdb::Vec3fGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
446 else if (TYPE == UT_VDB_VEC3D) \
447 UT_VDB_CALL(openvdb::Vec3dGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
448 else if (TYPE == UT_VDB_VEC3I) \
449 UT_VDB_CALL(openvdb::Vec3IGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
451 #define UTvdbReturnPointType(TYPE, FNAME, GRIDBASE, ...) \
452 if (TYPE == UT_VDB_POINTINDEX) \
453 UT_VDB_CALL(openvdb::tools::PointIndexGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
454 else if (TYPE == UT_VDB_POINTDATA) \
455 UT_VDB_CALL(openvdb::points::PointDataGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
457 #define UTvdbReturnBoolType(TYPE, FNAME, GRIDBASE, ...) \
458 if (TYPE == UT_VDB_BOOL) \
459 UT_VDB_CALL(openvdb::BoolGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
461 #define UTvdbReturnAllType(TYPE, FNAME, GRIDBASE, ...) \
462 UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
463 else UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__); \
465 #define UTvdbReturnAllTopology(TYPE, FNAME, GRIDBASE, ...) \
466 UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
467 else UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
468 else UTvdbReturnBoolType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
478 template <
typename S>
488 template <
typename S>
497 template <
typename S>
508 template <
typename S>
509 openvdb::math::Mat4<S>
512 return openvdb::math::Mat4<S>(
src(0,0),
src(0,1),
src(0,2),
src(0,3),
517 template <
typename S>
518 openvdb::math::Mat3<S>
521 return openvdb::math::Mat3<S>(
src(0,0),
src(0,1),
src(0,2),
525 template <
typename S>
526 openvdb::math::Mat2<S>
529 return openvdb::math::Mat2<S>(
src(0,0),
src(0,1),
536 template <
typename S>
542 template <
typename S>
548 template <
typename S>
558 template <
typename S>
559 openvdb::math::Vec4<S>
562 return openvdb::math::Vec4<S>(src.
data());
564 template <
typename S>
565 openvdb::math::Vec3<S>
568 return openvdb::math::Vec3<S>(src.
data());
570 template <
typename S>
571 openvdb::math::Vec2<S>
574 return openvdb::math::Vec2<S>(src.
data());
592 openvdb::math::Coord(bbox.
xmin(), bbox.
ymin(), bbox.
zmin()),
593 openvdb::math::Coord(bbox.
xmax(), bbox.
ymax(), bbox.
zmax()));
598 inline openvdb::math::Transform::Ptr
604 openvdb::math::Transform::Ptr xform =
605 openvdb::math::Transform::createLinearTransform(vs);
611 template <
typename T>
612 inline openvdb::math::Vec4<T>
SYSabs(
const openvdb::math::Vec4<T> &
v1)
613 {
return openvdb::math::Vec4<T>(
SYSabs(v1[0]),
619 template <
typename T>
620 inline openvdb::math::Vec3<T>
SYSabs(
const openvdb::math::Vec3<T> &
v1)
621 {
return openvdb::math::Vec3<T>(
SYSabs(v1[0]),
626 template <
typename T>
627 inline openvdb::math::Vec2<T>
SYSabs(
const openvdb::math::Vec2<T> &
v1)
628 {
return openvdb::math::Vec2<T>(
SYSabs(v1[0]),
633 template <
typename T>
634 inline openvdb::math::Vec4<T>
SYSmin(
const openvdb::math::Vec4<T> &
v1,
const openvdb::math::Vec4<T> &
v2)
635 {
return openvdb::math::Vec4<T>(
SYSmin(v1[0], v2[0]),
641 template <
typename T>
642 inline openvdb::math::Vec4<T>
SYSmax(
const openvdb::math::Vec4<T> &
v1,
const openvdb::math::Vec4<T> &
v2)
643 {
return openvdb::math::Vec4<T>(
SYSmax(v1[0], v2[0]),
649 template <
typename T>
650 inline openvdb::math::Vec4<T>
SYSmin(
const openvdb::math::Vec4<T> &
v1,
const openvdb::math::Vec4<T> &
v2,
const openvdb::math::Vec4<T> &
v3)
651 {
return openvdb::math::Vec4<T>(
SYSmin(v1[0], v2[0], v3[0]),
652 SYSmin(v1[1], v2[1], v3[1]),
653 SYSmin(v1[2], v2[2], v3[2]),
654 SYSmin(v1[3], v2[3], v3[3])
657 template <
typename T>
658 inline openvdb::math::Vec4<T>
SYSmax(
const openvdb::math::Vec4<T> &
v1,
const openvdb::math::Vec4<T> &
v2,
const openvdb::math::Vec4<T> &
v3)
659 {
return openvdb::math::Vec4<T>(
SYSmax(v1[0], v2[0], v3[0]),
660 SYSmax(v1[1], v2[1], v3[1]),
661 SYSmax(v1[2], v2[2], v3[2]),
662 SYSmax(v1[3], v2[3], v3[3])
665 template <
typename T>
666 inline openvdb::math::Vec3<T>
SYSmin(
const openvdb::math::Vec3<T> &
v1,
const openvdb::math::Vec3<T> &
v2)
667 {
return openvdb::math::Vec3<T>(
SYSmin(v1[0], v2[0]),
672 template <
typename T>
673 inline openvdb::math::Vec3<T>
SYSmax(
const openvdb::math::Vec3<T> &
v1,
const openvdb::math::Vec3<T> &
v2)
674 {
return openvdb::math::Vec3<T>(
SYSmax(v1[0], v2[0]),
679 template <
typename T>
680 inline openvdb::math::Vec3<T>
SYSmin(
const openvdb::math::Vec3<T> &
v1,
const openvdb::math::Vec3<T> &
v2,
const openvdb::math::Vec3<T> &
v3)
681 {
return openvdb::math::Vec3<T>(
SYSmin(v1[0], v2[0], v3[0]),
682 SYSmin(v1[1], v2[1], v3[1]),
683 SYSmin(v1[2], v2[2], v3[2])
686 template <
typename T>
687 inline openvdb::math::Vec3<T>
SYSmax(
const openvdb::math::Vec3<T> &
v1,
const openvdb::math::Vec3<T> &
v2,
const openvdb::math::Vec3<T> &
v3)
688 {
return openvdb::math::Vec3<T>(
SYSmax(v1[0], v2[0], v3[0]),
689 SYSmax(v1[1], v2[1], v3[1]),
690 SYSmax(v1[2], v2[2], v3[2])
693 template <
typename T>
694 inline openvdb::math::Vec2<T>
SYSmin(
const openvdb::math::Vec2<T> &
v1,
const openvdb::math::Vec2<T> &
v2)
695 {
return openvdb::math::Vec2<T>(
SYSmin(v1[0], v2[0]),
699 template <
typename T>
700 inline openvdb::math::Vec2<T>
SYSmax(
const openvdb::math::Vec2<T> &
v1,
const openvdb::math::Vec2<T> &
v2)
701 {
return openvdb::math::Vec2<T>(
SYSmax(v1[0], v2[0]),
705 template <
typename T>
706 inline openvdb::math::Vec2<T>
SYSmin(
const openvdb::math::Vec2<T> &
v1,
const openvdb::math::Vec2<T> &
v2,
const openvdb::math::Vec2<T> &
v3)
707 {
return openvdb::math::Vec2<T>(
SYSmin(v1[0], v2[0], v3[0]),
708 SYSmin(v1[1], v2[1], v3[1])
711 template <
typename T>
712 inline openvdb::math::Vec2<T>
SYSmax(
const openvdb::math::Vec2<T> &
v1,
const openvdb::math::Vec2<T> &
v2,
const openvdb::math::Vec2<T> &
v3)
713 {
return openvdb::math::Vec2<T>(
SYSmax(v1[0], v2[0], v3[0]),
714 SYSmax(v1[1], v2[1], v3[1])
718 #endif // __UT_VDBUtils__
static void plusEqual(bool &lhs, const bool &rhs)
GLdouble GLdouble GLint GLint const GLdouble * points
GridType
List of types that are currently supported by NanoVDB.
Grid< Vec3fTree > Vec3fGrid
UT_VDBType UTvdbGetGridType(const openvdb::GridBase &grid)
Find the UT_VDBType from a grid.
Grid< DoubleTree > DoubleGrid
const GridType * UTvdbGridCast(const openvdb::GridBase *grid)
void UTvdbInitialize()
Calls openvdb::initialize()
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
void callTypedGrid(GridBaseType &grid, OpType &op)
GLfloat GLfloat GLfloat v2
GLfloat GLfloat GLfloat GLfloat v3
UT_BoundingBoxT< fpreal64 > UT_BoundingBoxD
constexpr SYS_FORCE_INLINE const T * data() const noexcept
openvdb::math::Vec4< T > SYSabs(const openvdb::math::Vec4< T > &v1)
openvdb::math::Vec4< T > SYSmax(const openvdb::math::Vec4< T > &v1, const openvdb::math::Vec4< T > &v2)
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
#define UT_VDB_DECL_PROCESS_TYPED_GRID(GRID_BASE_T)
Utility function that, given a generic grid pointer, calls a functor on the fully-resolved grid...
Grid< Int64Tree > Int64Grid
Grid< FloatTree > FloatGrid
openvdb::math::Transform::Ptr UTvdbCreateTransform(const UT_Vector3 &orig, const UT_Vector3 &voxsize)
Grid< Vec3ITree > Vec3IGrid
static void plusEqual(T &lhs, const T &rhs)
const char * UTvdbGetGridTypeString(const openvdb::GridBase &grid)
Return the string representation of a grid's underlying value type.
Grid< PointDataTree > PointDataGrid
Point data grid.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
int UTvdbGetGridTupleSize(UT_VDBType type)
Returns the tuple size of a grid given its value type.
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Grid< BoolTree > BoolGrid
Grid< Vec3dTree > Vec3dGrid
openvdb::math::Vec4< T > SYSmin(const openvdb::math::Vec4< T > &v1, const openvdb::math::Vec4< T > &v2)
constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
UT_Matrix4T< S > UTvdbConvert(const openvdb::math::Mat4< S > &src)
Matrix conversion from openvdb to UT.
Grid< Int32Tree > Int32Grid