OpenVDB: LeafNodeBool.h Source File

OpenVDB 8.0.0

LeafNodeBool.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #ifndef OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
5 #define OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
6
7 #include <openvdb/Types.h>
8 #include <openvdb/io/Compression.h> // for io::readData(), etc.
9 #include <openvdb/math/Math.h> // for math::isZero()
10 #include <openvdb/util/NodeMasks.h>
11 #include "LeafNode.h"
12 #include "Iterator.h"
13 #include <iostream>
14 #include <sstream>
15 #include <string>
16 #include <type_traits>
17 #include <vector>
18
19
20 namespace openvdb {
21 OPENVDB_USE_VERSION_NAMESPACE
22 namespace OPENVDB_VERSION_NAME {
23 namespace tree {
24
27 template<Index Log2Dim>
28 class LeafNode<bool, Log2Dim>
29 {
30 public:
31 using LeafNodeType = LeafNode<bool, Log2Dim>;
32 using BuildType = bool;
33 using ValueType = bool;
34 using Buffer = LeafBuffer<ValueType, Log2Dim>;
35 using NodeMaskType = util::NodeMask<Log2Dim>;
36 using Ptr = SharedPtr<LeafNodeType>;
37
38 // These static declarations must be on separate lines to avoid VC9 compiler errors.
39 static const Index LOG2DIM = Log2Dim; // needed by parent nodes
40 static const Index TOTAL = Log2Dim; // needed by parent nodes
41 static const Index DIM = 1 << TOTAL; // dimension along one coordinate direction
42 static const Index NUM_VALUES = 1 << 3 * Log2Dim;
43 static const Index NUM_VOXELS = NUM_VALUES; // total number of voxels represented by this node
44 static const Index SIZE = NUM_VALUES;
45 static const Index LEVEL = 0; // level 0 = leaf
46
49 template<typename ValueType>
50 struct ValueConverter { using Type = LeafNode<ValueType, Log2Dim>; };
51
54 template<typename OtherNodeType>
55 struct SameConfiguration {
56 static const bool value = SameLeafConfig<LOG2DIM, OtherNodeType>::value;
57 };
58
59
61 LeafNode();
62
67 explicit LeafNode(const Coord& xyz, bool value = false, bool active = false);
68
70 LeafNode(PartialCreate, const Coord& xyz, bool value = false, bool active = false);
71
73 LeafNode(const LeafNode&);
74
76 LeafNode& operator=(const LeafNode&) = default;
77
79 template<typename OtherValueType>
80 explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
81
83 template<typename ValueType>
84 LeafNode(const LeafNode<ValueType, Log2Dim>& other, TopologyCopy);
85
87 template<typename ValueType>
90 LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool offValue, bool onValue, TopologyCopy);
91 template<typename ValueType>
92 LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool background, TopologyCopy);
94
96 ~LeafNode();
97
98 //
99 // Statistics
100 //
102 static Index log2dim() { return Log2Dim; }
104 static Index dim() { return DIM; }
105 static Index size() { return SIZE; }
106 static Index numValues() { return SIZE; }
107 static Index getLevel() { return LEVEL; }
108 static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
109 static Index getChildDim() { return 1; }
110
111 static Index32 leafCount() { return 1; }
113 void nodeCount(std::vector<Index32> &) const {}
114 static Index32 nonLeafCount() { return 0; }
115
117 Index64 onVoxelCount() const { return mValueMask.countOn(); }
119 Index64 offVoxelCount() const { return mValueMask.countOff(); }
120 Index64 onLeafVoxelCount() const { return onVoxelCount(); }
121 Index64 offLeafVoxelCount() const { return offVoxelCount(); }
122 static Index64 onTileCount() { return 0; }
123 static Index64 offTileCount() { return 0; }
124
126 bool isEmpty() const { return mValueMask.isOff(); }
128 bool isDense() const { return mValueMask.isOn(); }
132 bool isAllocated() const { return true; }
136 bool allocate() { return true; }
137
139 Index64 memUsage() const;
140
144 void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
145
148 CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
149
151 void setOrigin(const Coord& origin) { mOrigin = origin; }
153 const Coord& origin() const { return mOrigin; }
155 void getOrigin(Coord& origin) const { origin = mOrigin; }
156 void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
158
160 static Index coordToOffset(const Coord& xyz);
163 static Coord offsetToLocalCoord(Index n);
165 Coord offsetToGlobalCoord(Index n) const;
166
168 std::string str() const;
169
172 template<typename OtherType, Index OtherLog2Dim>
173 bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
174
176 bool operator==(const LeafNode&) const;
177 bool operator!=(const LeafNode&) const;
178
179 //
180 // Buffer management
181 //
184 void swap(Buffer& other) { mBuffer.swap(other); }
185 const Buffer& buffer() const { return mBuffer; }
186 Buffer& buffer() { return mBuffer; }
187
188 //
189 // I/O methods
190 //
192 void readTopology(std::istream&, bool fromHalf = false);
194 void writeTopology(std::ostream&, bool toHalf = false) const;
195
197 void readBuffers(std::istream&, bool fromHalf = false);
198 void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
200 void writeBuffers(std::ostream&, bool toHalf = false) const;
201
202 //
203 // Accessor methods
204 //
206 const bool& getValue(const Coord& xyz) const;
208 const bool& getValue(Index offset) const;
209
213 bool probeValue(const Coord& xyz, bool& val) const;
214
216 static Index getValueLevel(const Coord&) { return LEVEL; }
217
219 void setActiveState(const Coord& xyz, bool on);
221 void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
222
224 void setValueOnly(const Coord& xyz, bool val);
226 void setValueOnly(Index offset, bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
227
229 void setValueOff(const Coord& xyz) { mValueMask.setOff(this->coordToOffset(xyz)); }
231 void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
232
234 void setValueOff(const Coord& xyz, bool val);
236 void setValueOff(Index offset, bool val);
237
239 void setValueOn(const Coord& xyz) { mValueMask.setOn(this->coordToOffset(xyz)); }
241 void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
242
244 void setValueOn(const Coord& xyz, bool val);
246 void setValue(const Coord& xyz, bool val) { this->setValueOn(xyz, val); }
248 void setValueOn(Index offset, bool val);
249
252 template<typename ModifyOp>
253 void modifyValue(Index offset, const ModifyOp& op);
256 template<typename ModifyOp>
257 void modifyValue(const Coord& xyz, const ModifyOp& op);
258
260 template<typename ModifyOp>
261 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op);
262
264 void setValuesOn() { mValueMask.setOn(); }
266 void setValuesOff() { mValueMask.setOff(); }
267
269 bool isValueOn(const Coord& xyz) const { return mValueMask.isOn(this->coordToOffset(xyz)); }
271 bool isValueOn(Index offset) const { assert(offset < SIZE); return mValueMask.isOn(offset); }
272
274 static bool hasActiveTiles() { return false; }
275
277 void clip(const CoordBBox&, bool background);
278
280 void fill(const CoordBBox& bbox, bool value, bool active = true);
282 void denseFill(const CoordBBox& bbox, bool val, bool on = true) { this->fill(bbox, val, on); }
283
285 void fill(const bool& value);
287 void fill(const bool& value, bool active);
288
300 template<typename DenseT>
301 void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
302
319 template<typename DenseT>
320 void copyFromDense(const CoordBBox& bbox, const DenseT& dense, bool background, bool tolerance);
321
324 template<typename AccessorT>
325 const bool& getValueAndCache(const Coord& xyz, AccessorT&) const {return this->getValue(xyz);}
326
329 template<typename AccessorT>
330 bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
331
334 template<typename AccessorT>
335 void setValueAndCache(const Coord& xyz, bool val, AccessorT&) { this->setValueOn(xyz, val); }
336
340 template<typename AccessorT>
341 void setValueOnlyAndCache(const Coord& xyz, bool val, AccessorT&) {this->setValueOnly(xyz,val);}
342
345 template<typename AccessorT>
346 void setValueOffAndCache(const Coord& xyz, bool value, AccessorT&)
347 {
348 this->setValueOff(xyz, value);
349 }
350
354 template<typename ModifyOp, typename AccessorT>
355 void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
356 {
357 this->modifyValue(xyz, op);
358 }
359
362 template<typename ModifyOp, typename AccessorT>
363 void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
364 {
365 this->modifyValueAndActiveState(xyz, op);
366 }
367
371 template<typename AccessorT>
372 void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
373 {
374 this->setActiveState(xyz, on);
375 }
376
380 template<typename AccessorT>
381 bool probeValueAndCache(const Coord& xyz, bool& val, AccessorT&) const
382 {
383 return this->probeValue(xyz, val);
384 }
385
388 template<typename AccessorT>
389 static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
390
394 const bool& getFirstValue() const { if (mValueMask.isOn(0)) return Buffer::sOn; else return Buffer::sOff; }
398 const bool& getLastValue() const { if (mValueMask.isOn(SIZE-1)) return Buffer::sOn; else return Buffer::sOff; }
399
403 bool isConstant(bool& constValue, bool& state, bool tolerance = 0) const;
404
410 bool medianAll() const;
411
418 Index medianOn(ValueType &value) const;
419
426 Index medianOff(ValueType &value) const;
427
429 bool isInactive() const { return mValueMask.isOff(); }
430
431 void resetBackground(bool oldBackground, bool newBackground);
432
433 void negate() { mBuffer.mData.toggle(); }
434
435 template<MergePolicy Policy>
436 void merge(const LeafNode& other, bool bg = false, bool otherBG = false);
437 template<MergePolicy Policy> void merge(bool tileValue, bool tileActive);
438
441 void voxelizeActiveTiles(bool = true) {}
442
449 template<typename OtherType>
450 void topologyUnion(const LeafNode<OtherType, Log2Dim>& other);
451
463 template<typename OtherType>
464 void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const bool&);
465
477 template<typename OtherType>
478 void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const bool&);
479
480 template<typename CombineOp>
481 void combine(const LeafNode& other, CombineOp& op);
482 template<typename CombineOp>
483 void combine(bool, bool valueIsActive, CombineOp& op);
484
485 template<typename CombineOp, typename OtherType /*= bool*/>
486 void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
487 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
488 void combine2(bool, const OtherNodeT& other, bool valueIsActive, CombineOp&);
489 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
490 void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
491
496 template<typename BBoxOp> void visitActiveBBox(BBoxOp&) const;
497
498 template<typename VisitorOp> void visit(VisitorOp&);
499 template<typename VisitorOp> void visit(VisitorOp&) const;
500
501 template<typename OtherLeafNodeType, typename VisitorOp>
502 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
503 template<typename OtherLeafNodeType, typename VisitorOp>
504 void visit2Node(OtherLeafNodeType& other, VisitorOp&) const;
505 template<typename IterT, typename VisitorOp>
506 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false);
507 template<typename IterT, typename VisitorOp>
508 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false) const;
509
511 void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
513 void addLeaf(LeafNode*) {}
514 template<typename AccessorT>
515 void addLeafAndCache(LeafNode*, AccessorT&) {}
516 template<typename NodeT>
517 NodeT* stealNode(const Coord&, const ValueType&, bool) { return nullptr; }
518 template<typename NodeT>
519 NodeT* probeNode(const Coord&) { return nullptr; }
520 template<typename NodeT>
521 const NodeT* probeConstNode(const Coord&) const { return nullptr; }
522 template<typename ArrayT> void getNodes(ArrayT&) const {}
523 template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
525
526 void addTile(Index level, const Coord&, bool val, bool active);
527 void addTile(Index offset, bool val, bool active);
528 template<typename AccessorT>
529 void addTileAndCache(Index level, const Coord&, bool val, bool active, AccessorT&);
530
532 LeafNode* touchLeaf(const Coord&) { return this; }
534 template<typename AccessorT>
535 LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
536 LeafNode* probeLeaf(const Coord&) { return this; }
537 template<typename AccessorT>
538 LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
539 template<typename NodeT, typename AccessorT>
540 NodeT* probeNodeAndCache(const Coord&, AccessorT&)
541 {
542 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
543 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
544 return reinterpret_cast<NodeT*>(this);
545 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
546 }
548
549 const LeafNode* probeLeaf(const Coord&) const { return this; }
551 template<typename AccessorT>
552 const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
553 const LeafNode* probeConstLeaf(const Coord&) const { return this; }
554 template<typename AccessorT>
555 const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
556 template<typename NodeT, typename AccessorT>
557 const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
558 {
559 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
560 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
561 return reinterpret_cast<const NodeT*>(this);
562 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
563 }
565
566 //
567 // Iterators
568 //
569 protected:
570 using MaskOnIter = typename NodeMaskType::OnIterator;
571 using MaskOffIter = typename NodeMaskType::OffIterator;
572 using MaskDenseIter = typename NodeMaskType::DenseIterator;
573
574 template<typename MaskIterT, typename NodeT, typename ValueT>
575 struct ValueIter:
576 // Derives from SparseIteratorBase, but can also be used as a dense iterator,
577 // if MaskIterT is a dense mask iterator type.
578 public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
579 {
580 using BaseT = SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT>;
581
582 ValueIter() {}
583 ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
584
585 const bool& getItem(Index pos) const { return this->parent().getValue(pos); }
586 const bool& getValue() const { return this->getItem(this->pos()); }
587
588 // Note: setItem() can't be called on const iterators.
589 void setItem(Index pos, bool value) const { this->parent().setValueOnly(pos, value); }
590 // Note: setValue() can't be called on const iterators.
591 void setValue(bool value) const { this->setItem(this->pos(), value); }
592
593 // Note: modifyItem() can't be called on const iterators.
594 template<typename ModifyOp>
595 void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
596 // Note: modifyValue() can't be called on const iterators.
597 template<typename ModifyOp>
598 void modifyValue(const ModifyOp& op) const { this->modifyItem(this->pos(), op); }
599 };
600
602 template<typename MaskIterT, typename NodeT>
603 struct ChildIter:
604 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>
605 {
606 ChildIter() {}
607 ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
608 MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
609 };
610
611 template<typename NodeT, typename ValueT>
612 struct DenseIter: public DenseIteratorBase<
613 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, /*ChildT=*/void, ValueT>
614 {
615 using BaseT = DenseIteratorBase<MaskDenseIter, DenseIter, NodeT, void, ValueT>;
616 using NonConstValueT = typename BaseT::NonConstValueType;
617
618 DenseIter() {}
619 DenseIter(const MaskDenseIter& iter, NodeT* parent): BaseT(iter, parent) {}
620
621 bool getItem(Index pos, void*& child, NonConstValueT& value) const
622 {
623 value = this->parent().getValue(pos);
624 child = nullptr;
625 return false; // no child
626 }
627
628 // Note: setItem() can't be called on const iterators.
629 //void setItem(Index pos, void* child) const {}
630
631 // Note: unsetItem() can't be called on const iterators.
632 void unsetItem(Index pos, const ValueT& val) const {this->parent().setValueOnly(pos, val);}
633 };
634
635 public:
636 using ValueOnIter = ValueIter<MaskOnIter, LeafNode, const bool>;
637 using ValueOnCIter = ValueIter<MaskOnIter, const LeafNode, const bool>;
638 using ValueOffIter = ValueIter<MaskOffIter, LeafNode, const bool>;
639 using ValueOffCIter = ValueIter<MaskOffIter, const LeafNode, const bool>;
640 using ValueAllIter = ValueIter<MaskDenseIter, LeafNode, const bool>;
641 using ValueAllCIter = ValueIter<MaskDenseIter, const LeafNode, const bool>;
642 using ChildOnIter = ChildIter<MaskOnIter, LeafNode>;
643 using ChildOnCIter = ChildIter<MaskOnIter, const LeafNode>;
644 using ChildOffIter = ChildIter<MaskOffIter, LeafNode>;
645 using ChildOffCIter = ChildIter<MaskOffIter, const LeafNode>;
646 using ChildAllIter = DenseIter<LeafNode, bool>;
647 using ChildAllCIter = DenseIter<const LeafNode, const bool>;
648
649 ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
650 ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
651 ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
652 ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
653 ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
654 ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
655 ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
656 ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
657 ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
658
659 ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
660 ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
661 ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
662 ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
663 ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
664 ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
665 ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
666 ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
667 ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
668
669 // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
670 // because leaf nodes have no children.
671 ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
672 ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
673 ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
674 ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
675 ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
676 ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
677 ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
678 ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
679 ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
680
681 ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
682 ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
683 ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
684 ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
685 ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
686 ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
687 ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
688 ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
689 ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
690
691 //
692 // Mask accessors
693 //
694 bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
695 bool isValueMaskOn() const { return mValueMask.isOn(); }
696 bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
697 bool isValueMaskOff() const { return mValueMask.isOff(); }
698 const NodeMaskType& getValueMask() const { return mValueMask; }
699 const NodeMaskType& valueMask() const { return mValueMask; }
700 NodeMaskType& getValueMask() { return mValueMask; }
701 void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
702 bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
703 bool isChildMaskOff(Index) const { return true; }
704 bool isChildMaskOff() const { return true; }
705 protected:
706 void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
707 void setValueMaskOn(Index n) { mValueMask.setOn(n); }
708 void setValueMaskOff(Index n) { mValueMask.setOff(n); }
709
711 static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
712
713 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
714 static inline void doVisit(NodeT&, VisitorOp&);
715
716 template<typename NodeT, typename OtherNodeT, typename VisitorOp,
717 typename ChildAllIterT, typename OtherChildAllIterT>
718 static inline void doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp&);
719
720 template<typename NodeT, typename VisitorOp,
721 typename ChildAllIterT, typename OtherChildAllIterT>
722 static inline void doVisit2(NodeT& self, OtherChildAllIterT&, VisitorOp&, bool otherIsLHS);
723
724
726 NodeMaskType mValueMask;
728 Buffer mBuffer;
730 Coord mOrigin;
731
732 private:
735 template<typename, Index> friend class LeafNode;
736
737 friend struct ValueIter<MaskOnIter, LeafNode, bool>;
738 friend struct ValueIter<MaskOffIter, LeafNode, bool>;
739 friend struct ValueIter<MaskDenseIter, LeafNode, bool>;
740 friend struct ValueIter<MaskOnIter, const LeafNode, bool>;
741 friend struct ValueIter<MaskOffIter, const LeafNode, bool>;
742 friend struct ValueIter<MaskDenseIter, const LeafNode, bool>;
743
745 friend class IteratorBase<MaskOnIter, LeafNode>;
748 friend class IteratorBase<MaskOffIter, LeafNode>;
749 friend class IteratorBase<MaskDenseIter, LeafNode>;
751
752 }; // class LeafNode<bool>
753
754
756
757
758 template<Index Log2Dim>
759 inline
760 LeafNode<bool, Log2Dim>::LeafNode()
761 : mOrigin(0, 0, 0)
762 {
763 }
764
765
766 template<Index Log2Dim>
767 inline
768 LeafNode<bool, Log2Dim>::LeafNode(const Coord& xyz, bool value, bool active)
769 : mValueMask(active)
770 , mBuffer(value)
771 , mOrigin(xyz & (~(DIM - 1)))
772 {
773 }
774
775
776 template<Index Log2Dim>
777 inline
778 LeafNode<bool, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, bool value, bool active)
779 : mValueMask(active)
780 , mBuffer(value)
781 , mOrigin(xyz & (~(DIM - 1)))
782 {
786 }
787
788
789 template<Index Log2Dim>
790 inline
791 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode &other)
792 : mValueMask(other.valueMask())
793 , mBuffer(other.mBuffer)
794 , mOrigin(other.mOrigin)
795 {
796 }
797
798
799 // Copy-construct from a leaf node with the same configuration but a different ValueType.
800 template<Index Log2Dim>
801 template<typename ValueT>
802 inline
803 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other)
804 : mValueMask(other.valueMask())
805 , mOrigin(other.origin())
806 {
807 struct Local {
809 static inline bool convertValue(const ValueT& val) { return bool(val); }
810 };
811
812 for (Index i = 0; i < SIZE; ++i) {
813 mBuffer.setValue(i, Local::convertValue(other.mBuffer[i]));
814 }
815 }
816
817
818 template<Index Log2Dim>
819 template<typename ValueT>
820 inline
821 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other,
822 bool background, TopologyCopy)
823 : mValueMask(other.valueMask())
824 , mBuffer(background)
825 , mOrigin(other.origin())
826 {
827 }
828
829
830 template<Index Log2Dim>
831 template<typename ValueT>
832 inline
833 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other, TopologyCopy)
834 : mValueMask(other.valueMask())
835 , mBuffer(other.valueMask())// value = active state
836 , mOrigin(other.origin())
837 {
838 }
839
840
841 template<Index Log2Dim>
842 template<typename ValueT>
843 inline
844 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other,
845 bool offValue, bool onValue, TopologyCopy)
846 : mValueMask(other.valueMask())
847 , mBuffer(other.valueMask())
848 , mOrigin(other.origin())
849 {
850 if (offValue) { if (!onValue) mBuffer.mData.toggle(); else mBuffer.mData.setOn(); }
851 }
852
853
854 template<Index Log2Dim>
855 inline
856 LeafNode<bool, Log2Dim>::~LeafNode()
857 {
858 }
859
860
862
863
864 template<Index Log2Dim>
865 inline Index64
866 LeafNode<bool, Log2Dim>::memUsage() const
867 {
868 // Use sizeof(*this) to capture alignment-related padding
869 return sizeof(*this);
870 }
871
872
873 template<Index Log2Dim>
874 inline void
875 LeafNode<bool, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
876 {
877 CoordBBox this_bbox = this->getNodeBoundingBox();
878 if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
879 if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
880 if (visitVoxels) {//use voxel granularity?
881 this_bbox.reset();
882 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
883 this_bbox.translate(this->origin());
884 }
885 bbox.expand(this_bbox);
886 }
887 }
888
889
890 template<Index Log2Dim>
891 template<typename OtherType, Index OtherLog2Dim>
892 inline bool
893 LeafNode<bool, Log2Dim>::hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const
894 {
895 assert(other);
896 return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
897 }
898
899
900 template<Index Log2Dim>
901 inline std::string
902 LeafNode<bool, Log2Dim>::str() const
903 {
904 std::ostringstream ostr;
905 ostr << "LeafNode @" << mOrigin << ": ";
906 for (Index32 n = 0; n < SIZE; ++n) ostr << (mValueMask.isOn(n) ? '#' : '.');
907 return ostr.str();
908 }
909
910
912
913
914 template<Index Log2Dim>
915 inline Index
916 LeafNode<bool, Log2Dim>::coordToOffset(const Coord& xyz)
917 {
918 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
919 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
920 + ((xyz[1] & (DIM-1u)) << Log2Dim)
921 + (xyz[2] & (DIM-1u));
922 }
923
924
925 template<Index Log2Dim>
926 inline Coord
927 LeafNode<bool, Log2Dim>::offsetToLocalCoord(Index n)
928 {
929 assert(n < (1 << 3*Log2Dim));
930 Coord xyz;
931 xyz.setX(n >> 2*Log2Dim);
932 n &= ((1 << 2*Log2Dim) - 1);
933 xyz.setY(n >> Log2Dim);
934 xyz.setZ(n & ((1 << Log2Dim) - 1));
935 return xyz;
936 }
937
938
939 template<Index Log2Dim>
940 inline Coord
941 LeafNode<bool, Log2Dim>::offsetToGlobalCoord(Index n) const
942 {
943 return (this->offsetToLocalCoord(n) + this->origin());
944 }
945
946
948
949
950 template<Index Log2Dim>
951 inline void
952 LeafNode<bool, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
953 {
954 mValueMask.load(is);
955 }
956
957
958 template<Index Log2Dim>
959 inline void
960 LeafNode<bool, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
961 {
962 mValueMask.save(os);
963 }
964
965
966 template<Index Log2Dim>
967 inline void
968 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
969 {
970 // Boolean LeafNodes don't currently implement lazy loading.
971 // Instead, load the full buffer, then clip it.
972
973 this->readBuffers(is, fromHalf);
974
975 // Get this tree's background value.
976 bool background = false;
977 if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
978 background = *static_cast<const bool*>(bgPtr);
979 }
980 this->clip(clipBBox, background);
981 }
982
983
984 template<Index Log2Dim>
985 inline void
986 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, bool /*fromHalf*/)
987 {
988 // Read in the value mask.
989 mValueMask.load(is);
990 // Read in the origin.
991 is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
992
993 if (io::getFormatVersion(is) >= OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION) {
994 // Read in the mask for the voxel values.
995 mBuffer.mData.load(is);
996 } else {
997 // Older files stored one or more bool arrays.
998
999 // Read in the number of buffers, which should now always be one.
1000 int8_t numBuffers = 0;
1001 is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1002
1003 // Read in the buffer.
1004 // (Note: prior to the bool leaf optimization, buffers were always compressed.)
1005 std::unique_ptr<bool[]> buf{new bool[SIZE]};
1006 io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1007
1008 // Transfer values to mBuffer.
1009 mBuffer.mData.setOff();
1010 for (Index i = 0; i < SIZE; ++i) {
1011 if (buf[i]) mBuffer.mData.setOn(i);
1012 }
1013
1014 if (numBuffers > 1) {
1015 // Read in and discard auxiliary buffers that were created with
1016 // earlier versions of the library.
1017 for (int i = 1; i < numBuffers; ++i) {
1018 io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1019 }
1020 }
1021 }
1022 }
1023
1024
1025 template<Index Log2Dim>
1026 inline void
1027 LeafNode<bool, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
1028 {
1029 // Write out the value mask.
1030 mValueMask.save(os);
1031 // Write out the origin.
1032 os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1033 // Write out the voxel values.
1034 mBuffer.mData.save(os);
1035 }
1036
1037
1039
1040
1041 template<Index Log2Dim>
1042 inline bool
1043 LeafNode<bool, Log2Dim>::operator==(const LeafNode& other) const
1044 {
1045 return mOrigin == other.mOrigin &&
1046 mValueMask == other.valueMask() &&
1047 mBuffer == other.mBuffer;
1048 }
1049
1050
1051 template<Index Log2Dim>
1052 inline bool
1053 LeafNode<bool, Log2Dim>::operator!=(const LeafNode& other) const
1054 {
1055 return !(this->operator==(other));
1056 }
1057
1058
1060
1061
1062 template<Index Log2Dim>
1063 inline bool
1064 LeafNode<bool, Log2Dim>::isConstant(bool& constValue, bool& state, bool tolerance) const
1065 {
1066 if (!mValueMask.isConstant(state)) return false;
1067
1068 // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1069 if (!tolerance && !(mBuffer.mData.isOn() || mBuffer.mData.isOff())) return false;
1070
1071 constValue = mBuffer.mData.isOn();
1072 return true;
1073 }
1074
1076
1077 template<Index Log2Dim>
1078 inline bool
1079 LeafNode<bool, Log2Dim>::medianAll() const
1080 {
1081 const Index countTrue = mBuffer.mData.countOn();
1082 return countTrue > (NUM_VALUES >> 1);
1083 }
1084
1085 template<Index Log2Dim>
1086 inline Index
1087 LeafNode<bool, Log2Dim>::medianOn(bool& state) const
1088 {
1089 const NodeMaskType tmp = mBuffer.mData & mValueMask;//both true and active
1090 const Index countTrueOn = tmp.countOn(), countOn = mValueMask.countOn();
1091 state = countTrueOn > (NUM_VALUES >> 1);
1092 return countOn;
1093 }
1094
1095 template<Index Log2Dim>
1096 inline Index
1097 LeafNode<bool, Log2Dim>::medianOff(bool& state) const
1098 {
1099 const NodeMaskType tmp = mBuffer.mData & (!mValueMask);//both true and inactive
1100 const Index countTrueOff = tmp.countOn(), countOff = mValueMask.countOff();
1101 state = countTrueOff > (NUM_VALUES >> 1);
1102 return countOff;
1103 }
1104
1106
1107
1108 template<Index Log2Dim>
1109 inline void
1110 LeafNode<bool, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, bool val, bool active)
1111 {
1112 this->addTile(this->coordToOffset(xyz), val, active);
1113 }
1114
1115 template<Index Log2Dim>
1116 inline void
1117 LeafNode<bool, Log2Dim>::addTile(Index offset, bool val, bool active)
1118 {
1119 assert(offset < SIZE);
1120 this->setValueOnly(offset, val);
1121 this->setActiveState(offset, active);
1122 }
1123
1124 template<Index Log2Dim>
1125 template<typename AccessorT>
1126 inline void
1127 LeafNode<bool, Log2Dim>::addTileAndCache(Index level, const Coord& xyz,
1128 bool val, bool active, AccessorT&)
1129 {
1130 this->addTile(level, xyz, val, active);
1131 }
1132
1133
1135
1136
1137 template<Index Log2Dim>
1138 inline const bool&
1139 LeafNode<bool, Log2Dim>::getValue(const Coord& xyz) const
1140 {
1141 // This *CANNOT* use operator ? because Visual C++
1142 if (mBuffer.mData.isOn(this->coordToOffset(xyz))) return Buffer::sOn; else return Buffer::sOff;
1143 }
1144
1145
1146 template<Index Log2Dim>
1147 inline const bool&
1148 LeafNode<bool, Log2Dim>::getValue(Index offset) const
1149 {
1150 assert(offset < SIZE);
1151 // This *CANNOT* use operator ? for Windows
1152 if (mBuffer.mData.isOn(offset)) return Buffer::sOn; else return Buffer::sOff;
1153 }
1154
1155
1156 template<Index Log2Dim>
1157 inline bool
1158 LeafNode<bool, Log2Dim>::probeValue(const Coord& xyz, bool& val) const
1159 {
1160 const Index offset = this->coordToOffset(xyz);
1161 val = mBuffer.mData.isOn(offset);
1162 return mValueMask.isOn(offset);
1163 }
1164
1165
1166 template<Index Log2Dim>
1167 inline void
1168 LeafNode<bool, Log2Dim>::setValueOn(const Coord& xyz, bool val)
1169 {
1170 this->setValueOn(this->coordToOffset(xyz), val);
1171 }
1172
1173
1174 template<Index Log2Dim>
1175 inline void
1176 LeafNode<bool, Log2Dim>::setValueOn(Index offset, bool val)
1177 {
1178 assert(offset < SIZE);
1179 mValueMask.setOn(offset);
1180 mBuffer.mData.set(offset, val);
1181 }
1182
1183
1184 template<Index Log2Dim>
1185 inline void
1186 LeafNode<bool, Log2Dim>::setValueOnly(const Coord& xyz, bool val)
1187 {
1188 this->setValueOnly(this->coordToOffset(xyz), val);
1189 }
1190
1191
1192 template<Index Log2Dim>
1193 inline void
1194 LeafNode<bool, Log2Dim>::setActiveState(const Coord& xyz, bool on)
1195 {
1196 mValueMask.set(this->coordToOffset(xyz), on);
1197 }
1198
1199
1200 template<Index Log2Dim>
1201 inline void
1202 LeafNode<bool, Log2Dim>::setValueOff(const Coord& xyz, bool val)
1203 {
1204 this->setValueOff(this->coordToOffset(xyz), val);
1205 }
1206
1207
1208 template<Index Log2Dim>
1209 inline void
1210 LeafNode<bool, Log2Dim>::setValueOff(Index offset, bool val)
1211 {
1212 assert(offset < SIZE);
1213 mValueMask.setOff(offset);
1214 mBuffer.mData.set(offset, val);
1215 }
1216
1217
1218 template<Index Log2Dim>
1219 template<typename ModifyOp>
1220 inline void
1221 LeafNode<bool, Log2Dim>::modifyValue(Index offset, const ModifyOp& op)
1222 {
1223 bool val = mBuffer.mData.isOn(offset);
1224 op(val);
1225 mBuffer.mData.set(offset, val);
1226 mValueMask.setOn(offset);
1227 }
1228
1229
1230 template<Index Log2Dim>
1231 template<typename ModifyOp>
1232 inline void
1233 LeafNode<bool, Log2Dim>::modifyValue(const Coord& xyz, const ModifyOp& op)
1234 {
1235 this->modifyValue(this->coordToOffset(xyz), op);
1236 }
1237
1238
1239 template<Index Log2Dim>
1240 template<typename ModifyOp>
1241 inline void
1242 LeafNode<bool, Log2Dim>::modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
1243 {
1244 const Index offset = this->coordToOffset(xyz);
1245 bool val = mBuffer.mData.isOn(offset), state = mValueMask.isOn(offset);
1246 op(val, state);
1247 mBuffer.mData.set(offset, val);
1248 mValueMask.set(offset, state);
1249 }
1250
1251
1253
1254
1255 template<Index Log2Dim>
1256 inline void
1257 LeafNode<bool, Log2Dim>::resetBackground(bool oldBackground, bool newBackground)
1258 {
1259 if (newBackground != oldBackground) {
1260 // Flip mBuffer's background bits and zero its foreground bits.
1261 NodeMaskType bgMask = !(mBuffer.mData | mValueMask);
1262 // Overwrite mBuffer's background bits, leaving its foreground bits intact.
1263 mBuffer.mData = (mBuffer.mData & mValueMask) | bgMask;
1264 }
1265 }
1266
1267
1269
1270
1271 template<Index Log2Dim>
1272 template<MergePolicy Policy>
1273 inline void
1274 LeafNode<bool, Log2Dim>::merge(const LeafNode& other, bool /*bg*/, bool /*otherBG*/)
1275 {
1276 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1277 if (Policy == MERGE_NODES) return;
1278 for (typename NodeMaskType::OnIterator iter = other.valueMask().beginOn(); iter; ++iter) {
1279 const Index n = iter.pos();
1280 if (mValueMask.isOff(n)) {
1281 mBuffer.mData.set(n, other.mBuffer.mData.isOn(n));
1282 mValueMask.setOn(n);
1283 }
1284 }
1285 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1286 }
1287
1288 template<Index Log2Dim>
1289 template<MergePolicy Policy>
1290 inline void
1291 LeafNode<bool, Log2Dim>::merge(bool tileValue, bool tileActive)
1292 {
1293 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1294 if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1295 if (!tileActive) return;
1296 // Replace all inactive values with the active tile value.
1297 if (tileValue) mBuffer.mData |= !mValueMask; // -0=>1, +0=>0, -1=>1, +1=>1 (-,+ = off,on)
1298 else mBuffer.mData &= mValueMask; // -0=>0, +0=>0, -1=>0, +1=>1
1299 mValueMask.setOn();
1300 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1301 }
1302
1303
1305
1306
1307 template<Index Log2Dim>
1308 template<typename OtherType>
1309 inline void
1310 LeafNode<bool, Log2Dim>::topologyUnion(const LeafNode<OtherType, Log2Dim>& other)
1311 {
1312 mValueMask |= other.valueMask();
1313 }
1314
1315
1316 template<Index Log2Dim>
1317 template<typename OtherType>
1318 inline void
1319 LeafNode<bool, Log2Dim>::topologyIntersection(const LeafNode<OtherType, Log2Dim>& other,
1320 const bool&)
1321 {
1322 mValueMask &= other.valueMask();
1323 }
1324
1325
1326 template<Index Log2Dim>
1327 template<typename OtherType>
1328 inline void
1329 LeafNode<bool, Log2Dim>::topologyDifference(const LeafNode<OtherType, Log2Dim>& other,
1330 const bool&)
1331 {
1332 mValueMask &= !other.valueMask();
1333 }
1334
1335
1337
1338
1339 template<Index Log2Dim>
1340 inline void
1341 LeafNode<bool, Log2Dim>::clip(const CoordBBox& clipBBox, bool background)
1342 {
1343 CoordBBox nodeBBox = this->getNodeBoundingBox();
1344 if (!clipBBox.hasOverlap(nodeBBox)) {
1345 // This node lies completely outside the clipping region. Fill it with background tiles.
1346 this->fill(nodeBBox, background, /*active=*/false);
1347 } else if (clipBBox.isInside(nodeBBox)) {
1348 // This node lies completely inside the clipping region. Leave it intact.
1349 return;
1350 }
1351
1352 // This node isn't completely contained inside the clipping region.
1353 // Set any voxels that lie outside the region to the background value.
1354
1355 // Construct a boolean mask that is on inside the clipping region and off outside it.
1356 NodeMaskType mask;
1357 nodeBBox.intersect(clipBBox);
1358 Coord xyz;
1359 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1360 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1361 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1362 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1363 mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1364 }
1365 }
1366 }
1367
1368 // Set voxels that lie in the inactive region of the mask (i.e., outside
1369 // the clipping region) to the background value.
1370 for (MaskOffIter maskIter = mask.beginOff(); maskIter; ++maskIter) {
1371 this->setValueOff(maskIter.pos(), background);
1372 }
1373 }
1374
1375
1377
1378
1379 template<Index Log2Dim>
1380 inline void
1381 LeafNode<bool, Log2Dim>::fill(const CoordBBox& bbox, bool value, bool active)
1382 {
1383 auto clippedBBox = this->getNodeBoundingBox();
1384 clippedBBox.intersect(bbox);
1385 if (!clippedBBox) return;
1386
1387 for (Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1388 const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1389 for (Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1390 const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1391 for (Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1392 const Index offset = offsetXY + (z & (DIM-1u));
1393 mValueMask.set(offset, active);
1394 mBuffer.mData.set(offset, value);
1395 }
1396 }
1397 }
1398 }
1399
1400 template<Index Log2Dim>
1401 inline void
1402 LeafNode<bool, Log2Dim>::fill(const bool& value)
1403 {
1404 mBuffer.fill(value);
1405 }
1406
1407 template<Index Log2Dim>
1408 inline void
1409 LeafNode<bool, Log2Dim>::fill(const bool& value, bool active)
1410 {
1411 mBuffer.fill(value);
1412 mValueMask.set(active);
1413 }
1414
1415
1417
1418
1419 template<Index Log2Dim>
1420 template<typename DenseT>
1421 inline void
1422 LeafNode<bool, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1423 {
1424 using DenseValueType = typename DenseT::ValueType;
1425
1426 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1427 const Coord& min = dense.bbox().min();
1428 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1429 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1430 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1431 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1432 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1433 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1434 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1435 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1436 for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1437 *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1438 }
1439 }
1440 }
1441 }
1442
1443
1444 template<Index Log2Dim>
1445 template<typename DenseT>
1446 inline void
1447 LeafNode<bool, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1448 bool background, bool tolerance)
1449 {
1450 using DenseValueType = typename DenseT::ValueType;
1451 struct Local {
1452 inline static bool toBool(const DenseValueType& v) { return !math::isZero(v); }
1453 };
1454
1455 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1456 const Coord& min = dense.bbox().min();
1457 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1458 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1459 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1460 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1461 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1462 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1463 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1464 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1465 for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1466 // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1467 if (tolerance || (background == Local::toBool(*s2))) {
1468 mValueMask.setOff(n2);
1469 mBuffer.mData.set(n2, background);
1470 } else {
1471 mValueMask.setOn(n2);
1472 mBuffer.mData.set(n2, Local::toBool(*s2));
1473 }
1474 }
1475 }
1476 }
1477 }
1478
1479
1481
1482
1483 template<Index Log2Dim>
1484 template<typename CombineOp>
1485 inline void
1486 LeafNode<bool, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1487 {
1488 CombineArgs<bool> args;
1489 for (Index i = 0; i < SIZE; ++i) {
1490 bool result = false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1491 op(args.setARef(aVal)
1492 .setAIsActive(mValueMask.isOn(i))
1493 .setBRef(bVal)
1494 .setBIsActive(other.valueMask().isOn(i))
1495 .setResultRef(result));
1496 mValueMask.set(i, args.resultIsActive());
1497 mBuffer.mData.set(i, result);
1498 }
1499 }
1500
1501
1502 template<Index Log2Dim>
1503 template<typename CombineOp>
1504 inline void
1505 LeafNode<bool, Log2Dim>::combine(bool value, bool valueIsActive, CombineOp& op)
1506 {
1507 CombineArgs<bool> args;
1508 args.setBRef(value).setBIsActive(valueIsActive);
1509 for (Index i = 0; i < SIZE; ++i) {
1510 bool result = false, aVal = mBuffer.mData.isOn(i);
1511 op(args.setARef(aVal)
1512 .setAIsActive(mValueMask.isOn(i))
1513 .setResultRef(result));
1514 mValueMask.set(i, args.resultIsActive());
1515 mBuffer.mData.set(i, result);
1516 }
1517 }
1518
1519
1521
1522
1523 template<Index Log2Dim>
1524 template<typename CombineOp, typename OtherType>
1525 inline void
1526 LeafNode<bool, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1527 bool valueIsActive, CombineOp& op)
1528 {
1529 CombineArgs<bool, OtherType> args;
1530 args.setBRef(value).setBIsActive(valueIsActive);
1531 for (Index i = 0; i < SIZE; ++i) {
1532 bool result = false, aVal = other.mBuffer.mData.isOn(i);
1533 op(args.setARef(aVal)
1534 .setAIsActive(other.valueMask().isOn(i))
1535 .setResultRef(result));
1536 mValueMask.set(i, args.resultIsActive());
1537 mBuffer.mData.set(i, result);
1538 }
1539 }
1540
1541
1542 template<Index Log2Dim>
1543 template<typename CombineOp, typename OtherNodeT>
1544 inline void
1545 LeafNode<bool, Log2Dim>::combine2(bool value, const OtherNodeT& other,
1546 bool valueIsActive, CombineOp& op)
1547 {
1548 CombineArgs<bool, typename OtherNodeT::ValueType> args;
1549 args.setARef(value).setAIsActive(valueIsActive);
1550 for (Index i = 0; i < SIZE; ++i) {
1551 bool result = false, bVal = other.mBuffer.mData.isOn(i);
1552 op(args.setBRef(bVal)
1553 .setBIsActive(other.valueMask().isOn(i))
1554 .setResultRef(result));
1555 mValueMask.set(i, args.resultIsActive());
1556 mBuffer.mData.set(i, result);
1557 }
1558 }
1559
1560
1561 template<Index Log2Dim>
1562 template<typename CombineOp, typename OtherNodeT>
1563 inline void
1564 LeafNode<bool, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1565 {
1566 CombineArgs<bool, typename OtherNodeT::ValueType> args;
1567 for (Index i = 0; i < SIZE; ++i) {
1568 // Default behavior: output voxel is active if either input voxel is active.
1569 mValueMask.set(i, b0.valueMask().isOn(i) || b1.valueMask().isOn(i));
1570
1571 bool result = false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1572 op(args.setARef(b0Val)
1573 .setAIsActive(b0.valueMask().isOn(i))
1574 .setBRef(b1Val)
1575 .setBIsActive(b1.valueMask().isOn(i))
1576 .setResultRef(result));
1577 mValueMask.set(i, args.resultIsActive());
1578 mBuffer.mData.set(i, result);
1579 }
1580 }
1581
1582
1584
1585 template<Index Log2Dim>
1586 template<typename BBoxOp>
1587 inline void
1588 LeafNode<bool, Log2Dim>::visitActiveBBox(BBoxOp& op) const
1589 {
1590 if (op.template descent<LEVEL>()) {
1591 for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
1592 op.template operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1593 }
1594 } else {
1595 op.template operator()<LEVEL>(this->getNodeBoundingBox());
1596 }
1597 }
1598
1599
1600 template<Index Log2Dim>
1601 template<typename VisitorOp>
1602 inline void
1603 LeafNode<bool, Log2Dim>::visit(VisitorOp& op)
1604 {
1605 doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
1606 }
1607
1608
1609 template<Index Log2Dim>
1610 template<typename VisitorOp>
1611 inline void
1612 LeafNode<bool, Log2Dim>::visit(VisitorOp& op) const
1613 {
1614 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
1615 }
1616
1617
1618 template<Index Log2Dim>
1619 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1620 inline void
1621 LeafNode<bool, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
1622 {
1623 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1624 op(iter);
1625 }
1626 }
1627
1628
1630
1631
1632 template<Index Log2Dim>
1633 template<typename OtherLeafNodeType, typename VisitorOp>
1634 inline void
1635 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
1636 {
1637 doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
1638 typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
1639 }
1640
1641
1642 template<Index Log2Dim>
1643 template<typename OtherLeafNodeType, typename VisitorOp>
1644 inline void
1645 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
1646 {
1647 doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
1648 typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
1649 }
1650
1651
1652 template<Index Log2Dim>
1653 template<
1654 typename NodeT,
1655 typename OtherNodeT,
1656 typename VisitorOp,
1657 typename ChildAllIterT,
1658 typename OtherChildAllIterT>
1659 inline void
1660 LeafNode<bool, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
1661 {
1662 // Allow the two nodes to have different ValueTypes, but not different dimensions.
1663 static_assert(OtherNodeT::SIZE == NodeT::SIZE,
1664 "can't visit nodes of different sizes simultaneously");
1665 static_assert(OtherNodeT::LEVEL == NodeT::LEVEL,
1666 "can't visit nodes at different tree levels simultaneously");
1667
1668 ChildAllIterT iter = self.beginChildAll();
1669 OtherChildAllIterT otherIter = other.beginChildAll();
1670
1671 for ( ; iter && otherIter; ++iter, ++otherIter) {
1672 op(iter, otherIter);
1673 }
1674 }
1675
1676
1678
1679
1680 template<Index Log2Dim>
1681 template<typename IterT, typename VisitorOp>
1682 inline void
1683 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
1684 {
1685 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(*this, otherIter, op, otherIsLHS);
1686 }
1687
1688
1689 template<Index Log2Dim>
1690 template<typename IterT, typename VisitorOp>
1691 inline void
1692 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
1693 {
1694 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(*this, otherIter, op, otherIsLHS);
1695 }
1696
1697
1698 template<Index Log2Dim>
1699 template<
1700 typename NodeT,
1701 typename VisitorOp,
1702 typename ChildAllIterT,
1703 typename OtherChildAllIterT>
1704 inline void
1705 LeafNode<bool, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
1706 VisitorOp& op, bool otherIsLHS)
1707 {
1708 if (!otherIter) return;
1709
1710 if (otherIsLHS) {
1711 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1712 op(otherIter, iter);
1713 }
1714 } else {
1715 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1716 op(iter, otherIter);
1717 }
1718 }
1719 }
1720
1721 } // namespace tree
1722 } // namespace OPENVDB_VERSION_NAME
1723 } // namespace openvdb
1724
1725 #endif // OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
Types.h
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueType
bool ValueType
Definition: LeafNodeBool.h:33
openvdb::v8_2::math::Coord::x
Int32 x() const
Definition: Coord.h:131
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getValueMask
NodeMaskType & getValueMask()
Definition: LeafNodeBool.h:700
openvdb::v8_2::tree::DenseIteratorBase::NonConstValueType
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:184
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getValueMask
const NodeMaskType & getValueMask() const
Definition: LeafNodeBool.h:698
Compression.h
openvdb::v8_2::tree::LeafNode::operator==
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1431
openvdb::v8_2::CombineArgs::setARef
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: openvdb/Types.h:481
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeConstLeaf
const LeafNode * probeConstLeaf(const Coord &) const
Definition: LeafNodeBool.h:553
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueOnly
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don't change its active state.
Definition: LeafNodeBool.h:226
openvdb::v8_2::math::CoordBBox::isInside
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:400
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildOnCIter
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeBool.h:643
openvdb::v8_2::tree::LeafNode::SIZE
static const Index SIZE
Definition: LeafNode.h:53
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::setItem
void setItem(Index pos, bool value) const
Definition: LeafNodeBool.h:589
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cendChildOff
ChildOffCIter cendChildOff() const
Definition: LeafNodeBool.h:684
openvdb::v8_2::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOff
bool isValueMaskOff(Index n) const
Definition: LeafNodeBool.h:696
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueOnlyAndCache
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:341
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::modifyItem
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeBool.h:595
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::offTileCount
static Index64 offTileCount()
Definition: LeafNodeBool.h:123
openvdb::v8_2::tree::LeafNode::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:291
openvdb::v8_2::util::NodeMask::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:502
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::negate
void negate()
Definition: LeafNodeBool.h:433
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isValueOn
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeBool.h:271
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isAllocated
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition: LeafNodeBool.h:132
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::voxelizeActiveTiles
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNodeBool.h:441
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::swap
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition: LeafNodeBool.h:184
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeBool.h:649
openvdb::v8_2::math::CoordBBox::intersect
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:444
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::buffer
const Buffer & buffer() const
Definition: LeafNodeBool.h:185
openvdb::v8_2::tree::LeafNode::doVisit2Node
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:1895
NodeMasks.h
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginValueOn
ValueOnCIter beginValueOn() const
Definition: LeafNodeBool.h:650
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::hasActiveTiles
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeBool.h:274
openvdb::v8_2::OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION
@ OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION
Definition: version.h:188
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeLeafAndCache
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition: LeafNodeBool.h:552
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::onTileCount
static Index64 onTileCount()
Definition: LeafNodeBool.h:122
openvdb::v8_2::tree::LeafNode::memUsage
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1441
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endChildOn
ChildOnIter endChildOn()
Definition: LeafNodeBool.h:683
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::dim
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeBool.h:104
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endValueOn
ValueOnIter endValueOn()
Definition: LeafNodeBool.h:661
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOn
bool isValueMaskOn() const
Definition: LeafNodeBool.h:695
openvdb::v8_2::CombineArgs::setBRef
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: openvdb/Types.h:483
openvdb::v8_2::tree::LeafNode::LOG2DIM
static const Index LOG2DIM
Definition: LeafNode.h:48
openvdb::v8_2::tree::LeafNode::copyFromDense
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:1249
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getNodeLog2Dims
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition: LeafNodeBool.h:108
openvdb::v8_2::tree::LeafNode::valueMask
const NodeMaskType & valueMask() const
Definition: LeafNode.h:869
openvdb::v8_2::tree::LeafNode::medianAll
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition: LeafNode.h:1513
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::getItem
const bool & getItem(Index pos) const
Definition: LeafNodeBool.h:585
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getValueLevelAndCache
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeBool.h:389
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildOffCIter
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeBool.h:645
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::nodeCount
void nodeCount(std::vector< Index32 > &) const
no-op
Definition: LeafNodeBool.h:113
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getValueLevel
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeBool.h:216
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::addLeaf
void addLeaf(LeafNode *)
Definition: LeafNodeBool.h:513
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginChildOff
ChildOffCIter beginChildOff() const
Definition: LeafNodeBool.h:675
openvdb::v8_2::math::CoordBBox::max
const Coord & max() const
Definition: Coord.h:322
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isValueOn
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:269
openvdb::v8_2::Int32
int32_t Int32
Definition: openvdb/Types.h:34
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::size
static Index size()
Definition: LeafNodeBool.h:105
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginChildOn
ChildOnCIter beginChildOn() const
Definition: LeafNodeBool.h:672
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::modifyValue
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeBool.h:598
openvdb::v8_2::tree::LeafNode::str
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1015
openvdb::v8_2::tree::LeafNode::readBuffers
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1322
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValuesOn
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNodeBool.h:264
openvdb::v8_2::Index
Index32 Index
Definition: openvdb/Types.h:32
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueMaskOff
void setValueMaskOff(Index n)
Definition: LeafNodeBool.h:708
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setActiveStateAndCache
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:372
openvdb::v8_2::math::Coord::y
Int32 y() const
Definition: Coord.h:132
openvdb::v8_2::tree::LeafNode::LeafNode
friend class LeafNode
Definition: LeafNode.h:846
openvdb::v8_2::tree::LeafNode::readTopology
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1286
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueMask
void setValueMask(Index n, bool on)
Definition: LeafNodeBool.h:706
openvdb::v8_2::tree::LeafBuffer::mData
ValueType * mData
Definition: LeafBuffer.h:148
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::denseFill
void denseFill(const CoordBBox &bbox, bool val, bool on=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNodeBool.h:282
openvdb::v8_2::util::NodeMask::countOff
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:450
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isChildMaskOff
bool isChildMaskOff() const
Definition: LeafNodeBool.h:704
openvdb::v8_2::tools::prune
void prune(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any nodes whose values are all the same...
Definition: Prune.h:334
openvdb::v8_2::math::CoordBBox::translate
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition: Coord.h:458
openvdb::v8_2::math::isZero
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:338
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueAllIter
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition: LeafNodeBool.h:640
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::stealNode
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition: LeafNodeBool.h:517
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueAndCache
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:335
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValuesOff
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNodeBool.h:266
openvdb::v8_2::tree::LeafNode::resetBackground
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1611
openvdb::v8_2::io::getFormatVersion
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueOffIter
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition: LeafNodeBool.h:638
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginChildAll
ChildAllIter beginChildAll()
Definition: LeafNodeBool.h:679
openvdb::v8_2::tree::LeafNode::clip
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1139
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueOn
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNodeBool.h:239
openvdb::v8_2::CombineArgs::resultIsActive
bool resultIsActive() const
Definition: openvdb/Types.h:492
openvdb::v8_2::util::OffMaskIterator
Definition: NodeMasks.h:240
openvdb::v8_2::MERGE_ACTIVE_STATES_AND_NODES
@ MERGE_ACTIVE_STATES_AND_NODES
Definition: openvdb/Types.h:369
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::MaskOffIter
typename NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeBool.h:571
openvdb::v8_2::util::NodeMask
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition: NodeMasks.h:308
openvdb::v8_2::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: openvdb/Types.h:542
openvdb::v8_2::tree::LeafNode::topologyIntersection
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node's set of active values with the active values of the other node,...
Definition: LeafNode.h:1689
openvdb::v8_2::math::CoordBBox::reset
void reset()
Definition: Coord.h:327
openvdb::v8_2::tree::LeafNode::ChildAllCIter
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:289
openvdb::v8_2::util::DenseMaskIterator
Definition: NodeMasks.h:271
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::mBuffer
Buffer mBuffer
Bitmask representing the values of voxels.
Definition: LeafNodeBool.h:728
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::modifyValueAndCache
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:355
openvdb::v8_2::math::Coord::setY
Coord & setY(Int32 y)
Definition: Coord.h:81
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildOnIter
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeBool.h:642
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeConstLeafAndCache
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition: LeafNodeBool.h:555
openvdb::v8_2::util::NodeMask::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:354
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValue
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:246
openvdb::v8_2::tree::LeafNode::getValueMask
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:867
openvdb::v8_2::tree::LeafNode::~LeafNode
~LeafNode()
Destructor.
Definition: LeafNode.h:1008
openvdb::v8_2::math::Coord::setX
Coord & setX(Int32 x)
Definition: Coord.h:80
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildIter::ChildIter
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:607
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::leafCount
static Index32 leafCount()
Definition: LeafNodeBool.h:111
openvdb::v8_2::util::NodeMask::countOn
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:443
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginValueOff
ValueOffIter beginValueOff()
Definition: LeafNodeBool.h:654
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildIter::ChildIter
ChildIter()
Definition: LeafNodeBool.h:606
openvdb::v8_2::math::CoordBBox::min
const Coord & min() const
Definition: Coord.h:321
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginChildOn
ChildOnIter beginChildOn()
Definition: LeafNodeBool.h:673
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::buffer
Buffer & buffer()
Definition: LeafNodeBool.h:186
openvdb::v8_2::util::NodeMask::set
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:462
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< ValueType, Log2Dim > &other, bool background, TopologyCopy)
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endValueAll
ValueAllIter endValueAll()
Definition: LeafNodeBool.h:667
openvdb::v8_2::tree::LeafNode::doVisit2
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1942
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueOffAndCache
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:346
openvdb::v8_2::tree::LeafNode::modifyValueAndActiveState
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:450
openvdb::v8_2::tree::LeafBuffer< ValueType, Log2Dim >
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueOnIter
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition: LeafNodeBool.h:636
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeNode
NodeT * probeNode(const Coord &)
Definition: LeafNodeBool.h:519
openvdb::v8_2::tree::LeafNode::visitActiveBBox
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:1823
openvdb::v8_2::tree::LeafNode::visit
void visit(VisitorOp &)
Definition: LeafNode.h:1838
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::MaskDenseIter
typename NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeBool.h:572
openvdb::v8_2::tree::LeafNode::medianOff
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition: LeafNode.h:1555
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::numValues
static Index numValues()
Definition: LeafNodeBool.h:106
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isInactive
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNodeBool.h:429
openvdb::v8_2::tree::LeafNode::offsetToGlobalCoord
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1052
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::allocate
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNodeBool.h:136
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isValueOnAndCache
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:330
openvdb::v8_2::tree::LeafNode::addTile
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1582
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endValueOn
ValueOnCIter endValueOn() const
Definition: LeafNodeBool.h:660
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueOn
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNodeBool.h:241
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeConstNodeAndCache
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition: LeafNodeBool.h:557
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cbeginChildAll
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeBool.h:677
openvdb::v8_2::tree::LeafNode::operator!=
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:195
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getFirstValue
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeBool.h:394
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::onVoxelCount
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeBool.h:117
openvdb::v8_2::tree::LeafNode::setActiveState
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: LeafNode.h:1113
openvdb::v8_2::tree::LeafNode::DIM
static const Index DIM
Definition: LeafNode.h:50
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb_houdini::combine
ValueType combine(const ValueType &v0, const ValueType &v1, const ValueType &v2, const openvdb::Vec3d &w)
Combine different value types.
Definition: AttributeTransferUtil.h:140
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isEmpty
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeBool.h:126
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cendChildOn
ChildOnCIter cendChildOn() const
Definition: LeafNodeBool.h:681
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cendValueOff
ValueOffCIter cendValueOff() const
Definition: LeafNodeBool.h:662
openvdb::v8_2::tree::LeafNode::visit2
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1918
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeBool.h:655
openvdb::v8_2::tools::copyFromDense
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:568
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endChildAll
ChildAllCIter endChildAll() const
Definition: LeafNodeBool.h:688
openvdb::v8_2::tree::LeafNode::offsetToLocalCoord
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition: LeafNode.h:1038
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueMask
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeBool.h:701
openvdb::v8_2::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:103
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getNodeBoundingBox
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition: LeafNodeBool.h:148
openvdb::v8_2::SharedPtr
std::shared_ptr< T > SharedPtr
Definition: openvdb/Types.h:92
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginValueOn
ValueOnIter beginValueOn()
Definition: LeafNodeBool.h:651
openvdb::v8_2::util::NodeMask::load
void load(std::istream &is)
Definition: NodeMasks.h:569
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeValueAndCache
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:381
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getChildDim
static Index getChildDim()
Definition: LeafNodeBool.h:109
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::DenseIter::NonConstValueT
typename BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeBool.h:616
openvdb::v8_2::tree::LeafNode::writeBuffers
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1414
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cbeginChildOn
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeBool.h:671
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::MaskOnIter
typename NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeBool.h:570
openvdb::v8_2::tree::IteratorBase
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:30
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::BuildType
bool BuildType
Definition: LeafNodeBool.h:32
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setActiveState
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition: LeafNodeBool.h:221
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginChildAll
ChildAllCIter beginChildAll() const
Definition: LeafNodeBool.h:678
openvdb::v8_2::util::OnMaskIterator
Definition: NodeMasks.h:209
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::DenseIter::DenseIter
DenseIter()
Definition: LeafNodeBool.h:618
openvdb::v8_2::tree::LeafNode::NUM_VALUES
static const Index NUM_VALUES
Definition: LeafNode.h:51
openvdb::v8_2::MERGE_NODES
@ MERGE_NODES
Definition: openvdb/Types.h:368
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::addLeafAndCache
void addLeafAndCache(LeafNode *, AccessorT &)
Definition: LeafNodeBool.h:515
openvdb::v8_2::tree::LeafNode::modifyValue
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:429
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isChildMaskOff
bool isChildMaskOff(Index) const
Definition: LeafNodeBool.h:703
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::nonLeafCount
static Index32 nonLeafCount()
Definition: LeafNodeBool.h:114
openvdb::v8_2::tree::LeafNode::getNodeBoundingBox
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition: LeafNode.h:166
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::stealNodes
void stealNodes(ArrayT &, const ValueType &, bool)
Definition: LeafNodeBool.h:523
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cbeginChildOff
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeBool.h:674
openvdb::v8_2::CombineArgs
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: openvdb/Types.h:429
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::evalNodeOrigin
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeBool.h:711
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildAllIter
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeBool.h:646
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
SIMD Intrinsic Headers.
Definition: Platform.h:92
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueOffCIter
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeBool.h:639
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueOnCIter
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeBool.h:637
openvdb::v8_2::util::NodeMask::isOff
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:508
openvdb::v8_2::tree::LeafNode::coordToOffset
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1028
openvdb::v8_2::util::NodeMask::isConstant
bool isConstant(bool &isOn) const
Definition: NodeMasks.h:526
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginValueAll
ValueAllIter beginValueAll()
Definition: LeafNodeBool.h:657
openvdb::v8_2::tree::LeafNode::addTileAndCache
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1599
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isChildMaskOn
bool isChildMaskOn(Index) const
Definition: LeafNodeBool.h:702
openvdb::v8_2::tree::LeafNode::origin
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:172
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::getValue
const bool & getValue() const
Definition: LeafNodeBool.h:586
openvdb::v8_2::tree::LeafBuffer::fill
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:247
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeLeafAndCache
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition: LeafNodeBool.h:538
Iterator.h
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getNodes
void getNodes(ArrayT &) const
Definition: LeafNodeBool.h:522
openvdb::v8_2::tree::LeafNode::copyToDense
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:1222
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::DenseIter::unsetItem
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeBool.h:632
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::DenseIter::getItem
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeBool.h:621
openvdb::v8_2::tree::LeafNode::setValueOff
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:401
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOff
bool isValueMaskOff() const
Definition: LeafNodeBool.h:697
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::modifyValueAndActiveStateAndCache
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeBool.h:363
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153
openvdb::v8_2::tree::LeafNode::ChildAllIter
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:288
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getLastValue
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeBool.h:398
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginValueOff
ValueOffCIter beginValueOff() const
Definition: LeafNodeBool.h:653
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeConstNode
const NodeT * probeConstNode(const Coord &) const
Definition: LeafNodeBool.h:521
openvdb::v8_2::tree::LeafNode::writeTopology
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1294
openvdb::v8_2::tree::LeafNode::fill
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:1179
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeLeaf
LeafNode * probeLeaf(const Coord &)
Definition: LeafNodeBool.h:536
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::mValueMask
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNodeBool.h:726
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueMaskOn
void setValueMaskOn(Index n)
Definition: LeafNodeBool.h:707
openvdb::v8_2::math::operator!=
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:485
openvdb::v8_2::tools::copyToDense
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:421
openvdb::v8_2::tree::LeafNode::combine
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1722
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::onLeafVoxelCount
Index64 onLeafVoxelCount() const
Definition: LeafNodeBool.h:120
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endValueAll
ValueAllCIter endValueAll() const
Definition: LeafNodeBool.h:666
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getValueAndCache
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeBool.h:325
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >
LeafNode specialization for values of type bool that stores both the active states and the values of ...
Definition: LeafNodeBool.h:29
openvdb::v8_2::tree::DenseIteratorBase
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:179
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::DenseIter::DenseIter
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeBool.h:619
openvdb::v8_2::tree::LeafNode::topologyUnion
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition: LeafNode.h:1681
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildAllCIter
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeBool.h:647
openvdb::v8_2::tree::LeafNode::isConstant
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1477
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::probeNodeAndCache
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition: LeafNodeBool.h:540
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::touchLeafAndCache
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition: LeafNodeBool.h:535
openvdb::v8_2::Index32
uint32_t Index32
Definition: openvdb/Types.h:30
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ChildOffIter
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeBool.h:644
openvdb::v8_2::tree::LeafNode::setValueOnly
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition: LeafNode.h:1121
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endChildOff
ChildOffIter endChildOff()
Definition: LeafNodeBool.h:686
openvdb::v8_2::tree::SparseIteratorBase
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:115
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< ValueType, Log2Dim > &other, bool offValue, bool onValue, TopologyCopy)
Topology copy constructor.
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endChildOff
ChildOffCIter endChildOff() const
Definition: LeafNodeBool.h:685
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cendChildAll
ChildAllCIter cendChildAll() const
Definition: LeafNodeBool.h:687
openvdb::v8_2::math::Coord::ValueType
Int32 ValueType
Definition: Coord.h:33
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getOrigin
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition: LeafNodeBool.h:156
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueAllCIter
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeBool.h:641
openvdb::v8_2::util::NodeMask::beginOn
OnIterator beginOn() const
Definition: NodeMasks.h:352
openvdb::v8_2::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:411
openvdb::v8_2::math::CoordBBox::expand
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:418
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getOrigin
void getOrigin(Coord &origin) const
Definition: LeafNodeBool.h:155
openvdb::v8_2::tree::LeafNode::LEVEL
static const Index LEVEL
Definition: LeafNode.h:54
openvdb::v8_2::math::Coord::setZ
Coord & setZ(Int32 z)
Definition: Coord.h:82
openvdb::v8_2::tree::LeafNode::beginChildAll
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:320
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::ValueIter
ValueIter()
Definition: LeafNodeBool.h:582
openvdb::v8_2::tools::clip
GridType::Ptr clip(const GridType &grid, const BBoxd &bbox, bool keepInterior=true)
Clip the given grid against a world-space bounding box and return a new grid containing the result.
Definition: Clip.h:348
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endChildOn
ChildOnCIter endChildOn() const
Definition: LeafNodeBool.h:682
openvdb::v8_2::math::CoordBBox::hasOverlap
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:412
openvdb::v8_2::tree::LeafNode::doVisit
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:1856
openvdb::v8_2::Index64
uint64_t Index64
Definition: openvdb/Types.h:31
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::offLeafVoxelCount
Index64 offLeafVoxelCount() const
Definition: LeafNodeBool.h:121
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other)
Value conversion copy constructor.
openvdb::v8_2::tree::LeafNode::hasSameTopology
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:1469
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::mOrigin
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeBool.h:730
openvdb::v8_2::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:477
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:93
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endChildAll
ChildAllIter endChildAll()
Definition: LeafNodeBool.h:689
openvdb::v8_2::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
openvdb::v8_2::tree::LeafNode::topologyDifference
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node's set of active values with the active values of the other node,...
Definition: LeafNode.h:1698
openvdb::v8_2::tree::SameLeafConfig
Definition: LeafNode.h:912
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endValueOff
ValueOffIter endValueOff()
Definition: LeafNodeBool.h:664
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueOff
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNodeBool.h:229
openvdb::v8_2::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1063
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::offVoxelCount
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeBool.h:119
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginValueAll
ValueAllCIter beginValueAll() const
Definition: LeafNodeBool.h:656
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setValueOff
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNodeBool.h:231
openvdb::v8_2::tree::LeafBuffer::setValue
void setValue(Index i, const ValueType &)
Set the i'th value of this buffer to the specified value.
Definition: LeafBuffer.h:212
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::beginChildOff
ChildOffIter beginChildOff()
Definition: LeafNodeBool.h:676
openvdb::v8_2::util::NodeMask::save
void save(std::ostream &os) const
Definition: NodeMasks.h:565
openvdb::v8_2::tree::LeafNode::evalActiveBoundingBox
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1451
openvdb::v8_2::math::CoordBBox::createCube
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:313
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::endValueOff
ValueOffCIter endValueOff() const
Definition: LeafNodeBool.h:663
openvdb::v8_2::tree::LeafNode
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition: LeafNode.h:38
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeBool.h:652
openvdb
Definition: openvdb/Exceptions.h:13
openvdb::v8_2::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:452
LeafNode.h
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::Ptr
SharedPtr< LeafNodeType > Ptr
Definition: LeafNodeBool.h:36
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::setOrigin
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNodeBool.h:151
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::log2dim
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeBool.h:102
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cendValueOn
ValueOnCIter cendValueOn() const
Definition: LeafNodeBool.h:659
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::cendValueAll
ValueAllCIter cendValueAll() const
Definition: LeafNodeBool.h:665
openvdb::v8_2::tree::LeafNode::combine2
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1762
openvdb::v8_2::tree::LeafNode::medianOn
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition: LeafNode.h:1531
openvdb::v8_2::math::Coord::z
Int32 z() const
Definition: Coord.h:133
openvdb::v8_2::tree::LeafNode::visit2Node
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:1870
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::setValue
void setValue(bool value) const
Definition: LeafNodeBool.h:591
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::valueMask
const NodeMaskType & valueMask() const
Definition: LeafNodeBool.h:699
openvdb::v8_2::tree::LeafNode::merge
void merge(const LeafNode &)
Definition: LeafNode.h:1632
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::getLevel
static Index getLevel()
Definition: LeafNodeBool.h:107
openvdb::v8_2::tree::LeafNode::probeValue
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1079
openvdb::v8_2::PartialCreate
Tag dispatch class that distinguishes constructors during file input.
Definition: openvdb/Types.h:548
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOn
bool isValueMaskOn(Index n) const
Definition: LeafNodeBool.h:694
openvdb::v8_2::util::NodeMask::setOff
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:457
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< ValueType, Log2Dim > &other, TopologyCopy)
Topology copy constructor.
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::isDense
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeBool.h:128
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::operator=
LeafNode & operator=(const LeafNode &)=default
Deep assignment operator.
openvdb::v8_2::io::getGridBackgroundValuePtr
OPENVDB_API const void * getGridBackgroundValuePtr(std::ios_base &)
Return a pointer to the background value of the grid currently being read from or written to the give...
openvdb::v8_2::tree::LeafNode< bool, Log2Dim >::ValueIter::ValueIter
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:583