OpenVDB  3.0.0
LeafManager.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 //
41 
42 #ifndef OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
43 #define OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
44 
45 #include <boost/shared_ptr.hpp>
46 #include <boost/bind.hpp>
47 #include <boost/function.hpp>
48 #include <tbb/blocked_range.h>
49 #include <tbb/parallel_for.h>
50 #include <openvdb/Types.h>
51 #include "TreeIterator.h" // for CopyConstness
52 
53 namespace openvdb {
55 namespace OPENVDB_VERSION_NAME {
56 namespace tree {
57 
58 namespace leafmgr {
59 
61 template<typename TreeT> struct TreeTraits {
63  static const bool IsConstTree = false;
64  typedef typename TreeT::LeafIter LeafIterType;
65 };
66 template<typename TreeT> struct TreeTraits<const TreeT> {
67  static const bool IsConstTree = true;
68  typedef typename TreeT::LeafCIter LeafIterType;
69 };
71 
72 } // namespace leafmgr
73 
74 
77 template<typename ManagerT>
79 {
80  typedef typename ManagerT::RangeType RangeT;
81  typedef typename ManagerT::LeafType LeafT;
82  typedef typename ManagerT::BufferType BufT;
83 
84  static inline void doSwapLeafBuffer(const RangeT& r, size_t auxBufferIdx,
85  LeafT** leafs, BufT* bufs, size_t bufsPerLeaf)
86  {
87  for (size_t n = r.begin(), m = r.end(), N = bufsPerLeaf; n != m; ++n) {
88  leafs[n]->swap(bufs[n * N + auxBufferIdx]);
89  }
90  }
91 };
92 
93 
95 
96 
108 template<typename TreeT>
110 {
111 public:
112  typedef TreeT TreeType;
113  typedef typename TreeT::ValueType ValueType;
114  typedef typename TreeT::RootNodeType RootNodeType;
115  typedef typename TreeType::LeafNodeType NonConstLeafType;
117  typedef LeafType LeafNodeType;
119  typedef typename LeafType::Buffer NonConstBufferType;
121  typedef tbb::blocked_range<size_t> RangeType;//leaf index range
122  static const Index DEPTH = 2;//root + leafs
123 
124  static const bool IsConstTree = leafmgr::TreeTraits<TreeT>::IsConstTree;
125 
126  class LeafRange
127  {
128  public:
129  class Iterator
130  {
131  public:
132  Iterator(const LeafRange& range, size_t pos): mRange(range), mPos(pos)
133  {
134  assert(this->isValid());
135  }
136  Iterator& operator=(const Iterator& other)
137  {
138  mRange = other.mRange; mPos = other.mPos; return *this;
139  }
141  Iterator& operator++() { ++mPos; return *this; }
143  LeafType& operator*() const { return mRange.mLeafManager.leaf(mPos); }
145  LeafType* operator->() const { return &(this->operator*()); }
148  BufferType& buffer(size_t bufferIdx)
149  {
150  return mRange.mLeafManager.getBuffer(mPos, bufferIdx);
151  }
153  size_t pos() const { return mPos; }
154  bool isValid() const { return mPos>=mRange.mBegin && mPos<=mRange.mEnd; }
156  bool test() const { return mPos < mRange.mEnd; }
158  operator bool() const { return this->test(); }
160  bool empty() const { return !this->test(); }
161  bool operator!=(const Iterator& other) const
162  {
163  return (mPos != other.mPos) || (&mRange != &other.mRange);
164  }
165  bool operator==(const Iterator& other) const { return !(*this != other); }
166  const LeafRange& leafRange() const { return mRange; }
167 
168  private:
169  const LeafRange& mRange;
170  size_t mPos;
171  };// end Iterator
172 
173  LeafRange(size_t begin, size_t end, const LeafManager& leafManager, size_t grainSize=1):
174  mEnd(end), mBegin(begin), mGrainSize(grainSize), mLeafManager(leafManager) {}
175 
176  Iterator begin() const {return Iterator(*this, mBegin);}
177 
178  Iterator end() const {return Iterator(*this, mEnd);}
179 
180  size_t size() const { return mEnd - mBegin; }
181 
182  size_t grainsize() const { return mGrainSize; }
183 
184  const LeafManager& leafManager() const { return mLeafManager; }
185 
186  bool empty() const {return !(mBegin < mEnd);}
187 
188  bool is_divisible() const {return mGrainSize < this->size();}
189 
190  LeafRange(LeafRange& r, tbb::split):
191  mEnd(r.mEnd), mBegin(doSplit(r)), mGrainSize(r.mGrainSize),
192  mLeafManager(r.mLeafManager) {}
193 
194  private:
195  size_t mEnd, mBegin, mGrainSize;
196  const LeafManager& mLeafManager;
197 
198  static size_t doSplit(LeafRange& r)
199  {
200  assert(r.is_divisible());
201  size_t middle = r.mBegin + (r.mEnd - r.mBegin) / 2u;
202  r.mEnd = middle;
203  return middle;
204  }
205  };// end of LeafRange
206 
209  LeafManager(TreeType& tree, size_t auxBuffersPerLeaf=0, bool serial=false):
210  mTree(&tree),
211  mLeafCount(0),
212  mAuxBufferCount(0),
213  mAuxBuffersPerLeaf(auxBuffersPerLeaf),
214  mLeafs(NULL),
215  mAuxBuffers(NULL),
216  mTask(0),
217  mIsMaster(true)
218  {
219  this->rebuild(serial);
220  }
221 
225  LeafManager(const LeafManager& other):
226  mTree(other.mTree),
227  mLeafCount(other.mLeafCount),
228  mAuxBufferCount(other.mAuxBufferCount),
229  mAuxBuffersPerLeaf(other.mAuxBuffersPerLeaf),
230  mLeafs(other.mLeafs),
231  mAuxBuffers(other.mAuxBuffers),
232  mTask(other.mTask),
233  mIsMaster(false)
234  {
235  }
236 
237  virtual ~LeafManager()
238  {
239  if (mIsMaster) {
240  delete [] mLeafs;
241  delete [] mAuxBuffers;
242  }
243  }
244 
250  void rebuild(bool serial=false)
251  {
252  this->initLeafArray();
253  this->initAuxBuffers(serial);
254  }
256  void rebuild(size_t auxBuffersPerLeaf, bool serial=false)
258  {
259  mAuxBuffersPerLeaf = auxBuffersPerLeaf;
260  this->rebuild(serial);
261  }
262  void rebuild(TreeType& tree, bool serial=false)
263  {
264  mTree = &tree;
265  this->rebuild(serial);
266  }
267  void rebuild(TreeType& tree, size_t auxBuffersPerLeaf, bool serial=false)
268  {
269  mTree = &tree;
270  mAuxBuffersPerLeaf = auxBuffersPerLeaf;
271  this->rebuild(serial);
272  }
274  void rebuildAuxBuffers(size_t auxBuffersPerLeaf, bool serial=false)
279  {
280  mAuxBuffersPerLeaf = auxBuffersPerLeaf;
281  this->initAuxBuffers(serial);
282  }
284  void removeAuxBuffers() { this->rebuildAuxBuffers(0); }
285 
288  {
289  this->removeAuxBuffers();
290  this->initLeafArray();
291  }
292 
294  size_t auxBufferCount() const { return mAuxBufferCount; }
296  size_t auxBuffersPerLeaf() const { return mAuxBuffersPerLeaf; }
297 
299  size_t leafCount() const { return mLeafCount; }
300 
302  const TreeType& tree() const { return *mTree; }
303 
305  TreeType& tree() { return *mTree; }
306 
308  const RootNodeType& root() const { return mTree->root(); }
309 
311  RootNodeType& root() { return mTree->root(); }
312 
314  bool isConstTree() const { return this->IsConstTree; }
315 
318  LeafType& leaf(size_t leafIdx) const { assert(leafIdx<mLeafCount); return *mLeafs[leafIdx]; }
319 
330  BufferType& getBuffer(size_t leafIdx, size_t bufferIdx) const
331  {
332  assert(leafIdx < mLeafCount);
333  assert(bufferIdx == 0 || bufferIdx - 1 < mAuxBuffersPerLeaf);
334  return bufferIdx == 0 ? mLeafs[leafIdx]->buffer()
335  : mAuxBuffers[leafIdx * mAuxBuffersPerLeaf + bufferIdx - 1];
336  }
337 
342  RangeType getRange(size_t grainsize = 1) const { return RangeType(0, mLeafCount, grainsize); }
343 
345  LeafRange leafRange(size_t grainsize = 1) const
346  {
347  return LeafRange(0, mLeafCount, *this, grainsize);
348  }
349 
359  bool swapLeafBuffer(size_t bufferIdx, bool serial = false)
360  {
361  if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf || this->isConstTree()) return false;
362  mTask = boost::bind(&LeafManager::doSwapLeafBuffer, _1, _2, bufferIdx - 1);
363  this->cook(serial ? 0 : 512);
364  return true;//success
365  }
370  bool swapBuffer(size_t bufferIdx1, size_t bufferIdx2, bool serial = false)
371  {
372  const size_t b1 = std::min(bufferIdx1, bufferIdx2);
373  const size_t b2 = std::max(bufferIdx1, bufferIdx2);
374  if (b1 == b2 || b2 > mAuxBuffersPerLeaf) return false;
375  if (b1 == 0) {
376  if (this->isConstTree()) return false;
377  mTask = boost::bind(&LeafManager::doSwapLeafBuffer, _1, _2, b2-1);
378  } else {
379  mTask = boost::bind(&LeafManager::doSwapAuxBuffer, _1, _2, b1-1, b2-1);
380  }
381  this->cook(serial ? 0 : 512);
382  return true;//success
383  }
384 
393  bool syncAuxBuffer(size_t bufferIdx, bool serial = false)
394  {
395  if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf) return false;
396  mTask = boost::bind(&LeafManager::doSyncAuxBuffer, _1, _2, bufferIdx - 1);
397  this->cook(serial ? 0 : 64);
398  return true;//success
399  }
400 
404  bool syncAllBuffers(bool serial = false)
405  {
406  switch (mAuxBuffersPerLeaf) {
407  case 0: return false;//nothing to do
408  case 1: mTask = boost::bind(&LeafManager::doSyncAllBuffers1, _1, _2); break;
409  case 2: mTask = boost::bind(&LeafManager::doSyncAllBuffers2, _1, _2); break;
410  default: mTask = boost::bind(&LeafManager::doSyncAllBuffersN, _1, _2); break;
411  }
412  this->cook(serial ? 0 : 64);
413  return true;//success
414  }
415 
475  template<typename LeafOp>
476  void foreach(const LeafOp& op, bool threaded = true, size_t grainSize=1)
477  {
478  LeafTransformer<LeafOp> transform(op);
479  transform.run(this->leafRange(grainSize), threaded);
480  }
481 
482 
483  template<typename ArrayT>
484  void getNodes(ArrayT& array)
485  {
486  typedef typename ArrayT::value_type T;
487  BOOST_STATIC_ASSERT(boost::is_pointer<T>::value);
488  typedef typename boost::mpl::if_<boost::is_const<typename boost::remove_pointer<T>::type>,
489  const LeafType, LeafType>::type LeafT;
490 
492  if (boost::is_same<T, LeafT*>::value) {
493  array.resize(mLeafCount);
494  for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
495  } else {
496  mTree->getNodes(array);
497  }
499  }
500 
501  template<typename ArrayT>
502  void getNodes(ArrayT& array) const
503  {
504  typedef typename ArrayT::value_type T;
505  BOOST_STATIC_ASSERT(boost::is_pointer<T>::value);
506  BOOST_STATIC_ASSERT(boost::is_const<typename boost::remove_pointer<T>::type>::value);
507 
509  if (boost::is_same<T, const LeafType*>::value) {
510  array.resize(mLeafCount);
511  for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
512  } else {
513  mTree->getNodes(array);
514  }
516  }
517 
519  // All methods below are for internal use only and should never be called directly
520 
522  void operator()(const RangeType& r) const
523  {
524  if (mTask) mTask(const_cast<LeafManager*>(this), r);
525  else OPENVDB_THROW(ValueError, "task is undefined");
526  }
527 
528 
529 
530  private:
531 
532  // This a simple wrapper for a c-style array so it mimics the api
533  // of a std container, e.g. std::vector or std::deque, and can be
534  // passed to Tree::getNodes().
535  struct MyArray {
536  typedef LeafType* value_type;//required by Tree::getNodes
537  value_type* ptr;
538  MyArray(value_type* array) : ptr(array) {}
539  void push_back(value_type leaf) { *ptr++ = leaf; }//required by Tree::getNodes
540  };
541 
542  void initLeafArray()
543  {
544  const size_t leafCount = mTree->leafCount();
545  if (leafCount != mLeafCount) {
546  delete [] mLeafs;
547  mLeafs = (leafCount == 0) ? NULL : new LeafType*[leafCount];
548  mLeafCount = leafCount;
549  }
550  MyArray a(mLeafs);
551  mTree->getNodes(a);
552  }
553 
554  void initAuxBuffers(bool serial)
555  {
556  const size_t auxBufferCount = mLeafCount * mAuxBuffersPerLeaf;
557  if (auxBufferCount != mAuxBufferCount) {
558  delete [] mAuxBuffers;
559  mAuxBuffers = (auxBufferCount == 0) ? NULL : new NonConstBufferType[auxBufferCount];
560  mAuxBufferCount = auxBufferCount;
561  }
562  this->syncAllBuffers(serial);
563  }
564 
565  void cook(size_t grainsize)
566  {
567  if (grainsize>0) {
568  tbb::parallel_for(this->getRange(grainsize), *this);
569  } else {
570  (*this)(this->getRange());
571  }
572  }
573 
574  void doSwapLeafBuffer(const RangeType& r, size_t auxBufferIdx)
575  {
576  LeafManagerImpl<LeafManager>::doSwapLeafBuffer(
577  r, auxBufferIdx, mLeafs, mAuxBuffers, mAuxBuffersPerLeaf);
578  }
579 
580  void doSwapAuxBuffer(const RangeType& r, size_t auxBufferIdx1, size_t auxBufferIdx2)
581  {
582  for (size_t N = mAuxBuffersPerLeaf, n = N*r.begin(), m = N*r.end(); n != m; n+=N) {
583  mAuxBuffers[n + auxBufferIdx1].swap(mAuxBuffers[n + auxBufferIdx2]);
584  }
585  }
586 
587  void doSyncAuxBuffer(const RangeType& r, size_t auxBufferIdx)
588  {
589  for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
590  mAuxBuffers[n*N + auxBufferIdx] = mLeafs[n]->buffer();
591  }
592  }
593 
594  void doSyncAllBuffers1(const RangeType& r)
595  {
596  for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
597  mAuxBuffers[n] = mLeafs[n]->buffer();
598  }
599  }
600 
601  void doSyncAllBuffers2(const RangeType& r)
602  {
603  for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
604  const BufferType& leafBuffer = mLeafs[n]->buffer();
605  mAuxBuffers[2*n ] = leafBuffer;
606  mAuxBuffers[2*n+1] = leafBuffer;
607  }
608  }
609 
610  void doSyncAllBuffersN(const RangeType& r)
611  {
612  for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
613  const BufferType& leafBuffer = mLeafs[n]->buffer();
614  for (size_t i=n*N, j=i+N; i!=j; ++i) mAuxBuffers[i] = leafBuffer;
615  }
616  }
617 
620  template<typename LeafOp>
621  struct LeafTransformer
622  {
623  LeafTransformer(const LeafOp& leafOp) : mLeafOp(leafOp) {}
624  void run(const LeafRange& range, bool threaded = true)
625  {
626  threaded ? tbb::parallel_for(range, *this) : (*this)(range);
627  }
628  void operator()(const LeafRange& range) const
629  {
630  for (typename LeafRange::Iterator it = range.begin(); it; ++it) mLeafOp(*it, it.pos());
631  }
632  const LeafOp mLeafOp;
633  };
634 
635  typedef typename boost::function<void (LeafManager*, const RangeType&)> FuncType;
636 
637  TreeType* mTree;
638  size_t mLeafCount, mAuxBufferCount, mAuxBuffersPerLeaf;
639  LeafType** mLeafs;//array of LeafNode pointers
640  NonConstBufferType* mAuxBuffers;//array of auxiliary buffers
641  FuncType mTask;
642  const bool mIsMaster;
643 };//end of LeafManager class
644 
645 
646 // Partial specializations of LeafManager methods for const trees
647 template<typename TreeT>
648 struct LeafManagerImpl<LeafManager<const TreeT> >
649 {
651  typedef typename ManagerT::RangeType RangeT;
652  typedef typename ManagerT::LeafType LeafT;
653  typedef typename ManagerT::BufferType BufT;
654 
655  static inline void doSwapLeafBuffer(const RangeT&, size_t /*auxBufferIdx*/,
656  LeafT**, BufT*, size_t /*bufsPerLeaf*/)
657  {
658  // Buffers can't be swapped into const trees.
659  }
660 };
661 
662 } // namespace tree
663 } // namespace OPENVDB_VERSION_NAME
664 } // namespace openvdb
665 
666 #endif // OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
667 
668 // Copyright (c) 2012-2014 DreamWorks Animation LLC
669 // All rights reserved. This software is distributed under the
670 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Useful traits for Tree types.
Definition: LeafManager.h:62
CopyConstness< TreeType, NonConstLeafType >::Type LeafType
Definition: LeafManager.h:116
LeafType LeafNodeType
Definition: LeafManager.h:117
bool operator==(const Iterator &other) const
Definition: LeafManager.h:165
tbb::blocked_range< size_t > RangeType
Definition: LeafManager.h:121
size_t grainsize() const
Definition: LeafManager.h:182
LeafRange(LeafRange &r, tbb::split)
Definition: LeafManager.h:190
const RootNodeType & root() const
Return a const reference to root node associated with this manager.
Definition: LeafManager.h:308
Iterator(const LeafRange &range, size_t pos)
Definition: LeafManager.h:132
Iterator & operator=(const Iterator &other)
Definition: LeafManager.h:136
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
const LeafRange & leafRange() const
Definition: LeafManager.h:166
bool is_divisible() const
Definition: LeafManager.h:188
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
TreeT::LeafCIter LeafIterType
Definition: LeafManager.h:68
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:608
boost::remove_const< ToType >::type Type
Definition: TreeIterator.h:66
RangeType getRange(size_t grainsize=1) const
Return a tbb::blocked_range of leaf array indices.
Definition: LeafManager.h:342
TreeT TreeType
Definition: LeafManager.h:112
TreeT::RootNodeType RootNodeType
Definition: LeafManager.h:114
void getNodes(ArrayT &array)
Definition: LeafManager.h:484
size_t leafCount() const
Return the number of leaf nodes.
Definition: LeafManager.h:299
bool syncAllBuffers(bool serial=false)
Sync up all auxiliary buffers with their corresponding leaf node buffers.
Definition: LeafManager.h:404
size_t size() const
Definition: LeafManager.h:180
static void doSwapLeafBuffer(const RangeT &r, size_t auxBufferIdx, LeafT **leafs, BufT *bufs, size_t bufsPerLeaf)
Definition: LeafManager.h:84
size_t auxBuffersPerLeaf() const
Return the number of auxiliary buffers per leaf node.
Definition: LeafManager.h:296
LeafManager(TreeType &tree, size_t auxBuffersPerLeaf=0, bool serial=false)
Constructor from a tree reference and an auxiliary buffer count (default is no auxiliary buffers) ...
Definition: LeafManager.h:209
TreeType & tree()
Return a reference to the tree associated with this manager.
Definition: LeafManager.h:305
#define OPENVDB_VERSION_NAME
Definition: version.h:43
ManagerT::LeafType LeafT
Definition: LeafManager.h:81
RootNodeType & root()
Return a reference to the root node associated with this manager.
Definition: LeafManager.h:311
bool operator!=(const Iterator &other) const
Definition: LeafManager.h:161
Index32 Index
Definition: Types.h:59
BufferType & buffer(size_t bufferIdx)
Return the nth buffer for the leaf node to which this iterator is pointing, where n = bufferIdx and n...
Definition: LeafManager.h:148
bool test() const
Return true if this iterator is not yet exhausted.
Definition: LeafManager.h:156
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:345
Iterator & operator++()
Advance to the next leaf node.
Definition: LeafManager.h:141
TreeT::ValueType ValueType
Definition: LeafManager.h:113
Definition: Exceptions.h:39
LeafManager< const TreeT > ManagerT
Definition: LeafManager.h:650
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:121
BufferType & getBuffer(size_t leafIdx, size_t bufferIdx) const
Return the leaf or auxiliary buffer for the leaf node at index leafIdx. If bufferIdx is zero...
Definition: LeafManager.h:330
bool swapBuffer(size_t bufferIdx1, size_t bufferIdx2, bool serial=false)
Swap any two buffers for each leaf node.
Definition: LeafManager.h:370
LeafType & operator*() const
Return a reference to the leaf node to which this iterator is pointing.
Definition: LeafManager.h:143
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
size_t auxBufferCount() const
Return the total number of allocated auxiliary buffers.
Definition: LeafManager.h:294
void getNodes(ArrayT &array) const
Definition: LeafManager.h:502
LeafType * operator->() const
Return a pointer to the leaf node to which this iterator is pointing.
Definition: LeafManager.h:145
Definition: LeafManager.h:78
ManagerT::RangeType RangeT
Definition: LeafManager.h:80
void rebuild(TreeType &tree, bool serial=false)
Repopulate the leaf array and delete and reallocate auxiliary buffers.
Definition: LeafManager.h:262
LeafRange(size_t begin, size_t end, const LeafManager &leafManager, size_t grainSize=1)
Definition: LeafManager.h:173
virtual ~LeafManager()
Definition: LeafManager.h:237
TreeT::LeafIter LeafIterType
Definition: LeafManager.h:64
bool isConstTree() const
Return true if the tree associated with this manager is immutable.
Definition: LeafManager.h:314
Definition: Exceptions.h:88
Iterator end() const
Definition: LeafManager.h:178
void removeAuxBuffers()
Remove the auxiliary buffers, but don't rebuild the leaf array.
Definition: LeafManager.h:284
void rebuildLeafArray()
Remove the auxiliary buffers and rebuild the leaf array.
Definition: LeafManager.h:287
ManagerT::BufferType BufT
Definition: LeafManager.h:82
void operator()(const RangeType &r) const
Used internally by tbb::parallel_for() - never call it directly!
Definition: LeafManager.h:522
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:122
void rebuild(bool serial=false)
(Re)initialize by resizing (if necessary) and repopulating the leaf array and by deleting existing au...
Definition: LeafManager.h:250
LeafType::Buffer NonConstBufferType
Definition: LeafManager.h:119
static void doSwapLeafBuffer(const RangeT &, size_t, LeafT **, BufT *, size_t)
Definition: LeafManager.h:655
ManagerT::RangeType RangeT
Definition: LeafManager.h:651
ManagerT::LeafType LeafT
Definition: LeafManager.h:652
bool syncAuxBuffer(size_t bufferIdx, bool serial=false)
Sync up the specified auxiliary buffer with the corresponding leaf node buffer.
Definition: LeafManager.h:393
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
bool empty() const
Definition: LeafManager.h:186
bool isValid() const
Definition: LeafManager.h:154
void rebuild(TreeType &tree, size_t auxBuffersPerLeaf, bool serial=false)
Repopulate the leaf array and delete and reallocate auxiliary buffers.
Definition: LeafManager.h:267
bool empty() const
Return true if this iterator is exhausted.
Definition: LeafManager.h:160
ManagerT::BufferType BufT
Definition: LeafManager.h:653
bool swapLeafBuffer(size_t bufferIdx, bool serial=false)
Swap each leaf node's buffer with the nth corresponding auxiliary buffer, where n = bufferIdx...
Definition: LeafManager.h:359
const LeafManager & leafManager() const
Definition: LeafManager.h:184
const TreeType & tree() const
Return a const reference to tree associated with this manager.
Definition: LeafManager.h:302
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
leafmgr::TreeTraits< TreeT >::LeafIterType LeafIterType
Definition: LeafManager.h:118
Iterator begin() const
Definition: LeafManager.h:176
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
Definition: LeafManager.h:318
CopyConstness< TreeType, NonConstBufferType >::Type BufferType
Definition: LeafManager.h:120
LeafManager(const LeafManager &other)
Definition: LeafManager.h:225
size_t pos() const
Return the index into the leaf array of the current leaf node.
Definition: LeafManager.h:153
TreeType::LeafNodeType NonConstLeafType
Definition: LeafManager.h:115