OpenVDB  2.1.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)
919  + ((xyz[1] & (DIM-1u)) << Log2Dim)
920  + (xyz[2] & (DIM-1u));
921 }
922 
923 
924 template<Index Log2Dim>
925 inline Coord
927 {
928  assert(n < (1 << 3*Log2Dim));
929  Coord xyz;
930  xyz.setX(n >> 2*Log2Dim);
931  n &= ((1 << 2*Log2Dim) - 1);
932  xyz.setY(n >> Log2Dim);
933  xyz.setZ(n & ((1 << Log2Dim) - 1));
934  return xyz;
935 }
936 
937 
938 template<Index Log2Dim>
939 inline Coord
941 {
942  return (this->offsetToLocalCoord(n) + this->origin());
943 }
944 
945 
947 
948 
949 template<Index Log2Dim>
950 inline void
951 LeafNode<bool, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
952 {
953  mValueMask.load(is);
954 }
955 
956 
957 template<Index Log2Dim>
958 inline void
959 LeafNode<bool, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
960 {
961  mValueMask.save(os);
962 }
963 
964 
965 template<Index Log2Dim>
966 inline void
967 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, bool /*fromHalf*/)
968 {
969  // Read in the value mask.
970  mValueMask.load(is);
971  // Read in the origin.
972  is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
973 
975  // Read in the mask for the voxel values.
976  mBuffer.mData.load(is);
977  } else {
978  // Older files stored one or more bool arrays.
979 
980  // Read in the number of buffers, which should now always be one.
981  int8_t numBuffers = 0;
982  is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
983 
984  // Read in the buffer.
985  // (Note: prior to the bool leaf optimization, buffers were always compressed.)
986  boost::shared_array<bool> buf(new bool[SIZE]);
987  io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
988 
989  // Transfer values to mBuffer.
990  mBuffer.mData.setOff();
991  for (Index i = 0; i < SIZE; ++i) {
992  if (buf[i]) mBuffer.mData.setOn(i);
993  }
994 
995  if (numBuffers > 1) {
996  // Read in and discard auxiliary buffers that were created with
997  // earlier versions of the library.
998  for (int i = 1; i < numBuffers; ++i) {
999  io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1000  }
1001  }
1002  }
1003 }
1004 
1005 
1006 template<Index Log2Dim>
1007 inline void
1008 LeafNode<bool, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
1009 {
1010  // Write out the value mask.
1011  mValueMask.save(os);
1012  // Write out the origin.
1013  os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1014  // Write out the voxel values.
1015  mBuffer.mData.save(os);
1016 }
1017 
1018 
1020 
1021 
1022 template<Index Log2Dim>
1023 inline bool
1025 {
1026  return (mValueMask == other.mValueMask && mBuffer.mData == other.mBuffer.mData);
1027 }
1028 
1029 
1030 template<Index Log2Dim>
1031 inline bool
1033 {
1034  return !(this->operator==(other));
1035 }
1036 
1037 
1039 
1040 
1041 template<Index Log2Dim>
1042 inline bool
1043 LeafNode<bool, Log2Dim>::isConstant(bool& constValue, bool& state, bool tolerance) const
1044 {
1045  state = mValueMask.isOn();
1046 
1047  if (!(state || mValueMask.isOff())) return false;
1048 
1049  // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1050  if (!tolerance && !(mBuffer.mData.isOn() || mBuffer.mData.isOff())) return false;
1051 
1052  state = mValueMask.isOn();
1053  constValue = mBuffer.mData.isOn();
1054  return true;
1055 }
1056 
1057 
1059 
1060 
1061 template<Index Log2Dim>
1062 inline void
1063 LeafNode<bool, Log2Dim>::addTile(Index level, const Coord& xyz, bool val, bool active)
1064 {
1065  assert(level == 0);
1066  this->addTile(this->coordToOffset(xyz), val, active);
1067 }
1068 
1069 template<Index Log2Dim>
1070 inline void
1071 LeafNode<bool, Log2Dim>::addTile(Index offset, bool val, bool active)
1072 {
1073  assert(offset < SIZE);
1074  setValueOnly(offset, val);
1075  setActiveState(offset, active);
1076 }
1077 
1078 template<Index Log2Dim>
1079 template<typename AccessorT>
1080 inline void
1082  bool val, bool active, AccessorT&)
1083 {
1084  this->addTile(level, xyz, val, active);
1085 }
1086 
1087 
1089 
1090 
1091 template<Index Log2Dim>
1092 inline const bool&
1093 LeafNode<bool, Log2Dim>::getValue(const Coord& xyz) const
1094 {
1095  // This *CANNOT* use operator ? because Visual C++
1096  if (mBuffer.mData.isOn(this->coordToOffset(xyz))) return sOn; else return sOff;
1097 }
1098 
1099 
1100 template<Index Log2Dim>
1101 inline const bool&
1103 {
1104  assert(offset < SIZE);
1105  // This *CANNOT* use operator ? for Windows
1106  if (mBuffer.mData.isOn(offset)) return sOn; else return sOff;
1107 }
1108 
1109 
1110 template<Index Log2Dim>
1111 inline bool
1112 LeafNode<bool, Log2Dim>::probeValue(const Coord& xyz, bool& val) const
1113 {
1114  const Index offset = this->coordToOffset(xyz);
1115  val = mBuffer.mData.isOn(offset);
1116  return mValueMask.isOn(offset);
1117 }
1118 
1119 
1120 template<Index Log2Dim>
1121 inline void
1122 LeafNode<bool, Log2Dim>::setValueOn(const Coord& xyz, bool val)
1123 {
1124  this->setValueOn(this->coordToOffset(xyz), val);
1125 }
1126 
1127 
1128 template<Index Log2Dim>
1129 inline void
1131 {
1132  assert(offset < SIZE);
1133  mValueMask.setOn(offset);
1134  mBuffer.mData.set(offset, val);
1135 }
1136 
1137 
1138 template<Index Log2Dim>
1139 inline void
1140 LeafNode<bool, Log2Dim>::setValueOnly(const Coord& xyz, bool val)
1141 {
1142  this->setValueOnly(this->coordToOffset(xyz), val);
1143 }
1144 
1145 
1146 template<Index Log2Dim>
1147 inline void
1149 {
1150  mValueMask.set(this->coordToOffset(xyz), on);
1151 }
1152 
1153 
1154 template<Index Log2Dim>
1155 inline void
1156 LeafNode<bool, Log2Dim>::setValueOff(const Coord& xyz, bool val)
1157 {
1158  this->setValueOff(this->coordToOffset(xyz), val);
1159 }
1160 
1161 
1162 template<Index Log2Dim>
1163 inline void
1165 {
1166  assert(offset < SIZE);
1167  mValueMask.setOff(offset);
1168  mBuffer.mData.set(offset, val);
1169 }
1170 
1171 
1172 template<Index Log2Dim>
1173 template<typename ModifyOp>
1174 inline void
1175 LeafNode<bool, Log2Dim>::modifyValue(Index offset, const ModifyOp& op)
1176 {
1177  bool val = mBuffer.mData.isOn(offset);
1178  op(val);
1179  mBuffer.mData.set(offset, val);
1180  mValueMask.setOn(offset);
1181 }
1182 
1183 
1184 template<Index Log2Dim>
1185 template<typename ModifyOp>
1186 inline void
1187 LeafNode<bool, Log2Dim>::modifyValue(const Coord& xyz, const ModifyOp& op)
1188 {
1189  this->modifyValue(this->coordToOffset(xyz), op);
1190 }
1191 
1192 
1193 template<Index Log2Dim>
1194 template<typename ModifyOp>
1195 inline void
1196 LeafNode<bool, Log2Dim>::modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
1197 {
1198  const Index offset = this->coordToOffset(xyz);
1199  bool val = mBuffer.mData.isOn(offset), state = mValueMask.isOn(offset);
1200  op(val, state);
1201  mBuffer.mData.set(offset, val);
1202  mValueMask.set(offset, state);
1203 }
1204 
1205 
1207 
1208 
1209 template<Index Log2Dim>
1210 inline void
1211 LeafNode<bool, Log2Dim>::resetBackground(bool oldBackground, bool newBackground)
1212 {
1213  if (newBackground != oldBackground) {
1214  // Flip mBuffer's background bits and zero its foreground bits.
1215  NodeMaskType bgMask = !(mBuffer.mData | mValueMask);
1216  // Overwrite mBuffer's background bits, leaving its foreground bits intact.
1217  mBuffer.mData = (mBuffer.mData & mValueMask) | bgMask;
1218  }
1219 }
1220 
1221 
1223 
1224 
1225 template<Index Log2Dim>
1226 template<MergePolicy Policy>
1227 inline void
1228 LeafNode<bool, Log2Dim>::merge(const LeafNode& other, bool /*bg*/, bool /*otherBG*/)
1229 {
1231  if (Policy == MERGE_NODES) return;
1232  for (typename NodeMaskType::OnIterator iter = other.mValueMask.beginOn(); iter; ++iter) {
1233  const Index n = iter.pos();
1234  if (mValueMask.isOff(n)) {
1235  mBuffer.mData.set(n, other.mBuffer.mData.isOn(n));
1236  mValueMask.setOn(n);
1237  }
1238  }
1240 }
1241 
1242 template<Index Log2Dim>
1243 template<MergePolicy Policy>
1244 inline void
1245 LeafNode<bool, Log2Dim>::merge(bool tileValue, bool tileActive)
1246 {
1248  if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1249  if (!tileActive) return;
1250  // Replace all inactive values with the active tile value.
1251  if (tileValue) mBuffer.mData |= !mValueMask; // -0=>1, +0=>0, -1=>1, +1=>1 (-,+ = off,on)
1252  else mBuffer.mData &= mValueMask; // -0=>0, +0=>0, -1=>0, +1=>1
1253  mValueMask.setOn();
1255 }
1256 
1257 
1259 
1260 
1261 template<Index Log2Dim>
1262 template<typename OtherType>
1263 inline void
1265 {
1266  mValueMask |= other.getValueMask();
1267 }
1268 
1269 
1270 template<Index Log2Dim>
1271 template<typename OtherType>
1272 inline void
1274  const bool&)
1275 {
1276  mValueMask &= other.getValueMask();
1277 }
1278 
1279 
1280 template<Index Log2Dim>
1281 template<typename OtherType>
1282 inline void
1284  const bool&)
1285 {
1286  mValueMask &= !other.getValueMask();
1287 }
1288 
1289 
1291 
1292 
1293 template<Index Log2Dim>
1294 inline void
1295 LeafNode<bool, Log2Dim>::fill(const CoordBBox& bbox, bool value, bool active)
1296 {
1297  for (Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1298  const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1299  for (Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1300  const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1301  for (Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1302  const Index offset = offsetXY + (z & (DIM-1u));
1303  mValueMask.set(offset, active);
1304  mBuffer.mData.set(offset, value);
1305  }
1306  }
1307  }
1308 }
1309 
1310 template<Index Log2Dim>
1311 inline void
1313 {
1314  mBuffer.fill(value);
1315 }
1316 
1317 template<Index Log2Dim>
1318 inline void
1319 LeafNode<bool, Log2Dim>::fill(const bool& value, bool active)
1320 {
1321  mBuffer.fill(value);
1322  mValueMask.set(active);
1323 }
1324 
1325 
1327 
1328 
1329 template<Index Log2Dim>
1330 template<typename DenseT>
1331 inline void
1332 LeafNode<bool, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1333 {
1334  typedef typename DenseT::ValueType DenseValueType;
1335 
1336  const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1337  const Coord& min = dense.bbox().min();
1338  DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1339  const Int32 n0 = bbox.min()[2] & (DIM-1u);
1340  for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1341  DenseValueType* t1 = t0 + xStride * (x - min[0]);
1342  const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1343  for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1344  DenseValueType* t2 = t1 + yStride * (y - min[1]);
1345  Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1346  for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1347  *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1348  }
1349  }
1350  }
1351 }
1352 
1353 
1354 template<Index Log2Dim>
1355 template<typename DenseT>
1356 inline void
1357 LeafNode<bool, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1358  bool background, bool tolerance)
1359 {
1360  typedef typename DenseT::ValueType DenseValueType;
1361 
1362  const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1363  const Coord& min = dense.bbox().min();
1364  const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1365  const Int32 n0 = bbox.min()[2] & (DIM-1u);
1366  for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1367  const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1368  const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1369  for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1370  const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1371  Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1372  for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1373  // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1374  if (tolerance || background == bool(*s2)) {
1375  mValueMask.setOff(n2);
1376  mBuffer.mData.set(n2, background);
1377  } else {
1378  mValueMask.setOn(n2);
1379  mBuffer.mData.set(n2, bool(*s2));
1380  }
1381  }
1382  }
1383  }
1384 }
1385 
1386 
1388 
1389 
1390 template<Index Log2Dim>
1391 template<typename CombineOp>
1392 inline void
1393 LeafNode<bool, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1394 {
1395  CombineArgs<bool> args;
1396  for (Index i = 0; i < SIZE; ++i) {
1397  bool result = false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1398  op(args.setARef(aVal)
1399  .setAIsActive(mValueMask.isOn(i))
1400  .setBRef(bVal)
1401  .setBIsActive(other.mValueMask.isOn(i))
1402  .setResultRef(result));
1403  mValueMask.set(i, args.resultIsActive());
1404  mBuffer.mData.set(i, result);
1405  }
1406 }
1407 
1408 
1409 template<Index Log2Dim>
1410 template<typename CombineOp>
1411 inline void
1412 LeafNode<bool, Log2Dim>::combine(bool value, bool valueIsActive, CombineOp& op)
1413 {
1414  CombineArgs<bool> args;
1415  args.setBRef(value).setBIsActive(valueIsActive);
1416  for (Index i = 0; i < SIZE; ++i) {
1417  bool result = false, aVal = mBuffer.mData.isOn(i);
1418  op(args.setARef(aVal)
1419  .setAIsActive(mValueMask.isOn(i))
1420  .setResultRef(result));
1421  mValueMask.set(i, args.resultIsActive());
1422  mBuffer.mData.set(i, result);
1423  }
1424 }
1425 
1426 
1428 
1429 
1430 template<Index Log2Dim>
1431 template<typename CombineOp>
1432 inline void
1434  bool valueIsActive, CombineOp& op)
1435 {
1436  CombineArgs<bool> args;
1437  args.setBRef(value).setBIsActive(valueIsActive);
1438  for (Index i = 0; i < SIZE; ++i) {
1439  bool result = false, aVal = other.mBuffer.mData.isOn(i);
1440  op(args.setARef(aVal)
1441  .setAIsActive(other.mValueMask.isOn(i))
1442  .setResultRef(result));
1443  mValueMask.set(i, args.resultIsActive());
1444  mBuffer.mData.set(i, result);
1445  }
1446 }
1447 
1448 
1449 template<Index Log2Dim>
1450 template<typename CombineOp>
1451 inline void
1453  bool valueIsActive, CombineOp& op)
1454 {
1455  CombineArgs<bool> args;
1456  args.setARef(value).setAIsActive(valueIsActive);
1457  for (Index i = 0; i < SIZE; ++i) {
1458  bool result = false, bVal = other.mBuffer.mData.isOn(i);
1459  op(args.setBRef(bVal)
1460  .setBIsActive(other.mValueMask.isOn(i))
1461  .setResultRef(result));
1462  mValueMask.set(i, args.resultIsActive());
1463  mBuffer.mData.set(i, result);
1464  }
1465 }
1466 
1467 
1468 template<Index Log2Dim>
1469 template<typename CombineOp>
1470 inline void
1471 LeafNode<bool, Log2Dim>::combine2(const LeafNode& b0, const LeafNode& b1, CombineOp& op)
1472 {
1473  CombineArgs<bool> args;
1474  for (Index i = 0; i < SIZE; ++i) {
1475  // Default behavior: output voxel is active if either input voxel is active.
1476  mValueMask.set(i, b0.mValueMask.isOn(i) || b1.mValueMask.isOn(i));
1477 
1478  bool result = false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1479  op(args.setARef(b0Val)
1480  .setAIsActive(b0.mValueMask.isOn(i))
1481  .setBRef(b1Val)
1482  .setBIsActive(b1.mValueMask.isOn(i))
1483  .setResultRef(result));
1484  mValueMask.set(i, args.resultIsActive());
1485  mBuffer.mData.set(i, result);
1486  }
1487 }
1488 
1489 
1491 
1492 template<Index Log2Dim>
1493 template<typename BBoxOp>
1494 inline void
1496 {
1497  if (op.template descent<LEVEL>()) {
1498  for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
1499 #ifdef _MSC_VER
1500  op.operator()<LEVEL>(CoordBBox(i.getCoord(),1));
1501 #else
1502  op.template operator()<LEVEL>(CoordBBox(i.getCoord(),1));
1503 #endif
1504  }
1505  } else {
1506 #ifdef _MSC_VER
1507  op.operator()<LEVEL>(this->getNodeBoundingBox());
1508 #else
1509  op.template operator()<LEVEL>(this->getNodeBoundingBox());
1510 #endif
1511  }
1512 }
1513 
1514 
1515 template<Index Log2Dim>
1516 template<typename VisitorOp>
1517 inline void
1519 {
1520  doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
1521 }
1522 
1523 
1524 template<Index Log2Dim>
1525 template<typename VisitorOp>
1526 inline void
1528 {
1529  doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
1530 }
1531 
1532 
1533 template<Index Log2Dim>
1534 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1535 inline void
1536 LeafNode<bool, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
1537 {
1538  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1539  op(iter);
1540  }
1541 }
1542 
1543 
1545 
1546 
1547 template<Index Log2Dim>
1548 template<typename OtherLeafNodeType, typename VisitorOp>
1549 inline void
1550 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
1551 {
1552  doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
1553  typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
1554 }
1555 
1556 
1557 template<Index Log2Dim>
1558 template<typename OtherLeafNodeType, typename VisitorOp>
1559 inline void
1560 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
1561 {
1562  doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
1563  typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
1564 }
1565 
1566 
1567 template<Index Log2Dim>
1568 template<
1569  typename NodeT,
1570  typename OtherNodeT,
1571  typename VisitorOp,
1572  typename ChildAllIterT,
1573  typename OtherChildAllIterT>
1574 inline void
1575 LeafNode<bool, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
1576 {
1577  // Allow the two nodes to have different ValueTypes, but not different dimensions.
1578  BOOST_STATIC_ASSERT(OtherNodeT::SIZE == NodeT::SIZE);
1579  BOOST_STATIC_ASSERT(OtherNodeT::LEVEL == NodeT::LEVEL);
1580 
1581  ChildAllIterT iter = self.beginChildAll();
1582  OtherChildAllIterT otherIter = other.beginChildAll();
1583 
1584  for ( ; iter && otherIter; ++iter, ++otherIter) {
1585  op(iter, otherIter);
1586  }
1587 }
1588 
1589 
1591 
1592 
1593 template<Index Log2Dim>
1594 template<typename IterT, typename VisitorOp>
1595 inline void
1596 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
1597 {
1598  doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(*this, otherIter, op, otherIsLHS);
1599 }
1600 
1601 
1602 template<Index Log2Dim>
1603 template<typename IterT, typename VisitorOp>
1604 inline void
1605 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
1606 {
1607  doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(*this, otherIter, op, otherIsLHS);
1608 }
1609 
1610 
1611 template<Index Log2Dim>
1612 template<
1613  typename NodeT,
1614  typename VisitorOp,
1615  typename ChildAllIterT,
1616  typename OtherChildAllIterT>
1617 inline void
1618 LeafNode<bool, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
1619  VisitorOp& op, bool otherIsLHS)
1620 {
1621  if (!otherIter) return;
1622 
1623  if (otherIsLHS) {
1624  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1625  op(otherIter, iter);
1626  }
1627  } else {
1628  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1629  op(iter, otherIter);
1630  }
1631  }
1632 }
1633 
1634 } // namespace tree
1635 } // namespace OPENVDB_VERSION_NAME
1636 } // namespace openvdb
1637 
1638 #endif // OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
1639 
1640 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1641 // All rights reserved. This software is distributed under the
1642 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeBool.h:420
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
bool isInactive() const
Return true if all of this node&#39;s values are inactive.
Definition: LeafNodeBool.h:436
NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeBool.h:580
void setValue(bool value) const
Definition: LeafNodeBool.h:599
ValueOffCIter endValueOff() const
Definition: LeafNodeBool.h:671
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:395
NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeBool.h:579
boost::shared_ptr< LeafNodeType > Ptr
Definition: LeafNodeBool.h:58
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition: LeafNodeBool.h:151
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:358
bool isChildMaskOn(Index) const
Definition: LeafNodeBool.h:709
Buffer mBuffer
Buffer containing the actual data values.
Definition: LeafNode.h:850
const bool & getValue(Index i) const
Definition: LeafNodeBool.h:87
ChildAllIter endChildAll()
Definition: LeafNodeBool.h:697
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeBool.h:394
static const Index LOG2DIM
Definition: LeafNode.h:71
util::NodeMask< Log2Dim > NodeMaskType
Definition: LeafNodeBool.h:60
#define OPENVDB_DEPRECATED
Definition: Platform.h:47
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
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:531
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1001
void evalActiveBoundingBox(CoordBBox &, bool visitVoxels=true) const
Definition: LeafNode.h:1285
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeBool.h:679
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:1303
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 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:1125
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeBool.h:169
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeBool.h:356
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:561
static const bool sOff
Definition: LeafNodeBool.h:741
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeBool.h:640
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:591
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:521
static Index64 onTileCount()
Definition: LeafNodeBool.h:163
LeafNode specialization for values of type bool that stores both the active states and the values of ...
Definition: LeafNodeBool.h:54
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1253
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:305
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeBool.h:145
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:361
Definition: NodeMasks.h:189
ValueOffCIter beginValueOff() const
Definition: LeafNodeBool.h:661
const Coord & origin() const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:241
DenseIteratorBase< MaskDenseIter, DenseIter, NodeT, void, ValueT > BaseT
Definition: LeafNodeBool.h:623
void load(std::istream &is)
Definition: NodeMasks.h:496
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 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:1480
static Index memUsage()
Return the memory-footprint of this Buffer in units of bytes.
Definition: LeafNode.h:142
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:546
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeBool.h:663
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:1657
OnIterator beginOn() const
Definition: NodeMasks.h:332
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:1472
ChildAllIter beginChildAll()
Definition: LeafNodeBool.h:687
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
const bool & operator[](Index i) const
Definition: LeafNodeBool.h:92
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeBool.h:167
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1012
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeBool.h:650
Index memUsage() const
Definition: LeafNodeBool.h:101
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeBool.h:252
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:965
bool isValueMaskOn() const
Definition: LeafNodeBool.h:703
void combine2(const LeafNode &other, const ValueType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1547
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 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 setValueMask(Index n, bool on)
Definition: LeafNodeBool.h:713
ValueAllCIter beginValueAll() const
Definition: LeafNodeBool.h:664
ValueOnCIter cendValueOn() const
Definition: LeafNodeBool.h:667
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:288
NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeBool.h:578
Index32 Index
Definition: Types.h:56
static const Index SIZE
Definition: LeafNode.h:76
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:1682
void setItem(Index pos, bool value) const
Definition: LeafNodeBool.h:597
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:430
ChildOnIter endChildOn()
Definition: LeafNodeBool.h:691
static const Index DIM
Definition: LeafNode.h:73
void combine(FloatTreeT &lhsDist, IntTreeT &lhsIndex, FloatTreeT &rhsDist, IntTreeT &rhsIndex)
Definition: MeshToVolume.h:396
static Index32 leafCount()
Definition: LeafNodeBool.h:154
ValueOffIter endValueOff()
Definition: LeafNodeBool.h:672
Buffer(const Buffer &other)
Definition: LeafNodeBool.h:82
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
Definition: Types.h:190
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
ValueOnCIter beginValueOn() const
Definition: LeafNodeBool.h:658
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1204
void voxelizeActiveTiles()
Definition: LeafNodeBool.h:446
bool ValueType
Definition: LeafNodeBool.h:59
ValueIter< MaskOffIter, LeafNode, bool > ValueOffIter
Definition: LeafNodeBool.h:646
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeBool.h:158
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
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeBool.h:708
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don&#39;t change its value.
Definition: LeafNodeBool.h:267
void signedFloodFill(bool, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:519
Buffer & buffer()
Definition: LeafNodeBool.h:223
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeBool.h:544
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeBool.h:603
static Index64 offTileCount()
Definition: LeafNodeBool.h:164
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeBool.h:425
ChildAllCIter beginChildAll() const
Definition: LeafNodeBool.h:686
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:265
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
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:563
static Index getChildDim()
Definition: LeafNodeBool.h:152
void setValue(Index i, bool val)
Definition: LeafNodeBool.h:97
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:529
CombineArgs & setBRef(const ValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:271
This struct collects both input and output arguments to &quot;grid combiner&quot; functors used with the tree::...
Definition: Types.h:232
NodeMaskType & getValueMask()
Definition: LeafNodeBool.h:707
Index64 onLeafVoxelCount() const
Definition: LeafNodeBool.h:161
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
const bool & getItem(Index pos) const
Definition: LeafNodeBool.h:593
#define OPENVDB_VERSION_NAME
Definition: version.h:45
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
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:560
ChildOnIter beginChildOn()
Definition: LeafNodeBool.h:681
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeBool.h:160
void fill(const ValueType &val)
Populates the buffer with a constant value.
Definition: LeafNode.h:100
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeBool.h:429
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
ValueOnIter endValueOn()
Definition: LeafNodeBool.h:669
void negate()
Definition: LeafNodeBool.h:440
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:446
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:377
Buffer(const NodeMaskType &other)
Definition: LeafNodeBool.h:81
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:440
ValueIter< MaskDenseIter, LeafNode, bool > ValueAllIter
Definition: LeafNodeBool.h:648
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeBool.h:307
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:548
BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeBool.h:624
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:1602
void visit(VisitorOp &)
Definition: LeafNode.h:1625
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeBool.h:645
bool isConstant(ValueType &constValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1312
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:1643
bool operator==(const Buffer &other) const
Definition: LeafNodeBool.h:94
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
uint32_t Index32
Definition: Types.h:54
const NodeMaskType & getValueMask() const
Definition: LeafNodeBool.h:706
ChildAllCIter cendChildAll() const
Definition: LeafNodeBool.h:695
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
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeBool.h:653
uint64_t Index64
Definition: Types.h:55
int32_t Int32
Definition: Types.h:58
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1335
static Index32 nonLeafCount()
Definition: LeafNodeBool.h:155
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1263
Index64 offLeafVoxelCount() const
Definition: LeafNodeBool.h:162
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeBool.h:310
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:96
ChildOffIter endChildOff()
Definition: LeafNodeBool.h:694
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1353
CombineArgs & setARef(const ValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:269
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:862
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeBool.h:655
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition: LeafNodeBool.h:588
void setValuesOff()
Mark all voxels as inactive but don&#39;t change their values.
Definition: LeafNodeBool.h:302
static Index size()
Definition: LeafNodeBool.h:102
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:543
ValueOnIter beginValueOn()
Definition: LeafNodeBool.h:659
ChildOnCIter endChildOn() const
Definition: LeafNodeBool.h:690
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeBool.h:651
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeBool.h:737
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:527
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:367
static Index numValues()
Definition: LeafNodeBool.h:149
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:192
bool operator!=(const Buffer &other) const
Definition: LeafNodeBool.h:95
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:390
bool isDense() const
Return true if this node contains only active voxels.
Definition: LeafNode.h:219
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
static Index size()
Definition: LeafNodeBool.h:148
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1185
static const Index LEVEL
Definition: LeafNode.h:77
LeafNode< ValueType, Log2Dim > Type
Definition: LeafNodeBool.h:74
Buffer mBuffer
Bitmask representing the values of voxels.
Definition: LeafNodeBool.h:735
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1727
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeBool.h:649
bool isValueMaskOn(Index n) const
Definition: LeafNodeBool.h:702
static const bool sOn
Definition: LeafNodeBool.h:740
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:438
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1703
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:952
bool isChildMaskOff(Index) const
Definition: LeafNodeBool.h:710
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1028
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1408
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeBool.h:682
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:1150
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:97
void pruneOp(PruneOp &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:520
OPENVDB_DEPRECATED void evalActiveVoxelBoundingBox(CoordBBox &) const
Definition: LeafNode.h:1271
bool isValueMaskOff() const
Definition: LeafNodeBool.h:705
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:525
ValueOffCIter cendValueOff() const
Definition: LeafNodeBool.h:670
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1238
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:359
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNode.h:854
ValueAllCIter endValueAll() const
Definition: LeafNodeBool.h:674
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeBool.h:627
ChildOffCIter endChildOff() const
Definition: LeafNodeBool.h:693
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
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeBool.h:654
ChildAllCIter endChildAll() const
Definition: LeafNodeBool.h:696
ValueAllCIter cendValueAll() const
Definition: LeafNodeBool.h:673
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:400
Definition: Types.h:346
LeafNode< bool, Log2Dim > LeafNodeType
Definition: LeafNodeBool.h:57
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeBool.h:685
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeBool.h:647
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:565
const bool & getValue() const
Definition: LeafNodeBool.h:594
Definition: NodeMasks.h:220
bool resultIsActive() const
Definition: Types.h:280
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:1489
ChildOffCIter cendChildOff() const
Definition: LeafNodeBool.h:692
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeBool.h:629
ChildOnCIter beginChildOn() const
Definition: LeafNodeBool.h:680
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:62
static Index getLevel()
Definition: LeafNodeBool.h:150
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:509
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNodeBool.h:733
bool isChildMaskOff() const
Definition: LeafNodeBool.h:711
bool isValueMaskOff(Index n) const
Definition: LeafNodeBool.h:704
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:185
LeafNode()
Default constructor.
Definition: LeafNode.h:894
ValueOffIter beginValueOff()
Definition: LeafNodeBool.h:662
Definition: NodeMasks.h:251
ChildOffCIter beginChildOff() const
Definition: LeafNodeBool.h:683
~LeafNode()
Destructor.
Definition: LeafNode.h:946
ValueAllIter beginValueAll()
Definition: LeafNodeBool.h:665
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
void pruneInactive(const ValueType &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:522
ValueAllIter endValueAll()
Definition: LeafNodeBool.h:675
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
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:523
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don&#39;t change its value.
Definition: LeafNodeBool.h:277
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
void swap(Buffer &other)
Definition: LeafNodeBool.h:99
void setValueMaskOn(Index n)
Definition: LeafNodeBool.h:714
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:361
void save(std::ostream &os) const
Definition: NodeMasks.h:492
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeBool.h:652
const Buffer & buffer() const
Definition: LeafNodeBool.h:222
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNode.h:852
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1193
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
ValueIter< MaskOnIter, LeafNode, bool > ValueOnIter
Definition: LeafNodeBool.h:644
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeBool.h:657
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeBool.h:660
OPENVDB_IMPORT uint32_t getFormatVersion(std::istream &)
Return the file format version number associated with the given input stream.
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
void setValueMaskOff(Index n)
Definition: LeafNodeBool.h:715
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
void merge(const LeafNode &)
Definition: LeafNode.h:1427
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeBool.h:606
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:514
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:615
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
Buffer(bool on)
Definition: LeafNodeBool.h:80
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeBool.h:147
ChildOnCIter cendChildOn() const
Definition: LeafNodeBool.h:689
void fill(bool val)
Definition: LeafNodeBool.h:84
ChildOffIter beginChildOff()
Definition: LeafNodeBool.h:684
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
Buffer & operator=(const Buffer &b)
Definition: LeafNodeBool.h:85
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 combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1511