OpenVDB  3.0.0
Types.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2014 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 //
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 <openvdb/math/Hermite.h>
47 #include <boost/type_traits/is_convertible.hpp>
48 #include <boost/type_traits/is_integral.hpp>
49 #include <boost/static_assert.hpp>
50 
51 
52 namespace openvdb {
54 namespace OPENVDB_VERSION_NAME {
55 
56 // One-dimensional scalar types
57 typedef uint32_t Index32;
58 typedef uint64_t Index64;
59 typedef Index32 Index;
60 typedef int16_t Int16;
61 typedef int32_t Int32;
62 typedef int64_t Int64;
63 typedef Int32 Int;
64 typedef unsigned char Byte;
65 typedef double Real;
66 
67 // Two-dimensional vector types
72 using math::Vec2i;
73 using math::Vec2s;
74 using math::Vec2d;
75 
76 // Three-dimensional vector types
81 using math::Vec3i;
82 using math::Vec3s;
83 using math::Vec3d;
84 
85 using math::Coord;
86 using math::CoordBBox;
88 
89 // Four-dimensional vector types
94 using math::Vec4i;
95 using math::Vec4s;
96 using math::Vec4d;
97 
98 // Three-dimensional matrix types
100 
101 // Four-dimensional matrix types
105 
106 // Compressed Hermite data
108 
109 // Quaternions
111 
112 
114 
115 
119 template<typename IntType_, Index Kind>
121 {
122  BOOST_STATIC_ASSERT(boost::is_integral<IntType_>::value);
123 
124  typedef IntType_ IntType;
125 
126  PointIndex(IntType i = IntType(0)): mIndex(i) {}
127 
128  operator IntType() const { return mIndex; }
129 
131  template<typename T>
132  PointIndex operator+(T x) { return PointIndex(mIndex + IntType(x)); }
133 
134 private:
135  IntType mIndex;
136 };
137 
138 
141 
144 
145 
147 
148 
149 template<typename T> struct VecTraits {
150  static const bool IsVec = false;
151  static const int Size = 1;
152  typedef T ElementType;
153 };
154 template<typename T> struct VecTraits<math::Vec2<T> > {
155  static const bool IsVec = true;
156  static const int Size = 2;
157  typedef T ElementType;
158 };
159 template<typename T> struct VecTraits<math::Vec3<T> > {
160  static const bool IsVec = true;
161  static const int Size = 3;
162  typedef T ElementType;
163 };
164 template<typename T> struct VecTraits<math::Vec4<T> > {
165  static const bool IsVec = true;
166  static const int Size = 4;
167  typedef T ElementType;
168 };
169 
170 
172 
173 
183 template<typename FromType, typename ToType>
184 struct CanConvertType { enum { value = boost::is_convertible<FromType, ToType>::value }; };
185 
186 // Specializations for vector types, which can be constructed from values
187 // of their own ValueTypes (or values that can be converted to their ValueTypes),
188 // but only explicitly
189 template<typename T> struct CanConvertType<T, math::Vec2<T> > { enum { value = true }; };
190 template<typename T> struct CanConvertType<T, math::Vec3<T> > { enum { value = true }; };
191 template<typename T> struct CanConvertType<T, math::Vec4<T> > { enum { value = true }; };
192 template<typename T> struct CanConvertType<math::Vec2<T>, math::Vec2<T> > { enum {value = true}; };
193 template<typename T> struct CanConvertType<math::Vec3<T>, math::Vec3<T> > { enum {value = true}; };
194 template<typename T> struct CanConvertType<math::Vec4<T>, math::Vec4<T> > { enum {value = true}; };
195 template<typename T0, typename T1>
196 struct CanConvertType<T0, math::Vec2<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
197 template<typename T0, typename T1>
198 struct CanConvertType<T0, math::Vec3<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
199 template<typename T0, typename T1>
200 struct CanConvertType<T0, math::Vec4<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
201 template<> struct CanConvertType<PointIndex32, PointDataIndex32> { enum {value = true}; };
202 template<> struct CanConvertType<PointDataIndex32, PointIndex32> { enum {value = true}; };
203 
205 
206 
207 // Add new items to the *end* of this list, and update NUM_GRID_CLASSES.
208 enum GridClass {
213 };
215 
216 static const Real LEVEL_SET_HALF_WIDTH = 3;
217 
238 enum VecType {
244 };
246 
247 
265 };
266 
267 
269 
270 
271 template<typename T> const char* typeNameAsString() { return typeid(T).name(); }
272 template<> inline const char* typeNameAsString<bool>() { return "bool"; }
273 template<> inline const char* typeNameAsString<float>() { return "float"; }
274 template<> inline const char* typeNameAsString<double>() { return "double"; }
275 template<> inline const char* typeNameAsString<int32_t>() { return "int32"; }
276 template<> inline const char* typeNameAsString<uint32_t>() { return "uint32"; }
277 template<> inline const char* typeNameAsString<int64_t>() { return "int64"; }
278 template<> inline const char* typeNameAsString<Hermite>() { return "Hermite"; }
279 template<> inline const char* typeNameAsString<Vec2i>() { return "vec2i"; }
280 template<> inline const char* typeNameAsString<Vec2s>() { return "vec2s"; }
281 template<> inline const char* typeNameAsString<Vec2d>() { return "vec2d"; }
282 template<> inline const char* typeNameAsString<Vec3i>() { return "vec3i"; }
283 template<> inline const char* typeNameAsString<Vec3f>() { return "vec3s"; }
284 template<> inline const char* typeNameAsString<Vec3d>() { return "vec3d"; }
285 template<> inline const char* typeNameAsString<std::string>() { return "string"; }
286 template<> inline const char* typeNameAsString<Mat4s>() { return "mat4s"; }
287 template<> inline const char* typeNameAsString<Mat4d>() { return "mat4d"; }
288 template<> inline const char* typeNameAsString<PointIndex32>() { return "ptidx32"; }
289 template<> inline const char* typeNameAsString<PointIndex64>() { return "ptidx64"; }
290 template<> inline const char* typeNameAsString<PointDataIndex32>() { return "ptdataidx32"; }
291 template<> inline const char* typeNameAsString<PointDataIndex64>() { return "ptdataidx64"; }
292 
293 
295 
296 
308 template<typename AValueType, typename BValueType = AValueType>
310 {
311 public:
312  typedef AValueType AValueT;
313  typedef BValueType BValueT;
314 
316  mAValPtr(NULL), mBValPtr(NULL), mResultValPtr(&mResultVal),
317  mAIsActive(false), mBIsActive(false), mResultIsActive(false)
318  {}
319 
321  CombineArgs(const AValueType& a, const BValueType& b, AValueType& result,
322  bool aOn = false, bool bOn = false):
323  mAValPtr(&a), mBValPtr(&b), mResultValPtr(&result),
324  mAIsActive(aOn), mBIsActive(bOn)
325  { updateResultActive(); }
326 
328  CombineArgs(const AValueType& a, const BValueType& b, bool aOn = false, bool bOn = false):
329  mAValPtr(&a), mBValPtr(&b), mResultValPtr(&mResultVal),
330  mAIsActive(aOn), mBIsActive(bOn)
331  { updateResultActive(); }
332 
334  const AValueType& a() const { return *mAValPtr; }
336  const BValueType& b() const { return *mBValPtr; }
338  const AValueType& result() const { return *mResultValPtr; }
340  AValueType& result() { return *mResultValPtr; }
342 
344  CombineArgs& setResult(const AValueType& val) { *mResultValPtr = val; return *this; }
345 
347  CombineArgs& setARef(const AValueType& a) { mAValPtr = &a; return *this; }
349  CombineArgs& setBRef(const BValueType& b) { mBValPtr = &b; return *this; }
351  CombineArgs& setResultRef(AValueType& val) { mResultValPtr = &val; return *this; }
352 
354  bool aIsActive() const { return mAIsActive; }
356  bool bIsActive() const { return mBIsActive; }
358  bool resultIsActive() const { return mResultIsActive; }
359 
361  CombineArgs& setAIsActive(bool b) { mAIsActive = b; updateResultActive(); return *this; }
363  CombineArgs& setBIsActive(bool b) { mBIsActive = b; updateResultActive(); return *this; }
365  CombineArgs& setResultIsActive(bool b) { mResultIsActive = b; return *this; }
366 
367 protected:
370  void updateResultActive() { mResultIsActive = mAIsActive || mBIsActive; }
371 
372  const AValueType* mAValPtr; // pointer to input value from A grid
373  const BValueType* mBValPtr; // pointer to input value from B grid
374  AValueType mResultVal; // computed output value (unused if stored externally)
375  AValueType* mResultValPtr; // pointer to either mResultVal or an external value
376  bool mAIsActive, mBIsActive; // active states of A and B values
377  bool mResultIsActive; // computed active state (default: A active || B active)
378 };
379 
380 
384 template<typename ValueType, typename CombineOp>
386 {
387  SwappedCombineOp(CombineOp& _op): op(_op) {}
388 
390  {
391  CombineArgs<ValueType> swappedArgs(args.b(), args.a(), args.result(),
392  args.bIsActive(), args.aIsActive());
393  op(swappedArgs);
394  }
395 
396  CombineOp& op;
397 };
398 
399 
401 
402 
417 
418 
419 // Dummy class that distinguishes shallow copy constructors from
420 // deep copy constructors
421 class ShallowCopy {};
422 // Dummy class that distinguishes topology copy constructors from
423 // deep copy constructors
424 class TopologyCopy {};
425 // Dummy class that distinguishes constructors during file input
426 class PartialCreate {};
427 
428 } // namespace OPENVDB_VERSION_NAME
429 } // namespace openvdb
430 
431 
432 #if defined(__ICC)
433 
434 // Use these defines to bracket a region of code that has safe static accesses.
435 // Keep the region as small as possible.
436 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
437 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
438 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
439 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
440 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
441 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
442 
443 // Use these defines to bracket a region of code that has unsafe static accesses.
444 // Keep the region as small as possible.
445 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
446 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
447 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
448 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
449 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
450 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
451 
452 // Simpler version for one-line cases
453 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
454  __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
455 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
456  __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
457 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
458  __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
459 
460 #else // GCC does not support these compiler warnings
461 
462 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
463 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
464 #define OPENVDB_START_THREADSAFE_STATIC_WRITE
465 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
466 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
467 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
468 
469 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
470 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
471 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
472 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
473 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
474 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
475 
476 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
477 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
478 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
479 
480 #endif // defined(__ICC)
481 
482 #endif // OPENVDB_TYPES_HAS_BEEN_INCLUDED
483 
484 // Copyright (c) 2012-2014 DreamWorks Animation LLC
485 // All rights reserved. This software is distributed under the
486 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
int64_t Int64
Definition: Types.h:62
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:349
Definition: Types.h:424
Int32 Int
Definition: Types.h:63
Definition: Types.h:240
const char * typeNameAsString< Vec3d >()
Definition: Types.h:284
const char * typeNameAsString< Mat4d >()
Definition: Types.h:287
PointIndex(IntType i=IntType(0))
Definition: Types.h:126
AValueType mResultVal
Definition: Types.h:374
const char * typeNameAsString< float >()
Definition: Types.h:273
uint64_t Index64
Definition: Types.h:58
Vec4< double > Vec4d
Definition: Vec4.h:546
T ElementType
Definition: Types.h:152
int16_t Int16
Definition: Types.h:60
math::Vec4< Index32 > Vec4I
Definition: Types.h:91
Vec4< int32_t > Vec4i
Definition: Vec4.h:543
Definition: Types.h:385
const char * typeNameAsString< PointDataIndex32 >()
Definition: Types.h:290
PointIndex operator+(T x)
Needed to support the (zeroVal() + val) idiom.
Definition: Types.h:132
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:229
math::Vec3< half > Vec3H
Definition: Types.h:80
AValueType AValueT
Definition: Types.h:312
bool resultIsActive() const
Definition: Types.h:358
const char * typeNameAsString< int32_t >()
Definition: Types.h:275
Vec2< int32_t > Vec2i
Definition: Vec2.h:518
const char * typeNameAsString< PointIndex64 >()
Definition: Types.h:289
CombineArgs()
Definition: Types.h:315
CopyPolicy
Definition: Types.h:416
bool bIsActive() const
Definition: Types.h:356
AValueType & result()
Get the output value.
Definition: Types.h:340
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
Definition: Mat.h:145
double Real
Definition: Types.h:65
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:347
Vec3< int32_t > Vec3i
Definition: Vec3.h:626
Quantized Hermite data object that stores compressed intersection information (offsets and normlas) f...
Definition: Hermite.h:66
int32_t Int32
Definition: Types.h:61
math::Mat3< Real > Mat3R
Definition: Types.h:99
const char * typeNameAsString< int64_t >()
Definition: Types.h:277
PointIndex< Index32, 0 > PointIndex32
Definition: Types.h:139
math::Vec4< Real > Vec4R
Definition: Types.h:90
Definition: Types.h:416
Definition: Types.h:210
void operator()(CombineArgs< ValueType > &args)
Definition: Types.h:389
const char * typeNameAsString< bool >()
Definition: Types.h:272
const char * typeNameAsString< Vec3f >()
Definition: Types.h:283
math::Vec3< Index32 > Vec3I
Definition: Types.h:78
Definition: Types.h:421
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Types.h:263
3x3 matrix class.
Definition: Mat3.h:54
AValueType * mResultValPtr
Definition: Types.h:375
Index32 Index
Definition: Types.h:59
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:216
PointIndex< Index64, 1 > PointDataIndex64
Definition: Types.h:143
const char * typeNameAsString< PointIndex32 >()
Definition: Types.h:288
Definition: Types.h:211
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:309
Definition: Types.h:212
SwappedCombineOp(CombineOp &_op)
Definition: Types.h:387
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition: Types.h:351
const AValueType * mAValPtr
Definition: Types.h:372
math::Vec3< Real > Vec3R
Definition: Types.h:77
PointIndex< Index32, 1 > PointDataIndex32
Definition: Types.h:142
CombineArgs & setResult(const AValueType &val)
Set the output value.
Definition: Types.h:344
const char * typeNameAsString< Vec2i >()
Definition: Types.h:279
Definition: Exceptions.h:39
Definition: Vec2.h:48
Vec4< float > Vec4s
Definition: Vec4.h:545
const BValueType * mBValPtr
Definition: Types.h:373
const char * typeNameAsString< uint32_t >()
Definition: Types.h:276
const AValueType & a() const
Get the A input value.
Definition: Types.h:334
Vec3< double > Vec3d
Definition: Vec3.h:629
math::Vec2< Real > Vec2R
Definition: Types.h:68
const AValueType & result() const
Get the output value.
Definition: Types.h:339
MergePolicy
Definition: Types.h:261
Definition: Types.h:149
Definition: Types.h:209
Definition: Types.h:239
const char * typeNameAsString< Hermite >()
Definition: Types.h:278
const char * typeNameAsString()
Definition: Types.h:271
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:321
math::Vec4< float > Vec4f
Definition: Types.h:92
PointIndex< Index64, 0 > PointIndex64
Definition: Types.h:140
unsigned char Byte
Definition: Types.h:64
math::Mat4< Real > Mat4R
Definition: Types.h:102
math::Vec3< float > Vec3f
Definition: Types.h:79
BValueType BValueT
Definition: Types.h:313
GridClass
Definition: Types.h:208
bool mBIsActive
Definition: Types.h:376
const char * typeNameAsString< Vec2s >()
Definition: Types.h:280
math::Hermite Hermite
Definition: Types.h:107
bool mResultIsActive
Definition: Types.h:377
const char * typeNameAsString< double >()
Definition: Types.h:274
const char * typeNameAsString< Vec2d >()
Definition: Types.h:281
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition: Types.h:361
CanConvertType::value is true if a value of type ToType can be constructed from a v...
Definition: Types.h:184
Vec2< float > Vec2s
Definition: Vec2.h:520
Definition: Types.h:416
math::Vec2< half > Vec2H
Definition: Types.h:71
CombineArgs & setResultIsActive(bool b)
Set the active state of the output value.
Definition: Types.h:365
void updateResultActive()
Definition: Types.h:370
const char * typeNameAsString< PointDataIndex64 >()
Definition: Types.h:291
Definition: Mat4.h:51
uint32_t Index32
Definition: Types.h:57
Definition: Types.h:426
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition: Types.h:363
const char * typeNameAsString< Vec3i >()
Definition: Types.h:282
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Vec3< float > Vec3s
Definition: Vec3.h:628
VecType
Definition: Types.h:238
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:120
math::BBox< Vec3d > BBoxd
Definition: Types.h:87
math::Vec2< float > Vec2f
Definition: Types.h:70
math::Vec4< half > Vec4H
Definition: Types.h:93
Definition: Types.h:214
math::Vec2< Index32 > Vec2I
Definition: Types.h:69
math::Quat< Real > QuatR
Definition: Types.h:110
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:328
math::Mat4< double > Mat4d
Definition: Types.h:103
Vec2< double > Vec2d
Definition: Vec2.h:521
IntType_ IntType
Definition: Types.h:124
const char * typeNameAsString< Mat4s >()
Definition: Types.h:286
math::Mat4< float > Mat4s
Definition: Types.h:104
Definition: Types.h:245
bool aIsActive() const
Definition: Types.h:354
const BValueType & b() const
Get the B input value.
Definition: Types.h:336
CombineOp & op
Definition: Types.h:396
Definition: Types.h:416