OpenVDB  2.0.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 
48 
49 namespace openvdb {
51 namespace OPENVDB_VERSION_NAME {
52 
53 // One-dimensional scalar types
54 typedef uint32_t Index32;
55 typedef uint64_t Index64;
56 typedef Index32 Index;
57 typedef int16_t Int16;
58 typedef int32_t Int32;
59 typedef int64_t Int64;
60 typedef Int32 Int;
61 typedef unsigned char Byte;
62 typedef double Real;
63 
64 // Two-dimensional vector types
69 using math::Vec2i;
70 using math::Vec2s;
71 using math::Vec2d;
72 
73 // Three-dimensional vector types
78 using math::Vec3i;
79 using math::Vec3s;
80 using math::Vec3d;
81 
82 using math::Coord;
83 using math::CoordBBox;
85 
86 // Four-dimensional vector types
91 using math::Vec4i;
92 using math::Vec4s;
93 using math::Vec4d;
94 
95 // Three-dimensional matrix types
97 
98 // Four-dimensional matrix types
102 
103 // Compressed Hermite data
105 
106 // Quaternions
108 
109 
111 
112 
113 template<typename T> struct VecTraits {
114  static const bool IsVec = false;
115  static const int Size = 1;
116 };
117 template<typename T> struct VecTraits<math::Vec2<T> > {
118  static const bool IsVec = true;
119  static const int Size = 2;
120 };
121 template<typename T> struct VecTraits<math::Vec3<T> > {
122  static const bool IsVec = true;
123  static const int Size = 3;
124 };
125 template<typename T> struct VecTraits<math::Vec4<T> > {
126  static const bool IsVec = true;
127  static const int Size = 4;
128 };
129 
130 
132 
133 
134 // Add new items to the *end* of this list, and update NUM_GRID_CLASSES.
135 enum GridClass {
140 };
142 
143 static const Real LEVEL_SET_HALF_WIDTH = 3;
144 
165 enum VecType {
171 };
173 
174 
192 };
193 
194 
196 
197 
198 template<typename T> const char* typeNameAsString() { return typeid(T).name(); }
199 template<> inline const char* typeNameAsString<bool>() { return "bool"; }
200 template<> inline const char* typeNameAsString<float>() { return "float"; }
201 template<> inline const char* typeNameAsString<double>() { return "double"; }
202 template<> inline const char* typeNameAsString<int32_t>() { return "int32"; }
203 template<> inline const char* typeNameAsString<uint32_t>() { return "uint32"; }
204 template<> inline const char* typeNameAsString<int64_t>() { return "int64"; }
205 template<> inline const char* typeNameAsString<Hermite>() { return "Hermite"; }
206 template<> inline const char* typeNameAsString<Vec2i>() { return "vec2i"; }
207 template<> inline const char* typeNameAsString<Vec2s>() { return "vec2s"; }
208 template<> inline const char* typeNameAsString<Vec2d>() { return "vec2d"; }
209 template<> inline const char* typeNameAsString<Vec3i>() { return "vec3i"; }
210 template<> inline const char* typeNameAsString<Vec3f>() { return "vec3s"; }
211 template<> inline const char* typeNameAsString<Vec3d>() { return "vec3d"; }
212 template<> inline const char* typeNameAsString<std::string>() { return "string"; }
213 template<> inline const char* typeNameAsString<Mat4s>() { return "mat4s"; }
214 template<> inline const char* typeNameAsString<Mat4d>() { return "mat4d"; }
215 
216 
218 
219 
231 template<typename ValueType>
233 {
234 public:
235  typedef ValueType ValueT;
236 
238  mAValPtr(NULL), mBValPtr(NULL), mResultValPtr(&mResultVal),
239  mAIsActive(false), mBIsActive(false), mResultIsActive(false)
240  {}
241 
243  CombineArgs(const ValueType& a, const ValueType& b, ValueType& result,
244  bool aOn = false, bool bOn = false):
245  mAValPtr(&a), mBValPtr(&b), mResultValPtr(&result),
246  mAIsActive(aOn), mBIsActive(bOn)
247  { updateResultActive(); }
248 
250  CombineArgs(const ValueType& a, const ValueType& b, bool aOn = false, bool bOn = false):
251  mAValPtr(&a), mBValPtr(&b), mResultValPtr(&mResultVal),
252  mAIsActive(aOn), mBIsActive(bOn)
253  { updateResultActive(); }
254 
256  const ValueType& a() const { return *mAValPtr; }
258  const ValueType& b() const { return *mBValPtr; }
260  const ValueType& result() const { return *mResultValPtr; }
262  ValueType& result() { return *mResultValPtr; }
264 
266  CombineArgs& setResult(const ValueType& val) { *mResultValPtr = val; return *this; }
267 
269  CombineArgs& setARef(const ValueType& a) { mAValPtr = &a; return *this; }
271  CombineArgs& setBRef(const ValueType& b) { mBValPtr = &b; return *this; }
273  CombineArgs& setResultRef(ValueType& val) { mResultValPtr = &val; return *this; }
274 
276  bool aIsActive() const { return mAIsActive; }
278  bool bIsActive() const { return mBIsActive; }
280  bool resultIsActive() const { return mResultIsActive; }
281 
283  CombineArgs& setAIsActive(bool b) { mAIsActive = b; updateResultActive(); return *this; }
285  CombineArgs& setBIsActive(bool b) { mBIsActive = b; updateResultActive(); return *this; }
287  CombineArgs& setResultIsActive(bool b) { mResultIsActive = b; return *this; }
288 
289 protected:
292  void updateResultActive() { mResultIsActive = mAIsActive || mBIsActive; }
293 
294  const ValueType* mAValPtr; // pointer to input value from A grid
295  const ValueType* mBValPtr; // pointer to input value from B grid
296  ValueType mResultVal; // computed output value (unused if stored externally)
297  ValueType* mResultValPtr; // pointer to either mResultVal or an external value
298  bool mAIsActive, mBIsActive; // active states of A and B values
299  bool mResultIsActive; // computed active state (default: A active || B active)
300 };
301 
302 
306 template<typename ValueType, typename CombineOp>
308 {
309  SwappedCombineOp(CombineOp& op): op(op) {}
310 
312  {
313  CombineArgs<ValueType> swappedArgs(args.b(), args.a(), args.result(),
314  args.bIsActive(), args.aIsActive());
315  op(swappedArgs);
316  }
317 
318  CombineOp& op;
319 };
320 
321 
323 
324 
339 
340 
341 // Dummy class that distinguishes shallow copy constructors from
342 // deep copy constructors
343 class ShallowCopy {};
344 // Dummy class that distinguishes topology copy constructors from
345 // deep copy constructors
346 class TopologyCopy {};
347 
348 } // namespace OPENVDB_VERSION_NAME
349 } // namespace openvdb
350 
351 
352 #if defined(__ICC)
353 
354 // Use these defines to bracket a region of code that has safe static accesses.
355 // Keep the region as small as possible.
356 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
357 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
358 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
359 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
360 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
361 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
362 
363 // Use these defines to bracket a region of code that has unsafe static accesses.
364 // Keep the region as small as possible.
365 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
366 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
367 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
368 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
369 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
370 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
371 
372 // Simpler version for one-line cases
373 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
374  __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
375 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
376  __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
377 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
378  __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
379 
380 #else // GCC does not support these compiler warnings
381 
382 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
383 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
384 #define OPENVDB_START_THREADSAFE_STATIC_WRITE
385 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
386 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
387 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
388 
389 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
390 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
391 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
392 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
393 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
394 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
395 
396 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
397 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
398 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
399 
400 #endif // defined(__ICC)
401 
402 #endif // OPENVDB_TYPES_HAS_BEEN_INCLUDED
403 
404 // Copyright (c) 2012-2013 DreamWorks Animation LLC
405 // All rights reserved. This software is distributed under the
406 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Definition: Types.h:343
CopyPolicy
Definition: Types.h:338
const char * typeNameAsString< float >()
Definition: Types.h:200
Vec4< float > Vec4s
Definition: Vec4.h:523
const ValueType * mBValPtr
Definition: Types.h:295
ValueType mResultVal
Definition: Types.h:296
int32_t Int32
Definition: Types.h:58
Definition: Types.h:190
math::Vec4< Index32 > Vec4I
Definition: Types.h:88
unsigned char Byte
Definition: Types.h:61
const char * typeNameAsString()
Definition: Types.h:198
Definition: Vec2.h:48
bool mResultIsActive
Definition: Types.h:299
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition: Types.h:283
This struct collects both input and output arguments to &quot;grid combiner&quot; functors used with the tree::...
Definition: Types.h:232
uint32_t Index32
Definition: Types.h:54
math::Mat3< Real > Mat3R
Definition: Types.h:96
math::Mat4< float > Mat4s
Definition: Types.h:101
ValueType & result()
Get the output value.
Definition: Types.h:262
const char * typeNameAsString< Mat4d >()
Definition: Types.h:214
Definition: Types.h:166
const char * typeNameAsString< Vec3f >()
Definition: Types.h:210
double Real
Definition: Types.h:62
math::Vec3< half > Vec3H
Definition: Types.h:77
int64_t Int64
Definition: Types.h:59
math::Vec4< Real > Vec4R
Definition: Types.h:87
Definition: Types.h:346
Definition: Types.h:307
Int32 Int
Definition: Types.h:60
void operator()(CombineArgs< ValueType > &args)
Definition: Types.h:311
ValueType ValueT
Definition: Types.h:235
Definition: Types.h:338
CombineArgs(const ValueType &a, const ValueType &b, bool aOn=false, bool bOn=false)
Use this constructor when the result value should be stored in this struct.
Definition: Types.h:250
Definition: Types.h:136
void updateResultActive()
Definition: Types.h:292
Vec3< int32_t > Vec3i
Definition: Vec3.h:602
const char * typeNameAsString< Mat4s >()
Definition: Types.h:213
Vec3< float > Vec3s
Definition: Vec3.h:604
Definition: Types.h:172
bool mBIsActive
Definition: Types.h:298
CombineArgs(const ValueType &a, const ValueType &b, ValueType &result, bool aOn=false, bool bOn=false)
Use this constructor when the result value is stored externally.
Definition: Types.h:243
const char * typeNameAsString< Hermite >()
Definition: Types.h:205
const char * typeNameAsString< Vec3i >()
Definition: Types.h:209
const ValueType & b() const
Get the B input value.
Definition: Types.h:258
Vec2< float > Vec2s
Definition: Vec2.h:501
const char * typeNameAsString< Vec2i >()
Definition: Types.h:206
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition: Types.h:285
const ValueType & a() const
Get the A input value.
Definition: Types.h:256
Definition: Mat4.h:51
Vec4< int32_t > Vec4i
Definition: Vec4.h:521
#define OPENVDB_VERSION_NAME
Definition: version.h:45
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
const char * typeNameAsString< Vec3d >()
Definition: Types.h:211
Definition: Types.h:141
CombineOp & op
Definition: Types.h:318
const char * typeNameAsString< bool >()
Definition: Types.h:199
int16_t Int16
Definition: Types.h:57
CombineArgs & setResultIsActive(bool b)
Set the active state of the output value.
Definition: Types.h:287
math::Vec3< Real > Vec3R
Definition: Types.h:74
math::Vec3< float > Vec3f
Definition: Types.h:76
CombineArgs & setResultRef(ValueType &val)
Redirect the result value to a new external destination.
Definition: Types.h:273
CombineArgs & setBRef(const ValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:271
VecType
Definition: Types.h:165
math::Vec2< Real > Vec2R
Definition: Types.h:65
Definition: Types.h:113
ValueType * mResultValPtr
Definition: Types.h:297
const char * typeNameAsString< int32_t >()
Definition: Types.h:202
Definition: Types.h:167
3x3 matrix class.
Definition: Mat3.h:54
Vec3< double > Vec3d
Definition: Vec3.h:605
bool aIsActive() const
Definition: Types.h:276
Definition: Types.h:338
math::BBox< Vec3d > BBoxd
Definition: Types.h:84
math::Vec3< Index32 > Vec3I
Definition: Types.h:75
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:229
Vec2< double > Vec2d
Definition: Vec2.h:502
math::Vec2< Index32 > Vec2I
Definition: Types.h:66
math::Vec4< half > Vec4H
Definition: Types.h:90
const char * typeNameAsString< Vec2s >()
Definition: Types.h:207
const char * typeNameAsString< double >()
Definition: Types.h:201
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:143
Index32 Index
Definition: Types.h:56
math::Vec4< float > Vec4f
Definition: Types.h:89
MergePolicy
Definition: Types.h:188
math::Vec2< float > Vec2f
Definition: Types.h:67
Quantized Hermite data object that stores compressed intersection information (offsets and normlas) f...
Definition: Hermite.h:66
math::Vec2< half > Vec2H
Definition: Types.h:68
const char * typeNameAsString< uint32_t >()
Definition: Types.h:203
const ValueType & result() const
Get the output value.
Definition: Types.h:261
SwappedCombineOp(CombineOp &op)
Definition: Types.h:309
CombineArgs()
Definition: Types.h:237
bool bIsActive() const
Definition: Types.h:278
GridClass
Definition: Types.h:135
CombineArgs & setARef(const ValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:269
CombineArgs & setResult(const ValueType &val)
Set the output value.
Definition: Types.h:266
const char * typeNameAsString< int64_t >()
Definition: Types.h:204
const ValueType * mAValPtr
Definition: Types.h:294
Definition: Mat.h:149
bool resultIsActive() const
Definition: Types.h:280
Vec4< double > Vec4d
Definition: Vec4.h:524
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
Definition: Types.h:139
math::Quat< Real > QuatR
Definition: Types.h:107
math::Mat4< double > Mat4d
Definition: Types.h:100
uint64_t Index64
Definition: Types.h:55
math::Hermite Hermite
Definition: Types.h:104
Definition: Types.h:338
math::Mat4< Real > Mat4R
Definition: Types.h:99
const char * typeNameAsString< Vec2d >()
Definition: Types.h:208
Definition: Types.h:137
Definition: Types.h:138
Vec2< int32_t > Vec2i
Definition: Vec2.h:499