OpenVDB  2.0.0
LeafNodeBool.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_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
32 #define OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
33 
34 #include <iostream>
35 #include <boost/shared_ptr.hpp>
36 #include <boost/shared_array.hpp>
37 #include <boost/static_assert.hpp>
38 #include <openvdb/Types.h>
39 #include <openvdb/io/Compression.h> // for io::readData(), etc.
40 #include <openvdb/util/NodeMasks.h>
41 #include "LeafNode.h"
42 #include "Iterator.h"
43 #include "Util.h"
44 
45 
46 namespace openvdb {
48 namespace OPENVDB_VERSION_NAME {
49 namespace tree {
50 
53 template<Index Log2Dim>
54 class LeafNode<bool, Log2Dim>
55 {
56 public:
58  typedef boost::shared_ptr<LeafNodeType> Ptr;
59  typedef bool ValueType;
61 
62  // These static declarations must be on separate lines to avoid VC9 compiler errors.
63  static const Index LOG2DIM = Log2Dim; // needed by parent nodes
64  static const Index TOTAL = Log2Dim; // needed by parent nodes
65  static const Index DIM = 1 << TOTAL; // dimension along one coordinate direction
66  static const Index NUM_VALUES = 1 << 3 * Log2Dim;
67  static const Index NUM_VOXELS = NUM_VALUES; // total number of voxels represented by this node
68  static const Index SIZE = NUM_VALUES;
69  static const Index LEVEL = 0; // level 0 = leaf
70 
73  template<typename ValueType>
74  struct ValueConverter { typedef LeafNode<ValueType, Log2Dim> Type; };
75 
76  class Buffer
77  {
78  public:
79  Buffer() {}
80  Buffer(bool on) : mData(on) {}
81  Buffer(const NodeMaskType& other): mData(other) {}
82  Buffer(const Buffer& other): mData(other.mData) {}
83  ~Buffer() {}
84  void fill(bool val) { mData.set(val); }
85  Buffer& operator=(const Buffer& b) { if (&b != this) { mData = b.mData; } return *this; }
86 
87  const bool& getValue(Index i) const
88  {
89  assert(i < SIZE);
90  return mData.isOn(i) ? LeafNode::sOn : LeafNode::sOff;
91  }
92  const bool& operator[](Index i) const { return this->getValue(i); }
93 
94  bool operator==(const Buffer& other) const { return mData == other.mData; }
95  bool operator!=(const Buffer& other) const { return mData != other.mData; }
96 
97  void setValue(Index i, bool val) { assert(i < SIZE); mData.set(i, val); }
98 
99  void swap(Buffer& other) { if (&other != this) std::swap(mData, other.mData); }
100 
101  Index memUsage() const { return mData.memUsage(); }
102  static Index size() { return SIZE; }
103 
104  private:
105  friend class ::TestLeaf;
106  // Allow the parent LeafNode to access this Buffer's bit mask.
107  friend class LeafNode;
108 
109  NodeMaskType mData;
110  }; // class Buffer
111 
112 
114  LeafNode();
115 
120  explicit LeafNode(const Coord& xyz, bool value = false, bool active = false);
121 
123  LeafNode(const LeafNode&);
124 
126  template<typename ValueType>
128 
131  template<typename ValueType>
133  bool offValue, bool onValue, TopologyCopy);
134  template<typename ValueType>
136  bool background, TopologyCopy);
137 
139  ~LeafNode();
140 
141  //
142  // Statistics
143  //
145  static Index log2dim() { return Log2Dim; }
147  static Index dim() { return DIM; }
148  static Index size() { return SIZE; }
149  static Index numValues() { return SIZE; }
150  static Index getLevel() { return LEVEL; }
151  static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
152  static Index getChildDim() { return 1; }
153 
154  static Index32 leafCount() { return 1; }
155  static Index32 nonLeafCount() { return 0; }
156 
158  Index64 onVoxelCount() const { return mValueMask.countOn(); }
160  Index64 offVoxelCount() const { return mValueMask.countOff(); }
161  Index64 onLeafVoxelCount() const { return onVoxelCount(); }
162  Index64 offLeafVoxelCount() const { return offVoxelCount(); }
163  static Index64 onTileCount() { return 0; }
164  static Index64 offTileCount() { return 0; }
165 
167  bool isEmpty() const { return mValueMask.isOff(); }
169  bool isDense() const { return mValueMask.isOn(); }
170 
172  Index64 memUsage() const;
173 
177  void evalActiveBoundingBox(CoordBBox&, bool visitVoxels = true) const;
178  OPENVDB_DEPRECATED void evalActiveVoxelBoundingBox(CoordBBox& bbox) const;
179 
182  CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
183 
185  void setOrigin(const Coord& origin) { mOrigin = origin; }
188  OPENVDB_DEPRECATED const Coord& getOrigin() const { return mOrigin; }
190  const Coord& origin() const { return mOrigin; }
192  void getOrigin(Coord& origin) const { origin = mOrigin; }
193  void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
195 
197  static Index coordToOffset(const Coord& xyz);
200  static Coord offsetToLocalCoord(Index n);
202  Coord offsetToGlobalCoord(Index n) const;
203 
205  std::string str() const;
206 
209  template<typename OtherType, Index OtherLog2Dim>
210  bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
211 
213  bool operator==(const LeafNode&) const;
214  bool operator!=(const LeafNode&) const;
215 
216  //
217  // Buffer management
218  //
221  void swap(Buffer& other) { mBuffer.swap(other); }
222  const Buffer& buffer() const { return mBuffer; }
223  Buffer& buffer() { return mBuffer; }
224 
225  //
226  // I/O methods
227  //
229  void readTopology(std::istream&, bool fromHalf = false);
231  void writeTopology(std::ostream&, bool toHalf = false) const;
232 
234  void readBuffers(std::istream&, bool fromHalf = false);
236  void writeBuffers(std::ostream&, bool toHalf = false) const;
237 
238  //
239  // Accessor methods
240  //
242  const bool& getValue(const Coord& xyz) const;
244  const bool& getValue(Index offset) const;
245 
249  bool probeValue(const Coord& xyz, bool& val) const;
250 
252  static Index getValueLevel(const Coord&) { return LEVEL; }
253 
255  void setActiveState(const Coord& xyz, bool on);
257  void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
258 
260  void setValueOnly(const Coord& xyz, bool val);
262  void setValueOnly(Index offset, bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
263 
265  void setValueOff(const Coord& xyz) { mValueMask.setOff(this->coordToOffset(xyz)); }
267  void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
268 
270  void setValueOff(const Coord& xyz, bool val);
272  void setValueOff(Index offset, bool val);
273 
275  void setValueOn(const Coord& xyz) { mValueMask.setOn(this->coordToOffset(xyz)); }
277  void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
278 
280  void setValueOn(const Coord& xyz, bool val);
282  void setValue(const Coord& xyz, bool val) { this->setValueOn(xyz, val); };
284  void setValueOn(Index offset, bool val);
285 
288  template<typename ModifyOp>
289  void modifyValue(Index offset, const ModifyOp& op);
292  template<typename ModifyOp>
293  void modifyValue(const Coord& xyz, const ModifyOp& op);
294 
296  template<typename ModifyOp>
297  void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op);
298 
300  void setValuesOn() { mValueMask.setOn(); }
302  void setValuesOff() { mValueMask.setOff(); }
303 
305  bool isValueOn(const Coord& xyz) const { return mValueMask.isOn(this->coordToOffset(xyz)); }
307  bool isValueOn(Index offset) const { assert(offset < SIZE); return mValueMask.isOn(offset); }
308 
310  static bool hasActiveTiles() { return false; }
311 
313  void fill(const CoordBBox& bbox, bool value, bool active = true);
314 
316  void fill(const bool& value);
318  void fill(const bool& value, bool active);
319 
331  template<typename DenseT>
332  void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
333 
350  template<typename DenseT>
351  void copyFromDense(const CoordBBox& bbox, const DenseT& dense, bool background, bool tolerance);
352 
355  template<typename AccessorT>
356  const bool& getValueAndCache(const Coord& xyz, AccessorT&) const {return this->getValue(xyz);}
357 
360  template<typename AccessorT>
361  bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
362 
365  template<typename AccessorT>
366  void setValueAndCache(const Coord& xyz, bool val, AccessorT&) { this->setValueOn(xyz, val); }
367 
371  template<typename AccessorT>
372  void setValueOnlyAndCache(const Coord& xyz, bool val, AccessorT&) {this->setValueOnly(xyz,val);}
373 
376  template<typename AccessorT>
377  void setValueOffAndCache(const Coord& xyz, bool value, AccessorT&)
378  {
379  this->setValueOff(xyz, value);
380  }
381 
385  template<typename ModifyOp, typename AccessorT>
386  void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
387  {
388  this->modifyValue(xyz, op);
389  }
390 
393  template<typename ModifyOp, typename AccessorT>
394  void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
395  {
396  this->modifyValueAndActiveState(xyz, op);
397  }
398 
402  template<typename AccessorT>
403  void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
404  {
405  this->setActiveState(xyz, on);
406  }
407 
411  template<typename AccessorT>
412  bool probeValueAndCache(const Coord& xyz, bool& val, AccessorT&) const
413  {
414  return this->probeValue(xyz, val);
415  }
416 
419  template<typename AccessorT>
420  static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
421 
425  const bool& getFirstValue() const { if (mValueMask.isOn(0)) return sOn; else return sOff; }
429  const bool& getLastValue() const { if (mValueMask.isOn(SIZE-1)) return sOn; else return sOff; }
430 
434  bool isConstant(bool& constValue, bool& state, bool tolerance = 0) const;
436  bool isInactive() const { return mValueMask.isOff(); }
437 
438  void resetBackground(bool oldBackground, bool newBackground);
439 
440  void negate() { mBuffer.mData.toggle(); }
441 
442  template<MergePolicy Policy>
443  void merge(const LeafNode& other, bool bg = false, bool otherBG = false);
444  template<MergePolicy Policy> void merge(bool tileValue, bool tileActive);
445 
447 
454  template<typename OtherType>
455  void topologyUnion(const LeafNode<OtherType, Log2Dim>& other);
456 
468  template<typename OtherType>
469  void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const bool&);
470 
482  template<typename OtherType>
483  void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const bool&);
484 
485  template<typename CombineOp>
486  void combine(const LeafNode& other, CombineOp& op);
487  template<typename CombineOp>
488  void combine(bool, bool valueIsActive, CombineOp& op);
489 
490  template<typename CombineOp>
491  void combine2(const LeafNode& other, bool, bool valueIsActive, CombineOp&);
492  template<typename CombineOp>
493  void combine2(bool, const LeafNode& other, bool valueIsActive, CombineOp&);
494  template<typename CombineOp>
495  void combine2(const LeafNode& b0, const LeafNode& b1, CombineOp&);
496 
501  template<typename BBoxOp> void visitActiveBBox(BBoxOp&) const;
502 
503  template<typename VisitorOp> void visit(VisitorOp&);
504  template<typename VisitorOp> void visit(VisitorOp&) const;
505 
506  template<typename OtherLeafNodeType, typename VisitorOp>
507  void visit2Node(OtherLeafNodeType& other, VisitorOp&);
508  template<typename OtherLeafNodeType, typename VisitorOp>
509  void visit2Node(OtherLeafNodeType& other, VisitorOp&) const;
510  template<typename IterT, typename VisitorOp>
511  void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false);
512  template<typename IterT, typename VisitorOp>
513  void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false) const;
514 
516  void signedFloodFill(bool) {}
519  void signedFloodFill(bool, bool) {}
520  template<typename PruneOp> void pruneOp(PruneOp&) {}
521  void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
522  void pruneInactive(const ValueType&) {}
523  void addLeaf(LeafNode*) {}
524  template<typename AccessorT>
525  void addLeafAndCache(LeafNode*, AccessorT&) {}
526  template<typename NodeT>
527  NodeT* stealNode(const Coord&, const ValueType&, bool) { return NULL; }
528  template<typename NodeT>
529  NodeT* probeNode(const Coord&) { return NULL; }
530  template<typename NodeT>
531  const NodeT* probeConstNode(const Coord&) const { return NULL; }
533 
534  void addTile(Index level, const Coord&, bool val, bool active);
535  void addTile(Index offset, bool val, bool active);
536  template<typename AccessorT>
537  void addTileAndCache(Index level, const Coord&, bool val, bool active, AccessorT&);
538 
540  LeafNode* touchLeaf(const Coord&) { return this; }
542  template<typename AccessorT>
543  LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
544  LeafNode* probeLeaf(const Coord&) { return this; }
545  template<typename AccessorT>
546  LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
547  template<typename NodeT, typename AccessorT>
548  NodeT* probeNodeAndCache(const Coord&, AccessorT&)
549  {
551  if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
552  return reinterpret_cast<NodeT*>(this);
554  }
556 
557  const LeafNode* probeLeaf(const Coord&) const { return this; }
559  template<typename AccessorT>
560  const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
561  const LeafNode* probeConstLeaf(const Coord&) const { return this; }
562  template<typename AccessorT>
563  const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
564  template<typename NodeT, typename AccessorT>
565  const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
566  {
568  if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
569  return reinterpret_cast<const NodeT*>(this);
571  }
573 
574  //
575  // Iterators
576  //
577 protected:
581 
582  template<typename MaskIterT, typename NodeT, typename ValueT>
583  struct ValueIter:
584  // Derives from SparseIteratorBase, but can also be used as a dense iterator,
585  // if MaskIterT is a dense mask iterator type.
586  public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
587  {
589 
591  ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
592 
593  const bool& getItem(Index pos) const { return this->parent().getValue(pos); }
594  const bool& getValue() const { return this->getItem(this->pos()); }
595 
596  // Note: setItem() can't be called on const iterators.
597  void setItem(Index pos, bool value) const { this->parent().setValueOnly(pos, value); }
598  // Note: setValue() can't be called on const iterators.
599  void setValue(bool value) const { this->setItem(this->pos(), value); }
600 
601  // Note: modifyItem() can't be called on const iterators.
602  template<typename ModifyOp>
603  void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
604  // Note: modifyValue() can't be called on const iterators.
605  template<typename ModifyOp>
606  void modifyValue(const ModifyOp& op) const { this->modifyItem(this->pos(), op); }
607  };
608 
610  template<typename MaskIterT, typename NodeT>
611  struct ChildIter:
612  public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>
613  {
615  ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
616  MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
617  };
618 
619  template<typename NodeT, typename ValueT>
620  struct DenseIter: public DenseIteratorBase<
621  MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, /*ChildT=*/void, ValueT>
622  {
625 
627  DenseIter(const MaskDenseIter& iter, NodeT* parent): BaseT(iter, parent) {}
628 
629  bool getItem(Index pos, void*& child, NonConstValueT& value) const
630  {
631  value = this->parent().getValue(pos);
632  child = NULL;
633  return false; // no child
634  }
635 
636  // Note: setItem() can't be called on const iterators.
637  //void setItem(Index pos, void* child) const {}
638 
639  // Note: unsetItem() can't be called on const iterators.
640  void unsetItem(Index pos, const ValueT& val) const {this->parent().setValueOnly(pos, val);}
641  };
642 
643 public:
644  typedef ValueIter<MaskOnIter, LeafNode, bool> ValueOnIter;
645  typedef ValueIter<MaskOnIter, const LeafNode, const bool> ValueOnCIter;
646  typedef ValueIter<MaskOffIter, LeafNode, bool> ValueOffIter;
647  typedef ValueIter<MaskOffIter, const LeafNode, const bool> ValueOffCIter;
648  typedef ValueIter<MaskDenseIter, LeafNode, bool> ValueAllIter;
649  typedef ValueIter<MaskDenseIter, const LeafNode, const bool> ValueAllCIter;
650  typedef ChildIter<MaskOnIter, LeafNode> ChildOnIter;
651  typedef ChildIter<MaskOnIter, const LeafNode> ChildOnCIter;
652  typedef ChildIter<MaskOffIter, LeafNode> ChildOffIter;
653  typedef ChildIter<MaskOffIter, const LeafNode> ChildOffCIter;
654  typedef DenseIter<LeafNode, bool> ChildAllIter;
655  typedef DenseIter<const LeafNode, const bool> ChildAllCIter;
656 
657  ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
658  ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
659  ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
660  ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
661  ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
662  ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
663  ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
664  ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
665  ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
666 
667  ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
668  ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
669  ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
670  ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
671  ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
672  ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
673  ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
674  ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
675  ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
676 
677  // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
678  // because leaf nodes have no children.
679  ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
680  ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
681  ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
682  ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
683  ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
684  ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
685  ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
686  ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
687  ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
688 
689  ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
690  ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
691  ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
692  ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
693  ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
694  ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
695  ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
696  ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
697  ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
698 
699  //
700  // Mask accessors
701  //
702  bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
703  bool isValueMaskOn() const { return mValueMask.isOn(); }
704  bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
705  bool isValueMaskOff() const { return mValueMask.isOff(); }
706  const NodeMaskType& getValueMask() const { return mValueMask; }
707  NodeMaskType& getValueMask() { return mValueMask; }
708  void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
709  bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
710  bool isChildMaskOff(Index) const { return true; }
711  bool isChildMaskOff() const { return true; }
712 protected:
713  void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
714  void setValueMaskOn(Index n) { mValueMask.setOn(n); }
715  void setValueMaskOff(Index n) { mValueMask.setOff(n); }
716 
718  static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
719 
720  template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
721  static inline void doVisit(NodeT&, VisitorOp&);
722 
723  template<typename NodeT, typename OtherNodeT, typename VisitorOp,
724  typename ChildAllIterT, typename OtherChildAllIterT>
725  static inline void doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp&);
726 
727  template<typename NodeT, typename VisitorOp,
728  typename ChildAllIterT, typename OtherChildAllIterT>
729  static inline void doVisit2(NodeT& self, OtherChildAllIterT&, VisitorOp&, bool otherIsLHS);
730 
731 
735  Buffer mBuffer;
737  Coord mOrigin;
738 
739  // These static declarations must be on separate lines to avoid VC9 compiler errors.
740  static const bool sOn;
741  static const bool sOff;
742 
743 private:
746  template<typename, Index> friend class LeafNode;
747 
748  friend struct ValueIter<MaskOnIter, LeafNode, bool>;
749  friend struct ValueIter<MaskOffIter, LeafNode, bool>;
750  friend struct ValueIter<MaskDenseIter, LeafNode, bool>;
751  friend struct ValueIter<MaskOnIter, const LeafNode, bool>;
752  friend struct ValueIter<MaskOffIter, const LeafNode, bool>;
753  friend struct ValueIter<MaskDenseIter, const LeafNode, bool>;
754 
756  friend class IteratorBase<MaskOnIter, LeafNode>;
762 
763 }; // class LeafNode<bool>
764 
765 
770 template<Index Log2Dim> const bool LeafNode<bool, Log2Dim>::sOn = true;
771 template<Index Log2Dim> const bool LeafNode<bool, Log2Dim>::sOff = false;
772 
773 
775 
776 
777 template<Index Log2Dim>
778 inline
780 {
781 }
782 
783 
784 template<Index Log2Dim>
785 inline
786 LeafNode<bool, Log2Dim>::LeafNode(const Coord& xyz, bool value, bool active):
787  mValueMask(active),
788  mBuffer(value),
789  mOrigin(xyz & (~(DIM - 1)))
790 {
791 }
792 
793 
794 template<Index Log2Dim>
795 template<typename ValueT>
796 inline
798  mValueMask(other.getValueMask()),
799  mBuffer(other.getValueMask()), // value = active state
800  mOrigin(other.origin())
801 {
802 }
803 
804 
805 template<Index Log2Dim>
806 template<typename ValueT>
807 inline
809  bool offValue, bool onValue, TopologyCopy):
810  mValueMask(other.getValueMask()),
811  mBuffer(other.getValueMask()),
812  mOrigin(other.origin())
813 {
814  if (offValue) { if (!onValue) mBuffer.mData.toggle(); else mBuffer.mData.setOn(); }
815 }
816 
817 
818 template<Index Log2Dim>
819 template<typename ValueT>
820 inline
822  bool background, TopologyCopy):
823  mValueMask(other.getValueMask()),
824  mBuffer(background),
825  mOrigin(other.origin())
826 {
827 }
828 
829 
830 template<Index Log2Dim>
831 inline
833  mValueMask(other.mValueMask),
834  mBuffer(other.mBuffer),
835  mOrigin(other.mOrigin)
836 {
837 }
838 
839 
840 template<Index Log2Dim>
841 inline
843 {
844 }
845 
846 
848 
849 
850 template<Index Log2Dim>
851 inline Index64
853 {
854  return sizeof(mOrigin) + mValueMask.memUsage() + mBuffer.memUsage();
855 }
856 
857 
858 template<Index Log2Dim>
859 inline void
861 {
862  const CoordBBox this_bbox = this->getNodeBoundingBox();
863  if (bbox.isInside(this_bbox)) {
864  // nothing to do
865  } else if (this->isDense()) {
866  bbox.expand(this_bbox);
867  } else {
868  for (ValueOnCIter iter=this->cbeginValueOn(); iter; ++iter) bbox.expand(iter.getCoord());
869  }
870 }
871 
872 template<Index Log2Dim>
873 inline void
874 LeafNode<bool, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
875 {
876  CoordBBox this_bbox = this->getNodeBoundingBox();
877  if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
878  if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
879  if (visitVoxels) {//use voxel granularity?
880  this_bbox.reset();
881  for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
882  this_bbox.translate(this->origin());
883  }
884  bbox.expand(this_bbox);
885  }
886 }
887 
888 
889 template<Index Log2Dim>
890 template<typename OtherType, Index OtherLog2Dim>
891 inline bool
893 {
894  assert(other);
895  return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
896 }
897 
898 
899 template<Index Log2Dim>
900 inline std::string
902 {
903  std::ostringstream ostr;
904  ostr << "LeafNode @" << mOrigin << ": ";
905  for (Index32 n = 0; n < SIZE; ++n) ostr << (mValueMask.isOn(n) ? '#' : '.');
906  return ostr.str();
907 }
908 
909 
911 
912 
913 template<Index Log2Dim>
914 inline Index
916 {
917  assert ((xyz[0] & DIM-1u) < DIM && (xyz[1] & DIM-1u) < DIM && (xyz[2] & DIM-1u) < DIM);
918  return ((xyz[0] & DIM-1u) << 2*Log2Dim) + ((xyz[1] & DIM-1u) << Log2Dim) + (xyz[2] & DIM-1u);
919 }
920 
921 
922 template<Index Log2Dim>
923 inline Coord
925 {
926  assert(n < (1 << 3*Log2Dim));
927  Coord xyz;
928  xyz.setX(n >> 2*Log2Dim);
929  n &= ((1 << 2*Log2Dim) - 1);
930  xyz.setY(n >> Log2Dim);
931  xyz.setZ(n & ((1 << Log2Dim) - 1));
932  return xyz;
933 }
934 
935 
936 template<Index Log2Dim>
937 inline Coord
939 {
940  return (this->offsetToLocalCoord(n) + this->origin());
941 }
942 
943 
945 
946 
947 template<Index Log2Dim>
948 inline void
949 LeafNode<bool, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
950 {
951  mValueMask.load(is);
952 }
953 
954 
955 template<Index Log2Dim>
956 inline void
957 LeafNode<bool, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
958 {
959  mValueMask.save(os);
960 }
961 
962 
963 template<Index Log2Dim>
964 inline void
965 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, bool /*fromHalf*/)
966 {
967  // Read in the value mask.
968  mValueMask.load(is);
969  // Read in the origin.
970  is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
971 
973  // Read in the mask for the voxel values.
974  mBuffer.mData.load(is);
975  } else {
976  // Older files stored one or more bool arrays.
977 
978  // Read in the number of buffers, which should now always be one.
979  int8_t numBuffers = 0;
980  is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
981 
982  // Read in the buffer.
983  // (Note: prior to the bool leaf optimization, buffers were always compressed.)
984  boost::shared_array<bool> buf(new bool[SIZE]);
985  io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
986 
987  // Transfer values to mBuffer.
988  mBuffer.mData.setOff();
989  for (Index i = 0; i < SIZE; ++i) {
990  if (buf[i]) mBuffer.mData.setOn(i);
991  }
992 
993  if (numBuffers > 1) {
994  // Read in and discard auxiliary buffers that were created with
995  // earlier versions of the library.
996  for (int i = 1; i < numBuffers; ++i) {
997  io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
998  }
999  }
1000  }
1001 }
1002 
1003 
1004 template<Index Log2Dim>
1005 inline void
1006 LeafNode<bool, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
1007 {
1008  // Write out the value mask.
1009  mValueMask.save(os);
1010  // Write out the origin.
1011  os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1012  // Write out the voxel values.
1013  mBuffer.mData.save(os);
1014 }
1015 
1016 
1018 
1019 
1020 template<Index Log2Dim>
1021 inline bool
1023 {
1024  return (mValueMask == other.mValueMask && mBuffer.mData == other.mBuffer.mData);
1025 }
1026 
1027 
1028 template<Index Log2Dim>
1029 inline bool
1031 {
1032  return !(this->operator==(other));
1033 }
1034 
1035 
1037 
1038 
1039 template<Index Log2Dim>
1040 inline bool
1041 LeafNode<bool, Log2Dim>::isConstant(bool& constValue, bool& state, bool tolerance) const
1042 {
1043  state = mValueMask.isOn();
1044 
1045  if (!(state || mValueMask.isOff())) return false;
1046 
1047  // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1048  if (!tolerance && !(mBuffer.mData.isOn() || mBuffer.mData.isOff())) return false;
1049 
1050  state = mValueMask.isOn();
1051  constValue = mBuffer.mData.isOn();
1052  return true;
1053 }
1054 
1055 
1057 
1058 
1059 template<Index Log2Dim>
1060 inline void
1061 LeafNode<bool, Log2Dim>::addTile(Index level, const Coord& xyz, bool val, bool active)
1062 {
1063  assert(level == 0);
1064  this->addTile(this->coordToOffset(xyz), val, active);
1065 }
1066 
1067 template<Index Log2Dim>
1068 inline void
1069 LeafNode<bool, Log2Dim>::addTile(Index offset, bool val, bool active)
1070 {
1071  assert(offset < SIZE);
1072  setValueOnly(offset, val);
1073  setActiveState(offset, active);
1074 }
1075 
1076 template<Index Log2Dim>
1077 template<typename AccessorT>
1078 inline void
1080  bool val, bool active, AccessorT&)
1081 {
1082  this->addTile(level, xyz, val, active);
1083 }
1084 
1085 
1087 
1088 
1089 template<Index Log2Dim>
1090 inline const bool&
1091 LeafNode<bool, Log2Dim>::getValue(const Coord& xyz) const
1092 {
1093  // This *CANNOT* use operator ? because Visual C++
1094  if (mBuffer.mData.isOn(this->coordToOffset(xyz))) return sOn; else return sOff;
1095 }
1096 
1097 
1098 template<Index Log2Dim>
1099 inline const bool&
1101 {
1102  assert(offset < SIZE);
1103  // This *CANNOT* use operator ? for Windows
1104  if (mBuffer.mData.isOn(offset)) return sOn; else return sOff;
1105 }
1106 
1107 
1108 template<Index Log2Dim>
1109 inline bool
1110 LeafNode<bool, Log2Dim>::probeValue(const Coord& xyz, bool& val) const
1111 {
1112  const Index offset = this->coordToOffset(xyz);
1113  val = mBuffer.mData.isOn(offset);
1114  return mValueMask.isOn(offset);
1115 }
1116 
1117 
1118 template<Index Log2Dim>
1119 inline void
1120 LeafNode<bool, Log2Dim>::setValueOn(const Coord& xyz, bool val)
1121 {
1122  this->setValueOn(this->coordToOffset(xyz), val);
1123 }
1124 
1125 
1126 template<Index Log2Dim>
1127 inline void
1129 {
1130  assert(offset < SIZE);
1131  mValueMask.setOn(offset);
1132  mBuffer.mData.set(offset, val);
1133 }
1134 
1135 
1136 template<Index Log2Dim>
1137 inline void
1138 LeafNode<bool, Log2Dim>::setValueOnly(const Coord& xyz, bool val)
1139 {
1140  this->setValueOnly(this->coordToOffset(xyz), val);
1141 }
1142 
1143 
1144 template<Index Log2Dim>
1145 inline void
1147 {
1148  mValueMask.set(this->coordToOffset(xyz), on);
1149 }
1150 
1151 
1152 template<Index Log2Dim>
1153 inline void
1154 LeafNode<bool, Log2Dim>::setValueOff(const Coord& xyz, bool val)
1155 {
1156  this->setValueOff(this->coordToOffset(xyz), val);
1157 }
1158 
1159 
1160 template<Index Log2Dim>
1161 inline void
1163 {
1164  assert(offset < SIZE);
1165  mValueMask.setOff(offset);
1166  mBuffer.mData.set(offset, val);
1167 }
1168 
1169 
1170 template<Index Log2Dim>
1171 template<typename ModifyOp>
1172 inline void
1173 LeafNode<bool, Log2Dim>::modifyValue(Index offset, const ModifyOp& op)
1174 {
1175  bool val = mBuffer.mData.isOn(offset);
1176  op(val);
1177  mBuffer.mData.set(offset, val);
1178  mValueMask.setOn(offset);
1179 }
1180 
1181 
1182 template<Index Log2Dim>
1183 template<typename ModifyOp>
1184 inline void
1185 LeafNode<bool, Log2Dim>::modifyValue(const Coord& xyz, const ModifyOp& op)
1186 {
1187  this->modifyValue(this->coordToOffset(xyz), op);
1188 }
1189 
1190 
1191 template<Index Log2Dim>
1192 template<typename ModifyOp>
1193 inline void
1194 LeafNode<bool, Log2Dim>::modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
1195 {
1196  const Index offset = this->coordToOffset(xyz);
1197  bool val = mBuffer.mData.isOn(offset), state = mValueMask.isOn(offset);
1198  op(val, state);
1199  mBuffer.mData.set(offset, val);
1200  mValueMask.set(offset, state);
1201 }
1202 
1203 
1205 
1206 
1207 template<Index Log2Dim>
1208 inline void
1209 LeafNode<bool, Log2Dim>::resetBackground(bool oldBackground, bool newBackground)
1210 {
1211  if (newBackground != oldBackground) {
1212  // Flip mBuffer's background bits and zero its foreground bits.
1213  NodeMaskType bgMask = !(mBuffer.mData | mValueMask);
1214  // Overwrite mBuffer's background bits, leaving its foreground bits intact.
1215  mBuffer.mData = (mBuffer.mData & mValueMask) | bgMask;
1216  }
1217 }
1218 
1219 
1220 template<Index Log2Dim>
1221 template<MergePolicy Policy>
1222 inline void
1223 LeafNode<bool, Log2Dim>::merge(const LeafNode& other, bool /*bg*/, bool /*otherBG*/)
1224 {
1226  if (Policy == MERGE_NODES) return;
1227  for (typename NodeMaskType::OnIterator iter = other.mValueMask.beginOn(); iter; ++iter) {
1228  const Index n = iter.pos();
1229  if (mValueMask.isOff(n)) {
1230  mBuffer.mData.set(n, other.mBuffer.mData.isOn(n));
1231  mValueMask.setOn(n);
1232  }
1233  }
1235 }
1236 
1237 template<Index Log2Dim>
1238 template<MergePolicy Policy>
1239 inline void
1240 LeafNode<bool, Log2Dim>::merge(bool tileValue, bool tileActive)
1241 {
1243  if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1244  if (!tileActive) return;
1245  // Replace all inactive values with the active tile value.
1246  if (tileValue) mBuffer.mData |= !mValueMask; // -0=>1, +0=>0, -1=>1, +1=>1 (-,+ = off,on)
1247  else mBuffer.mData &= mValueMask; // -0=>0, +0=>0, -1=>0, +1=>1
1248  mValueMask.setOn();
1250 }
1251 
1252 
1253 template<Index Log2Dim>
1254 template<typename OtherType>
1255 inline void
1257 {
1258  mValueMask |= other.getValueMask();
1259 }
1260 
1261 template<Index Log2Dim>
1262 template<typename OtherType>
1263 inline void
1265  const bool&)
1266 {
1267  mValueMask &= other.getValueMask();
1268 }
1269 
1270 template<Index Log2Dim>
1271 template<typename OtherType>
1272 inline void
1274  const bool&)
1275 {
1276  mValueMask &= !other.getValueMask();
1277 }
1278 
1279 template<Index Log2Dim>
1280 inline void
1281 LeafNode<bool, Log2Dim>::fill(const CoordBBox& bbox, bool value, bool active)
1282 {
1283  for (Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1284  const Index offsetX = (x&DIM-1u)<<2*Log2Dim;
1285  for (Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1286  const Index offsetXY = offsetX + ((y&DIM-1u)<< Log2Dim);
1287  for (Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1288  const Index offset = offsetXY + (z&DIM-1u);
1289  mValueMask.set(offset, active);
1290  mBuffer.mData.set(offset, value);
1291  }
1292  }
1293  }
1294 }
1295 
1296 template<Index Log2Dim>
1297 inline void
1299 {
1300  mBuffer.fill(value);
1301 }
1302 
1303 template<Index Log2Dim>
1304 inline void
1305 LeafNode<bool, Log2Dim>::fill(const bool& value, bool active)
1306 {
1307  mBuffer.fill(value);
1308  mValueMask.set(active);
1309 }
1310 
1311 
1313 
1314 
1315 template<Index Log2Dim>
1316 template<typename DenseT>
1317 inline void
1318 LeafNode<bool, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1319 {
1320  typedef typename DenseT::ValueType DenseValueType;
1321 
1322  const size_t xStride = dense.xStride(), yStride = dense.yStride();// zStride=1
1323  const Coord& min = dense.bbox().min();
1324  DenseValueType* t0 = dense.data() + bbox.min()[2]-min[2];//target array
1325  const Int32 n0 = bbox.min()[2]&DIM-1u;
1326  for (Int32 x = bbox.min()[0], ex=bbox.max()[0]+1; x<ex; ++x) {
1327  DenseValueType* t1 = t0 + xStride*(x-min[0]);
1328  const Int32 n1 = n0 + ((x&DIM-1u)<<2*LOG2DIM);
1329  for (Int32 y = bbox.min()[1], ey=bbox.max()[1]+1; y<ey; ++y) {
1330  DenseValueType* t2 = t1 + yStride*(y-min[1]);
1331  Int32 n2 = n1 + ((y&DIM-1u)<<LOG2DIM) ;
1332  for (Int32 z = bbox.min()[2], ez=bbox.max()[2]+1; z<ez ; ++z) {
1333  *t2++ = DenseValueType(mBuffer.mData.isOn(n2++));
1334  }
1335  }
1336  }
1337 }
1338 
1339 
1340 template<Index Log2Dim>
1341 template<typename DenseT>
1342 inline void
1343 LeafNode<bool, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1344  bool background, bool tolerance)
1345 {
1346  typedef typename DenseT::ValueType DenseValueType;
1347 
1348  const size_t xStride = dense.xStride(), yStride = dense.yStride();// zStride=1
1349  const Coord& min = dense.bbox().min();
1350  const DenseValueType* s0 = dense.data() + bbox.min()[2]-min[2];//source
1351  const Int32 n0 = bbox.min()[2]&DIM-1u;
1352  for (Int32 x = bbox.min()[0], ex=bbox.max()[0]+1; x<ex; ++x) {
1353  const DenseValueType* s1 = s0 + xStride*(x-min[0]);
1354  const Int32 n1 = n0 + ((x&DIM-1u)<<2*LOG2DIM);
1355  for (Int32 y = bbox.min()[1], ey=bbox.max()[1]+1; y<ey; ++y) {
1356  const DenseValueType* s2 = s1 + yStride*(y-min[1]);
1357  Int32 n2 = n1 + ((y&DIM-1u)<<LOG2DIM);
1358  for (Int32 z = bbox.min()[2], ez=bbox.max()[2]+1; z<ez ; ++z, ++n2, ++s2) {
1359  // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1360  if (tolerance || background == bool(*s2)) {
1361  mValueMask.setOff(n2);
1362  mBuffer.mData.set(n2, background);
1363  } else {
1364  mValueMask.setOn(n2);
1365  mBuffer.mData.set(n2, bool(*s2));
1366  }
1367  }
1368  }
1369  }
1370 }
1371 
1372 
1374 
1375 
1376 template<Index Log2Dim>
1377 template<typename CombineOp>
1378 inline void
1379 LeafNode<bool, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1380 {
1381  CombineArgs<bool> args;
1382  for (Index i = 0; i < SIZE; ++i) {
1383  bool result = false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1384  op(args.setARef(aVal)
1385  .setAIsActive(mValueMask.isOn(i))
1386  .setBRef(bVal)
1387  .setBIsActive(other.mValueMask.isOn(i))
1388  .setResultRef(result));
1389  mValueMask.set(i, args.resultIsActive());
1390  mBuffer.mData.set(i, result);
1391  }
1392 }
1393 
1394 
1395 template<Index Log2Dim>
1396 template<typename CombineOp>
1397 inline void
1398 LeafNode<bool, Log2Dim>::combine(bool value, bool valueIsActive, CombineOp& op)
1399 {
1400  CombineArgs<bool> args;
1401  args.setBRef(value).setBIsActive(valueIsActive);
1402  for (Index i = 0; i < SIZE; ++i) {
1403  bool result = false, aVal = mBuffer.mData.isOn(i);
1404  op(args.setARef(aVal)
1405  .setAIsActive(mValueMask.isOn(i))
1406  .setResultRef(result));
1407  mValueMask.set(i, args.resultIsActive());
1408  mBuffer.mData.set(i, result);
1409  }
1410 }
1411 
1412 
1414 
1415 
1416 template<Index Log2Dim>
1417 template<typename CombineOp>
1418 inline void
1420  bool valueIsActive, CombineOp& op)
1421 {
1422  CombineArgs<bool> args;
1423  args.setBRef(value).setBIsActive(valueIsActive);
1424  for (Index i = 0; i < SIZE; ++i) {
1425  bool result = false, aVal = other.mBuffer.mData.isOn(i);
1426  op(args.setARef(aVal)
1427  .setAIsActive(other.mValueMask.isOn(i))
1428  .setResultRef(result));
1429  mValueMask.set(i, args.resultIsActive());
1430  mBuffer.mData.set(i, result);
1431  }
1432 }
1433 
1434 
1435 template<Index Log2Dim>
1436 template<typename CombineOp>
1437 inline void
1439  bool valueIsActive, CombineOp& op)
1440 {
1441  CombineArgs<bool> args;
1442  args.setARef(value).setAIsActive(valueIsActive);
1443  for (Index i = 0; i < SIZE; ++i) {
1444  bool result = false, bVal = other.mBuffer.mData.isOn(i);
1445  op(args.setBRef(bVal)
1446  .setBIsActive(other.mValueMask.isOn(i))
1447  .setResultRef(result));
1448  mValueMask.set(i, args.resultIsActive());
1449  mBuffer.mData.set(i, result);
1450  }
1451 }
1452 
1453 
1454 template<Index Log2Dim>
1455 template<typename CombineOp>
1456 inline void
1457 LeafNode<bool, Log2Dim>::combine2(const LeafNode& b0, const LeafNode& b1, CombineOp& op)
1458 {
1459  CombineArgs<bool> args;
1460  for (Index i = 0; i < SIZE; ++i) {
1461  // Default behavior: output voxel is active if either input voxel is active.
1462  mValueMask.set(i, b0.mValueMask.isOn(i) || b1.mValueMask.isOn(i));
1463 
1464  bool result = false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1465  op(args.setARef(b0Val)
1466  .setAIsActive(b0.mValueMask.isOn(i))
1467  .setBRef(b1Val)
1468  .setBIsActive(b1.mValueMask.isOn(i))
1469  .setResultRef(result));
1470  mValueMask.set(i, args.resultIsActive());
1471  mBuffer.mData.set(i, result);
1472  }
1473 }
1474 
1475 
1477 
1478 template<Index Log2Dim>
1479 template<typename BBoxOp>
1480 inline void
1482 {
1483  if (op.template descent<LEVEL>()) {
1484  for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
1485 #ifdef _MSC_VER
1486  op.operator()<LEVEL>(CoordBBox(i.getCoord(),1));
1487 #else
1488  op.template operator()<LEVEL>(CoordBBox(i.getCoord(),1));
1489 #endif
1490  }
1491  } else {
1492 #ifdef _MSC_VER
1493  op.operator()<LEVEL>(this->getNodeBoundingBox());
1494 #else
1495  op.template operator()<LEVEL>(this->getNodeBoundingBox());
1496 #endif
1497  }
1498 }
1499 
1500 
1501 template<Index Log2Dim>
1502 template<typename VisitorOp>
1503 inline void
1505 {
1506  doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
1507 }
1508 
1509 
1510 template<Index Log2Dim>
1511 template<typename VisitorOp>
1512 inline void
1514 {
1515  doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
1516 }
1517 
1518 
1519 template<Index Log2Dim>
1520 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1521 inline void
1522 LeafNode<bool, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
1523 {
1524  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1525  op(iter);
1526  }
1527 }
1528 
1529 
1531 
1532 
1533 template<Index Log2Dim>
1534 template<typename OtherLeafNodeType, typename VisitorOp>
1535 inline void
1536 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
1537 {
1538  doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
1539  typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
1540 }
1541 
1542 
1543 template<Index Log2Dim>
1544 template<typename OtherLeafNodeType, typename VisitorOp>
1545 inline void
1546 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
1547 {
1548  doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
1549  typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
1550 }
1551 
1552 
1553 template<Index Log2Dim>
1554 template<
1555  typename NodeT,
1556  typename OtherNodeT,
1557  typename VisitorOp,
1558  typename ChildAllIterT,
1559  typename OtherChildAllIterT>
1560 inline void
1561 LeafNode<bool, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
1562 {
1563  // Allow the two nodes to have different ValueTypes, but not different dimensions.
1564  BOOST_STATIC_ASSERT(OtherNodeT::SIZE == NodeT::SIZE);
1565  BOOST_STATIC_ASSERT(OtherNodeT::LEVEL == NodeT::LEVEL);
1566 
1567  ChildAllIterT iter = self.beginChildAll();
1568  OtherChildAllIterT otherIter = other.beginChildAll();
1569 
1570  for ( ; iter && otherIter; ++iter, ++otherIter) {
1571  op(iter, otherIter);
1572  }
1573 }
1574 
1575 
1577 
1578 
1579 template<Index Log2Dim>
1580 template<typename IterT, typename VisitorOp>
1581 inline void
1582 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
1583 {
1584  doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(*this, otherIter, op, otherIsLHS);
1585 }
1586 
1587 
1588 template<Index Log2Dim>
1589 template<typename IterT, typename VisitorOp>
1590 inline void
1591 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
1592 {
1593  doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(*this, otherIter, op, otherIsLHS);
1594 }
1595 
1596 
1597 template<Index Log2Dim>
1598 template<
1599  typename NodeT,
1600  typename VisitorOp,
1601  typename ChildAllIterT,
1602  typename OtherChildAllIterT>
1603 inline void
1604 LeafNode<bool, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
1605  VisitorOp& op, bool otherIsLHS)
1606 {
1607  if (!otherIter) return;
1608 
1609  if (otherIsLHS) {
1610  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1611  op(otherIter, iter);
1612  }
1613  } else {
1614  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1615  op(iter, otherIter);
1616  }
1617  }
1618 }
1619 
1620 } // namespace tree
1621 } // namespace OPENVDB_VERSION_NAME
1622 } // namespace openvdb
1623 
1624 #endif // OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
1625 
1626 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1627 // All rights reserved. This software is distributed under the
1628 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
ValueIter< MaskDenseIter, LeafNode, bool > ValueAllIter
Definition: LeafNodeBool.h:648
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:358
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeBool.h:718
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeBool.h:603
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeBool.h:679
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeBool.h:647
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeBool.h:307
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1507
ChildAllCIter cendChildAll() const
Definition: LeafNodeBool.h:695
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don&#39;t change its value.
Definition: LeafNode.h:466
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:563
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeBool.h:653
void load(std::istream &is)
Definition: NodeMasks.h:496
const bool & operator[](Index i) const
Definition: LeafNodeBool.h:92
void evalActiveBoundingBox(CoordBBox &, bool visitVoxels=true) const
Definition: LeafNode.h:1281
ValueOffIter beginValueOff()
Definition: LeafNodeBool.h:662
#define OPENVDB_DEPRECATED
Definition: Platform.h:47
Buffer mBuffer
Buffer containing the actual data values.
Definition: LeafNode.h:850
NodeMaskType & getValueMask()
Definition: LeafNodeBool.h:707
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeBool.h:655
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition: LeafNode.h:1299
LeafNode< ValueType, Log2Dim > Type
Definition: LeafNodeBool.h:74
Index64 onLeafVoxelCount() const
Definition: LeafNodeBool.h:161
ValueOffCIter beginValueOff() const
Definition: LeafNodeBool.h:661
static const Index LOG2DIM
Definition: LeafNode.h:71
ValueAllIter endValueAll()
Definition: LeafNodeBool.h:675
const bool & getItem(Index pos) const
Definition: LeafNodeBool.h:593
Buffer(const NodeMaskType &other)
Definition: LeafNodeBool.h:81
int32_t Int32
Definition: Types.h:58
Definition: Types.h:190
boost::shared_ptr< LeafNodeType > Ptr
Definition: LeafNodeBool.h:58
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1001
ChildOnIter beginChildOn()
Definition: LeafNodeBool.h:681
void fill(bool val)
Definition: LeafNodeBool.h:84
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1249
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:400
ChildAllCIter endChildAll() const
Definition: LeafNodeBool.h:696
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:361
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeBool.h:394
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of the voxels that lie within a given bounding box.
Definition: LeafNode.h:1123
LeafNode specialization for values of type bool that stores both the active states and the values of ...
Definition: LeafNodeBool.h:54
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:531
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeBool.h:544
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: LeafNode.h:975
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:1653
const bool & getValue() const
Definition: LeafNodeBool.h:594
Definition: NodeMasks.h:220
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
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1012
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeBool.h:169
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:965
static Index size()
Definition: LeafNodeBool.h:102
const Coord & origin() const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:241
void combine2(const LeafNode &other, const ValueType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1543
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeBool.h:310
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node&#39;s set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if both of the original voxels were active.
Definition: LeafNode.h:1476
void modifyValue(Index offset, const ModifyOp &op)
Apply a functor to the value of the voxel at the given offset and mark the voxel as active...
Definition: LeafNode.h:494
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other)
Union this node&#39;s set of active values with the active values of the other node, whose ValueType may ...
Definition: LeafNode.h:1468
static Index64 onTileCount()
Definition: LeafNodeBool.h:163
ChildOffIter endChildOff()
Definition: LeafNodeBool.h:694
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don&#39;t change its value.
Definition: LeafNodeBool.h:265
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNodeBool.h:182
ValueOffCIter cendValueOff() const
Definition: LeafNodeBool.h:670
void setValuesOff()
Mark all voxels as inactive but don&#39;t change their values.
Definition: LeafNodeBool.h:302
Definition: Types.h:346
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don&#39;t change its value. ...
Definition: LeafNodeBool.h:257
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeBool.h:160
OnIterator beginOn() const
Definition: NodeMasks.h:332
const Buffer & buffer() const
Definition: LeafNodeBool.h:222
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeBool.h:708
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeBool.h:657
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeBool.h:660
void signedFloodFill(bool, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:519
static const Index SIZE
Definition: LeafNode.h:76
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:565
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:1678
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:395
bool probeValueAndCache(const Coord &xyz, bool &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val...
Definition: LeafNodeBool.h:412
static const Index DIM
Definition: LeafNode.h:73
Buffer mBuffer
Bitmask representing the values of voxels.
Definition: LeafNodeBool.h:735
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNodeBool.h:733
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don&#39;t change its active state. ...
Definition: LeafNodeBool.h:262
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1200
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:529
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeBool.h:356
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:521
NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeBool.h:578
ValueAllIter beginValueAll()
Definition: LeafNodeBool.h:665
bool isChildMaskOff(Index) const
Definition: LeafNodeBool.h:710
ChildOffCIter beginChildOff() const
Definition: LeafNodeBool.h:683
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:265
void setValueAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNodeBool.h:366
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeBool.h:682
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeBool.h:629
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:430
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:62
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don&#39;t change its value.
Definition: LeafNode.h:476
OPENVDB_IMPORT uint32_t getFormatVersion(std::istream &)
Return the file format version number associated with the given input stream.
ValueOnIter beginValueOn()
Definition: LeafNodeBool.h:659
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:361
bool operator==(const Buffer &other) const
Definition: LeafNodeBool.h:94
ChildOnCIter endChildOn() const
Definition: LeafNodeBool.h:690
void setValueMaskOn(Index n)
Definition: LeafNodeBool.h:714
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeBool.h:606
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:546
Buffer & operator=(const Buffer &b)
Definition: LeafNodeBool.h:85
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:446
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:440
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don&#39;t change its value.
Definition: LeafNode.h:1062
DenseIteratorBase< MaskDenseIter, DenseIter, NodeT, void, ValueT > BaseT
Definition: LeafNodeBool.h:623
ValueAllCIter cendValueAll() const
Definition: LeafNodeBool.h:673
bool ValueType
Definition: LeafNodeBool.h:59
static Index size()
Definition: LeafNodeBool.h:148
#define OPENVDB_VERSION_NAME
Definition: version.h:45
Buffer & buffer()
Definition: LeafNodeBool.h:223
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeBool.h:685
static Index64 offTileCount()
Definition: LeafNodeBool.h:164
bool isValueMaskOn(Index n) const
Definition: LeafNodeBool.h:702
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don&#39;t change its value.
Definition: LeafNodeBool.h:275
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeBool.h:147
void swap(Buffer &other)
Definition: LeafNodeBool.h:99
ChildOnCIter cendChildOn() const
Definition: LeafNodeBool.h:689
Index64 offLeafVoxelCount() const
Definition: LeafNodeBool.h:162
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:185
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:591
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:390
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:1598
void visit(VisitorOp &)
Definition: LeafNode.h:1621
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeBool.h:627
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:1639
bool operator!=(const Buffer &other) const
Definition: LeafNodeBool.h:95
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeBool.h:145
void fill(const CoordBBox &bbox, const ValueType &, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNode.h:1088
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1331
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don&#39;t change its value.
Definition: LeafNodeBool.h:277
bool isChildMaskOn(Index) const
Definition: LeafNodeBool.h:709
NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeBool.h:579
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeBool.h:737
void copyFromDense(const DenseT &dense, GridOrTreeT &sparse, const typename GridOrTreeT::ValueType &tolerance, bool serial=false)
Populate a sparse grid with the values of all of the voxels of a dense grid.
Definition: Dense.h:457
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition: LeafNodeBool.h:151
CombineArgs & setBRef(const ValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:271
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:527
bool isConstant(ValueType &constValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1308
ValueOnCIter beginValueOn() const
Definition: LeafNodeBool.h:658
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1349
util::NodeMask< Log2Dim > NodeMaskType
Definition: LeafNodeBool.h:60
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeBool.h:429
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:96
ValueIter< MaskOffIter, LeafNode, bool > ValueOffIter
Definition: LeafNodeBool.h:646
void setValueOnlyAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNodeBool.h:372
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1259
void save(std::ostream &os) const
Definition: NodeMasks.h:492
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
static const bool sOff
Definition: LeafNodeBool.h:741
ChildOffCIter cendChildOff() const
Definition: LeafNodeBool.h:692
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:862
const NodeMaskType & getValueMask() const
Definition: LeafNodeBool.h:706
bool isChildMaskOff() const
Definition: LeafNodeBool.h:711
ChildOnIter endChildOn()
Definition: LeafNodeBool.h:691
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:305
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1181
void setValue(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNodeBool.h:282
static const Index LEVEL
Definition: LeafNode.h:77
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1723
void pruneOp(PruneOp &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:520
void pruneInactive(const ValueType &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:522
void setValue(bool value) const
Definition: LeafNodeBool.h:599
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:523
void setValuesOn()
Mark all voxels as active but don&#39;t change their values.
Definition: LeafNodeBool.h:300
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:193
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:952
bool isDense() const
Return true if this node contains only active voxels.
Definition: LeafNode.h:219
BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeBool.h:624
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeBool.h:654
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1028
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeBool.h:651
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:615
ChildAllIter endChildAll()
Definition: LeafNodeBool.h:697
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeBool.h:663
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeBool.h:650
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeBool.h:652
void copyFromDense(const CoordBBox &bbox, const DenseT &dense, const ValueType &background, const ValueType &tolerance)
Copy from a dense grid into this node the values of the voxels that lie within a given bounding box...
Definition: LeafNode.h:1147
ChildAllIter beginChildAll()
Definition: LeafNodeBool.h:687
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeBool.h:252
Definition: NodeMasks.h:189
OPENVDB_DEPRECATED void evalActiveVoxelBoundingBox(CoordBBox &) const
Definition: LeafNode.h:1267
Buffer(const Buffer &other)
Definition: LeafNodeBool.h:82
bool isValueMaskOn() const
Definition: LeafNodeBool.h:703
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1699
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don&#39;t change its value.
Definition: LeafNodeBool.h:267
Index32 Index
Definition: Types.h:56
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1234
LeafNode< bool, Log2Dim > LeafNodeType
Definition: LeafNodeBool.h:57
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNode.h:854
void setValueMaskOff(Index n)
Definition: LeafNodeBool.h:715
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:390
void swap(Buffer &other)
Exchange this node&#39;s data buffer with the given data buffer without changing the active states of the...
Definition: LeafNodeBool.h:221
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:97
static Index memUsage()
Return the memory-footprint of this Buffer in units of bytes.
Definition: LeafNode.h:142
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:438
ValueAllCIter beginValueAll() const
Definition: LeafNodeBool.h:664
ChildOnCIter beginChildOn() const
Definition: LeafNodeBool.h:680
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1404
static Index getLevel()
Definition: LeafNodeBool.h:150
ValueOnCIter cendValueOn() const
Definition: LeafNodeBool.h:667
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: LeafNodeBool.h:403
bool isValueMaskOff(Index n) const
Definition: LeafNodeBool.h:704
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeBool.h:649
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:561
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:377
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:359
ChildOffIter beginChildOff()
Definition: LeafNodeBool.h:684
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeBool.h:420
static Index32 leafCount()
Definition: LeafNodeBool.h:154
NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeBool.h:580
ValueOffCIter endValueOff() const
Definition: LeafNodeBool.h:671
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:509
LeafNode()
Default constructor.
Definition: LeafNode.h:894
ValueOffIter endValueOff()
Definition: LeafNodeBool.h:672
CombineArgs & setARef(const ValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:269
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:543
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:525
Buffer(bool on)
Definition: LeafNodeBool.h:80
ValueAllCIter endValueAll() const
Definition: LeafNodeBool.h:674
ChildOffCIter endChildOff() const
Definition: LeafNodeBool.h:693
static Index numValues()
Definition: LeafNodeBool.h:149
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node&#39;s set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this LeafNode and inactive in the other LeafNode.
Definition: LeafNode.h:1485
ValueIter< MaskOnIter, LeafNode, bool > ValueOnIter
Definition: LeafNodeBool.h:644
void copyToDense(const GridOrTreeT &sparse, DenseT &dense, bool serial=false)
Populate a dense grid with the values of voxels from a sparse grid, where the sparse grid intersects ...
Definition: Dense.h:310
bool resultIsActive() const
Definition: Types.h:280
void setValueOffAndCache(const Coord &xyz, bool value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNodeBool.h:377
Definition: NodeMasks.h:251
void voxelizeActiveTiles()
Definition: LeafNodeBool.h:446
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeBool.h:640
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:548
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeBool.h:425
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeBool.h:158
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeBool.h:645
~LeafNode()
Destructor.
Definition: LeafNode.h:946
static Index getChildDim()
Definition: LeafNodeBool.h:152
ChildAllCIter beginChildAll() const
Definition: LeafNodeBool.h:686
void setValueMask(Index n, bool on)
Definition: LeafNodeBool.h:713
static const bool sOn
Definition: LeafNodeBool.h:740
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNode.h:852
uint64_t Index64
Definition: Types.h:55
static Index32 nonLeafCount()
Definition: LeafNodeBool.h:155
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:288
const bool & getValue(Index i) const
Definition: LeafNodeBool.h:87
void setItem(Index pos, bool value) const
Definition: LeafNodeBool.h:597
void fill(const ValueType &val)
Populates the buffer with a constant value.
Definition: LeafNode.h:100
bool isInactive() const
Return true if all of this node&#39;s values are inactive.
Definition: LeafNodeBool.h:436
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition: LeafNodeBool.h:588
void combine(FloatTreeT &lhsDist, IntTreeT &lhsIndex, FloatTreeT &rhsDist, IntTreeT &rhsIndex)
Definition: MeshToVolume.h:396
bool isValueMaskOff() const
Definition: LeafNodeBool.h:705
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1189
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don&#39;t change its active state.
Definition: LeafNode.h:1070
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:560
void merge(const LeafNode &)
Definition: LeafNode.h:1423
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:232
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: LeafNodeBool.h:386
Index memUsage() const
Definition: LeafNodeBool.h:101
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:192
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeBool.h:167
ValueOnCIter endValueOn() const
Definition: LeafNodeBool.h:668
OPENVDB_DEPRECATED const Coord & getOrigin() const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:188
void setValue(Index i, bool val)
Definition: LeafNodeBool.h:97
ValueOnIter endValueOn()
Definition: LeafNodeBool.h:669
void negate()
Definition: LeafNodeBool.h:440