OpenVDB: LeafNode.h Source File

OpenVDB 8.0.0

LeafNode.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_LEAFNODE_HAS_BEEN_INCLUDED
5 #define OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
6
7 #include <openvdb/Types.h>
8 #include <openvdb/util/NodeMasks.h>
9 #include <openvdb/io/Compression.h> // for io::readData(), etc.
10 #include "Iterator.h"
11 #include "LeafBuffer.h"
12 #include <algorithm> // for std::nth_element()
13 #include <iostream>
14 #include <memory>
15 #include <sstream>
16 #include <string>
17 #include <type_traits>
18 #include <vector>
19
20
21 class TestLeaf;
22 template<typename> class TestLeafIO;
23
24 namespace openvdb {
25 OPENVDB_USE_VERSION_NAMESPACE
26 namespace OPENVDB_VERSION_NAME {
27 namespace tree {
28
29 template<Index, typename> struct SameLeafConfig; // forward declaration
30
31
36 template<typename T, Index Log2Dim>
37 class LeafNode
38 {
39 public:
40 using BuildType = T;
41 using ValueType = T;
42 using Buffer = LeafBuffer<ValueType, Log2Dim>;
43 using LeafNodeType = LeafNode<ValueType, Log2Dim>;
44 using NodeMaskType = util::NodeMask<Log2Dim>;
45 using Ptr = SharedPtr<LeafNode>;
46
47 static const Index
48 LOG2DIM = Log2Dim, // needed by parent nodes
49 TOTAL = Log2Dim, // needed by parent nodes
50 DIM = 1 << TOTAL, // dimension along one coordinate direction
51 NUM_VALUES = 1 << 3 * Log2Dim,
52 NUM_VOXELS = NUM_VALUES, // total number of voxels represented by this node
53 SIZE = NUM_VALUES,
54 LEVEL = 0; // level 0 = leaf
55
58 template<typename OtherValueType>
59 struct ValueConverter { using Type = LeafNode<OtherValueType, Log2Dim>; };
60
63 template<typename OtherNodeType>
64 struct SameConfiguration {
65 static const bool value = SameLeafConfig<LOG2DIM, OtherNodeType>::value;
66 };
67
68
70 LeafNode();
71
76 explicit LeafNode(const Coord& coords,
77 const ValueType& value = zeroVal<ValueType>(),
78 bool active = false);
79
85 LeafNode(PartialCreate,
86 const Coord& coords,
87 const ValueType& value = zeroVal<ValueType>(),
88 bool active = false);
89
91 LeafNode(const LeafNode&);
92
94 LeafNode& operator=(const LeafNode&) = default;
95
97 template<typename OtherValueType>
98 explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
99
101 template<typename OtherValueType>
102 LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
103 const ValueType& offValue, const ValueType& onValue, TopologyCopy);
104
106 template<typename OtherValueType>
107 LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
108 const ValueType& background, TopologyCopy);
109
111 ~LeafNode();
112
113 //
114 // Statistics
115 //
117 static Index log2dim() { return Log2Dim; }
119 static Index dim() { return DIM; }
121 static Index size() { return SIZE; }
123 static Index numValues() { return SIZE; }
125 static Index getLevel() { return LEVEL; }
127 static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
129 static Index getChildDim() { return 1; }
131 static Index32 leafCount() { return 1; }
133 void nodeCount(std::vector<Index32> &) const {}
135 static Index32 nonLeafCount() { return 0; }
137 static Index32 childCount() { return 0; }
138
140 Index64 onVoxelCount() const { return mValueMask.countOn(); }
142 Index64 offVoxelCount() const { return mValueMask.countOff(); }
143 Index64 onLeafVoxelCount() const { return onVoxelCount(); }
144 Index64 offLeafVoxelCount() const { return offVoxelCount(); }
145 static Index64 onTileCount() { return 0; }
146 static Index64 offTileCount() { return 0; }
148 bool isEmpty() const { return mValueMask.isOff(); }
150 bool isDense() const { return mValueMask.isOn(); }
152 bool isAllocated() const { return !mBuffer.isOutOfCore() && !mBuffer.empty(); }
154 bool allocate() { return mBuffer.allocate(); }
155
157 Index64 memUsage() const;
158
162 void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
163
166 CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
167
169 void setOrigin(const Coord& origin) { mOrigin = origin; }
171 const Coord& origin() const { return mOrigin; }
173 void getOrigin(Coord& origin) const { origin = mOrigin; }
174 void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
176
178 static Index coordToOffset(const Coord& xyz);
181 static Coord offsetToLocalCoord(Index n);
183 Coord offsetToGlobalCoord(Index n) const;
184
186 std::string str() const;
187
190 template<typename OtherType, Index OtherLog2Dim>
191 bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
192
194 bool operator==(const LeafNode& other) const;
195 bool operator!=(const LeafNode& other) const { return !(other == *this); }
196
197 protected:
198 using MaskOnIterator = typename NodeMaskType::OnIterator;
199 using MaskOffIterator = typename NodeMaskType::OffIterator;
200 using MaskDenseIterator = typename NodeMaskType::DenseIterator;
201
202 // Type tags to disambiguate template instantiations
203 struct ValueOn {}; struct ValueOff {}; struct ValueAll {};
204 struct ChildOn {}; struct ChildOff {}; struct ChildAll {};
205
206 template<typename MaskIterT, typename NodeT, typename ValueT, typename TagT>
207 struct ValueIter:
208 // Derives from SparseIteratorBase, but can also be used as a dense iterator,
209 // if MaskIterT is a dense mask iterator type.
210 public SparseIteratorBase<
211 MaskIterT, ValueIter<MaskIterT, NodeT, ValueT, TagT>, NodeT, ValueT>
212 {
213 using BaseT = SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT>;
214
215 ValueIter() {}
216 ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
217
218 ValueT& getItem(Index pos) const { return this->parent().getValue(pos); }
219 ValueT& getValue() const { return this->parent().getValue(this->pos()); }
220
221 // Note: setItem() can't be called on const iterators.
222 void setItem(Index pos, const ValueT& value) const
223 {
224 this->parent().setValueOnly(pos, value);
225 }
226 // Note: setValue() can't be called on const iterators.
227 void setValue(const ValueT& value) const
228 {
229 this->parent().setValueOnly(this->pos(), value);
230 }
231
232 // Note: modifyItem() can't be called on const iterators.
233 template<typename ModifyOp>
234 void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
235 // Note: modifyValue() can't be called on const iterators.
236 template<typename ModifyOp>
237 void modifyValue(const ModifyOp& op) const { this->parent().modifyValue(this->pos(), op); }
238 };
239
241 template<typename MaskIterT, typename NodeT, typename TagT>
242 struct ChildIter:
243 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>
244 {
245 ChildIter() {}
246 ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
247 MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>(iter, parent) {}
248 };
249
250 template<typename NodeT, typename ValueT, typename TagT>
251 struct DenseIter: public DenseIteratorBase<
252 MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, /*ChildT=*/void, ValueT>
253 {
254 using BaseT = DenseIteratorBase<MaskDenseIterator, DenseIter, NodeT, void, ValueT>;
255 using NonConstValueT = typename BaseT::NonConstValueType;
256
257 DenseIter() {}
258 DenseIter(const MaskDenseIterator& iter, NodeT* parent): BaseT(iter, parent) {}
259
260 bool getItem(Index pos, void*& child, NonConstValueT& value) const
261 {
262 value = this->parent().getValue(pos);
263 child = nullptr;
264 return false; // no child
265 }
266
267 // Note: setItem() can't be called on const iterators.
268 //void setItem(Index pos, void* child) const {}
269
270 // Note: unsetItem() can't be called on const iterators.
271 void unsetItem(Index pos, const ValueT& value) const
272 {
273 this->parent().setValueOnly(pos, value);
274 }
275 };
276
277 public:
278 using ValueOnIter = ValueIter<MaskOnIterator, LeafNode, const ValueType, ValueOn>;
279 using ValueOnCIter = ValueIter<MaskOnIterator, const LeafNode, const ValueType, ValueOn>;
280 using ValueOffIter = ValueIter<MaskOffIterator, LeafNode, const ValueType, ValueOff>;
281 using ValueOffCIter = ValueIter<MaskOffIterator,const LeafNode,const ValueType,ValueOff>;
282 using ValueAllIter = ValueIter<MaskDenseIterator, LeafNode, const ValueType, ValueAll>;
283 using ValueAllCIter = ValueIter<MaskDenseIterator,const LeafNode,const ValueType,ValueAll>;
284 using ChildOnIter = ChildIter<MaskOnIterator, LeafNode, ChildOn>;
285 using ChildOnCIter = ChildIter<MaskOnIterator, const LeafNode, ChildOn>;
286 using ChildOffIter = ChildIter<MaskOffIterator, LeafNode, ChildOff>;
287 using ChildOffCIter = ChildIter<MaskOffIterator, const LeafNode, ChildOff>;
288 using ChildAllIter = DenseIter<LeafNode, ValueType, ChildAll>;
289 using ChildAllCIter = DenseIter<const LeafNode, const ValueType, ChildAll>;
290
291 ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
292 ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
293 ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
294 ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
295 ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
296 ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
297 ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
298 ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
299 ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
300
301 ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
302 ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
303 ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
304 ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
305 ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
306 ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
307 ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
308 ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
309 ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
310
311 // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
312 // because leaf nodes have no children.
313 ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
314 ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
315 ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
316 ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
317 ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
318 ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
319 ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
320 ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
321 ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
322
323 ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
324 ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
325 ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
326 ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
327 ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
328 ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
329 ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
330 ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
331 ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
332
333 //
334 // Buffer management
335 //
338 void swap(Buffer& other) { mBuffer.swap(other); }
339 const Buffer& buffer() const { return mBuffer; }
340 Buffer& buffer() { return mBuffer; }
341
342 //
343 // I/O methods
344 //
348 void readTopology(std::istream& is, bool fromHalf = false);
352 void writeTopology(std::ostream& os, bool toHalf = false) const;
353
357 void readBuffers(std::istream& is, bool fromHalf = false);
362 void readBuffers(std::istream& is, const CoordBBox& bbox, bool fromHalf = false);
366 void writeBuffers(std::ostream& os, bool toHalf = false) const;
367
368 size_t streamingSize(bool toHalf = false) const;
369
370 //
371 // Accessor methods
372 //
374 const ValueType& getValue(const Coord& xyz) const;
376 const ValueType& getValue(Index offset) const;
377
381 bool probeValue(const Coord& xyz, ValueType& val) const;
385 bool probeValue(Index offset, ValueType& val) const;
386
388 static Index getValueLevel(const Coord&) { return LEVEL; }
389
391 void setActiveState(const Coord& xyz, bool on);
393 void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
394
396 void setValueOnly(const Coord& xyz, const ValueType& val);
398 void setValueOnly(Index offset, const ValueType& val);
399
401 void setValueOff(const Coord& xyz) { mValueMask.setOff(LeafNode::coordToOffset(xyz)); }
403 void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
404
406 void setValueOff(const Coord& xyz, const ValueType& val);
408 void setValueOff(Index offset, const ValueType& val);
409
411 void setValueOn(const Coord& xyz) { mValueMask.setOn(LeafNode::coordToOffset(xyz)); }
413 void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
415 void setValueOn(const Coord& xyz, const ValueType& val) {
416 this->setValueOn(LeafNode::coordToOffset(xyz), val);
417 }
419 void setValue(const Coord& xyz, const ValueType& val) { this->setValueOn(xyz, val); }
421 void setValueOn(Index offset, const ValueType& val) {
422 mBuffer.setValue(offset, val);
423 mValueMask.setOn(offset);
424 }
425
428 template<typename ModifyOp>
429 void modifyValue(Index offset, const ModifyOp& op)
430 {
431 mBuffer.loadValues();
432 if (!mBuffer.empty()) {
433 // in-place modify value
434 ValueType& val = const_cast<ValueType&>(mBuffer[offset]);
435 op(val);
436 mValueMask.setOn(offset);
437 }
438 }
439
442 template<typename ModifyOp>
443 void modifyValue(const Coord& xyz, const ModifyOp& op)
444 {
445 this->modifyValue(this->coordToOffset(xyz), op);
446 }
447
449 template<typename ModifyOp>
450 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
451 {
452 mBuffer.loadValues();
453 if (!mBuffer.empty()) {
454 const Index offset = this->coordToOffset(xyz);
455 bool state = mValueMask.isOn(offset);
456 // in-place modify value
457 ValueType& val = const_cast<ValueType&>(mBuffer[offset]);
458 op(val, state);
459 mValueMask.set(offset, state);
460 }
461 }
462
464 void setValuesOn() { mValueMask.setOn(); }
466 void setValuesOff() { mValueMask.setOff(); }
467
469 bool isValueOn(const Coord& xyz) const {return this->isValueOn(LeafNode::coordToOffset(xyz));}
471 bool isValueOn(Index offset) const { return mValueMask.isOn(offset); }
472
474 static bool hasActiveTiles() { return false; }
475
477 void clip(const CoordBBox&, const ValueType& background);
478
480 void fill(const CoordBBox& bbox, const ValueType&, bool active = true);
482 void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true)
483 {
484 this->fill(bbox, value, active);
485 }
486
488 void fill(const ValueType& value);
490 void fill(const ValueType& value, bool active);
491
503 template<typename DenseT>
504 void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
505
522 template<typename DenseT>
523 void copyFromDense(const CoordBBox& bbox, const DenseT& dense,
524 const ValueType& background, const ValueType& tolerance);
525
528 template<typename AccessorT>
529 const ValueType& getValueAndCache(const Coord& xyz, AccessorT&) const
530 {
531 return this->getValue(xyz);
532 }
533
536 template<typename AccessorT>
537 bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
538
541 template<typename AccessorT>
542 void setValueAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
543 {
544 this->setValueOn(xyz, val);
545 }
546
550 template<typename AccessorT>
551 void setValueOnlyAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
552 {
553 this->setValueOnly(xyz, val);
554 }
555
559 template<typename ModifyOp, typename AccessorT>
560 void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
561 {
562 this->modifyValue(xyz, op);
563 }
564
567 template<typename ModifyOp, typename AccessorT>
568 void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
569 {
570 this->modifyValueAndActiveState(xyz, op);
571 }
572
575 template<typename AccessorT>
576 void setValueOffAndCache(const Coord& xyz, const ValueType& value, AccessorT&)
577 {
578 this->setValueOff(xyz, value);
579 }
580
584 template<typename AccessorT>
585 void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
586 {
587 this->setActiveState(xyz, on);
588 }
589
593 template<typename AccessorT>
594 bool probeValueAndCache(const Coord& xyz, ValueType& val, AccessorT&) const
595 {
596 return this->probeValue(xyz, val);
597 }
598
602 template<typename AccessorT>
603 const ValueType& getValue(const Coord& xyz, bool& state, int& level, AccessorT&) const
604 {
605 const Index offset = this->coordToOffset(xyz);
606 state = mValueMask.isOn(offset);
607 level = LEVEL;
608 return mBuffer[offset];
609 }
610
613 template<typename AccessorT>
614 static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
615
619 const ValueType& getFirstValue() const { return mBuffer[0]; }
621 const ValueType& getLastValue() const { return mBuffer[SIZE - 1]; }
622
625 void resetBackground(const ValueType& oldBackground, const ValueType& newBackground);
626
627 void negate();
628
631 void voxelizeActiveTiles(bool = true) {}
632
633 template<MergePolicy Policy> void merge(const LeafNode&);
634 template<MergePolicy Policy> void merge(const ValueType& tileValue, bool tileActive);
635 template<MergePolicy Policy>
636 void merge(const LeafNode& other, const ValueType& /*bg*/, const ValueType& /*otherBG*/);
637
644 template<typename OtherType>
645 void topologyUnion(const LeafNode<OtherType, Log2Dim>& other);
646
658 template<typename OtherType>
659 void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
660
672 template<typename OtherType>
673 void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
674
675 template<typename CombineOp>
676 void combine(const LeafNode& other, CombineOp& op);
677 template<typename CombineOp>
678 void combine(const ValueType& value, bool valueIsActive, CombineOp& op);
679
680 template<typename CombineOp, typename OtherType /*= ValueType*/>
681 void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
682 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
683 void combine2(const ValueType&, const OtherNodeT& other, bool valueIsActive, CombineOp&);
684 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
685 void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
686
692 template<typename BBoxOp> void visitActiveBBox(BBoxOp&) const;
693
694 template<typename VisitorOp> void visit(VisitorOp&);
695 template<typename VisitorOp> void visit(VisitorOp&) const;
696
697 template<typename OtherLeafNodeType, typename VisitorOp>
698 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
699 template<typename OtherLeafNodeType, typename VisitorOp>
700 void visit2Node(OtherLeafNodeType& other, VisitorOp&) const;
701 template<typename IterT, typename VisitorOp>
702 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false);
703 template<typename IterT, typename VisitorOp>
704 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false) const;
705
707 void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
709 void addLeaf(LeafNode*) {}
710 template<typename AccessorT>
711 void addLeafAndCache(LeafNode*, AccessorT&) {}
712 template<typename NodeT>
713 NodeT* stealNode(const Coord&, const ValueType&, bool) { return nullptr; }
714 template<typename NodeT>
715 NodeT* probeNode(const Coord&) { return nullptr; }
716 template<typename NodeT>
717 const NodeT* probeConstNode(const Coord&) const { return nullptr; }
718 template<typename ArrayT> void getNodes(ArrayT&) const {}
719 template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
721
722 void addTile(Index level, const Coord&, const ValueType&, bool);
723 void addTile(Index offset, const ValueType&, bool);
724 template<typename AccessorT>
725 void addTileAndCache(Index, const Coord&, const ValueType&, bool, AccessorT&);
726
728 LeafNode* touchLeaf(const Coord&) { return this; }
730 template<typename AccessorT>
731 LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
732 template<typename NodeT, typename AccessorT>
733 NodeT* probeNodeAndCache(const Coord&, AccessorT&)
734 {
735 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
736 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
737 return reinterpret_cast<NodeT*>(this);
738 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
739 }
740 LeafNode* probeLeaf(const Coord&) { return this; }
741 template<typename AccessorT>
742 LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
744
745 const LeafNode* probeConstLeaf(const Coord&) const { return this; }
747 template<typename AccessorT>
748 const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
749 template<typename AccessorT>
750 const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
751 const LeafNode* probeLeaf(const Coord&) const { return this; }
752 template<typename NodeT, typename AccessorT>
753 const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
754 {
755 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
756 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
757 return reinterpret_cast<const NodeT*>(this);
758 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
759 }
761
771 bool isConstant(ValueType& firstValue, bool& state,
772 const ValueType& tolerance = zeroVal<ValueType>()) const;
773
785 bool isConstant(ValueType& minValue, ValueType& maxValue,
786 bool& state, const ValueType& tolerance = zeroVal<ValueType>()) const;
787
788
803 ValueType medianAll(ValueType *tmp = nullptr) const;
804
819 Index medianOn(ValueType &value, ValueType *tmp = nullptr) const;
820
835 Index medianOff(ValueType &value, ValueType *tmp = nullptr) const;
836
838 bool isInactive() const { return mValueMask.isOff(); }
839
840 protected:
841 friend class ::TestLeaf;
842 template<typename> friend class ::TestLeafIO;
843
844 // During topology-only construction, access is needed
845 // to protected/private members of other template instances.
846 template<typename, Index> friend class LeafNode;
847
848 friend struct ValueIter<MaskOnIterator, LeafNode, ValueType, ValueOn>;
849 friend struct ValueIter<MaskOffIterator, LeafNode, ValueType, ValueOff>;
850 friend struct ValueIter<MaskDenseIterator, LeafNode, ValueType, ValueAll>;
851 friend struct ValueIter<MaskOnIterator, const LeafNode, ValueType, ValueOn>;
852 friend struct ValueIter<MaskOffIterator, const LeafNode, ValueType, ValueOff>;
853 friend struct ValueIter<MaskDenseIterator, const LeafNode, ValueType, ValueAll>;
854
855 // Allow iterators to call mask accessor methods (see below).
857 friend class IteratorBase<MaskOnIterator, LeafNode>;
858 friend class IteratorBase<MaskOffIterator, LeafNode>;
859 friend class IteratorBase<MaskDenseIterator, LeafNode>;
860
861 // Mask accessors
862 public:
863 bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
864 bool isValueMaskOn() const { return mValueMask.isOn(); }
865 bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
866 bool isValueMaskOff() const { return mValueMask.isOff(); }
867 const NodeMaskType& getValueMask() const { return mValueMask; }
868 NodeMaskType& getValueMask() { return mValueMask; }
869 const NodeMaskType& valueMask() const { return mValueMask; }
870 void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
871 bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
872 bool isChildMaskOff(Index) const { return true; }
873 bool isChildMaskOff() const { return true; }
874 protected:
875 void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
876 void setValueMaskOn(Index n) { mValueMask.setOn(n); }
877 void setValueMaskOff(Index n) { mValueMask.setOff(n); }
878
879 inline void skipCompressedValues(bool seekable, std::istream&, bool fromHalf);
880
882 static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
883
884 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
885 static inline void doVisit(NodeT&, VisitorOp&);
886
887 template<typename NodeT, typename OtherNodeT, typename VisitorOp,
888 typename ChildAllIterT, typename OtherChildAllIterT>
889 static inline void doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp&);
890
891 template<typename NodeT, typename VisitorOp,
892 typename ChildAllIterT, typename OtherChildAllIterT>
893 static inline void doVisit2(NodeT& self, OtherChildAllIterT&, VisitorOp&, bool otherIsLHS);
894
895 private:
897 Buffer mBuffer;
899 NodeMaskType mValueMask;
901 Coord mOrigin;
902 }; // end of LeafNode class
903
904
906
907
909 template<Index Dim1, typename NodeT2>
912 struct SameLeafConfig { static const bool value = false; };
913
914 template<Index Dim1, typename T2>
915 struct SameLeafConfig<Dim1, LeafNode<T2, Dim1> > { static const bool value = true; };
917
918
920
921
922 template<typename T, Index Log2Dim>
923 inline
924 LeafNode<T, Log2Dim>::LeafNode():
925 mValueMask(),//default is off!
926 mOrigin(0, 0, 0)
927 {
928 }
929
930
931 template<typename T, Index Log2Dim>
932 inline
933 LeafNode<T, Log2Dim>::LeafNode(const Coord& xyz, const ValueType& val, bool active):
934 mBuffer(val),
935 mValueMask(active),
936 mOrigin(xyz & (~(DIM - 1)))
937 {
938 }
939
940
941 template<typename T, Index Log2Dim>
942 inline
943 LeafNode<T, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, const ValueType& val, bool active):
944 mBuffer(PartialCreate(), val),
945 mValueMask(active),
946 mOrigin(xyz & (~(DIM - 1)))
947 {
948 }
949
950
951 template<typename T, Index Log2Dim>
952 inline
953 LeafNode<T, Log2Dim>::LeafNode(const LeafNode& other):
954 mBuffer(other.mBuffer),
955 mValueMask(other.valueMask()),
956 mOrigin(other.mOrigin)
957 {
958 }
959
960
961 // Copy-construct from a leaf node with the same configuration but a different ValueType.
962 template<typename T, Index Log2Dim>
963 template<typename OtherValueType>
964 inline
965 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other):
966 mValueMask(other.valueMask()),
967 mOrigin(other.mOrigin)
968 {
969 struct Local {
971 static inline ValueType convertValue(const OtherValueType& val) { return ValueType(val); }
972 };
973
974 for (Index i = 0; i < SIZE; ++i) {
975 mBuffer[i] = Local::convertValue(other.mBuffer[i]);
976 }
977 }
978
979
980 template<typename T, Index Log2Dim>
981 template<typename OtherValueType>
982 inline
983 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
984 const ValueType& background, TopologyCopy):
985 mBuffer(background),
986 mValueMask(other.valueMask()),
987 mOrigin(other.mOrigin)
988 {
989 }
990
991
992 template<typename T, Index Log2Dim>
993 template<typename OtherValueType>
994 inline
995 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
996 const ValueType& offValue, const ValueType& onValue, TopologyCopy):
997 mValueMask(other.valueMask()),
998 mOrigin(other.mOrigin)
999 {
1000 for (Index i = 0; i < SIZE; ++i) {
1001 mBuffer[i] = (mValueMask.isOn(i) ? onValue : offValue);
1002 }
1003 }
1004
1005
1006 template<typename T, Index Log2Dim>
1007 inline
1008 LeafNode<T, Log2Dim>::~LeafNode()
1009 {
1010 }
1011
1012
1013 template<typename T, Index Log2Dim>
1014 inline std::string
1015 LeafNode<T, Log2Dim>::str() const
1016 {
1017 std::ostringstream ostr;
1018 ostr << "LeafNode @" << mOrigin << ": " << mBuffer;
1019 return ostr.str();
1020 }
1021
1022
1024
1025
1026 template<typename T, Index Log2Dim>
1027 inline Index
1028 LeafNode<T, Log2Dim>::coordToOffset(const Coord& xyz)
1029 {
1030 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
1031 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
1032 + ((xyz[1] & (DIM-1u)) << Log2Dim)
1033 + (xyz[2] & (DIM-1u));
1034 }
1035
1036 template<typename T, Index Log2Dim>
1037 inline Coord
1038 LeafNode<T, Log2Dim>::offsetToLocalCoord(Index n)
1039 {
1040 assert(n<(1<< 3*Log2Dim));
1041 Coord xyz;
1042 xyz.setX(n >> 2*Log2Dim);
1043 n &= ((1<<2*Log2Dim)-1);
1044 xyz.setY(n >> Log2Dim);
1045 xyz.setZ(n & ((1<<Log2Dim)-1));
1046 return xyz;
1047 }
1048
1049
1050 template<typename T, Index Log2Dim>
1051 inline Coord
1052 LeafNode<T, Log2Dim>::offsetToGlobalCoord(Index n) const
1053 {
1054 return (this->offsetToLocalCoord(n) + this->origin());
1055 }
1056
1057
1059
1060
1061 template<typename ValueT, Index Log2Dim>
1062 inline const ValueT&
1063 LeafNode<ValueT, Log2Dim>::getValue(const Coord& xyz) const
1064 {
1065 return this->getValue(LeafNode::coordToOffset(xyz));
1066 }
1067
1068 template<typename ValueT, Index Log2Dim>
1069 inline const ValueT&
1070 LeafNode<ValueT, Log2Dim>::getValue(Index offset) const
1071 {
1072 assert(offset < SIZE);
1073 return mBuffer[offset];
1074 }
1075
1076
1077 template<typename T, Index Log2Dim>
1078 inline bool
1079 LeafNode<T, Log2Dim>::probeValue(const Coord& xyz, ValueType& val) const
1080 {
1081 return this->probeValue(LeafNode::coordToOffset(xyz), val);
1082 }
1083
1084 template<typename T, Index Log2Dim>
1085 inline bool
1086 LeafNode<T, Log2Dim>::probeValue(Index offset, ValueType& val) const
1087 {
1088 assert(offset < SIZE);
1089 val = mBuffer[offset];
1090 return mValueMask.isOn(offset);
1091 }
1092
1093
1094 template<typename T, Index Log2Dim>
1095 inline void
1096 LeafNode<T, Log2Dim>::setValueOff(const Coord& xyz, const ValueType& val)
1097 {
1098 this->setValueOff(LeafNode::coordToOffset(xyz), val);
1099 }
1100
1101 template<typename T, Index Log2Dim>
1102 inline void
1103 LeafNode<T, Log2Dim>::setValueOff(Index offset, const ValueType& val)
1104 {
1105 assert(offset < SIZE);
1106 mBuffer.setValue(offset, val);
1107 mValueMask.setOff(offset);
1108 }
1109
1110
1111 template<typename T, Index Log2Dim>
1112 inline void
1113 LeafNode<T, Log2Dim>::setActiveState(const Coord& xyz, bool on)
1114 {
1115 mValueMask.set(this->coordToOffset(xyz), on);
1116 }
1117
1118
1119 template<typename T, Index Log2Dim>
1120 inline void
1121 LeafNode<T, Log2Dim>::setValueOnly(const Coord& xyz, const ValueType& val)
1122 {
1123 this->setValueOnly(LeafNode::coordToOffset(xyz), val);
1124 }
1125
1126 template<typename T, Index Log2Dim>
1127 inline void
1128 LeafNode<T, Log2Dim>::setValueOnly(Index offset, const ValueType& val)
1129 {
1130 assert(offset<SIZE); mBuffer.setValue(offset, val);
1131 }
1132
1133
1135
1136
1137 template<typename T, Index Log2Dim>
1138 inline void
1139 LeafNode<T, Log2Dim>::clip(const CoordBBox& clipBBox, const T& background)
1140 {
1141 CoordBBox nodeBBox = this->getNodeBoundingBox();
1142 if (!clipBBox.hasOverlap(nodeBBox)) {
1143 // This node lies completely outside the clipping region. Fill it with the background.
1144 this->fill(background, /*active=*/false);
1145 } else if (clipBBox.isInside(nodeBBox)) {
1146 // This node lies completely inside the clipping region. Leave it intact.
1147 return;
1148 }
1149
1150 // This node isn't completely contained inside the clipping region.
1151 // Set any voxels that lie outside the region to the background value.
1152
1153 // Construct a boolean mask that is on inside the clipping region and off outside it.
1154 NodeMaskType mask;
1155 nodeBBox.intersect(clipBBox);
1156 Coord xyz;
1157 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1158 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1159 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1160 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1161 mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1162 }
1163 }
1164 }
1165
1166 // Set voxels that lie in the inactive region of the mask (i.e., outside
1167 // the clipping region) to the background value.
1168 for (MaskOffIterator maskIter = mask.beginOff(); maskIter; ++maskIter) {
1169 this->setValueOff(maskIter.pos(), background);
1170 }
1171 }
1172
1173
1175
1176
1177 template<typename T, Index Log2Dim>
1178 inline void
1179 LeafNode<T, Log2Dim>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1180 {
1181 if (!this->allocate()) return;
1182
1183 auto clippedBBox = this->getNodeBoundingBox();
1184 clippedBBox.intersect(bbox);
1185 if (!clippedBBox) return;
1186
1187 for (Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1188 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1189 for (Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1190 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1191 for (Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1192 const Index offset = offsetXY + (z & (DIM-1u));
1193 mBuffer[offset] = value;
1194 mValueMask.set(offset, active);
1195 }
1196 }
1197 }
1198 }
1199
1200 template<typename T, Index Log2Dim>
1201 inline void
1202 LeafNode<T, Log2Dim>::fill(const ValueType& value)
1203 {
1204 mBuffer.fill(value);
1205 }
1206
1207 template<typename T, Index Log2Dim>
1208 inline void
1209 LeafNode<T, Log2Dim>::fill(const ValueType& value, bool active)
1210 {
1211 mBuffer.fill(value);
1212 mValueMask.set(active);
1213 }
1214
1215
1217
1218
1219 template<typename T, Index Log2Dim>
1220 template<typename DenseT>
1221 inline void
1222 LeafNode<T, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1223 {
1224 mBuffer.loadValues();
1225
1226 using DenseValueType = typename DenseT::ValueType;
1227
1228 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1229 const Coord& min = dense.bbox().min();
1230 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1231 const T* s0 = &mBuffer[bbox.min()[2] & (DIM-1u)]; // source array
1232 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1233 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1234 const T* s1 = s0 + ((x & (DIM-1u)) << 2*Log2Dim);
1235 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1236 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1237 const T* s2 = s1 + ((y & (DIM-1u)) << Log2Dim);
1238 for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1239 *t2 = DenseValueType(*s2++);
1240 }
1241 }
1242 }
1243 }
1244
1245
1246 template<typename T, Index Log2Dim>
1247 template<typename DenseT>
1248 inline void
1249 LeafNode<T, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1250 const ValueType& background, const ValueType& tolerance)
1251 {
1252 if (!this->allocate()) return;
1253
1254 using DenseValueType = typename DenseT::ValueType;
1255
1256 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1257 const Coord& min = dense.bbox().min();
1258
1259 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1260 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1261 for (Int32 x = bbox.min()[0], ex = bbox.max()[0]+1; x < ex; ++x) {
1262 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1263 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1264 for (Int32 y = bbox.min()[1], ey = bbox.max()[1]+1; y < ey; ++y) {
1265 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1266 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1267 for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1268 if (math::isApproxEqual(background, ValueType(*s2), tolerance)) {
1269 mValueMask.setOff(n2);
1270 mBuffer[n2] = background;
1271 } else {
1272 mValueMask.setOn(n2);
1273 mBuffer[n2] = ValueType(*s2);
1274 }
1275 }
1276 }
1277 }
1278 }
1279
1280
1282
1283
1284 template<typename T, Index Log2Dim>
1285 inline void
1286 LeafNode<T, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
1287 {
1288 mValueMask.load(is);
1289 }
1290
1291
1292 template<typename T, Index Log2Dim>
1293 inline void
1294 LeafNode<T, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
1295 {
1296 mValueMask.save(os);
1297 }
1298
1299
1301
1302
1303
1304 template<typename T, Index Log2Dim>
1305 inline void
1306 LeafNode<T,Log2Dim>::skipCompressedValues(bool seekable, std::istream& is, bool fromHalf)
1307 {
1308 if (seekable) {
1309 // Seek over voxel values.
1310 io::readCompressedValues<ValueType, NodeMaskType>(
1311 is, nullptr, SIZE, mValueMask, fromHalf);
1312 } else {
1313 // Read and discard voxel values.
1314 Buffer temp;
1315 io::readCompressedValues(is, temp.mData, SIZE, mValueMask, fromHalf);
1316 }
1317 }
1318
1319
1320 template<typename T, Index Log2Dim>
1321 inline void
1322 LeafNode<T,Log2Dim>::readBuffers(std::istream& is, bool fromHalf)
1323 {
1324 this->readBuffers(is, CoordBBox::inf(), fromHalf);
1325 }
1326
1327
1328 template<typename T, Index Log2Dim>
1329 inline void
1330 LeafNode<T,Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
1331 {
1332 SharedPtr<io::StreamMetadata> meta = io::getStreamMetadataPtr(is);
1333 const bool seekable = meta && meta->seekable();
1334
1335 std::streamoff maskpos = is.tellg();
1336
1337 if (seekable) {
1338 // Seek over the value mask.
1339 mValueMask.seek(is);
1340 } else {
1341 // Read in the value mask.
1342 mValueMask.load(is);
1343 }
1344
1345 int8_t numBuffers = 1;
1346 if (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
1347 // Read in the origin.
1348 is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1349
1350 // Read in the number of buffers, which should now always be one.
1351 is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1352 }
1353
1354 CoordBBox nodeBBox = this->getNodeBoundingBox();
1355 if (!clipBBox.hasOverlap(nodeBBox)) {
1356 // This node lies completely outside the clipping region.
1357 skipCompressedValues(seekable, is, fromHalf);
1358 mValueMask.setOff();
1359 mBuffer.setOutOfCore(false);
1360 } else {
1361 // If this node lies completely inside the clipping region and it is being read
1362 // from a memory-mapped file, delay loading of its buffer until the buffer
1363 // is actually accessed. (If this node requires clipping, its buffer
1364 // must be accessed and therefore must be loaded.)
1365 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is);
1366 const bool delayLoad = ((mappedFile.get() != nullptr) && clipBBox.isInside(nodeBBox));
1367
1368 if (delayLoad) {
1369 mBuffer.setOutOfCore(true);
1370 mBuffer.mFileInfo = new typename Buffer::FileInfo;
1371 mBuffer.mFileInfo->meta = meta;
1372 mBuffer.mFileInfo->bufpos = is.tellg();
1373 mBuffer.mFileInfo->mapping = mappedFile;
1374 // Save the offset to the value mask, because the in-memory copy
1375 // might change before the value buffer gets read.
1376 mBuffer.mFileInfo->maskpos = maskpos;
1377 // Skip over voxel values.
1378 skipCompressedValues(seekable, is, fromHalf);
1379 } else {
1380 mBuffer.allocate();
1381 io::readCompressedValues(is, mBuffer.mData, SIZE, mValueMask, fromHalf);
1382 mBuffer.setOutOfCore(false);
1383
1384 // Get this tree's background value.
1385 T background = zeroVal<T>();
1386 if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
1387 background = *static_cast<const T*>(bgPtr);
1388 }
1389 this->clip(clipBBox, background);
1390 }
1391 }
1392
1393 if (numBuffers > 1) {
1394 // Read in and discard auxiliary buffers that were created with earlier
1395 // versions of the library. (Auxiliary buffers are not mask compressed.)
1396 const bool zipped = io::getDataCompression(is) & io::COMPRESS_ZIP;
1397 Buffer temp;
1398 for (int i = 1; i < numBuffers; ++i) {
1399 if (fromHalf) {
1400 io::HalfReader<io::RealToHalf<T>::isReal, T>::read(is, temp.mData, SIZE, zipped);
1401 } else {
1402 io::readData<T>(is, temp.mData, SIZE, zipped);
1403 }
1404 }
1405 }
1406
1407 // increment the leaf number
1408 if (meta) meta->setLeaf(meta->leaf() + 1);
1409 }
1410
1411
1412 template<typename T, Index Log2Dim>
1413 inline void
1414 LeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
1415 {
1416 // Write out the value mask.
1417 mValueMask.save(os);
1418
1419 mBuffer.loadValues();
1420
1421 io::writeCompressedValues(os, mBuffer.mData, SIZE,
1422 mValueMask, /*childMask=*/NodeMaskType(), toHalf);
1423 }
1424
1425
1427
1428
1429 template<typename T, Index Log2Dim>
1430 inline bool
1431 LeafNode<T, Log2Dim>::operator==(const LeafNode& other) const
1432 {
1433 return mOrigin == other.mOrigin &&
1434 mValueMask == other.valueMask() &&
1435 mBuffer == other.mBuffer;
1436 }
1437
1438
1439 template<typename T, Index Log2Dim>
1440 inline Index64
1441 LeafNode<T, Log2Dim>::memUsage() const
1442 {
1443 // Use sizeof(*this) to capture alignment-related padding
1444 // (but note that sizeof(*this) includes sizeof(mBuffer)).
1445 return sizeof(*this) + mBuffer.memUsage() - sizeof(mBuffer);
1446 }
1447
1448
1449 template<typename T, Index Log2Dim>
1450 inline void
1451 LeafNode<T, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
1452 {
1453 CoordBBox this_bbox = this->getNodeBoundingBox();
1454 if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
1455 if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
1456 if (visitVoxels) {//use voxel granularity?
1457 this_bbox.reset();
1458 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
1459 this_bbox.translate(this->origin());
1460 }
1461 bbox.expand(this_bbox);
1462 }
1463 }
1464
1465
1466 template<typename T, Index Log2Dim>
1467 template<typename OtherType, Index OtherLog2Dim>
1468 inline bool
1469 LeafNode<T, Log2Dim>::hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const
1470 {
1471 assert(other);
1472 return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
1473 }
1474
1475 template<typename T, Index Log2Dim>
1476 inline bool
1477 LeafNode<T, Log2Dim>::isConstant(ValueType& firstValue,
1478 bool& state,
1479 const ValueType& tolerance) const
1480 {
1481 if (!mValueMask.isConstant(state)) return false;// early termination
1482 firstValue = mBuffer[0];
1483 for (Index i = 1; i < SIZE; ++i) {
1484 if ( !math::isApproxEqual(mBuffer[i], firstValue, tolerance) ) return false;// early termination
1485 }
1486 return true;
1487 }
1488
1489 template<typename T, Index Log2Dim>
1490 inline bool
1491 LeafNode<T, Log2Dim>::isConstant(ValueType& minValue,
1492 ValueType& maxValue,
1493 bool& state,
1494 const ValueType& tolerance) const
1495 {
1496 if (!mValueMask.isConstant(state)) return false;// early termination
1497 minValue = maxValue = mBuffer[0];
1498 for (Index i = 1; i < SIZE; ++i) {
1499 const T& v = mBuffer[i];
1500 if (v < minValue) {
1501 if ((maxValue - v) > tolerance) return false;// early termination
1502 minValue = v;
1503 } else if (v > maxValue) {
1504 if ((v - minValue) > tolerance) return false;// early termination
1505 maxValue = v;
1506 }
1507 }
1508 return true;
1509 }
1510
1511 template<typename T, Index Log2Dim>
1512 inline T
1513 LeafNode<T, Log2Dim>::medianAll(T *tmp) const
1514 {
1515 std::unique_ptr<T[]> data(nullptr);
1516 if (tmp == nullptr) {//allocate temporary storage
1517 data.reset(new T[NUM_VALUES]);
1518 tmp = data.get();
1519 }
1520 if (tmp != mBuffer.data()) {
1521 const T* src = mBuffer.data();
1522 for (T* dst = tmp; dst-tmp < NUM_VALUES;) *dst++ = *src++;
1523 }
1524 static const size_t midpoint = (NUM_VALUES - 1) >> 1;
1525 std::nth_element(tmp, tmp + midpoint, tmp + NUM_VALUES);
1526 return tmp[midpoint];
1527 }
1528
1529 template<typename T, Index Log2Dim>
1530 inline Index
1531 LeafNode<T, Log2Dim>::medianOn(T &value, T *tmp) const
1532 {
1533 const Index count = mValueMask.countOn();
1534 if (count == NUM_VALUES) {//special case: all voxels are active
1535 value = this->medianAll(tmp);
1536 return NUM_VALUES;
1537 } else if (count == 0) {
1538 return 0;
1539 }
1540 std::unique_ptr<T[]> data(nullptr);
1541 if (tmp == nullptr) {//allocate temporary storage
1542 data.reset(new T[count]);// 0 < count < NUM_VALUES
1543 tmp = data.get();
1544 }
1545 for (auto iter=this->cbeginValueOn(); iter; ++iter) *tmp++ = *iter;
1546 T *begin = tmp - count;
1547 const size_t midpoint = (count - 1) >> 1;
1548 std::nth_element(begin, begin + midpoint, tmp);
1549 value = begin[midpoint];
1550 return count;
1551 }
1552
1553 template<typename T, Index Log2Dim>
1554 inline Index
1555 LeafNode<T, Log2Dim>::medianOff(T &value, T *tmp) const
1556 {
1557 const Index count = mValueMask.countOff();
1558 if (count == NUM_VALUES) {//special case: all voxels are inactive
1559 value = this->medianAll(tmp);
1560 return NUM_VALUES;
1561 } else if (count == 0) {
1562 return 0;
1563 }
1564 std::unique_ptr<T[]> data(nullptr);
1565 if (tmp == nullptr) {//allocate temporary storage
1566 data.reset(new T[count]);// 0 < count < NUM_VALUES
1567 tmp = data.get();
1568 }
1569 for (auto iter=this->cbeginValueOff(); iter; ++iter) *tmp++ = *iter;
1570 T *begin = tmp - count;
1571 const size_t midpoint = (count - 1) >> 1;
1572 std::nth_element(begin, begin + midpoint, tmp);
1573 value = begin[midpoint];
1574 return count;
1575 }
1576
1578
1579
1580 template<typename T, Index Log2Dim>
1581 inline void
1582 LeafNode<T, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, const ValueType& val, bool active)
1583 {
1584 this->addTile(this->coordToOffset(xyz), val, active);
1585 }
1586
1587 template<typename T, Index Log2Dim>
1588 inline void
1589 LeafNode<T, Log2Dim>::addTile(Index offset, const ValueType& val, bool active)
1590 {
1591 assert(offset < SIZE);
1592 setValueOnly(offset, val);
1593 setActiveState(offset, active);
1594 }
1595
1596 template<typename T, Index Log2Dim>
1597 template<typename AccessorT>
1598 inline void
1599 LeafNode<T, Log2Dim>::addTileAndCache(Index level, const Coord& xyz,
1600 const ValueType& val, bool active, AccessorT&)
1601 {
1602 this->addTile(level, xyz, val, active);
1603 }
1604
1605
1607
1608
1609 template<typename T, Index Log2Dim>
1610 inline void
1611 LeafNode<T, Log2Dim>::resetBackground(const ValueType& oldBackground,
1612 const ValueType& newBackground)
1613 {
1614 if (!this->allocate()) return;
1615
1616 typename NodeMaskType::OffIterator iter;
1617 // For all inactive values...
1618 for (iter = this->mValueMask.beginOff(); iter; ++iter) {
1619 ValueType &inactiveValue = mBuffer[iter.pos()];
1620 if (math::isApproxEqual(inactiveValue, oldBackground)) {
1621 inactiveValue = newBackground;
1622 } else if (math::isApproxEqual(inactiveValue, math::negative(oldBackground))) {
1623 inactiveValue = math::negative(newBackground);
1624 }
1625 }
1626 }
1627
1628
1629 template<typename T, Index Log2Dim>
1630 template<MergePolicy Policy>
1631 inline void
1632 LeafNode<T, Log2Dim>::merge(const LeafNode& other)
1633 {
1634 if (!this->allocate()) return;
1635
1636 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1637 if (Policy == MERGE_NODES) return;
1638 typename NodeMaskType::OnIterator iter = other.valueMask().beginOn();
1639 for (; iter; ++iter) {
1640 const Index n = iter.pos();
1641 if (mValueMask.isOff(n)) {
1642 mBuffer[n] = other.mBuffer[n];
1643 mValueMask.setOn(n);
1644 }
1645 }
1646 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1647 }
1648
1649 template<typename T, Index Log2Dim>
1650 template<MergePolicy Policy>
1651 inline void
1652 LeafNode<T, Log2Dim>::merge(const LeafNode& other,
1653 const ValueType& /*bg*/, const ValueType& /*otherBG*/)
1654 {
1655 this->template merge<Policy>(other);
1656 }
1657
1658 template<typename T, Index Log2Dim>
1659 template<MergePolicy Policy>
1660 inline void
1661 LeafNode<T, Log2Dim>::merge(const ValueType& tileValue, bool tileActive)
1662 {
1663 if (!this->allocate()) return;
1664
1665 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1666 if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1667 if (!tileActive) return;
1668 // Replace all inactive values with the active tile value.
1669 for (typename NodeMaskType::OffIterator iter = mValueMask.beginOff(); iter; ++iter) {
1670 const Index n = iter.pos();
1671 mBuffer[n] = tileValue;
1672 mValueMask.setOn(n);
1673 }
1674 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1675 }
1676
1677
1678 template<typename T, Index Log2Dim>
1679 template<typename OtherType>
1680 inline void
1681 LeafNode<T, Log2Dim>::topologyUnion(const LeafNode<OtherType, Log2Dim>& other)
1682 {
1683 mValueMask |= other.valueMask();
1684 }
1685
1686 template<typename T, Index Log2Dim>
1687 template<typename OtherType>
1688 inline void
1689 LeafNode<T, Log2Dim>::topologyIntersection(const LeafNode<OtherType, Log2Dim>& other,
1690 const ValueType&)
1691 {
1692 mValueMask &= other.valueMask();
1693 }
1694
1695 template<typename T, Index Log2Dim>
1696 template<typename OtherType>
1697 inline void
1698 LeafNode<T, Log2Dim>::topologyDifference(const LeafNode<OtherType, Log2Dim>& other,
1699 const ValueType&)
1700 {
1701 mValueMask &= !other.valueMask();
1702 }
1703
1704 template<typename T, Index Log2Dim>
1705 inline void
1706 LeafNode<T, Log2Dim>::negate()
1707 {
1708 if (!this->allocate()) return;
1709
1710 for (Index i = 0; i < SIZE; ++i) {
1711 mBuffer[i] = -mBuffer[i];
1712 }
1713 }
1714
1715
1717
1718
1719 template<typename T, Index Log2Dim>
1720 template<typename CombineOp>
1721 inline void
1722 LeafNode<T, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1723 {
1724 if (!this->allocate()) return;
1725
1726 CombineArgs<T> args;
1727 for (Index i = 0; i < SIZE; ++i) {
1728 op(args.setARef(mBuffer[i])
1729 .setAIsActive(mValueMask.isOn(i))
1730 .setBRef(other.mBuffer[i])
1731 .setBIsActive(other.valueMask().isOn(i))
1732 .setResultRef(mBuffer[i]));
1733 mValueMask.set(i, args.resultIsActive());
1734 }
1735 }
1736
1737
1738 template<typename T, Index Log2Dim>
1739 template<typename CombineOp>
1740 inline void
1741 LeafNode<T, Log2Dim>::combine(const ValueType& value, bool valueIsActive, CombineOp& op)
1742 {
1743 if (!this->allocate()) return;
1744
1745 CombineArgs<T> args;
1746 args.setBRef(value).setBIsActive(valueIsActive);
1747 for (Index i = 0; i < SIZE; ++i) {
1748 op(args.setARef(mBuffer[i])
1749 .setAIsActive(mValueMask.isOn(i))
1750 .setResultRef(mBuffer[i]));
1751 mValueMask.set(i, args.resultIsActive());
1752 }
1753 }
1754
1755
1757
1758
1759 template<typename T, Index Log2Dim>
1760 template<typename CombineOp, typename OtherType>
1761 inline void
1762 LeafNode<T, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1763 bool valueIsActive, CombineOp& op)
1764 {
1765 if (!this->allocate()) return;
1766
1767 CombineArgs<T, OtherType> args;
1768 args.setBRef(value).setBIsActive(valueIsActive);
1769 for (Index i = 0; i < SIZE; ++i) {
1770 op(args.setARef(other.mBuffer[i])
1771 .setAIsActive(other.valueMask().isOn(i))
1772 .setResultRef(mBuffer[i]));
1773 mValueMask.set(i, args.resultIsActive());
1774 }
1775 }
1776
1777
1778 template<typename T, Index Log2Dim>
1779 template<typename CombineOp, typename OtherNodeT>
1780 inline void
1781 LeafNode<T, Log2Dim>::combine2(const ValueType& value, const OtherNodeT& other,
1782 bool valueIsActive, CombineOp& op)
1783 {
1784 if (!this->allocate()) return;
1785
1786 CombineArgs<T, typename OtherNodeT::ValueType> args;
1787 args.setARef(value).setAIsActive(valueIsActive);
1788 for (Index i = 0; i < SIZE; ++i) {
1789 op(args.setBRef(other.mBuffer[i])
1790 .setBIsActive(other.valueMask().isOn(i))
1791 .setResultRef(mBuffer[i]));
1792 mValueMask.set(i, args.resultIsActive());
1793 }
1794 }
1795
1796
1797 template<typename T, Index Log2Dim>
1798 template<typename CombineOp, typename OtherNodeT>
1799 inline void
1800 LeafNode<T, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1801 {
1802 if (!this->allocate()) return;
1803
1804 CombineArgs<T, typename OtherNodeT::ValueType> args;
1805 for (Index i = 0; i < SIZE; ++i) {
1806 mValueMask.set(i, b0.valueMask().isOn(i) || b1.valueMask().isOn(i));
1807 op(args.setARef(b0.mBuffer[i])
1808 .setAIsActive(b0.valueMask().isOn(i))
1809 .setBRef(b1.mBuffer[i])
1810 .setBIsActive(b1.valueMask().isOn(i))
1811 .setResultRef(mBuffer[i]));
1812 mValueMask.set(i, args.resultIsActive());
1813 }
1814 }
1815
1816
1818
1819
1820 template<typename T, Index Log2Dim>
1821 template<typename BBoxOp>
1822 inline void
1823 LeafNode<T, Log2Dim>::visitActiveBBox(BBoxOp& op) const
1824 {
1825 if (op.template descent<LEVEL>()) {
1826 for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
1827 op.template operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1828 }
1829 } else {
1830 op.template operator()<LEVEL>(this->getNodeBoundingBox());
1831 }
1832 }
1833
1834
1835 template<typename T, Index Log2Dim>
1836 template<typename VisitorOp>
1837 inline void
1838 LeafNode<T, Log2Dim>::visit(VisitorOp& op)
1839 {
1840 doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
1841 }
1842
1843
1844 template<typename T, Index Log2Dim>
1845 template<typename VisitorOp>
1846 inline void
1847 LeafNode<T, Log2Dim>::visit(VisitorOp& op) const
1848 {
1849 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
1850 }
1851
1852
1853 template<typename T, Index Log2Dim>
1854 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1855 inline void
1856 LeafNode<T, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
1857 {
1858 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1859 op(iter);
1860 }
1861 }
1862
1863
1865
1866
1867 template<typename T, Index Log2Dim>
1868 template<typename OtherLeafNodeType, typename VisitorOp>
1869 inline void
1870 LeafNode<T, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
1871 {
1872 doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
1873 typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
1874 }
1875
1876
1877 template<typename T, Index Log2Dim>
1878 template<typename OtherLeafNodeType, typename VisitorOp>
1879 inline void
1880 LeafNode<T, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
1881 {
1882 doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
1883 typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
1884 }
1885
1886
1887 template<typename T, Index Log2Dim>
1888 template<
1889 typename NodeT,
1890 typename OtherNodeT,
1891 typename VisitorOp,
1892 typename ChildAllIterT,
1893 typename OtherChildAllIterT>
1894 inline void
1895 LeafNode<T, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
1896 {
1897 // Allow the two nodes to have different ValueTypes, but not different dimensions.
1898 static_assert(OtherNodeT::SIZE == NodeT::SIZE,
1899 "can't visit nodes of different sizes simultaneously");
1900 static_assert(OtherNodeT::LEVEL == NodeT::LEVEL,
1901 "can't visit nodes at different tree levels simultaneously");
1902
1903 ChildAllIterT iter = self.beginChildAll();
1904 OtherChildAllIterT otherIter = other.beginChildAll();
1905
1906 for ( ; iter && otherIter; ++iter, ++otherIter) {
1907 op(iter, otherIter);
1908 }
1909 }
1910
1911
1913
1914
1915 template<typename T, Index Log2Dim>
1916 template<typename IterT, typename VisitorOp>
1917 inline void
1918 LeafNode<T, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
1919 {
1920 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(
1921 *this, otherIter, op, otherIsLHS);
1922 }
1923
1924
1925 template<typename T, Index Log2Dim>
1926 template<typename IterT, typename VisitorOp>
1927 inline void
1928 LeafNode<T, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
1929 {
1930 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(
1931 *this, otherIter, op, otherIsLHS);
1932 }
1933
1934
1935 template<typename T, Index Log2Dim>
1936 template<
1937 typename NodeT,
1938 typename VisitorOp,
1939 typename ChildAllIterT,
1940 typename OtherChildAllIterT>
1941 inline void
1942 LeafNode<T, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
1943 VisitorOp& op, bool otherIsLHS)
1944 {
1945 if (!otherIter) return;
1946
1947 if (otherIsLHS) {
1948 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1949 op(otherIter, iter);
1950 }
1951 } else {
1952 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1953 op(iter, otherIter);
1954 }
1955 }
1956 }
1957
1958
1960
1961
1962 template<typename T, Index Log2Dim>
1963 inline std::ostream&
1964 operator<<(std::ostream& os, const typename LeafNode<T, Log2Dim>::Buffer& buf)
1965 {
1966 for (Index32 i = 0, N = buf.size(); i < N; ++i) os << buf.mData[i] << ", ";
1967 return os;
1968 }
1969
1970 } // namespace tree
1971 } // namespace OPENVDB_VERSION_NAME
1972 } // namespace openvdb
1973
1974
1976
1977
1978 // Specialization for LeafNodes of type bool
1979 #include "LeafNodeBool.h"
1980
1981 // Specialization for LeafNodes with mask information only
1982 #include "LeafNodeMask.h"
1983
1984 #endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
Types.h
openvdb::v8_2::math::Coord::x
Int32 x() const
Definition: Coord.h:131
openvdb::v8_2::tree::LeafNode::probeLeaf
LeafNode * probeLeaf(const Coord &)
Definition: LeafNode.h:740
openvdb::v8_2::tree::DenseIteratorBase::NonConstValueType
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:184
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::tree::LeafNode::ChildIter::ChildIter
ChildIter()
Definition: LeafNode.h:245
openvdb::v8_2::tree::LeafNode::setValueOffAndCache
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNode.h:576
openvdb::v8_2::tree::LeafNode::isValueMaskOff
bool isValueMaskOff(Index n) const
Definition: LeafNode.h:865
openvdb::v8_2::tree::LeafNode::DenseIter::DenseIter
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition: LeafNode.h:258
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::isAllocated
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition: LeafNode.h:152
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::endValueOff
ValueOffCIter endValueOff() const
Definition: LeafNode.h:305
openvdb::v8_2::math::CoordBBox::inf
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:319
openvdb::v8_2::tree::LeafNode::SIZE
static const Index SIZE
Definition: LeafNode.h:53
openvdb::v8_2::tree::LeafNode::endValueAll
ValueAllCIter endValueAll() const
Definition: LeafNode.h:308
openvdb::v8_2::tree::LeafNode::ValueIter::ValueIter
ValueIter()
Definition: LeafNode.h:215
openvdb::v8_2::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
openvdb::v8_2::tree::LeafNode::beginValueAll
ValueAllIter beginValueAll()
Definition: LeafNode.h:299
openvdb::v8_2::tree::LeafNode::setValue
void setValue(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition: LeafNode.h:419
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::BuildType
T BuildType
Definition: LeafNode.h:40
openvdb::v8_2::tree::LeafNode::isValueMaskOn
bool isValueMaskOn() const
Definition: LeafNode.h:864
openvdb::v8_2::tree::LeafNode::ValueOff
Definition: LeafNode.h:203
openvdb::v8_2::tree::LeafNode::Ptr
SharedPtr< LeafNode > Ptr
Definition: LeafNode.h:45
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::cendValueOn
ValueOnCIter cendValueOn() const
Definition: LeafNode.h:301
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::memUsage
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1441
openvdb::v8_2::tree::LeafNode::buffer
Buffer & buffer()
Definition: LeafNode.h:340
openvdb::v8_2::tree::LeafNode::setValueOff
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNode.h:403
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::ValueAll
Definition: LeafNode.h:203
openvdb::v8_2::tree::LeafNode::streamingSize
size_t streamingSize(bool toHalf=false) const
openvdb::v8_2::tree::LeafNode::setValueOn
void setValueOn(Index offset, const ValueType &val)
Set the value of the voxel at the given offset and mark the voxel as active.
Definition: LeafNode.h:421
openvdb::v8_2::io::getDataCompression
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
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::beginValueOn
ValueOnIter beginValueOn()
Definition: LeafNode.h:293
LeafNodeBool.h
openvdb::v8_2::tree::LeafNode::onVoxelCount
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition: LeafNode.h:140
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::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: LeafNode.h:585
openvdb::v8_2::tree::LeafNode::setValueMaskOn
void setValueMaskOn(Index n)
Definition: LeafNode.h:876
openvdb::v8_2::math::isApproxEqual
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:407
openvdb::v8_2::tree::LeafNode::beginChildOn
ChildOnCIter beginChildOn() const
Definition: LeafNode.h:314
openvdb::v8_2::tree::LeafNode::getLastValue
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition: LeafNode.h:621
openvdb::v8_2::tree::LeafNode::setValueOn
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNode.h:413
openvdb::v8_2::math::CoordBBox::max
const Coord & max() const
Definition: Coord.h:322
openvdb::v8_2::tree::LeafNode::beginValueOff
ValueOffIter beginValueOff()
Definition: LeafNode.h:296
openvdb::v8_2::tree::LeafNode::endChildAll
ChildAllCIter endChildAll() const
Definition: LeafNode.h:330
openvdb::v8_2::Int32
int32_t Int32
Definition: openvdb/Types.h:34
openvdb::v8_2::tree::LeafNode::isChildMaskOff
bool isChildMaskOff(Index) const
Definition: LeafNode.h:872
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::offLeafVoxelCount
Index64 offLeafVoxelCount() const
Definition: LeafNode.h:144
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::offVoxelCount
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition: LeafNode.h:142
openvdb::v8_2::Index
Index32 Index
Definition: openvdb/Types.h:32
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::ValueIter::getItem
ValueT & getItem(Index pos) const
Definition: LeafNode.h:218
openvdb::v8_2::tree::LeafBuffer::mData
ValueType * mData
Definition: LeafBuffer.h:148
openvdb::v8_2::tree::LeafNode::DenseIter::unsetItem
void unsetItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:271
openvdb::v8_2::tree::LeafNode::ChildIter::ChildIter
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:246
openvdb::v8_2::tree::LeafNode::cendValueOff
ValueOffCIter cendValueOff() const
Definition: LeafNode.h:304
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::tree::LeafNode::beginValueAll
ValueAllCIter beginValueAll() const
Definition: LeafNode.h:298
openvdb::v8_2::tree::LeafNode::endValueOn
ValueOnCIter endValueOn() const
Definition: LeafNode.h:302
openvdb::v8_2::tree::LeafNode::childCount
static Index32 childCount()
Return the child count for this node, which is zero.
Definition: LeafNode.h:137
openvdb::v8_2::tree::LeafNode::ValueIter::modifyValue
void modifyValue(const ModifyOp &op) const
Definition: LeafNode.h:237
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::tree::LeafNode::endChildOff
ChildOffIter endChildOff()
Definition: LeafNode.h:328
openvdb::v8_2::tree::LeafNode::ValueConverter
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition: LeafNode.h:59
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.
TestLeafIO
Definition: LeafNode.h:22
openvdb::v8_2::tree::LeafNode::beginValueOn
ValueOnCIter beginValueOn() const
Definition: LeafNode.h:292
openvdb::v8_2::tree::LeafNode::ValueIter::setValue
void setValue(const ValueT &value) const
Definition: LeafNode.h:227
openvdb::v8_2::tree::LeafNode::endValueOn
ValueOnIter endValueOn()
Definition: LeafNode.h:303
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::endChildAll
ChildAllIter endChildAll()
Definition: LeafNode.h:331
openvdb::v8_2::math::negative
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:127
openvdb::v8_2::CombineArgs::resultIsActive
bool resultIsActive() const
Definition: openvdb/Types.h:492
LeafNodeMask.h
openvdb::v8_2::tree::LeafNode::cbeginChildOff
ChildOffCIter cbeginChildOff() const
Definition: LeafNode.h:316
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::setValueMask
void setValueMask(const NodeMaskType &mask)
Definition: LeafNode.h:870
openvdb::v8_2::tree::LeafNode::getChildDim
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNode.h:129
openvdb::v8_2::tree::LeafNode::getNodeLog2Dims
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNode.h:127
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::isValueMaskOff
bool isValueMaskOff() const
Definition: LeafNode.h:866
openvdb::v8_2::util::DenseMaskIterator
Definition: NodeMasks.h:271
openvdb::v8_2::tree::LeafNode::ChildIter
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:244
openvdb::v8_2::tree::LeafNode::ValueIter::modifyItem
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNode.h:234
openvdb::v8_2::math::Coord::setY
Coord & setY(Int32 y)
Definition: Coord.h:81
openvdb::v8_2::tree::LeafNode::ValueIter::ValueIter
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:216
openvdb::v8_2::util::NodeMask::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:354
openvdb::v8_2::tree::LeafNode::negate
void negate()
Definition: LeafNode.h:1706
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::tree::LeafNode::getLevel
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNode.h:125
openvdb::v8_2::tree::LeafNode::getOrigin
void getOrigin(Coord &origin) const
Definition: LeafNode.h:173
openvdb::v8_2::math::Coord::setX
Coord & setX(Int32 x)
Definition: Coord.h:80
openvdb::v8_2::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz, bool &state, int &level, AccessorT &) const
Return the value of the voxel at the given coordinates and return its active state and level (i....
Definition: LeafNode.h:603
openvdb::v8_2::tree::LeafNode::getValueLevelAndCache
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNode.h:614
openvdb::v8_2::tree::LeafNode::operator=
LeafNode & operator=(const LeafNode &)=default
Deep assignment operator.
openvdb::v8_2::tree::LeafNode::onTileCount
static Index64 onTileCount()
Definition: LeafNode.h:145
openvdb::v8_2::tree::LeafNode::isValueOn
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:469
openvdb::v8_2::tree::LeafNode::isInactive
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNode.h:838
openvdb::v8_2::math::CoordBBox::min
const Coord & min() const
Definition: Coord.h:321
openvdb::v8_2::tree::LeafNode::doVisit2
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1942
openvdb::v8_2::tree::LeafNode::probeConstNodeAndCache
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition: LeafNode.h:753
openvdb::v8_2::tree::SparseIteratorBase< MaskIterT, ChildIter< MaskIterT, NodeT, TagT >, NodeT, ValueType >::ValueType
ValueType ValueType
Definition: Iterator.h:117
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::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Definition: LeafNode.h:297
openvdb::v8_2::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition: LeafNode.h:415
openvdb::v8_2::tree::LeafNode::offTileCount
static Index64 offTileCount()
Definition: LeafNode.h:146
openvdb::v8_2::tree::LeafNode::endChildOff
ChildOffCIter endChildOff() const
Definition: LeafNode.h:327
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::beginChildOff
ChildOffIter beginChildOff()
Definition: LeafNode.h:318
openvdb::v8_2::tree::LeafNode::ValueOn
Definition: LeafNode.h:203
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::probeLeaf
const LeafNode * probeLeaf(const Coord &) const
Definition: LeafNode.h:751
openvdb::v8_2::tree::LeafNode::denseFill
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNode.h:482
openvdb::v8_2::tree::LeafNode::isEmpty
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNode.h:148
openvdb::v8_2::tree::LeafNode::evalNodeOrigin
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNode.h:882
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::voxelizeActiveTiles
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNode.h:631
openvdb::v8_2::tree::LeafNode::touchLeafAndCache
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition: LeafNode.h:731
openvdb::v8_2::tree::LeafNode::addTile
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1582
openvdb::v8_2::tree::LeafNode::probeValueAndCache
bool probeValueAndCache(const Coord &xyz, ValueType &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val.
Definition: LeafNode.h:594
openvdb::v8_2::tree::LeafNode::onLeafVoxelCount
Index64 onLeafVoxelCount() const
Definition: LeafNode.h:143
openvdb::v8_2::tree::LeafNode::getValueLevel
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition: LeafNode.h:388
openvdb::v8_2::tree::LeafNode::operator!=
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:195
openvdb::v8_2::tree::LeafNode::endChildOn
ChildOnIter endChildOn()
Definition: LeafNode.h:325
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::io::COMPRESS_ZIP
@ COMPRESS_ZIP
Definition: Compression.h:54
openvdb::v8_2::tree::LeafNode::cendChildOff
ChildOffCIter cendChildOff() const
Definition: LeafNode.h:326
openvdb::v8_2::tree::LeafNode::DenseIter::getItem
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNode.h:260
openvdb::v8_2::tree::LeafNode::stealNodes
void stealNodes(ArrayT &, const ValueType &, bool)
Definition: LeafNode.h:719
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::endValueOff
ValueOffIter endValueOff()
Definition: LeafNode.h:306
openvdb::v8_2::tree::LeafNode::visit2
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1918
openvdb::v8_2::tree::LeafNode::DenseIter::NonConstValueT
typename BaseT::NonConstValueType NonConstValueT
Definition: LeafNode.h:255
openvdb::v8_2::tree::LeafNode::setValuesOff
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNode.h:466
openvdb::v8_2::tree::LeafNode::isDense
bool isDense() const
Return true if this node contains only active voxels.
Definition: LeafNode.h:150
openvdb::v8_2::tree::LeafNode::SameConfiguration
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition: LeafNode.h:64
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::ValueIter::getValue
ValueT & getValue() const
Definition: LeafNode.h:219
openvdb::v8_2::tree::LeafNode::swap
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition: LeafNode.h:338
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::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::SharedPtr
std::shared_ptr< T > SharedPtr
Definition: openvdb/Types.h:92
openvdb::v8_2::tree::LeafNode::cbeginChildAll
ChildAllCIter cbeginChildAll() const
Definition: LeafNode.h:319
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::leafCount
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNode.h:131
openvdb::v8_2::tree::LeafNode::beginChildAll
ChildAllIter beginChildAll()
Definition: LeafNode.h:321
openvdb::v8_2::tree::LeafNode::setValueMask
void setValueMask(Index n, bool on)
Definition: LeafNode.h:875
openvdb::v8_2::tree::LeafNode::probeLeafAndCache
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition: LeafNode.h:750
openvdb::v8_2::tree::IteratorBase
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:30
openvdb::v8_2::tree::LeafNode::hasActiveTiles
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNode.h:474
openvdb::v8_2::util::OnMaskIterator
Definition: NodeMasks.h:209
openvdb::v8_2::tree::LeafNode::allocate
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNode.h:154
openvdb::v8_2::MERGE_NODES
@ MERGE_NODES
Definition: openvdb/Types.h:368
openvdb::v8_2::io::getMappedFilePtr
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
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::ValueType
T ValueType
Definition: LeafNode.h:41
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::nonLeafCount
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNode.h:135
openvdb::v8_2::tree::LeafNode::MaskDenseIterator
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: LeafNode.h:200
openvdb::v8_2::tree::LeafNode::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: LeafNode.h:560
openvdb::v8_2::tree::LeafNode::log2dim
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition: LeafNode.h:117
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::beginChildOff
ChildOffCIter beginChildOff() const
Definition: LeafNode.h:317
openvdb::v8_2::tree::LeafNode::setValueOnlyAndCache
void setValueOnlyAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNode.h:551
openvdb::v8_2::tree::operator<<
std::ostream & operator<<(std::ostream &os, const typename LeafNode< T, Log2Dim >::Buffer &buf)
Definition: LeafNode.h:1964
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::setValueAndCache
void setValueAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNode.h:542
openvdb::v8_2::tree::LeafNode::ValueIter
Definition: LeafNode.h:212
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::tree::LeafNode::probeNodeAndCache
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition: LeafNode.h:733
openvdb::v8_2::tree::LeafNode::addTileAndCache
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1599
openvdb::v8_2::tree::LeafNode::beginChildOn
ChildOnIter beginChildOn()
Definition: LeafNode.h:315
Iterator.h
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::beginValueOff
ValueOffCIter beginValueOff() const
Definition: LeafNode.h:295
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::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: LeafNode.h:393
openvdb::v8_2::tree::LeafNode::modifyValue
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition: LeafNode.h:443
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153
LeafBuffer.h
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::skipCompressedValues
void skipCompressedValues(bool seekable, std::istream &, bool fromHalf)
Definition: LeafNode.h:1306
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::dim
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition: LeafNode.h:119
openvdb::v8_2::tree::LeafBuffer::size
static Index size()
Return the number of values contained in this buffer.
Definition: LeafBuffer.h:114
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::probeConstNode
const NodeT * probeConstNode(const Coord &) const
Definition: LeafNode.h:717
openvdb::v8_2::tree::DenseIteratorBase
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:179
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::getValueAndCache
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:529
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::addLeafAndCache
void addLeafAndCache(LeafNode *, AccessorT &)
Definition: LeafNode.h:711
openvdb::v8_2::tree::LeafNode::cendChildOn
ChildOnCIter cendChildOn() const
Definition: LeafNode.h:323
openvdb::v8_2::Index32
uint32_t Index32
Definition: openvdb/Types.h:30
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::getNodes
void getNodes(ArrayT &) const
Definition: LeafNode.h:718
openvdb::v8_2::tree::SparseIteratorBase
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:115
openvdb::v8_2::math::Coord::ValueType
Int32 ValueType
Definition: Coord.h:33
openvdb::v8_2::io::getStreamMetadataPtr
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
openvdb::v8_2::tree::LeafNode::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Definition: LeafNode.h:294
openvdb::v8_2::tree::LeafNode::modifyValueAndActiveStateAndCache
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNode.h:568
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::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::io::HalfReader
Definition: Compression.h:292
openvdb::v8_2::tree::LeafNode::probeConstLeafAndCache
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition: LeafNode.h:748
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::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::tree::LeafNode::cendValueAll
ValueAllCIter cendValueAll() const
Definition: LeafNode.h:307
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::getOrigin
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition: LeafNode.h:174
openvdb::v8_2::tree::LeafNode::ChildOn
Definition: LeafNode.h:204
openvdb::v8_2::tree::LeafNode::DenseIter
Definition: LeafNode.h:253
openvdb::v8_2::tree::LeafNode::isChildMaskOn
bool isChildMaskOn(Index) const
Definition: LeafNode.h:871
openvdb::v8_2::tree::LeafNode::cbeginChildOn
ChildOnCIter cbeginChildOn() const
Definition: LeafNode.h:313
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::ChildOff
Definition: LeafNode.h:204
openvdb::v8_2::tree::LeafNode::setOrigin
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNode.h:169
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::v8_2::tree::LeafNode::numValues
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:123
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:93
openvdb::v8_2::tree::LeafNode::setValueMaskOff
void setValueMaskOff(Index n)
Definition: LeafNode.h:877
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::OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
@ OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
Definition: version.h:194
openvdb::v8_2::tree::SameLeafConfig
Definition: LeafNode.h:912
openvdb::v8_2::tree::LeafNode::size
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:121
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::endValueAll
ValueAllIter endValueAll()
Definition: LeafNode.h:309
openvdb::v8_2::io::readCompressedValues
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:465
openvdb::v8_2::tree::LeafNode::setValuesOn
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNode.h:464
openvdb::v8_2::tree::LeafNode::evalActiveBoundingBox
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1451
openvdb::v8_2::tree::LeafNode::isValueOnAndCache
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:537
openvdb::v8_2::tree::LeafNode::buffer
const Buffer & buffer() const
Definition: LeafNode.h:339
openvdb::v8_2::math::CoordBBox::createCube
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:313
openvdb::v8_2::tree::LeafNode::stealNode
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition: LeafNode.h:713
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::probeLeafAndCache
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition: LeafNode.h:742
openvdb
Definition: openvdb/Exceptions.h:13
openvdb::v8_2::tree::LeafNode::nodeCount
void nodeCount(std::vector< Index32 > &) const
no-op
Definition: LeafNode.h:133
openvdb::v8_2::tree::LeafNode::isValueMaskOn
bool isValueMaskOn(Index n) const
Definition: LeafNode.h:863
openvdb::v8_2::io::MappedFile::Ptr
SharedPtr< MappedFile > Ptr
Definition: io.h:136
openvdb::v8_2::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:452
openvdb::v8_2::tree::LeafNode::isChildMaskOff
bool isChildMaskOff() const
Definition: LeafNode.h:873
openvdb::v8_2::tree::LeafNode::endChildOn
ChildOnCIter endChildOn() const
Definition: LeafNode.h:324
openvdb::v8_2::tree::LeafNode::getFirstValue
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition: LeafNode.h:619
openvdb::v8_2::tree::LeafNode::isValueOn
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNode.h:471
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::tree::LeafNode::MaskOffIterator
typename NodeMaskType::OffIterator MaskOffIterator
Definition: LeafNode.h:199
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::ValueIter::setItem
void setItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:222
openvdb::v8_2::tree::LeafNode::merge
void merge(const LeafNode &)
Definition: LeafNode.h:1632
openvdb::v8_2::io::writeCompressedValues
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition: Compression.h:645
openvdb::v8_2::tree::LeafNode::DenseIter::DenseIter
DenseIter()
Definition: LeafNode.h:257
openvdb::v8_2::tree::LeafNode::getValueMask
NodeMaskType & getValueMask()
Definition: LeafNode.h:868
openvdb::v8_2::tree::LeafNode::MaskOnIterator
typename NodeMaskType::OnIterator MaskOnIterator
Definition: LeafNode.h:198
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::probeNode
NodeT * probeNode(const Coord &)
Definition: LeafNode.h:715
openvdb::v8_2::tree::LeafNode::cendChildAll
ChildAllCIter cendChildAll() const
Definition: LeafNode.h:329
openvdb::v8_2::util::BaseMaskIterator::pos
Index32 pos() const
Definition: NodeMasks.h:200
openvdb::v8_2::tree::LeafNode::addLeaf
void addLeaf(LeafNode *)
Definition: LeafNode.h:709
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...