HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LeafBuffer.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2012-2018 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_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED
32 #define OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED
33 
34 #include <openvdb/Types.h>
35 #include <openvdb/io/Compression.h> // for io::readCompressedValues(), etc
36 #include <openvdb/util/NodeMasks.h>
37 #include <tbb/atomic.h>
38 #include <tbb/spin_mutex.h>
39 #include <algorithm> // for std::swap
40 #include <cstddef> // for offsetof()
41 #include <iostream>
42 #include <memory>
43 #include <type_traits>
44 
45 
46 class TestLeaf;
47 
48 namespace openvdb {
50 namespace OPENVDB_VERSION_NAME {
51 namespace tree {
52 
53 namespace internal {
54 
55 /// @internal For delayed loading to be threadsafe, LeafBuffer::mOutOfCore must be
56 /// memory-fenced when it is set in LeafBuffer::doLoad(), otherwise that operation
57 /// could be reordered ahead of others in doLoad(), with the possible result that
58 /// other threads could see the buffer as in-core before it has been fully loaded.
59 /// Making mOutOfCore a TBB atomic solves the problem, since TBB atomics are release-fenced
60 /// by default (unlike STL atomics, which are not even guaranteed to be lock-free).
61 /// However, TBB atomics have stricter alignment requirements than their underlying value_types,
62 /// so a LeafBuffer with an atomic mOutOfCore is potentially ABI-incompatible with
63 /// its non-atomic counterpart.
64 /// This helper class conditionally declares mOutOfCore as an atomic only if doing so
65 /// doesn't break ABI compatibility.
66 template<typename T>
68 {
69 #if OPENVDB_ABI_VERSION_NUMBER >= 5
70  /// The type of LeafBuffer::mOutOfCore
71  using type = tbb::atomic<Index32>;
72  static constexpr bool IsAtomic = true;
73 #else // OPENVDB_ABI_VERSION_NUMBER < 5
74  // These structs need to have the same data members as LeafBuffer.
75  struct Atomic { union { T* data; void* ptr; }; tbb::atomic<Index32> i; tbb::spin_mutex mutex; };
76  struct NonAtomic { union { T* data; void* ptr; }; Index32 i; tbb::spin_mutex mutex; };
77 
78 #ifndef __INTEL_COMPILER
79  /// @c true if LeafBuffer::mOutOfCore is atomic, @c false otherwise
80  static constexpr bool IsAtomic = ((sizeof(Atomic) == sizeof(NonAtomic))
81  && (offsetof(Atomic, i) == offsetof(NonAtomic, i)));
82 #else
83  // We can't use offsetof() with ICC, because it requires the arguments
84  // to be POD types. (C++11 requires only that they be standard layout types,
85  // which Atomic and NonAtomic are.)
86  static constexpr bool IsAtomic = (sizeof(Atomic) == sizeof(NonAtomic));
87 #endif
88  /// The size of a LeafBuffer when LeafBuffer::mOutOfCore is atomic
89  static constexpr size_t size = sizeof(Atomic);
90  /// The type of LeafBuffer::mOutOfCore
91  using type = typename std::conditional<IsAtomic, tbb::atomic<Index32>, Index32>::type;
92 #endif
93 };
94 
95 } // namespace internal
96 
97 
98 /// @brief Array of fixed size 2<SUP>3<I>Log2Dim</I></SUP> that stores
99 /// the voxel values of a LeafNode
100 template<typename T, Index Log2Dim>
102 {
103 public:
104  using ValueType = T;
107  static const Index SIZE = 1 << 3 * Log2Dim;
108 
109 #if OPENVDB_ABI_VERSION_NUMBER >= 3
110  struct FileInfo
111  {
112  FileInfo(): bufpos(0) , maskpos(0) {}
113  std::streamoff bufpos;
114  std::streamoff maskpos;
115  io::MappedFile::Ptr mapping;
117  };
118 #endif
119 
120 #if OPENVDB_ABI_VERSION_NUMBER <= 2
121  /// Default constructor
122  LeafBuffer(): mData(new ValueType[SIZE]) {}
123  /// Construct a buffer populated with the specified value.
124  explicit LeafBuffer(const ValueType& val): mData(new ValueType[SIZE]) { this->fill(val); }
125  /// Copy constructor
126  LeafBuffer(const LeafBuffer& other): mData(new ValueType[SIZE]) { *this = other; }
127  /// Destructor
128  ~LeafBuffer() { delete[] mData; }
129 
130  /// Return @c true if this buffer's values have not yet been read from disk.
131  bool isOutOfCore() const { return false; }
132  /// Return @c true if memory for this buffer has not yet been allocated.
133  bool empty() const { return (mData == nullptr); }
134 #else
135  /// Default constructor
136  inline LeafBuffer(): mData(new ValueType[SIZE]), mOutOfCore(0) {}
137  /// Construct a buffer populated with the specified value.
138  explicit inline LeafBuffer(const ValueType&);
139  /// Copy constructor
140  inline LeafBuffer(const LeafBuffer&);
141  /// Construct a buffer but don't allocate memory for the full array of values.
142  LeafBuffer(PartialCreate, const ValueType&): mData(nullptr), mOutOfCore(0) {}
143  /// Destructor
144  inline ~LeafBuffer();
145 
146  /// Return @c true if this buffer's values have not yet been read from disk.
147  bool isOutOfCore() const { return bool(mOutOfCore); }
148  /// Return @c true if memory for this buffer has not yet been allocated.
149  bool empty() const { return !mData || this->isOutOfCore(); }
150 #endif
151  /// Allocate memory for this buffer if it has not already been allocated.
152  bool allocate() { if (mData == nullptr) mData = new ValueType[SIZE]; return true; }
153 
154  /// Populate this buffer with a constant value.
155  inline void fill(const ValueType&);
156 
157  /// Return a const reference to the i'th element of this buffer.
158  const ValueType& getValue(Index i) const { return this->at(i); }
159  /// Return a const reference to the i'th element of this buffer.
160  const ValueType& operator[](Index i) const { return this->at(i); }
161  /// Set the i'th value of this buffer to the specified value.
162  inline void setValue(Index i, const ValueType&);
163 
164  /// Copy the other buffer's values into this buffer.
165  inline LeafBuffer& operator=(const LeafBuffer&);
166 
167  /// @brief Return @c true if the contents of the other buffer
168  /// exactly equal the contents of this buffer.
169  inline bool operator==(const LeafBuffer&) const;
170  /// @brief Return @c true if the contents of the other buffer
171  /// are not exactly equal to the contents of this buffer.
172  inline bool operator!=(const LeafBuffer& other) const { return !(other == *this); }
173 
174  /// Exchange this buffer's values with the other buffer's values.
175  inline void swap(LeafBuffer&);
176 
177  /// Return the memory footprint of this buffer in bytes.
178  inline Index memUsage() const;
179  /// Return the number of values contained in this buffer.
180  static Index size() { return SIZE; }
181 
182  /// @brief Return a const pointer to the array of voxel values.
183  /// @details This method guarantees that the buffer is allocated and loaded.
184  /// @warning This method should only be used by experts seeking low-level optimizations.
185  const ValueType* data() const;
186  /// @brief Return a pointer to the array of voxel values.
187  /// @details This method guarantees that the buffer is allocated and loaded.
188  /// @warning This method should only be used by experts seeking low-level optimizations.
189  ValueType* data();
190 
191 private:
192  /// If this buffer is empty, return zero, otherwise return the value at index @ i.
193  inline const ValueType& at(Index i) const;
194 
195  /// @brief Return a non-const reference to the value at index @a i.
196  /// @details This method is private since it makes assumptions about the
197  /// buffer's memory layout. LeafBuffers associated with custom leaf node types
198  /// (e.g., a bool buffer implemented as a bitmask) might not be able to
199  /// return non-const references to their values.
200  ValueType& operator[](Index i) { return const_cast<ValueType&>(this->at(i)); }
201 
202  bool deallocate();
203 
204 #if OPENVDB_ABI_VERSION_NUMBER <= 2
205  void setOutOfCore(bool) {}
206  void loadValues() const {}
207  void doLoad() const {}
208  bool detachFromFile() { return false; }
209 #else
210  inline void setOutOfCore(bool b) { mOutOfCore = b; }
211  // To facilitate inlining in the common case in which the buffer is in-core,
212  // the loading logic is split into a separate function, doLoad().
213  inline void loadValues() const { if (this->isOutOfCore()) this->doLoad(); }
214  inline void doLoad() const;
215  inline bool detachFromFile();
216 #endif
217 
218 
219 #if OPENVDB_ABI_VERSION_NUMBER <= 2
220  ValueType* mData;
221 #else
222  using FlagsType = typename internal::LeafBufferFlags<ValueType>::type;
223 
224  union {
225  ValueType* mData;
226  FileInfo* mFileInfo;
227  };
228  FlagsType mOutOfCore; // interpreted as bool; extra bits reserved for future use
229  tbb::spin_mutex mMutex; // 1 byte
230  //int8_t mReserved[3]; // padding for alignment
231 
232  static const ValueType sZero;
233 #endif
234 
235  friend class ::TestLeaf;
236  // Allow the parent LeafNode to access this buffer's data pointer.
237  template<typename, Index> friend class LeafNode;
238 }; // class LeafBuffer
239 
240 
241 ////////////////////////////////////////
242 
243 
244 #if OPENVDB_ABI_VERSION_NUMBER >= 3
245 
246 template<typename T, Index Log2Dim>
247 const T LeafBuffer<T, Log2Dim>::sZero = zeroVal<T>();
248 
249 
250 template<typename T, Index Log2Dim>
251 inline
252 LeafBuffer<T, Log2Dim>::LeafBuffer(const ValueType& val)
253  : mData(new ValueType[SIZE])
254  , mOutOfCore(0)
255 {
256  this->fill(val);
257 }
258 
259 
260 template<typename T, Index Log2Dim>
261 inline
262 LeafBuffer<T, Log2Dim>::~LeafBuffer()
263 {
264  if (this->isOutOfCore()) {
265  this->detachFromFile();
266  } else {
267  this->deallocate();
268  }
269 }
270 
271 
272 template<typename T, Index Log2Dim>
273 inline
274 LeafBuffer<T, Log2Dim>::LeafBuffer(const LeafBuffer& other)
275  : mData(nullptr)
276  , mOutOfCore(other.mOutOfCore)
277 {
278  if (other.isOutOfCore()) {
279  mFileInfo = new FileInfo(*other.mFileInfo);
280  } else if (other.mData != nullptr) {
281  this->allocate();
282  ValueType* target = mData;
283  const ValueType* source = other.mData;
284  Index n = SIZE;
285  while (n--) *target++ = *source++;
286  }
287 }
288 
289 #endif // OPENVDB_ABI_VERSION_NUMBER >= 3
290 
291 
292 template<typename T, Index Log2Dim>
293 inline void
295 {
296  assert(i < SIZE);
297 #if OPENVDB_ABI_VERSION_NUMBER <= 2
298  mData[i] = val;
299 #else
300  this->loadValues();
301  if (mData) mData[i] = val;
302 #endif
303 }
304 
305 
306 template<typename T, Index Log2Dim>
309 {
310  if (&other != this) {
311 #if OPENVDB_ABI_VERSION_NUMBER <= 2
312  if (other.mData != nullptr) {
313  this->allocate();
314  ValueType* target = mData;
315  const ValueType* source = other.mData;
316  Index n = SIZE;
317  while (n--) *target++ = *source++;
318  }
319 #else // OPENVDB_ABI_VERSION_NUMBER >= 3
320  if (this->isOutOfCore()) {
321  this->detachFromFile();
322  } else {
323  if (other.isOutOfCore()) this->deallocate();
324  }
325  if (other.isOutOfCore()) {
326  mOutOfCore = other.mOutOfCore;
327  mFileInfo = new FileInfo(*other.mFileInfo);
328  } else if (other.mData != nullptr) {
329  this->allocate();
330  ValueType* target = mData;
331  const ValueType* source = other.mData;
332  Index n = SIZE;
333  while (n--) *target++ = *source++;
334  }
335 #endif
336  }
337  return *this;
338 }
339 
340 
341 template<typename T, Index Log2Dim>
342 inline void
344 {
345  this->detachFromFile();
346  if (mData != nullptr) {
347  ValueType* target = mData;
348  Index n = SIZE;
349  while (n--) *target++ = val;
350  }
351 }
352 
353 
354 template<typename T, Index Log2Dim>
355 inline bool
357 {
358  this->loadValues();
359  other.loadValues();
360  const ValueType *target = mData, *source = other.mData;
361  if (!target && !source) return true;
362  if (!target || !source) return false;
363  Index n = SIZE;
364  while (n && math::isExactlyEqual(*target++, *source++)) --n;
365  return n == 0;
366 }
367 
368 
369 template<typename T, Index Log2Dim>
370 inline void
372 {
373  std::swap(mData, other.mData);
374 #if OPENVDB_ABI_VERSION_NUMBER >= 3
375  std::swap(mOutOfCore, other.mOutOfCore);
376 #endif
377 }
378 
379 
380 template<typename T, Index Log2Dim>
381 inline Index
383 {
384  size_t n = sizeof(*this);
385 #if OPENVDB_ABI_VERSION_NUMBER <= 2
386  if (mData) n += SIZE * sizeof(ValueType);
387 #else
388  if (this->isOutOfCore()) n += sizeof(FileInfo);
389  else if (mData) n += SIZE * sizeof(ValueType);
390 #endif
391  return static_cast<Index>(n);
392 }
393 
394 
395 template<typename T, Index Log2Dim>
396 inline const typename LeafBuffer<T, Log2Dim>::ValueType*
398 {
399 #if OPENVDB_ABI_VERSION_NUMBER >= 3
400  this->loadValues();
401  if (mData == nullptr) {
402  LeafBuffer* self = const_cast<LeafBuffer*>(this);
403  // This lock will be contended at most once.
404  tbb::spin_mutex::scoped_lock lock(self->mMutex);
405  if (mData == nullptr) self->mData = new ValueType[SIZE];
406  }
407 #endif
408  return mData;
409 }
410 
411 template<typename T, Index Log2Dim>
412 inline typename LeafBuffer<T, Log2Dim>::ValueType*
414 {
415 #if OPENVDB_ABI_VERSION_NUMBER >= 3
416  this->loadValues();
417  if (mData == nullptr) {
418  // This lock will be contended at most once.
419  tbb::spin_mutex::scoped_lock lock(mMutex);
420  if (mData == nullptr) mData = new ValueType[SIZE];
421  }
422 #endif
423  return mData;
424 }
425 
426 
427 template<typename T, Index Log2Dim>
428 inline const typename LeafBuffer<T, Log2Dim>::ValueType&
430 {
431  assert(i < SIZE);
432 #if OPENVDB_ABI_VERSION_NUMBER <= 2
433  return mData[i];
434 #else
435  this->loadValues();
436  // We can't use the ternary operator here, otherwise Visual C++ returns
437  // a reference to a temporary.
438  if (mData) return mData[i]; else return sZero;
439 #endif
440 }
441 
442 
443 template<typename T, Index Log2Dim>
444 inline bool
445 LeafBuffer<T, Log2Dim>::deallocate()
446 {
447  if (mData != nullptr && !this->isOutOfCore()) {
448  delete[] mData;
449  mData = nullptr;
450  return true;
451  }
452  return false;
453 }
454 
455 
456 #if OPENVDB_ABI_VERSION_NUMBER >= 3
457 
458 template<typename T, Index Log2Dim>
459 inline void
460 LeafBuffer<T, Log2Dim>::doLoad() const
461 {
462  if (!this->isOutOfCore()) return;
463 
464  LeafBuffer<T, Log2Dim>* self = const_cast<LeafBuffer<T, Log2Dim>*>(this);
465 
466  // This lock will be contended at most once, after which this buffer
467  // will no longer be out-of-core.
468  tbb::spin_mutex::scoped_lock lock(self->mMutex);
469  if (!this->isOutOfCore()) return;
470 
471  std::unique_ptr<FileInfo> info(self->mFileInfo);
472  assert(info.get() != nullptr);
473  assert(info->mapping.get() != nullptr);
474  assert(info->meta.get() != nullptr);
475 
476  /// @todo For now, we have to clear the mData pointer in order for allocate() to take effect.
477  self->mData = nullptr;
478  self->allocate();
479 
480  SharedPtr<std::streambuf> buf = info->mapping->createBuffer();
481  std::istream is(buf.get());
482 
483  io::setStreamMetadataPtr(is, info->meta, /*transfer=*/true);
484 
485  NodeMaskType mask;
486  is.seekg(info->maskpos);
487  mask.load(is);
488 
489  is.seekg(info->bufpos);
490  io::readCompressedValues(is, self->mData, SIZE, mask, io::getHalfFloat(is));
491 
492  self->setOutOfCore(false);
493 }
494 
495 
496 template<typename T, Index Log2Dim>
497 inline bool
498 LeafBuffer<T, Log2Dim>::detachFromFile()
499 {
500  if (this->isOutOfCore()) {
501  delete mFileInfo;
502  mFileInfo = nullptr;
503  this->setOutOfCore(false);
504  return true;
505  }
506  return false;
507 }
508 
509 #endif // OPENVDB_ABI_VERSION_NUMBER >= 3
510 
511 
512 ////////////////////////////////////////
513 
514 
515 // Partial specialization for bool ValueType
516 template<Index Log2Dim>
517 class LeafBuffer<bool, Log2Dim>
518 {
519 public:
521  using WordType = typename NodeMaskType::Word;
522  using ValueType = bool;
524 
525  static const Index WORD_COUNT = NodeMaskType::WORD_COUNT;
526  static const Index SIZE = 1 << 3 * Log2Dim;
527 
528  // These static declarations must be on separate lines to avoid VC9 compiler errors.
529  static const bool sOn;
530  static const bool sOff;
531 
533  LeafBuffer(bool on): mData(on) {}
534  LeafBuffer(const NodeMaskType& other): mData(other) {}
535  LeafBuffer(const LeafBuffer& other): mData(other.mData) {}
537  void fill(bool val) { mData.set(val); }
538  LeafBuffer& operator=(const LeafBuffer& b) { if (&b != this) { mData=b.mData; } return *this; }
539 
540  const bool& getValue(Index i) const
541  {
542  assert(i < SIZE);
543  // We can't use the ternary operator here, otherwise Visual C++ returns
544  // a reference to a temporary.
545  if (mData.isOn(i)) return sOn; else return sOff;
546  }
547  const bool& operator[](Index i) const { return this->getValue(i); }
548 
549  bool operator==(const LeafBuffer& other) const { return mData == other.mData; }
550  bool operator!=(const LeafBuffer& other) const { return mData != other.mData; }
551 
552  void setValue(Index i, bool val) { assert(i < SIZE); mData.set(i, val); }
553 
554  void swap(LeafBuffer& other) { if (&other != this) std::swap(mData, other.mData); }
555 
556  Index memUsage() const { return sizeof(*this); }
557  static Index size() { return SIZE; }
558 
559  /// @brief Return a pointer to the C-style array of words encoding the bits.
560  /// @warning This method should only be used by experts seeking low-level optimizations.
561  WordType* data() { return &(mData.template getWord<WordType>(0)); }
562  /// @brief Return a const pointer to the C-style array of words encoding the bits.
563  /// @warning This method should only be used by experts seeking low-level optimizations.
564  const WordType* data() const { return const_cast<LeafBuffer*>(this)->data(); }
565 
566 private:
567  // Allow the parent LeafNode to access this buffer's data.
568  template<typename, Index> friend class LeafNode;
569 
570  NodeMaskType mData;
571 }; // class LeafBuffer
572 
573 
574 /// @internal For consistency with other nodes and with iterators, methods like
575 /// LeafNode::getValue() return a reference to a value. Since it's not possible
576 /// to return a reference to a bit in a node mask, we return a reference to one
577 /// of the following static values instead.
578 template<Index Log2Dim> const bool LeafBuffer<bool, Log2Dim>::sOn = true;
579 template<Index Log2Dim> const bool LeafBuffer<bool, Log2Dim>::sOff = false;
580 
581 } // namespace tree
582 } // namespace OPENVDB_VERSION_NAME
583 } // namespace openvdb
584 
585 #endif // OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED
586 
587 // Copyright (c) 2012-2018 DreamWorks Animation LLC
588 // All rights reserved. This software is distributed under the
589 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
LeafBuffer & operator=(const LeafBuffer &)
Copy the other buffer's values into this buffer.
Definition: LeafBuffer.h:308
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition: UT_ArraySet.h:1519
GLint GLuint mask
Definition: glcorearb.h:123
OPENVDB_API bool getHalfFloat(std::ios_base &)
Return true if floating-point values should be quantized to 16 bits when writing to the given stream ...
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:189
SharedPtr< MappedFile > Ptr
Definition: io.h:152
bool operator==(const LeafBuffer &) const
Return true if the contents of the other buffer exactly equal the contents of this buffer...
Definition: LeafBuffer.h:356
bool empty() const
Return true if memory for this buffer has not yet been allocated.
Definition: LeafBuffer.h:133
png_uint_32 i
Definition: png.h:2877
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:520
GLsizeiptr size
Definition: glcorearb.h:663
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:339
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
static constexpr bool IsAtomic
true if LeafBuffer::mOutOfCore is atomic, false otherwise
Definition: LeafBuffer.h:80
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GLdouble n
Definition: glcorearb.h:2007
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:309
void swap(LeafBuffer &)
Exchange this buffer's values with the other buffer's values.
Definition: LeafBuffer.h:371
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:64
bool allocate()
Allocate memory for this buffer if it has not already been allocated.
Definition: LeafBuffer.h:152
static Index size()
Return the number of values contained in this buffer.
Definition: LeafBuffer.h:180
LeafBuffer(const ValueType &val)
Construct a buffer populated with the specified value.
Definition: LeafBuffer.h:124
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
const ValueType & getValue(Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:158
GLenum target
Definition: glcorearb.h:1666
GLboolean * data
Definition: glcorearb.h:130
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition: LeafBuffer.h:382
WordType * data()
Return a pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:561
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
OPENVDB_API void setStreamMetadataPtr(std::ios_base &, SharedPtr< StreamMetadata > &, bool transfer=true)
Associate the given stream with (a shared pointer to) an object that stores metadata (file format...
const ValueType * data() const
Return a const pointer to the array of voxel values.
Definition: LeafBuffer.h:397
const ValueType & operator[](Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:160
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:343
typename std::conditional< IsAtomic, tbb::atomic< Index32 >, Index32 >::type type
The type of LeafBuffer::mOutOfCore.
Definition: LeafBuffer.h:91
LeafBuffer(const LeafBuffer &other)
Copy constructor.
Definition: LeafBuffer.h:126
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: LeafBuffer.h:131
Array of fixed size 23Log2Dim that stores the voxel values of a LeafNode.
Definition: LeafBuffer.h:101
GLuint GLfloat * val
Definition: glcorearb.h:1607
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
void swap(TfErrorTransport &l, TfErrorTransport &r)
#define SIZE
Definition: simple.C:40
void setValue(Index i, const ValueType &)
Set the i'th value of this buffer to the specified value.
Definition: LeafBuffer.h:294
bool operator!=(const LeafBuffer &other) const
Return true if the contents of the other buffer are not exactly equal to the contents of this buffer...
Definition: LeafBuffer.h:172
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:135
const WordType * data() const
Return a const pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:564