OpenVDB: openvdb/Types.h Source File

OpenVDB 10.1.0

Loading...
Searching...
No Matches
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
17namespace openvdb {
18 OPENVDB_USE_VERSION_NAMESPACE
19namespace OPENVDB_VERSION_NAME {
20namespace math {
21using half = half;
22}}}
23#else
24#include <openvdb/math/Half.h>
25namespace openvdb {
26 OPENVDB_USE_VERSION_NAMESPACE
27namespace OPENVDB_VERSION_NAME {
28 namespace math {
29 using half = internal::half;
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
47namespace openvdb {
48 OPENVDB_USE_VERSION_NAMESPACE
49namespace 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
63 using Vec2R = math::Vec2<Real>;
64 using Vec2I = math::Vec2<Index32>;
65 using Vec2f = math::Vec2<float>;
66 using Vec2H = math::Vec2<math::half>;
67using math::Vec2i;
68using math::Vec2s;
69using math::Vec2d;
70
71// Three-dimensional vector types
72 using Vec3R = math::Vec3<Real>;
73 using Vec3I = math::Vec3<Index32>;
74 using Vec3f = math::Vec3<float>;
75 using Vec3H = math::Vec3<math::half>;
76 using Vec3U8 = math::Vec3<uint8_t>;
77 using Vec3U16 = math::Vec3<uint16_t>;
78using math::Vec3i;
79using math::Vec3s;
80using math::Vec3d;
81
82using math::Coord;
83using math::CoordBBox;
84 using BBoxd = math::BBox<Vec3d>;
85
86// Four-dimensional vector types
87 using Vec4R = math::Vec4<Real>;
88 using Vec4I = math::Vec4<Index32>;
89 using Vec4f = math::Vec4<float>;
90 using Vec4H = math::Vec4<math::half>;
91using math::Vec4i;
92using math::Vec4s;
93using math::Vec4d;
94
95// Three-dimensional matrix types
96 using Mat3R = math::Mat3<Real>;
97using math::Mat3s;
98using math::Mat3d;
99
100// Four-dimensional matrix types
101 using Mat4R = math::Mat4<Real>;
102using math::Mat4s;
103using math::Mat4d;
104
105// Quaternions
106 using QuatR = math::Quat<Real>;
107using math::Quats;
108using 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
125template<typename T, typename U> inline SharedPtr<T>
126ConstPtrCast(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
135template<typename T, typename U> inline SharedPtr<T>
136DynamicPtrCast(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
145template<typename T, typename U> inline SharedPtr<T>
146StaticPtrCast(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.
155template<typename IntType_, Index Kind>
156 struct PointIndex
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
173private:
174 IntType mIndex;
175};
176
177
178 using PointIndex32 = PointIndex<Index32, 0>;
179 using PointIndex64 = PointIndex<Index64, 0>;
180
181 using PointDataIndex32 = PointIndex<Index32, 1>;
182 using PointDataIndex64 = PointIndex<Index64, 1>;
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
191template <typename T, template <typename...> class Template>
192 struct IsSpecializationOf: public std::false_type {};
193
194template <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
222template <std::size_t... Ns>
223 struct index_sequence {};
224
225template <std::size_t N, std::size_t... Is>
226 auto make_index_sequence_impl() {
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
232template <std::size_t N>
233 using make_index_sequence =
234 std::decay_t<decltype(make_index_sequence_impl<N>())>;
235
236
237////////////////////////////////////////
238
239
240template<typename T, bool = IsSpecializationOf<T, math::Vec2>::value ||
241 IsSpecializationOf<T, math::Vec3>::value ||
242 IsSpecializationOf<T, math::Vec4>::value>
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
250template<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
258template<typename T, bool = IsSpecializationOf<T, math::Quat>::value>
259 struct QuatTraits
260{
261 static const bool IsQuat = true;
262 static const int Size = T::size;
263 using ElementType = typename T::ValueType;
264};
265
266template<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
274template<typename T, bool = IsSpecializationOf<T, math::Mat3>::value ||
275 IsSpecializationOf<T, math::Mat4>::value>
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
283template<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
291template<typename T, bool = VecTraits<T>::IsVec ||
292 QuatTraits<T>::IsQuat ||
293 MatTraits<T>::IsMat>
294 struct ValueTraits
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
305template<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/// @{
352template<typename T>
353 struct PromoteType
354{
355private:
356 template <size_t bits>
357 using TypeT = typename std::conditional<std::is_integral<T>::value,
358 types_internal::int_t<bits, std::is_signed<T>::value>,
359 types_internal::flt_t<std::max(size_t(16), bits)>>::type;
360public:
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>;
374 using Previous = Demote<1>;
375};
376
377template <typename T, template <typename> class ContainerT>
378 struct PromoteContainerType
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.
402template<typename FromType, typename ToType>
403 struct CanConvertType { enum { value = std::is_constructible<ToType, FromType>::value }; };
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}; };
414template<typename T0, typename T1>
415 struct CanConvertType<T0, math::Vec2<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
416template<typename T0, typename T1>
417 struct CanConvertType<T0, math::Vec3<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
418template<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}; };
422template<typename T>
423 struct CanConvertType<T, ValueMask> { enum {value = CanConvertType<T, bool>::value}; };
424template<typename T>
425 struct CanConvertType<ValueMask, T> { enum {value = CanConvertType<bool, T>::value}; };
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 {
439 using Type = typename std::remove_const<ToType>::type;
440};
441
442/// @cond OPENVDB_DOCS_INTERNAL
443template<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 {
454 GRID_UNKNOWN = 0,
455 GRID_LEVEL_SET,
456 GRID_FOG_VOLUME,
457 GRID_STAGGERED
458};
459 enum { NUM_GRID_CLASSES = GRID_STAGGERED + 1 };
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 {
484 VEC_INVARIANT = 0,
485 VEC_COVARIANT,
486 VEC_COVARIANT_NORMALIZE,
487 VEC_CONTRAVARIANT_RELATIVE,
488 VEC_CONTRAVARIANT_ABSOLUTE
489};
490 enum { NUM_VEC_TYPES = VEC_CONTRAVARIANT_ABSOLUTE + 1 };
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>
506 enum MergePolicy {
507 MERGE_ACTIVE_STATES = 0,
508 MERGE_NODES,
509 MERGE_ACTIVE_STATES_AND_NODES
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
567template<typename AValueType, typename BValueType = AValueType>
568 class CombineArgs
569{
570public:
571 using AValueT = AValueType;
572 using BValueT = BValueType;
573
574 CombineArgs()
575 : mAValPtr(nullptr)
576 , mBValPtr(nullptr)
577 , mResultValPtr(&mResultVal)
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)
600 , mResultValPtr(&mResultVal)
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
641protected:
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().
644 void updateResultActive() { mResultIsActive = mAIsActive || mBIsActive; }
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).
658template<typename ValueType, typename CombineOp>
659 struct SwappedCombineOp
660{
661 SwappedCombineOp(CombineOp& _op): op(_op) {}
662
663 void operator()(CombineArgs<ValueType>& args)
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
BBox.h
Coord.h
value
ValueT value
Definition GridBuilder.h:1290
Half.h
Mat3.h
Mat4.h
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Platform.h
Quat.h
TypeList.h
A TypeList provides a compile time sequence of heterogeneous types which can be accessed,...
Vec2.h
Vec3.h
Vec4.h
openvdb::v10_1::CombineArgs
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:569
openvdb::v10_1::CombineArgs::setARef
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:621
openvdb::v10_1::CombineArgs::bIsActive
bool bIsActive() const
Definition Types.h:630
openvdb::v10_1::CombineArgs::result
const AValueType & result() const
Get the output value.
Definition Types.h:613
openvdb::v10_1::CombineArgs::CombineArgs
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
openvdb::v10_1::CombineArgs::mAIsActive
bool mAIsActive
Definition Types.h:650
openvdb::v10_1::CombineArgs::mResultValPtr
AValueType * mResultValPtr
Definition Types.h:649
openvdb::v10_1::CombineArgs::updateResultActive
void updateResultActive()
Definition Types.h:644
openvdb::v10_1::CombineArgs::setResultIsActive
CombineArgs & setResultIsActive(bool b)
Set the active state of the output value.
Definition Types.h:639
openvdb::v10_1::CombineArgs::mAValPtr
const AValueType * mAValPtr
Definition Types.h:646
openvdb::v10_1::CombineArgs::mResultVal
AValueType mResultVal
Definition Types.h:648
openvdb::v10_1::CombineArgs::aIsActive
bool aIsActive() const
Definition Types.h:628
openvdb::v10_1::CombineArgs::setBIsActive
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:637
openvdb::v10_1::CombineArgs::b
const BValueType & b() const
Get the B input value.
Definition Types.h:610
openvdb::v10_1::CombineArgs::mBValPtr
const BValueType * mBValPtr
Definition Types.h:647
openvdb::v10_1::CombineArgs::CombineArgs
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
openvdb::v10_1::CombineArgs::setResultRef
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition Types.h:625
openvdb::v10_1::CombineArgs::result
AValueType & result()
Definition Types.h:614
openvdb::v10_1::CombineArgs::AValueT
AValueType AValueT
Definition Types.h:571
openvdb::v10_1::CombineArgs::setBRef
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:623
openvdb::v10_1::CombineArgs::a
const AValueType & a() const
Get the A input value.
Definition Types.h:608
openvdb::v10_1::CombineArgs::resultIsActive
bool resultIsActive() const
Definition Types.h:632
openvdb::v10_1::CombineArgs::mResultIsActive
bool mResultIsActive
Definition Types.h:651
openvdb::v10_1::CombineArgs::BValueT
BValueType BValueT
Definition Types.h:572
openvdb::v10_1::CombineArgs::CombineArgs
CombineArgs()
Definition Types.h:574
openvdb::v10_1::CombineArgs::setResult
CombineArgs & setResult(const AValueType &val)
Set the output value.
Definition Types.h:618
openvdb::v10_1::CombineArgs::setAIsActive
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:635
openvdb::v10_1::DeepCopy
Tag dispatch class that distinguishes constructors that deep copy.
Definition Types.h:685
openvdb::v10_1::PartialCreate
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:689
openvdb::v10_1::ShallowCopy
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition Types.h:680
openvdb::v10_1::Steal
Tag dispatch class that distinguishes constructors that steal.
Definition Types.h:687
openvdb::v10_1::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:683
openvdb::v10_1::ValueMask
Definition Types.h:111
openvdb::v10_1::math::BBox< Vec3d >
openvdb::v10_1::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:251
openvdb::v10_1::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:25
openvdb::v10_1::math::Mat3
3x3 matrix class.
Definition Mat3.h:29
openvdb::v10_1::math::Mat4< Real >
openvdb::v10_1::math::Quat
Definition Quat.h:79
openvdb::v10_1::math::Vec2
Definition Vec2.h:24
openvdb::v10_1::math::Vec3< Real >
openvdb::v10_1::math::Vec4
Definition Vec4.h:25
openvdb::v10_1::math::internal::half
Definition Half.h:503
openvdb::v10_1::math::half
internal::half half
Definition Types.h:29
openvdb::v10_1::LEVEL_SET_HALF_WIDTH
static const Real LEVEL_SET_HALF_WIDTH
Definition Types.h:461
openvdb::v10_1::NUM_GRID_CLASSES
@ NUM_GRID_CLASSES
Definition Types.h:459
openvdb::v10_1::Index
Index32 Index
Definition Types.h:54
openvdb::v10_1::Int16
int16_t Int16
Definition Types.h:55
openvdb::v10_1::make_index_sequence_impl
auto make_index_sequence_impl()
Definition Types.h:226
openvdb::v10_1::Byte
unsigned char Byte
Definition Types.h:59
openvdb::v10_1::Real
double Real
Definition Types.h:60
openvdb::v10_1::GridClass
GridClass
Definition Types.h:453
openvdb::v10_1::GRID_FOG_VOLUME
@ GRID_FOG_VOLUME
Definition Types.h:456
openvdb::v10_1::GRID_STAGGERED
@ GRID_STAGGERED
Definition Types.h:457
openvdb::v10_1::GRID_LEVEL_SET
@ GRID_LEVEL_SET
Definition Types.h:455
openvdb::v10_1::GRID_UNKNOWN
@ GRID_UNKNOWN
Definition Types.h:454
openvdb::v10_1::Int64
int64_t Int64
Definition Types.h:57
openvdb::v10_1::Int
Int32 Int
Definition Types.h:58
openvdb::v10_1::make_index_sequence
std::decay_t< decltype(make_index_sequence_impl< N >())> make_index_sequence
Definition Types.h:234
openvdb::v10_1::WeakPtr
std::weak_ptr< T > WeakPtr
Definition Types.h:115
openvdb::v10_1::Index32
uint32_t Index32
Definition Types.h:52
openvdb::v10_1::ConstPtrCast
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
openvdb::v10_1::DynamicPtrCast
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
openvdb::v10_1::Int32
int32_t Int32
Definition Types.h:56
openvdb::v10_1::Index64
uint64_t Index64
Definition Types.h:53
openvdb::v10_1::SharedPtr
std::shared_ptr< T > SharedPtr
Definition Types.h:114
openvdb::v10_1::MergePolicy
MergePolicy
Definition Types.h:506
openvdb::v10_1::MERGE_ACTIVE_STATES
@ MERGE_ACTIVE_STATES
Definition Types.h:507
openvdb::v10_1::MERGE_NODES
@ MERGE_NODES
Definition Types.h:508
openvdb::v10_1::MERGE_ACTIVE_STATES_AND_NODES
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:509
openvdb::v10_1::NUM_VEC_TYPES
@ NUM_VEC_TYPES
Definition Types.h:490
openvdb::v10_1::VecType
VecType
Definition Types.h:483
openvdb::v10_1::VEC_CONTRAVARIANT_ABSOLUTE
@ VEC_CONTRAVARIANT_ABSOLUTE
Definition Types.h:488
openvdb::v10_1::VEC_CONTRAVARIANT_RELATIVE
@ VEC_CONTRAVARIANT_RELATIVE
Definition Types.h:487
openvdb::v10_1::VEC_COVARIANT
@ VEC_COVARIANT
Definition Types.h:485
openvdb::v10_1::VEC_COVARIANT_NORMALIZE
@ VEC_COVARIANT_NORMALIZE
Definition Types.h:486
openvdb::v10_1::VEC_INVARIANT
@ VEC_INVARIANT
Definition Types.h:484
openvdb::v10_1::StaticPtrCast
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
openvdb::v10_1::typeNameAsString
const char * typeNameAsString()
Definition Types.h:516
openvdb
Definition Exceptions.h:13
OPENVDB_TARGET_BITS
#define OPENVDB_TARGET_BITS(SHIFT, PROMOTE)
Definition Types.h:363
openvdb::v10_1::CanConvertType
CanConvertType<FromType, ToType>::value is true if a value of type ToType can be constructed from a v...
Definition Types.h:403
openvdb::v10_1::ConvertElementType
Conversion classes for changing the underlying type of VDB types.
Definition Types.h:320
openvdb::v10_1::ConvertElementType::Type
SubT Type
Definition Types.h:320
openvdb::v10_1::CopyConstness
CopyConstness<T1, T2>::Type is either const T2 or T2 with no const qualifier, depending on whether T1...
Definition Types.h:438
openvdb::v10_1::CopyConstness::Type
typename std::remove_const< ToType >::type Type
Definition Types.h:439
openvdb::v10_1::IsSpecializationOf
Helper metafunction used to determine if the first template parameter is a specialization of the clas...
Definition Types.h:192
openvdb::v10_1::MatTraits< T, false >::ElementType
T ElementType
Definition Types.h:288
openvdb::v10_1::MatTraits
Definition Types.h:277
openvdb::v10_1::MatTraits::ElementType
typename T::ValueType ElementType
Definition Types.h:280
openvdb::v10_1::PointIndex
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition Types.h:157
openvdb::v10_1::PointIndex::PointIndex
PointIndex(T i)
Explicit type conversion constructor.
Definition Types.h:165
openvdb::v10_1::PointIndex::PointIndex
PointIndex(IntType i=IntType(0))
Definition Types.h:162
openvdb::v10_1::PointIndex::operator+
PointIndex operator+(T x)
Needed to support the (zeroVal<PointIndex>() + val) idiom.
Definition Types.h:171
openvdb::v10_1::PointIndex::IntType
IntType_ IntType
Definition Types.h:160
openvdb::v10_1::PromoteContainerType
Definition Types.h:379
openvdb::v10_1::PromoteContainerType::Previous
ContainerT< typename PromoteType< T >::Previous > Previous
Definition Types.h:385
openvdb::v10_1::PromoteContainerType::Demote
ContainerT< typename PromoteType< T >::template Demote< Shift > > Demote
Definition Types.h:381
openvdb::v10_1::PromoteContainerType::Highest
ContainerT< typename PromoteType< T >::Highest > Highest
Definition Types.h:382
openvdb::v10_1::PromoteContainerType::Lowest
ContainerT< typename PromoteType< T >::Lowest > Lowest
Definition Types.h:383
openvdb::v10_1::PromoteContainerType::Next
ContainerT< typename PromoteType< T >::Next > Next
Definition Types.h:384
openvdb::v10_1::PromoteContainerType::Promote
ContainerT< typename PromoteType< T >::template Promote< Shift > > Promote
Definition Types.h:380
openvdb::v10_1::PromoteType
Promotion classes which provide an interface for elevating and demoting a scalar or VDB type to a hig...
Definition Types.h:354
openvdb::v10_1::PromoteType::Next
Promote< 1 > Next
Definition Types.h:373
openvdb::v10_1::PromoteType::Previous
Demote< 1 > Previous
Definition Types.h:374
openvdb::v10_1::PromoteType::Promote
typename TypeT< std::max(size_t(8), std::min(size_t(64),(true ? size_t(8) *(sizeof(T)<< Shift) :size_t(8) *(sizeof(T)> > Shift))))>::type Promote
Definition Types.h:367
openvdb::v10_1::PromoteType::Demote
typename TypeT< std::max(size_t(8), std::min(size_t(64),(false ? size_t(8) *(sizeof(T)<< Shift) :size_t(8) *(sizeof(T)> > Shift))))>::type Demote
Definition Types.h:368
openvdb::v10_1::PromoteType::Lowest
typename TypeT< 8ul >::type Lowest
Definition Types.h:372
openvdb::v10_1::PromoteType::Highest
typename TypeT< 64ul >::type Highest
Definition Types.h:371
openvdb::v10_1::QuatTraits< T, false >::ElementType
T ElementType
Definition Types.h:271
openvdb::v10_1::QuatTraits
Definition Types.h:260
openvdb::v10_1::QuatTraits::ElementType
typename T::ValueType ElementType
Definition Types.h:263
openvdb::v10_1::SwappedCombineOp
Definition Types.h:660
openvdb::v10_1::SwappedCombineOp::SwappedCombineOp
SwappedCombineOp(CombineOp &_op)
Definition Types.h:661
openvdb::v10_1::SwappedCombineOp::operator()
void operator()(CombineArgs< ValueType > &args)
Definition Types.h:663
openvdb::v10_1::SwappedCombineOp::op
CombineOp & op
Definition Types.h:671
openvdb::v10_1::ValueTraits< T, false >::ElementType
T ElementType
Definition Types.h:314
openvdb::v10_1::ValueTraits
Definition Types.h:295
openvdb::v10_1::ValueTraits::ElementType
typename T::ValueType ElementType
Definition Types.h:302
openvdb::v10_1::VecTraits< T, false >::ElementType
T ElementType
Definition Types.h:255
openvdb::v10_1::VecTraits
Definition Types.h:244
openvdb::v10_1::VecTraits::ElementType
typename T::ValueType ElementType
Definition Types.h:247
openvdb::v10_1::index_sequence
Re-implementation of C++17's index_sequence and the helper alias make_index_sequence....
Definition Types.h:223
openvdb::v10_1::types_internal::flt_t< 32ul >::type
float type
Definition Types.h:343
openvdb::v10_1::types_internal::flt_t< 64ul >::type
double type
Definition Types.h:344
openvdb::v10_1::types_internal::flt_t
Definition Types.h:341
openvdb::v10_1::types_internal::int_t< 16ul, false >::type
uint16_t type
Definition Types.h:337
openvdb::v10_1::types_internal::int_t< 16ul, true >::type
int16_t type
Definition Types.h:333
openvdb::v10_1::types_internal::int_t< 32ul, false >::type
uint32_t type
Definition Types.h:338
openvdb::v10_1::types_internal::int_t< 32ul, true >::type
int32_t type
Definition Types.h:334
openvdb::v10_1::types_internal::int_t< 64ul, false >::type
uint64_t type
Definition Types.h:339
openvdb::v10_1::types_internal::int_t< 64ul, true >::type
int64_t type
Definition Types.h:335
openvdb::v10_1::types_internal::int_t< 8ul, false >::type
uint8_t type
Definition Types.h:336
openvdb::v10_1::types_internal::int_t< 8ul, true >::type
int8_t type
Definition Types.h:332
openvdb::v10_1::types_internal::int_t
Definition Types.h:331
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212