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