HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Types.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 #ifndef OPENVDB_TYPES_HAS_BEEN_INCLUDED
5 #define OPENVDB_TYPES_HAS_BEEN_INCLUDED
6 
7 #include "version.h"
8 #include "Platform.h"
9 #include "TypeList.h" // backwards compat
10 
11 #ifdef OPENVDB_USE_IMATH_HALF
12 #ifdef OPENVDB_IMATH_VERSION
13 #include <Imath/half.h>
14 #else
15 #include <OpenEXR/half.h>
16 #endif
17 namespace openvdb {
19 namespace OPENVDB_VERSION_NAME {
20 namespace math {
21 using half = half;
22 }}}
23 #else
24 #include <openvdb/math/Half.h>
25 namespace openvdb {
27 namespace OPENVDB_VERSION_NAME {
28 namespace math {
30 }}}
31 #endif
32 
33 #include <openvdb/math/Math.h>
34 #include <openvdb/math/BBox.h>
35 #include <openvdb/math/Quat.h>
36 #include <openvdb/math/Vec2.h>
37 #include <openvdb/math/Vec3.h>
38 #include <openvdb/math/Vec4.h>
39 #include <openvdb/math/Mat3.h>
40 #include <openvdb/math/Mat4.h>
41 #include <openvdb/math/Coord.h>
42 #include <cstdint>
43 #include <memory>
44 #include <type_traits>
45 
46 
47 namespace openvdb {
49 namespace OPENVDB_VERSION_NAME {
50 
51 // One-dimensional scalar types
52 using Index32 = uint32_t;
53 using Index64 = uint64_t;
54 using Index = Index32;
55 using Int16 = int16_t;
56 using Int32 = int32_t;
57 using Int64 = int64_t;
58 using Int = Int32;
59 using Byte = unsigned char;
60 using Real = double;
61 
62 // Two-dimensional vector types
67 using math::Vec2i;
68 using math::Vec2s;
69 using math::Vec2d;
70 
71 // Three-dimensional vector types
78 using math::Vec3i;
79 using math::Vec3s;
80 using math::Vec3d;
81 
82 using math::Coord;
83 using math::CoordBBox;
85 
86 // Four-dimensional vector types
91 using math::Vec4i;
92 using math::Vec4s;
93 using math::Vec4d;
94 
95 // Three-dimensional matrix types
97 using math::Mat3s;
98 using math::Mat3d;
99 
100 // Four-dimensional matrix types
102 using math::Mat4s;
103 using math::Mat4d;
104 
105 // Quaternions
107 using math::Quats;
108 using math::Quatd;
109 
110 // Dummy type for a voxel with a binary mask value, e.g. the active state
111 class ValueMask {};
112 
113 // Use STL shared pointers from OpenVDB 4 on.
114 template<typename T> using SharedPtr = std::shared_ptr<T>;
115 template<typename T> using WeakPtr = std::weak_ptr<T>;
116 
117 /// @brief Return a new shared pointer that points to the same object
118 /// as the given pointer but with possibly different <TT>const</TT>-ness.
119 /// @par Example:
120 /// @code
121 /// FloatGrid::ConstPtr grid = ...;
122 /// FloatGrid::Ptr nonConstGrid = ConstPtrCast<FloatGrid>(grid);
123 /// FloatGrid::ConstPtr constGrid = ConstPtrCast<const FloatGrid>(nonConstGrid);
124 /// @endcode
125 template<typename T, typename U> inline SharedPtr<T>
126 ConstPtrCast(const SharedPtr<U>& ptr) { return std::const_pointer_cast<T, U>(ptr); }
127 
128 /// @brief Return a new shared pointer that is either null or points to
129 /// the same object as the given pointer after a @c dynamic_cast.
130 /// @par Example:
131 /// @code
132 /// GridBase::ConstPtr grid = ...;
133 /// FloatGrid::ConstPtr floatGrid = DynamicPtrCast<const FloatGrid>(grid);
134 /// @endcode
135 template<typename T, typename U> inline SharedPtr<T>
136 DynamicPtrCast(const SharedPtr<U>& ptr) { return std::dynamic_pointer_cast<T, U>(ptr); }
137 
138 /// @brief Return a new shared pointer that points to the same object
139 /// as the given pointer after a @c static_cast.
140 /// @par Example:
141 /// @code
142 /// FloatGrid::Ptr floatGrid = ...;
143 /// GridBase::Ptr grid = StaticPtrCast<GridBase>(floatGrid);
144 /// @endcode
145 template<typename T, typename U> inline SharedPtr<T>
146 StaticPtrCast(const SharedPtr<U>& ptr) { return std::static_pointer_cast<T, U>(ptr); }
147 
148 
149 ////////////////////////////////////////
150 
151 
152 /// @brief Integer wrapper, required to distinguish PointIndexGrid and
153 /// PointDataGrid from Int32Grid and Int64Grid
154 /// @note @c Kind is a dummy parameter used to create distinct types.
155 template<typename IntType_, Index Kind>
157 {
158  static_assert(std::is_integral<IntType_>::value, "PointIndex requires an integer value type");
159 
160  using IntType = IntType_;
161 
162  PointIndex(IntType i = IntType(0)): mIndex(i) {}
163 
164  /// Explicit type conversion constructor
165  template<typename T> explicit PointIndex(T i): mIndex(static_cast<IntType>(i)) {}
166 
167  operator IntType() const { return mIndex; }
168 
169  /// Needed to support the <tt>(zeroVal<PointIndex>() + val)</tt> idiom.
170  template<typename T>
171  PointIndex operator+(T x) { return PointIndex(mIndex + IntType(x)); }
172 
173 private:
174  IntType mIndex;
175 };
176 
177 
180 
183 
184 
185 ////////////////////////////////////////
186 
187 
188 /// @brief Helper metafunction used to determine if the first template
189 /// parameter is a specialization of the class template given in the second
190 /// template parameter
191 template <typename T, template <typename...> class Template>
192 struct IsSpecializationOf: public std::false_type {};
193 
194 template <typename... Args, template <typename...> class Template>
195 struct IsSpecializationOf<Template<Args...>, Template>: public std::true_type {};
196 
197 
198 ////////////////////////////////////////
199 
200 
201 /// @brief Re-implementation of C++17's index_sequence and the helper alias
202 /// make_index_sequence. This was introduced to fix an issue with clang's
203 /// builtin implementation which treats template specializations of builtin
204 /// templates differently when a subsequent parameter is dependent. The
205 /// result is a resolution failure during partial specialization selection.
206 /// For example, the following will fail to specialize:
207 ///
208 /// @code
209 /// struct Test { static const int VALUE = 1; };
210 ///
211 /// template <typename T, typename S = std::make_index_sequence<T::VALUE>>
212 /// struct Item {};
213 /// template <typename T> struct Adapter {};
214 /// template <typename T> struct Adapter<Item<T>> {}; // FAIL: will never be selected.
215 /// @endcode
216 ///
217 /// This is fixed from Clang16. See also:
218 /// https://reviews.llvm.org/D133262
219 /// https://github.com/llvm/llvm-project/issues/42102
220 /// https://github.com/llvm/llvm-project/issues/51928
221 /// https://github.com/llvm/llvm-project/commit/f4ea3bd4b2086e6de10131b197aaf7d066a24df8
222 template <std::size_t... Ns>
223 struct index_sequence {};
224 
225 template <std::size_t N, std::size_t... Is>
227  // only one branch is considered. The other may be ill-formed
228  if constexpr (N == 0) return index_sequence<Is...>(); // end case
229  else return make_index_sequence_impl<N-1, N-1, Is...>(); // recursion
230 }
231 
232 template <std::size_t N>
233 using make_index_sequence =
234  std::decay_t<decltype(make_index_sequence_impl<N>())>;
235 
236 
237 ////////////////////////////////////////
238 
239 
243 struct VecTraits
244 {
245  static const bool IsVec = true;
246  static const int Size = T::size;
247  using ElementType = typename T::ValueType;
248 };
249 
250 template<typename T>
251 struct VecTraits<T, false>
252 {
253  static const bool IsVec = false;
254  static const int Size = 1;
255  using ElementType = T;
256 };
257 
260 {
261  static const bool IsQuat = true;
262  static const int Size = T::size;
263  using ElementType = typename T::ValueType;
264 };
265 
266 template<typename T>
267 struct QuatTraits<T, false>
268 {
269  static const bool IsQuat = false;
270  static const int Size = 1;
271  using ElementType = T;
272 };
273 
276 struct MatTraits
277 {
278  static const bool IsMat = true;
279  static const int Size = T::size;
280  using ElementType = typename T::ValueType;
281 };
282 
283 template<typename T>
284 struct MatTraits<T, false>
285 {
286  static const bool IsMat = false;
287  static const int Size = 1;
288  using ElementType = T;
289 };
290 
291 template<typename T, bool = VecTraits<T>::IsVec ||
295 {
296  static const bool IsVec = VecTraits<T>::IsVec;
297  static const bool IsQuat = QuatTraits<T>::IsQuat;
298  static const bool IsMat = MatTraits<T>::IsMat;
299  static const bool IsScalar = false;
300  static const int Size = T::size;
301  static const int Elements = IsMat ? Size*Size : Size;
302  using ElementType = typename T::ValueType;
303 };
304 
305 template<typename T>
306 struct ValueTraits<T, false>
307 {
308  static const bool IsVec = false;
309  static const bool IsQuat = false;
310  static const bool IsMat = false;
311  static const bool IsScalar = true;
312  static const int Size = 1;
313  static const int Elements = 1;
314  using ElementType = T;
315 };
316 
317 
318 /// @brief Conversion classes for changing the underlying type of VDB types
319 /// @{
320 template<typename T, typename SubT> struct ConvertElementType { using Type = SubT; };
321 template<typename T, typename SubT> struct ConvertElementType<math::Vec2<T>, SubT> { using Type = math::Vec2<SubT>; };
322 template<typename T, typename SubT> struct ConvertElementType<math::Vec3<T>, SubT> { using Type = math::Vec3<SubT>; };
323 template<typename T, typename SubT> struct ConvertElementType<math::Vec4<T>, SubT> { using Type = math::Vec4<SubT>; };
324 template<typename T, typename SubT> struct ConvertElementType<math::Quat<T>, SubT> { using Type = math::Quat<SubT>; };
325 template<typename T, typename SubT> struct ConvertElementType<math::Mat3<T>, SubT> { using Type = math::Mat3<SubT>; };
326 template<typename T, typename SubT> struct ConvertElementType<math::Mat4<T>, SubT> { using Type = math::Mat4<SubT>; };
327 /// @}
328 
329 namespace types_internal
330 {
331 template <size_t Bits, bool Signed> struct int_t;
332 template <> struct int_t<8ul, true> { using type = int8_t; };
333 template <> struct int_t<16ul, true> { using type = int16_t; };
334 template <> struct int_t<32ul, true> { using type = int32_t; };
335 template <> struct int_t<64ul, true> { using type = int64_t; };
336 template <> struct int_t<8ul, false> { using type = uint8_t; };
337 template <> struct int_t<16ul, false> { using type = uint16_t; };
338 template <> struct int_t<32ul, false> { using type = uint32_t; };
339 template <> struct int_t<64ul, false> { using type = uint64_t; };
340 
341 template <size_t Bits> struct flt_t;
342 template <> struct flt_t<16ul> { using type = math::half; };
343 template <> struct flt_t<32ul> { using type = float; };
344 template <> struct flt_t<64ul> { using type = double; };
345 }
346 
347 /// @brief Promotion classes which provide an interface for elevating and
348 /// demoting a scalar or VDB type to a higher or lower precision. Integer
349 /// types preserve their sign. Types promotion are only valid between
350 /// 8 to 64 bits (long doubles are not supported).
351 /// @{
352 template<typename T>
354 {
355 private:
356  template <size_t bits>
357  using TypeT = typename std::conditional<std::is_integral<T>::value,
360 public:
361  static_assert(sizeof(T) <= 8ul, "Unsupported source type for promotion");
362 
363 #define OPENVDB_TARGET_BITS(SHIFT, PROMOTE) \
364  std::max(size_t(8), \
365  std::min(size_t(64), (PROMOTE ? size_t(8)*(sizeof(T)<<SHIFT) : \
366  size_t(8)*(sizeof(T)>>SHIFT))))
367  template <size_t Shift = ~0UL> using Promote = typename TypeT<OPENVDB_TARGET_BITS(Shift, true)>::type;
368  template <size_t Shift = ~0UL> using Demote = typename TypeT<OPENVDB_TARGET_BITS(Shift, false)>::type;
369 #undef OPENVDB_TARGET_BITS
370 
371  using Highest = typename TypeT<64ul>::type;
372  using Lowest = typename TypeT<8ul>::type;
373  using Next = Promote<1>;
375 };
376 
377 template <typename T, template <typename> class ContainerT>
379 {
380  template <size_t Shift = ~0UL> using Promote = ContainerT<typename PromoteType<T>::template Promote<Shift>>;
381  template <size_t Shift = ~0UL> using Demote = ContainerT<typename PromoteType<T>::template Demote<Shift>>;
382  using Highest = ContainerT<typename PromoteType<T>::Highest>;
383  using Lowest = ContainerT<typename PromoteType<T>::Lowest>;
384  using Next = ContainerT<typename PromoteType<T>::Next>;
385  using Previous = ContainerT<typename PromoteType<T>::Previous>;
386 };
387 
388 template<typename T> struct PromoteType<math::Vec2<T>> : public PromoteContainerType<T, math::Vec2> {};
389 template<typename T> struct PromoteType<math::Vec3<T>> : public PromoteContainerType<T, math::Vec3> {};
390 template<typename T> struct PromoteType<math::Vec4<T>> : public PromoteContainerType<T, math::Vec4> {};
391 template<typename T> struct PromoteType<math::Quat<T>> : public PromoteContainerType<T, math::Quat> {};
392 template<typename T> struct PromoteType<math::Mat3<T>> : public PromoteContainerType<T, math::Mat3> {};
393 template<typename T> struct PromoteType<math::Mat4<T>> : public PromoteContainerType<T, math::Mat4> {};
394 /// @}
395 
396 
397 ////////////////////////////////////////
398 
399 
400 /// @brief CanConvertType<FromType, ToType>::value is @c true if a value
401 /// of type @a ToType can be constructed from a value of type @a FromType.
402 template<typename FromType, typename ToType>
404 
405 // Specializations for vector types, which can be constructed from values
406 // of their own ValueTypes (or values that can be converted to their ValueTypes),
407 // but only explicitly
408 template<typename T> struct CanConvertType<T, math::Vec2<T> > { enum { value = true }; };
409 template<typename T> struct CanConvertType<T, math::Vec3<T> > { enum { value = true }; };
410 template<typename T> struct CanConvertType<T, math::Vec4<T> > { enum { value = true }; };
411 template<typename T> struct CanConvertType<math::Vec2<T>, math::Vec2<T> > { enum {value = true}; };
412 template<typename T> struct CanConvertType<math::Vec3<T>, math::Vec3<T> > { enum {value = true}; };
413 template<typename T> struct CanConvertType<math::Vec4<T>, math::Vec4<T> > { enum {value = true}; };
414 template<typename T0, typename T1>
415 struct CanConvertType<T0, math::Vec2<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
416 template<typename T0, typename T1>
417 struct CanConvertType<T0, math::Vec3<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
418 template<typename T0, typename T1>
419 struct CanConvertType<T0, math::Vec4<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
420 template<> struct CanConvertType<PointIndex32, PointDataIndex32> { enum {value = true}; };
421 template<> struct CanConvertType<PointDataIndex32, PointIndex32> { enum {value = true}; };
422 template<typename T>
424 template<typename T>
426 
427 
428 ////////////////////////////////////////
429 
430 
431 /// @brief CopyConstness<T1, T2>::Type is either <tt>const T2</tt>
432 /// or @c T2 with no @c const qualifier, depending on whether @c T1 is @c const.
433 /// @details For example,
434 /// - CopyConstness<int, int>::Type is @c int
435 /// - CopyConstness<int, const int>::Type is @c int
436 /// - CopyConstness<const int, int>::Type is <tt>const int</tt>
437 /// - CopyConstness<const int, const int>::Type is <tt>const int</tt>
438 template<typename FromType, typename ToType> struct CopyConstness {
440 };
441 
442 /// @cond OPENVDB_DOCS_INTERNAL
443 template<typename FromType, typename ToType> struct CopyConstness<const FromType, ToType> {
444  using Type = const ToType;
445 };
446 /// @endcond
447 
448 
449 ////////////////////////////////////////
450 
451 
452 // Add new items to the *end* of this list, and update NUM_GRID_CLASSES.
453 enum GridClass {
458 };
460 
461 static const Real LEVEL_SET_HALF_WIDTH = 3;
462 
463 /// The type of a vector determines how transforms are applied to it:
464 /// <dl>
465 /// <dt><b>Invariant</b>
466 /// <dd>Does not transform (e.g., tuple, uvw, color)
467 ///
468 /// <dt><b>Covariant</b>
469 /// <dd>Apply inverse-transpose transformation: @e w = 0, ignores translation
470 /// (e.g., gradient/normal)
471 ///
472 /// <dt><b>Covariant Normalize</b>
473 /// <dd>Apply inverse-transpose transformation: @e w = 0, ignores translation,
474 /// vectors are renormalized (e.g., unit normal)
475 ///
476 /// <dt><b>Contravariant Relative</b>
477 /// <dd>Apply "regular" transformation: @e w = 0, ignores translation
478 /// (e.g., displacement, velocity, acceleration)
479 ///
480 /// <dt><b>Contravariant Absolute</b>
481 /// <dd>Apply "regular" transformation: @e w = 1, vector translates (e.g., position)
482 /// </dl>
483 enum VecType {
489 };
491 
492 
493 /// Specify how grids should be merged during certain (typically multithreaded) operations.
494 /// <dl>
495 /// <dt><b>MERGE_ACTIVE_STATES</b>
496 /// <dd>The output grid is active wherever any of the input grids is active.
497 ///
498 /// <dt><b>MERGE_NODES</b>
499 /// <dd>The output grid's tree has a node wherever any of the input grids' trees
500 /// has a node, regardless of any active states.
501 ///
502 /// <dt><b>MERGE_ACTIVE_STATES_AND_NODES</b>
503 /// <dd>The output grid is active wherever any of the input grids is active,
504 /// and its tree has a node wherever any of the input grids' trees has a node.
505 /// </dl>
510 };
511 
512 
513 ////////////////////////////////////////
514 
515 
516 template<typename T> const char* typeNameAsString() { return typeid(T).name(); }
517 template<> inline const char* typeNameAsString<bool>() { return "bool"; }
518 template<> inline const char* typeNameAsString<ValueMask>() { return "mask"; }
519 template<> inline const char* typeNameAsString<math::half>() { return "half"; }
520 template<> inline const char* typeNameAsString<float>() { return "float"; }
521 template<> inline const char* typeNameAsString<double>() { return "double"; }
522 template<> inline const char* typeNameAsString<int8_t>() { return "int8"; }
523 template<> inline const char* typeNameAsString<uint8_t>() { return "uint8"; }
524 template<> inline const char* typeNameAsString<int16_t>() { return "int16"; }
525 template<> inline const char* typeNameAsString<uint16_t>() { return "uint16"; }
526 template<> inline const char* typeNameAsString<int32_t>() { return "int32"; }
527 template<> inline const char* typeNameAsString<uint32_t>() { return "uint32"; }
528 template<> inline const char* typeNameAsString<int64_t>() { return "int64"; }
529 template<> inline const char* typeNameAsString<Vec2i>() { return "vec2i"; }
530 template<> inline const char* typeNameAsString<Vec2s>() { return "vec2s"; }
531 template<> inline const char* typeNameAsString<Vec2d>() { return "vec2d"; }
532 template<> inline const char* typeNameAsString<Vec3U8>() { return "vec3u8"; }
533 template<> inline const char* typeNameAsString<Vec3U16>() { return "vec3u16"; }
534 template<> inline const char* typeNameAsString<Vec3i>() { return "vec3i"; }
535 template<> inline const char* typeNameAsString<Vec3f>() { return "vec3s"; }
536 template<> inline const char* typeNameAsString<Vec3d>() { return "vec3d"; }
537 template<> inline const char* typeNameAsString<Vec4i>() { return "vec4i"; }
538 template<> inline const char* typeNameAsString<Vec4f>() { return "vec4s"; }
539 template<> inline const char* typeNameAsString<Vec4d>() { return "vec4d"; }
540 template<> inline const char* typeNameAsString<std::string>() { return "string"; }
541 template<> inline const char* typeNameAsString<Mat3s>() { return "mat3s"; }
542 template<> inline const char* typeNameAsString<Mat3d>() { return "mat3d"; }
543 template<> inline const char* typeNameAsString<Mat4s>() { return "mat4s"; }
544 template<> inline const char* typeNameAsString<Mat4d>() { return "mat4d"; }
545 template<> inline const char* typeNameAsString<math::Quats>() { return "quats"; }
546 template<> inline const char* typeNameAsString<math::Quatd>() { return "quatd"; }
547 template<> inline const char* typeNameAsString<PointIndex32>() { return "ptidx32"; }
548 template<> inline const char* typeNameAsString<PointIndex64>() { return "ptidx64"; }
549 template<> inline const char* typeNameAsString<PointDataIndex32>() { return "ptdataidx32"; }
550 template<> inline const char* typeNameAsString<PointDataIndex64>() { return "ptdataidx64"; }
551 
552 
553 ////////////////////////////////////////
554 
555 
556 /// @brief This struct collects both input and output arguments to "grid combiner" functors
557 /// used with the tree::TypedGrid::combineExtended() and combine2Extended() methods.
558 /// AValueType and BValueType are the value types of the two grids being combined.
559 ///
560 /// @see openvdb/tree/Tree.h for usage information.
561 ///
562 /// Setter methods return references to this object, to facilitate the following usage:
563 /// @code
564 /// CombineArgs<float> args;
565 /// myCombineOp(args.setARef(aVal).setBRef(bVal).setAIsActive(true).setBIsActive(false));
566 /// @endcode
567 template<typename AValueType, typename BValueType = AValueType>
569 {
570 public:
571  using AValueT = AValueType;
572  using BValueT = BValueType;
573 
575  : mAValPtr(nullptr)
576  , mBValPtr(nullptr)
578  , mAIsActive(false)
579  , mBIsActive(false)
580  , mResultIsActive(false)
581  {
582  }
583 
584  /// Use this constructor when the result value is stored externally.
585  CombineArgs(const AValueType& a, const BValueType& b, AValueType& result,
586  bool aOn = false, bool bOn = false)
587  : mAValPtr(&a)
588  , mBValPtr(&b)
589  , mResultValPtr(&result)
590  , mAIsActive(aOn)
591  , mBIsActive(bOn)
592  {
593  this->updateResultActive();
594  }
595 
596  /// Use this constructor when the result value should be stored in this struct.
597  CombineArgs(const AValueType& a, const BValueType& b, bool aOn = false, bool bOn = false)
598  : mAValPtr(&a)
599  , mBValPtr(&b)
601  , mAIsActive(aOn)
602  , mBIsActive(bOn)
603  {
604  this->updateResultActive();
605  }
606 
607  /// Get the A input value.
608  const AValueType& a() const { return *mAValPtr; }
609  /// Get the B input value.
610  const BValueType& b() const { return *mBValPtr; }
611  //@{
612  /// Get the output value.
613  const AValueType& result() const { return *mResultValPtr; }
614  AValueType& result() { return *mResultValPtr; }
615  //@}
616 
617  /// Set the output value.
618  CombineArgs& setResult(const AValueType& val) { *mResultValPtr = val; return *this; }
619 
620  /// Redirect the A value to a new external source.
621  CombineArgs& setARef(const AValueType& a) { mAValPtr = &a; return *this; }
622  /// Redirect the B value to a new external source.
623  CombineArgs& setBRef(const BValueType& b) { mBValPtr = &b; return *this; }
624  /// Redirect the result value to a new external destination.
625  CombineArgs& setResultRef(AValueType& val) { mResultValPtr = &val; return *this; }
626 
627  /// @return true if the A value is active
628  bool aIsActive() const { return mAIsActive; }
629  /// @return true if the B value is active
630  bool bIsActive() const { return mBIsActive; }
631  /// @return true if the output value is active
632  bool resultIsActive() const { return mResultIsActive; }
633 
634  /// Set the active state of the A value.
635  CombineArgs& setAIsActive(bool b) { mAIsActive = b; updateResultActive(); return *this; }
636  /// Set the active state of the B value.
637  CombineArgs& setBIsActive(bool b) { mBIsActive = b; updateResultActive(); return *this; }
638  /// Set the active state of the output value.
639  CombineArgs& setResultIsActive(bool b) { mResultIsActive = b; return *this; }
640 
641 protected:
642  /// By default, the result value is active if either of the input values is active,
643  /// but this behavior can be overridden by calling setResultIsActive().
645 
646  const AValueType* mAValPtr; // pointer to input value from A grid
647  const BValueType* mBValPtr; // pointer to input value from B grid
648  AValueType mResultVal; // computed output value (unused if stored externally)
649  AValueType* mResultValPtr; // pointer to either mResultVal or an external value
650  bool mAIsActive, mBIsActive; // active states of A and B values
651  bool mResultIsActive; // computed active state (default: A active || B active)
652 };
653 
654 
655 /// This struct adapts a "grid combiner" functor to swap the A and B grid values
656 /// (e.g., so that if the original functor computes a + 2 * b, the adapted functor
657 /// will compute b + 2 * a).
658 template<typename ValueType, typename CombineOp>
660 {
661  SwappedCombineOp(CombineOp& _op): op(_op) {}
662 
664  {
665  CombineArgs<ValueType> swappedArgs(args.b(), args.a(), args.result(),
666  args.bIsActive(), args.aIsActive());
667  op(swappedArgs);
668  args.setResultIsActive(swappedArgs.resultIsActive());
669  }
670 
671  CombineOp& op;
672 };
673 
674 
675 ////////////////////////////////////////
676 
677 
678 /// @brief Tag dispatch class that distinguishes shallow copy constructors
679 /// from deep copy constructors
680 class ShallowCopy {};
681 /// @brief Tag dispatch class that distinguishes topology copy constructors
682 /// from deep copy constructors
683 class TopologyCopy {};
684 /// @brief Tag dispatch class that distinguishes constructors that deep copy
685 class DeepCopy {};
686 /// @brief Tag dispatch class that distinguishes constructors that steal
687 class Steal {};
688 /// @brief Tag dispatch class that distinguishes constructors during file input
689 class PartialCreate {};
690 
691 } // namespace OPENVDB_VERSION_NAME
692 } // namespace openvdb
693 
694 
695 #endif // OPENVDB_TYPES_HAS_BEEN_INCLUDED
const AValueType & result() const
Get the output value.
Definition: Types.h:613
SharedPtr< T > StaticPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer after a static_cast...
Definition: Types.h:146
typename TypeT< OPENVDB_TARGET_BITS(Shift, true)>::type Promote
Definition: Types.h:367
PointIndex operator+(T x)
Needed to support the (zeroVal<PointIndex>() + val) idiom.
Definition: Types.h:171
const char * typeNameAsString< ValueMask >()
Definition: Types.h:518
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:568
typename T::ValueType ElementType
Definition: Types.h:302
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:680
Definition: ImathVec.h:32
Definition: ImathQuat.h:42
imath_half_bits_t half
if we're in a C-only context, alias the half bits type to half
Definition: half.h:266
const char * typeNameAsString< PointIndex32 >()
Definition: Types.h:547
typename T::ValueType ElementType
Definition: Types.h:247
const char * typeNameAsString< int32_t >()
Definition: Types.h:526
const char * typeNameAsString< Vec3i >()
Definition: Types.h:534
const char * typeNameAsString< uint16_t >()
Definition: Types.h:525
GLsizei const GLfloat * value
Definition: glcorearb.h:824
CombineArgs(const AValueType &a, const BValueType &b, bool aOn=false, bool bOn=false)
Use this constructor when the result value should be stored in this struct.
Definition: Types.h:597
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition: Types.h:637
const char * typeNameAsString< int8_t >()
Definition: Types.h:522
const char * typeNameAsString< int16_t >()
Definition: Types.h:524
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:239
const char * typeNameAsString< Mat3s >()
Definition: Types.h:541
imath_half_bits_t half
if we're in a C-only context, alias the half bits type to half
Definition: Half.h:283
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:24
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:689
const char * typeNameAsString< PointIndex64 >()
Definition: Types.h:548
const char * typeNameAsString< Vec3d >()
Definition: Types.h:536
std::decay_t< decltype(make_index_sequence_impl< N >())> make_index_sequence
Definition: Types.h:234
SharedPtr< T > ConstPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer but with possibly dif...
Definition: Types.h:126
const char * typeNameAsString< Mat4s >()
Definition: Types.h:543
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
const AValueType & a() const
Get the A input value.
Definition: Types.h:608
const char * typeNameAsString< Vec3U16 >()
Definition: Types.h:533
Helper metafunction used to determine if the first template parameter is a specialization of the clas...
Definition: Types.h:192
const char * typeNameAsString< Vec3f >()
Definition: Types.h:535
const char * typeNameAsString< PointDataIndex32 >()
Definition: Types.h:549
Re-implementation of C++17's index_sequence and the helper alias make_index_sequence. This was introduced to fix an issue with clang's builtin implementation which treats template specializations of builtin templates differently when a subsequent parameter is dependent. The result is a resolution failure during partial specialization selection. For example, the following will fail to specialize:
Definition: Types.h:223
typename TypeT< OPENVDB_TARGET_BITS(Shift, false)>::type Demote
Definition: Types.h:368
const char * typeNameAsString< uint32_t >()
Definition: Types.h:527
A TypeList provides a compile time sequence of heterogeneous types which can be accessed, transformed and executed over in various ways. It incorporates a subset of functionality similar to hboost::mpl::vector however provides most of its content through using declarations rather than additional typed classes.
IMATH_NAMESPACE::V2f float
std::weak_ptr< T > WeakPtr
Definition: Types.h:115
PointIndex(T i)
Explicit type conversion constructor.
Definition: Types.h:165
const char * typeNameAsString< uint8_t >()
Definition: Types.h:523
BBox< Coord > CoordBBox
Definition: NanoVDB.h:2516
const char * typeNameAsString< float >()
Definition: Types.h:520
const char * typeNameAsString< Vec2i >()
Definition: Types.h:529
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition: Types.h:635
typename std::remove_const< ToType >::type Type
Definition: Types.h:439
const char * typeNameAsString()
Definition: Types.h:516
const char * typeNameAsString< int64_t >()
Definition: Types.h:528
Tag dispatch class that distinguishes constructors that steal.
Definition: Types.h:687
Promotion classes which provide an interface for elevating and demoting a scalar or VDB type to a hig...
Definition: Types.h:353
CopyConstness<T1, T2>::Type is either const T2 or T2 with no const qualifier, depending on whether T1...
Definition: Types.h:438
GLuint const GLchar * name
Definition: glcorearb.h:786
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
const char * typeNameAsString< Vec4d >()
Definition: Types.h:539
CombineArgs(const AValueType &a, const BValueType &b, AValueType &result, bool aOn=false, bool bOn=false)
Use this constructor when the result value is stored externally.
Definition: Types.h:585
CombineArgs & setResultIsActive(bool b)
Set the active state of the output value.
Definition: Types.h:639
const char * typeNameAsString< double >()
Definition: Types.h:521
CanConvertType<FromType, ToType>::value is true if a value of type ToType can be constructed from a v...
Definition: Types.h:403
typename TypeT< 8ul >::type Lowest
Definition: Types.h:372
SharedPtr< T > DynamicPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that is either null or points to the same object as the given pointer aft...
Definition: Types.h:136
typename T::ValueType ElementType
Definition: Types.h:280
GLsizeiptr size
Definition: glcorearb.h:664
Library and file format version numbers.
const char * typeNameAsString< bool >()
Definition: Types.h:517
AValueType & result()
Get the output value.
Definition: Types.h:614
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:623
Definition: ImathVec.h:31
const char * typeNameAsString< Mat4d >()
Definition: Types.h:544
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition: Types.h:625
const char * typeNameAsString< Vec3U8 >()
Definition: Types.h:532
const char * typeNameAsString< Vec2d >()
Definition: Types.h:531
typename TypeT< 64ul >::type Highest
Definition: Types.h:371
auto ptr(T p) -> const void *
Definition: format.h:2448
GLuint GLfloat * val
Definition: glcorearb.h:1608
void operator()(CombineArgs< ValueType > &args)
Definition: Types.h:663
GA_API const UT_StringHolder N
unsigned char Byte
Definition: Types.h:59
**If you just want to fire and args
Definition: thread.h:609
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:621
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:156
Definition: core.h:1131
const char * typeNameAsString< Vec4f >()
Definition: Types.h:538
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:683
const BValueType & b() const
Get the B input value.
Definition: Types.h:610
Tag dispatch class that distinguishes constructors that deep copy.
Definition: Types.h:685
const char * typeNameAsString< Vec4i >()
Definition: Types.h:537
Definition: ImathVec.h:33
typename T::ValueType ElementType
Definition: Types.h:263
type
Definition: core.h:1059
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:119
bool ValueType
Definition: NanoVDB.h:5729
Conversion classes for changing the underlying type of VDB types.
Definition: Types.h:320
const char * typeNameAsString< PointDataIndex64 >()
Definition: Types.h:550
CombineArgs & setResult(const AValueType &val)
Set the output value.
Definition: Types.h:618
const char * typeNameAsString< Vec2s >()
Definition: Types.h:530
PointIndex(IntType i=IntType(0))
Definition: Types.h:162
const char * typeNameAsString< Mat3d >()
Definition: Types.h:542