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