OpenVDB: openvdb_houdini/UT_VDBUtils.h Source File

OpenVDB 12.1.0

Loading...
Searching...
No Matches
UT_VDBUtils.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4/*
5 * Copyright (c) Side Effects Software Inc.
6 *
7 * Produced by:
8 * Side Effects Software Inc.
9 * 123 Front Street West, Suite 1401
10 * Toronto, Ontario
11 * Canada M5J 2M2
12 * 416-366-4607
13 */
14
15#include <UT/UT_Version.h>
16
17#if !defined(SESI_OPENVDB) && !defined(SESI_OPENVDB_PRIM)
18
19#include <UT/UT_VDBUtils.h>
20
21#else
22
23#ifndef __HDK_UT_VDBUtils__
24#define __HDK_UT_VDBUtils__
25
26enum UT_VDBType
27{
28 UT_VDB_INVALID,
29 UT_VDB_FLOAT,
30 UT_VDB_DOUBLE,
31 UT_VDB_INT32,
32 UT_VDB_INT64,
33 UT_VDB_BOOL,
34 UT_VDB_VEC3F,
35 UT_VDB_VEC3D,
36 UT_VDB_VEC3I,
37 UT_VDB_POINTINDEX,
38 UT_VDB_POINTDATA,
39};
40
41#include <openvdb/openvdb.h>
42#include <openvdb/tools/PointIndexGrid.h>
43#include <openvdb/points/PointDataGrid.h>
44
45#include <UT/UT_Assert.h>
46#include <UT/UT_BoundingBox.h>
47#include <UT/UT_Matrix4.h>
48#include <UT/UT_Matrix3.h>
49#include <UT/UT_Matrix2.h>
50#include <SYS/SYS_Math.h>
51
52
53/// Calls openvdb::initialize()
54inline void UTvdbInitialize() { openvdb::initialize(); }
55
56/// Find the UT_VDBType from a grid
57inline UT_VDBType
58UTvdbGetGridType(const openvdb::GridBase &grid)
59{
60 using namespace openvdb;
61 using namespace openvdb::tools;
62 using namespace openvdb::points;
63
64 if (grid.isType<FloatGrid>())
65 return UT_VDB_FLOAT;
66 if (grid.isType<DoubleGrid>())
67 return UT_VDB_DOUBLE;
68 if (grid.isType<Int32Grid>())
69 return UT_VDB_INT32;
70 if (grid.isType<Int64Grid>())
71 return UT_VDB_INT64;
72 if (grid.isType<BoolGrid>())
73 return UT_VDB_BOOL;
74 if (grid.isType<Vec3fGrid>())
75 return UT_VDB_VEC3F;
76 if (grid.isType<Vec3dGrid>())
77 return UT_VDB_VEC3D;
78 if (grid.isType<Vec3IGrid>())
79 return UT_VDB_VEC3I;
80 if (grid.isType<Vec3IGrid>())
81 return UT_VDB_VEC3I;
82 if (grid.isType<PointIndexGrid>())
83 return UT_VDB_POINTINDEX;
84 if (grid.isType<PointDataGrid>())
85 return UT_VDB_POINTDATA;
86
87 return UT_VDB_INVALID;
88}
89
90/// Return the string representation of a grid's underlying value type
91inline const char *
92UTvdbGetGridTypeString(const openvdb::GridBase &grid)
93{
94 switch(UTvdbGetGridType(grid))
95 {
96 case UT_VDB_FLOAT:
97 return "float";
98 case UT_VDB_DOUBLE:
99 return "double";
100 case UT_VDB_INT32:
101 return "int32";
102 case UT_VDB_INT64:
103 return "int64";
104 case UT_VDB_BOOL:
105 return "bool";
106 case UT_VDB_VEC3F:
107 return "Vec3f";
108 case UT_VDB_VEC3D:
109 return "Vec3d";
110 case UT_VDB_VEC3I:
111 return "Vec3i";
112 case UT_VDB_POINTINDEX:
113 return "PointIndex";
114 case UT_VDB_POINTDATA:
115 return "PointData";
116 default:
117 return "invalid type";
118 }
119}
120
121/// Returns the tuple size of a grid given its value type.
122inline int
123UTvdbGetGridTupleSize(UT_VDBType type)
124{
125 switch(type)
126 {
127 case UT_VDB_FLOAT:
128 case UT_VDB_DOUBLE:
129 case UT_VDB_INT32:
130 case UT_VDB_INT64:
131 case UT_VDB_BOOL:
132 return 1;
133
134 case UT_VDB_VEC3F:
135 case UT_VDB_VEC3D:
136 case UT_VDB_VEC3I:
137 return 3;
138
139 case UT_VDB_POINTINDEX:
140 case UT_VDB_POINTDATA:
141 case UT_VDB_INVALID:
142 default:
143 break;
144 }
145
146 return 0;
147}
148
149/// Returns the tuple size of a grid
150inline int
151UTvdbGetGridTupleSize(const openvdb::GridBase &grid)
152{
153 return UTvdbGetGridTupleSize(UTvdbGetGridType(grid));
154}
155
156/// Special plusEqual class to avoid bool warnings
157/// @{
158template <typename T>
159struct UT_VDBMath
160{
161 static void plusEqual(T &lhs, const T &rhs)
162 { lhs += rhs; }
163};
164template <>
165struct UT_VDBMath<bool>
166{
167 static void plusEqual(bool &lhs, const bool &rhs)
168 { lhs = lhs | rhs; }
169};
170/// @}
171
172/// Helpers for downcasting to a specific grid type
173/// @{
174template <typename GridType>
175inline const GridType *
176UTvdbGridCast(const openvdb::GridBase *grid)
177 { return UTverify_cast<const GridType *>(grid); }
178
179template <typename GridType>
180inline GridType *
181UTvdbGridCast(openvdb::GridBase *grid)
182 { return UTverify_cast<GridType *>(grid); }
183
184template <typename GridType>
185inline const GridType &
186UTvdbGridCast(const openvdb::GridBase &grid)
187 { return *UTverify_cast<const GridType *>(&grid); }
188
189template <typename GridType>
190inline GridType &
191UTvdbGridCast(openvdb::GridBase &grid)
192 { return *UTverify_cast<GridType *>(&grid); }
193
194template <typename GridType>
195inline typename GridType::ConstPtr
196UTvdbGridCast(openvdb::GridBase::ConstPtr grid)
197 { return openvdb::gridConstPtrCast<GridType>(grid); }
198
199template <typename GridType>
200inline typename GridType::Ptr
201UTvdbGridCast(openvdb::GridBase::Ptr grid)
202 { return openvdb::gridPtrCast<GridType>(grid); }
203/// @}
204
205////////////////////////////////////////
206
207namespace UT_VDBUtils {
208
209// Helper function used internally by UTvdbProcessTypedGrid()
210// to instantiate a templated functor for a specific grid type
211// and then to call the functor with a grid of that type
212template<typename GridType, typename OpType, typename GridBaseType>
213inline void
214callTypedGrid(GridBaseType &grid, OpType& op)
215{
216 op.template operator()<GridType>(UTvdbGridCast<GridType>(grid));
217}
218
219} // namespace UT_VDBUtils
220
221////////////////////////////////////////
222
223
224/// @brief Utility function that, given a generic grid pointer,
225/// calls a functor on the fully-resolved grid
226///
227/// @par Example:
228/// @code
229/// using openvdb::Coord;
230/// using openvdb::CoordBBox;
231///
232/// struct FillOp {
233/// const CoordBBox bbox;
234///
235/// FillOp(const CoordBBox& b): bbox(b) {}
236///
237/// template<typename GridT>
238/// void operator()(GridT& grid) const {
239/// using ValueT = typename GridT::ValueType;
240/// grid.fill(bbox, ValueT(1));
241/// }
242/// };
243///
244/// GU_PrimVDB* vdb = ...;
245/// vdb->makeGridUnique();
246/// CoordBBox bbox(Coord(0,0,0), Coord(10,10,10));
247/// UTvdbProcessTypedGrid(vdb->getStorageType(), vdb->getGrid(), FillOp(bbox));
248/// @endcode
249///
250/// @return @c false if the grid type is unknown or unhandled.
251/// @{
252#define UT_VDB_DECL_PROCESS_TYPED_GRID(GRID_BASE_T) \
253template<typename OpType> \
254inline bool \
255UTvdbProcessTypedGrid(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
256{ \
257 using namespace openvdb; \
258 using namespace UT_VDBUtils; \
259 switch (grid_type) \
260 { \
261 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
262 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
263 case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
264 case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
265 case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
266 case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
267 case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
268 default: return false; \
269 } \
270 return true; \
271} \
272template<typename OpType> \
273inline bool \
274UTvdbProcessTypedGridTopology(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
275{ \
276 using namespace openvdb; \
277 using namespace UT_VDBUtils; \
278 switch (grid_type) \
279 { \
280 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
281 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
282 case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
283 case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
284 case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
285 case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
286 case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
287 case UT_VDB_BOOL: callTypedGrid<BoolGrid>(grid, op); break; \
288 default: return false; \
289 } \
290 return true; \
291} \
292template<typename OpType> \
293inline bool \
294UTvdbProcessTypedGridVec3(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
295{ \
296 using namespace openvdb; \
297 using namespace UT_VDBUtils; \
298 switch (grid_type) \
299 { \
300 case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
301 case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
302 case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
303 default: return false; \
304 } \
305 return true; \
306} \
307template<typename OpType> \
308inline bool \
309UTvdbProcessTypedGridScalar(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
310{ \
311 using namespace openvdb; \
312 using namespace UT_VDBUtils; \
313 switch (grid_type) \
314 { \
315 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
316 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
317 case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
318 case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
319 default: return false; \
320 } \
321 return true; \
322} \
323template<typename OpType> \
324inline bool \
325UTvdbProcessTypedGridReal(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
326{ \
327 using namespace openvdb; \
328 using namespace UT_VDBUtils; \
329 switch (grid_type) \
330 { \
331 case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
332 case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
333 default: return false; \
334 } \
335 return true; \
336} \
337template<typename OpType> \
338inline bool \
339UTvdbProcessTypedGridPoint(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
340{ \
341 using namespace openvdb; \
342 using namespace openvdb::tools; \
343 using namespace openvdb::points; \
344 using namespace UT_VDBUtils; \
345 switch (grid_type) \
346 { \
347 case UT_VDB_POINTINDEX: callTypedGrid<PointIndexGrid>(grid, op); break; \
348 case UT_VDB_POINTDATA: callTypedGrid<PointDataGrid>(grid, op); break; \
349 default: return false; \
350 } \
351 return true; \
352} \
353/**/
354UT_VDB_DECL_PROCESS_TYPED_GRID(const openvdb::GridBase &)
355UT_VDB_DECL_PROCESS_TYPED_GRID(const openvdb::GridBase *)
356UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase::ConstPtr)
357UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase &)
358UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase *)
359UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase::Ptr)
360
361/// @}
362
363
364// Helper macro for UTvdbCall* macros, do not outside of this file!
365#define UT_VDB_CALL(GRIDT, RETURN, FNAME, GRIDBASE, ...) \
366 { \
367 RETURN FNAME <GRIDT> (UTvdbGridCast<GRIDT>(GRIDBASE), __VA_ARGS__ ); \
368 } \
369 /**/
370
371//@{
372/// Macro to invoke the correct type of grid.
373/// Use like:
374/// @code
375/// UTvdbCallScalarType(grid_type, myfunction, grid, parms)
376/// @endcode
377/// to invoke
378/// @code
379/// template <typename GridType>
380/// static void
381/// myfunction(const GridType &grid, parms)
382/// { }
383/// @endcode
384
385#define UTvdbCallRealType(TYPE, FNAME, GRIDBASE, ...) \
386 if (TYPE == UT_VDB_FLOAT) \
387 UT_VDB_CALL(openvdb::FloatGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
388 else if (TYPE == UT_VDB_DOUBLE) \
389 UT_VDB_CALL(openvdb::DoubleGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
390 /**/
391#define UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, ...) \
392 UTvdbCallRealType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
393 else if (TYPE == UT_VDB_INT32) \
394 UT_VDB_CALL(openvdb::Int32Grid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
395 else if (TYPE == UT_VDB_INT64) \
396 UT_VDB_CALL(openvdb::Int64Grid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
397 /**/
398#define UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, ...) \
399 if (TYPE == UT_VDB_VEC3F) \
400 UT_VDB_CALL(openvdb::Vec3fGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
401 else if (TYPE == UT_VDB_VEC3D) \
402 UT_VDB_CALL(openvdb::Vec3dGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
403 else if (TYPE == UT_VDB_VEC3I) \
404 UT_VDB_CALL(openvdb::Vec3IGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
405 /**/
406#define UTvdbCallPointType(TYPE, FNAME, GRIDBASE, ...) \
407 if (TYPE == UT_VDB_POINTINDEX) \
408 UT_VDB_CALL(openvdb::tools::PointIndexGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
409 else if (TYPE == UT_VDB_POINTDATA) \
410 UT_VDB_CALL(openvdb::points::PointDataGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
411 /**/
412#define UTvdbCallBoolType(TYPE, FNAME, GRIDBASE, ...) \
413 if (TYPE == UT_VDB_BOOL) \
414 UT_VDB_CALL(openvdb::BoolGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
415 /**/
416#define UTvdbCallAllType(TYPE, FNAME, GRIDBASE, ...) \
417 UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
418 else UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__); \
419 /**/
420#define UTvdbCallAllTopology(TYPE, FNAME, GRIDBASE, ...) \
421 UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
422 else UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
423 else UTvdbCallBoolType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
424 /**/
425//@}
426
427//@{
428/// Macro to invoke the correct type of grid.
429/// Use like:
430/// @code
431/// UTvdbReturnScalarType(grid_type, myfunction, grid, parms)
432/// @endcode
433/// to invoke
434/// @code
435/// return myfunction(grid, parms);
436/// @endcode
437/// via:
438/// @code
439/// template <typename GridType>
440/// static RESULT
441/// myfunction(const GridType &grid, parms)
442/// { }
443/// @endcode
444
445#define UTvdbReturnRealType(TYPE, FNAME, GRIDBASE, ...) \
446 if (TYPE == UT_VDB_FLOAT) \
447 UT_VDB_CALL(openvdb::FloatGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
448 else if (TYPE == UT_VDB_DOUBLE) \
449 UT_VDB_CALL(openvdb::DoubleGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
450 /**/
451#define UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, ...) \
452 UTvdbReturnRealType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
453 else if (TYPE == UT_VDB_INT32) \
454 UT_VDB_CALL(openvdb::Int32Grid,return,FNAME,GRIDBASE,__VA_ARGS__) \
455 else if (TYPE == UT_VDB_INT64) \
456 UT_VDB_CALL(openvdb::Int64Grid,return,FNAME,GRIDBASE,__VA_ARGS__) \
457 /**/
458#define UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, ...) \
459 if (TYPE == UT_VDB_VEC3F) \
460 UT_VDB_CALL(openvdb::Vec3fGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
461 else if (TYPE == UT_VDB_VEC3D) \
462 UT_VDB_CALL(openvdb::Vec3dGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
463 else if (TYPE == UT_VDB_VEC3I) \
464 UT_VDB_CALL(openvdb::Vec3IGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
465 /**/
466#define UTvdbReturnPointType(TYPE, FNAME, GRIDBASE, ...) \
467 if (TYPE == UT_VDB_POINTINDEX) \
468 UT_VDB_CALL(openvdb::tools::PointIndexGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
469 else if (TYPE == UT_VDB_POINTDATA) \
470 UT_VDB_CALL(openvdb::points::PointDataGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
471 /**/
472#define UTvdbReturnBoolType(TYPE, FNAME, GRIDBASE, ...) \
473 if (TYPE == UT_VDB_BOOL) \
474 UT_VDB_CALL(openvdb::BoolGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
475 /**/
476#define UTvdbReturnAllType(TYPE, FNAME, GRIDBASE, ...) \
477 UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
478 else UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__); \
479 /**/
480#define UTvdbReturnAllTopology(TYPE, FNAME, GRIDBASE, ...) \
481 UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
482 else UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
483 else UTvdbReturnBoolType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
484 /**/
485//@}
486
487
488////////////////////////////////////////
489
490
491/// Matrix conversion from openvdb to UT
492// @{
493template <typename S>
494UT_Matrix4T<S>
495UTvdbConvert(const openvdb::math::Mat4<S> &src)
496{
497 return UT_Matrix4T<S>(src(0,0), src(0,1), src(0,2), src(0,3),
498 src(1,0), src(1,1), src(1,2), src(1,3),
499 src(2,0), src(2,1), src(2,2), src(2,3),
500 src(3,0), src(3,1), src(3,2), src(3,3));
501}
502
503template <typename S>
504UT_Matrix3T<S>
505UTvdbConvert(const openvdb::math::Mat3<S> &src)
506{
507 return UT_Matrix3T<S>(src(0,0), src(0,1), src(0,2),
508 src(1,0), src(1,1), src(1,2),
509 src(2,0), src(2,1), src(2,2));
510}
511
512template <typename S>
513UT_Matrix2T<S>
514UTvdbConvert(const openvdb::math::Mat2<S> &src)
515{
516 return UT_Matrix2T<S>(src(0,0), src(0,1),
517 src(1,0), src(1,1));
518}
519// @}
520
521/// Matrix conversion from UT to openvdb
522// @{
523template <typename S>
524openvdb::math::Mat4<S>
525UTvdbConvert(const UT_Matrix4T<S> &src)
526{
527 return openvdb::math::Mat4<S>(src(0,0), src(0,1), src(0,2), src(0,3),
528 src(1,0), src(1,1), src(1,2), src(1,3),
529 src(2,0), src(2,1), src(2,2), src(2,3),
530 src(3,0), src(3,1), src(3,2), src(3,3));
531}
532template <typename S>
533openvdb::math::Mat3<S>
534UTvdbConvert(const UT_Matrix3T<S> &src)
535{
536 return openvdb::math::Mat3<S>(src(0,0), src(0,1), src(0,2),
537 src(1,0), src(1,1), src(1,2),
538 src(2,0), src(2,1), src(2,2));
539}
540template <typename S>
541openvdb::math::Mat2<S>
542UTvdbConvert(const UT_Matrix2T<S> &src)
543{
544 return openvdb::math::Mat2<S>(src(0,0), src(0,1),
545 src(1,0), src(1,1));
546}
547// @}
548
549/// Vector conversion from openvdb to UT
550// @{
551template <typename S>
552UT_Vector4T<S>
553UTvdbConvert(const openvdb::math::Vec4<S> &src)
554{
555 return UT_Vector4T<S>(src.asPointer());
556}
557template <typename S>
558UT_Vector3T<S>
559UTvdbConvert(const openvdb::math::Vec3<S> &src)
560{
561 return UT_Vector3T<S>(src.asPointer());
562}
563template <typename S>
564UT_Vector2T<S>
565UTvdbConvert(const openvdb::math::Vec2<S> &src)
566{
567 return UT_Vector2T<S>(src.asPointer());
568}
569// @}
570
571/// Vector conversion from UT to openvdb
572// @{
573template <typename S>
574openvdb::math::Vec4<S>
575UTvdbConvert(const UT_Vector4T<S> &src)
576{
577 return openvdb::math::Vec4<S>(src.data());
578}
579template <typename S>
580openvdb::math::Vec3<S>
581UTvdbConvert(const UT_Vector3T<S> &src)
582{
583 return openvdb::math::Vec3<S>(src.data());
584}
585template <typename S>
586openvdb::math::Vec2<S>
587UTvdbConvert(const UT_Vector2T<S> &src)
588{
589 return openvdb::math::Vec2<S>(src.data());
590}
591// @}
592
593
594/// Bounding box conversion from openvdb to UT
595inline UT_BoundingBoxD
596UTvdbConvert(const openvdb::CoordBBox &bbox)
597{
598 return UT_BoundingBoxD(UTvdbConvert(bbox.getStart().asVec3d()),
599 UTvdbConvert(bbox.getEnd().asVec3d()));
600}
601
602/// Bounding box conversion from openvdb to UT
603inline openvdb::math::CoordBBox
604UTvdbConvert(const UT_BoundingBoxI &bbox)
605{
606 return openvdb::math::CoordBBox(
607 openvdb::math::Coord(bbox.xmin(), bbox.ymin(), bbox.zmin()),
608 openvdb::math::Coord(bbox.xmax(), bbox.ymax(), bbox.zmax()));
609}
610
611/// Utility method to construct a Transform that lines up with a
612/// cell-centered Houdini volume with specified origin and voxel size.
613inline openvdb::math::Transform::Ptr
614UTvdbCreateTransform(const UT_Vector3 &orig, const UT_Vector3 &voxsize)
615{
616 // Transforms only valid for square voxels.
617 UT_ASSERT(SYSalmostEqual(voxsize.minComponent(), voxsize.maxComponent()));
618 fpreal vs = voxsize.maxComponent();
619 openvdb::math::Transform::Ptr xform =
620 openvdb::math::Transform::createLinearTransform(vs);
621 // Ensure voxel centers line up.
622 xform->postTranslate(UTvdbConvert(orig) + vs / 2);
623 return xform;
624}
625
626template <typename T>
627inline openvdb::math::Vec4<T> SYSabs(const openvdb::math::Vec4<T> &v1)
628{ return openvdb::math::Vec4<T>( SYSabs(v1[0]),
629 SYSabs(v1[1]),
630 SYSabs(v1[2]),
631 SYSabs(v1[3])
632 );
633}
634template <typename T>
635inline openvdb::math::Vec3<T> SYSabs(const openvdb::math::Vec3<T> &v1)
636{ return openvdb::math::Vec3<T>( SYSabs(v1[0]),
637 SYSabs(v1[1]),
638 SYSabs(v1[2])
639 );
640}
641template <typename T>
642inline openvdb::math::Vec2<T> SYSabs(const openvdb::math::Vec2<T> &v1)
643{ return openvdb::math::Vec2<T>( SYSabs(v1[0]),
644 SYSabs(v1[1])
645 );
646}
647
648template <typename T>
649inline openvdb::math::Vec4<T> SYSmin(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2)
650{ return openvdb::math::Vec4<T>( SYSmin(v1[0], v2[0]),
651 SYSmin(v1[1], v2[1]),
652 SYSmin(v1[2], v2[2]),
653 SYSmin(v1[3], v2[3])
654 );
655}
656template <typename T>
657inline openvdb::math::Vec4<T> SYSmax(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2)
658{ return openvdb::math::Vec4<T>( SYSmax(v1[0], v2[0]),
659 SYSmax(v1[1], v2[1]),
660 SYSmax(v1[2], v2[2]),
661 SYSmax(v1[3], v2[3])
662 );
663}
664template <typename T>
665inline openvdb::math::Vec4<T> SYSmin(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2, const openvdb::math::Vec4<T> &v3)
666{ return openvdb::math::Vec4<T>( SYSmin(v1[0], v2[0], v3[0]),
667 SYSmin(v1[1], v2[1], v3[1]),
668 SYSmin(v1[2], v2[2], v3[2]),
669 SYSmin(v1[3], v2[3], v3[3])
670 );
671}
672template <typename T>
673inline openvdb::math::Vec4<T> SYSmax(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2, const openvdb::math::Vec4<T> &v3)
674{ return openvdb::math::Vec4<T>( SYSmax(v1[0], v2[0], v3[0]),
675 SYSmax(v1[1], v2[1], v3[1]),
676 SYSmax(v1[2], v2[2], v3[2]),
677 SYSmax(v1[3], v2[3], v3[3])
678 );
679}
680template <typename T>
681inline openvdb::math::Vec3<T> SYSmin(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2)
682{ return openvdb::math::Vec3<T>( SYSmin(v1[0], v2[0]),
683 SYSmin(v1[1], v2[1]),
684 SYSmin(v1[2], v2[2])
685 );
686}
687template <typename T>
688inline openvdb::math::Vec3<T> SYSmax(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2)
689{ return openvdb::math::Vec3<T>( SYSmax(v1[0], v2[0]),
690 SYSmax(v1[1], v2[1]),
691 SYSmax(v1[2], v2[2])
692 );
693}
694template <typename T>
695inline openvdb::math::Vec3<T> SYSmin(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2, const openvdb::math::Vec3<T> &v3)
696{ return openvdb::math::Vec3<T>( SYSmin(v1[0], v2[0], v3[0]),
697 SYSmin(v1[1], v2[1], v3[1]),
698 SYSmin(v1[2], v2[2], v3[2])
699 );
700}
701template <typename T>
702inline openvdb::math::Vec3<T> SYSmax(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2, const openvdb::math::Vec3<T> &v3)
703{ return openvdb::math::Vec3<T>( SYSmax(v1[0], v2[0], v3[0]),
704 SYSmax(v1[1], v2[1], v3[1]),
705 SYSmax(v1[2], v2[2], v3[2])
706 );
707}
708template <typename T>
709inline openvdb::math::Vec2<T> SYSmin(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2)
710{ return openvdb::math::Vec2<T>( SYSmin(v1[0], v2[0]),
711 SYSmin(v1[1], v2[1])
712 );
713}
714template <typename T>
715inline openvdb::math::Vec2<T> SYSmax(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2)
716{ return openvdb::math::Vec2<T>( SYSmax(v1[0], v2[0]),
717 SYSmax(v1[1], v2[1])
718 );
719}
720template <typename T>
721inline openvdb::math::Vec2<T> SYSmin(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2, const openvdb::math::Vec2<T> &v3)
722{ return openvdb::math::Vec2<T>( SYSmin(v1[0], v2[0], v3[0]),
723 SYSmin(v1[1], v2[1], v3[1])
724 );
725}
726template <typename T>
727inline openvdb::math::Vec2<T> SYSmax(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2, const openvdb::math::Vec2<T> &v3)
728{ return openvdb::math::Vec2<T>( SYSmax(v1[0], v2[0], v3[0]),
729 SYSmax(v1[1], v2[1], v3[1])
730 );
731}
732
733#endif // __HDK_UT_VDBUtils__
734
735#endif // SESI_OPENVDB || SESI_OPENVDB_PRIM
PointDataGrid.h
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
PointIndexGrid.h
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
openvdb::v12_1::GridBase
Abstract base class for typed grids.
Definition Grid.h:78
openvdb::v12_1::GridBase::isType
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition Grid.h:146
openvdb::v12_1::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
openvdb::v12_1::math::CoordBBox::getStart
Coord getStart() const
Return the minimum coordinate.
Definition Coord.h:336
openvdb::v12_1::math::CoordBBox::getEnd
Coord getEnd() const
Return the maximum coordinate plus one.
Definition Coord.h:339
openvdb::v12_1::math::Coord::asVec3d
Vec3d asVec3d() const
Definition Coord.h:144
nanovdb::GridType
GridType
List of types that are currently supported by NanoVDB.
Definition NanoVDB.h:220
openvdb::v12_1::points
Definition AttributeArray.h:42
openvdb::v12_1::tools
Definition Activate.h:25
openvdb::v12_1::tools::bool
OutGridT const XformOp bool bool
Definition ValueTransformer.h:610
openvdb::v12_1::tools::op
OutGridT XformOp & op
Definition ValueTransformer.h:140
openvdb::v12_1::Vec3dGrid
Vec3DGrid Vec3dGrid
Definition openvdb.h:84
openvdb::v12_1::FloatGrid
Grid< FloatTree > FloatGrid
Definition openvdb.h:75
openvdb::v12_1::gridConstPtrCast
GridType::ConstPtr gridConstPtrCast(const GridBase::ConstPtr &grid)
Cast a generic const grid pointer to a const pointer to a grid of a concrete class.
Definition Grid.h:1018
openvdb::v12_1::BoolGrid
Grid< BoolTree > BoolGrid
Common grid types.
Definition openvdb.h:73
openvdb::v12_1::gridPtrCast
GridType::Ptr gridPtrCast(const GridBase::Ptr &grid)
Cast a generic grid pointer to a pointer to a grid of a concrete class.
Definition Grid.h:1002
openvdb::v12_1::Vec3fGrid
Vec3SGrid Vec3fGrid
Definition openvdb.h:85
openvdb::v12_1::initialize
OPENVDB_IMPORT void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types....
openvdb::v12_1::Vec3IGrid
Grid< Vec3ITree > Vec3IGrid
Definition openvdb.h:80
openvdb::v12_1::Int64Grid
Grid< Int64Tree > Int64Grid
Definition openvdb.h:77
openvdb::v12_1::Int32Grid
Grid< Int32Tree > Int32Grid
Definition openvdb.h:76
openvdb::v12_1::DoubleGrid
Grid< DoubleTree > DoubleGrid
Definition openvdb.h:74
openvdb
Definition Exceptions.h:13
openvdb.h