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  op.template operator()<GridType>(UTvdbGridCast<GridType>(grid));
202 }
203 
204 } // namespace UT_VDBUtils
205 
206 ////////////////////////////////////////
207 
208 
209 /// @brief Utility function that, given a generic grid pointer,
210 /// calls a functor on the fully-resolved grid
211 ///
212 /// @par Example:
213 /// @code
214 /// using openvdb::Coord;
215 /// using openvdb::CoordBBox;
216 ///
217 /// struct FillOp {
218 /// const CoordBBox bbox;
219 ///
220 /// FillOp(const CoordBBox& b): bbox(b) {}
221 ///
222 /// template<typename GridT>
223 /// void operator()(GridT& grid) const {
224 /// using ValueT = typename GridT::ValueType;
225 /// grid.fill(bbox, ValueT(1));
226 /// }
227 /// };
228 ///
229 /// GU_PrimVDB* vdb = ...;
230 /// vdb->makeGridUnique();
231 /// CoordBBox bbox(Coord(0,0,0), Coord(10,10,10));
232 /// UTvdbProcessTypedGrid(vdb->getStorageType(), vdb->getGrid(), FillOp(bbox));
233 /// @endcode
234 ///
235 /// @return @c false if the grid type is unknown or unhandled.
236 /// @{
237 #define UT_VDB_DECL_PROCESS_TYPED_GRID(GRID_BASE_T) \
238 template<typename OpType> \
239 inline bool \
240 UTvdbProcessTypedGrid(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
241 { \
242  using namespace openvdb; \
243  using namespace UT_VDBUtils; \
244  switch (grid_type) \
245  { \
246  case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
247  case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
248  case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
249  case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
250  case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
251  case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
252  case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
253  default: return false; \
254  } \
255  return true; \
256 } \
257 template<typename OpType> \
258 inline bool \
259 UTvdbProcessTypedGridTopology(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
260 { \
261  using namespace openvdb; \
262  using namespace UT_VDBUtils; \
263  switch (grid_type) \
264  { \
265  case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
266  case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
267  case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
268  case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
269  case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
270  case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
271  case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
272  case UT_VDB_BOOL: callTypedGrid<BoolGrid>(grid, op); break; \
273  default: return false; \
274  } \
275  return true; \
276 } \
277 template<typename OpType> \
278 inline bool \
279 UTvdbProcessTypedGridVec3(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
280 { \
281  using namespace openvdb; \
282  using namespace UT_VDBUtils; \
283  switch (grid_type) \
284  { \
285  case UT_VDB_VEC3F: callTypedGrid<Vec3SGrid>(grid, op); break; \
286  case UT_VDB_VEC3D: callTypedGrid<Vec3DGrid>(grid, op); break; \
287  case UT_VDB_VEC3I: callTypedGrid<Vec3IGrid>(grid, op); break; \
288  default: return false; \
289  } \
290  return true; \
291 } \
292 template<typename OpType> \
293 inline bool \
294 UTvdbProcessTypedGridScalar(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_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
301  case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
302  case UT_VDB_INT32: callTypedGrid<Int32Grid>(grid, op); break; \
303  case UT_VDB_INT64: callTypedGrid<Int64Grid>(grid, op); break; \
304  default: return false; \
305  } \
306  return true; \
307 } \
308 template<typename OpType> \
309 inline bool \
310 UTvdbProcessTypedGridReal(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
311 { \
312  using namespace openvdb; \
313  using namespace UT_VDBUtils; \
314  switch (grid_type) \
315  { \
316  case UT_VDB_FLOAT: callTypedGrid<FloatGrid>(grid, op); break; \
317  case UT_VDB_DOUBLE: callTypedGrid<DoubleGrid>(grid, op); break; \
318  default: return false; \
319  } \
320  return true; \
321 } \
322 template<typename OpType> \
323 inline bool \
324 UTvdbProcessTypedGridPoint(UT_VDBType grid_type, GRID_BASE_T grid, OpType& op) \
325 { \
326  using namespace openvdb; \
327  using namespace openvdb::tools; \
328  using namespace openvdb::points; \
329  using namespace UT_VDBUtils; \
330  switch (grid_type) \
331  { \
332  case UT_VDB_POINTINDEX: callTypedGrid<PointIndexGrid>(grid, op); break; \
333  case UT_VDB_POINTDATA: callTypedGrid<PointDataGrid>(grid, op); break; \
334  default: return false; \
335  } \
336  return true; \
337 } \
338 /**/
339 UT_VDB_DECL_PROCESS_TYPED_GRID(const openvdb::GridBase &)
340 UT_VDB_DECL_PROCESS_TYPED_GRID(const openvdb::GridBase *)
341 UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase::ConstPtr)
342 UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase &)
343 UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase *)
344 UT_VDB_DECL_PROCESS_TYPED_GRID(openvdb::GridBase::Ptr)
345 
346 /// @}
347 
348 
349 // Helper macro for UTvdbCall* macros, do not outside of this file!
350 #define UT_VDB_CALL(GRIDT, RETURN, FNAME, GRIDBASE, ...) \
351  { \
352  RETURN FNAME <GRIDT> (UTvdbGridCast<GRIDT>(GRIDBASE), __VA_ARGS__ ); \
353  } \
354  /**/
355 
356 //@{
357 /// Macro to invoke the correct type of grid.
358 /// Use like:
359 /// @code
360 /// UTvdbCallScalarType(grid_type, myfunction, grid, parms)
361 /// @endcode
362 /// to invoke
363 /// @code
364 /// template <typename GridType>
365 /// static void
366 /// myfunction(const GridType &grid, parms)
367 /// { }
368 /// @endcode
369 
370 #define UTvdbCallRealType(TYPE, FNAME, GRIDBASE, ...) \
371  if (TYPE == UT_VDB_FLOAT) \
372  UT_VDB_CALL(openvdb::FloatGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
373  else if (TYPE == UT_VDB_DOUBLE) \
374  UT_VDB_CALL(openvdb::DoubleGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
375  /**/
376 #define UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, ...) \
377  UTvdbCallRealType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
378  else if (TYPE == UT_VDB_INT32) \
379  UT_VDB_CALL(openvdb::Int32Grid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
380  else if (TYPE == UT_VDB_INT64) \
381  UT_VDB_CALL(openvdb::Int64Grid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
382  /**/
383 #define UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, ...) \
384  if (TYPE == UT_VDB_VEC3F) \
385  UT_VDB_CALL(openvdb::Vec3fGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
386  else if (TYPE == UT_VDB_VEC3D) \
387  UT_VDB_CALL(openvdb::Vec3dGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
388  else if (TYPE == UT_VDB_VEC3I) \
389  UT_VDB_CALL(openvdb::Vec3IGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
390  /**/
391 #define UTvdbCallPointType(TYPE, FNAME, GRIDBASE, ...) \
392  if (TYPE == UT_VDB_POINTINDEX) \
393  UT_VDB_CALL(openvdb::tools::PointIndexGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
394  else if (TYPE == UT_VDB_POINTDATA) \
395  UT_VDB_CALL(openvdb::points::PointDataGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
396  /**/
397 #define UTvdbCallBoolType(TYPE, FNAME, GRIDBASE, ...) \
398  if (TYPE == UT_VDB_BOOL) \
399  UT_VDB_CALL(openvdb::BoolGrid,(void),FNAME,GRIDBASE,__VA_ARGS__) \
400  /**/
401 #define UTvdbCallAllType(TYPE, FNAME, GRIDBASE, ...) \
402  UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
403  else UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__); \
404  /**/
405 #define UTvdbCallAllTopology(TYPE, FNAME, GRIDBASE, ...) \
406  UTvdbCallScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
407  else UTvdbCallVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
408  else UTvdbCallBoolType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
409  /**/
410 //@}
411 
412 //@{
413 /// Macro to invoke the correct type of grid.
414 /// Use like:
415 /// @code
416 /// UTvdbReturnScalarType(grid_type, myfunction, grid, parms)
417 /// @endcode
418 /// to invoke
419 /// @code
420 /// return myfunction(grid, parms);
421 /// @endcode
422 /// via:
423 /// @code
424 /// template <typename GridType>
425 /// static RESULT
426 /// myfunction(const GridType &grid, parms)
427 /// { }
428 /// @endcode
429 
430 #define UTvdbReturnRealType(TYPE, FNAME, GRIDBASE, ...) \
431  if (TYPE == UT_VDB_FLOAT) \
432  UT_VDB_CALL(openvdb::FloatGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
433  else if (TYPE == UT_VDB_DOUBLE) \
434  UT_VDB_CALL(openvdb::DoubleGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
435  /**/
436 #define UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, ...) \
437  UTvdbReturnRealType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
438  else if (TYPE == UT_VDB_INT32) \
439  UT_VDB_CALL(openvdb::Int32Grid,return,FNAME,GRIDBASE,__VA_ARGS__) \
440  else if (TYPE == UT_VDB_INT64) \
441  UT_VDB_CALL(openvdb::Int64Grid,return,FNAME,GRIDBASE,__VA_ARGS__) \
442  /**/
443 #define UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, ...) \
444  if (TYPE == UT_VDB_VEC3F) \
445  UT_VDB_CALL(openvdb::Vec3fGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
446  else if (TYPE == UT_VDB_VEC3D) \
447  UT_VDB_CALL(openvdb::Vec3dGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
448  else if (TYPE == UT_VDB_VEC3I) \
449  UT_VDB_CALL(openvdb::Vec3IGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
450  /**/
451 #define UTvdbReturnPointType(TYPE, FNAME, GRIDBASE, ...) \
452  if (TYPE == UT_VDB_POINTINDEX) \
453  UT_VDB_CALL(openvdb::tools::PointIndexGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
454  else if (TYPE == UT_VDB_POINTDATA) \
455  UT_VDB_CALL(openvdb::points::PointDataGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
456  /**/
457 #define UTvdbReturnBoolType(TYPE, FNAME, GRIDBASE, ...) \
458  if (TYPE == UT_VDB_BOOL) \
459  UT_VDB_CALL(openvdb::BoolGrid,return,FNAME,GRIDBASE,__VA_ARGS__) \
460  /**/
461 #define UTvdbReturnAllType(TYPE, FNAME, GRIDBASE, ...) \
462  UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
463  else UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__); \
464  /**/
465 #define UTvdbReturnAllTopology(TYPE, FNAME, GRIDBASE, ...) \
466  UTvdbReturnScalarType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
467  else UTvdbReturnVec3Type(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
468  else UTvdbReturnBoolType(TYPE, FNAME, GRIDBASE, __VA_ARGS__) \
469  /**/
470 //@}
471 
472 
473 ////////////////////////////////////////
474 
475 
476 /// Matrix conversion from openvdb to UT
477 // @{
478 template <typename S>
480 UTvdbConvert(const openvdb::math::Mat4<S> &src)
481 {
482  return UT_Matrix4T<S>(src(0,0), src(0,1), src(0,2), src(0,3),
483  src(1,0), src(1,1), src(1,2), src(1,3),
484  src(2,0), src(2,1), src(2,2), src(2,3),
485  src(3,0), src(3,1), src(3,2), src(3,3));
486 }
487 
488 template <typename S>
490 UTvdbConvert(const openvdb::math::Mat3<S> &src)
491 {
492  return UT_Matrix3T<S>(src(0,0), src(0,1), src(0,2),
493  src(1,0), src(1,1), src(1,2),
494  src(2,0), src(2,1), src(2,2));
495 }
496 
497 template <typename S>
499 UTvdbConvert(const openvdb::math::Mat2<S> &src)
500 {
501  return UT_Matrix2T<S>(src(0,0), src(0,1),
502  src(1,0), src(1,1));
503 }
504 // @}
505 
506 /// Matrix conversion from UT to openvdb
507 // @{
508 template <typename S>
509 openvdb::math::Mat4<S>
511 {
512  return openvdb::math::Mat4<S>(src(0,0), src(0,1), src(0,2), src(0,3),
513  src(1,0), src(1,1), src(1,2), src(1,3),
514  src(2,0), src(2,1), src(2,2), src(2,3),
515  src(3,0), src(3,1), src(3,2), src(3,3));
516 }
517 template <typename S>
518 openvdb::math::Mat3<S>
520 {
521  return openvdb::math::Mat3<S>(src(0,0), src(0,1), src(0,2),
522  src(1,0), src(1,1), src(1,2),
523  src(2,0), src(2,1), src(2,2));
524 }
525 template <typename S>
526 openvdb::math::Mat2<S>
528 {
529  return openvdb::math::Mat2<S>(src(0,0), src(0,1),
530  src(1,0), src(1,1));
531 }
532 // @}
533 
534 /// Vector conversion from openvdb to UT
535 // @{
536 template <typename S>
538 UTvdbConvert(const openvdb::math::Vec4<S> &src)
539 {
540  return UT_Vector4T<S>(src.asPointer());
541 }
542 template <typename S>
544 UTvdbConvert(const openvdb::math::Vec3<S> &src)
545 {
546  return UT_Vector3T<S>(src.asPointer());
547 }
548 template <typename S>
550 UTvdbConvert(const openvdb::math::Vec2<S> &src)
551 {
552  return UT_Vector2T<S>(src.asPointer());
553 }
554 // @}
555 
556 /// Vector conversion from UT to openvdb
557 // @{
558 template <typename S>
559 openvdb::math::Vec4<S>
561 {
562  return openvdb::math::Vec4<S>(src.data());
563 }
564 template <typename S>
565 openvdb::math::Vec3<S>
567 {
568  return openvdb::math::Vec3<S>(src.data());
569 }
570 template <typename S>
571 openvdb::math::Vec2<S>
573 {
574  return openvdb::math::Vec2<S>(src.data());
575 }
576 // @}
577 
578 
579 /// Bounding box conversion from openvdb to UT
580 inline UT_BoundingBoxD
582 {
583  return UT_BoundingBoxD(UTvdbConvert(bbox.getStart().asVec3d()),
584  UTvdbConvert(bbox.getEnd().asVec3d()));
585 }
586 
587 /// Bounding box conversion from openvdb to UT
590 {
592  openvdb::math::Coord(bbox.xmin(), bbox.ymin(), bbox.zmin()),
593  openvdb::math::Coord(bbox.xmax(), bbox.ymax(), bbox.zmax()));
594 }
595 
596 /// Utility method to construct a Transform that lines up with a
597 /// cell-centered Houdini volume with specified origin and voxel size.
598 inline openvdb::math::Transform::Ptr
599 UTvdbCreateTransform(const UT_Vector3 &orig, const UT_Vector3 &voxsize)
600 {
601  // Transforms only valid for square voxels.
602  UT_ASSERT(SYSalmostEqual(voxsize.minComponent(), voxsize.maxComponent()));
603  fpreal vs = voxsize.maxComponent();
604  openvdb::math::Transform::Ptr xform =
605  openvdb::math::Transform::createLinearTransform(vs);
606  // Ensure voxel centers line up.
607  xform->postTranslate(UTvdbConvert(orig) + vs / 2);
608  return xform;
609 }
610 
611 template <typename T>
612 inline openvdb::math::Vec4<T> SYSabs(const openvdb::math::Vec4<T> &v1)
613 { return openvdb::math::Vec4<T>( SYSabs(v1[0]),
614  SYSabs(v1[1]),
615  SYSabs(v1[2]),
616  SYSabs(v1[3])
617  );
618 }
619 template <typename T>
620 inline openvdb::math::Vec3<T> SYSabs(const openvdb::math::Vec3<T> &v1)
621 { return openvdb::math::Vec3<T>( SYSabs(v1[0]),
622  SYSabs(v1[1]),
623  SYSabs(v1[2])
624  );
625 }
626 template <typename T>
627 inline openvdb::math::Vec2<T> SYSabs(const openvdb::math::Vec2<T> &v1)
628 { return openvdb::math::Vec2<T>( SYSabs(v1[0]),
629  SYSabs(v1[1])
630  );
631 }
632 
633 template <typename T>
634 inline openvdb::math::Vec4<T> SYSmin(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2)
635 { return openvdb::math::Vec4<T>( SYSmin(v1[0], v2[0]),
636  SYSmin(v1[1], v2[1]),
637  SYSmin(v1[2], v2[2]),
638  SYSmin(v1[3], v2[3])
639  );
640 }
641 template <typename T>
642 inline openvdb::math::Vec4<T> SYSmax(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2)
643 { return openvdb::math::Vec4<T>( SYSmax(v1[0], v2[0]),
644  SYSmax(v1[1], v2[1]),
645  SYSmax(v1[2], v2[2]),
646  SYSmax(v1[3], v2[3])
647  );
648 }
649 template <typename T>
650 inline openvdb::math::Vec4<T> SYSmin(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2, const openvdb::math::Vec4<T> &v3)
651 { return openvdb::math::Vec4<T>( SYSmin(v1[0], v2[0], v3[0]),
652  SYSmin(v1[1], v2[1], v3[1]),
653  SYSmin(v1[2], v2[2], v3[2]),
654  SYSmin(v1[3], v2[3], v3[3])
655  );
656 }
657 template <typename T>
658 inline openvdb::math::Vec4<T> SYSmax(const openvdb::math::Vec4<T> &v1, const openvdb::math::Vec4<T> &v2, const openvdb::math::Vec4<T> &v3)
659 { return openvdb::math::Vec4<T>( SYSmax(v1[0], v2[0], v3[0]),
660  SYSmax(v1[1], v2[1], v3[1]),
661  SYSmax(v1[2], v2[2], v3[2]),
662  SYSmax(v1[3], v2[3], v3[3])
663  );
664 }
665 template <typename T>
666 inline openvdb::math::Vec3<T> SYSmin(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2)
667 { return openvdb::math::Vec3<T>( SYSmin(v1[0], v2[0]),
668  SYSmin(v1[1], v2[1]),
669  SYSmin(v1[2], v2[2])
670  );
671 }
672 template <typename T>
673 inline openvdb::math::Vec3<T> SYSmax(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2)
674 { return openvdb::math::Vec3<T>( SYSmax(v1[0], v2[0]),
675  SYSmax(v1[1], v2[1]),
676  SYSmax(v1[2], v2[2])
677  );
678 }
679 template <typename T>
680 inline openvdb::math::Vec3<T> SYSmin(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2, const openvdb::math::Vec3<T> &v3)
681 { return openvdb::math::Vec3<T>( SYSmin(v1[0], v2[0], v3[0]),
682  SYSmin(v1[1], v2[1], v3[1]),
683  SYSmin(v1[2], v2[2], v3[2])
684  );
685 }
686 template <typename T>
687 inline openvdb::math::Vec3<T> SYSmax(const openvdb::math::Vec3<T> &v1, const openvdb::math::Vec3<T> &v2, const openvdb::math::Vec3<T> &v3)
688 { return openvdb::math::Vec3<T>( SYSmax(v1[0], v2[0], v3[0]),
689  SYSmax(v1[1], v2[1], v3[1]),
690  SYSmax(v1[2], v2[2], v3[2])
691  );
692 }
693 template <typename T>
694 inline openvdb::math::Vec2<T> SYSmin(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2)
695 { return openvdb::math::Vec2<T>( SYSmin(v1[0], v2[0]),
696  SYSmin(v1[1], v2[1])
697  );
698 }
699 template <typename T>
700 inline openvdb::math::Vec2<T> SYSmax(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2)
701 { return openvdb::math::Vec2<T>( SYSmax(v1[0], v2[0]),
702  SYSmax(v1[1], v2[1])
703  );
704 }
705 template <typename T>
706 inline openvdb::math::Vec2<T> SYSmin(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2, const openvdb::math::Vec2<T> &v3)
707 { return openvdb::math::Vec2<T>( SYSmin(v1[0], v2[0], v3[0]),
708  SYSmin(v1[1], v2[1], v3[1])
709  );
710 }
711 template <typename T>
712 inline openvdb::math::Vec2<T> SYSmax(const openvdb::math::Vec2<T> &v1, const openvdb::math::Vec2<T> &v2, const openvdb::math::Vec2<T> &v3)
713 { return openvdb::math::Vec2<T>( SYSmax(v1[0], v2[0], v3[0]),
714  SYSmax(v1[1], v2[1], v3[1])
715  );
716 }
717 
718 #endif // __UT_VDBUtils__
static void plusEqual(bool &lhs, const bool &rhs)
Definition: UT_VDBUtils.h:152
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:294
Grid< Vec3fTree > Vec3fGrid
Definition: NanoVDB.h:6498
UT_VDBType UTvdbGetGridType(const openvdb::GridBase &grid)
Find the UT_VDBType from a grid.
Definition: UT_VDBUtils.h:43
Grid< DoubleTree > DoubleGrid
Definition: NanoVDB.h:6494
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:229
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:818
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:819
4D Vector class.
Definition: UT_Vector4.h:174
UT_BoundingBoxT< fpreal64 > UT_BoundingBoxD
Definition: HUSD_Info.h:35
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector3.h:292
openvdb::math::Vec4< T > SYSabs(const openvdb::math::Vec4< T > &v1)
Definition: UT_VDBUtils.h:612
openvdb::math::Vec4< T > SYSmax(const openvdb::math::Vec4< T > &v1, const openvdb::math::Vec4< T > &v2)
Definition: UT_VDBUtils.h:642
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
Definition: UT_Vector3.h:413
#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:237
Grid< Int64Tree > Int64Grid
Definition: NanoVDB.h:6497
Grid< FloatTree > FloatGrid
Definition: NanoVDB.h:6489
openvdb::math::Transform::Ptr UTvdbCreateTransform(const UT_Vector3 &orig, const UT_Vector3 &voxsize)
Definition: UT_VDBUtils.h:599
Grid< Vec3ITree > Vec3IGrid
Definition: NanoVDB.h:6502
static void plusEqual(T &lhs, const T &rhs)
Definition: UT_VDBUtils.h:146
BBox< Coord > CoordBBox
Definition: NanoVDB.h:2516
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.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector2.h:217
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
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
fpreal64 fpreal
Definition: SYS_Types.h:277
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector4.h:224
GLfloat GLfloat v1
Definition: glcorearb.h:817
Grid< BoolTree > BoolGrid
Definition: NanoVDB.h:6504
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Grid< Vec3dTree > Vec3dGrid
Definition: NanoVDB.h:6499
openvdb::math::Vec4< T > SYSmin(const openvdb::math::Vec4< T > &v1, const openvdb::math::Vec4< T > &v2)
Definition: UT_VDBUtils.h:634
constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
Definition: UT_Vector3.h:408
type
Definition: core.h:1059
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:480
Grid< Int32Tree > Int32Grid
Definition: NanoVDB.h:6495
GLenum src
Definition: glcorearb.h:1793