OpenVDB: openvdb/tree/LeafNode.h Source File

OpenVDB 13.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>
8#include <openvdb/util/NodeMasks.h>
9#include <openvdb/util/Assert.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;
23 template<typename> class TestLeafIO;
24
25namespace openvdb {
26 OPENVDB_USE_VERSION_NAMESPACE
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>
38 class LeafNode
39{
40public:
41 using BuildType = T;
42 using ValueType = T;
43 using Buffer = LeafBuffer<ValueType, Log2Dim>;
44 using LeafNodeType = LeafNode<ValueType, Log2Dim>;
45 using NodeMaskType = util::NodeMask<Log2Dim>;
46 using Ptr = SharedPtr<LeafNode>;
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
54 SIZE = NUM_VALUES,
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>
60 struct ValueConverter { using Type = LeafNode<OtherValueType, Log2Dim>; };
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>
65 struct SameConfiguration {
66 static const bool value = SameLeafConfig<LOG2DIM, OtherNodeType>::value;
67 };
68
69
70 /// Default constructor
71 LeafNode();
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 LeafNode(PartialCreate,
87 const Coord& coords,
88 const ValueType& value = zeroVal<ValueType>(),
89 bool active = false);
90
91 /// Deep copy constructor
92 LeafNode(const LeafNode&);
93
94 /// Deep assignment operator
95 LeafNode& operator=(const LeafNode&) = default;
96
97 /// Value conversion copy constructor
98 template<typename OtherValueType>
99 explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
100
101 /// Topology copy constructor
102 template<typename OtherValueType>
103 LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
104 const ValueType& offValue, const ValueType& onValue, TopologyCopy);
105
106 /// Topology copy constructor
107 template<typename OtherValueType>
108 LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
109 const ValueType& background, TopologyCopy);
110
111 /// Destructor.
112 ~LeafNode();
113
114 //
115 // Statistics
116 //
117 /// Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3
118 static Index log2dim() { return Log2Dim; }
119 /// Return the number of voxels in each coordinate dimension.
120 static Index dim() { return DIM; }
121 /// Return the total number of voxels represented by this LeafNode
122 static Index size() { return SIZE; }
123 /// Return the total number of voxels represented by this LeafNode
124 static Index numValues() { return SIZE; }
125 /// Return the level of this node, which by definition is zero for LeafNodes
126 static Index getLevel() { return LEVEL; }
127 /// Append the Log2Dim of this LeafNode to the specified vector
128 static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
129 /// Return the dimension of child nodes of this LeafNode, which is one for voxels.
130 static Index getChildDim() { return 1; }
131 /// Return the leaf count for this node, which is one.
132 static Index64 leafCount() { return 1; }
133 /// no-op
134 void nodeCount(std::vector<Index64> &) const {}
135 OPENVDB_DEPRECATED_MESSAGE("Use input type std::vector<Index64> for nodeCount.")
136 void nodeCount(std::vector<Index32> &) const {}
137 /// Return the non-leaf count for this node, which is zero.
138 static Index64 nonLeafCount() { return 0; }
139 /// Return the child count for this node, which is zero.
140 static Index32 childCount() { return 0; }
141
142 /// Return the number of voxels marked On.
143 Index64 onVoxelCount() const { return mValueMask.countOn(); }
144 /// Return the number of voxels marked Off.
145 Index64 offVoxelCount() const { return mValueMask.countOff(); }
146 Index64 onLeafVoxelCount() const { return onVoxelCount(); }
147 Index64 offLeafVoxelCount() const { return offVoxelCount(); }
148 static Index64 onTileCount() { return 0; }
149 static Index64 offTileCount() { return 0; }
150 /// Return @c true if this node has no active voxels.
151 bool isEmpty() const { return mValueMask.isOff(); }
152 /// Return @c true if this node contains only active voxels.
153 bool isDense() const { return mValueMask.isOn(); }
154 /// Return @c true if memory for this node's buffer has been allocated.
155 bool isAllocated() const { return !mBuffer.isOutOfCore() && !mBuffer.empty(); }
156 /// Allocate memory for this node's buffer if it has not already been allocated.
157 bool allocate() { return mBuffer.allocate(); }
158
159 /// Return the memory in bytes occupied by this node.
160 Index64 memUsage() const;
161 Index64 memUsageIfLoaded() const;
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.
170 CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
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).
185 static Coord offsetToLocalCoord(Index n);
186 /// Return the global coordinates for a linear table offset.
187 Coord offsetToGlobalCoord(Index n) const;
188
189 /// Return the transient data value.
190 Index32 transientData() const { return mTransientData; }
191 /// Set the transient data value.
192 void setTransientData(Index32 transientData) { mTransientData = transientData; }
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>
200 bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
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:
207 using MaskOnIterator = typename NodeMaskType::OnIterator;
208 using MaskOffIterator = typename NodeMaskType::OffIterator;
209 using MaskDenseIterator = typename NodeMaskType::DenseIterator;
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>>;
224 using BaseT = SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT>;
225
226 ValueIter() {}
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 {
245 OPENVDB_ASSERT(pos < SIZE);
246 OPENVDB_ASSUME(pos < SIZE);
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 {
283 ChildIter() {}
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>
289 struct DenseIter: public DenseIteratorBase<
290 MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, /*ChildT=*/void, ValueT>
291 {
292 using BaseT = DenseIteratorBase<MaskDenseIterator, DenseIter, NodeT, void, ValueT>;
293 using NonConstValueT = typename BaseT::NonConstValueType;
294
295 DenseIter() {}
296 DenseIter(const MaskDenseIterator& iter, NodeT* parent): BaseT(iter, parent) {}
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 //
381 // I/O methods
382 //
383 /// @brief Read in just the topology.
384 /// @param is the stream from which to read
385 /// @param fromHalf if true, floating-point input values are assumed to be 16-bit
386 void readTopology(std::istream& is, bool fromHalf = false);
387 /// @brief Write out just the topology.
388 /// @param os the stream to which to write
389 /// @param toHalf if true, output floating-point values as 16-bit half floats
390 void writeTopology(std::ostream& os, bool toHalf = false) const;
391
392 /// @brief Read buffers from a stream.
393 /// @param is the stream from which to read
394 /// @param fromHalf if true, floating-point input values are assumed to be 16-bit
395 void readBuffers(std::istream& is, bool fromHalf = false);
396 /// @brief Read buffers that intersect the given bounding box.
397 /// @param is the stream from which to read
398 /// @param bbox an index-space bounding box
399 /// @param fromHalf if true, floating-point input values are assumed to be 16-bit
400 void readBuffers(std::istream& is, const CoordBBox& bbox, bool fromHalf = false);
401 /// @brief Write buffers to a stream.
402 /// @param os the stream to which to write
403 /// @param toHalf if true, output floating-point values as 16-bit half floats
404 void writeBuffers(std::ostream& os, bool toHalf = false) const;
405
406 size_t streamingSize(bool toHalf = false) const;
407
408 //
409 // Accessor methods
410 //
411 /// Return the value of the voxel at the given coordinates.
412 const ValueType& getValue(const Coord& xyz) const;
413 /// Return the value of the voxel at the given linear offset.
414 const ValueType& getValue(Index offset) const;
415
416 /// @brief Return @c true if the voxel at the given coordinates is active.
417 /// @param xyz the coordinates of the voxel to be probed
418 /// @param[out] val the value of the voxel at the given coordinates
419 bool probeValue(const Coord& xyz, ValueType& val) const;
420 /// @brief Return @c true if the voxel at the given offset is active.
421 /// @param offset the linear offset of the voxel to be probed
422 /// @param[out] val the value of the voxel at the given coordinates
423 bool probeValue(Index offset, ValueType& val) const;
424
425 /// Return the level (i.e., 0) at which leaf node values reside.
426 static Index getValueLevel(const Coord&) { return LEVEL; }
427
428 /// Set the active state of the voxel at the given coordinates but don't change its value.
429 void setActiveState(const Coord& xyz, bool on);
430 /// Set the active state of the voxel at the given offset but don't change its value.
431 void setActiveState(Index offset, bool on) { OPENVDB_ASSERT(offset<SIZE); mValueMask.set(offset, on); }
432
433 /// Set the value of the voxel at the given coordinates but don't change its active state.
434 void setValueOnly(const Coord& xyz, const ValueType& val);
435 /// Set the value of the voxel at the given offset but don't change its active state.
436 void setValueOnly(Index offset, const ValueType& val);
437
438 /// Mark the voxel at the given coordinates as inactive but don't change its value.
439 void setValueOff(const Coord& xyz) { mValueMask.setOff(LeafNode::coordToOffset(xyz)); }
440 /// Mark the voxel at the given offset as inactive but don't change its value.
441 void setValueOff(Index offset) { OPENVDB_ASSERT(offset < SIZE); mValueMask.setOff(offset); }
442
443 /// Set the value of the voxel at the given coordinates and mark the voxel as inactive.
444 void setValueOff(const Coord& xyz, const ValueType& val);
445 /// Set the value of the voxel at the given offset and mark the voxel as inactive.
446 void setValueOff(Index offset, const ValueType& val);
447
448 /// Mark the voxel at the given coordinates as active but don't change its value.
449 void setValueOn(const Coord& xyz) { mValueMask.setOn(LeafNode::coordToOffset(xyz)); }
450 /// Mark the voxel at the given offset as active but don't change its value.
451 void setValueOn(Index offset) { OPENVDB_ASSERT(offset < SIZE); mValueMask.setOn(offset); }
452 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
453 void setValueOn(const Coord& xyz, const ValueType& val) {
454 this->setValueOn(LeafNode::coordToOffset(xyz), val);
455 }
456 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
457 void setValue(const Coord& xyz, const ValueType& val) { this->setValueOn(xyz, val); }
458 /// Set the value of the voxel at the given offset and mark the voxel as active.
459 void setValueOn(Index offset, const ValueType& val) {
460 mBuffer.setValue(offset, val);
461 mValueMask.setOn(offset);
462 }
463
464 /// @brief Apply a functor to the value of the voxel at the given offset
465 /// and mark the voxel as active.
466 template<typename ModifyOp>
467 void modifyValue(Index offset, const ModifyOp& op)
468 {
469 mBuffer.loadValues();
470 if (!mBuffer.empty()) {
471 // in-place modify value
472 ValueType& val = const_cast<ValueType&>(mBuffer[offset]);
473 op(val);
474 mValueMask.setOn(offset);
475 }
476 }
477
478 /// @brief Apply a functor to the value of the voxel at the given coordinates
479 /// and mark the voxel as active.
480 template<typename ModifyOp>
481 void modifyValue(const Coord& xyz, const ModifyOp& op)
482 {
483 this->modifyValue(this->coordToOffset(xyz), op);
484 }
485
486 /// Apply a functor to the voxel at the given coordinates.
487 template<typename ModifyOp>
488 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
489 {
490 mBuffer.loadValues();
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>
701 void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
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>
715 void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
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>()) {}
732 void addLeaf(LeafNode*) {}
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 {
758 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
759 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
760 return reinterpret_cast<NodeT*>(this);
761 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
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 {
778 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
779 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
780 return reinterpret_cast<const NodeT*>(this);
781 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
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>;
904 friend class IteratorBase<MaskOffIterator, LeafNode>;
905 friend class IteratorBase<MaskDenseIterator, 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 inline void skipCompressedValues(bool seekable, std::istream&, bool fromHalf);
926
927 /// Compute the origin of the leaf node that contains the voxel with the given coordinates.
928 static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
929
930private:
931 /// Buffer containing the actual data values
932 Buffer mBuffer;
933 /// Bitmask that determines which voxels are active
934 NodeMaskType mValueMask;
935 /// Global grid index coordinates (x,y,z) of the local origin of this node
936 Coord mOrigin;
937 /// Transient data (not serialized)
938 Index32 mTransientData = 0;
939}; // end of LeafNode class
940
941
942////////////////////////////////////////
943
944
945//@{
946/// Helper metafunction used to implement LeafNode::SameConfiguration
947/// (which, as an inner class, can't be independently specialized)
948template<Index Dim1, typename NodeT2>
949 struct SameLeafConfig { static const bool value = false; };
950
951template<Index Dim1, typename T2>
952 struct SameLeafConfig<Dim1, LeafNode<T2, Dim1> > { static const bool value = true; };
953//@}
954
955
956////////////////////////////////////////
957
958
959template<typename T, Index Log2Dim>
960inline
961 LeafNode<T, Log2Dim>::LeafNode():
962 mValueMask(),//default is off!
963 mOrigin(0, 0, 0)
964{
965}
966
967
968template<typename T, Index Log2Dim>
969inline
970 LeafNode<T, Log2Dim>::LeafNode(const Coord& xyz, const ValueType& val, bool active):
971 mBuffer(val),
972 mValueMask(active),
973 mOrigin(xyz & (~(DIM - 1)))
974{
975}
976
977
978template<typename T, Index Log2Dim>
979inline
980 LeafNode<T, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, const ValueType& val, bool active):
981 mBuffer(PartialCreate(), val),
982 mValueMask(active),
983 mOrigin(xyz & (~(DIM - 1)))
984{
985}
986
987
988template<typename T, Index Log2Dim>
989inline
990 LeafNode<T, Log2Dim>::LeafNode(const LeafNode& other)
991 : mBuffer(other.mBuffer)
992 , mValueMask(other.valueMask())
993 , mOrigin(other.mOrigin)
994 , mTransientData(other.mTransientData)
995{
996}
997
998
999// Copy-construct from a leaf node with the same configuration but a different ValueType.
1000template<typename T, Index Log2Dim>
1001template<typename OtherValueType>
1002inline
1003 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other)
1004 : mValueMask(other.valueMask())
1005 , mOrigin(other.mOrigin)
1006 , mTransientData(other.mTransientData)
1007{
1008 struct Local {
1009 /// @todo Consider using a value conversion functor passed as an argument instead.
1010 static inline ValueType convertValue(const OtherValueType& val) { return ValueType(val); }
1011 };
1012
1013 for (Index i = 0; i < SIZE; ++i) {
1014 mBuffer[i] = Local::convertValue(other.mBuffer[i]);
1015 }
1016}
1017
1018
1019template<typename T, Index Log2Dim>
1020template<typename OtherValueType>
1021inline
1022 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
1023 const ValueType& background, TopologyCopy)
1024 : mBuffer(background)
1025 , mValueMask(other.valueMask())
1026 , mOrigin(other.mOrigin)
1027 , mTransientData(other.mTransientData)
1028{
1029}
1030
1031
1032template<typename T, Index Log2Dim>
1033template<typename OtherValueType>
1034inline
1035 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
1036 const ValueType& offValue, const ValueType& onValue, TopologyCopy)
1037 : mValueMask(other.valueMask())
1038 , mOrigin(other.mOrigin)
1039 , mTransientData(other.mTransientData)
1040{
1041 for (Index i = 0; i < SIZE; ++i) {
1042 mBuffer[i] = (mValueMask.isOn(i) ? onValue : offValue);
1043 }
1044}
1045
1046
1047template<typename T, Index Log2Dim>
1048inline
1049LeafNode<T, Log2Dim>::~LeafNode()
1050{
1051}
1052
1053
1054template<typename T, Index Log2Dim>
1055inline std::string
1056LeafNode<T, Log2Dim>::str() const
1057{
1058 std::ostringstream ostr;
1059 ostr << "LeafNode @" << mOrigin << ": " << mBuffer;
1060 return ostr.str();
1061}
1062
1063
1064////////////////////////////////////////
1065
1066
1067template<typename T, Index Log2Dim>
1068inline Index
1069LeafNode<T, Log2Dim>::coordToOffset(const Coord& xyz)
1070{
1071 OPENVDB_ASSERT((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
1072 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
1073 + ((xyz[1] & (DIM-1u)) << Log2Dim)
1074 + (xyz[2] & (DIM-1u));
1075}
1076
1077template<typename T, Index Log2Dim>
1078inline Coord
1079LeafNode<T, Log2Dim>::offsetToLocalCoord(Index n)
1080{
1081 OPENVDB_ASSERT(n<(1<< 3*Log2Dim));
1082 Coord xyz;
1083 xyz.setX(n >> 2*Log2Dim);
1084 n &= ((1<<2*Log2Dim)-1);
1085 xyz.setY(n >> Log2Dim);
1086 xyz.setZ(n & ((1<<Log2Dim)-1));
1087 return xyz;
1088}
1089
1090
1091template<typename T, Index Log2Dim>
1092inline Coord
1093LeafNode<T, Log2Dim>::offsetToGlobalCoord(Index n) const
1094{
1095 return (this->offsetToLocalCoord(n) + this->origin());
1096}
1097
1098
1099////////////////////////////////////////
1100
1101
1102template<typename ValueT, Index Log2Dim>
1103inline const ValueT&
1104LeafNode<ValueT, Log2Dim>::getValue(const Coord& xyz) const
1105{
1106 return this->getValue(LeafNode::coordToOffset(xyz));
1107}
1108
1109template<typename ValueT, Index Log2Dim>
1110inline const ValueT&
1111 LeafNode<ValueT, Log2Dim>::getValue(Index offset) const
1112{
1113 OPENVDB_ASSERT(offset < SIZE);
1114 return mBuffer[offset];
1115}
1116
1117
1118template<typename T, Index Log2Dim>
1119inline bool
1120LeafNode<T, Log2Dim>::probeValue(const Coord& xyz, ValueType& val) const
1121{
1122 return this->probeValue(LeafNode::coordToOffset(xyz), val);
1123}
1124
1125template<typename T, Index Log2Dim>
1126inline bool
1127 LeafNode<T, Log2Dim>::probeValue(Index offset, ValueType& val) const
1128{
1129 OPENVDB_ASSERT(offset < SIZE);
1130 val = mBuffer[offset];
1131 return mValueMask.isOn(offset);
1132}
1133
1134
1135template<typename T, Index Log2Dim>
1136inline void
1137 LeafNode<T, Log2Dim>::setValueOff(const Coord& xyz, const ValueType& val)
1138{
1139 this->setValueOff(LeafNode::coordToOffset(xyz), val);
1140}
1141
1142template<typename T, Index Log2Dim>
1143inline void
1144 LeafNode<T, Log2Dim>::setValueOff(Index offset, const ValueType& val)
1145{
1146 OPENVDB_ASSERT(offset < SIZE);
1147 mBuffer.setValue(offset, val);
1148 mValueMask.setOff(offset);
1149}
1150
1151
1152template<typename T, Index Log2Dim>
1153inline void
1154LeafNode<T, Log2Dim>::setActiveState(const Coord& xyz, bool on)
1155{
1156 mValueMask.set(this->coordToOffset(xyz), on);
1157}
1158
1159
1160template<typename T, Index Log2Dim>
1161inline void
1162LeafNode<T, Log2Dim>::setValueOnly(const Coord& xyz, const ValueType& val)
1163{
1164 this->setValueOnly(LeafNode::coordToOffset(xyz), val);
1165}
1166
1167template<typename T, Index Log2Dim>
1168inline void
1169 LeafNode<T, Log2Dim>::setValueOnly(Index offset, const ValueType& val)
1170{
1171 OPENVDB_ASSERT(offset<SIZE); mBuffer.setValue(offset, val);
1172}
1173
1174
1175////////////////////////////////////////
1176
1177
1178template<typename T, Index Log2Dim>
1179inline void
1180LeafNode<T, Log2Dim>::clip(const CoordBBox& clipBBox, const T& background)
1181{
1182 CoordBBox nodeBBox = this->getNodeBoundingBox();
1183 if (!clipBBox.hasOverlap(nodeBBox)) {
1184 // This node lies completely outside the clipping region. Fill it with the background.
1185 this->fill(background, /*active=*/false);
1186 } else if (clipBBox.isInside(nodeBBox)) {
1187 // This node lies completely inside the clipping region. Leave it intact.
1188 return;
1189 }
1190
1191 // This node isn't completely contained inside the clipping region.
1192 // Set any voxels that lie outside the region to the background value.
1193
1194 // Construct a boolean mask that is on inside the clipping region and off outside it.
1195 NodeMaskType mask;
1196 nodeBBox.intersect(clipBBox);
1197 Coord xyz;
1198 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1199 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1200 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1201 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1202 mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1203 }
1204 }
1205 }
1206
1207 // Set voxels that lie in the inactive region of the mask (i.e., outside
1208 // the clipping region) to the background value.
1209 for (MaskOffIterator maskIter = mask.beginOff(); maskIter; ++maskIter) {
1210 this->setValueOff(maskIter.pos(), background);
1211 }
1212}
1213
1214
1215////////////////////////////////////////
1216
1217
1218template<typename T, Index Log2Dim>
1219inline void
1220LeafNode<T, Log2Dim>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1221{
1222 if (!this->allocate()) return;
1223
1224 auto clippedBBox = this->getNodeBoundingBox();
1225 clippedBBox.intersect(bbox);
1226 if (!clippedBBox) return;
1227
1228 for (Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1229 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1230 for (Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1231 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1232 for (Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1233 const Index offset = offsetXY + (z & (DIM-1u));
1234 mBuffer[offset] = value;
1235 mValueMask.set(offset, active);
1236 }
1237 }
1238 }
1239}
1240
1241template<typename T, Index Log2Dim>
1242inline void
1243 LeafNode<T, Log2Dim>::fill(const ValueType& value)
1244{
1245 mBuffer.fill(value);
1246}
1247
1248template<typename T, Index Log2Dim>
1249inline void
1250 LeafNode<T, Log2Dim>::fill(const ValueType& value, bool active)
1251{
1252 mBuffer.fill(value);
1253 mValueMask.set(active);
1254}
1255
1256
1257////////////////////////////////////////
1258
1259
1260template<typename T, Index Log2Dim>
1261template<typename DenseT>
1262inline void
1263LeafNode<T, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1264{
1265 mBuffer.loadValues();
1266
1267 using DenseValueType = typename DenseT::ValueType;
1268
1269 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1270 const Coord& min = dense.bbox().min();
1271 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1272 const T* s0 = &mBuffer[bbox.min()[2] & (DIM-1u)]; // source array
1273 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1274 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1275 const T* s1 = s0 + ((x & (DIM-1u)) << 2*Log2Dim);
1276 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1277 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1278 const T* s2 = s1 + ((y & (DIM-1u)) << Log2Dim);
1279 for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1280 *t2 = DenseValueType(*s2++);
1281 }
1282 }
1283 }
1284}
1285
1286
1287template<typename T, Index Log2Dim>
1288template<typename DenseT>
1289inline void
1290LeafNode<T, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1291 const ValueType& background, const ValueType& tolerance)
1292{
1293 if (!this->allocate()) return;
1294
1295 using DenseValueType = typename DenseT::ValueType;
1296
1297 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1298 const Coord& min = dense.bbox().min();
1299
1300 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1301 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1302 for (Int32 x = bbox.min()[0], ex = bbox.max()[0]+1; x < ex; ++x) {
1303 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1304 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1305 for (Int32 y = bbox.min()[1], ey = bbox.max()[1]+1; y < ey; ++y) {
1306 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1307 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1308 for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1309 if (math::isApproxEqual(background, ValueType(*s2), tolerance)) {
1310 mValueMask.setOff(n2);
1311 mBuffer[n2] = background;
1312 } else {
1313 mValueMask.setOn(n2);
1314 mBuffer[n2] = ValueType(*s2);
1315 }
1316 }
1317 }
1318 }
1319}
1320
1321
1322////////////////////////////////////////
1323
1324
1325template<typename T, Index Log2Dim>
1326inline void
1327LeafNode<T, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
1328{
1329 mValueMask.load(is);
1330}
1331
1332
1333template<typename T, Index Log2Dim>
1334inline void
1335LeafNode<T, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
1336{
1337 mValueMask.save(os);
1338}
1339
1340
1341////////////////////////////////////////
1342
1343
1344
1345template<typename T, Index Log2Dim>
1346inline void
1347LeafNode<T,Log2Dim>::skipCompressedValues(bool seekable, std::istream& is, bool fromHalf)
1348{
1349 if (seekable) {
1350 // Seek over voxel values.
1351 io::readCompressedValues<ValueType, NodeMaskType>(
1352 is, nullptr, SIZE, mValueMask, fromHalf);
1353 } else {
1354 // Read and discard voxel values.
1355 Buffer temp;
1356 io::readCompressedValues(is, temp.mData, SIZE, mValueMask, fromHalf);
1357 }
1358}
1359
1360
1361template<typename T, Index Log2Dim>
1362inline void
1363LeafNode<T,Log2Dim>::readBuffers(std::istream& is, bool fromHalf)
1364{
1365 this->readBuffers(is, CoordBBox::inf(), fromHalf);
1366}
1367
1368
1369template<typename T, Index Log2Dim>
1370inline void
1371 LeafNode<T,Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
1372{
1373 io::checkFormatVersion(is);
1374
1375 SharedPtr<io::StreamMetadata> meta = io::getStreamMetadataPtr(is);
1376 const bool seekable = meta && meta->seekable();
1377
1378#ifdef OPENVDB_USE_DELAYED_LOADING
1379 std::streamoff maskpos = is.tellg();
1380#endif
1381
1382 if (seekable) {
1383 // Seek over the value mask.
1384 mValueMask.seek(is);
1385 } else {
1386 // Read in the value mask.
1387 mValueMask.load(is);
1388 }
1389
1390 int8_t numBuffers = 1;
1391
1392 CoordBBox nodeBBox = this->getNodeBoundingBox();
1393 if (!clipBBox.hasOverlap(nodeBBox)) {
1394 // This node lies completely outside the clipping region.
1395 skipCompressedValues(seekable, is, fromHalf);
1396 mValueMask.setOff();
1397 mBuffer.setOutOfCore(false);
1398 } else {
1399#ifdef OPENVDB_USE_DELAYED_LOADING
1400 // If this node lies completely inside the clipping region and it is being read
1401 // from a memory-mapped file, delay loading of its buffer until the buffer
1402 // is actually accessed. (If this node requires clipping, its buffer
1403 // must be accessed and therefore must be loaded.)
1404 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is);
1405 const bool delayLoad = ((mappedFile.get() != nullptr) && clipBBox.isInside(nodeBBox));
1406
1407 if (delayLoad) {
1408 // Save the offset to the value mask (maskpos), because the in-memory copy
1409 // might change before the value buffer gets read.
1410 mBuffer.enableOutOfCore(meta, is.tellg(), mappedFile, maskpos);
1411 // Skip over voxel values.
1412 skipCompressedValues(seekable, is, fromHalf);
1413 } else {
1414#endif
1415 mBuffer.allocate();
1416 io::readCompressedValues(is, mBuffer.mData, SIZE, mValueMask, fromHalf);
1417 mBuffer.setOutOfCore(false);
1418
1419 // Get this tree's background value.
1420 T background = zeroVal<T>();
1421 if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
1422 background = *static_cast<const T*>(bgPtr);
1423 }
1424 this->clip(clipBBox, background);
1425#ifdef OPENVDB_USE_DELAYED_LOADING
1426 }
1427#endif
1428 }
1429
1430 if (numBuffers > 1) {
1431 // Read in and discard auxiliary buffers that were created with earlier
1432 // versions of the library. (Auxiliary buffers are not mask compressed.)
1433 const bool zipped = io::getDataCompression(is) & io::COMPRESS_ZIP;
1434 Buffer temp;
1435 for (int i = 1; i < numBuffers; ++i) {
1436 if (fromHalf) {
1437 io::HalfReader<io::RealToHalf<T>::isReal, T>::read(is, temp.mData, SIZE, zipped);
1438 } else {
1439 io::readData<T>(is, temp.mData, SIZE, zipped);
1440 }
1441 }
1442 }
1443
1444 // increment the leaf number
1445 if (meta) meta->setLeaf(meta->leaf() + 1);
1446}
1447
1448
1449template<typename T, Index Log2Dim>
1450inline void
1451LeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
1452{
1453 // Write out the value mask.
1454 mValueMask.save(os);
1455
1456 mBuffer.loadValues();
1457
1458 io::writeCompressedValues(os, mBuffer.mData, SIZE,
1459 mValueMask, /*childMask=*/NodeMaskType(), toHalf);
1460}
1461
1462
1463////////////////////////////////////////
1464
1465
1466template<typename T, Index Log2Dim>
1467inline bool
1468LeafNode<T, Log2Dim>::operator==(const LeafNode& other) const
1469{
1470 return mOrigin == other.mOrigin &&
1471 mValueMask == other.valueMask() &&
1472 mBuffer == other.mBuffer;
1473}
1474
1475
1476template<typename T, Index Log2Dim>
1477inline Index64
1478LeafNode<T, Log2Dim>::memUsage() const
1479{
1480 // Use sizeof(*this) to capture alignment-related padding
1481 // (but note that sizeof(*this) includes sizeof(mBuffer)).
1482 return sizeof(*this) + mBuffer.memUsage() - sizeof(mBuffer);
1483}
1484
1485
1486template<typename T, Index Log2Dim>
1487inline Index64
1488LeafNode<T, Log2Dim>::memUsageIfLoaded() const
1489{
1490 // Use sizeof(*this) to capture alignment-related padding
1491 // (but note that sizeof(*this) includes sizeof(mBuffer)).
1492 return sizeof(*this) + mBuffer.memUsageIfLoaded() - sizeof(mBuffer);
1493}
1494
1495
1496template<typename T, Index Log2Dim>
1497inline void
1498LeafNode<T, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
1499{
1500 CoordBBox this_bbox = this->getNodeBoundingBox();
1501 if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
1502 if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
1503 if (visitVoxels) {//use voxel granularity?
1504 this_bbox.reset();
1505 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
1506 this_bbox.translate(this->origin());
1507 }
1508 bbox.expand(this_bbox);
1509 }
1510}
1511
1512
1513template<typename T, Index Log2Dim>
1514template<typename OtherType, Index OtherLog2Dim>
1515inline bool
1516LeafNode<T, Log2Dim>::hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const
1517{
1518 OPENVDB_ASSERT(other);
1519 return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
1520}
1521
1522template<typename T, Index Log2Dim>
1523inline bool
1524LeafNode<T, Log2Dim>::isConstant(ValueType& firstValue,
1525 bool& state,
1526 const ValueType& tolerance) const
1527{
1528 if (!mValueMask.isConstant(state)) return false;// early termination
1529 firstValue = mBuffer[0];
1530 for (Index i = 1; i < SIZE; ++i) {
1531 if ( !math::isApproxEqual(mBuffer[i], firstValue, tolerance) ) return false;// early termination
1532 }
1533 return true;
1534}
1535
1536template<typename T, Index Log2Dim>
1537inline bool
1538 LeafNode<T, Log2Dim>::isConstant(ValueType& minValue,
1539 ValueType& maxValue,
1540 bool& state,
1541 const ValueType& tolerance) const
1542{
1543 if (!mValueMask.isConstant(state)) return false;// early termination
1544 minValue = maxValue = mBuffer[0];
1545 for (Index i = 1; i < SIZE; ++i) {
1546 const T& v = mBuffer[i];
1547 if (v < minValue) {
1548 if ((maxValue - v) > tolerance) return false;// early termination
1549 minValue = v;
1550 } else if (v > maxValue) {
1551 if ((v - minValue) > tolerance) return false;// early termination
1552 maxValue = v;
1553 }
1554 }
1555 return true;
1556}
1557
1558template<typename T, Index Log2Dim>
1559inline T
1560LeafNode<T, Log2Dim>::medianAll(T *tmp) const
1561{
1562 std::unique_ptr<T[]> data(nullptr);
1563 if (tmp == nullptr) {//allocate temporary storage
1564 data.reset(new T[NUM_VALUES]);
1565 tmp = data.get();
1566 }
1567 if (tmp != mBuffer.data()) {
1568 const T* src = mBuffer.data();
1569 for (T* dst = tmp; dst-tmp < NUM_VALUES;) *dst++ = *src++;
1570 }
1571 static const size_t midpoint = (NUM_VALUES - 1) >> 1;
1572 std::nth_element(tmp, tmp + midpoint, tmp + NUM_VALUES);
1573 return tmp[midpoint];
1574}
1575
1576template<typename T, Index Log2Dim>
1577inline Index
1578LeafNode<T, Log2Dim>::medianOn(T &value, T *tmp) const
1579{
1580 const Index count = mValueMask.countOn();
1581 if (count == NUM_VALUES) {//special case: all voxels are active
1582 value = this->medianAll(tmp);
1583 return NUM_VALUES;
1584 } else if (count == 0) {
1585 return 0;
1586 }
1587 std::unique_ptr<T[]> data(nullptr);
1588 if (tmp == nullptr) {//allocate temporary storage
1589 data.reset(new T[count]);// 0 < count < NUM_VALUES
1590 tmp = data.get();
1591 }
1592 for (auto iter=this->cbeginValueOn(); iter; ++iter) *tmp++ = *iter;
1593 T *begin = tmp - count;
1594 const size_t midpoint = (count - 1) >> 1;
1595 std::nth_element(begin, begin + midpoint, tmp);
1596 value = begin[midpoint];
1597 return count;
1598}
1599
1600template<typename T, Index Log2Dim>
1601inline Index
1602LeafNode<T, Log2Dim>::medianOff(T &value, T *tmp) const
1603{
1604 const Index count = mValueMask.countOff();
1605 if (count == NUM_VALUES) {//special case: all voxels are inactive
1606 value = this->medianAll(tmp);
1607 return NUM_VALUES;
1608 } else if (count == 0) {
1609 return 0;
1610 }
1611 std::unique_ptr<T[]> data(nullptr);
1612 if (tmp == nullptr) {//allocate temporary storage
1613 data.reset(new T[count]);// 0 < count < NUM_VALUES
1614 tmp = data.get();
1615 }
1616 for (auto iter=this->cbeginValueOff(); iter; ++iter) *tmp++ = *iter;
1617 T *begin = tmp - count;
1618 const size_t midpoint = (count - 1) >> 1;
1619 std::nth_element(begin, begin + midpoint, tmp);
1620 value = begin[midpoint];
1621 return count;
1622}
1623
1624////////////////////////////////////////
1625
1626
1627template<typename T, Index Log2Dim>
1628inline void
1629LeafNode<T, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, const ValueType& val, bool active)
1630{
1631 this->addTile(this->coordToOffset(xyz), val, active);
1632}
1633
1634template<typename T, Index Log2Dim>
1635inline void
1636 LeafNode<T, Log2Dim>::addTile(Index offset, const ValueType& val, bool active)
1637{
1638 OPENVDB_ASSERT(offset < SIZE);
1639 setValueOnly(offset, val);
1640 setActiveState(offset, active);
1641}
1642
1643template<typename T, Index Log2Dim>
1644template<typename AccessorT>
1645inline void
1646LeafNode<T, Log2Dim>::addTileAndCache(Index level, const Coord& xyz,
1647 const ValueType& val, bool active, AccessorT&)
1648{
1649 this->addTile(level, xyz, val, active);
1650}
1651
1652
1653////////////////////////////////////////
1654
1655
1656template<typename T, Index Log2Dim>
1657inline void
1658LeafNode<T, Log2Dim>::resetBackground(const ValueType& oldBackground,
1659 const ValueType& newBackground)
1660{
1661 if (!this->allocate()) return;
1662 if (math::isExactlyEqual(oldBackground, newBackground)) return;
1663
1664 typename NodeMaskType::OffIterator iter;
1665 // For all inactive values...
1666 for (iter = this->mValueMask.beginOff(); iter; ++iter) {
1667 ValueType &inactiveValue = mBuffer[iter.pos()];
1668 if (math::isApproxEqual(inactiveValue, oldBackground)) {
1669 inactiveValue = newBackground;
1670 } else if (math::isApproxEqual(inactiveValue, math::negative(oldBackground))) {
1671 inactiveValue = math::negative(newBackground);
1672 }
1673 }
1674}
1675
1676
1677template<typename T, Index Log2Dim>
1678template<MergePolicy Policy>
1679inline void
1680LeafNode<T, Log2Dim>::merge(const LeafNode& other)
1681{
1682 if (!this->allocate()) return;
1683
1684 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1685 if (Policy == MERGE_NODES) return;
1686 typename NodeMaskType::OnIterator iter = other.valueMask().beginOn();
1687 for (; iter; ++iter) {
1688 const Index n = iter.pos();
1689 if (mValueMask.isOff(n)) {
1690 mBuffer[n] = other.mBuffer[n];
1691 mValueMask.setOn(n);
1692 }
1693 }
1694 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1695}
1696
1697template<typename T, Index Log2Dim>
1698template<MergePolicy Policy>
1699inline void
1700 LeafNode<T, Log2Dim>::merge(const LeafNode& other,
1701 const ValueType& /*bg*/, const ValueType& /*otherBG*/)
1702{
1703 this->template merge<Policy>(other);
1704}
1705
1706template<typename T, Index Log2Dim>
1707template<MergePolicy Policy>
1708inline void
1709 LeafNode<T, Log2Dim>::merge(const ValueType& tileValue, bool tileActive)
1710{
1711 if (!this->allocate()) return;
1712
1713 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1714 if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1715 if (!tileActive) return;
1716 // Replace all inactive values with the active tile value.
1717 for (typename NodeMaskType::OffIterator iter = mValueMask.beginOff(); iter; ++iter) {
1718 const Index n = iter.pos();
1719 mBuffer[n] = tileValue;
1720 mValueMask.setOn(n);
1721 }
1722 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1723}
1724
1725
1726template<typename T, Index Log2Dim>
1727template<typename OtherType>
1728inline void
1729LeafNode<T, Log2Dim>::topologyUnion(const LeafNode<OtherType, Log2Dim>& other, bool)
1730{
1731 mValueMask |= other.valueMask();
1732}
1733
1734template<typename T, Index Log2Dim>
1735template<typename OtherType>
1736inline void
1737LeafNode<T, Log2Dim>::topologyIntersection(const LeafNode<OtherType, Log2Dim>& other,
1738 const ValueType&)
1739{
1740 mValueMask &= other.valueMask();
1741}
1742
1743template<typename T, Index Log2Dim>
1744template<typename OtherType>
1745inline void
1746LeafNode<T, Log2Dim>::topologyDifference(const LeafNode<OtherType, Log2Dim>& other,
1747 const ValueType&)
1748{
1749 mValueMask &= !other.valueMask();
1750}
1751
1752template<typename T, Index Log2Dim>
1753inline void
1754LeafNode<T, Log2Dim>::negate()
1755{
1756 if (!this->allocate()) return;
1757
1758 for (Index i = 0; i < SIZE; ++i) {
1759 mBuffer[i] = -mBuffer[i];
1760 }
1761}
1762
1763
1764////////////////////////////////////////
1765
1766
1767template<typename T, Index Log2Dim>
1768template<typename CombineOp>
1769inline void
1770LeafNode<T, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1771{
1772 if (!this->allocate()) return;
1773
1774 CombineArgs<T> args;
1775 for (Index i = 0; i < SIZE; ++i) {
1776 op(args.setARef(mBuffer[i])
1777 .setAIsActive(mValueMask.isOn(i))
1778 .setBRef(other.mBuffer[i])
1779 .setBIsActive(other.valueMask().isOn(i))
1780 .setResultRef(mBuffer[i]));
1781 mValueMask.set(i, args.resultIsActive());
1782 }
1783}
1784
1785
1786template<typename T, Index Log2Dim>
1787template<typename CombineOp>
1788inline void
1789 LeafNode<T, Log2Dim>::combine(const ValueType& value, bool valueIsActive, CombineOp& op)
1790{
1791 if (!this->allocate()) return;
1792
1793 CombineArgs<T> args;
1794 args.setBRef(value).setBIsActive(valueIsActive);
1795 for (Index i = 0; i < SIZE; ++i) {
1796 op(args.setARef(mBuffer[i])
1797 .setAIsActive(mValueMask.isOn(i))
1798 .setResultRef(mBuffer[i]));
1799 mValueMask.set(i, args.resultIsActive());
1800 }
1801}
1802
1803
1804////////////////////////////////////////
1805
1806
1807template<typename T, Index Log2Dim>
1808template<typename CombineOp, typename OtherType>
1809inline void
1810LeafNode<T, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1811 bool valueIsActive, CombineOp& op)
1812{
1813 if (!this->allocate()) return;
1814
1815 CombineArgs<T, OtherType> args;
1816 args.setBRef(value).setBIsActive(valueIsActive);
1817 for (Index i = 0; i < SIZE; ++i) {
1818 op(args.setARef(other.mBuffer[i])
1819 .setAIsActive(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
1829 LeafNode<T, Log2Dim>::combine2(const ValueType& value, const OtherNodeT& other,
1830 bool valueIsActive, CombineOp& op)
1831{
1832 if (!this->allocate()) return;
1833
1834 CombineArgs<T, typename OtherNodeT::ValueType> args;
1835 args.setARef(value).setAIsActive(valueIsActive);
1836 for (Index i = 0; i < SIZE; ++i) {
1837 op(args.setBRef(other.mBuffer[i])
1838 .setBIsActive(other.valueMask().isOn(i))
1839 .setResultRef(mBuffer[i]));
1840 mValueMask.set(i, args.resultIsActive());
1841 }
1842}
1843
1844
1845template<typename T, Index Log2Dim>
1846template<typename CombineOp, typename OtherNodeT>
1847inline void
1848 LeafNode<T, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1849{
1850 if (!this->allocate()) return;
1851
1852 CombineArgs<T, typename OtherNodeT::ValueType> args;
1853 for (Index i = 0; i < SIZE; ++i) {
1854 mValueMask.set(i, b0.valueMask().isOn(i) || b1.valueMask().isOn(i));
1855 op(args.setARef(b0.mBuffer[i])
1856 .setAIsActive(b0.valueMask().isOn(i))
1857 .setBRef(b1.mBuffer[i])
1858 .setBIsActive(b1.valueMask().isOn(i))
1859 .setResultRef(mBuffer[i]));
1860 mValueMask.set(i, args.resultIsActive());
1861 }
1862}
1863
1864
1865////////////////////////////////////////
1866
1867
1868template<typename T, Index Log2Dim>
1869 inline std::ostream&
1870 operator<<(std::ostream& os, const typename LeafNode<T, Log2Dim>::Buffer& buf)
1871{
1872 for (Index32 i = 0, N = buf.size(); i < N; ++i) os << buf.mData[i] << ", ";
1873 return os;
1874}
1875
1876} // namespace tree
1877} // namespace OPENVDB_VERSION_NAME
1878} // namespace openvdb
1879
1880
1881////////////////////////////////////////
1882
1883
1884// Specialization for LeafNodes of type bool
1885#include "LeafNodeBool.h"
1886
1887// Specialization for LeafNodes with mask information only
1888#include "LeafNodeMask.h"
1889
1890#endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
Assert.h
OPENVDB_ASSERT
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Compression.h
Iterator.h
LeafBuffer.h
LeafNodeBool.h
LeafNodeMask.h
NodeMasks.h
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition Platform.h:164
OPENVDB_ASSUME
#define OPENVDB_ASSUME(...)
Definition Platform.h:115
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition Platform.h:163
OPENVDB_DEPRECATED_MESSAGE
#define OPENVDB_DEPRECATED_MESSAGE(msg)
Definition Platform.h:171
TestLeafIO
Definition LeafNode.h:23
openvdb::v13_0::CombineArgs
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:636
openvdb::v13_0::CombineArgs::setARef
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:688
openvdb::v13_0::CombineArgs::setBIsActive
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:704
openvdb::v13_0::CombineArgs::setResultRef
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition Types.h:692
openvdb::v13_0::CombineArgs::setBRef
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:690
openvdb::v13_0::CombineArgs::resultIsActive
bool resultIsActive() const
Definition Types.h:699
openvdb::v13_0::CombineArgs::setAIsActive
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:702
openvdb::v13_0::CoordBBox::inf
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition Coord.h:322
openvdb::v13_0::CoordBBox::createCube
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition Coord.h:316
openvdb::v13_0::PartialCreate
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:756
openvdb::v13_0::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:750
openvdb::v13_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
openvdb::v13_0::math::CoordBBox::translate
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition Coord.h:461
openvdb::v13_0::math::CoordBBox::expand
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition Coord.h:421
openvdb::v13_0::math::CoordBBox::min
const Coord & min() const
Definition Coord.h:324
openvdb::v13_0::math::CoordBBox::hasOverlap
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition Coord.h:415
openvdb::v13_0::math::CoordBBox::max
const Coord & max() const
Definition Coord.h:325
openvdb::v13_0::math::CoordBBox::isInside
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition Coord.h:403
openvdb::v13_0::math::CoordBBox::intersect
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:447
openvdb::v13_0::math::CoordBBox::reset
void reset()
Definition Coord.h:330
openvdb::v13_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
openvdb::v13_0::math::Coord::y
Int32 y() const
Definition Coord.h:132
openvdb::v13_0::math::Coord::x
Int32 x() const
Definition Coord.h:131
openvdb::v13_0::math::Coord::setZ
Coord & setZ(Int32 z)
Definition Coord.h:82
openvdb::v13_0::math::Coord::setY
Coord & setY(Int32 y)
Definition Coord.h:81
openvdb::v13_0::math::Coord::z
Int32 z() const
Definition Coord.h:133
openvdb::v13_0::math::Coord::setX
Coord & setX(Int32 x)
Definition Coord.h:80
openvdb::v13_0::tree::IteratorBase
Base class for iterators over internal and leaf nodes.
Definition Iterator.h:30
openvdb::v13_0::tree::LeafNode::ValueIter< MaskOnIterator, LeafNode, const ValueType, ValueOn >::pos
Index pos() const
Definition Iterator.h:60
openvdb::v13_0::tree::LeafNode::ValueIter< MaskOnIterator, LeafNode, const ValueType, ValueOn >::parent
LeafNode & parent() const
Definition Iterator.h:50
openvdb::v13_0::tree::LeafBuffer
Array of fixed size 23Log2Dim that stores the voxel values of a LeafNode.
Definition LeafBuffer.h:32
openvdb::v13_0::tree::LeafBuffer::size
static Index size()
Return the number of values contained in this buffer.
Definition LeafBuffer.h:118
openvdb::v13_0::tree::LeafNode
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition LeafNode.h:39
openvdb::v13_0::tree::LeafNode::stealNodes
void stealNodes(ArrayT &, const ValueType &, bool)
Definition LeafNode.h:742
openvdb::v13_0::tree::LeafNode::setValueOff
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:1144
openvdb::v13_0::tree::LeafNode::operator=
LeafNode & operator=(const LeafNode &)=default
Deep assignment operator.
openvdb::v13_0::tree::LeafNode::probeValueAndCache
bool probeValueAndCache(const Coord &xyz, ValueType &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val.
Definition LeafNode.h:636
openvdb::v13_0::tree::LeafNode::isValueOn
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition LeafNode.h:509
openvdb::v13_0::tree::LeafNode::addTile
void addTile(Index offset, const ValueType &, bool)
Definition LeafNode.h:1636
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ChildAllCIter
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition LeafNode.h:327
openvdb::v13_0::tree::LeafNode::onTileCount
static Index64 onTileCount()
Definition LeafNode.h:148
openvdb::v13_0::tree::LeafNode::getOrigin
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition LeafNode.h:178
openvdb::v13_0::tree::LeafNode::offsetToLocalCoord
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition LeafNode.h:1079
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ValueOffIter
ValueIter< MaskOffIterator, LeafNode, const ValueType, ValueOff > ValueOffIter
Definition LeafNode.h:318
openvdb::v13_0::tree::LeafNode::cbeginChildOn
ChildOnCIter cbeginChildOn() const
Definition LeafNode.h:351
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::Ptr
SharedPtr< LeafNode > Ptr
Definition LeafNode.h:46
openvdb::v13_0::tree::LeafNode::getNodeBoundingBox
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition LeafNode.h:170
openvdb::v13_0::tree::LeafNode::getValueMask
NodeMaskType & getValueMask()
Definition LeafNode.h:914
openvdb::v13_0::tree::LeafNode::isConstant
bool isConstant(ValueType &minValue, ValueType &maxValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition LeafNode.h:1538
openvdb::v13_0::tree::LeafNode::setValueOn
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNode.h:451
openvdb::v13_0::tree::LeafNode::isChildMaskOn
bool isChildMaskOn(Index) const
Definition LeafNode.h:917
openvdb::v13_0::tree::LeafNode::beginChildOn
ChildOnCIter beginChildOn() const
Definition LeafNode.h:352
openvdb::v13_0::tree::LeafNode::beginChildOn
ChildOnIter beginChildOn()
Definition LeafNode.h:353
openvdb::v13_0::tree::LeafNode::LeafNode
LeafNode()
Default constructor.
Definition LeafNode.h:961
openvdb::v13_0::tree::LeafNode::nonLeafCount
static Index64 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition LeafNode.h:138
openvdb::v13_0::tree::LeafNode::isValueOn
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:507
openvdb::v13_0::tree::LeafNode::endValueOn
ValueOnIter endValueOn()
Definition LeafNode.h:341
openvdb::v13_0::tree::LeafNode::writeTopology
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition LeafNode.h:1335
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::NodeMaskType
util::NodeMask< Log2Dim > NodeMaskType
Definition LeafNode.h:45
openvdb::v13_0::tree::LeafNode::copyToDense
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of the voxels that lie within a given bounding box.
Definition LeafNode.h:1263
openvdb::v13_0::tree::LeafNode::isChildMaskOff
bool isChildMaskOff() const
Definition LeafNode.h:919
openvdb::v13_0::tree::LeafNode::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Definition LeafNode.h:332
openvdb::v13_0::tree::LeafNode::transientData
Index32 transientData() const
Return the transient data value.
Definition LeafNode.h:190
openvdb::v13_0::tree::LeafNode::childCount
static Index32 childCount()
Return the child count for this node, which is zero.
Definition LeafNode.h:140
openvdb::v13_0::tree::LeafNode::setValue
void setValue(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:457
openvdb::v13_0::tree::LeafNode::LeafNode
LeafNode(const LeafNode &)
Deep copy constructor.
Definition LeafNode.h:990
openvdb::v13_0::tree::LeafNode::getChildDim
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition LeafNode.h:130
openvdb::v13_0::tree::LeafNode::operator!=
bool operator!=(const LeafNode &other) const
Definition LeafNode.h:204
openvdb::v13_0::tree::LeafNode::leafCount
static Index64 leafCount()
Return the leaf count for this node, which is one.
Definition LeafNode.h:132
openvdb::v13_0::tree::LeafNode::copyFromDense
void copyFromDense(const CoordBBox &bbox, const DenseT &dense, const ValueType &background, const ValueType &tolerance)
Copy from a dense grid into this node the values of the voxels that lie within a given bounding box.
Definition LeafNode.h:1290
openvdb::v13_0::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:1104
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ChildOnIter
ChildIter< MaskOnIterator, LeafNode, ChildOn > ChildOnIter
Definition LeafNode.h:322
openvdb::v13_0::tree::LeafNode::setValueMask
void setValueMask(const NodeMaskType &mask)
Definition LeafNode.h:916
openvdb::v13_0::tree::LeafNode::endChildOn
ChildOnIter endChildOn()
Definition LeafNode.h:363
openvdb::v13_0::tree::LeafNode::endValueAll
ValueAllIter endValueAll()
Definition LeafNode.h:347
openvdb::v13_0::tree::LeafNode::touchLeaf
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition LeafNode.h:752
openvdb::v13_0::tree::LeafNode::setValueOnly
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition LeafNode.h:1162
openvdb::v13_0::tree::LeafNode::probeLeaf
LeafNode * probeLeaf(const Coord &)
Definition LeafNode.h:763
openvdb::v13_0::tree::LeafNode::isValueMaskOff
bool isValueMaskOff() const
Definition LeafNode.h:912
openvdb::v13_0::tree::LeafNode::prune
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition LeafNode.h:731
openvdb::v13_0::tree::LeafNode::isValueMaskOn
bool isValueMaskOn() const
Definition LeafNode.h:910
openvdb::v13_0::tree::LeafNode::topologyDifference
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node's set of active values with the active values of the other node,...
Definition LeafNode.h:1746
openvdb::v13_0::tree::LeafNode::Buffer
LeafBuffer< ValueType, Log2Dim > Buffer
Definition LeafNode.h:43
openvdb::v13_0::tree::LeafNode::getNodes
void getNodes(ArrayT &) const
Definition LeafNode.h:741
openvdb::v13_0::tree::LeafNode::setValuesOff
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition LeafNode.h:504
openvdb::v13_0::tree::LeafNode::endValueAll
ValueAllCIter endValueAll() const
Definition LeafNode.h:346
openvdb::v13_0::tree::LeafNode::medianOff
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition LeafNode.h:1602
openvdb::v13_0::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:453
openvdb::v13_0::tree::LeafNode::onLeafVoxelCount
Index64 onLeafVoxelCount() const
Definition LeafNode.h:146
openvdb::v13_0::tree::LeafNode::endChildOff
ChildOffCIter endChildOff() const
Definition LeafNode.h:365
openvdb::v13_0::tree::LeafNode::merge
void merge(const ValueType &tileValue, bool tileActive)
Definition LeafNode.h:1709
openvdb::v13_0::tree::LeafNode::medianAll
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition LeafNode.h:1560
openvdb::v13_0::tree::LeafNode::getValueUnsafe
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
openvdb::v13_0::tree::LeafNode::~LeafNode
~LeafNode()
Destructor.
Definition LeafNode.h:1049
openvdb::v13_0::tree::LeafNode::probeValue
bool probeValue(Index offset, ValueType &val) const
Return true if the voxel at the given offset is active.
Definition LeafNode.h:1127
openvdb::v13_0::tree::LeafNode::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Definition LeafNode.h:335
openvdb::v13_0::tree::LeafNode::probeNode
NodeT * probeNode(const Coord &)
Definition LeafNode.h:738
openvdb::v13_0::tree::LeafNode::readTopology
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition LeafNode.h:1327
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ChildOffIter
ChildIter< MaskOffIterator, LeafNode, ChildOff > ChildOffIter
Definition LeafNode.h:324
openvdb::v13_0::tree::LeafNode::beginValueOn
ValueOnCIter beginValueOn() const
Definition LeafNode.h:330
openvdb::v13_0::tree::LeafNode::evalNodeOrigin
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition LeafNode.h:928
openvdb::v13_0::tree::LeafNode::buffer
const Buffer & buffer() const
Definition LeafNode.h:377
openvdb::v13_0::tree::LeafNode::probeLeafAndCache
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:765
openvdb::v13_0::tree::LeafNode::setValueMaskOn
void setValueMaskOn(Index n)
Definition LeafNode.h:922
openvdb::v13_0::tree::LeafNode::setValueOnlyUnsafe
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
openvdb::v13_0::tree::LeafNode::medianOn
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition LeafNode.h:1578
openvdb::v13_0::tree::LeafNode::offLeafVoxelCount
Index64 offLeafVoxelCount() const
Definition LeafNode.h:147
openvdb::v13_0::tree::LeafNode::probeLeaf
const LeafNode * probeLeaf(const Coord &) const
Definition LeafNode.h:774
openvdb::v13_0::tree::LeafNode::addTile
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition LeafNode.h:1629
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ChildOffCIter
ChildIter< MaskOffIterator, const LeafNode, ChildOff > ChildOffCIter
Definition LeafNode.h:325
openvdb::v13_0::tree::LeafNode::resetBackground
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition LeafNode.h:1658
openvdb::v13_0::tree::LeafNode::setOrigin
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition LeafNode.h:173
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::origin
const Coord & origin() const
Definition LeafNode.h:176
openvdb::v13_0::tree::LeafNode::getValueLevel
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition LeafNode.h:426
openvdb::v13_0::tree::LeafNode::isInactive
bool isInactive() const
Return true if all of this node's values are inactive.
Definition LeafNode.h:861
openvdb::v13_0::tree::LeafNode::modifyValueAndActiveState
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition LeafNode.h:488
openvdb::v13_0::tree::LeafNode::isValueMaskOff
bool isValueMaskOff(Index n) const
Definition LeafNode.h:911
openvdb::v13_0::tree::LeafNode::cendValueOn
ValueOnCIter cendValueOn() const
Definition LeafNode.h:339
openvdb::v13_0::tree::LeafNode::getValue
const ValueType & getValue(Index offset) const
Return the value of the voxel at the given linear offset.
Definition LeafNode.h:1111
openvdb::v13_0::tree::LeafNode::isAllocated
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition LeafNode.h:155
openvdb::v13_0::tree::LeafNode::getValueLevelAndCache
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition LeafNode.h:656
openvdb::v13_0::tree::LeafNode::numValues
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition LeafNode.h:124
openvdb::v13_0::tree::LeafNode::getValueUnsafe
const ValueType & getValueUnsafe(Index offset) const
Return the value of the voxel at the given offset.
Definition LeafNode.h:870
openvdb::v13_0::tree::LeafNode::setActiveStateUnsafe
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
openvdb::v13_0::tree::LeafNode::beginValueOff
ValueOffCIter beginValueOff() const
Definition LeafNode.h:333
openvdb::v13_0::tree::LeafNode::setValueOffAndCache
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition LeafNode.h:618
openvdb::v13_0::tree::LeafNode::LeafNode
LeafNode(PartialCreate, const Coord &coords, const ValueType &value=zeroVal< ValueType >(), bool active=false)
"Partial creation" constructor used during file input
Definition LeafNode.h:980
openvdb::v13_0::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz, bool &state, int &level, AccessorT &) const
Return the value of the voxel at the given coordinates and return its active state and level (i....
Definition LeafNode.h:645
openvdb::v13_0::tree::LeafNode::getValueAndCache
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:571
openvdb::v13_0::tree::LeafNode::cbeginChildAll
ChildAllCIter cbeginChildAll() const
Definition LeafNode.h:357
openvdb::v13_0::tree::LeafNode::topologyIntersection
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node's set of active values with the active values of the other node,...
Definition LeafNode.h:1737
openvdb::v13_0::tree::LeafNode::endChildOff
ChildOffIter endChildOff()
Definition LeafNode.h:366
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::NUM_VOXELS
static const Index NUM_VOXELS
Definition LeafNode.h:53
openvdb::v13_0::tree::LeafNode::clip
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition LeafNode.h:1180
openvdb::v13_0::tree::LeafNode::beginChildAll
ChildAllIter beginChildAll()
Definition LeafNode.h:359
openvdb::v13_0::tree::LeafNode::setValueOn
void setValueOn(Index offset, const ValueType &val)
Set the value of the voxel at the given offset and mark the voxel as active.
Definition LeafNode.h:459
openvdb::v13_0::tree::LeafNode::combine2
void combine2(const ValueType &, const OtherNodeT &other, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1829
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ValueAllIter
ValueIter< MaskDenseIterator, LeafNode, const ValueType, ValueAll > ValueAllIter
Definition LeafNode.h:320
openvdb::v13_0::tree::LeafNode::getLevel
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition LeafNode.h:126
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ValueOffCIter
ValueIter< MaskOffIterator, const LeafNode, const ValueType, ValueOff > ValueOffCIter
Definition LeafNode.h:319
openvdb::v13_0::tree::LeafNode::isValueOnAndCache
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:579
openvdb::v13_0::tree::LeafNode::addLeaf
void addLeaf(LeafNode *)
Definition LeafNode.h:732
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::DIM
static const Index DIM
Definition LeafNode.h:51
openvdb::v13_0::tree::LeafNode::setActiveState
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition LeafNode.h:1154
openvdb::v13_0::tree::LeafNode::beginValueOn
ValueOnIter beginValueOn()
Definition LeafNode.h:331
openvdb::v13_0::tree::LeafNode::modifyValueAndCache
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:602
openvdb::v13_0::tree::LeafNode::topologyUnion
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:1729
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::LEVEL
static const Index LEVEL
Definition LeafNode.h:55
openvdb::v13_0::tree::LeafNode::probeNodeAndCache
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:756
openvdb::v13_0::tree::LeafNode::getFirstValue
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition LeafNode.h:661
openvdb::v13_0::tree::LeafNode::cbeginChildOff
ChildOffCIter cbeginChildOff() const
Definition LeafNode.h:354
openvdb::v13_0::tree::LeafNode::beginChildOff
ChildOffIter beginChildOff()
Definition LeafNode.h:356
openvdb::v13_0::tree::LeafNode::isChildMaskOff
bool isChildMaskOff(Index) const
Definition LeafNode.h:918
openvdb::v13_0::tree::LeafNode::readBuffers
void readBuffers(std::istream &is, const CoordBBox &bbox, bool fromHalf=false)
Read buffers that intersect the given bounding box.
Definition LeafNode.h:1371
openvdb::v13_0::tree::LeafNode::onVoxelCount
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition LeafNode.h:143
openvdb::v13_0::tree::LeafNode::beginChildOff
ChildOffCIter beginChildOff() const
Definition LeafNode.h:355
openvdb::v13_0::tree::LeafNode::coordToOffset
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition LeafNode.h:1069
openvdb::v13_0::tree::LeafNode::offTileCount
static Index64 offTileCount()
Definition LeafNode.h:149
openvdb::v13_0::tree::LeafNode::setValueOff
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition LeafNode.h:439
openvdb::v13_0::tree::LeafNode::hasSameTopology
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition LeafNode.h:1516
openvdb::v13_0::tree::LeafNode::endValueOff
ValueOffIter endValueOff()
Definition LeafNode.h:344
openvdb::v13_0::tree::LeafNode::setValueOff
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNode.h:441
openvdb::v13_0::tree::LeafNode::probeConstLeafAndCache
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:771
openvdb::v13_0::tree::LeafNode::endChildAll
ChildAllCIter endChildAll() const
Definition LeafNode.h:368
openvdb::v13_0::tree::LeafNode::nodeCount
void nodeCount(std::vector< Index64 > &) const
no-op
Definition LeafNode.h:134
openvdb::v13_0::tree::LeafNode::probeConstNodeAndCache
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:776
openvdb::v13_0::tree::LeafNode::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition LeafNode.h:329
openvdb::v13_0::tree::LeafNode::writeBuffers
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition LeafNode.h:1451
openvdb::v13_0::tree::LeafNode::log2dim
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition LeafNode.h:118
openvdb::v13_0::tree::LeafNode::combine
void combine(const LeafNode &other, CombineOp &op)
Definition LeafNode.h:1770
openvdb::v13_0::tree::LeafNode::getNodeLog2Dims
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition LeafNode.h:128
openvdb::v13_0::tree::LeafNode::endChildOn
ChildOnCIter endChildOn() const
Definition LeafNode.h:362
openvdb::v13_0::tree::LeafNode::probeConstLeaf
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition LeafNode.h:769
openvdb::v13_0::tree::LeafNode::setValueOnUnsafe
void setValueOnUnsafe(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNode.h:878
openvdb::v13_0::tree::LeafNode::setValueOnUnsafe
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
openvdb::v13_0::tree::LeafNode::cendChildOn
ChildOnCIter cendChildOn() const
Definition LeafNode.h:361
openvdb::v13_0::tree::LeafNode::merge
void merge(const LeafNode &other, const ValueType &, const ValueType &)
Definition LeafNode.h:1700
openvdb::v13_0::tree::LeafNode::hasActiveTiles
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition LeafNode.h:516
openvdb::v13_0::tree::LeafNode::cendChildAll
ChildAllCIter cendChildAll() const
Definition LeafNode.h:367
openvdb::v13_0::tree::LeafNode::memUsageIfLoaded
Index64 memUsageIfLoaded() const
Definition LeafNode.h:1488
openvdb::v13_0::tree::LeafNode::combine2
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1810
openvdb::v13_0::tree::LeafNode::fill
void fill(const ValueType &value, bool active)
Set all voxels to the specified value and active state.
Definition LeafNode.h:1250
openvdb::v13_0::tree::LeafNode::fill
void fill(const CoordBBox &bbox, const ValueType &, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition LeafNode.h:1220
openvdb::v13_0::tree::LeafNode::LeafNode
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other, const ValueType &offValue, const ValueType &onValue, TopologyCopy)
Topology copy constructor.
Definition LeafNode.h:1035
openvdb::v13_0::tree::LeafNode::modifyValue
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:481
openvdb::v13_0::tree::LeafNode::endChildAll
ChildAllIter endChildAll()
Definition LeafNode.h:369
openvdb::v13_0::tree::LeafNode::streamingSize
size_t streamingSize(bool toHalf=false) const
openvdb::v13_0::tree::LeafNode::setValueMask
void setValueMask(Index n, bool on)
Definition LeafNode.h:921
openvdb::v13_0::tree::LeafNode::valueMask
const NodeMaskType & valueMask() const
Definition LeafNode.h:915
openvdb::v13_0::tree::LeafNode::offVoxelCount
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition LeafNode.h:145
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::MaskOffIterator
typename NodeMaskType::OffIterator MaskOffIterator
Definition LeafNode.h:208
openvdb::v13_0::tree::LeafNode::setValueOff
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:1137
openvdb::v13_0::tree::LeafNode::swap
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition LeafNode.h:376
openvdb::v13_0::tree::LeafNode::readBuffers
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition LeafNode.h:1363
openvdb::v13_0::tree::LeafNode::isConstant
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition LeafNode.h:1524
openvdb::v13_0::tree::LeafNode::BuildType
T BuildType
Definition LeafNode.h:41
openvdb::v13_0::tree::LeafNode::cendValueAll
ValueAllCIter cendValueAll() const
Definition LeafNode.h:345
openvdb::v13_0::tree::LeafNode::LeafNode
friend class LeafNode
Definition LeafNode.h:892
openvdb::v13_0::tree::LeafNode::denseFill
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition LeafNode.h:524
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::NUM_VALUES
static const Index NUM_VALUES
Definition LeafNode.h:52
openvdb::v13_0::tree::LeafNode::negate
void negate()
Definition LeafNode.h:1754
openvdb::v13_0::tree::LeafNode::offsetToGlobalCoord
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition LeafNode.h:1093
openvdb::v13_0::tree::LeafNode::beginChildAll
ChildAllCIter beginChildAll() const
Definition LeafNode.h:358
openvdb::v13_0::tree::LeafNode::probeLeafAndCache
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:773
openvdb::v13_0::tree::LeafNode::setActiveStateAndCache
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition LeafNode.h:627
openvdb::v13_0::tree::LeafNode::getOrigin
void getOrigin(Coord &origin) const
Definition LeafNode.h:177
openvdb::v13_0::tree::LeafNode::setValuesOn
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition LeafNode.h:502
openvdb::v13_0::tree::LeafNode::setTransientData
void setTransientData(Index32 transientData)
Set the transient data value.
Definition LeafNode.h:192
openvdb::v13_0::tree::LeafNode::size
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition LeafNode.h:122
openvdb::v13_0::tree::LeafNode::cendChildOff
ChildOffCIter cendChildOff() const
Definition LeafNode.h:364
openvdb::v13_0::tree::LeafNode::skipCompressedValues
void skipCompressedValues(bool seekable, std::istream &, bool fromHalf)
Definition LeafNode.h:1347
openvdb::v13_0::tree::LeafNode::fill
void fill(const ValueType &value)
Set all voxels to the specified value but don't change their active states.
Definition LeafNode.h:1243
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::MaskOnIterator
typename NodeMaskType::OnIterator MaskOnIterator
Definition LeafNode.h:207
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::LOG2DIM
static const Index LOG2DIM
Definition LeafNode.h:49
openvdb::v13_0::tree::LeafNode::operator==
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition LeafNode.h:1468
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::SIZE
static const Index SIZE
Definition LeafNode.h:54
openvdb::v13_0::tree::LeafNode::evalActiveBoundingBox
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition LeafNode.h:1498
openvdb::v13_0::tree::LeafNode::isEmpty
bool isEmpty() const
Return true if this node has no active voxels.
Definition LeafNode.h:151
openvdb::v13_0::tree::LeafNode::combine2
void combine2(const LeafNode &b0, const OtherNodeT &b1, CombineOp &)
Definition LeafNode.h:1848
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ValueOnIter
ValueIter< MaskOnIterator, LeafNode, const ValueType, ValueOn > ValueOnIter
Definition LeafNode.h:316
openvdb::v13_0::tree::LeafNode::merge
void merge(const LeafNode &)
Definition LeafNode.h:1680
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ValueOnCIter
ValueIter< MaskOnIterator, const LeafNode, const ValueType, ValueOn > ValueOnCIter
Definition LeafNode.h:317
openvdb::v13_0::tree::LeafNode::beginValueOff
ValueOffIter beginValueOff()
Definition LeafNode.h:334
openvdb::v13_0::tree::LeafNode::probeConstNode
const NodeT * probeConstNode(const Coord &) const
Definition LeafNode.h:740
openvdb::v13_0::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition LeafNode.h:449
openvdb::v13_0::tree::LeafNode::buffer
Buffer & buffer()
Definition LeafNode.h:378
openvdb::v13_0::tree::LeafNode::setValueOnlyAndCache
void setValueOnlyAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition LeafNode.h:593
openvdb::v13_0::tree::LeafNode::setValueOnly
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:1169
openvdb::v13_0::tree::LeafNode::setActiveState
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition LeafNode.h:431
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ChildOnCIter
ChildIter< MaskOnIterator, const LeafNode, ChildOn > ChildOnCIter
Definition LeafNode.h:323
openvdb::v13_0::tree::LeafNode::allocate
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition LeafNode.h:157
openvdb::v13_0::tree::LeafNode::getValueMask
const NodeMaskType & getValueMask() const
Definition LeafNode.h:913
openvdb::v13_0::tree::LeafNode::addTileAndCache
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition LeafNode.h:1646
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::TOTAL
static const Index TOTAL
Definition LeafNode.h:50
openvdb::v13_0::tree::LeafNode::addLeafAndCache
void addLeafAndCache(LeafNode *, AccessorT &)
Definition LeafNode.h:734
openvdb::v13_0::tree::LeafNode::modifyValue
void modifyValue(Index offset, const ModifyOp &op)
Apply a functor to the value of the voxel at the given offset and mark the voxel as active.
Definition LeafNode.h:467
openvdb::v13_0::tree::LeafNode::cendValueOff
ValueOffCIter cendValueOff() const
Definition LeafNode.h:342
openvdb::v13_0::tree::LeafNode::setValueMaskOff
void setValueMaskOff(Index n)
Definition LeafNode.h:923
openvdb::v13_0::tree::LeafNode::memUsage
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition LeafNode.h:1478
openvdb::v13_0::tree::LeafNode::isDense
bool isDense() const
Return true if this node contains only active voxels.
Definition LeafNode.h:153
openvdb::v13_0::tree::LeafNode::endValueOff
ValueOffCIter endValueOff() const
Definition LeafNode.h:343
openvdb::v13_0::tree::LeafNode::setValueAndCache
void setValueAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition LeafNode.h:584
openvdb::v13_0::tree::LeafNode::isValueOff
bool isValueOff(const Coord &xyz) const
Return true if the voxel at the given coordinates is inactive.
Definition LeafNode.h:511
openvdb::v13_0::tree::LeafNode::str
std::string str() const
Return a string representation of this node.
Definition LeafNode.h:1056
openvdb::v13_0::tree::LeafNode::stealNode
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition LeafNode.h:736
openvdb::v13_0::tree::LeafNode::setValueOffUnsafe
void setValueOffUnsafe(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNode.h:882
openvdb::v13_0::tree::LeafNode::ValueType
T ValueType
Definition LeafNode.h:42
openvdb::v13_0::tree::LeafNode::probeValue
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:1120
openvdb::v13_0::tree::LeafNode::endValueOn
ValueOnCIter endValueOn() const
Definition LeafNode.h:340
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::MaskDenseIterator
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition LeafNode.h:209
openvdb::v13_0::tree::LeafNode::voxelizeActiveTiles
void voxelizeActiveTiles(bool=true)
No-op.
Definition LeafNode.h:673
openvdb::v13_0::tree::LeafNode::modifyValueAndActiveStateAndCache
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition LeafNode.h:610
openvdb::v13_0::tree::LeafNode::isValueOff
bool isValueOff(Index offset) const
Return true if the voxel at the given offset is inactive.
Definition LeafNode.h:513
openvdb::v13_0::tree::LeafNode::touchLeafAndCache
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:754
openvdb::v13_0::tree::LeafNode::LeafNode
LeafNode(const Coord &coords, const ValueType &value=zeroVal< ValueType >(), bool active=false)
Constructor.
Definition LeafNode.h:970
openvdb::v13_0::tree::LeafNode::getLastValue
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition LeafNode.h:663
openvdb::v13_0::tree::LeafNode::beginValueAll
ValueAllCIter beginValueAll() const
Definition LeafNode.h:336
openvdb::v13_0::tree::LeafNode::dim
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition LeafNode.h:120
openvdb::v13_0::tree::LeafNode::setValueOffUnsafe
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
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ValueAllCIter
ValueIter< MaskDenseIterator, const LeafNode, const ValueType, ValueAll > ValueAllCIter
Definition LeafNode.h:321
openvdb::v13_0::tree::LeafNode::combine
void combine(const ValueType &value, bool valueIsActive, CombineOp &op)
Definition LeafNode.h:1789
openvdb::v13_0::tree::LeafNode< ValueType, Log2Dim >::ChildAllIter
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition LeafNode.h:326
openvdb::v13_0::tree::LeafNode::isValueMaskOn
bool isValueMaskOn(Index n) const
Definition LeafNode.h:909
openvdb::v13_0::tree::LeafNode::LeafNodeType
LeafNode< ValueType, Log2Dim > LeafNodeType
Definition LeafNode.h:44
openvdb::v13_0::tree::LeafNode::LeafNode
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other, const ValueType &background, TopologyCopy)
Topology copy constructor.
Definition LeafNode.h:1022
openvdb::v13_0::tree::LeafNode::beginValueAll
ValueAllIter beginValueAll()
Definition LeafNode.h:337
openvdb::v13_0::tree::LeafNode::LeafNode
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other)
Value conversion copy constructor.
Definition LeafNode.h:1003
openvdb::v13_0::util::NodeMask
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition NodeMasks.h:308
openvdb::v13_0::util::NodeMask::beginOn
OnIterator beginOn() const
Definition NodeMasks.h:352
openvdb::v13_0::util::NodeMask::beginOff
OffIterator beginOff() const
Definition NodeMasks.h:354
openvdb::v13_0::util::NodeMask::DenseIterator
DenseMaskIterator< NodeMask > DenseIterator
Definition NodeMasks.h:350
openvdb::v13_0::util::NodeMask::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition NodeMasks.h:502
openvdb::v13_0::util::NodeMask::OnIterator
OnMaskIterator< NodeMask > OnIterator
Definition NodeMasks.h:348
openvdb::v13_0::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition NodeMasks.h:452
openvdb::v13_0::util::NodeMask::OffIterator
OffMaskIterator< NodeMask > OffIterator
Definition NodeMasks.h:349
openvdb::v13_0::io::getDataCompression
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
openvdb::v13_0::io::COMPRESS_ZIP
@ COMPRESS_ZIP
Definition Compression.h:55
openvdb::v13_0::io::checkFormatVersion
OPENVDB_API void checkFormatVersion(std::ios_base &)
Throws an IoError if the file format version number is not supported.
openvdb::v13_0::io::readCompressedValues
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition Compression.h:466
openvdb::v13_0::io::getGridBackgroundValuePtr
OPENVDB_API const void * getGridBackgroundValuePtr(std::ios_base &)
Return a pointer to the background value of the grid currently being read from or written to the give...
openvdb::v13_0::io::getStreamMetadataPtr
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
openvdb::v13_0::io::readData
void readData(std::istream &is, T *data, Index count, uint32_t compression, DelayedLoadMetadata *metadata=nullptr, size_t metadataOffset=size_t(0))
Read data from a stream.
Definition Compression.h:248
openvdb::v13_0::io::writeCompressedValues
void writeCompressedValues(std::ostream &os, const ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition Compression.h:646
openvdb::v13_0::math::isApproxEqual
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:431
openvdb::v13_0::math::negative
T negative(const T &val)
Return the unary negation of the given value.
Definition Math.h:139
openvdb::v13_0::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:468
openvdb::v13_0::tree::iter
Definition TreeIterator.h:30
openvdb::v13_0::tree::operator<<
std::ostream & operator<<(std::ostream &os, const typename LeafNode< T, Log2Dim >::Buffer &buf)
Definition LeafNode.h:1870
openvdb::v13_0::Index
Index32 Index
Definition Types.h:34
openvdb::v13_0::zeroVal
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:71
openvdb::v13_0::Index32
uint32_t Index32
Definition Types.h:32
openvdb::v13_0::Int32
int32_t Int32
Definition Types.h:36
openvdb::v13_0::Index64
uint64_t Index64
Definition Types.h:33
openvdb::v13_0::SharedPtr
std::shared_ptr< T > SharedPtr
Definition Types.h:95
openvdb::v13_0::MERGE_NODES
@ MERGE_NODES
Definition Types.h:575
openvdb::v13_0::MERGE_ACTIVE_STATES_AND_NODES
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:576
openvdb
Definition Exceptions.h:13
std
Definition Coord.h:590
Types.h
allocate
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition pnanovdb_validate_strides.h:20
openvdb::v13_0::io::HalfReader
Definition Compression.h:293
openvdb::v13_0::tree::DenseIteratorBase< MaskDenseIterator, DenseIter, NodeT, void, ValueT >::NonConstValueType
typename std::remove_const< ValueT >::type NonConstValueType
Definition Iterator.h:184
openvdb::v13_0::tree::DenseIteratorBase< MaskDenseIterator, DenseIter< NodeT, ValueT, TagT >, NodeT, void, ValueT >::DenseIteratorBase
DenseIteratorBase()
Definition Iterator.h:188
openvdb::v13_0::tree::LeafNode::ChildIter::ChildIter
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNode.h:284
openvdb::v13_0::tree::LeafNode::ChildIter::ChildIter
ChildIter()
Definition LeafNode.h:283
openvdb::v13_0::tree::LeafNode::ChildOff
Definition LeafNode.h:213
openvdb::v13_0::tree::LeafNode::ChildOn
Definition LeafNode.h:213
openvdb::v13_0::tree::LeafNode::DenseIter::DenseIter
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition LeafNode.h:296
openvdb::v13_0::tree::LeafNode::DenseIter::unsetItem
void unsetItem(Index pos, const ValueT &value) const
Definition LeafNode.h:309
openvdb::v13_0::tree::LeafNode::DenseIter::getItem
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition LeafNode.h:298
openvdb::v13_0::tree::LeafNode::DenseIter::DenseIter
DenseIter()
Definition LeafNode.h:295
openvdb::v13_0::tree::LeafNode::DenseIter::NonConstValueT
typename BaseT::NonConstValueType NonConstValueT
Definition LeafNode.h:293
openvdb::v13_0::tree::LeafNode::DenseIter::BaseT
DenseIteratorBase< MaskDenseIterator, DenseIter, NodeT, void, ValueT > BaseT
Definition LeafNode.h:292
openvdb::v13_0::tree::LeafNode::SameConfiguration
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition LeafNode.h:65
openvdb::v13_0::tree::LeafNode::SameConfiguration::value
static const bool value
Definition LeafNode.h:66
openvdb::v13_0::tree::LeafNode::ValueConverter
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition LeafNode.h:60
openvdb::v13_0::tree::LeafNode::ValueConverter::Type
LeafNode< OtherValueType, Log2Dim > Type
Definition LeafNode.h:60
openvdb::v13_0::tree::LeafNode::ValueIter::setValue
void setValue(const ValueT &value) const
Definition LeafNode.h:251
openvdb::v13_0::tree::LeafNode::ValueIter::modifyValue
void modifyValue(const ModifyOp &op) const
Definition LeafNode.h:270
openvdb::v13_0::tree::LeafNode::ValueIter::getItem
ValueT & getItem(Index pos) const
Definition LeafNode.h:234
openvdb::v13_0::tree::LeafNode::ValueIter::setItem
void setItem(Index pos, const ValueT &value) const
Definition LeafNode.h:238
openvdb::v13_0::tree::LeafNode::ValueIter::ValueType
std::conditional_t< std::is_const_v< NodeT >, ValueT, std::remove_const_t< ValueT > > ValueType
Definition LeafNode.h:222
openvdb::v13_0::tree::LeafNode::ValueIter::ValueIter
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNode.h:227
openvdb::v13_0::tree::LeafNode::ValueIter::getValue
ValueT & getValue() const
Definition LeafNode.h:235
openvdb::v13_0::tree::LeafNode::ValueIter::ValueIter
ValueIter()
Definition LeafNode.h:226
openvdb::v13_0::tree::LeafNode::ValueIter::modifyItem
void modifyItem(Index n, const ModifyOp &op) const
Definition LeafNode.h:255
openvdb::v13_0::tree::LeafNode::ValueIter::BaseT
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition LeafNode.h:224
openvdb::v13_0::tree::LeafNode::ValueOff
Definition LeafNode.h:212
openvdb::v13_0::tree::LeafNode::ValueOn
Definition LeafNode.h:212
openvdb::v13_0::tree::SameLeafConfig< Dim1, LeafNode< T2, Dim1 > >::value
static const bool value
Definition LeafNode.h:952
openvdb::v13_0::tree::SameLeafConfig
Definition LeafNode.h:949
openvdb::v13_0::tree::SameLeafConfig::value
static const bool value
Definition LeafNode.h:949
openvdb::v13_0::tree::SparseIteratorBase< MaskIterT, ValueIter< MaskIterT, NodeT, ValueT, TagT >, NodeT, ValueT >::SparseIteratorBase
SparseIteratorBase()
Definition Iterator.h:122
openvdb::v13_0::tree::LeafNode::ChildIter< MaskOnIterator, LeafNode, ChildOn >::ValueType
ValueType ValueType
Definition Iterator.h:117
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218