OpenVDB  2.3.0
Types.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 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 
49 
50 namespace openvdb {
52 namespace OPENVDB_VERSION_NAME {
53 
54 // One-dimensional scalar types
55 typedef uint32_t Index32;
56 typedef uint64_t Index64;
57 typedef Index32 Index;
58 typedef int16_t Int16;
59 typedef int32_t Int32;
60 typedef int64_t Int64;
61 typedef Int32 Int;
62 typedef unsigned char Byte;
63 typedef double Real;
64 
65 // Two-dimensional vector types
70 using math::Vec2i;
71 using math::Vec2s;
72 using math::Vec2d;
73 
74 // Three-dimensional vector types
79 using math::Vec3i;
80 using math::Vec3s;
81 using math::Vec3d;
82 
83 using math::Coord;
84 using math::CoordBBox;
86 
87 // Four-dimensional vector types
92 using math::Vec4i;
93 using math::Vec4s;
94 using math::Vec4d;
95 
96 // Three-dimensional matrix types
98 
99 // Four-dimensional matrix types
103 
104 // Compressed Hermite data
106 
107 // Quaternions
109 
110 
112 
113 
114 template<typename T> struct VecTraits {
115  static const bool IsVec = false;
116  static const int Size = 1;
117 };
118 template<typename T> struct VecTraits<math::Vec2<T> > {
119  static const bool IsVec = true;
120  static const int Size = 2;
121 };
122 template<typename T> struct VecTraits<math::Vec3<T> > {
123  static const bool IsVec = true;
124  static const int Size = 3;
125 };
126 template<typename T> struct VecTraits<math::Vec4<T> > {
127  static const bool IsVec = true;
128  static const int Size = 4;
129 };
130 
131 
133 
134 
144 template<typename FromType, typename ToType>
145 struct CanConvertType { enum { value = boost::is_convertible<FromType, ToType>::value }; };
146 
147 // Specializations for vector types, which can be constructed from values
148 // of their own ValueTypes (or values that can be converted to their ValueTypes),
149 // but only explicitly
150 template<typename T> struct CanConvertType<T, math::Vec2<T> > { enum { value = true }; };
151 template<typename T> struct CanConvertType<T, math::Vec3<T> > { enum { value = true }; };
152 template<typename T> struct CanConvertType<T, math::Vec4<T> > { enum { value = true }; };
153 template<typename T> struct CanConvertType<math::Vec2<T>, math::Vec2<T> > { enum {value = true}; };
154 template<typename T> struct CanConvertType<math::Vec3<T>, math::Vec3<T> > { enum {value = true}; };
155 template<typename T> struct CanConvertType<math::Vec4<T>, math::Vec4<T> > { enum {value = true}; };
156 template<typename T0, typename T1>
157 struct CanConvertType<T0, math::Vec2<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
158 template<typename T0, typename T1>
159 struct CanConvertType<T0, math::Vec3<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
160 template<typename T0, typename T1>
161 struct CanConvertType<T0, math::Vec4<T1> > { enum { value = CanConvertType<T0, T1>::value }; };
162 
163 
165 
166 
167 // Add new items to the *end* of this list, and update NUM_GRID_CLASSES.
168 enum GridClass {
173 };
175 
176 static const Real LEVEL_SET_HALF_WIDTH = 3;
177 
198 enum VecType {
204 };
206 
207 
225 };
226 
227 
229 
230 
231 template<typename T> const char* typeNameAsString() { return typeid(T).name(); }
232 template<> inline const char* typeNameAsString<bool>() { return "bool"; }
233 template<> inline const char* typeNameAsString<float>() { return "float"; }
234 template<> inline const char* typeNameAsString<double>() { return "double"; }
235 template<> inline const char* typeNameAsString<int32_t>() { return "int32"; }
236 template<> inline const char* typeNameAsString<uint32_t>() { return "uint32"; }
237 template<> inline const char* typeNameAsString<int64_t>() { return "int64"; }
238 template<> inline const char* typeNameAsString<Hermite>() { return "Hermite"; }
239 template<> inline const char* typeNameAsString<Vec2i>() { return "vec2i"; }
240 template<> inline const char* typeNameAsString<Vec2s>() { return "vec2s"; }
241 template<> inline const char* typeNameAsString<Vec2d>() { return "vec2d"; }
242 template<> inline const char* typeNameAsString<Vec3i>() { return "vec3i"; }
243 template<> inline const char* typeNameAsString<Vec3f>() { return "vec3s"; }
244 template<> inline const char* typeNameAsString<Vec3d>() { return "vec3d"; }
245 template<> inline const char* typeNameAsString<std::string>() { return "string"; }
246 template<> inline const char* typeNameAsString<Mat4s>() { return "mat4s"; }
247 template<> inline const char* typeNameAsString<Mat4d>() { return "mat4d"; }
248 
249 
251 
252 
264 template<typename AValueType, typename BValueType = AValueType>
266 {
267 public:
268  typedef AValueType AValueT;
269  typedef BValueType BValueT;
270 
272  mAValPtr(NULL), mBValPtr(NULL), mResultValPtr(&mResultVal),
273  mAIsActive(false), mBIsActive(false), mResultIsActive(false)
274  {}
275 
277  CombineArgs(const AValueType& a, const BValueType& b, AValueType& result,
278  bool aOn = false, bool bOn = false):
279  mAValPtr(&a), mBValPtr(&b), mResultValPtr(&result),
280  mAIsActive(aOn), mBIsActive(bOn)
281  { updateResultActive(); }
282 
284  CombineArgs(const AValueType& a, const BValueType& b, bool aOn = false, bool bOn = false):
285  mAValPtr(&a), mBValPtr(&b), mResultValPtr(&mResultVal),
286  mAIsActive(aOn), mBIsActive(bOn)
287  { updateResultActive(); }
288 
290  const AValueType& a() const { return *mAValPtr; }
292  const BValueType& b() const { return *mBValPtr; }
294  const AValueType& result() const { return *mResultValPtr; }
296  AValueType& result() { return *mResultValPtr; }
298 
300  CombineArgs& setResult(const AValueType& val) { *mResultValPtr = val; return *this; }
301 
303  CombineArgs& setARef(const AValueType& a) { mAValPtr = &a; return *this; }
305  CombineArgs& setBRef(const BValueType& b) { mBValPtr = &b; return *this; }
307  CombineArgs& setResultRef(AValueType& val) { mResultValPtr = &val; return *this; }
308 
310  bool aIsActive() const { return mAIsActive; }
312  bool bIsActive() const { return mBIsActive; }
314  bool resultIsActive() const { return mResultIsActive; }
315 
317  CombineArgs& setAIsActive(bool b) { mAIsActive = b; updateResultActive(); return *this; }
319  CombineArgs& setBIsActive(bool b) { mBIsActive = b; updateResultActive(); return *this; }
321  CombineArgs& setResultIsActive(bool b) { mResultIsActive = b; return *this; }
322 
323 protected:
326  void updateResultActive() { mResultIsActive = mAIsActive || mBIsActive; }
327 
328  const AValueType* mAValPtr; // pointer to input value from A grid
329  const BValueType* mBValPtr; // pointer to input value from B grid
330  AValueType mResultVal; // computed output value (unused if stored externally)
331  AValueType* mResultValPtr; // pointer to either mResultVal or an external value
332  bool mAIsActive, mBIsActive; // active states of A and B values
333  bool mResultIsActive; // computed active state (default: A active || B active)
334 };
335 
336 
340 template<typename ValueType, typename CombineOp>
342 {
343  SwappedCombineOp(CombineOp& _op): op(_op) {}
344 
346  {
347  CombineArgs<ValueType> swappedArgs(args.b(), args.a(), args.result(),
348  args.bIsActive(), args.aIsActive());
349  op(swappedArgs);
350  }
351 
352  CombineOp& op;
353 };
354 
355 
357 
358 
373 
374 
375 // Dummy class that distinguishes shallow copy constructors from
376 // deep copy constructors
377 class ShallowCopy {};
378 // Dummy class that distinguishes topology copy constructors from
379 // deep copy constructors
380 class TopologyCopy {};
381 
382 } // namespace OPENVDB_VERSION_NAME
383 } // namespace openvdb
384 
385 
386 #if defined(__ICC)
387 
388 // Use these defines to bracket a region of code that has safe static accesses.
389 // Keep the region as small as possible.
390 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
391 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
392 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
393 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
394 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
395 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
396 
397 // Use these defines to bracket a region of code that has unsafe static accesses.
398 // Keep the region as small as possible.
399 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
400 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
401 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
402 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
403 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
404 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
405 
406 // Simpler version for one-line cases
407 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
408  __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
409 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
410  __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
411 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
412  __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
413 
414 #else // GCC does not support these compiler warnings
415 
416 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
417 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
418 #define OPENVDB_START_THREADSAFE_STATIC_WRITE
419 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
420 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
421 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
422 
423 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
424 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
425 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
426 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
427 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
428 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
429 
430 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
431 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
432 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
433 
434 #endif // defined(__ICC)
435 
436 #endif // OPENVDB_TYPES_HAS_BEEN_INCLUDED
437 
438 // Copyright (c) 2012-2013 DreamWorks Animation LLC
439 // All rights reserved. This software is distributed under the
440 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
bool resultIsActive() const
Definition: Types.h:314
const char * typeNameAsString< Vec3d >()
Definition: Types.h:244
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition: Types.h:317
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:229
int16_t Int16
Definition: Types.h:58
math::Vec3< Real > Vec3R
Definition: Types.h:75
Vec2< int32_t > Vec2i
Definition: Vec2.h:518
Definition: Types.h:174
Vec2< double > Vec2d
Definition: Vec2.h:521
AValueType AValueT
Definition: Types.h:268
Definition: Types.h:372
math::Vec3< float > Vec3f
Definition: Types.h:77
CanConvertType::value is true if a value of type ToType can be constructed from a v...
Definition: Types.h:145
math::BBox< Vec3d > BBoxd
Definition: Types.h:85
math::Vec3< Index32 > Vec3I
Definition: Types.h:76
VecType
Definition: Types.h:198
const char * typeNameAsString< Vec3i >()
Definition: Types.h:242
math::Vec2< Real > Vec2R
Definition: Types.h:66
math::Vec2< Index32 > Vec2I
Definition: Types.h:67
math::Vec4< half > Vec4H
Definition: Types.h:91
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:303
Index32 Index
Definition: Types.h:57
const char * typeNameAsString< Mat4d >()
Definition: Types.h:247
Definition: Types.h:200
const char * typeNameAsString< Vec2i >()
Definition: Types.h:239
const char * typeNameAsString< int64_t >()
Definition: Types.h:237
Definition: Types.h:341
const char * typeNameAsString()
Definition: Types.h:231
const AValueType * mAValPtr
Definition: Types.h:328
math::Vec4< float > Vec4f
Definition: Types.h:90
bool aIsActive() const
Definition: Types.h:310
Definition: Mat.h:145
MergePolicy
Definition: Types.h:221
math::Vec2< float > Vec2f
Definition: Types.h:68
Vec4< int32_t > Vec4i
Definition: Vec4.h:543
const char * typeNameAsString< float >()
Definition: Types.h:233
math::Vec2< half > Vec2H
Definition: Types.h:69
CombineArgs & setResult(const AValueType &val)
Set the output value.
Definition: Types.h:300
3x3 matrix class.
Definition: Mat3.h:54
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:176
bool bIsActive() const
Definition: Types.h:312
const AValueType & result() const
Get the output value.
Definition: Types.h:295
math::Quat< Real > QuatR
Definition: Types.h:108
Definition: Types.h:372
const char * typeNameAsString< int32_t >()
Definition: Types.h:235
GridClass
Definition: Types.h:168
Definition: Types.h:170
const BValueType * mBValPtr
Definition: Types.h:329
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition: Types.h:307
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:265
math::Mat4< Real > Mat4R
Definition: Types.h:100
Definition: Types.h:114
bool mBIsActive
Definition: Types.h:332
math::Mat4< double > Mat4d
Definition: Types.h:101
uint64_t Index64
Definition: Types.h:56
#define OPENVDB_VERSION_NAME
Definition: version.h:45
void operator()(CombineArgs< ValueType > &args)
Definition: Types.h:345
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
Definition: Types.h:172
CopyPolicy
Definition: Types.h:372
math::Hermite Hermite
Definition: Types.h:105
const char * typeNameAsString< uint32_t >()
Definition: Types.h:236
CombineOp & op
Definition: Types.h:352
Definition: Types.h:223
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition: Types.h:319
Definition: Types.h:171
const AValueType & a() const
Get the A input value.
Definition: Types.h:290
bool mResultIsActive
Definition: Types.h:333
Vec3< int32_t > Vec3i
Definition: Vec3.h:622
unsigned char Byte
Definition: Types.h:62
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:305
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:284
uint32_t Index32
Definition: Types.h:55
const char * typeNameAsString< Mat4s >()
Definition: Types.h:246
const char * typeNameAsString< bool >()
Definition: Types.h:232
int32_t Int32
Definition: Types.h:59
math::Mat4< float > Mat4s
Definition: Types.h:102
math::Vec4< Index32 > Vec4I
Definition: Types.h:89
Vec2< float > Vec2s
Definition: Vec2.h:520
const BValueType & b() const
Get the B input value.
Definition: Types.h:292
Vec3< double > Vec3d
Definition: Vec3.h:625
math::Vec3< half > Vec3H
Definition: Types.h:78
AValueType mResultVal
Definition: Types.h:330
Definition: Types.h:372
int64_t Int64
Definition: Types.h:60
Definition: Vec2.h:48
Vec3< float > Vec3s
Definition: Vec3.h:624
math::Vec4< Real > Vec4R
Definition: Types.h:88
AValueType * mResultValPtr
Definition: Types.h:331
Definition: Types.h:169
void updateResultActive()
Definition: Types.h:326
Definition: Types.h:205
Vec4< float > Vec4s
Definition: Vec4.h:545
CombineArgs()
Definition: Types.h:271
math::Mat3< Real > Mat3R
Definition: Types.h:97
SwappedCombineOp(CombineOp &_op)
Definition: Types.h:343
double Real
Definition: Types.h:63
Definition: Types.h:199
Int32 Int
Definition: Types.h:61
const char * typeNameAsString< double >()
Definition: Types.h:234
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:277
Vec4< double > Vec4d
Definition: Vec4.h:546
const char * typeNameAsString< Vec2d >()
Definition: Types.h:241
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
Definition: Types.h:380
const char * typeNameAsString< Vec3f >()
Definition: Types.h:243
const char * typeNameAsString< Vec2s >()
Definition: Types.h:240
AValueType & result()
Get the output value.
Definition: Types.h:296
Definition: Types.h:377
BValueType BValueT
Definition: Types.h:269
CombineArgs & setResultIsActive(bool b)
Set the active state of the output value.
Definition: Types.h:321
Definition: Mat4.h:51
Quantized Hermite data object that stores compressed intersection information (offsets and normlas) f...
Definition: Hermite.h:66
const char * typeNameAsString< Hermite >()
Definition: Types.h:238