OpenVDB  3.1.0
LeafManager.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2015 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 <boost/mpl/if.hpp>
49 #include <boost/type_traits/is_const.hpp>
50 #include <boost/type_traits/is_pointer.hpp>
51 #include <boost/type_traits/is_same.hpp>
52 #include <boost/type_traits/remove_pointer.hpp>
53 #include <tbb/blocked_range.h>
54 #include <tbb/parallel_for.h>
55 #include <openvdb/Types.h>
56 #include "TreeIterator.h" // for CopyConstness
57 
58 namespace openvdb {
60 namespace OPENVDB_VERSION_NAME {
61 namespace tree {
62 
63 namespace leafmgr {
64 
66 template<typename TreeT> struct TreeTraits {
68  static const bool IsConstTree = false;
69  typedef typename TreeT::LeafIter LeafIterType;
70 };
71 template<typename TreeT> struct TreeTraits<const TreeT> {
72  static const bool IsConstTree = true;
73  typedef typename TreeT::LeafCIter LeafIterType;
74 };
76 
77 } // namespace leafmgr
78 
79 
82 template<typename ManagerT>
84 {
85  typedef typename ManagerT::RangeType RangeT;
86  typedef typename ManagerT::LeafType LeafT;
87  typedef typename ManagerT::BufferType BufT;
88 
89  static inline void doSwapLeafBuffer(const RangeT& r, size_t auxBufferIdx,
90  LeafT** leafs, BufT* bufs, size_t bufsPerLeaf)
91  {
92  for (size_t n = r.begin(), m = r.end(), N = bufsPerLeaf; n != m; ++n) {
93  leafs[n]->swap(bufs[n * N + auxBufferIdx]);
94  }
95  }
96 };
97 
98 
100 
101 
113 template<typename TreeT>
115 {
116 public:
117  typedef TreeT TreeType;
118  typedef typename TreeT::ValueType ValueType;
119  typedef typename TreeT::RootNodeType RootNodeType;
120  typedef typename TreeType::LeafNodeType NonConstLeafType;
122  typedef LeafType LeafNodeType;
124  typedef typename LeafType::Buffer NonConstBufferType;
126  typedef tbb::blocked_range<size_t> RangeType;//leaf index range
127  static const Index DEPTH = 2;//root + leafs
128 
129  static const bool IsConstTree = leafmgr::TreeTraits<TreeT>::IsConstTree;
130 
131  class LeafRange
132  {
133  public:
134  class Iterator
135  {
136  public:
137  Iterator(const LeafRange& range, size_t pos): mRange(range), mPos(pos)
138  {
139  assert(this->isValid());
140  }
141  Iterator& operator=(const Iterator& other)
142  {
143  mRange = other.mRange; mPos = other.mPos; return *this;
144  }
146  Iterator& operator++() { ++mPos; return *this; }
148  LeafType& operator*() const { return mRange.mLeafManager.leaf(mPos); }
150  LeafType* operator->() const { return &(this->operator*()); }
153  BufferType& buffer(size_t bufferIdx)
154  {
155  return mRange.mLeafManager.getBuffer(mPos, bufferIdx);
156  }
158  size_t pos() const { return mPos; }
159  bool isValid() const { return mPos>=mRange.mBegin && mPos<=mRange.mEnd; }
161  bool test() const { return mPos < mRange.mEnd; }
163  operator bool() const { return this->test(); }
165  bool empty() const { return !this->test(); }
166  bool operator!=(const Iterator& other) const
167  {
168  return (mPos != other.mPos) || (&mRange != &other.mRange);
169  }
170  bool operator==(const Iterator& other) const { return !(*this != other); }
171  const LeafRange& leafRange() const { return mRange; }
172 
173  private:
174  const LeafRange& mRange;
175  size_t mPos;
176  };// end Iterator
177 
178  LeafRange(size_t begin, size_t end, const LeafManager& leafManager, size_t grainSize=1):
179  mEnd(end), mBegin(begin), mGrainSize(grainSize), mLeafManager(leafManager) {}
180 
181  Iterator begin() const {return Iterator(*this, mBegin);}
182 
183  Iterator end() const {return Iterator(*this, mEnd);}
184 
185  size_t size() const { return mEnd - mBegin; }
186 
187  size_t grainsize() const { return mGrainSize; }
188 
189  const LeafManager& leafManager() const { return mLeafManager; }
190 
191  bool empty() const {return !(mBegin < mEnd);}
192 
193  bool is_divisible() const {return mGrainSize < this->size();}
194 
195  LeafRange(LeafRange& r, tbb::split):
196  mEnd(r.mEnd), mBegin(doSplit(r)), mGrainSize(r.mGrainSize),
197  mLeafManager(r.mLeafManager) {}
198 
199  private:
200  size_t mEnd, mBegin, mGrainSize;
201  const LeafManager& mLeafManager;
202 
203  static size_t doSplit(LeafRange& r)
204  {
205  assert(r.is_divisible());
206  size_t middle = r.mBegin + (r.mEnd - r.mBegin) / 2u;
207  r.mEnd = middle;
208  return middle;
209  }
210  };// end of LeafRange
211 
214  LeafManager(TreeType& tree, size_t auxBuffersPerLeaf=0, bool serial=false):
215  mTree(&tree),
216  mLeafCount(0),
217  mAuxBufferCount(0),
218  mAuxBuffersPerLeaf(auxBuffersPerLeaf),
219  mLeafs(NULL),
220  mAuxBuffers(NULL),
221  mTask(0),
222  mIsMaster(true)
223  {
224  this->rebuild(serial);
225  }
226 
230  LeafManager(const LeafManager& other):
231  mTree(other.mTree),
232  mLeafCount(other.mLeafCount),
233  mAuxBufferCount(other.mAuxBufferCount),
234  mAuxBuffersPerLeaf(other.mAuxBuffersPerLeaf),
235  mLeafs(other.mLeafs),
236  mAuxBuffers(other.mAuxBuffers),
237  mTask(other.mTask),
238  mIsMaster(false)
239  {
240  }
241 
242  virtual ~LeafManager()
243  {
244  if (mIsMaster) {
245  delete [] mLeafs;
246  delete [] mAuxBuffers;
247  }
248  }
249 
255  void rebuild(bool serial=false)
256  {
257  this->initLeafArray();
258  this->initAuxBuffers(serial);
259  }
261  void rebuild(size_t auxBuffersPerLeaf, bool serial=false)
263  {
264  mAuxBuffersPerLeaf = auxBuffersPerLeaf;
265  this->rebuild(serial);
266  }
267  void rebuild(TreeType& tree, bool serial=false)
268  {
269  mTree = &tree;
270  this->rebuild(serial);
271  }
272  void rebuild(TreeType& tree, size_t auxBuffersPerLeaf, bool serial=false)
273  {
274  mTree = &tree;
275  mAuxBuffersPerLeaf = auxBuffersPerLeaf;
276  this->rebuild(serial);
277  }
279  void rebuildAuxBuffers(size_t auxBuffersPerLeaf, bool serial=false)
284  {
285  mAuxBuffersPerLeaf = auxBuffersPerLeaf;
286  this->initAuxBuffers(serial);
287  }
289  void removeAuxBuffers() { this->rebuildAuxBuffers(0); }
290 
293  {
294  this->removeAuxBuffers();
295  this->initLeafArray();
296  }
297 
299  size_t auxBufferCount() const { return mAuxBufferCount; }
301  size_t auxBuffersPerLeaf() const { return mAuxBuffersPerLeaf; }
302 
304  size_t leafCount() const { return mLeafCount; }
305 
307  const TreeType& tree() const { return *mTree; }
308 
310  TreeType& tree() { return *mTree; }
311 
313  const RootNodeType& root() const { return mTree->root(); }
314 
316  RootNodeType& root() { return mTree->root(); }
317 
319  bool isConstTree() const { return this->IsConstTree; }
320 
323  LeafType& leaf(size_t leafIdx) const { assert(leafIdx<mLeafCount); return *mLeafs[leafIdx]; }
324 
335  BufferType& getBuffer(size_t leafIdx, size_t bufferIdx) const
336  {
337  assert(leafIdx < mLeafCount);
338  assert(bufferIdx == 0 || bufferIdx - 1 < mAuxBuffersPerLeaf);
339  return bufferIdx == 0 ? mLeafs[leafIdx]->buffer()
340  : mAuxBuffers[leafIdx * mAuxBuffersPerLeaf + bufferIdx - 1];
341  }
342 
347  RangeType getRange(size_t grainsize = 1) const { return RangeType(0, mLeafCount, grainsize); }
348 
350  LeafRange leafRange(size_t grainsize = 1) const
351  {
352  return LeafRange(0, mLeafCount, *this, grainsize);
353  }
354 
364  bool swapLeafBuffer(size_t bufferIdx, bool serial = false)
365  {
366  if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf || this->isConstTree()) return false;
367  mTask = boost::bind(&LeafManager::doSwapLeafBuffer, _1, _2, bufferIdx - 1);
368  this->cook(serial ? 0 : 512);
369  return true;//success
370  }
375  bool swapBuffer(size_t bufferIdx1, size_t bufferIdx2, bool serial = false)
376  {
377  const size_t b1 = std::min(bufferIdx1, bufferIdx2);
378  const size_t b2 = std::max(bufferIdx1, bufferIdx2);
379  if (b1 == b2 || b2 > mAuxBuffersPerLeaf) return false;
380  if (b1 == 0) {
381  if (this->isConstTree()) return false;
382  mTask = boost::bind(&LeafManager::doSwapLeafBuffer, _1, _2, b2-1);
383  } else {
384  mTask = boost::bind(&LeafManager::doSwapAuxBuffer, _1, _2, b1-1, b2-1);
385  }
386  this->cook(serial ? 0 : 512);
387  return true;//success
388  }
389 
398  bool syncAuxBuffer(size_t bufferIdx, bool serial = false)
399  {
400  if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf) return false;
401  mTask = boost::bind(&LeafManager::doSyncAuxBuffer, _1, _2, bufferIdx - 1);
402  this->cook(serial ? 0 : 64);
403  return true;//success
404  }
405 
409  bool syncAllBuffers(bool serial = false)
410  {
411  switch (mAuxBuffersPerLeaf) {
412  case 0: return false;//nothing to do
413  case 1: mTask = boost::bind(&LeafManager::doSyncAllBuffers1, _1, _2); break;
414  case 2: mTask = boost::bind(&LeafManager::doSyncAllBuffers2, _1, _2); break;
415  default: mTask = boost::bind(&LeafManager::doSyncAllBuffersN, _1, _2); break;
416  }
417  this->cook(serial ? 0 : 64);
418  return true;//success
419  }
420 
480  template<typename LeafOp>
481  void foreach(const LeafOp& op, bool threaded = true, size_t grainSize=1)
482  {
483  LeafTransformer<LeafOp> transform(op);
484  transform.run(this->leafRange(grainSize), threaded);
485  }
486 
487 
488  template<typename ArrayT>
489  void getNodes(ArrayT& array)
490  {
491  typedef typename ArrayT::value_type T;
492  BOOST_STATIC_ASSERT(boost::is_pointer<T>::value);
493  typedef typename boost::mpl::if_<boost::is_const<typename boost::remove_pointer<T>::type>,
494  const LeafType, LeafType>::type LeafT;
495 
497  if (boost::is_same<T, LeafT*>::value) {
498  array.resize(mLeafCount);
499  for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
500  } else {
501  mTree->getNodes(array);
502  }
504  }
505 
506  template<typename ArrayT>
507  void getNodes(ArrayT& array) const
508  {
509  typedef typename ArrayT::value_type T;
510  BOOST_STATIC_ASSERT(boost::is_pointer<T>::value);
511  BOOST_STATIC_ASSERT(boost::is_const<typename boost::remove_pointer<T>::type>::value);
512 
514  if (boost::is_same<T, const LeafType*>::value) {
515  array.resize(mLeafCount);
516  for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
517  } else {
518  mTree->getNodes(array);
519  }
521  }
522 
524  // All methods below are for internal use only and should never be called directly
525 
527  void operator()(const RangeType& r) const
528  {
529  if (mTask) mTask(const_cast<LeafManager*>(this), r);
530  else OPENVDB_THROW(ValueError, "task is undefined");
531  }
532 
533 
534 
535  private:
536 
537  // This a simple wrapper for a c-style array so it mimics the api
538  // of a std container, e.g. std::vector or std::deque, and can be
539  // passed to Tree::getNodes().
540  struct MyArray {
541  typedef LeafType* value_type;//required by Tree::getNodes
542  value_type* ptr;
543  MyArray(value_type* array) : ptr(array) {}
544  void push_back(value_type leaf) { *ptr++ = leaf; }//required by Tree::getNodes
545  };
546 
547  void initLeafArray()
548  {
549  const size_t leafCount = mTree->leafCount();
550  if (leafCount != mLeafCount) {
551  delete [] mLeafs;
552  mLeafs = (leafCount == 0) ? NULL : new LeafType*[leafCount];
553  mLeafCount = leafCount;
554  }
555  MyArray a(mLeafs);
556  mTree->getNodes(a);
557  }
558 
559  void initAuxBuffers(bool serial)
560  {
561  const size_t auxBufferCount = mLeafCount * mAuxBuffersPerLeaf;
562  if (auxBufferCount != mAuxBufferCount) {
563  delete [] mAuxBuffers;
564  mAuxBuffers = (auxBufferCount == 0) ? NULL : new NonConstBufferType[auxBufferCount];
565  mAuxBufferCount = auxBufferCount;
566  }
567  this->syncAllBuffers(serial);
568  }
569 
570  void cook(size_t grainsize)
571  {
572  if (grainsize>0) {
573  tbb::parallel_for(this->getRange(grainsize), *this);
574  } else {
575  (*this)(this->getRange());
576  }
577  }
578 
579  void doSwapLeafBuffer(const RangeType& r, size_t auxBufferIdx)
580  {
582  r, auxBufferIdx, mLeafs, mAuxBuffers, mAuxBuffersPerLeaf);
583  }
584 
585  void doSwapAuxBuffer(const RangeType& r, size_t auxBufferIdx1, size_t auxBufferIdx2)
586  {
587  for (size_t N = mAuxBuffersPerLeaf, n = N*r.begin(), m = N*r.end(); n != m; n+=N) {
588  mAuxBuffers[n + auxBufferIdx1].swap(mAuxBuffers[n + auxBufferIdx2]);
589  }
590  }
591 
592  void doSyncAuxBuffer(const RangeType& r, size_t auxBufferIdx)
593  {
594  for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
595  mAuxBuffers[n*N + auxBufferIdx] = mLeafs[n]->buffer();
596  }
597  }
598 
599  void doSyncAllBuffers1(const RangeType& r)
600  {
601  for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
602  mAuxBuffers[n] = mLeafs[n]->buffer();
603  }
604  }
605 
606  void doSyncAllBuffers2(const RangeType& r)
607  {
608  for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
609  const BufferType& leafBuffer = mLeafs[n]->buffer();
610  mAuxBuffers[2*n ] = leafBuffer;
611  mAuxBuffers[2*n+1] = leafBuffer;
612  }
613  }
614 
615  void doSyncAllBuffersN(const RangeType& r)
616  {
617  for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
618  const BufferType& leafBuffer = mLeafs[n]->buffer();
619  for (size_t i=n*N, j=i+N; i!=j; ++i) mAuxBuffers[i] = leafBuffer;
620  }
621  }
622 
625  template<typename LeafOp>
626  struct LeafTransformer
627  {
628  LeafTransformer(const LeafOp& leafOp) : mLeafOp(leafOp) {}
629  void run(const LeafRange& range, bool threaded = true)
630  {
631  threaded ? tbb::parallel_for(range, *this) : (*this)(range);
632  }
633  void operator()(const LeafRange& range) const
634  {
635  for (typename LeafRange::Iterator it = range.begin(); it; ++it) mLeafOp(*it, it.pos());
636  }
637  const LeafOp mLeafOp;
638  };
639 
640  typedef typename boost::function<void (LeafManager*, const RangeType&)> FuncType;
641 
642  TreeType* mTree;
643  size_t mLeafCount, mAuxBufferCount, mAuxBuffersPerLeaf;
644  LeafType** mLeafs;//array of LeafNode pointers
645  NonConstBufferType* mAuxBuffers;//array of auxiliary buffers
646  FuncType mTask;
647  const bool mIsMaster;
648 };//end of LeafManager class
649 
650 
651 // Partial specializations of LeafManager methods for const trees
652 template<typename TreeT>
653 struct LeafManagerImpl<LeafManager<const TreeT> >
654 {
656  typedef typename ManagerT::RangeType RangeT;
657  typedef typename ManagerT::LeafType LeafT;
658  typedef typename ManagerT::BufferType BufT;
659 
660  static inline void doSwapLeafBuffer(const RangeT&, size_t /*auxBufferIdx*/,
661  LeafT**, BufT*, size_t /*bufsPerLeaf*/)
662  {
663  // Buffers can't be swapped into const trees.
664  }
665 };
666 
667 } // namespace tree
668 } // namespace OPENVDB_VERSION_NAME
669 } // namespace openvdb
670 
671 #endif // OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
672 
673 // Copyright (c) 2012-2015 DreamWorks Animation LLC
674 // All rights reserved. This software is distributed under the
675 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:608
LeafRange(size_t begin, size_t end, const LeafManager &leafManager, size_t grainSize=1)
Definition: LeafManager.h:178
bool operator!=(const Iterator &other) const
Definition: LeafManager.h:166
Index32 Index
Definition: Types.h:58
size_t auxBuffersPerLeaf() const
Return the number of auxiliary buffers per leaf node.
Definition: LeafManager.h:301
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:335
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:153
bool test() const
Return true if this iterator is not yet exhausted.
Definition: LeafManager.h:161
Useful traits for Tree types.
Definition: LeafManager.h:67
ManagerT::BufferType BufT
Definition: LeafManager.h:87
Definition: Exceptions.h:88
bool syncAllBuffers(bool serial=false)
Sync up all auxiliary buffers with their corresponding leaf node buffers.
Definition: LeafManager.h:409
bool empty() const
Definition: LeafManager.h:191
LeafType * operator->() const
Return a pointer to the leaf node to which this iterator is pointing.
Definition: LeafManager.h:150
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:350
TreeT::LeafCIter LeafIterType
Definition: LeafManager.h:73
void rebuildLeafArray()
Remove the auxiliary buffers and rebuild the leaf array.
Definition: LeafManager.h:292
This class manages a linear array of pointers to a given tree&#39;s leaf nodes, as well as optional auxil...
Definition: LeafManager.h:114
size_t auxBufferCount() const
Return the total number of allocated auxiliary buffers.
Definition: LeafManager.h:299
LeafType::Buffer NonConstBufferType
Definition: LeafManager.h:124
Iterator & operator++()
Advance to the next leaf node.
Definition: LeafManager.h:146
const LeafManager & leafManager() const
Definition: LeafManager.h:189
boost::remove_const< ToType >::type Type
Definition: TreeIterator.h:66
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:105
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:214
ManagerT::RangeType RangeT
Definition: LeafManager.h:656
bool swapLeafBuffer(size_t bufferIdx, bool serial=false)
Swap each leaf node&#39;s buffer with the nth corresponding auxiliary buffer, where n = bufferIdx...
Definition: LeafManager.h:364
Iterator & operator=(const Iterator &other)
Definition: LeafManager.h:141
Iterator end() const
Definition: LeafManager.h:183
LeafManager< const TreeT > ManagerT
Definition: LeafManager.h:655
const LeafRange & leafRange() const
Definition: LeafManager.h:171
Iterator begin() const
Definition: LeafManager.h:181
leafmgr::TreeTraits< TreeT >::LeafIterType LeafIterType
Definition: LeafManager.h:123
void getNodes(ArrayT &array) const
Definition: LeafManager.h:507
void rebuild(bool serial=false)
(Re)initialize by resizing (if necessary) and repopulating the leaf array and by deleting existing au...
Definition: LeafManager.h:255
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
Definition: LeafManager.h:323
LeafType & operator*() const
Return a reference to the leaf node to which this iterator is pointing.
Definition: LeafManager.h:148
ManagerT::RangeType RangeT
Definition: LeafManager.h:85
size_t pos() const
Return the index into the leaf array of the current leaf node.
Definition: LeafManager.h:158
#define OPENVDB_VERSION_NAME
Definition: version.h:43
void rebuild(TreeType &tree, size_t auxBuffersPerLeaf, bool serial=false)
Repopulate the leaf array and delete and reallocate auxiliary buffers.
Definition: LeafManager.h:272
tbb::blocked_range< size_t > RangeType
Definition: LeafManager.h:126
const TreeType & tree() const
Return a const reference to tree associated with this manager.
Definition: LeafManager.h:307
TreeT TreeType
Definition: LeafManager.h:117
ManagerT::LeafType LeafT
Definition: LeafManager.h:657
RootNodeType & root()
Return a reference to the root node associated with this manager.
Definition: LeafManager.h:316
bool isValid() const
Definition: LeafManager.h:159
bool empty() const
Return true if this iterator is exhausted.
Definition: LeafManager.h:165
Definition: Exceptions.h:39
bool syncAuxBuffer(size_t bufferIdx, bool serial=false)
Sync up the specified auxiliary buffer with the corresponding leaf node buffer.
Definition: LeafManager.h:398
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:129
void rebuild(TreeType &tree, bool serial=false)
Repopulate the leaf array and delete and reallocate auxiliary buffers.
Definition: LeafManager.h:267
size_t grainsize() const
Definition: LeafManager.h:187
size_t leafCount() const
Return the number of leaf nodes.
Definition: LeafManager.h:304
CopyConstness< TreeType, NonConstBufferType >::Type BufferType
Definition: LeafManager.h:125
LeafManager(const LeafManager &other)
Definition: LeafManager.h:230
TreeT::LeafIter LeafIterType
Definition: LeafManager.h:69
TreeT::ValueType ValueType
Definition: LeafManager.h:118
bool swapBuffer(size_t bufferIdx1, size_t bufferIdx2, bool serial=false)
Swap any two buffers for each leaf node.
Definition: LeafManager.h:375
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:130
virtual ~LeafManager()
Definition: LeafManager.h:242
size_t size() const
Definition: LeafManager.h:185
static void doSwapLeafBuffer(const RangeT &, size_t, LeafT **, BufT *, size_t)
Definition: LeafManager.h:660
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:109
ManagerT::BufferType BufT
Definition: LeafManager.h:658
TreeType & tree()
Return a reference to the tree associated with this manager.
Definition: LeafManager.h:310
bool is_divisible() const
Definition: LeafManager.h:193
LeafRange(LeafRange &r, tbb::split)
Definition: LeafManager.h:195
RangeType getRange(size_t grainsize=1) const
Return a tbb::blocked_range of leaf array indices.
Definition: LeafManager.h:347
static void doSwapLeafBuffer(const RangeT &r, size_t auxBufferIdx, LeafT **leafs, BufT *bufs, size_t bufsPerLeaf)
Definition: LeafManager.h:89
void operator()(const RangeType &r) const
Used internally by tbb::parallel_for() - never call it directly!
Definition: LeafManager.h:527
void getNodes(ArrayT &array)
Definition: LeafManager.h:489
Definition: LeafManager.h:83
bool operator==(const Iterator &other) const
Definition: LeafManager.h:170
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
ManagerT::LeafType LeafT
Definition: LeafManager.h:86
CopyConstness< TreeType, NonConstLeafType >::Type LeafType
Definition: LeafManager.h:121
LeafType LeafNodeType
Definition: LeafManager.h:122
bool isConstTree() const
Return true if the tree associated with this manager is immutable.
Definition: LeafManager.h:319
TreeType::LeafNodeType NonConstLeafType
Definition: LeafManager.h:120
Iterator(const LeafRange &range, size_t pos)
Definition: LeafManager.h:137
const RootNodeType & root() const
Return a const reference to root node associated with this manager.
Definition: LeafManager.h:313
void removeAuxBuffers()
Remove the auxiliary buffers, but don&#39;t rebuild the leaf array.
Definition: LeafManager.h:289
TreeT::RootNodeType RootNodeType
Definition: LeafManager.h:119