OpenVDB 14.0.0
Loading...
Searching...
No Matches
LeafNode.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-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>
10#include <openvdb/io/Compression.h> // for io::readData(), etc.
11#include "Iterator.h"
12#include "LeafBuffer.h"
13#include <algorithm> // for std::nth_element()
14#include <iostream>
15#include <memory>
16#include <sstream>
17#include <string>
18#include <type_traits>
19#include <vector>
20
21
22class TestLeaf;
23template<typename> class TestLeafIO;
24
25namespace openvdb {
27namespace OPENVDB_VERSION_NAME {
28namespace tree {
29
30template<Index, typename> struct SameLeafConfig; // forward declaration
31
32
33/// @brief Templated block class to hold specific data types and a fixed
34/// number of values determined by Log2Dim. The actual coordinate
35/// dimension of the block is 2^Log2Dim, i.e. Log2Dim=3 corresponds to
36/// a LeafNode that spans a 8^3 block.
37template<typename T, Index Log2Dim>
39{
40public:
41 using BuildType = T;
42 using ValueType = T;
47
48 static const Index
49 LOG2DIM = Log2Dim, // needed by parent nodes
50 TOTAL = Log2Dim, // needed by parent nodes
51 DIM = 1 << TOTAL, // dimension along one coordinate direction
52 NUM_VALUES = 1 << 3 * Log2Dim,
53 NUM_VOXELS = NUM_VALUES, // total number of voxels represented by this node
55 LEVEL = 0; // level 0 = leaf
56
57 /// @brief ValueConverter<T>::Type is the type of a LeafNode having the same
58 /// dimensions as this node but a different value type, T.
59 template<typename OtherValueType>
61
62 /// @brief SameConfiguration<OtherNodeType>::value is @c true if and only if
63 /// OtherNodeType is the type of a LeafNode with the same dimensions as this node.
64 template<typename OtherNodeType>
68
69
70 /// Default constructor
72
73 /// @brief Constructor
74 /// @param coords the grid index coordinates of a voxel
75 /// @param value a value with which to fill the buffer
76 /// @param active the active state to which to initialize all voxels
77 explicit LeafNode(const Coord& coords,
78 const ValueType& value = zeroVal<ValueType>(),
79 bool active = false);
80
81 /// @brief "Partial creation" constructor used during file input
82 /// @param coords the grid index coordinates of a voxel
83 /// @param value a value with which to fill the buffer
84 /// @param active the active state to which to initialize all voxels
85 /// @details This constructor does not allocate memory for voxel values.
86 /// Call @c buffer().allocate() before accessing voxel data. The valid
87 /// advanced pattern is: create all leaves single-threaded, then call
88 /// @c allocate() in parallel across distinct leaves.
90 const Coord& coords,
91 const ValueType& value = zeroVal<ValueType>(),
92 bool active = false);
93
94 /// Deep copy constructor
96
97 /// Deep assignment operator
98 LeafNode& operator=(const LeafNode&) = default;
99
100 /// Value conversion copy constructor
101 template<typename OtherValueType>
103
104 /// Topology copy constructor
105 template<typename OtherValueType>
107 const ValueType& offValue, const ValueType& onValue, TopologyCopy);
108
109 /// Topology copy constructor
110 template<typename OtherValueType>
112 const ValueType& background, TopologyCopy);
113
114 /// Destructor.
116
117 //
118 // Statistics
119 //
120 /// Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3
121 static Index log2dim() { return Log2Dim; }
122 /// Return the number of voxels in each coordinate dimension.
123 static Index dim() { return DIM; }
124 /// Return the total number of voxels represented by this LeafNode
125 static Index size() { return SIZE; }
126 /// Return the total number of voxels represented by this LeafNode
127 static Index numValues() { return SIZE; }
128 /// Return the level of this node, which by definition is zero for LeafNodes
129 static Index getLevel() { return LEVEL; }
130 /// Append the Log2Dim of this LeafNode to the specified vector
131 static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
132 /// Return the dimension of child nodes of this LeafNode, which is one for voxels.
133 static Index getChildDim() { return 1; }
134 /// Return the leaf count for this node, which is one.
135 static Index64 leafCount() { return 1; }
136 /// no-op
137 void nodeCount(std::vector<Index64> &) const {}
138 /// Return the non-leaf count for this node, which is zero.
139 static Index64 nonLeafCount() { return 0; }
140 /// Return the child count for this node, which is zero.
141 static Index32 childCount() { return 0; }
142
143 /// Return the number of voxels marked On.
144 Index64 onVoxelCount() const { return mValueMask.countOn(); }
145 /// Return the number of voxels marked Off.
146 Index64 offVoxelCount() const { return mValueMask.countOff(); }
149 static Index64 onTileCount() { return 0; }
150 static Index64 offTileCount() { return 0; }
151 /// Return @c true if this node has no active voxels.
152 bool isEmpty() const { return mValueMask.isOff(); }
153 /// Return @c true if this node contains only active voxels.
154 bool isDense() const { return mValueMask.isOn(); }
155 /// Return @c true if memory for this node's buffer has been allocated.
156 bool isAllocated() const { return !mBuffer.empty(); }
157 /// Allocate memory for this node's buffer if it has not already been allocated.
158 bool allocate() { return mBuffer.allocate(); }
159
160 /// Return the memory in bytes occupied by this node.
162
163 /// Expand the given bounding box so that it includes this leaf node's active voxels.
164 /// If visitVoxels is false this LeafNode will be approximated as dense, i.e. with all
165 /// voxels active. Else the individual active voxels are visited to produce a tight bbox.
166 void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
167
168 /// @brief Return the bounding box of this node, i.e., the full index space
169 /// spanned by this leaf node.
171
172 /// Set the grid index coordinates of this node's local origin.
173 void setOrigin(const Coord& origin) { mOrigin = origin; }
174 //@{
175 /// Return the grid index coordinates of this node's local origin.
176 const Coord& origin() const { return mOrigin; }
177 void getOrigin(Coord& origin) const { origin = mOrigin; }
178 void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
179 //@}
180
181 /// Return the linear table offset of the given global or local coordinates.
182 static Index coordToOffset(const Coord& xyz);
183 /// @brief Return the local coordinates for a linear table offset,
184 /// where offset 0 has coordinates (0, 0, 0).
186 /// Return the global coordinates for a linear table offset.
188
189 /// Return the transient data value.
190 Index32 transientData() const { return mTransientData; }
191 /// Set the transient data value.
193
194 /// Return a string representation of this node.
195 std::string str() const;
196
197 /// @brief Return @c true if the given node (which may have a different @c ValueType
198 /// than this node) has the same active value topology as this node.
199 template<typename OtherType, Index OtherLog2Dim>
201
202 /// Check for buffer, state and origin equivalence.
203 bool operator==(const LeafNode& other) const;
204 bool operator!=(const LeafNode& other) const { return !(other == *this); }
205
206protected:
210
211 // Type tags to disambiguate template instantiations
212 struct ValueOn {}; struct ValueOff {}; struct ValueAll {};
213 struct ChildOn {}; struct ChildOff {}; struct ChildAll {};
214
215 template<typename MaskIterT, typename NodeT, typename ValueT, typename TagT>
216 struct ValueIter:
217 // Derives from SparseIteratorBase, but can also be used as a dense iterator,
218 // if MaskIterT is a dense mask iterator type.
219 public SparseIteratorBase<
220 MaskIterT, ValueIter<MaskIterT, NodeT, ValueT, TagT>, NodeT, ValueT>
221 {
222 using ValueType = std::conditional_t<std::is_const_v<NodeT>, ValueT,
223 std::remove_const_t<ValueT>>;
225
227 ValueIter(const MaskIterT& iter, NodeT* parent)
228 : BaseT(iter, parent)
229 // Unlike other value iterators, cache the buffer data as part of
230 // the iterators members to avoid the cost of going through the
231 // leaf buffer atomic/checking API
232 , mData([&]() { OPENVDB_ASSERT(parent); return parent->buffer().data(); }()) {}
233
234 ValueT& getItem(Index pos) const { return mData[pos]; }
235 ValueT& getValue() const { return this->getItem(this->pos()); }
236
237 // Note: setItem() can't be called on const iterators.
238 void setItem(Index pos, const ValueT& value) const
239 {
240 if constexpr (std::is_const_v<NodeT>) {
241 static_assert(!std::is_const_v<NodeT>,
242 "ValueIter::setItem cannot be called on const iterators");
243 }
244 else {
247 mData[pos] = value;
248 }
249 }
250 // Note: setValue() can't be called on const iterators.
251 void setValue(const ValueT& value) const { this->setItem(this->pos(), value); }
252
253 // Note: modifyItem() can't be called on const iterators.
254 template<typename ModifyOp>
255 void modifyItem(Index n, const ModifyOp& op) const
256 {
257 if constexpr (std::is_const_v<NodeT>) {
258 static_assert(!std::is_const_v<NodeT>,
259 "ValueIter::modifyItem cannot be called on const iterators");
260 }
261 else {
262 OPENVDB_ASSERT(n < SIZE);
263 OPENVDB_ASSUME(n < SIZE);
264 op(mData[n]);
265 this->parent().setValueOn(n);
266 }
267 }
268 // Note: modifyValue() can't be called on const iterators.
269 template<typename ModifyOp>
270 void modifyValue(const ModifyOp& op) const
271 {
272 this->modifyItem(this->pos(), op);
273 }
274 private:
275 ValueType* mData;
276 };
277
278 /// Leaf nodes have no children, so their child iterators have no get/set accessors.
279 template<typename MaskIterT, typename NodeT, typename TagT>
280 struct ChildIter:
281 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>
282 {
284 ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
285 MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>(iter, parent) {}
286 };
287
288 template<typename NodeT, typename ValueT, typename TagT>
290 MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, /*ChildT=*/void, ValueT>
291 {
294
297
298 bool getItem(Index pos, void*& child, NonConstValueT& value) const
299 {
300 value = this->parent().getValue(pos);
301 child = nullptr;
302 return false; // no child
303 }
304
305 // Note: setItem() can't be called on const iterators.
306 //void setItem(Index pos, void* child) const {}
307
308 // Note: unsetItem() can't be called on const iterators.
309 void unsetItem(Index pos, const ValueT& value) const
310 {
311 this->parent().setValueOnly(pos, value);
312 }
313 };
314
315public:
316 using ValueOnIter = ValueIter<MaskOnIterator, LeafNode, const ValueType, ValueOn>;
317 using ValueOnCIter = ValueIter<MaskOnIterator, const LeafNode, const ValueType, ValueOn>;
318 using ValueOffIter = ValueIter<MaskOffIterator, LeafNode, const ValueType, ValueOff>;
319 using ValueOffCIter = ValueIter<MaskOffIterator,const LeafNode,const ValueType,ValueOff>;
320 using ValueAllIter = ValueIter<MaskDenseIterator, LeafNode, const ValueType, ValueAll>;
321 using ValueAllCIter = ValueIter<MaskDenseIterator,const LeafNode,const ValueType,ValueAll>;
322 using ChildOnIter = ChildIter<MaskOnIterator, LeafNode, ChildOn>;
323 using ChildOnCIter = ChildIter<MaskOnIterator, const LeafNode, ChildOn>;
324 using ChildOffIter = ChildIter<MaskOffIterator, LeafNode, ChildOff>;
325 using ChildOffCIter = ChildIter<MaskOffIterator, const LeafNode, ChildOff>;
326 using ChildAllIter = DenseIter<LeafNode, ValueType, ChildAll>;
327 using ChildAllCIter = DenseIter<const LeafNode, const ValueType, ChildAll>;
328
329 ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
330 ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
331 ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
332 ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
333 ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
334 ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
335 ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
336 ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
337 ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
338
339 ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
340 ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
341 ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
342 ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
343 ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
344 ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
345 ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
346 ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
347 ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
348
349 // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
350 // because leaf nodes have no children.
351 ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
352 ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
353 ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
354 ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
355 ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
356 ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
357 ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
358 ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
359 ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
360
361 ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
362 ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
363 ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
364 ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
365 ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
366 ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
367 ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
368 ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
369 ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
370
371 //
372 // Buffer management
373 //
374 /// @brief Exchange this node's data buffer with the given data buffer
375 /// without changing the active states of the values.
376 void swap(Buffer& other) { mBuffer.swap(other); }
377 const Buffer& buffer() const { return mBuffer; }
378 Buffer& buffer() { return mBuffer; }
379
380#if OPENVDB_ABI_VERSION_NUMBER < 14
381 //
382 // I/O methods
383 //
384 /// @brief Read in just the topology.
385 /// @param is the stream from which to read
386 /// @param fromHalf if true, floating-point input values are assumed to be 16-bit
387 void readTopology(std::istream& is, bool fromHalf = false);
388 /// @brief Write out just the topology.
389 /// @param os the stream to which to write
390 /// @param toHalf if true, output floating-point values as 16-bit half floats
391 void writeTopology(std::ostream& os, bool toHalf = false) const;
392
393 /// @brief Read buffers from a stream.
394 /// @param is the stream from which to read
395 /// @param fromHalf if true, floating-point input values are assumed to be 16-bit
396 void readBuffers(std::istream& is, bool fromHalf = false);
397 /// @brief Read buffers that intersect the given bounding box.
398 /// @param is the stream from which to read
399 /// @param bbox an index-space bounding box
400 /// @param fromHalf if true, floating-point input values are assumed to be 16-bit
401 void readBuffers(std::istream& is, const CoordBBox& bbox, bool fromHalf = false);
402 /// @brief Write buffers to a stream.
403 /// @param os the stream to which to write
404 /// @param toHalf if true, output floating-point values as 16-bit half floats
405 void writeBuffers(std::ostream& os, bool toHalf = false) const;
406#endif // OPENVDB_ABI_VERSION_NUMBER < 14
407
408 size_t streamingSize(bool toHalf = false) const;
409
410 //
411 // Accessor methods
412 //
413 /// Return the value of the voxel at the given coordinates.
414 const ValueType& getValue(const Coord& xyz) const;
415 /// Return the value of the voxel at the given linear offset.
416 const ValueType& getValue(Index offset) const;
417
418 /// @brief Return @c true if the voxel at the given coordinates is active.
419 /// @param xyz the coordinates of the voxel to be probed
420 /// @param[out] val the value of the voxel at the given coordinates
421 bool probeValue(const Coord& xyz, ValueType& val) const;
422 /// @brief Return @c true if the voxel at the given offset is active.
423 /// @param offset the linear offset of the voxel to be probed
424 /// @param[out] val the value of the voxel at the given coordinates
425 bool probeValue(Index offset, ValueType& val) const;
426
427 /// Return the level (i.e., 0) at which leaf node values reside.
428 static Index getValueLevel(const Coord&) { return LEVEL; }
429
430 /// Set the active state of the voxel at the given coordinates but don't change its value.
431 void setActiveState(const Coord& xyz, bool on);
432 /// Set the active state of the voxel at the given offset but don't change its value.
433 void setActiveState(Index offset, bool on) { OPENVDB_ASSERT(offset<SIZE); mValueMask.set(offset, on); }
434
435 /// Set the value of the voxel at the given coordinates but don't change its active state.
436 void setValueOnly(const Coord& xyz, const ValueType& val);
437 /// Set the value of the voxel at the given offset but don't change its active state.
438 void setValueOnly(Index offset, const ValueType& val);
439
440 /// Mark the voxel at the given coordinates as inactive but don't change its value.
441 void setValueOff(const Coord& xyz) { mValueMask.setOff(LeafNode::coordToOffset(xyz)); }
442 /// Mark the voxel at the given offset as inactive but don't change its value.
443 void setValueOff(Index offset) { OPENVDB_ASSERT(offset < SIZE); mValueMask.setOff(offset); }
444
445 /// Set the value of the voxel at the given coordinates and mark the voxel as inactive.
446 void setValueOff(const Coord& xyz, const ValueType& val);
447 /// Set the value of the voxel at the given offset and mark the voxel as inactive.
448 void setValueOff(Index offset, const ValueType& val);
449
450 /// Mark the voxel at the given coordinates as active but don't change its value.
451 void setValueOn(const Coord& xyz) { mValueMask.setOn(LeafNode::coordToOffset(xyz)); }
452 /// Mark the voxel at the given offset as active but don't change its value.
453 void setValueOn(Index offset) { OPENVDB_ASSERT(offset < SIZE); mValueMask.setOn(offset); }
454 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
455 void setValueOn(const Coord& xyz, const ValueType& val) {
456 this->setValueOn(LeafNode::coordToOffset(xyz), val);
457 }
458 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
459 void setValue(const Coord& xyz, const ValueType& val) { this->setValueOn(xyz, val); }
460 /// Set the value of the voxel at the given offset and mark the voxel as active.
461 void setValueOn(Index offset, const ValueType& val) {
462 mBuffer.setValue(offset, val);
463 mValueMask.setOn(offset);
464 }
465
466 /// @brief Apply a functor to the value of the voxel at the given offset
467 /// and mark the voxel as active.
468 template<typename ModifyOp>
469 void modifyValue(Index offset, const ModifyOp& op)
470 {
471 if (!mBuffer.empty()) {
472 // in-place modify value
473 ValueType& val = const_cast<ValueType&>(mBuffer[offset]);
474 op(val);
475 mValueMask.setOn(offset);
476 }
477 }
478
479 /// @brief Apply a functor to the value of the voxel at the given coordinates
480 /// and mark the voxel as active.
481 template<typename ModifyOp>
482 void modifyValue(const Coord& xyz, const ModifyOp& op)
483 {
484 this->modifyValue(this->coordToOffset(xyz), op);
485 }
486
487 /// Apply a functor to the voxel at the given coordinates.
488 template<typename ModifyOp>
489 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
490 {
491 if (!mBuffer.empty()) {
492 const Index offset = this->coordToOffset(xyz);
493 bool state = mValueMask.isOn(offset);
494 // in-place modify value
495 ValueType& val = const_cast<ValueType&>(mBuffer[offset]);
496 op(val, state);
497 mValueMask.set(offset, state);
498 }
499 }
500
501 /// Mark all voxels as active but don't change their values.
502 void setValuesOn() { mValueMask.setOn(); }
503 /// Mark all voxels as inactive but don't change their values.
504 void setValuesOff() { mValueMask.setOff(); }
505
506 /// Return @c true if the voxel at the given coordinates is active.
507 bool isValueOn(const Coord& xyz) const { return this->isValueOn(LeafNode::coordToOffset(xyz)); }
508 /// Return @c true if the voxel at the given offset is active.
509 bool isValueOn(Index offset) const { OPENVDB_ASSERT(offset < SIZE); return mValueMask.isOn(offset); }
510 /// Return @c true if the voxel at the given coordinates is inactive.
511 bool isValueOff(const Coord& xyz) const { return this->isValueOff(LeafNode::coordToOffset(xyz)); }
512 /// Return @c true if the voxel at the given offset is inactive.
513 bool isValueOff(Index offset) const { OPENVDB_ASSERT(offset < SIZE); return mValueMask.isOff(offset); }
514
515 /// Return @c false since leaf nodes never contain tiles.
516 static bool hasActiveTiles() { return false; }
517
518 /// Set all voxels that lie outside the given axis-aligned box to the background.
519 void clip(const CoordBBox&, const ValueType& background);
520
521 /// Set all voxels within an axis-aligned box to the specified value and active state.
522 void fill(const CoordBBox& bbox, const ValueType&, bool active = true);
523 /// Set all voxels within an axis-aligned box to the specified value and active state.
524 void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true)
525 {
526 this->fill(bbox, value, active);
527 }
528
529 /// Set all voxels to the specified value but don't change their active states.
530 void fill(const ValueType& value);
531 /// Set all voxels to the specified value and active state.
532 void fill(const ValueType& value, bool active);
533
534 /// @brief Copy into a dense grid the values of the voxels that lie within
535 /// a given bounding box.
536 ///
537 /// @param bbox inclusive bounding box of the voxels to be copied into the dense grid
538 /// @param dense dense grid with a stride in @e z of one (see tools::Dense
539 /// in tools/Dense.h for the required API)
540 ///
541 /// @note @a bbox is assumed to be identical to or contained in the coordinate domains
542 /// of both the dense grid and this node, i.e., no bounds checking is performed.
543 /// @note Consider using tools::CopyToDense in tools/Dense.h
544 /// instead of calling this method directly.
545 template<typename DenseT>
546 void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
547
548 /// @brief Copy from a dense grid into this node the values of the voxels
549 /// that lie within a given bounding box.
550 /// @details Only values that are different (by more than the given tolerance)
551 /// from the background value will be active. Other values are inactive
552 /// and truncated to the background value.
553 ///
554 /// @param bbox inclusive bounding box of the voxels to be copied into this node
555 /// @param dense dense grid with a stride in @e z of one (see tools::Dense
556 /// in tools/Dense.h for the required API)
557 /// @param background background value of the tree that this node belongs to
558 /// @param tolerance tolerance within which a value equals the background value
559 ///
560 /// @note @a bbox is assumed to be identical to or contained in the coordinate domains
561 /// of both the dense grid and this node, i.e., no bounds checking is performed.
562 /// @note Consider using tools::CopyFromDense in tools/Dense.h
563 /// instead of calling this method directly.
564 template<typename DenseT>
565 void copyFromDense(const CoordBBox& bbox, const DenseT& dense,
566 const ValueType& background, const ValueType& tolerance);
567
568 /// @brief Return the value of the voxel at the given coordinates.
569 /// @note Used internally by ValueAccessor.
570 template<typename AccessorT>
571 const ValueType& getValueAndCache(const Coord& xyz, AccessorT&) const
572 {
573 return this->getValue(xyz);
574 }
575
576 /// @brief Return @c true if the voxel at the given coordinates is active.
577 /// @note Used internally by ValueAccessor.
578 template<typename AccessorT>
579 bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
580
581 /// @brief Change the value of the voxel at the given coordinates and mark it as active.
582 /// @note Used internally by ValueAccessor.
583 template<typename AccessorT>
584 void setValueAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
585 {
586 this->setValueOn(xyz, val);
587 }
588
589 /// @brief Change the value of the voxel at the given coordinates
590 /// but preserve its state.
591 /// @note Used internally by ValueAccessor.
592 template<typename AccessorT>
593 void setValueOnlyAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
594 {
595 this->setValueOnly(xyz, val);
596 }
597
598 /// @brief Apply a functor to the value of the voxel at the given coordinates
599 /// and mark the voxel as active.
600 /// @note Used internally by ValueAccessor.
601 template<typename ModifyOp, typename AccessorT>
602 void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
603 {
604 this->modifyValue(xyz, op);
605 }
606
607 /// Apply a functor to the voxel at the given coordinates.
608 /// @note Used internally by ValueAccessor.
609 template<typename ModifyOp, typename AccessorT>
610 void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
611 {
612 this->modifyValueAndActiveState(xyz, op);
613 }
614
615 /// @brief Change the value of the voxel at the given coordinates and mark it as inactive.
616 /// @note Used internally by ValueAccessor.
617 template<typename AccessorT>
618 void setValueOffAndCache(const Coord& xyz, const ValueType& value, AccessorT&)
619 {
620 this->setValueOff(xyz, value);
621 }
622
623 /// @brief Set the active state of the voxel at the given coordinates
624 /// without changing its value.
625 /// @note Used internally by ValueAccessor.
626 template<typename AccessorT>
627 void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
628 {
629 this->setActiveState(xyz, on);
630 }
631
632 /// @brief Return @c true if the voxel at the given coordinates is active
633 /// and return the voxel value in @a val.
634 /// @note Used internally by ValueAccessor.
635 template<typename AccessorT>
636 bool probeValueAndCache(const Coord& xyz, ValueType& val, AccessorT&) const
637 {
638 return this->probeValue(xyz, val);
639 }
640
641 /// @brief Return the value of the voxel at the given coordinates and return
642 /// its active state and level (i.e., 0) in @a state and @a level.
643 /// @note Used internally by ValueAccessor.
644 template<typename AccessorT>
645 const ValueType& getValue(const Coord& xyz, bool& state, int& level, AccessorT&) const
646 {
647 const Index offset = this->coordToOffset(xyz);
648 state = mValueMask.isOn(offset);
649 level = LEVEL;
650 return mBuffer[offset];
651 }
652
653 /// @brief Return the LEVEL (=0) at which leaf node values reside.
654 /// @note Used internally by ValueAccessor (note last argument is a dummy).
655 template<typename AccessorT>
656 static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
657
658 /// @brief Return a const reference to the first value in the buffer.
659 /// @note Though it is potentially risky you can convert this
660 /// to a non-const pointer by means of const_case<ValueType*>&.
661 const ValueType& getFirstValue() const { return mBuffer[0]; }
662 /// Return a const reference to the last value in the buffer.
663 const ValueType& getLastValue() const { return mBuffer[SIZE - 1]; }
664
665 /// @brief Replace inactive occurrences of @a oldBackground with @a newBackground,
666 /// and inactive occurrences of @a -oldBackground with @a -newBackground.
667 void resetBackground(const ValueType& oldBackground, const ValueType& newBackground);
668
669 void negate();
670
671 /// @brief No-op
672 /// @details This function exists only to enable template instantiation.
673 void voxelizeActiveTiles(bool = true) {}
674
675 template<MergePolicy Policy> void merge(const LeafNode&);
676 template<MergePolicy Policy> void merge(const ValueType& tileValue, bool tileActive);
677 template<MergePolicy Policy>
678 void merge(const LeafNode& other, const ValueType& /*bg*/, const ValueType& /*otherBG*/);
679
680 /// @brief Union this node's set of active values with the active values
681 /// of the other node, whose @c ValueType may be different. So a
682 /// resulting voxel will be active if either of the original voxels
683 /// were active.
684 ///
685 /// @note This operation modifies only active states, not values.
686 template<typename OtherType>
687 void topologyUnion(const LeafNode<OtherType, Log2Dim>& other, const bool preserveTiles = false);
688
689 /// @brief Intersect this node's set of active values with the active values
690 /// of the other node, whose @c ValueType may be different. So a
691 /// resulting voxel will be active only if both of the original voxels
692 /// were active.
693 ///
694 /// @details The last dummy argument is required to match the signature
695 /// for InternalNode::topologyIntersection.
696 ///
697 /// @note This operation modifies only active states, not
698 /// values. Also note that this operation can result in all voxels
699 /// being inactive so consider subsequently calling prune.
700 template<typename OtherType>
702
703 /// @brief Difference this node's set of active values with the active values
704 /// of the other node, whose @c ValueType may be different. So a
705 /// resulting voxel will be active only if the original voxel is
706 /// active in this LeafNode and inactive in the other LeafNode.
707 ///
708 /// @details The last dummy argument is required to match the signature
709 /// for InternalNode::topologyDifference.
710 ///
711 /// @note This operation modifies only active states, not values.
712 /// Also, because it can deactivate all of this node's voxels,
713 /// consider subsequently calling prune.
714 template<typename OtherType>
716
717 template<typename CombineOp>
718 void combine(const LeafNode& other, CombineOp& op);
719 template<typename CombineOp>
720 void combine(const ValueType& value, bool valueIsActive, CombineOp& op);
721
722 template<typename CombineOp, typename OtherType /*= ValueType*/>
723 void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
724 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
725 void combine2(const ValueType&, const OtherNodeT& other, bool valueIsActive, CombineOp&);
726 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
727 void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
728
729 //@{
730 /// This function exists only to enable template instantiation.
731 void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
733 template<typename AccessorT>
734 void addLeafAndCache(LeafNode*, AccessorT&) {}
735 template<typename NodeT>
736 NodeT* stealNode(const Coord&, const ValueType&, bool) { return nullptr; }
737 template<typename NodeT>
738 NodeT* probeNode(const Coord&) { return nullptr; }
739 template<typename NodeT>
740 const NodeT* probeConstNode(const Coord&) const { return nullptr; }
741 template<typename ArrayT> void getNodes(ArrayT&) const {}
742 template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
743 //@}
744
745 void addTile(Index level, const Coord&, const ValueType&, bool);
746 void addTile(Index offset, const ValueType&, bool);
747 template<typename AccessorT>
748 void addTileAndCache(Index, const Coord&, const ValueType&, bool, AccessorT&);
749
750 //@{
751 /// @brief Return a pointer to this node.
752 LeafNode* touchLeaf(const Coord&) { return this; }
753 template<typename AccessorT>
754 LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
755 template<typename NodeT, typename AccessorT>
756 NodeT* probeNodeAndCache(const Coord&, AccessorT&)
757 {
759 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
760 return reinterpret_cast<NodeT*>(this);
762 }
763 LeafNode* probeLeaf(const Coord&) { return this; }
764 template<typename AccessorT>
765 LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
766 //@}
767 //@{
768 /// @brief Return a @const pointer to this node.
769 const LeafNode* probeConstLeaf(const Coord&) const { return this; }
770 template<typename AccessorT>
771 const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
772 template<typename AccessorT>
773 const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
774 const LeafNode* probeLeaf(const Coord&) const { return this; }
775 template<typename NodeT, typename AccessorT>
776 const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
777 {
779 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
780 return reinterpret_cast<const NodeT*>(this);
782 }
783 //@}
784
785 /// Return @c true if all of this node's values have the same active state
786 /// and are in the range this->getFirstValue() +/- @a tolerance.
787 ///
788 ///
789 /// @param firstValue Is updated with the first value of this leaf node.
790 /// @param state Is updated with the state of all values IF method
791 /// returns @c true. Else the value is undefined!
792 /// @param tolerance The tolerance used to determine if values are
793 /// approximately equal to the for value.
794 bool isConstant(ValueType& firstValue, bool& state,
795 const ValueType& tolerance = zeroVal<ValueType>()) const;
796
797 /// Return @c true if all of this node's values have the same active state
798 /// and the range (@a maxValue - @a minValue) < @a tolerance.
799 ///
800 /// @param minValue Is updated with the minimum of all values IF method
801 /// returns @c true. Else the value is undefined!
802 /// @param maxValue Is updated with the maximum of all values IF method
803 /// returns @c true. Else the value is undefined!
804 /// @param state Is updated with the state of all values IF method
805 /// returns @c true. Else the value is undefined!
806 /// @param tolerance The tolerance used to determine if values are
807 /// approximately constant.
808 bool isConstant(ValueType& minValue, ValueType& maxValue,
809 bool& state, const ValueType& tolerance = zeroVal<ValueType>()) const;
810
811
812 /// @brief Computes the median value of all the active AND inactive voxels in this node.
813 /// @return The median value of all values in this node.
814 ///
815 /// @param tmp Optional temporary storage that can hold at least NUM_VALUES values
816 /// Use of this temporary storage can improve performance
817 /// when this method is called multiple times.
818 ///
819 /// @note If tmp = this->buffer().data() then the median
820 /// value is computed very efficiently (in place) but
821 /// the voxel values in this node are re-shuffled!
822 ///
823 /// @warning If tmp != nullptr then it is the responsibility of
824 /// the client code that it points to enough memory to
825 /// hold NUM_VALUES elements of type ValueType.
826 ValueType medianAll(ValueType *tmp = nullptr) const;
827
828 /// @brief Computes the median value of all the active voxels in this node.
829 /// @return The number of active voxels.
830 ///
831 /// @param value If the return value is non zero @a value is updated
832 /// with the median value.
833 ///
834 /// @param tmp Optional temporary storage that can hold at least
835 /// as many values as there are active voxels in this node.
836 /// Use of this temporary storage can improve performance
837 /// when this method is called multiple times.
838 ///
839 /// @warning If tmp != nullptr then it is the responsibility of
840 /// the client code that it points to enough memory to
841 /// hold the number of active voxels of type ValueType.
842 Index medianOn(ValueType &value, ValueType *tmp = nullptr) const;
843
844 /// @brief Computes the median value of all the inactive voxels in this node.
845 /// @return The number of inactive voxels.
846 ///
847 /// @param value If the return value is non zero @a value is updated
848 /// with the median value.
849 ///
850 /// @param tmp Optional temporary storage that can hold at least
851 /// as many values as there are inactive voxels in this node.
852 /// Use of this temporary storage can improve performance
853 /// when this method is called multiple times.
854 ///
855 /// @warning If tmp != nullptr then it is the responsibility of
856 /// the client code that it points to enough memory to
857 /// hold the number of inactive voxels of type ValueType.
858 Index medianOff(ValueType &value, ValueType *tmp = nullptr) const;
859
860 /// Return @c true if all of this node's values are inactive.
861 bool isInactive() const { return mValueMask.isOff(); }
862
863 //
864 // Unsafe methods
865 //
866 // These methods are not in fact unsafe, but are only offered so that
867 // the same methods can be called on both internal nodes and leaf nodes.
868
869 /// Return the value of the voxel at the given offset.
870 const ValueType& getValueUnsafe(Index offset) const { return this->getValue(offset); }
871 /// Return true if the voxel at the given offset is active and set value.
872 bool getValueUnsafe(Index offset, ValueType& value) const { return this->probeValue(offset, value); }
873 /// Set the active state of the voxel at the given offset but don't change its value.
874 void setActiveStateUnsafe(Index offset, bool on) { this->setActiveState(offset, on); }
875 /// Set the value of the voxel at the given coordinates but don't change its active state.
876 void setValueOnlyUnsafe(Index offset, const ValueType& value) { return this->setValueOnly(offset, value); }
877 /// Mark the voxel at the given offset as active but don't change its value.
878 void setValueOnUnsafe(Index offset) { this->setValueOn(offset); }
879 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
880 void setValueOnUnsafe(Index offset, const ValueType& value) { this->setValueOn(offset, value); }
881 /// Mark the voxel at the given offset as inactive but don't change its value.
882 void setValueOffUnsafe(Index offset) { this->setValueOff(offset); }
883 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
884 void setValueOffUnsafe(Index offset, const ValueType& value) { this->setValueOff(offset, value); }
885
886protected:
887 friend class ::TestLeaf;
888 template<typename> friend class ::TestLeafIO;
889
890 // During topology-only construction, access is needed
891 // to protected/private members of other template instances.
892 template<typename, Index> friend class LeafNode;
893
894 friend struct ValueIter<MaskOnIterator, LeafNode, ValueType, ValueOn>;
895 friend struct ValueIter<MaskOffIterator, LeafNode, ValueType, ValueOff>;
896 friend struct ValueIter<MaskDenseIterator, LeafNode, ValueType, ValueAll>;
897 friend struct ValueIter<MaskOnIterator, const LeafNode, ValueType, ValueOn>;
898 friend struct ValueIter<MaskOffIterator, const LeafNode, ValueType, ValueOff>;
899 friend struct ValueIter<MaskDenseIterator, const LeafNode, ValueType, ValueAll>;
900
901 // Allow iterators to call mask accessor methods (see below).
902 /// @todo Make mask accessors public?
903 friend class IteratorBase<MaskOnIterator, LeafNode>;
906
907 // Mask accessors
908public:
909 bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
910 bool isValueMaskOn() const { return mValueMask.isOn(); }
911 bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
912 bool isValueMaskOff() const { return mValueMask.isOff(); }
913 const NodeMaskType& getValueMask() const { return mValueMask; }
914 NodeMaskType& getValueMask() { return mValueMask; }
915 const NodeMaskType& valueMask() const { return mValueMask; }
916 void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
917 bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
918 bool isChildMaskOff(Index) const { return true; }
919 bool isChildMaskOff() const { return true; }
920protected:
921 void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
922 void setValueMaskOn(Index n) { mValueMask.setOn(n); }
923 void setValueMaskOff(Index n) { mValueMask.setOff(n); }
924
925
926#if OPENVDB_ABI_VERSION_NUMBER < 14
927 inline void skipCompressedValues(bool seekable, std::istream&, bool fromHalf);
928#endif // OPENVDB_ABI_VERSION_NUMBER < 14
929
930 /// Compute the origin of the leaf node that contains the voxel with the given coordinates.
931 static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
932
933private:
934 /// Buffer containing the actual data values
935 Buffer mBuffer;
936 /// Bitmask that determines which voxels are active
937 NodeMaskType mValueMask;
938 /// Global grid index coordinates (x,y,z) of the local origin of this node
939 Coord mOrigin;
940 /// Transient data (not serialized)
941 Index32 mTransientData = 0;
942}; // end of LeafNode class
943
944
945////////////////////////////////////////
946
947
948//@{
949/// Helper metafunction used to implement LeafNode::SameConfiguration
950/// (which, as an inner class, can't be independently specialized)
951template<Index Dim1, typename NodeT2>
952struct SameLeafConfig { static const bool value = false; };
953
954template<Index Dim1, typename T2>
955struct SameLeafConfig<Dim1, LeafNode<T2, Dim1> > { static const bool value = true; };
956//@}
957
958
959////////////////////////////////////////
960
961
962template<typename T, Index Log2Dim>
963inline
965 mValueMask(),//default is off!
966 mOrigin(0, 0, 0)
967{
968}
969
970
971template<typename T, Index Log2Dim>
972inline
973LeafNode<T, Log2Dim>::LeafNode(const Coord& xyz, const ValueType& val, bool active):
974 mBuffer(val),
975 mValueMask(active),
976 mOrigin(xyz & (~(DIM - 1)))
977{
978}
979
980
981template<typename T, Index Log2Dim>
982inline
983LeafNode<T, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, const ValueType& val, bool active):
984 mBuffer(PartialCreate(), val),
985 mValueMask(active),
986 mOrigin(xyz & (~(DIM - 1)))
987{
988}
989
990
991template<typename T, Index Log2Dim>
992inline
994 : mBuffer(other.mBuffer)
995 , mValueMask(other.valueMask())
996 , mOrigin(other.mOrigin)
997 , mTransientData(other.mTransientData)
998{
999}
1000
1001
1002// Copy-construct from a leaf node with the same configuration but a different ValueType.
1003template<typename T, Index Log2Dim>
1004template<typename OtherValueType>
1005inline
1007 : mValueMask(other.valueMask())
1008 , mOrigin(other.mOrigin)
1009 , mTransientData(other.mTransientData)
1010{
1011 struct Local {
1012 /// @todo Consider using a value conversion functor passed as an argument instead.
1013 static inline ValueType convertValue(const OtherValueType& val) {
1015 return ValueType(val);
1017 }
1018 };
1019
1020 for (Index i = 0; i < SIZE; ++i) {
1021 mBuffer[i] = Local::convertValue(other.mBuffer[i]);
1022 }
1023}
1024
1025
1026template<typename T, Index Log2Dim>
1027template<typename OtherValueType>
1028inline
1030 const ValueType& background, TopologyCopy)
1031 : mBuffer(background)
1032 , mValueMask(other.valueMask())
1033 , mOrigin(other.mOrigin)
1034 , mTransientData(other.mTransientData)
1035{
1036}
1037
1038
1039template<typename T, Index Log2Dim>
1040template<typename OtherValueType>
1041inline
1043 const ValueType& offValue, const ValueType& onValue, TopologyCopy)
1044 : mValueMask(other.valueMask())
1045 , mOrigin(other.mOrigin)
1046 , mTransientData(other.mTransientData)
1047{
1048 for (Index i = 0; i < SIZE; ++i) {
1049 mBuffer[i] = (mValueMask.isOn(i) ? onValue : offValue);
1050 }
1051}
1052
1053
1054template<typename T, Index Log2Dim>
1055inline
1059
1060
1061template<typename T, Index Log2Dim>
1062inline std::string
1064{
1065 std::ostringstream ostr;
1066 ostr << "LeafNode @" << mOrigin << ": " << mBuffer;
1067 return ostr.str();
1068}
1069
1070
1071////////////////////////////////////////
1072
1073
1074template<typename T, Index Log2Dim>
1075inline Index
1077{
1078 OPENVDB_ASSERT((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
1079 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
1080 + ((xyz[1] & (DIM-1u)) << Log2Dim)
1081 + (xyz[2] & (DIM-1u));
1082}
1083
1084template<typename T, Index Log2Dim>
1085inline Coord
1087{
1088 OPENVDB_ASSERT(n<(1<< 3*Log2Dim));
1089 Coord xyz;
1090 xyz.setX(n >> 2*Log2Dim);
1091 n &= ((1<<2*Log2Dim)-1);
1092 xyz.setY(n >> Log2Dim);
1093 xyz.setZ(n & ((1<<Log2Dim)-1));
1094 return xyz;
1095}
1096
1097
1098template<typename T, Index Log2Dim>
1099inline Coord
1101{
1102 return (this->offsetToLocalCoord(n) + this->origin());
1103}
1104
1105
1106////////////////////////////////////////
1107
1108
1109template<typename ValueT, Index Log2Dim>
1110inline const ValueT&
1112{
1113 return this->getValue(LeafNode::coordToOffset(xyz));
1114}
1115
1116template<typename ValueT, Index Log2Dim>
1117inline const ValueT&
1119{
1120 OPENVDB_ASSERT(offset < SIZE);
1121 return mBuffer[offset];
1122}
1123
1124
1125template<typename T, Index Log2Dim>
1126inline bool
1128{
1129 return this->probeValue(LeafNode::coordToOffset(xyz), val);
1130}
1131
1132template<typename T, Index Log2Dim>
1133inline bool
1135{
1136 OPENVDB_ASSERT(offset < SIZE);
1137 val = mBuffer[offset];
1138 return mValueMask.isOn(offset);
1139}
1140
1141
1142template<typename T, Index Log2Dim>
1143inline void
1145{
1146 this->setValueOff(LeafNode::coordToOffset(xyz), val);
1147}
1148
1149template<typename T, Index Log2Dim>
1150inline void
1152{
1153 OPENVDB_ASSERT(offset < SIZE);
1154 mBuffer.setValue(offset, val);
1155 mValueMask.setOff(offset);
1156}
1157
1158
1159template<typename T, Index Log2Dim>
1160inline void
1162{
1163 mValueMask.set(this->coordToOffset(xyz), on);
1164}
1165
1166
1167template<typename T, Index Log2Dim>
1168inline void
1170{
1171 this->setValueOnly(LeafNode::coordToOffset(xyz), val);
1172}
1173
1174template<typename T, Index Log2Dim>
1175inline void
1177{
1178 OPENVDB_ASSERT(offset<SIZE); mBuffer.setValue(offset, val);
1179}
1180
1181
1182////////////////////////////////////////
1183
1184
1185template<typename T, Index Log2Dim>
1186inline void
1187LeafNode<T, Log2Dim>::clip(const CoordBBox& clipBBox, const T& background)
1188{
1189 CoordBBox nodeBBox = this->getNodeBoundingBox();
1190 if (!clipBBox.hasOverlap(nodeBBox)) {
1191 // This node lies completely outside the clipping region. Fill it with the background.
1192 this->fill(background, /*active=*/false);
1193 } else if (clipBBox.isInside(nodeBBox)) {
1194 // This node lies completely inside the clipping region. Leave it intact.
1195 return;
1196 }
1197
1198 // This node isn't completely contained inside the clipping region.
1199 // Set any voxels that lie outside the region to the background value.
1200
1201 // Construct a boolean mask that is on inside the clipping region and off outside it.
1202 NodeMaskType mask;
1203 nodeBBox.intersect(clipBBox);
1204 Coord xyz;
1205 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1206 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1207 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1208 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1209 mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1210 }
1211 }
1212 }
1213
1214 // Set voxels that lie in the inactive region of the mask (i.e., outside
1215 // the clipping region) to the background value.
1216 for (MaskOffIterator maskIter = mask.beginOff(); maskIter; ++maskIter) {
1217 this->setValueOff(maskIter.pos(), background);
1218 }
1219}
1220
1221
1222////////////////////////////////////////
1223
1224
1225template<typename T, Index Log2Dim>
1226inline void
1227LeafNode<T, Log2Dim>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1228{
1229 if (!this->allocate()) return;
1230
1231 auto clippedBBox = this->getNodeBoundingBox();
1232 clippedBBox.intersect(bbox);
1233 if (!clippedBBox) return;
1234
1235 for (Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1236 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1237 for (Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1238 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1239 for (Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1240 const Index offset = offsetXY + (z & (DIM-1u));
1241 mBuffer[offset] = value;
1242 mValueMask.set(offset, active);
1243 }
1244 }
1245 }
1246}
1247
1248template<typename T, Index Log2Dim>
1249inline void
1251{
1252 mBuffer.fill(value);
1253}
1254
1255template<typename T, Index Log2Dim>
1256inline void
1257LeafNode<T, Log2Dim>::fill(const ValueType& value, bool active)
1258{
1259 mBuffer.fill(value);
1260 mValueMask.set(active);
1261}
1262
1263
1264////////////////////////////////////////
1265
1266
1267template<typename T, Index Log2Dim>
1268template<typename DenseT>
1269inline void
1270LeafNode<T, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1271{
1272 using DenseValueType = typename DenseT::ValueType;
1273
1274 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1275 const Coord& min = dense.bbox().min();
1276 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1277 const T* s0 = &mBuffer[bbox.min()[2] & (DIM-1u)]; // source array
1278 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1279 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1280 const T* s1 = s0 + ((x & (DIM-1u)) << 2*Log2Dim);
1281 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1282 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1283 const T* s2 = s1 + ((y & (DIM-1u)) << Log2Dim);
1284 for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1285 *t2 = DenseValueType(*s2++);
1286 }
1287 }
1288 }
1289}
1290
1291
1292template<typename T, Index Log2Dim>
1293template<typename DenseT>
1294inline void
1295LeafNode<T, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1296 const ValueType& background, const ValueType& tolerance)
1297{
1298 if (!this->allocate()) return;
1299
1300 using DenseValueType = typename DenseT::ValueType;
1301
1302 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1303 const Coord& min = dense.bbox().min();
1304
1305 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1306 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1307 for (Int32 x = bbox.min()[0], ex = bbox.max()[0]+1; x < ex; ++x) {
1308 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1309 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1310 for (Int32 y = bbox.min()[1], ey = bbox.max()[1]+1; y < ey; ++y) {
1311 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1312 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1313 for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1314 if (math::isApproxEqual(background, ValueType(*s2), tolerance)) {
1315 mValueMask.setOff(n2);
1316 mBuffer[n2] = background;
1317 } else {
1318 mValueMask.setOn(n2);
1319 mBuffer[n2] = ValueType(*s2);
1320 }
1321 }
1322 }
1323 }
1324}
1325
1326
1327////////////////////////////////////////
1328
1329
1330#if OPENVDB_ABI_VERSION_NUMBER < 14
1331
1332template<typename T, Index Log2Dim>
1333inline void
1334LeafNode<T, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
1335{
1336 mValueMask.load(is);
1337}
1338
1339
1340template<typename T, Index Log2Dim>
1341inline void
1342LeafNode<T, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
1343{
1344 mValueMask.save(os);
1345}
1346
1347
1348template<typename T, Index Log2Dim>
1349inline void
1350LeafNode<T,Log2Dim>::skipCompressedValues(bool seekable, std::istream& is, bool fromHalf)
1351{
1352 if (seekable) {
1353 // Seek over voxel values.
1355 is, nullptr, SIZE, mValueMask, fromHalf);
1356 } else {
1357 // Read and discard voxel values.
1358 Buffer temp;
1359 io::readCompressedValues(is, temp.mData, SIZE, mValueMask, fromHalf);
1360 }
1361}
1362
1363
1364template<typename T, Index Log2Dim>
1365inline void
1366LeafNode<T,Log2Dim>::readBuffers(std::istream& is, bool fromHalf)
1367{
1368 this->readBuffers(is, CoordBBox::inf(), fromHalf);
1369}
1370
1371
1372template<typename T, Index Log2Dim>
1373inline void
1374LeafNode<T,Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
1375{
1377
1379 const bool seekable = meta && meta->seekable();
1380
1381 if (seekable) {
1382 // Seek over the value mask.
1383 mValueMask.seek(is);
1384 } else {
1385 // Read in the value mask.
1386 mValueMask.load(is);
1387 }
1388
1389 int8_t numBuffers = 1;
1391 // Read in the origin.
1392 is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1393
1394 // Read in the number of buffers, which should now always be one.
1395 is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1396 }
1397
1398 CoordBBox nodeBBox = this->getNodeBoundingBox();
1399 if (!clipBBox.hasOverlap(nodeBBox)) {
1400 // This node lies completely outside the clipping region.
1401 skipCompressedValues(seekable, is, fromHalf);
1402 mValueMask.setOff();
1403 } else {
1404 mBuffer.allocate();
1405 io::readCompressedValues(is, mBuffer.mData, SIZE, mValueMask, fromHalf);
1406
1407 // Get this tree's background value.
1408 T background = zeroVal<T>();
1409 if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
1410 background = *static_cast<const T*>(bgPtr);
1411 }
1412 this->clip(clipBBox, background);
1413 }
1414
1415 if (numBuffers > 1) {
1416 // Read in and discard auxiliary buffers that were created with earlier
1417 // versions of the library. (Auxiliary buffers are not mask compressed.)
1418 const bool zipped = io::getDataCompression(is) & io::COMPRESS_ZIP;
1419 Buffer temp;
1420 for (int i = 1; i < numBuffers; ++i) {
1421 if (fromHalf) {
1422 io::HalfReader<io::RealToHalf<T>::isReal, T>::read(is, temp.mData, SIZE, zipped);
1423 } else {
1424 io::readData<T>(is, temp.mData, SIZE, zipped);
1425 }
1426 }
1427 }
1428}
1429
1430
1431template<typename T, Index Log2Dim>
1432inline void
1433LeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
1434{
1435 // Write out the value mask.
1436 mValueMask.save(os);
1437
1438 io::writeCompressedValues(os, mBuffer.mData, SIZE,
1439 mValueMask, /*childMask=*/NodeMaskType(), toHalf);
1440}
1441
1442#endif // OPENVDB_ABI_VERSION_NUMBER < 14
1443
1444
1445////////////////////////////////////////
1446
1447
1448template<typename T, Index Log2Dim>
1449inline bool
1451{
1452 return mOrigin == other.mOrigin &&
1453 mValueMask == other.valueMask() &&
1454 mBuffer == other.mBuffer;
1455}
1456
1457
1458template<typename T, Index Log2Dim>
1459inline Index64
1461{
1462 // Use sizeof(*this) to capture alignment-related padding
1463 // (but note that sizeof(*this) includes sizeof(mBuffer)).
1464 return sizeof(*this) + mBuffer.memUsage() - sizeof(mBuffer);
1465}
1466
1467
1468template<typename T, Index Log2Dim>
1469inline void
1471{
1472 CoordBBox this_bbox = this->getNodeBoundingBox();
1473 if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
1474 if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
1475 if (visitVoxels) {//use voxel granularity?
1476 this_bbox.reset();
1477 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
1478 this_bbox.translate(this->origin());
1479 }
1480 bbox.expand(this_bbox);
1481 }
1482}
1483
1484
1485template<typename T, Index Log2Dim>
1486template<typename OtherType, Index OtherLog2Dim>
1487inline bool
1489{
1490 OPENVDB_ASSERT(other);
1491 return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
1492}
1493
1494template<typename T, Index Log2Dim>
1495inline bool
1497 bool& state,
1498 const ValueType& tolerance) const
1499{
1500 if (!mValueMask.isConstant(state)) return false;// early termination
1501 firstValue = mBuffer[0];
1502 for (Index i = 1; i < SIZE; ++i) {
1503 if ( !math::isApproxEqual(mBuffer[i], firstValue, tolerance) ) return false;// early termination
1504 }
1505 return true;
1506}
1507
1508template<typename T, Index Log2Dim>
1509inline bool
1511 ValueType& maxValue,
1512 bool& state,
1513 const ValueType& tolerance) const
1514{
1515 if (!mValueMask.isConstant(state)) return false;// early termination
1516 minValue = maxValue = mBuffer[0];
1517 for (Index i = 1; i < SIZE; ++i) {
1518 const T& v = mBuffer[i];
1519 if (math::cwiseLessThan(v, minValue)) {
1520 if (math::cwiseGreaterThan((maxValue - v), tolerance)) return false;// early termination
1521 minValue = v;
1522 } else if (math::cwiseGreaterThan(v, maxValue)) {
1523 if (math::cwiseGreaterThan((v - minValue), tolerance)) return false;// early termination
1524 maxValue = v;
1525 }
1526 }
1527 return true;
1528}
1529
1530template<typename T, Index Log2Dim>
1531inline T
1533{
1534 std::unique_ptr<T[]> data(nullptr);
1535 if (tmp == nullptr) {//allocate temporary storage
1536 data.reset(new T[NUM_VALUES]);
1537 tmp = data.get();
1538 }
1539 if (tmp != mBuffer.data()) {
1540 const T* src = mBuffer.data();
1541 for (T* dst = tmp; dst-tmp < NUM_VALUES;) *dst++ = *src++;
1542 }
1543 static const size_t midpoint = (NUM_VALUES - 1) >> 1;
1544 std::nth_element(tmp, tmp + midpoint, tmp + NUM_VALUES,
1545 [](const auto& a, const auto& b) {
1546 return math::cwiseLessThan(a, b);
1547 });
1548 return tmp[midpoint];
1549}
1550
1551template<typename T, Index Log2Dim>
1552inline Index
1553LeafNode<T, Log2Dim>::medianOn(T &value, T *tmp) const
1554{
1555 const Index count = mValueMask.countOn();
1556 if (count == NUM_VALUES) {//special case: all voxels are active
1557 value = this->medianAll(tmp);
1558 return NUM_VALUES;
1559 } else if (count == 0) {
1560 return 0;
1561 }
1562 std::unique_ptr<T[]> data(nullptr);
1563 if (tmp == nullptr) {//allocate temporary storage
1564 data.reset(new T[count]);// 0 < count < NUM_VALUES
1565 tmp = data.get();
1566 }
1567 for (auto iter=this->cbeginValueOn(); iter; ++iter) *tmp++ = *iter;
1568 T *begin = tmp - count;
1569 const size_t midpoint = (count - 1) >> 1;
1570 std::nth_element(begin, begin + midpoint, tmp,
1571 [](const auto& a, const auto& b) {
1572 return math::cwiseLessThan(a, b);
1573 });
1574 value = begin[midpoint];
1575 return count;
1576}
1577
1578template<typename T, Index Log2Dim>
1579inline Index
1580LeafNode<T, Log2Dim>::medianOff(T &value, T *tmp) const
1581{
1582 const Index count = mValueMask.countOff();
1583 if (count == NUM_VALUES) {//special case: all voxels are inactive
1584 value = this->medianAll(tmp);
1585 return NUM_VALUES;
1586 } else if (count == 0) {
1587 return 0;
1588 }
1589 std::unique_ptr<T[]> data(nullptr);
1590 if (tmp == nullptr) {//allocate temporary storage
1591 data.reset(new T[count]);// 0 < count < NUM_VALUES
1592 tmp = data.get();
1593 }
1594 for (auto iter=this->cbeginValueOff(); iter; ++iter) *tmp++ = *iter;
1595 T *begin = tmp - count;
1596 const size_t midpoint = (count - 1) >> 1;
1597 std::nth_element(begin, begin + midpoint, tmp,
1598 [](const auto& a, const auto& b) {
1599 return math::cwiseLessThan(a, b);
1600 });
1601 value = begin[midpoint];
1602 return count;
1603}
1604
1605////////////////////////////////////////
1606
1607
1608template<typename T, Index Log2Dim>
1609inline void
1610LeafNode<T, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, const ValueType& val, bool active)
1611{
1612 this->addTile(this->coordToOffset(xyz), val, active);
1613}
1614
1615template<typename T, Index Log2Dim>
1616inline void
1617LeafNode<T, Log2Dim>::addTile(Index offset, const ValueType& val, bool active)
1618{
1619 OPENVDB_ASSERT(offset < SIZE);
1620 setValueOnly(offset, val);
1621 setActiveState(offset, active);
1622}
1623
1624template<typename T, Index Log2Dim>
1625template<typename AccessorT>
1626inline void
1628 const ValueType& val, bool active, AccessorT&)
1629{
1630 this->addTile(level, xyz, val, active);
1631}
1632
1633
1634////////////////////////////////////////
1635
1636
1637template<typename T, Index Log2Dim>
1638inline void
1640 const ValueType& newBackground)
1641{
1642 if (!this->allocate()) return;
1643 if (math::isExactlyEqual(oldBackground, newBackground)) return;
1644
1646 // For all inactive values...
1647 for (iter = this->mValueMask.beginOff(); iter; ++iter) {
1648 ValueType &inactiveValue = mBuffer[iter.pos()];
1649 if (math::isApproxEqual(inactiveValue, oldBackground)) {
1650 inactiveValue = newBackground;
1651 } else if (math::isApproxEqual(inactiveValue, math::negative(oldBackground))) {
1652 inactiveValue = math::negative(newBackground);
1653 }
1654 }
1655}
1656
1657
1658template<typename T, Index Log2Dim>
1659template<MergePolicy Policy>
1660inline void
1662{
1663 if (!this->allocate()) return;
1664
1666 if (Policy == MERGE_NODES) return;
1667 typename NodeMaskType::OnIterator iter = other.valueMask().beginOn();
1668 for (; iter; ++iter) {
1669 const Index n = iter.pos();
1670 if (mValueMask.isOff(n)) {
1671 mBuffer[n] = other.mBuffer[n];
1672 mValueMask.setOn(n);
1673 }
1674 }
1676}
1677
1678template<typename T, Index Log2Dim>
1679template<MergePolicy Policy>
1680inline void
1682 const ValueType& /*bg*/, const ValueType& /*otherBG*/)
1683{
1684 this->template merge<Policy>(other);
1685}
1686
1687template<typename T, Index Log2Dim>
1688template<MergePolicy Policy>
1689inline void
1690LeafNode<T, Log2Dim>::merge(const ValueType& tileValue, bool tileActive)
1691{
1692 if (!this->allocate()) return;
1693
1695 if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1696 if (!tileActive) return;
1697 // Replace all inactive values with the active tile value.
1698 for (typename NodeMaskType::OffIterator iter = mValueMask.beginOff(); iter; ++iter) {
1699 const Index n = iter.pos();
1700 mBuffer[n] = tileValue;
1701 mValueMask.setOn(n);
1702 }
1704}
1705
1706
1707template<typename T, Index Log2Dim>
1708template<typename OtherType>
1709inline void
1711{
1712 mValueMask |= other.valueMask();
1713}
1714
1715template<typename T, Index Log2Dim>
1716template<typename OtherType>
1717inline void
1719 const ValueType&)
1720{
1721 mValueMask &= other.valueMask();
1722}
1723
1724template<typename T, Index Log2Dim>
1725template<typename OtherType>
1726inline void
1728 const ValueType&)
1729{
1730 mValueMask &= !other.valueMask();
1731}
1732
1733template<typename T, Index Log2Dim>
1734inline void
1736{
1737 if (!this->allocate()) return;
1738
1739 for (Index i = 0; i < SIZE; ++i) {
1740 mBuffer[i] = -mBuffer[i];
1741 }
1742}
1743
1744
1745////////////////////////////////////////
1746
1747
1748template<typename T, Index Log2Dim>
1749template<typename CombineOp>
1750inline void
1751LeafNode<T, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1752{
1753 if (!this->allocate()) return;
1754
1755 CombineArgs<T> args;
1756 for (Index i = 0; i < SIZE; ++i) {
1757 op(args.setARef(mBuffer[i])
1758 .setAIsActive(mValueMask.isOn(i))
1759 .setBRef(other.mBuffer[i])
1760 .setBIsActive(other.valueMask().isOn(i))
1761 .setResultRef(mBuffer[i]));
1762 mValueMask.set(i, args.resultIsActive());
1763 }
1764}
1765
1766
1767template<typename T, Index Log2Dim>
1768template<typename CombineOp>
1769inline void
1770LeafNode<T, Log2Dim>::combine(const ValueType& value, bool valueIsActive, CombineOp& op)
1771{
1772 if (!this->allocate()) return;
1773
1774 CombineArgs<T> args;
1775 args.setBRef(value).setBIsActive(valueIsActive);
1776 for (Index i = 0; i < SIZE; ++i) {
1777 op(args.setARef(mBuffer[i])
1778 .setAIsActive(mValueMask.isOn(i))
1779 .setResultRef(mBuffer[i]));
1780 mValueMask.set(i, args.resultIsActive());
1781 }
1782}
1783
1784
1785////////////////////////////////////////
1786
1787
1788template<typename T, Index Log2Dim>
1789template<typename CombineOp, typename OtherType>
1790inline void
1791LeafNode<T, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1792 bool valueIsActive, CombineOp& op)
1793{
1794 if (!this->allocate()) return;
1795
1797 args.setBRef(value).setBIsActive(valueIsActive);
1798 for (Index i = 0; i < SIZE; ++i) {
1799 op(args.setARef(other.mBuffer[i])
1800 .setAIsActive(other.valueMask().isOn(i))
1801 .setResultRef(mBuffer[i]));
1802 mValueMask.set(i, args.resultIsActive());
1803 }
1804}
1805
1806
1807template<typename T, Index Log2Dim>
1808template<typename CombineOp, typename OtherNodeT>
1809inline void
1810LeafNode<T, Log2Dim>::combine2(const ValueType& value, const OtherNodeT& other,
1811 bool valueIsActive, CombineOp& op)
1812{
1813 if (!this->allocate()) return;
1814
1816 args.setARef(value).setAIsActive(valueIsActive);
1817 for (Index i = 0; i < SIZE; ++i) {
1818 op(args.setBRef(other.mBuffer[i])
1819 .setBIsActive(other.valueMask().isOn(i))
1820 .setResultRef(mBuffer[i]));
1821 mValueMask.set(i, args.resultIsActive());
1822 }
1823}
1824
1825
1826template<typename T, Index Log2Dim>
1827template<typename CombineOp, typename OtherNodeT>
1828inline void
1829LeafNode<T, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1830{
1831 if (!this->allocate()) return;
1832
1834 for (Index i = 0; i < SIZE; ++i) {
1835 mValueMask.set(i, b0.valueMask().isOn(i) || b1.valueMask().isOn(i));
1836 op(args.setARef(b0.mBuffer[i])
1837 .setAIsActive(b0.valueMask().isOn(i))
1838 .setBRef(b1.mBuffer[i])
1839 .setBIsActive(b1.valueMask().isOn(i))
1840 .setResultRef(mBuffer[i]));
1841 mValueMask.set(i, args.resultIsActive());
1842 }
1843}
1844
1845
1846////////////////////////////////////////
1847
1848
1849template<typename T, Index Log2Dim>
1850inline std::ostream&
1851operator<<(std::ostream& os, const typename LeafNode<T, Log2Dim>::Buffer& buf)
1852{
1853 for (Index32 i = 0, N = buf.size(); i < N; ++i) os << buf.mData[i] << ", ";
1854 return os;
1855}
1856
1857} // namespace tree
1858} // namespace OPENVDB_VERSION_NAME
1859} // namespace openvdb
1860
1861
1862////////////////////////////////////////
1863
1864
1865// Specialization for LeafNodes of type bool
1866#include "LeafNodeBool.h"
1867
1868// Specialization for LeafNodes with mask information only
1869#include "LeafNodeMask.h"
1870
1871#endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END, to inhibit warnings about type conve...
Definition Platform.h:239
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition Platform.h:151
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
Definition Platform.h:240
#define OPENVDB_ASSUME(...)
Definition Platform.h:102
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition Platform.h:150
Definition LeafNode.h:23
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:640
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:692
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:708
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition Types.h:696
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:694
bool resultIsActive() const
Definition Types.h:703
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:706
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition Coord.h:322
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition Coord.h:316
Int32 ValueType
Definition Coord.h:33
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:760
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:754
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition Coord.h:461
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition Coord.h:421
const Coord & min() const
Definition Coord.h:324
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition Coord.h:415
const Coord & max() const
Definition Coord.h:325
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition Coord.h:403
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:447
void reset()
Definition Coord.h:330
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Int32 y() const
Definition Coord.h:132
Int32 x() const
Definition Coord.h:131
Coord & setZ(Int32 z)
Definition Coord.h:82
Coord & setY(Int32 y)
Definition Coord.h:81
Int32 z() const
Definition Coord.h:133
Coord & setX(Int32 x)
Definition Coord.h:80
Base class for iterators over internal and leaf nodes.
Definition Iterator.h:30
Array of fixed size 23Log2Dim that stores the voxel values of a LeafNode.
Definition LeafBuffer.h:34
static Index size()
Return the number of values contained in this buffer.
Definition LeafBuffer.h:88
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition LeafNode.h:39
void stealNodes(ArrayT &, const ValueType &, bool)
Definition LeafNode.h:742
void setValueOff(Index offset, const ValueType &val)
Set the value of the voxel at the given offset and mark the voxel as inactive.
Definition LeafNode.h:1151
LeafNode & operator=(const LeafNode &)=default
Deep assignment operator.
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:636
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition LeafNode.h:509
void addTile(Index offset, const ValueType &, bool)
Definition LeafNode.h:1617
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition LeafNode.h:327
static Index64 onTileCount()
Definition LeafNode.h:149
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition LeafNode.h:178
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition LeafNode.h:1086
ValueIter< MaskOffIterator, LeafNode, const ValueType, ValueOff > ValueOffIter
Definition LeafNode.h:318
ChildOnCIter cbeginChildOn() const
Definition LeafNode.h:351
SharedPtr< LeafNode > Ptr
Definition LeafNode.h:46
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition LeafNode.h:170
NodeMaskType & getValueMask()
Definition LeafNode.h:914
bool isConstant(ValueType &minValue, ValueType &maxValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition LeafNode.h:1510
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNode.h:453
bool isChildMaskOn(Index) const
Definition LeafNode.h:917
ChildOnCIter beginChildOn() const
Definition LeafNode.h:352
ChildOnIter beginChildOn()
Definition LeafNode.h:353
LeafNode()
Default constructor.
Definition LeafNode.h:964
static Index64 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition LeafNode.h:139
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:507
ValueOnIter endValueOn()
Definition LeafNode.h:341
util::NodeMask< Log2Dim > NodeMaskType
Definition LeafNode.h:45
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:1270
bool isChildMaskOff() const
Definition LeafNode.h:919
ValueOffCIter cbeginValueOff() const
Definition LeafNode.h:332
Index32 transientData() const
Return the transient data value.
Definition LeafNode.h:190
static Index32 childCount()
Return the child count for this node, which is zero.
Definition LeafNode.h:141
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:459
LeafNode(const LeafNode &)
Deep copy constructor.
Definition LeafNode.h:993
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition LeafNode.h:133
bool operator!=(const LeafNode &other) const
Definition LeafNode.h:204
static Index64 leafCount()
Return the leaf count for this node, which is one.
Definition LeafNode.h:135
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:1295
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:1111
ChildIter< MaskOnIterator, LeafNode, ChildOn > ChildOnIter
Definition LeafNode.h:322
void setValueMask(const NodeMaskType &mask)
Definition LeafNode.h:916
ChildOnIter endChildOn()
Definition LeafNode.h:363
ValueAllIter endValueAll()
Definition LeafNode.h:347
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition LeafNode.h:752
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:1169
LeafNode * probeLeaf(const Coord &)
Definition LeafNode.h:763
bool isValueMaskOff() const
Definition LeafNode.h:912
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition LeafNode.h:731
bool isValueMaskOn() const
Definition LeafNode.h:910
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:1727
LeafBuffer< ValueType, Log2Dim > Buffer
Definition LeafNode.h:43
void getNodes(ArrayT &) const
Definition LeafNode.h:741
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition LeafNode.h:504
ValueAllCIter endValueAll() const
Definition LeafNode.h:346
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition LeafNode.h:1580
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:455
Index64 onLeafVoxelCount() const
Definition LeafNode.h:147
ChildOffCIter endChildOff() const
Definition LeafNode.h:365
void merge(const ValueType &tileValue, bool tileActive)
Definition LeafNode.h:1690
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition LeafNode.h:1532
bool getValueUnsafe(Index offset, ValueType &value) const
Return true if the voxel at the given offset is active and set value.
Definition LeafNode.h:872
~LeafNode()
Destructor.
Definition LeafNode.h:1056
bool probeValue(Index offset, ValueType &val) const
Return true if the voxel at the given offset is active.
Definition LeafNode.h:1134
ValueAllCIter cbeginValueAll() const
Definition LeafNode.h:335
NodeT * probeNode(const Coord &)
Definition LeafNode.h:738
ChildIter< MaskOffIterator, LeafNode, ChildOff > ChildOffIter
Definition LeafNode.h:324
ValueOnCIter beginValueOn() const
Definition LeafNode.h:330
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition LeafNode.h:931
const Buffer & buffer() const
Definition LeafNode.h:377
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:765
void setValueMaskOn(Index n)
Definition LeafNode.h:922
void setValueOnlyUnsafe(Index offset, const ValueType &value)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition LeafNode.h:876
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition LeafNode.h:1553
Index64 offLeafVoxelCount() const
Definition LeafNode.h:148
const LeafNode * probeLeaf(const Coord &) const
Definition LeafNode.h:774
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition LeafNode.h:1610
ChildIter< MaskOffIterator, const LeafNode, ChildOff > ChildOffCIter
Definition LeafNode.h:325
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition LeafNode.h:1639
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition LeafNode.h:173
const Coord & origin() const
Definition LeafNode.h:176
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition LeafNode.h:428
bool isInactive() const
Return true if all of this node's values are inactive.
Definition LeafNode.h:861
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition LeafNode.h:489
bool isValueMaskOff(Index n) const
Definition LeafNode.h:911
ValueOnCIter cendValueOn() const
Definition LeafNode.h:339
const ValueType & getValue(Index offset) const
Return the value of the voxel at the given linear offset.
Definition LeafNode.h:1118
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition LeafNode.h:156
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition LeafNode.h:656
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition LeafNode.h:127
const ValueType & getValueUnsafe(Index offset) const
Return the value of the voxel at the given offset.
Definition LeafNode.h:870
void setActiveStateUnsafe(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition LeafNode.h:874
ValueOffCIter beginValueOff() const
Definition LeafNode.h:333
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:618
LeafNode(PartialCreate, const Coord &coords, const ValueType &value=zeroVal< ValueType >(), bool active=false)
"Partial creation" constructor used during file input
Definition LeafNode.h:983
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:645
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:571
ChildAllCIter cbeginChildAll() const
Definition LeafNode.h:357
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:1718
ChildOffIter endChildOff()
Definition LeafNode.h:366
static const Index NUM_VOXELS
Definition LeafNode.h:53
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition LeafNode.h:1187
ChildAllIter beginChildAll()
Definition LeafNode.h:359
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:461
void combine2(const ValueType &, const OtherNodeT &other, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1810
ValueIter< MaskDenseIterator, LeafNode, const ValueType, ValueAll > ValueAllIter
Definition LeafNode.h:320
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition LeafNode.h:129
ValueIter< MaskOffIterator, const LeafNode, const ValueType, ValueOff > ValueOffCIter
Definition LeafNode.h:319
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:579
void addLeaf(LeafNode *)
Definition LeafNode.h:732
static const Index DIM
Definition LeafNode.h:51
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:1161
ValueOnIter beginValueOn()
Definition LeafNode.h:331
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:602
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other, const bool preserveTiles=false)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition LeafNode.h:1710
static const Index LEVEL
Definition LeafNode.h:55
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:756
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition LeafNode.h:661
ChildOffCIter cbeginChildOff() const
Definition LeafNode.h:354
ChildOffIter beginChildOff()
Definition LeafNode.h:356
bool isChildMaskOff(Index) const
Definition LeafNode.h:918
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition LeafNode.h:144
ChildOffCIter beginChildOff() const
Definition LeafNode.h:355
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition LeafNode.h:1076
static Index64 offTileCount()
Definition LeafNode.h:150
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition LeafNode.h:441
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:1488
ValueOffIter endValueOff()
Definition LeafNode.h:344
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNode.h:443
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:771
ChildAllCIter endChildAll() const
Definition LeafNode.h:368
void nodeCount(std::vector< Index64 > &) const
no-op
Definition LeafNode.h:137
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:776
ValueOnCIter cbeginValueOn() const
Definition LeafNode.h:329
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition LeafNode.h:121
void combine(const LeafNode &other, CombineOp &op)
Definition LeafNode.h:1751
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition LeafNode.h:131
ChildOnCIter endChildOn() const
Definition LeafNode.h:362
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition LeafNode.h:769
void setValueOnUnsafe(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNode.h:878
void setValueOnUnsafe(Index offset, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:880
ChildOnCIter cendChildOn() const
Definition LeafNode.h:361
void merge(const LeafNode &other, const ValueType &, const ValueType &)
Definition LeafNode.h:1681
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition LeafNode.h:516
ChildAllCIter cendChildAll() const
Definition LeafNode.h:367
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1791
void fill(const ValueType &value, bool active)
Set all voxels to the specified value and active state.
Definition LeafNode.h:1257
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:1227
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other, const ValueType &offValue, const ValueType &onValue, TopologyCopy)
Topology copy constructor.
Definition LeafNode.h:1042
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:482
ChildAllIter endChildAll()
Definition LeafNode.h:369
size_t streamingSize(bool toHalf=false) const
void setValueMask(Index n, bool on)
Definition LeafNode.h:921
const NodeMaskType & valueMask() const
Definition LeafNode.h:915
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition LeafNode.h:146
typename NodeMaskType::OffIterator MaskOffIterator
Definition LeafNode.h:208
void setValueOff(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition LeafNode.h:1144
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:376
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition LeafNode.h:1496
T BuildType
Definition LeafNode.h:41
ValueAllCIter cendValueAll() const
Definition LeafNode.h:345
friend class LeafNode
Definition LeafNode.h:892
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:524
static const Index NUM_VALUES
Definition LeafNode.h:52
void negate()
Definition LeafNode.h:1735
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition LeafNode.h:1100
ChildAllCIter beginChildAll() const
Definition LeafNode.h:358
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:773
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:627
void getOrigin(Coord &origin) const
Definition LeafNode.h:177
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition LeafNode.h:502
void setTransientData(Index32 transientData)
Set the transient data value.
Definition LeafNode.h:192
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition LeafNode.h:125
ChildOffCIter cendChildOff() const
Definition LeafNode.h:364
void fill(const ValueType &value)
Set all voxels to the specified value but don't change their active states.
Definition LeafNode.h:1250
typename NodeMaskType::OnIterator MaskOnIterator
Definition LeafNode.h:207
static const Index LOG2DIM
Definition LeafNode.h:49
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition LeafNode.h:1450
static const Index SIZE
Definition LeafNode.h:54
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition LeafNode.h:1470
bool isEmpty() const
Return true if this node has no active voxels.
Definition LeafNode.h:152
void combine2(const LeafNode &b0, const OtherNodeT &b1, CombineOp &)
Definition LeafNode.h:1829
ValueIter< MaskOnIterator, LeafNode, const ValueType, ValueOn > ValueOnIter
Definition LeafNode.h:316
void merge(const LeafNode &)
Definition LeafNode.h:1661
ValueIter< MaskOnIterator, const LeafNode, const ValueType, ValueOn > ValueOnCIter
Definition LeafNode.h:317
ValueOffIter beginValueOff()
Definition LeafNode.h:334
const NodeT * probeConstNode(const Coord &) const
Definition LeafNode.h:740
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition LeafNode.h:451
Buffer & buffer()
Definition LeafNode.h:378
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:593
void setValueOnly(Index offset, const ValueType &val)
Set the value of the voxel at the given offset but don't change its active state.
Definition LeafNode.h:1176
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:433
ChildIter< MaskOnIterator, const LeafNode, ChildOn > ChildOnCIter
Definition LeafNode.h:323
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition LeafNode.h:158
const NodeMaskType & getValueMask() const
Definition LeafNode.h:913
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition LeafNode.h:1627
static const Index TOTAL
Definition LeafNode.h:50
void addLeafAndCache(LeafNode *, AccessorT &)
Definition LeafNode.h:734
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:469
ValueOffCIter cendValueOff() const
Definition LeafNode.h:342
void setValueMaskOff(Index n)
Definition LeafNode.h:923
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition LeafNode.h:1460
bool isDense() const
Return true if this node contains only active voxels.
Definition LeafNode.h:154
ValueOffCIter endValueOff() const
Definition LeafNode.h:343
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:584
bool isValueOff(const Coord &xyz) const
Return true if the voxel at the given coordinates is inactive.
Definition LeafNode.h:511
std::string str() const
Return a string representation of this node.
Definition LeafNode.h:1063
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition LeafNode.h:736
void setValueOffUnsafe(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNode.h:882
T ValueType
Definition LeafNode.h:42
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:1127
ValueOnCIter endValueOn() const
Definition LeafNode.h:340
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition LeafNode.h:209
void voxelizeActiveTiles(bool=true)
No-op.
Definition LeafNode.h:673
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition LeafNode.h:610
bool isValueOff(Index offset) const
Return true if the voxel at the given offset is inactive.
Definition LeafNode.h:513
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:754
LeafNode(const Coord &coords, const ValueType &value=zeroVal< ValueType >(), bool active=false)
Constructor.
Definition LeafNode.h:973
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition LeafNode.h:663
ValueAllCIter beginValueAll() const
Definition LeafNode.h:336
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition LeafNode.h:123
void setValueOffUnsafe(Index offset, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:884
ValueIter< MaskDenseIterator, const LeafNode, const ValueType, ValueAll > ValueAllCIter
Definition LeafNode.h:321
void combine(const ValueType &value, bool valueIsActive, CombineOp &op)
Definition LeafNode.h:1770
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition LeafNode.h:326
bool isValueMaskOn(Index n) const
Definition LeafNode.h:909
LeafNode< ValueType, Log2Dim > LeafNodeType
Definition LeafNode.h:44
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other, const ValueType &background, TopologyCopy)
Topology copy constructor.
Definition LeafNode.h:1029
ValueAllIter beginValueAll()
Definition LeafNode.h:337
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other)
Value conversion copy constructor.
Definition LeafNode.h:1006
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition NodeMasks.h:309
OnIterator beginOn() const
Definition NodeMasks.h:353
OffIterator beginOff() const
Definition NodeMasks.h:355
DenseMaskIterator< NodeMask > DenseIterator
Definition NodeMasks.h:351
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition NodeMasks.h:503
OnMaskIterator< NodeMask > OnIterator
Definition NodeMasks.h:349
void setOn(Index32 n)
Set the nth bit on.
Definition NodeMasks.h:453
OffMaskIterator< NodeMask > OffIterator
Definition NodeMasks.h:350
math::BBox< Coord > CoordBBox
Definition Math.h:2838
@ COMPRESS_ZIP
Definition Compression.h:54
void writeCompressedValues(std::ostream &os, const ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf, const ValueT *background=nullptr)
Definition Compression.h:622
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf, const ValueT *background=nullptr)
Definition Compression.h:450
uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
void checkFormatVersion(std::ios_base &)
Throws an IoError if the file format version number is not supported.
uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
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...
void readData(std::istream &is, T *data, Index count, uint32_t compression)
Read data from a stream.
Definition Compression.h:242
bool cwiseLessThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition Mat.h:1015
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:428
T negative(const T &val)
Return the unary negation of the given value.
Definition Math.h:139
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:465
bool cwiseGreaterThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition Mat.h:1029
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:352
Definition TreeIterator.h:30
std::ostream & operator<<(std::ostream &os, const typename LeafNode< T, Log2Dim >::Buffer &buf)
Definition LeafNode.h:1851
Index32 Index
Definition Types.h:34
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:71
@ OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
Definition version.h.in:339
uint32_t Index32
Definition Types.h:32
int32_t Int32
Definition Types.h:36
uint64_t Index64
Definition Types.h:33
std::shared_ptr< T > SharedPtr
Definition Types.h:95
@ MERGE_NODES
Definition Types.h:579
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:580
Definition Exceptions.h:13
typename std::remove_const< ValueT >::type NonConstValueType
Definition Iterator.h:184
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNode.h:284
ChildIter()
Definition LeafNode.h:283
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition LeafNode.h:296
void unsetItem(Index pos, const ValueT &value) const
Definition LeafNode.h:309
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition LeafNode.h:298
DenseIter()
Definition LeafNode.h:295
typename BaseT::NonConstValueType NonConstValueT
Definition LeafNode.h:293
DenseIteratorBase< MaskDenseIterator, DenseIter, NodeT, void, ValueT > BaseT
Definition LeafNode.h:292
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition LeafNode.h:65
static const bool value
Definition LeafNode.h:66
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition LeafNode.h:60
LeafNode< OtherValueType, Log2Dim > Type
Definition LeafNode.h:60
void setValue(const ValueT &value) const
Definition LeafNode.h:251
void modifyValue(const ModifyOp &op) const
Definition LeafNode.h:270
ValueT & getItem(Index pos) const
Definition LeafNode.h:234
void setItem(Index pos, const ValueT &value) const
Definition LeafNode.h:238
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNode.h:227
ValueT & getValue() const
Definition LeafNode.h:235
std::conditional_t< std::is_const_v< NodeT >, ValueT, std::remove_const_t< ValueT > > ValueType
Definition LeafNode.h:222
ValueIter()
Definition LeafNode.h:226
void modifyItem(Index n, const ModifyOp &op) const
Definition LeafNode.h:255
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition LeafNode.h:224
Definition LeafNode.h:952
static const bool value
Definition LeafNode.h:952
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:291