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