HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Types.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
29 ///////////////////////////////////////////////////////////////////////////
30 
31 #ifndef OPENVDB_TYPES_HAS_BEEN_INCLUDED
32 #define OPENVDB_TYPES_HAS_BEEN_INCLUDED
33 
34 #include "version.h"
35 #include "Platform.h"
36 #include <OpenEXR/half.h>
37 #include <openvdb/math/Math.h>
38 #include <openvdb/math/BBox.h>
39 #include <openvdb/math/Quat.h>
40 #include <openvdb/math/Vec2.h>
41 #include <openvdb/math/Vec3.h>
42 #include <openvdb/math/Vec4.h>
43 #include <openvdb/math/Mat3.h>
44 #include <openvdb/math/Mat4.h>
45 #include <openvdb/math/Coord.h>
46 #include <memory>
47 #include <type_traits>
48 #if OPENVDB_ABI_VERSION_NUMBER <= 3
49 #include <hboost/shared_ptr.hpp>
50 #include <hboost/weak_ptr.hpp>
51 #endif
52 
53 
54 namespace openvdb {
56 namespace OPENVDB_VERSION_NAME {
57 
58 // One-dimensional scalar types
59 using Index32 = uint32_t;
60 using Index64 = uint64_t;
61 using Index = Index32;
62 using Int16 = int16_t;
63 using Int32 = int32_t;
64 using Int64 = int64_t;
65 using Int = Int32;
66 using Byte = unsigned char;
67 using Real = double;
68 
69 // Two-dimensional vector types
74 using math::Vec2i;
75 using math::Vec2s;
76 using math::Vec2d;
77 
78 // Three-dimensional vector types
85 using math::Vec3i;
86 using math::Vec3s;
87 using math::Vec3d;
88 
89 using math::Coord;
90 using math::CoordBBox;
92 
93 // Four-dimensional vector types
98 using math::Vec4i;
99 using math::Vec4s;
100 using math::Vec4d;
101 
102 // Three-dimensional matrix types
104 using math::Mat3s;
105 using math::Mat3d;
106 
107 // Four-dimensional matrix types
109 using math::Mat4s;
110 using math::Mat4d;
111 
112 // Quaternions
114 using math::Quats;
115 using math::Quatd;
116 
117 // Dummy type for a voxel with a binary mask value, e.g. the active state
118 class ValueMask {};
119 
120 
121 #if OPENVDB_ABI_VERSION_NUMBER <= 3
122 
123 // Use Boost shared pointers in OpenVDB 3 ABI compatibility mode.
124 template<typename T> using SharedPtr = hboost::shared_ptr<T>;
125 template<typename T> using WeakPtr = hboost::weak_ptr<T>;
126 
127 template<typename T, typename U> inline SharedPtr<T>
128 ConstPtrCast(const SharedPtr<U>& ptr) { return hboost::const_pointer_cast<T, U>(ptr); }
129 
130 template<typename T, typename U> inline SharedPtr<T>
131 DynamicPtrCast(const SharedPtr<U>& ptr) { return hboost::dynamic_pointer_cast<T, U>(ptr); }
132 
133 template<typename T, typename U> inline SharedPtr<T>
134 StaticPtrCast(const SharedPtr<U>& ptr) { return hboost::static_pointer_cast<T, U>(ptr); }
135 
136 #else // if OPENVDB_ABI_VERSION_NUMBER > 3
137 
138 // Use STL shared pointers from OpenVDB 4 on.
139 template<typename T> using SharedPtr = std::shared_ptr<T>;
140 template<typename T> using WeakPtr = std::weak_ptr<T>;
141 
142 /// @brief Return a new shared pointer that points to the same object
143 /// as the given pointer but with possibly different <TT>const</TT>-ness.
144 /// @par Example:
145 /// @code
146 /// FloatGrid::ConstPtr grid = ...;
147 /// FloatGrid::Ptr nonConstGrid = ConstPtrCast<FloatGrid>(grid);
148 /// FloatGrid::ConstPtr constGrid = ConstPtrCast<const FloatGrid>(nonConstGrid);
149 /// @endcode
150 template<typename T, typename U> inline SharedPtr<T>
151 ConstPtrCast(const SharedPtr<U>& ptr) { return std::const_pointer_cast<T, U>(ptr); }
152 
153 /// @brief Return a new shared pointer that is either null or points to
154 /// the same object as the given pointer after a @c dynamic_cast.
155 /// @par Example:
156 /// @code
157 /// GridBase::ConstPtr grid = ...;
158 /// FloatGrid::ConstPtr floatGrid = DynamicPtrCast<const FloatGrid>(grid);
159 /// @endcode
160 template<typename T, typename U> inline SharedPtr<T>
161 DynamicPtrCast(const SharedPtr<U>& ptr) { return std::dynamic_pointer_cast<T, U>(ptr); }
162 
163 /// @brief Return a new shared pointer that points to the same object
164 /// as the given pointer after a @c static_cast.
165 /// @par Example:
166 /// @code
167 /// FloatGrid::Ptr floatGrid = ...;
168 /// GridBase::Ptr grid = StaticPtrCast<GridBase>(floatGrid);
169 /// @endcode
170 template<typename T, typename U> inline SharedPtr<T>
171 StaticPtrCast(const SharedPtr<U>& ptr) { return std::static_pointer_cast<T, U>(ptr); }
172 
173 #endif
174 
175 
176 ////////////////////////////////////////
177 
178 
179 /// @brief Integer wrapper, required to distinguish PointIndexGrid and
180 /// PointDataGrid from Int32Grid and Int64Grid
181 /// @note @c Kind is a dummy parameter used to create distinct types.
182 template<typename IntType_, Index Kind>
184 {
185  static_assert(std::is_integral<IntType_>::value, "PointIndex requires an integer value type");
186 
187  using IntType = IntType_;
188 
189  PointIndex(IntType i = IntType(0)): mIndex(i) {}
190 
191  /// Explicit type conversion constructor
192  template<typename T> explicit PointIndex(T i): mIndex(static_cast<IntType>(i)) {}
193 
194  operator IntType() const { return mIndex; }
195 
196  /// Needed to support the <tt>(zeroVal<PointIndex>() + val)</tt> idiom.
197  template<typename T>
198  PointIndex operator+(T x) { return PointIndex(mIndex + IntType(x)); }
199 
200 private:
201  IntType mIndex;
202 };
203 
204 
207 
210 
211 
212 ////////////////////////////////////////
213 
214 
215 /// @brief Helper metafunction used to determine if the first template
216 /// parameter is a specialization of the class template given in the second
217 /// template parameter
218 template <typename T, template <typename...> class Template>
219 struct IsSpecializationOf: public std::false_type {};
220 
221 template <typename... Args, template <typename...> class Template>
222 struct IsSpecializationOf<Template<Args...>, Template>: public std::true_type {};
223 
224 
225 ////////////////////////////////////////
226 
227 
231 struct VecTraits
232 {
233  static const bool IsVec = true;
234  static const int Size = T::size;
235  using ElementType = typename T::ValueType;
236 };
237 
238 template<typename T>
239 struct VecTraits<T, false>
240 {
241  static const bool IsVec = false;
242  static const int Size = 1;
243  using ElementType = T;
244 };
245 
248 {
249  static const bool IsQuat = true;
250  static const int Size = T::size;
251  using ElementType = typename T::ValueType;
252 };
253 
254 template<typename T>
255 struct QuatTraits<T, false>
256 {
257  static const bool IsQuat = false;
258  static const int Size = 1;
259  using ElementType = T;
260 };
261 
264 struct MatTraits
265 {
266  static const bool IsMat = true;
267  static const int Size = T::size;
268  using ElementType = typename T::ValueType;
269 };
270 
271 template<typename T>
272 struct MatTraits<T, false>
273 {
274  static const bool IsMat = false;
275  static const int Size = 1;
276  using ElementType = T;
277 };
278 
279 template<typename T, bool = VecTraits<T>::IsVec ||
283 {
284  static const bool IsVec = VecTraits<T>::IsVec;
285  static const bool IsQuat = QuatTraits<T>::IsQuat;
286  static const bool IsMat = MatTraits<T>::IsMat;
287  static const bool IsScalar = false;
288  static const int Size = T::size;
289  static const int Elements = IsMat ? Size*Size : Size;
290  using ElementType = typename T::ValueType;
291 };
292 
293 template<typename T>
294 struct ValueTraits<T, false>
295 {
296  static const bool IsVec = false;
297  static const bool IsQuat = false;
298  static const bool IsMat = false;
299  static const bool IsScalar = true;
300  static const int Size = 1;
301  static const int Elements = 1;
302  using ElementType = T;
303 };
304 
305 
306 ////////////////////////////////////////
307 
308 
309 /// @brief CanConvertType<FromType, ToType>::value is @c true if a value
310 /// of type @a ToType can be constructed from a value of type @a FromType.
311 template<typename FromType, typename ToType>
313 
314 // Specializations for vector types, which can be constructed from values
315 // of their own ValueTypes (or values that can be converted to their ValueTypes),
316 // but only explicitly
317 template<typename T> struct CanConvertType<T, math::Vec2<T> > { enum { value = true }; };
318 template<typename T> struct CanConvertType<T, math::Vec3<T> > { enum { value = true }; };
319 template<typename T> struct CanConvertType<T, math::Vec4<T> > { enum { value = true }; };
320 template<typename T> struct CanConvertType<math::Vec2<T>, math::Vec2<T> > { enum {value = true}; };
321 template<typename T> struct CanConvertType<math::Vec3<T>, math::Vec3<T> > { enum {value = true}; };
322 template<typename T> struct CanConvertType<math::Vec4<T>, math::Vec4<T> > { enum {value = true}; };
323 template<typename T0, typename T1>
324 struct CanConvertType<T0, math::Vec2<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
325 template<typename T0, typename T1>
326 struct CanConvertType<T0, math::Vec3<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
327 template<typename T0, typename T1>
328 struct CanConvertType<T0, math::Vec4<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
329 template<> struct CanConvertType<PointIndex32, PointDataIndex32> { enum {value = true}; };
330 template<> struct CanConvertType<PointDataIndex32, PointIndex32> { enum {value = true}; };
331 template<typename T>
333 template<typename T>
335 
336 
337 ////////////////////////////////////////
338 
339 
340 /// @brief CopyConstness<T1, T2>::Type is either <tt>const T2</tt>
341 /// or @c T2 with no @c const qualifier, depending on whether @c T1 is @c const.
342 /// @details For example,
343 /// - CopyConstness<int, int>::Type is @c int
344 /// - CopyConstness<int, const int>::Type is @c int
345 /// - CopyConstness<const int, int>::Type is <tt>const int</tt>
346 /// - CopyConstness<const int, const int>::Type is <tt>const int</tt>
347 template<typename FromType, typename ToType> struct CopyConstness {
349 };
350 
351 /// @cond OPENVDB_TYPES_INTERNAL
352 template<typename FromType, typename ToType> struct CopyConstness<const FromType, ToType> {
353  using Type = const ToType;
354 };
355 /// @endcond
356 
357 
358 ////////////////////////////////////////
359 
360 
361 /// @cond OPENVDB_TYPES_INTERNAL
362 
363 template<typename... Ts> struct TypeList; // forward declaration
364 
365 namespace internal {
366 
367 // Implementation details of TypeList
368 
369 template<typename ListT, typename... Ts> struct TSAppendImpl;
370 
371 // Append zero or more types.
372 template<typename... Ts, typename... OtherTs>
373 struct TSAppendImpl<TypeList<Ts...>, OtherTs...> {
374  using type = TypeList<Ts..., OtherTs...>;
375 };
376 
377 // Append another TypeList's members.
378 template<typename... Ts, typename... OtherTs>
379 struct TSAppendImpl<TypeList<Ts...>, TypeList<OtherTs...>> {
380  using type = TypeList<Ts..., OtherTs...>;
381 };
382 
383 
384 // Remove all occurrences of type T.
385 template<typename ListT, typename T> struct TSEraseImpl;
386 
387 // TypeList<>::Erase<int> = TypeList<>
388 template<typename T>
389 struct TSEraseImpl<TypeList<>, T> { using type = TypeList<>; };
390 
391 // TypeList<int, char, ...>::Erase<int> = TypeList<char, ...>::Erase<int>
392 template<typename... Ts, typename T>
393 struct TSEraseImpl<TypeList<T, Ts...>, T> {
394  using type = typename TSEraseImpl<TypeList<Ts...>, T>::type;
395 };
396 
397 // TypeList<float, int, char...>::Erase<int> =
398 // TypeList<float>::Append<TypeList<int, char...>::Erase<int>>
399 template<typename T2, typename... Ts, typename T>
400 struct TSEraseImpl<TypeList<T2, Ts...>, T> {
401  using type = typename TSAppendImpl<TypeList<T2>,
402  typename TSEraseImpl<TypeList<Ts...>, T>::type>::type;
403 };
404 
405 
406 template<typename ListT, typename... Ts> struct TSRemoveImpl;
407 
408 template<typename ListT>
409 struct TSRemoveImpl<ListT> { using type = ListT; };
410 
411 // Remove one or more types.
412 template<typename ListT, typename T, typename... Ts>
413 struct TSRemoveImpl<ListT, T, Ts...> {
415 };
416 
417 // Remove the members of another TypeList.
418 template<typename ListT, typename... Ts>
419 struct TSRemoveImpl<ListT, TypeList<Ts...>> {
420  using type = typename TSRemoveImpl<ListT, Ts...>::type;
421 };
422 
423 
424 template<typename OpT> inline void TSForEachImpl(OpT) {}
425 template<typename OpT, typename T, typename... Ts>
426 inline void TSForEachImpl(OpT op) { op(T()); TSForEachImpl<OpT, Ts...>(op); }
427 
428 } // namespace internal
429 
430 /// @endcond
431 
432 
433 /// @brief A list of types (not necessarily unique)
434 /// @details Example:
435 /// @code
436 /// using MyTypes = openvdb::TypeList<int, float, int, double, float>;
437 /// @endcode
438 template<typename... Ts>
439 struct TypeList
440 {
441  /// The type of this list
442  using Self = TypeList;
443 
444  /// @brief Append types, or the members of another TypeList, to this list.
445  /// @details Example:
446  /// @code
447  /// {
448  /// using IntTypes = openvdb::TypeList<Int16, Int32, Int64>;
449  /// using RealTypes = openvdb::TypeList<float, double>;
450  /// using NumericTypes = IntTypes::Append<RealTypes>;
451  /// }
452  /// {
453  /// using IntTypes = openvdb::TypeList<Int16>::Append<Int32, Int64>;
454  /// using NumericTypes = IntTypes::Append<float>::Append<double>;
455  /// }
456  /// @endcode
457  template<typename... TypesToAppend>
458  using Append = typename internal::TSAppendImpl<Self, TypesToAppend...>::type;
459 
460  /// @brief Remove all occurrences of one or more types, or the members of
461  /// another TypeList, from this list.
462  /// @details Example:
463  /// @code
464  /// {
465  /// using NumericTypes = openvdb::TypeList<float, double, Int16, Int32, Int64>;
466  /// using LongTypes = openvdb::TypeList<Int64, double>;
467  /// using ShortTypes = NumericTypes::Remove<LongTypes>; // float, Int16, Int32
468  /// }
469  /// @endcode
470  template<typename... TypesToRemove>
471  using Remove = typename internal::TSRemoveImpl<Self, TypesToRemove...>::type;
472 
473  /// @brief Invoke a templated, unary functor on a value of each type in this list.
474  /// @details Example:
475  /// @code
476  /// #include <typeinfo>
477  ///
478  /// template<typename ListT>
479  /// void printTypeList()
480  /// {
481  /// std::string sep;
482  /// auto op = [&](auto x) { // C++14
483  /// std::cout << sep << typeid(decltype(x)).name(); sep = ", "; };
484  /// ListT::foreach(op);
485  /// }
486  ///
487  /// using MyTypes = openvdb::TypeList<int, float, double>;
488  /// printTypeList<MyTypes>(); // "i, f, d" (exact output is compiler-dependent)
489  /// @endcode
490  ///
491  /// @note The functor object is passed by value. Wrap it with @c std::ref
492  /// to use the same object for each type.
493  template<typename OpT>
494  static void foreach(OpT op) { internal::TSForEachImpl<OpT, Ts...>(op); }
495 };
496 
497 
498 ////////////////////////////////////////
499 
500 
501 // Add new items to the *end* of this list, and update NUM_GRID_CLASSES.
502 enum GridClass {
507 };
509 
510 static const Real LEVEL_SET_HALF_WIDTH = 3;
511 
512 /// The type of a vector determines how transforms are applied to it:
513 /// <dl>
514 /// <dt><b>Invariant</b>
515 /// <dd>Does not transform (e.g., tuple, uvw, color)
516 ///
517 /// <dt><b>Covariant</b>
518 /// <dd>Apply inverse-transpose transformation: @e w = 0, ignores translation
519 /// (e.g., gradient/normal)
520 ///
521 /// <dt><b>Covariant Normalize</b>
522 /// <dd>Apply inverse-transpose transformation: @e w = 0, ignores translation,
523 /// vectors are renormalized (e.g., unit normal)
524 ///
525 /// <dt><b>Contravariant Relative</b>
526 /// <dd>Apply "regular" transformation: @e w = 0, ignores translation
527 /// (e.g., displacement, velocity, acceleration)
528 ///
529 /// <dt><b>Contravariant Absolute</b>
530 /// <dd>Apply "regular" transformation: @e w = 1, vector translates (e.g., position)
531 /// </dl>
532 enum VecType {
538 };
540 
541 
542 /// Specify how grids should be merged during certain (typically multithreaded) operations.
543 /// <dl>
544 /// <dt><b>MERGE_ACTIVE_STATES</b>
545 /// <dd>The output grid is active wherever any of the input grids is active.
546 ///
547 /// <dt><b>MERGE_NODES</b>
548 /// <dd>The output grid's tree has a node wherever any of the input grids' trees
549 /// has a node, regardless of any active states.
550 ///
551 /// <dt><b>MERGE_ACTIVE_STATES_AND_NODES</b>
552 /// <dd>The output grid is active wherever any of the input grids is active,
553 /// and its tree has a node wherever any of the input grids' trees has a node.
554 /// </dl>
559 };
560 
561 
562 ////////////////////////////////////////
563 
564 
565 template<typename T> const char* typeNameAsString() { return typeid(T).name(); }
566 template<> inline const char* typeNameAsString<bool>() { return "bool"; }
567 template<> inline const char* typeNameAsString<ValueMask>() { return "mask"; }
568 template<> inline const char* typeNameAsString<half>() { return "half"; }
569 template<> inline const char* typeNameAsString<float>() { return "float"; }
570 template<> inline const char* typeNameAsString<double>() { return "double"; }
571 template<> inline const char* typeNameAsString<int8_t>() { return "int8"; }
572 template<> inline const char* typeNameAsString<uint8_t>() { return "uint8"; }
573 template<> inline const char* typeNameAsString<int16_t>() { return "int16"; }
574 template<> inline const char* typeNameAsString<uint16_t>() { return "uint16"; }
575 template<> inline const char* typeNameAsString<int32_t>() { return "int32"; }
576 template<> inline const char* typeNameAsString<uint32_t>() { return "uint32"; }
577 template<> inline const char* typeNameAsString<int64_t>() { return "int64"; }
578 template<> inline const char* typeNameAsString<Vec2i>() { return "vec2i"; }
579 template<> inline const char* typeNameAsString<Vec2s>() { return "vec2s"; }
580 template<> inline const char* typeNameAsString<Vec2d>() { return "vec2d"; }
581 template<> inline const char* typeNameAsString<Vec3U8>() { return "vec3u8"; }
582 template<> inline const char* typeNameAsString<Vec3U16>() { return "vec3u16"; }
583 template<> inline const char* typeNameAsString<Vec3i>() { return "vec3i"; }
584 template<> inline const char* typeNameAsString<Vec3f>() { return "vec3s"; }
585 template<> inline const char* typeNameAsString<Vec3d>() { return "vec3d"; }
586 template<> inline const char* typeNameAsString<Vec4i>() { return "vec4i"; }
587 template<> inline const char* typeNameAsString<Vec4f>() { return "vec4s"; }
588 template<> inline const char* typeNameAsString<Vec4d>() { return "vec4d"; }
589 template<> inline const char* typeNameAsString<std::string>() { return "string"; }
590 template<> inline const char* typeNameAsString<Mat3s>() { return "mat3s"; }
591 template<> inline const char* typeNameAsString<Mat3d>() { return "mat3d"; }
592 template<> inline const char* typeNameAsString<Mat4s>() { return "mat4s"; }
593 template<> inline const char* typeNameAsString<Mat4d>() { return "mat4d"; }
594 template<> inline const char* typeNameAsString<math::Quats>() { return "quats"; }
595 template<> inline const char* typeNameAsString<math::Quatd>() { return "quatd"; }
596 template<> inline const char* typeNameAsString<PointIndex32>() { return "ptidx32"; }
597 template<> inline const char* typeNameAsString<PointIndex64>() { return "ptidx64"; }
598 template<> inline const char* typeNameAsString<PointDataIndex32>() { return "ptdataidx32"; }
599 template<> inline const char* typeNameAsString<PointDataIndex64>() { return "ptdataidx64"; }
600 
601 
602 ////////////////////////////////////////
603 
604 
605 /// @brief This struct collects both input and output arguments to "grid combiner" functors
606 /// used with the tree::TypedGrid::combineExtended() and combine2Extended() methods.
607 /// AValueType and BValueType are the value types of the two grids being combined.
608 ///
609 /// @see openvdb/tree/Tree.h for usage information.
610 ///
611 /// Setter methods return references to this object, to facilitate the following usage:
612 /// @code
613 /// CombineArgs<float> args;
614 /// myCombineOp(args.setARef(aVal).setBRef(bVal).setAIsActive(true).setBIsActive(false));
615 /// @endcode
616 template<typename AValueType, typename BValueType = AValueType>
618 {
619 public:
620  using AValueT = AValueType;
621  using BValueT = BValueType;
622 
624  : mAValPtr(nullptr)
625  , mBValPtr(nullptr)
627  , mAIsActive(false)
628  , mBIsActive(false)
629  , mResultIsActive(false)
630  {
631  }
632 
633  /// Use this constructor when the result value is stored externally.
634  CombineArgs(const AValueType& a, const BValueType& b, AValueType& result,
635  bool aOn = false, bool bOn = false)
636  : mAValPtr(&a)
637  , mBValPtr(&b)
638  , mResultValPtr(&result)
639  , mAIsActive(aOn)
640  , mBIsActive(bOn)
641  {
642  this->updateResultActive();
643  }
644 
645  /// Use this constructor when the result value should be stored in this struct.
646  CombineArgs(const AValueType& a, const BValueType& b, bool aOn = false, bool bOn = false)
647  : mAValPtr(&a)
648  , mBValPtr(&b)
650  , mAIsActive(aOn)
651  , mBIsActive(bOn)
652  {
653  this->updateResultActive();
654  }
655 
656  /// Get the A input value.
657  const AValueType& a() const { return *mAValPtr; }
658  /// Get the B input value.
659  const BValueType& b() const { return *mBValPtr; }
660  //@{
661  /// Get the output value.
662  const AValueType& result() const { return *mResultValPtr; }
663  AValueType& result() { return *mResultValPtr; }
664  //@}
665 
666  /// Set the output value.
667  CombineArgs& setResult(const AValueType& val) { *mResultValPtr = val; return *this; }
668 
669  /// Redirect the A value to a new external source.
670  CombineArgs& setARef(const AValueType& a) { mAValPtr = &a; return *this; }
671  /// Redirect the B value to a new external source.
672  CombineArgs& setBRef(const BValueType& b) { mBValPtr = &b; return *this; }
673  /// Redirect the result value to a new external destination.
674  CombineArgs& setResultRef(AValueType& val) { mResultValPtr = &val; return *this; }
675 
676  /// @return true if the A value is active
677  bool aIsActive() const { return mAIsActive; }
678  /// @return true if the B value is active
679  bool bIsActive() const { return mBIsActive; }
680  /// @return true if the output value is active
681  bool resultIsActive() const { return mResultIsActive; }
682 
683  /// Set the active state of the A value.
684  CombineArgs& setAIsActive(bool b) { mAIsActive = b; updateResultActive(); return *this; }
685  /// Set the active state of the B value.
686  CombineArgs& setBIsActive(bool b) { mBIsActive = b; updateResultActive(); return *this; }
687  /// Set the active state of the output value.
688  CombineArgs& setResultIsActive(bool b) { mResultIsActive = b; return *this; }
689 
690 protected:
691  /// By default, the result value is active if either of the input values is active,
692  /// but this behavior can be overridden by calling setResultIsActive().
694 
695  const AValueType* mAValPtr; // pointer to input value from A grid
696  const BValueType* mBValPtr; // pointer to input value from B grid
697  AValueType mResultVal; // computed output value (unused if stored externally)
698  AValueType* mResultValPtr; // pointer to either mResultVal or an external value
699  bool mAIsActive, mBIsActive; // active states of A and B values
700  bool mResultIsActive; // computed active state (default: A active || B active)
701 };
702 
703 
704 /// This struct adapts a "grid combiner" functor to swap the A and B grid values
705 /// (e.g., so that if the original functor computes a + 2 * b, the adapted functor
706 /// will compute b + 2 * a).
707 template<typename ValueType, typename CombineOp>
709 {
710  SwappedCombineOp(CombineOp& _op): op(_op) {}
711 
713  {
714  CombineArgs<ValueType> swappedArgs(args.b(), args.a(), args.result(),
715  args.bIsActive(), args.aIsActive());
716  op(swappedArgs);
717  }
718 
719  CombineOp& op;
720 };
721 
722 
723 ////////////////////////////////////////
724 
725 
726 #if OPENVDB_ABI_VERSION_NUMBER <= 3
727 /// In copy constructors, members stored as shared pointers can be handled
728 /// in several ways:
729 /// <dl>
730 /// <dt><b>CP_NEW</b>
731 /// <dd>Don't copy the member; default construct a new member object instead.
732 ///
733 /// <dt><b>CP_SHARE</b>
734 /// <dd>Copy the shared pointer, so that the original and new objects share
735 /// the same member.
736 ///
737 /// <dt><b>CP_COPY</b>
738 /// <dd>Create a deep copy of the member.
739 /// </dl>
740 /// @deprecated ABI versions older than 4 are deprecated.
741 enum OPENVDB_DEPRECATED CopyPolicy { CP_NEW, CP_SHARE, CP_COPY };
742 #endif
743 
744 
745 /// @brief Tag dispatch class that distinguishes shallow copy constructors
746 /// from deep copy constructors
747 class ShallowCopy {};
748 /// @brief Tag dispatch class that distinguishes topology copy constructors
749 /// from deep copy constructors
750 class TopologyCopy {};
751 /// @brief Tag dispatch class that distinguishes constructors during file input
752 class PartialCreate {};
753 
754 } // namespace OPENVDB_VERSION_NAME
755 } // namespace openvdb
756 
757 
758 #if defined(__ICC)
759 
760 // Use these defines to bracket a region of code that has safe static accesses.
761 // Keep the region as small as possible.
762 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
763 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
764 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
765 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
766 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
767 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
768 
769 // Use these defines to bracket a region of code that has unsafe static accesses.
770 // Keep the region as small as possible.
771 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
772 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
773 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
774 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
775 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
776 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
777 
778 // Simpler version for one-line cases
779 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
780  __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
781 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
782  __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
783 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
784  __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
785 
786 #else // GCC does not support these compiler warnings
787 
788 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
789 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
790 #define OPENVDB_START_THREADSAFE_STATIC_WRITE
791 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
792 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
793 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
794 
795 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
796 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
797 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
798 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
799 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
800 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
801 
802 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
803 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
804 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
805 
806 #endif // defined(__ICC)
807 
808 #endif // OPENVDB_TYPES_HAS_BEEN_INCLUDED
809 
810 // Copyright (c) DreamWorks Animation LLC
811 // All rights reserved. This software is distributed under the
812 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
const AValueType & result() const
Get the output value.
Definition: Types.h:662
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:171
PointIndex operator+(T x)
Needed to support the (zeroVal<PointIndex>() + val) idiom.
Definition: Types.h:198
const char * typeNameAsString< ValueMask >()
Definition: Types.h:567
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:617
typename T::ValueType ElementType
Definition: Types.h:290
GLsizeiptr size
Definition: glew.h:1681
GLuint const GLchar * name
Definition: glew.h:1814
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: Types.h:747
const char * typeNameAsString< PointIndex32 >()
Definition: Types.h:596
const Args & args
Definition: printf.h:628
typename T::ValueType ElementType
Definition: Types.h:235
const char * typeNameAsString< int32_t >()
Definition: Types.h:575
GLuint const GLfloat * val
Definition: glew.h:2794
const char * typeNameAsString< Vec3i >()
Definition: Types.h:583
const char * typeNameAsString< uint16_t >()
Definition: Types.h:574
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:646
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition: Types.h:686
const char * typeNameAsString< int8_t >()
Definition: Types.h:571
const char * typeNameAsString< int16_t >()
Definition: Types.h:573
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:200
const char * typeNameAsString< Mat3s >()
Definition: Types.h:590
const char * typeNameAsString< half >()
Definition: Types.h:568
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:52
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:752
const char * typeNameAsString< PointIndex64 >()
Definition: Types.h:597
const char * typeNameAsString< Vec3d >()
Definition: Types.h:585
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:151
const char * typeNameAsString< Mat4s >()
Definition: Types.h:592
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
const AValueType & a() const
Get the A input value.
Definition: Types.h:657
const char * typeNameAsString< Vec3U16 >()
Definition: Types.h:582
Helper metafunction used to determine if the first template parameter is a specialization of the clas...
Definition: Types.h:219
const char * typeNameAsString< Vec3f >()
Definition: Types.h:584
const char * typeNameAsString< PointDataIndex32 >()
Definition: Types.h:598
const char * typeNameAsString< uint32_t >()
Definition: Types.h:576
std::weak_ptr< T > WeakPtr
Definition: Types.h:140
typename internal::TSAppendImpl< Self, TypesToAppend...>::type Append
Append types, or the members of another TypeList, to this list.
Definition: Types.h:458
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
PointIndex(T i)
Explicit type conversion constructor.
Definition: Types.h:192
#define OPENVDB_DEPRECATED
Definition: Platform.h:69
const char * typeNameAsString< uint8_t >()
Definition: Types.h:572
const char * typeNameAsString< float >()
Definition: Types.h:569
const char * typeNameAsString< Vec2i >()
Definition: Types.h:578
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:684
typename std::remove_const< ToType >::type Type
Definition: Types.h:348
const char * typeNameAsString()
Definition: Types.h:565
const char * typeNameAsString< int64_t >()
Definition: Types.h:577
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:275
CopyConstness<T1, T2>::Type is either const T2 or T2 with no const qualifier, depending on whether T1...
Definition: Types.h:347
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
const char * typeNameAsString< Vec4d >()
Definition: Types.h:588
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:634
CombineArgs & setResultIsActive(bool b)
Set the active state of the output value.
Definition: Types.h:688
const char * typeNameAsString< double >()
Definition: Types.h:570
TypeList Self
The type of this list.
Definition: Types.h:442
CanConvertType<FromType, ToType>::value is true if a value of type ToType can be constructed from a v...
Definition: Types.h:312
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:161
typename T::ValueType ElementType
Definition: Types.h:268
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
const char * typeNameAsString< bool >()
Definition: Types.h:566
AValueType & result()
Get the output value.
Definition: Types.h:663
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:672
const void * ptr(const T *p)
Definition: format.h:3292
const char * typeNameAsString< Mat4d >()
Definition: Types.h:593
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition: Types.h:674
const char * typeNameAsString< Vec3U8 >()
Definition: Types.h:581
const char * typeNameAsString< Vec2d >()
Definition: Types.h:580
typename internal::TSRemoveImpl< Self, TypesToRemove...>::type Remove
Remove all occurrences of one or more types, or the members of another TypeList, from this list...
Definition: Types.h:471
void operator()(CombineArgs< ValueType > &args)
Definition: Types.h:712
unsigned char Byte
Definition: Types.h:66
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:670
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:183
GLuint64EXT * result
Definition: glew.h:14007
const char * typeNameAsString< Vec4f >()
Definition: Types.h:587
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:750
const BValueType & b() const
Get the B input value.
Definition: Types.h:659
#define const
Definition: zconf.h:214
const char * typeNameAsString< Vec4i >()
Definition: Types.h:586
typename T::ValueType ElementType
Definition: Types.h:251
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:146
GLsizei const GLfloat * value
Definition: glew.h:1849
A list of types (not necessarily unique)
Definition: Types.h:439
const char * typeNameAsString< PointDataIndex64 >()
Definition: Types.h:599
CombineArgs & setResult(const AValueType &val)
Set the output value.
Definition: Types.h:667
const char * typeNameAsString< Vec2s >()
Definition: Types.h:579
type
Definition: core.h:528
PointIndex(IntType i=IntType(0))
Definition: Types.h:189
const char * typeNameAsString< Mat3d >()
Definition: Types.h:591