OpenVDB: openvdb/tree/LeafNodeBool.h Source File

OpenVDB 10.0.1

Loading...
Searching...
No Matches
LeafNodeBool.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4#ifndef OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
5#define OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
6
7#include <openvdb/Types.h>
8#include <openvdb/io/Compression.h> // for io::readData(), etc.
9#include <openvdb/math/Math.h> // for math::isZero()
10#include <openvdb/util/NodeMasks.h>
11#include "LeafNode.h"
12#include "Iterator.h"
13#include <iostream>
14#include <sstream>
15#include <string>
16#include <type_traits>
17#include <vector>
18
19
20namespace openvdb {
21 OPENVDB_USE_VERSION_NAMESPACE
22namespace OPENVDB_VERSION_NAME {
23namespace tree {
24
25/// @brief LeafNode specialization for values of type bool that stores both
26/// the active states and the values of (2^Log2Dim)^3 voxels as bit masks
27template<Index Log2Dim>
28 class LeafNode<bool, Log2Dim>
29{
30public:
31 using LeafNodeType = LeafNode<bool, Log2Dim>;
32 using BuildType = bool;
33 using ValueType = bool;
34 using Buffer = LeafBuffer<ValueType, Log2Dim>;
35 using NodeMaskType = util::NodeMask<Log2Dim>;
36 using Ptr = SharedPtr<LeafNodeType>;
37
38 // These static declarations must be on separate lines to avoid VC9 compiler errors.
39 static const Index LOG2DIM = Log2Dim; // needed by parent nodes
40 static const Index TOTAL = Log2Dim; // needed by parent nodes
41 static const Index DIM = 1 << TOTAL; // dimension along one coordinate direction
42 static const Index NUM_VALUES = 1 << 3 * Log2Dim;
43 static const Index NUM_VOXELS = NUM_VALUES; // total number of voxels represented by this node
44 static const Index SIZE = NUM_VALUES;
45 static const Index LEVEL = 0; // level 0 = leaf
46
47 /// @brief ValueConverter<T>::Type is the type of a LeafNode having the same
48 /// dimensions as this node but a different value type, T.
49 template<typename ValueType>
50 struct ValueConverter { using Type = LeafNode<ValueType, Log2Dim>; };
51
52 /// @brief SameConfiguration<OtherNodeType>::value is @c true if and only if
53 /// OtherNodeType is the type of a LeafNode with the same dimensions as this node.
54 template<typename OtherNodeType>
55 struct SameConfiguration {
56 static const bool value = SameLeafConfig<LOG2DIM, OtherNodeType>::value;
57 };
58
59
60 /// Default constructor
61 LeafNode();
62
63 /// Constructor
64 /// @param xyz the coordinates of a voxel that lies within the node
65 /// @param value the initial value for all of this node's voxels
66 /// @param active the active state to which to initialize all voxels
67 explicit LeafNode(const Coord& xyz, bool value = false, bool active = false);
68
69 /// "Partial creation" constructor used during file input
70 LeafNode(PartialCreate, const Coord& xyz, bool value = false, bool active = false);
71
72 /// Deep copy constructor
73 LeafNode(const LeafNode&);
74
75 /// Deep assignment operator
76 LeafNode& operator=(const LeafNode&) = default;
77
78 /// Value conversion copy constructor
79 template<typename OtherValueType>
80 explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
81
82 /// Topology copy constructor
83 template<typename ValueType>
84 LeafNode(const LeafNode<ValueType, Log2Dim>& other, TopologyCopy);
85
86 //@{
87 /// @brief Topology copy constructor
88 /// @note This variant exists mainly to enable template instantiation.
89 template<typename ValueType>
90 LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool offValue, bool onValue, TopologyCopy);
91 template<typename ValueType>
92 LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool background, TopologyCopy);
93 //@}
94
95 /// Destructor
96 ~LeafNode();
97
98 //
99 // Statistics
100 //
101 /// Return log2 of the size of the buffer storage.
102 static Index log2dim() { return Log2Dim; }
103 /// Return the number of voxels in each dimension.
104 static Index dim() { return DIM; }
105 static Index size() { return SIZE; }
106 static Index numValues() { return SIZE; }
107 static Index getLevel() { return LEVEL; }
108 static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
109 static Index getChildDim() { return 1; }
110
111 static Index32 leafCount() { return 1; }
112 /// no-op
113 void nodeCount(std::vector<Index32> &) const {}
114 static Index32 nonLeafCount() { return 0; }
115
116 /// Return the number of active voxels.
117 Index64 onVoxelCount() const { return mValueMask.countOn(); }
118 /// Return the number of inactive voxels.
119 Index64 offVoxelCount() const { return mValueMask.countOff(); }
120 Index64 onLeafVoxelCount() const { return onVoxelCount(); }
121 Index64 offLeafVoxelCount() const { return offVoxelCount(); }
122 static Index64 onTileCount() { return 0; }
123 static Index64 offTileCount() { return 0; }
124
125 /// Return @c true if this node has no active voxels.
126 bool isEmpty() const { return mValueMask.isOff(); }
127 /// Return @c true if this node only contains active voxels.
128 bool isDense() const { return mValueMask.isOn(); }
129 /// @brief Return @c true if memory for this node's buffer has been allocated.
130 /// @details Currently, boolean leaf nodes don't support partial creation,
131 /// so this always returns @c true.
132 bool isAllocated() const { return true; }
133 /// @brief Allocate memory for this node's buffer if it has not already been allocated.
134 /// @details Currently, boolean leaf nodes don't support partial creation,
135 /// so this has no effect.
136 bool allocate() { return true; }
137
138 /// Return the memory in bytes occupied by this node.
139 Index64 memUsage() const;
140 Index64 memUsageIfLoaded() const;
141
142 /// Expand the given bounding box so that it includes this leaf node's active voxels.
143 /// If visitVoxels is false this LeafNode will be approximated as dense, i.e. with all
144 /// voxels active. Else the individual active voxels are visited to produce a tight bbox.
145 void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
146
147 /// @brief Return the bounding box of this node, i.e., the full index space
148 /// spanned by this leaf node.
149 CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
150
151 /// Set the grid index coordinates of this node's local origin.
152 void setOrigin(const Coord& origin) { mOrigin = origin; }
153 //@{
154 /// Return the grid index coordinates of this node's local origin.
155 const Coord& origin() const { return mOrigin; }
156 void getOrigin(Coord& origin) const { origin = mOrigin; }
157 void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
158 //@}
159
160 /// Return the linear table offset of the given global or local coordinates.
161 static Index coordToOffset(const Coord& xyz);
162 /// @brief Return the local coordinates for a linear table offset,
163 /// where offset 0 has coordinates (0, 0, 0).
164 static Coord offsetToLocalCoord(Index n);
165 /// Return the global coordinates for a linear table offset.
166 Coord offsetToGlobalCoord(Index n) const;
167
168#if OPENVDB_ABI_VERSION_NUMBER >= 9
169 /// Return the transient data value.
170 Index32 transientData() const { return mTransientData; }
171 /// Set the transient data value.
172 void setTransientData(Index32 transientData) { mTransientData = transientData; }
173#endif
174
175 /// Return a string representation of this node.
176 std::string str() const;
177
178 /// @brief Return @c true if the given node (which may have a different @c ValueType
179 /// than this node) has the same active value topology as this node.
180 template<typename OtherType, Index OtherLog2Dim>
181 bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
182
183 /// Check for buffer equivalence by value.
184 bool operator==(const LeafNode&) const;
185 bool operator!=(const LeafNode&) const;
186
187 //
188 // Buffer management
189 //
190 /// @brief Exchange this node's data buffer with the given data buffer
191 /// without changing the active states of the values.
192 void swap(Buffer& other) { mBuffer.swap(other); }
193 const Buffer& buffer() const { return mBuffer; }
194 Buffer& buffer() { return mBuffer; }
195
196 //
197 // I/O methods
198 //
199 /// Read in just the topology.
200 void readTopology(std::istream&, bool fromHalf = false);
201 /// Write out just the topology.
202 void writeTopology(std::ostream&, bool toHalf = false) const;
203
204 /// Read in the topology and the origin.
205 void readBuffers(std::istream&, bool fromHalf = false);
206 void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
207 /// Write out the topology and the origin.
208 void writeBuffers(std::ostream&, bool toHalf = false) const;
209
210 //
211 // Accessor methods
212 //
213 /// Return the value of the voxel at the given coordinates.
214 const bool& getValue(const Coord& xyz) const;
215 /// Return the value of the voxel at the given offset.
216 const bool& getValue(Index offset) const;
217
218 /// @brief Return @c true if the voxel at the given coordinates is active.
219 /// @param xyz the coordinates of the voxel to be probed
220 /// @param[out] val the value of the voxel at the given coordinates
221 bool probeValue(const Coord& xyz, bool& val) const;
222
223 /// Return the level (0) at which leaf node values reside.
224 static Index getValueLevel(const Coord&) { return LEVEL; }
225
226 /// Set the active state of the voxel at the given coordinates but don't change its value.
227 void setActiveState(const Coord& xyz, bool on);
228 /// Set the active state of the voxel at the given offset but don't change its value.
229 void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
230
231 /// Set the value of the voxel at the given coordinates but don't change its active state.
232 void setValueOnly(const Coord& xyz, bool val);
233 /// Set the value of the voxel at the given offset but don't change its active state.
234 void setValueOnly(Index offset, bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
235
236 /// Mark the voxel at the given coordinates as inactive but don't change its value.
237 void setValueOff(const Coord& xyz) { mValueMask.setOff(this->coordToOffset(xyz)); }
238 /// Mark the voxel at the given offset as inactive but don't change its value.
239 void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
240
241 /// Set the value of the voxel at the given coordinates and mark the voxel as inactive.
242 void setValueOff(const Coord& xyz, bool val);
243 /// Set the value of the voxel at the given offset and mark the voxel as inactive.
244 void setValueOff(Index offset, bool val);
245
246 /// Mark the voxel at the given coordinates as active but don't change its value.
247 void setValueOn(const Coord& xyz) { mValueMask.setOn(this->coordToOffset(xyz)); }
248 /// Mark the voxel at the given offset as active but don't change its value.
249 void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
250
251 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
252 void setValueOn(const Coord& xyz, bool val);
253 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
254 void setValue(const Coord& xyz, bool val) { this->setValueOn(xyz, val); }
255 /// Set the value of the voxel at the given offset and mark the voxel as active.
256 void setValueOn(Index offset, bool val);
257
258 /// @brief Apply a functor to the value of the voxel at the given offset
259 /// and mark the voxel as active.
260 template<typename ModifyOp>
261 void modifyValue(Index offset, const ModifyOp& op);
262 /// @brief Apply a functor to the value of the voxel at the given coordinates
263 /// and mark the voxel as active.
264 template<typename ModifyOp>
265 void modifyValue(const Coord& xyz, const ModifyOp& op);
266
267 /// Apply a functor to the voxel at the given coordinates.
268 template<typename ModifyOp>
269 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op);
270
271 /// Mark all voxels as active but don't change their values.
272 void setValuesOn() { mValueMask.setOn(); }
273 /// Mark all voxels as inactive but don't change their values.
274 void setValuesOff() { mValueMask.setOff(); }
275
276 /// Return @c true if the voxel at the given coordinates is active.
277 bool isValueOn(const Coord& xyz) const { return mValueMask.isOn(this->coordToOffset(xyz)); }
278 /// Return @c true if the voxel at the given offset is active.
279 bool isValueOn(Index offset) const { assert(offset < SIZE); return mValueMask.isOn(offset); }
280
281 /// Return @c false since leaf nodes never contain tiles.
282 static bool hasActiveTiles() { return false; }
283
284 /// Set all voxels that lie outside the given axis-aligned box to the background.
285 void clip(const CoordBBox&, bool background);
286
287 /// Set all voxels within an axis-aligned box to the specified value and active state.
288 void fill(const CoordBBox& bbox, bool value, bool active = true);
289 /// Set all voxels within an axis-aligned box to the specified value and active state.
290 void denseFill(const CoordBBox& bbox, bool val, bool on = true) { this->fill(bbox, val, on); }
291
292 /// Set all voxels to the specified value but don't change their active states.
293 void fill(const bool& value);
294 /// Set all voxels to the specified value and active state.
295 void fill(const bool& value, bool active);
296
297 /// @brief Copy into a dense grid the values of the voxels that lie within
298 /// a given bounding box.
299 ///
300 /// @param bbox inclusive bounding box of the voxels to be copied into the dense grid
301 /// @param dense dense grid with a stride in @e z of one (see tools::Dense
302 /// in tools/Dense.h for the required API)
303 ///
304 /// @note @a bbox is assumed to be identical to or contained in the coordinate domains
305 /// of both the dense grid and this node, i.e., no bounds checking is performed.
306 /// @note Consider using tools::CopyToDense in tools/Dense.h
307 /// instead of calling this method directly.
308 template<typename DenseT>
309 void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
310
311 /// @brief Copy from a dense grid into this node the values of the voxels
312 /// that lie within a given bounding box.
313 /// @details Only values that are different (by more than the given tolerance)
314 /// from the background value will be active. Other values are inactive
315 /// and truncated to the background value.
316 ///
317 /// @param bbox inclusive bounding box of the voxels to be copied into this node
318 /// @param dense dense grid with a stride in @e z of one (see tools::Dense
319 /// in tools/Dense.h for the required API)
320 /// @param background background value of the tree that this node belongs to
321 /// @param tolerance tolerance within which a value equals the background value
322 ///
323 /// @note @a bbox is assumed to be identical to or contained in the coordinate domains
324 /// of both the dense grid and this node, i.e., no bounds checking is performed.
325 /// @note Consider using tools::CopyFromDense in tools/Dense.h
326 /// instead of calling this method directly.
327 template<typename DenseT>
328 void copyFromDense(const CoordBBox& bbox, const DenseT& dense, bool background, bool tolerance);
329
330 /// @brief Return the value of the voxel at the given coordinates.
331 /// @note Used internally by ValueAccessor.
332 template<typename AccessorT>
333 const bool& getValueAndCache(const Coord& xyz, AccessorT&) const {return this->getValue(xyz);}
334
335 /// @brief Return @c true if the voxel at the given coordinates is active.
336 /// @note Used internally by ValueAccessor.
337 template<typename AccessorT>
338 bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
339
340 /// @brief Change the value of the voxel at the given coordinates and mark it as active.
341 /// @note Used internally by ValueAccessor.
342 template<typename AccessorT>
343 void setValueAndCache(const Coord& xyz, bool val, AccessorT&) { this->setValueOn(xyz, val); }
344
345 /// @brief Change the value of the voxel at the given coordinates
346 /// but preserve its state.
347 /// @note Used internally by ValueAccessor.
348 template<typename AccessorT>
349 void setValueOnlyAndCache(const Coord& xyz, bool val, AccessorT&) {this->setValueOnly(xyz,val);}
350
351 /// @brief Change the value of the voxel at the given coordinates and mark it as inactive.
352 /// @note Used internally by ValueAccessor.
353 template<typename AccessorT>
354 void setValueOffAndCache(const Coord& xyz, bool value, AccessorT&)
355 {
356 this->setValueOff(xyz, value);
357 }
358
359 /// @brief Apply a functor to the value of the voxel at the given coordinates
360 /// and mark the voxel as active.
361 /// @note Used internally by ValueAccessor.
362 template<typename ModifyOp, typename AccessorT>
363 void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
364 {
365 this->modifyValue(xyz, op);
366 }
367
368 /// Apply a functor to the voxel at the given coordinates.
369 /// @note Used internally by ValueAccessor.
370 template<typename ModifyOp, typename AccessorT>
371 void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
372 {
373 this->modifyValueAndActiveState(xyz, op);
374 }
375
376 /// @brief Set the active state of the voxel at the given coordinates
377 /// without changing its value.
378 /// @note Used internally by ValueAccessor.
379 template<typename AccessorT>
380 void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
381 {
382 this->setActiveState(xyz, on);
383 }
384
385 /// @brief Return @c true if the voxel at the given coordinates is active
386 /// and return the voxel value in @a val.
387 /// @note Used internally by ValueAccessor.
388 template<typename AccessorT>
389 bool probeValueAndCache(const Coord& xyz, bool& val, AccessorT&) const
390 {
391 return this->probeValue(xyz, val);
392 }
393
394 /// @brief Return the LEVEL (=0) at which leaf node values reside.
395 /// @note Used internally by ValueAccessor.
396 template<typename AccessorT>
397 static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
398
399 /// @brief Return a const reference to the first entry in the buffer.
400 /// @note Since it's actually a reference to a static data member
401 /// it should not be converted to a non-const pointer!
402 const bool& getFirstValue() const { if (mValueMask.isOn(0)) return Buffer::sOn; else return Buffer::sOff; }
403 /// @brief Return a const reference to the last entry in the buffer.
404 /// @note Since it's actually a reference to a static data member
405 /// it should not be converted to a non-const pointer!
406 const bool& getLastValue() const { if (mValueMask.isOn(SIZE-1)) return Buffer::sOn; else return Buffer::sOff; }
407
408 /// Return @c true if all of this node's voxels have the same active state
409 /// and are equal to within the given tolerance, and return the value in
410 /// @a constValue and the active state in @a state.
411 bool isConstant(bool& constValue, bool& state, bool tolerance = 0) const;
412
413 /// @brief Computes the median value of all the active and inactive voxels in this node.
414 /// @return The median value.
415 ///
416 /// @details The median for boolean values is defined as the mode
417 /// of the values, i.e. the value that occurs most often.
418 bool medianAll() const;
419
420 /// @brief Computes the median value of all the active voxels in this node.
421 /// @return The number of active voxels.
422 /// @param value Updated with the median value of all the active voxels.
423 ///
424 /// @details The median for boolean values is defined as the mode
425 /// of the values, i.e. the value that occurs most often.
426 Index medianOn(ValueType &value) const;
427
428 /// @brief Computes the median value of all the inactive voxels in this node.
429 /// @return The number of inactive voxels.
430 /// @param value Updated with the median value of all the inactive voxels.
431 ///
432 /// @details The median for boolean values is defined as the mode
433 /// of the values, i.e. the value that occurs most often.
434 Index medianOff(ValueType &value) const;
435
436 /// Return @c true if all of this node's values are inactive.
437 bool isInactive() const { return mValueMask.isOff(); }
438
439 void resetBackground(bool oldBackground, bool newBackground);
440
441 void negate() { mBuffer.mData.toggle(); }
442
443 template<MergePolicy Policy>
444 void merge(const LeafNode& other, bool bg = false, bool otherBG = false);
445 template<MergePolicy Policy> void merge(bool tileValue, bool tileActive);
446
447 /// @brief No-op
448 /// @details This function exists only to enable template instantiation.
449 void voxelizeActiveTiles(bool = true) {}
450
451 /// @brief Union this node's set of active values with the active values
452 /// of the other node, whose @c ValueType may be different. So a
453 /// resulting voxel will be active if either of the original voxels
454 /// were active.
455 ///
456 /// @note This operation modifies only active states, not values.
457 template<typename OtherType>
458 void topologyUnion(const LeafNode<OtherType, Log2Dim>& other, const bool preserveTiles = false);
459
460 /// @brief Intersect this node's set of active values with the active values
461 /// of the other node, whose @c ValueType may be different. So a
462 /// resulting voxel will be active only if both of the original voxels
463 /// were active.
464 ///
465 /// @details The last dummy argument is required to match the signature
466 /// for InternalNode::topologyIntersection.
467 ///
468 /// @note This operation modifies only active states, not
469 /// values. Also note that this operation can result in all voxels
470 /// being inactive so consider subsequently calling prune.
471 template<typename OtherType>
472 void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const bool&);
473
474 /// @brief Difference this node's set of active values with the active values
475 /// of the other node, whose @c ValueType may be different. So a
476 /// resulting voxel will be active only if the original voxel is
477 /// active in this LeafNode and inactive in the other LeafNode.
478 ///
479 /// @details The last dummy argument is required to match the signature
480 /// for InternalNode::topologyDifference.
481 ///
482 /// @note This operation modifies only active states, not values.
483 /// Also, because it can deactivate all of this node's voxels,
484 /// consider subsequently calling prune.
485 template<typename OtherType>
486 void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const bool&);
487
488 template<typename CombineOp>
489 void combine(const LeafNode& other, CombineOp& op);
490 template<typename CombineOp>
491 void combine(bool, bool valueIsActive, CombineOp& op);
492
493 template<typename CombineOp, typename OtherType /*= bool*/>
494 void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
495 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
496 void combine2(bool, const OtherNodeT& other, bool valueIsActive, CombineOp&);
497 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
498 void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
499
500 //@{
501 /// This function exists only to enable template instantiation.
502 void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
503 void addLeaf(LeafNode*) {}
504 template<typename AccessorT>
505 void addLeafAndCache(LeafNode*, AccessorT&) {}
506 template<typename NodeT>
507 NodeT* stealNode(const Coord&, const ValueType&, bool) { return nullptr; }
508 template<typename NodeT>
509 NodeT* probeNode(const Coord&) { return nullptr; }
510 template<typename NodeT>
511 const NodeT* probeConstNode(const Coord&) const { return nullptr; }
512 template<typename ArrayT> void getNodes(ArrayT&) const {}
513 template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
514 //@}
515
516 void addTile(Index level, const Coord&, bool val, bool active);
517 void addTile(Index offset, bool val, bool active);
518 template<typename AccessorT>
519 void addTileAndCache(Index level, const Coord&, bool val, bool active, AccessorT&);
520
521 //@{
522 /// @brief Return a pointer to this node.
523 LeafNode* touchLeaf(const Coord&) { return this; }
524 template<typename AccessorT>
525 LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
526 LeafNode* probeLeaf(const Coord&) { return this; }
527 template<typename AccessorT>
528 LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
529 template<typename NodeT, typename AccessorT>
530 NodeT* probeNodeAndCache(const Coord&, AccessorT&)
531 {
532 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
533 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
534 return reinterpret_cast<NodeT*>(this);
535 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
536 }
537 //@}
538 //@{
539 /// @brief Return a @const pointer to this node.
540 const LeafNode* probeLeaf(const Coord&) const { return this; }
541 template<typename AccessorT>
542 const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
543 const LeafNode* probeConstLeaf(const Coord&) const { return this; }
544 template<typename AccessorT>
545 const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
546 template<typename NodeT, typename AccessorT>
547 const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
548 {
549 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
550 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
551 return reinterpret_cast<const NodeT*>(this);
552 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
553 }
554 //@}
555
556 //
557 // Iterators
558 //
559protected:
560 using MaskOnIter = typename NodeMaskType::OnIterator;
561 using MaskOffIter = typename NodeMaskType::OffIterator;
562 using MaskDenseIter = typename NodeMaskType::DenseIterator;
563
564 template<typename MaskIterT, typename NodeT, typename ValueT>
565 struct ValueIter:
566 // Derives from SparseIteratorBase, but can also be used as a dense iterator,
567 // if MaskIterT is a dense mask iterator type.
568 public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
569 {
570 using BaseT = SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT>;
571
572 ValueIter() {}
573 ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
574
575 const bool& getItem(Index pos) const { return this->parent().getValue(pos); }
576 const bool& getValue() const { return this->getItem(this->pos()); }
577
578 // Note: setItem() can't be called on const iterators.
579 void setItem(Index pos, bool value) const { this->parent().setValueOnly(pos, value); }
580 // Note: setValue() can't be called on const iterators.
581 void setValue(bool value) const { this->setItem(this->pos(), value); }
582
583 // Note: modifyItem() can't be called on const iterators.
584 template<typename ModifyOp>
585 void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
586 // Note: modifyValue() can't be called on const iterators.
587 template<typename ModifyOp>
588 void modifyValue(const ModifyOp& op) const { this->modifyItem(this->pos(), op); }
589 };
590
591 /// Leaf nodes have no children, so their child iterators have no get/set accessors.
592 template<typename MaskIterT, typename NodeT>
593 struct ChildIter:
594 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>
595 {
596 ChildIter() {}
597 ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
598 MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
599 };
600
601 template<typename NodeT, typename ValueT>
602 struct DenseIter: public DenseIteratorBase<
603 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, /*ChildT=*/void, ValueT>
604 {
605 using BaseT = DenseIteratorBase<MaskDenseIter, DenseIter, NodeT, void, ValueT>;
606 using NonConstValueT = typename BaseT::NonConstValueType;
607
608 DenseIter() {}
609 DenseIter(const MaskDenseIter& iter, NodeT* parent): BaseT(iter, parent) {}
610
611 bool getItem(Index pos, void*& child, NonConstValueT& value) const
612 {
613 value = this->parent().getValue(pos);
614 child = nullptr;
615 return false; // no child
616 }
617
618 // Note: setItem() can't be called on const iterators.
619 //void setItem(Index pos, void* child) const {}
620
621 // Note: unsetItem() can't be called on const iterators.
622 void unsetItem(Index pos, const ValueT& val) const {this->parent().setValueOnly(pos, val);}
623 };
624
625public:
626 using ValueOnIter = ValueIter<MaskOnIter, LeafNode, const bool>;
627 using ValueOnCIter = ValueIter<MaskOnIter, const LeafNode, const bool>;
628 using ValueOffIter = ValueIter<MaskOffIter, LeafNode, const bool>;
629 using ValueOffCIter = ValueIter<MaskOffIter, const LeafNode, const bool>;
630 using ValueAllIter = ValueIter<MaskDenseIter, LeafNode, const bool>;
631 using ValueAllCIter = ValueIter<MaskDenseIter, const LeafNode, const bool>;
632 using ChildOnIter = ChildIter<MaskOnIter, LeafNode>;
633 using ChildOnCIter = ChildIter<MaskOnIter, const LeafNode>;
634 using ChildOffIter = ChildIter<MaskOffIter, LeafNode>;
635 using ChildOffCIter = ChildIter<MaskOffIter, const LeafNode>;
636 using ChildAllIter = DenseIter<LeafNode, bool>;
637 using ChildAllCIter = DenseIter<const LeafNode, const bool>;
638
639 ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
640 ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
641 ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
642 ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
643 ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
644 ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
645 ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
646 ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
647 ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
648
649 ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
650 ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
651 ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
652 ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
653 ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
654 ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
655 ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
656 ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
657 ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
658
659 // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
660 // because leaf nodes have no children.
661 ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
662 ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
663 ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
664 ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
665 ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
666 ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
667 ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
668 ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
669 ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
670
671 ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
672 ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
673 ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
674 ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
675 ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
676 ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
677 ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
678 ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
679 ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
680
681 //
682 // Mask accessors
683 //
684 bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
685 bool isValueMaskOn() const { return mValueMask.isOn(); }
686 bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
687 bool isValueMaskOff() const { return mValueMask.isOff(); }
688 const NodeMaskType& getValueMask() const { return mValueMask; }
689 const NodeMaskType& valueMask() const { return mValueMask; }
690 NodeMaskType& getValueMask() { return mValueMask; }
691 void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
692 bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
693 bool isChildMaskOff(Index) const { return true; }
694 bool isChildMaskOff() const { return true; }
695protected:
696 void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
697 void setValueMaskOn(Index n) { mValueMask.setOn(n); }
698 void setValueMaskOff(Index n) { mValueMask.setOff(n); }
699
700 /// Compute the origin of the leaf node that contains the voxel with the given coordinates.
701 static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
702
703 /// Bitmask that determines which voxels are active
704 NodeMaskType mValueMask;
705 /// Bitmask representing the values of voxels
706 Buffer mBuffer;
707 /// Global grid index coordinates (x,y,z) of the local origin of this node
708 Coord mOrigin;
709#if OPENVDB_ABI_VERSION_NUMBER >= 9
710 /// Transient data (not serialized)
711 Index32 mTransientData = 0;
712#endif
713
714private:
715 /// @brief During topology-only construction, access is needed
716 /// to protected/private members of other template instances.
717 template<typename, Index> friend class LeafNode;
718
719 friend struct ValueIter<MaskOnIter, LeafNode, bool>;
720 friend struct ValueIter<MaskOffIter, LeafNode, bool>;
721 friend struct ValueIter<MaskDenseIter, LeafNode, bool>;
722 friend struct ValueIter<MaskOnIter, const LeafNode, bool>;
723 friend struct ValueIter<MaskOffIter, const LeafNode, bool>;
724 friend struct ValueIter<MaskDenseIter, const LeafNode, bool>;
725
726 //@{
727 /// Allow iterators to call mask accessor methods (see below).
728 /// @todo Make mask accessors public?
729 friend class IteratorBase<MaskOnIter, LeafNode>;
730 friend class IteratorBase<MaskOffIter, LeafNode>;
731 friend class IteratorBase<MaskDenseIter, LeafNode>;
732 //@}
733
734}; // class LeafNode<bool>
735
736
737////////////////////////////////////////
738
739
740template<Index Log2Dim>
741inline
742 LeafNode<bool, Log2Dim>::LeafNode()
743 : mOrigin(0, 0, 0)
744{
745}
746
747
748template<Index Log2Dim>
749inline
750 LeafNode<bool, Log2Dim>::LeafNode(const Coord& xyz, bool value, bool active)
751 : mValueMask(active)
752 , mBuffer(value)
753 , mOrigin(xyz & (~(DIM - 1)))
754{
755}
756
757
758template<Index Log2Dim>
759inline
760 LeafNode<bool, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, bool value, bool active)
761 : mValueMask(active)
762 , mBuffer(value)
763 , mOrigin(xyz & (~(DIM - 1)))
764{
765 /// @todo For now, this is identical to the non-PartialCreate constructor.
766 /// Consider modifying the Buffer class to allow it to be constructed
767 /// without allocating a bitmask.
768}
769
770
771template<Index Log2Dim>
772inline
773 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode &other)
774 : mValueMask(other.valueMask())
775 , mBuffer(other.mBuffer)
776 , mOrigin(other.mOrigin)
777#if OPENVDB_ABI_VERSION_NUMBER >= 9
778 , mTransientData(other.mTransientData)
779#endif
780{
781}
782
783
784// Copy-construct from a leaf node with the same configuration but a different ValueType.
785template<Index Log2Dim>
786template<typename ValueT>
787inline
788 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other)
789 : mValueMask(other.valueMask())
790 , mOrigin(other.origin())
791#if OPENVDB_ABI_VERSION_NUMBER >= 9
792 , mTransientData(other.mTransientData)
793#endif
794{
795 struct Local {
796 /// @todo Consider using a value conversion functor passed as an argument instead.
797 static inline bool convertValue(const ValueT& val) { return bool(val); }
798 };
799
800 for (Index i = 0; i < SIZE; ++i) {
801 mBuffer.setValue(i, Local::convertValue(other.mBuffer[i]));
802 }
803}
804
805
806template<Index Log2Dim>
807template<typename ValueT>
808inline
809 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other,
810 bool background, TopologyCopy)
811 : mValueMask(other.valueMask())
812 , mBuffer(background)
813 , mOrigin(other.origin())
814#if OPENVDB_ABI_VERSION_NUMBER >= 9
815 , mTransientData(other.mTransientData)
816#endif
817{
818}
819
820
821template<Index Log2Dim>
822template<typename ValueT>
823inline
824 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other, TopologyCopy)
825 : mValueMask(other.valueMask())
826 , mBuffer(other.valueMask())// value = active state
827 , mOrigin(other.origin())
828#if OPENVDB_ABI_VERSION_NUMBER >= 9
829 , mTransientData(other.mTransientData)
830#endif
831{
832}
833
834
835template<Index Log2Dim>
836template<typename ValueT>
837inline
838 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other,
839 bool offValue, bool onValue, TopologyCopy)
840 : mValueMask(other.valueMask())
841 , mBuffer(other.valueMask())
842 , mOrigin(other.origin())
843#if OPENVDB_ABI_VERSION_NUMBER >= 9
844 , mTransientData(other.mTransientData)
845#endif
846{
847 if (offValue) { if (!onValue) mBuffer.mData.toggle(); else mBuffer.mData.setOn(); }
848}
849
850
851template<Index Log2Dim>
852inline
853 LeafNode<bool, Log2Dim>::~LeafNode()
854{
855}
856
857
858////////////////////////////////////////
859
860
861template<Index Log2Dim>
862inline Index64
863 LeafNode<bool, Log2Dim>::memUsage() const
864{
865 // Use sizeof(*this) to capture alignment-related padding
866 return sizeof(*this);
867}
868
869
870template<Index Log2Dim>
871inline Index64
872 LeafNode<bool, Log2Dim>::memUsageIfLoaded() const
873{
874 // Use sizeof(*this) to capture alignment-related padding
875 return sizeof(*this);
876}
877
878
879template<Index Log2Dim>
880inline void
881 LeafNode<bool, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
882{
883 CoordBBox this_bbox = this->getNodeBoundingBox();
884 if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
885 if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
886 if (visitVoxels) {//use voxel granularity?
887 this_bbox.reset();
888 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
889 this_bbox.translate(this->origin());
890 }
891 bbox.expand(this_bbox);
892 }
893}
894
895
896template<Index Log2Dim>
897template<typename OtherType, Index OtherLog2Dim>
898inline bool
899 LeafNode<bool, Log2Dim>::hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const
900{
901 assert(other);
902 return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
903}
904
905
906template<Index Log2Dim>
907inline std::string
908 LeafNode<bool, Log2Dim>::str() const
909{
910 std::ostringstream ostr;
911 ostr << "LeafNode @" << mOrigin << ": ";
912 for (Index32 n = 0; n < SIZE; ++n) ostr << (mValueMask.isOn(n) ? '#' : '.');
913 return ostr.str();
914}
915
916
917////////////////////////////////////////
918
919
920template<Index Log2Dim>
921inline Index
922 LeafNode<bool, Log2Dim>::coordToOffset(const Coord& xyz)
923{
924 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
925 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
926 + ((xyz[1] & (DIM-1u)) << Log2Dim)
927 + (xyz[2] & (DIM-1u));
928}
929
930
931template<Index Log2Dim>
932inline Coord
933 LeafNode<bool, Log2Dim>::offsetToLocalCoord(Index n)
934{
935 assert(n < (1 << 3*Log2Dim));
936 Coord xyz;
937 xyz.setX(n >> 2*Log2Dim);
938 n &= ((1 << 2*Log2Dim) - 1);
939 xyz.setY(n >> Log2Dim);
940 xyz.setZ(n & ((1 << Log2Dim) - 1));
941 return xyz;
942}
943
944
945template<Index Log2Dim>
946inline Coord
947 LeafNode<bool, Log2Dim>::offsetToGlobalCoord(Index n) const
948{
949 return (this->offsetToLocalCoord(n) + this->origin());
950}
951
952
953////////////////////////////////////////
954
955
956template<Index Log2Dim>
957inline void
958 LeafNode<bool, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
959{
960 mValueMask.load(is);
961}
962
963
964template<Index Log2Dim>
965inline void
966 LeafNode<bool, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
967{
968 mValueMask.save(os);
969}
970
971
972template<Index Log2Dim>
973inline void
974 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
975{
976 // Boolean LeafNodes don't currently implement lazy loading.
977 // Instead, load the full buffer, then clip it.
978
979 this->readBuffers(is, fromHalf);
980
981 // Get this tree's background value.
982 bool background = false;
983 if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
984 background = *static_cast<const bool*>(bgPtr);
985 }
986 this->clip(clipBBox, background);
987}
988
989
990template<Index Log2Dim>
991inline void
992 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, bool /*fromHalf*/)
993{
994 // Read in the value mask.
995 mValueMask.load(is);
996 // Read in the origin.
997 is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
998
999 if (io::getFormatVersion(is) >= OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION) {
1000 // Read in the mask for the voxel values.
1001 mBuffer.mData.load(is);
1002 } else {
1003 // Older files stored one or more bool arrays.
1004
1005 // Read in the number of buffers, which should now always be one.
1006 int8_t numBuffers = 0;
1007 is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1008
1009 // Read in the buffer.
1010 // (Note: prior to the bool leaf optimization, buffers were always compressed.)
1011 std::unique_ptr<bool[]> buf{new bool[SIZE]};
1012 io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1013
1014 // Transfer values to mBuffer.
1015 mBuffer.mData.setOff();
1016 for (Index i = 0; i < SIZE; ++i) {
1017 if (buf[i]) mBuffer.mData.setOn(i);
1018 }
1019
1020 if (numBuffers > 1) {
1021 // Read in and discard auxiliary buffers that were created with
1022 // earlier versions of the library.
1023 for (int i = 1; i < numBuffers; ++i) {
1024 io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1025 }
1026 }
1027 }
1028}
1029
1030
1031template<Index Log2Dim>
1032inline void
1033 LeafNode<bool, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
1034{
1035 // Write out the value mask.
1036 mValueMask.save(os);
1037 // Write out the origin.
1038 os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1039 // Write out the voxel values.
1040 mBuffer.mData.save(os);
1041}
1042
1043
1044////////////////////////////////////////
1045
1046
1047template<Index Log2Dim>
1048inline bool
1049 LeafNode<bool, Log2Dim>::operator==(const LeafNode& other) const
1050{
1051 return mOrigin == other.mOrigin &&
1052 mValueMask == other.valueMask() &&
1053 mBuffer == other.mBuffer;
1054}
1055
1056
1057template<Index Log2Dim>
1058inline bool
1059 LeafNode<bool, Log2Dim>::operator!=(const LeafNode& other) const
1060{
1061 return !(this->operator==(other));
1062}
1063
1064
1065////////////////////////////////////////
1066
1067
1068template<Index Log2Dim>
1069inline bool
1070 LeafNode<bool, Log2Dim>::isConstant(bool& constValue, bool& state, bool tolerance) const
1071{
1072 if (!mValueMask.isConstant(state)) return false;
1073
1074 // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1075 if (!tolerance && !(mBuffer.mData.isOn() || mBuffer.mData.isOff())) return false;
1076
1077 constValue = mBuffer.mData.isOn();
1078 return true;
1079}
1080
1081////////////////////////////////////////
1082
1083template<Index Log2Dim>
1084inline bool
1085 LeafNode<bool, Log2Dim>::medianAll() const
1086{
1087 const Index countTrue = mBuffer.mData.countOn();
1088 return countTrue > (NUM_VALUES >> 1);
1089}
1090
1091template<Index Log2Dim>
1092inline Index
1093 LeafNode<bool, Log2Dim>::medianOn(bool& state) const
1094{
1095 const NodeMaskType tmp = mBuffer.mData & mValueMask;//both true and active
1096 const Index countTrueOn = tmp.countOn(), countOn = mValueMask.countOn();
1097 state = countTrueOn > (NUM_VALUES >> 1);
1098 return countOn;
1099}
1100
1101template<Index Log2Dim>
1102inline Index
1103 LeafNode<bool, Log2Dim>::medianOff(bool& state) const
1104{
1105 const NodeMaskType tmp = mBuffer.mData & (!mValueMask);//both true and inactive
1106 const Index countTrueOff = tmp.countOn(), countOff = mValueMask.countOff();
1107 state = countTrueOff > (NUM_VALUES >> 1);
1108 return countOff;
1109}
1110
1111////////////////////////////////////////
1112
1113
1114template<Index Log2Dim>
1115inline void
1116 LeafNode<bool, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, bool val, bool active)
1117{
1118 this->addTile(this->coordToOffset(xyz), val, active);
1119}
1120
1121template<Index Log2Dim>
1122inline void
1123 LeafNode<bool, Log2Dim>::addTile(Index offset, bool val, bool active)
1124{
1125 assert(offset < SIZE);
1126 this->setValueOnly(offset, val);
1127 this->setActiveState(offset, active);
1128}
1129
1130template<Index Log2Dim>
1131template<typename AccessorT>
1132inline void
1133 LeafNode<bool, Log2Dim>::addTileAndCache(Index level, const Coord& xyz,
1134 bool val, bool active, AccessorT&)
1135{
1136 this->addTile(level, xyz, val, active);
1137}
1138
1139
1140////////////////////////////////////////
1141
1142
1143template<Index Log2Dim>
1144inline const bool&
1145 LeafNode<bool, Log2Dim>::getValue(const Coord& xyz) const
1146{
1147 // This *CANNOT* use operator ? because Visual C++
1148 if (mBuffer.mData.isOn(this->coordToOffset(xyz))) return Buffer::sOn; else return Buffer::sOff;
1149}
1150
1151
1152template<Index Log2Dim>
1153inline const bool&
1154 LeafNode<bool, Log2Dim>::getValue(Index offset) const
1155{
1156 assert(offset < SIZE);
1157 // This *CANNOT* use operator ? for Windows
1158 if (mBuffer.mData.isOn(offset)) return Buffer::sOn; else return Buffer::sOff;
1159}
1160
1161
1162template<Index Log2Dim>
1163inline bool
1164 LeafNode<bool, Log2Dim>::probeValue(const Coord& xyz, bool& val) const
1165{
1166 const Index offset = this->coordToOffset(xyz);
1167 val = mBuffer.mData.isOn(offset);
1168 return mValueMask.isOn(offset);
1169}
1170
1171
1172template<Index Log2Dim>
1173inline void
1174 LeafNode<bool, Log2Dim>::setValueOn(const Coord& xyz, bool val)
1175{
1176 this->setValueOn(this->coordToOffset(xyz), val);
1177}
1178
1179
1180template<Index Log2Dim>
1181inline void
1182 LeafNode<bool, Log2Dim>::setValueOn(Index offset, bool val)
1183{
1184 assert(offset < SIZE);
1185 mValueMask.setOn(offset);
1186 mBuffer.mData.set(offset, val);
1187}
1188
1189
1190template<Index Log2Dim>
1191inline void
1192 LeafNode<bool, Log2Dim>::setValueOnly(const Coord& xyz, bool val)
1193{
1194 this->setValueOnly(this->coordToOffset(xyz), val);
1195}
1196
1197
1198template<Index Log2Dim>
1199inline void
1200 LeafNode<bool, Log2Dim>::setActiveState(const Coord& xyz, bool on)
1201{
1202 mValueMask.set(this->coordToOffset(xyz), on);
1203}
1204
1205
1206template<Index Log2Dim>
1207inline void
1208 LeafNode<bool, Log2Dim>::setValueOff(const Coord& xyz, bool val)
1209{
1210 this->setValueOff(this->coordToOffset(xyz), val);
1211}
1212
1213
1214template<Index Log2Dim>
1215inline void
1216 LeafNode<bool, Log2Dim>::setValueOff(Index offset, bool val)
1217{
1218 assert(offset < SIZE);
1219 mValueMask.setOff(offset);
1220 mBuffer.mData.set(offset, val);
1221}
1222
1223
1224template<Index Log2Dim>
1225template<typename ModifyOp>
1226inline void
1227 LeafNode<bool, Log2Dim>::modifyValue(Index offset, const ModifyOp& op)
1228{
1229 bool val = mBuffer.mData.isOn(offset);
1230 op(val);
1231 mBuffer.mData.set(offset, val);
1232 mValueMask.setOn(offset);
1233}
1234
1235
1236template<Index Log2Dim>
1237template<typename ModifyOp>
1238inline void
1239 LeafNode<bool, Log2Dim>::modifyValue(const Coord& xyz, const ModifyOp& op)
1240{
1241 this->modifyValue(this->coordToOffset(xyz), op);
1242}
1243
1244
1245template<Index Log2Dim>
1246template<typename ModifyOp>
1247inline void
1248 LeafNode<bool, Log2Dim>::modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
1249{
1250 const Index offset = this->coordToOffset(xyz);
1251 bool val = mBuffer.mData.isOn(offset), state = mValueMask.isOn(offset);
1252 op(val, state);
1253 mBuffer.mData.set(offset, val);
1254 mValueMask.set(offset, state);
1255}
1256
1257
1258////////////////////////////////////////
1259
1260
1261template<Index Log2Dim>
1262inline void
1263 LeafNode<bool, Log2Dim>::resetBackground(bool oldBackground, bool newBackground)
1264{
1265 if (newBackground != oldBackground) {
1266 // Flip mBuffer's background bits and zero its foreground bits.
1267 NodeMaskType bgMask = !(mBuffer.mData | mValueMask);
1268 // Overwrite mBuffer's background bits, leaving its foreground bits intact.
1269 mBuffer.mData = (mBuffer.mData & mValueMask) | bgMask;
1270 }
1271}
1272
1273
1274////////////////////////////////////////
1275
1276
1277template<Index Log2Dim>
1278template<MergePolicy Policy>
1279inline void
1280 LeafNode<bool, Log2Dim>::merge(const LeafNode& other, bool /*bg*/, bool /*otherBG*/)
1281{
1282 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1283 if (Policy == MERGE_NODES) return;
1284 for (typename NodeMaskType::OnIterator iter = other.valueMask().beginOn(); iter; ++iter) {
1285 const Index n = iter.pos();
1286 if (mValueMask.isOff(n)) {
1287 mBuffer.mData.set(n, other.mBuffer.mData.isOn(n));
1288 mValueMask.setOn(n);
1289 }
1290 }
1291 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1292}
1293
1294template<Index Log2Dim>
1295template<MergePolicy Policy>
1296inline void
1297 LeafNode<bool, Log2Dim>::merge(bool tileValue, bool tileActive)
1298{
1299 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1300 if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1301 if (!tileActive) return;
1302 // Replace all inactive values with the active tile value.
1303 if (tileValue) mBuffer.mData |= !mValueMask; // -0=>1, +0=>0, -1=>1, +1=>1 (-,+ = off,on)
1304 else mBuffer.mData &= mValueMask; // -0=>0, +0=>0, -1=>0, +1=>1
1305 mValueMask.setOn();
1306 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1307}
1308
1309
1310////////////////////////////////////////
1311
1312
1313template<Index Log2Dim>
1314template<typename OtherType>
1315inline void
1316 LeafNode<bool, Log2Dim>::topologyUnion(const LeafNode<OtherType, Log2Dim>& other, bool)
1317{
1318 mValueMask |= other.valueMask();
1319}
1320
1321
1322template<Index Log2Dim>
1323template<typename OtherType>
1324inline void
1325 LeafNode<bool, Log2Dim>::topologyIntersection(const LeafNode<OtherType, Log2Dim>& other,
1326 const bool&)
1327{
1328 mValueMask &= other.valueMask();
1329}
1330
1331
1332template<Index Log2Dim>
1333template<typename OtherType>
1334inline void
1335 LeafNode<bool, Log2Dim>::topologyDifference(const LeafNode<OtherType, Log2Dim>& other,
1336 const bool&)
1337{
1338 mValueMask &= !other.valueMask();
1339}
1340
1341
1342////////////////////////////////////////
1343
1344
1345template<Index Log2Dim>
1346inline void
1347 LeafNode<bool, Log2Dim>::clip(const CoordBBox& clipBBox, bool background)
1348{
1349 CoordBBox nodeBBox = this->getNodeBoundingBox();
1350 if (!clipBBox.hasOverlap(nodeBBox)) {
1351 // This node lies completely outside the clipping region. Fill it with background tiles.
1352 this->fill(nodeBBox, background, /*active=*/false);
1353 } else if (clipBBox.isInside(nodeBBox)) {
1354 // This node lies completely inside the clipping region. Leave it intact.
1355 return;
1356 }
1357
1358 // This node isn't completely contained inside the clipping region.
1359 // Set any voxels that lie outside the region to the background value.
1360
1361 // Construct a boolean mask that is on inside the clipping region and off outside it.
1362 NodeMaskType mask;
1363 nodeBBox.intersect(clipBBox);
1364 Coord xyz;
1365 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1366 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1367 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1368 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1369 mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1370 }
1371 }
1372 }
1373
1374 // Set voxels that lie in the inactive region of the mask (i.e., outside
1375 // the clipping region) to the background value.
1376 for (MaskOffIter maskIter = mask.beginOff(); maskIter; ++maskIter) {
1377 this->setValueOff(maskIter.pos(), background);
1378 }
1379}
1380
1381
1382////////////////////////////////////////
1383
1384
1385template<Index Log2Dim>
1386inline void
1387 LeafNode<bool, Log2Dim>::fill(const CoordBBox& bbox, bool value, bool active)
1388{
1389 auto clippedBBox = this->getNodeBoundingBox();
1390 clippedBBox.intersect(bbox);
1391 if (!clippedBBox) return;
1392
1393 for (Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1394 const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1395 for (Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1396 const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1397 for (Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1398 const Index offset = offsetXY + (z & (DIM-1u));
1399 mValueMask.set(offset, active);
1400 mBuffer.mData.set(offset, value);
1401 }
1402 }
1403 }
1404}
1405
1406template<Index Log2Dim>
1407inline void
1408 LeafNode<bool, Log2Dim>::fill(const bool& value)
1409{
1410 mBuffer.fill(value);
1411}
1412
1413template<Index Log2Dim>
1414inline void
1415 LeafNode<bool, Log2Dim>::fill(const bool& value, bool active)
1416{
1417 mBuffer.fill(value);
1418 mValueMask.set(active);
1419}
1420
1421
1422////////////////////////////////////////
1423
1424
1425template<Index Log2Dim>
1426template<typename DenseT>
1427inline void
1428 LeafNode<bool, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1429{
1430 using DenseValueType = typename DenseT::ValueType;
1431
1432 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1433 const Coord& min = dense.bbox().min();
1434 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1435 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1436 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1437 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1438 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1439 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1440 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1441 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1442 for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1443 *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1444 }
1445 }
1446 }
1447}
1448
1449
1450template<Index Log2Dim>
1451template<typename DenseT>
1452inline void
1453 LeafNode<bool, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1454 bool background, bool tolerance)
1455{
1456 using DenseValueType = typename DenseT::ValueType;
1457 struct Local {
1458 inline static bool toBool(const DenseValueType& v) { return !math::isZero(v); }
1459 };
1460
1461 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1462 const Coord& min = dense.bbox().min();
1463 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1464 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1465 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1466 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1467 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1468 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1469 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1470 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1471 for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1472 // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1473 if (tolerance || (background == Local::toBool(*s2))) {
1474 mValueMask.setOff(n2);
1475 mBuffer.mData.set(n2, background);
1476 } else {
1477 mValueMask.setOn(n2);
1478 mBuffer.mData.set(n2, Local::toBool(*s2));
1479 }
1480 }
1481 }
1482 }
1483}
1484
1485
1486////////////////////////////////////////
1487
1488
1489template<Index Log2Dim>
1490template<typename CombineOp>
1491inline void
1492 LeafNode<bool, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1493{
1494 CombineArgs<bool> args;
1495 for (Index i = 0; i < SIZE; ++i) {
1496 bool result = false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1497 op(args.setARef(aVal)
1498 .setAIsActive(mValueMask.isOn(i))
1499 .setBRef(bVal)
1500 .setBIsActive(other.valueMask().isOn(i))
1501 .setResultRef(result));
1502 mValueMask.set(i, args.resultIsActive());
1503 mBuffer.mData.set(i, result);
1504 }
1505}
1506
1507
1508template<Index Log2Dim>
1509template<typename CombineOp>
1510inline void
1511 LeafNode<bool, Log2Dim>::combine(bool value, bool valueIsActive, CombineOp& op)
1512{
1513 CombineArgs<bool> args;
1514 args.setBRef(value).setBIsActive(valueIsActive);
1515 for (Index i = 0; i < SIZE; ++i) {
1516 bool result = false, aVal = mBuffer.mData.isOn(i);
1517 op(args.setARef(aVal)
1518 .setAIsActive(mValueMask.isOn(i))
1519 .setResultRef(result));
1520 mValueMask.set(i, args.resultIsActive());
1521 mBuffer.mData.set(i, result);
1522 }
1523}
1524
1525
1526////////////////////////////////////////
1527
1528
1529template<Index Log2Dim>
1530template<typename CombineOp, typename OtherType>
1531inline void
1532 LeafNode<bool, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1533 bool valueIsActive, CombineOp& op)
1534{
1535 CombineArgs<bool, OtherType> args;
1536 args.setBRef(value).setBIsActive(valueIsActive);
1537 for (Index i = 0; i < SIZE; ++i) {
1538 bool result = false, aVal = other.mBuffer.mData.isOn(i);
1539 op(args.setARef(aVal)
1540 .setAIsActive(other.valueMask().isOn(i))
1541 .setResultRef(result));
1542 mValueMask.set(i, args.resultIsActive());
1543 mBuffer.mData.set(i, result);
1544 }
1545}
1546
1547
1548template<Index Log2Dim>
1549template<typename CombineOp, typename OtherNodeT>
1550inline void
1551 LeafNode<bool, Log2Dim>::combine2(bool value, const OtherNodeT& other,
1552 bool valueIsActive, CombineOp& op)
1553{
1554 CombineArgs<bool, typename OtherNodeT::ValueType> args;
1555 args.setARef(value).setAIsActive(valueIsActive);
1556 for (Index i = 0; i < SIZE; ++i) {
1557 bool result = false, bVal = other.mBuffer.mData.isOn(i);
1558 op(args.setBRef(bVal)
1559 .setBIsActive(other.valueMask().isOn(i))
1560 .setResultRef(result));
1561 mValueMask.set(i, args.resultIsActive());
1562 mBuffer.mData.set(i, result);
1563 }
1564}
1565
1566
1567template<Index Log2Dim>
1568template<typename CombineOp, typename OtherNodeT>
1569inline void
1570 LeafNode<bool, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1571{
1572 CombineArgs<bool, typename OtherNodeT::ValueType> args;
1573 for (Index i = 0; i < SIZE; ++i) {
1574 // Default behavior: output voxel is active if either input voxel is active.
1575 mValueMask.set(i, b0.valueMask().isOn(i) || b1.valueMask().isOn(i));
1576
1577 bool result = false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1578 op(args.setARef(b0Val)
1579 .setAIsActive(b0.valueMask().isOn(i))
1580 .setBRef(b1Val)
1581 .setBIsActive(b1.valueMask().isOn(i))
1582 .setResultRef(result));
1583 mValueMask.set(i, args.resultIsActive());
1584 mBuffer.mData.set(i, result);
1585 }
1586}
1587
1588
1589} // namespace tree
1590} // namespace OPENVDB_VERSION_NAME
1591} // namespace openvdb
1592
1593#endif // OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
Compression.h
value
ValueT value
Definition GridBuilder.h:1290
child
ChildT * child
Definition GridBuilder.h:1289
Iterator.h
LeafNode.h
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
NodeMasks.h
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition Platform.h:118
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition Platform.h:117
openvdb::v10_0::CombineArgs
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:530
openvdb::v10_0::CombineArgs::setARef
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:582
openvdb::v10_0::CombineArgs::setBIsActive
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:598
openvdb::v10_0::CombineArgs::setResultRef
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition Types.h:586
openvdb::v10_0::CombineArgs::setBRef
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:584
openvdb::v10_0::CombineArgs::resultIsActive
bool resultIsActive() const
Definition Types.h:593
openvdb::v10_0::CombineArgs::setAIsActive
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:596
openvdb::v10_0::PartialCreate
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:650
openvdb::v10_0::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:644
openvdb::v10_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:249
openvdb::v10_0::math::CoordBBox::translate
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition Coord.h:458
openvdb::v10_0::math::CoordBBox::expand
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition Coord.h:418
openvdb::v10_0::math::CoordBBox::min
const Coord & min() const
Definition Coord.h:321
openvdb::v10_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:412
openvdb::v10_0::math::CoordBBox::max
const Coord & max() const
Definition Coord.h:322
openvdb::v10_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:400
openvdb::v10_0::math::CoordBBox::intersect
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:444
openvdb::v10_0::math::CoordBBox::reset
void reset()
Definition Coord.h:327
openvdb::v10_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:25
openvdb::v10_0::math::Coord::ValueType
Int32 ValueType
Definition Coord.h:32
openvdb::v10_0::math::Coord::y
Int32 y() const
Definition Coord.h:131
openvdb::v10_0::math::Coord::x
Int32 x() const
Definition Coord.h:130
openvdb::v10_0::math::Coord::setZ
Coord & setZ(Int32 z)
Definition Coord.h:81
openvdb::v10_0::math::Coord::setY
Coord & setY(Int32 y)
Definition Coord.h:80
openvdb::v10_0::math::Coord::z
Int32 z() const
Definition Coord.h:132
openvdb::v10_0::math::Coord::setX
Coord & setX(Int32 x)
Definition Coord.h:79
openvdb::v10_0::tree::IteratorBase
Base class for iterators over internal and leaf nodes.
Definition Iterator.h:30
openvdb::v10_0::tree::LeafBuffer< ValueType, Log2Dim >
openvdb::v10_0::tree::LeafBuffer::setValue
void setValue(Index i, const ValueType &)
Set the i'th value of this buffer to the specified value.
Definition LeafBuffer.h:238
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >
LeafNode specialization for values of type bool that stores both the active states and the values of ...
Definition LeafNodeBool.h:29
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::stealNodes
void stealNodes(ArrayT &, const ValueType &, bool)
Definition LeafNodeBool.h:513
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::operator=
LeafNode & operator=(const LeafNode &)=default
Deep assignment operator.
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isValueOn
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition LeafNodeBool.h:279
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::onTileCount
static Index64 onTileCount()
Definition LeafNodeBool.h:122
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getOrigin
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition LeafNodeBool.h:157
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cbeginChildOn
ChildOnCIter cbeginChildOn() const
Definition LeafNodeBool.h:661
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::BuildType
bool BuildType
Definition LeafNodeBool.h:32
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getNodeBoundingBox
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition LeafNodeBool.h:149
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getValueMask
NodeMaskType & getValueMask()
Definition LeafNodeBool.h:690
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueOn
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNodeBool.h:249
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isChildMaskOn
bool isChildMaskOn(Index) const
Definition LeafNodeBool.h:692
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginChildOn
ChildOnCIter beginChildOn() const
Definition LeafNodeBool.h:662
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginChildOn
ChildOnIter beginChildOn()
Definition LeafNodeBool.h:663
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isValueOn
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition LeafNodeBool.h:277
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endValueOn
ValueOnIter endValueOn()
Definition LeafNodeBool.h:651
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isChildMaskOff
bool isChildMaskOff() const
Definition LeafNodeBool.h:694
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Definition LeafNodeBool.h:642
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::transientData
Index32 transientData() const
Return the transient data value.
Definition LeafNodeBool.h:170
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::Ptr
SharedPtr< LeafNodeType > Ptr
Definition LeafNodeBool.h:36
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getChildDim
static Index getChildDim()
Definition LeafNodeBool.h:109
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueMask
void setValueMask(const NodeMaskType &mask)
Definition LeafNodeBool.h:691
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endChildOn
ChildOnIter endChildOn()
Definition LeafNodeBool.h:673
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endValueAll
ValueAllIter endValueAll()
Definition LeafNodeBool.h:657
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::touchLeaf
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition LeafNodeBool.h:523
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeLeaf
LeafNode * probeLeaf(const Coord &)
Definition LeafNodeBool.h:526
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isValueMaskOff
bool isValueMaskOff() const
Definition LeafNodeBool.h:687
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< ValueType, Log2Dim > &other, bool offValue, bool onValue, TopologyCopy)
Topology copy constructor.
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::prune
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition LeafNodeBool.h:502
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isValueMaskOn
bool isValueMaskOn() const
Definition LeafNodeBool.h:685
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildAllCIter
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition LeafNodeBool.h:637
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getNodes
void getNodes(ArrayT &) const
Definition LeafNodeBool.h:512
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::mValueMask
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition LeafNodeBool.h:704
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValuesOff
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition LeafNodeBool.h:274
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endValueAll
ValueAllCIter endValueAll() const
Definition LeafNodeBool.h:656
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildOnCIter
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition LeafNodeBool.h:633
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::onLeafVoxelCount
Index64 onLeafVoxelCount() const
Definition LeafNodeBool.h:120
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueOnly
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don't change its active state.
Definition LeafNodeBool.h:234
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endChildOff
ChildOffCIter endChildOff() const
Definition LeafNodeBool.h:675
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Definition LeafNodeBool.h:645
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeNode
NodeT * probeNode(const Coord &)
Definition LeafNodeBool.h:509
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginValueOn
ValueOnCIter beginValueOn() const
Definition LeafNodeBool.h:640
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::denseFill
void denseFill(const CoordBBox &bbox, bool val, bool on=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition LeafNodeBool.h:290
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::evalNodeOrigin
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition LeafNodeBool.h:701
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::buffer
const Buffer & buffer() const
Definition LeafNodeBool.h:193
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeLeafAndCache
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition LeafNodeBool.h:528
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueMaskOn
void setValueMaskOn(Index n)
Definition LeafNodeBool.h:697
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::offLeafVoxelCount
Index64 offLeafVoxelCount() const
Definition LeafNodeBool.h:121
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeLeaf
const LeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition LeafNodeBool.h:540
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setOrigin
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition LeafNodeBool.h:152
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::origin
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition LeafNodeBool.h:155
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getValueLevel
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition LeafNodeBool.h:224
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::MaskOnIter
typename NodeMaskType::OnIterator MaskOnIter
Definition LeafNodeBool.h:560
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isInactive
bool isInactive() const
Return true if all of this node's values are inactive.
Definition LeafNodeBool.h:437
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::mBuffer
Buffer mBuffer
Bitmask representing the values of voxels.
Definition LeafNodeBool.h:706
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueOnCIter
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition LeafNodeBool.h:627
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isValueMaskOff
bool isValueMaskOff(Index n) const
Definition LeafNodeBool.h:686
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cendValueOn
ValueOnCIter cendValueOn() const
Definition LeafNodeBool.h:649
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isAllocated
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition LeafNodeBool.h:132
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getValueLevelAndCache
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition LeafNodeBool.h:397
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::numValues
static Index numValues()
Definition LeafNodeBool.h:106
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginValueOff
ValueOffCIter beginValueOff() const
Definition LeafNodeBool.h:643
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueOffIter
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition LeafNodeBool.h:628
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cbeginChildAll
ChildAllCIter cbeginChildAll() const
Definition LeafNodeBool.h:667
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endChildOff
ChildOffIter endChildOff()
Definition LeafNodeBool.h:676
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginChildAll
ChildAllIter beginChildAll()
Definition LeafNodeBool.h:669
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getLevel
static Index getLevel()
Definition LeafNodeBool.h:107
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isValueOnAndCache
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition LeafNodeBool.h:338
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::addLeaf
void addLeaf(LeafNode *)
Definition LeafNodeBool.h:503
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginValueOn
ValueOnIter beginValueOn()
Definition LeafNodeBool.h:641
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::modifyValueAndCache
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNodeBool.h:363
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueOffAndCache
void setValueOffAndCache(const Coord &xyz, bool value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition LeafNodeBool.h:354
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildOffCIter
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition LeafNodeBool.h:635
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeNodeAndCache
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition LeafNodeBool.h:530
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueAllIter
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition LeafNodeBool.h:630
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cbeginChildOff
ChildOffCIter cbeginChildOff() const
Definition LeafNodeBool.h:664
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginChildOff
ChildOffIter beginChildOff()
Definition LeafNodeBool.h:666
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isChildMaskOff
bool isChildMaskOff(Index) const
Definition LeafNodeBool.h:693
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::onVoxelCount
Index64 onVoxelCount() const
Return the number of active voxels.
Definition LeafNodeBool.h:117
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::MaskOffIter
typename NodeMaskType::OffIterator MaskOffIter
Definition LeafNodeBool.h:561
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginChildOff
ChildOffCIter beginChildOff() const
Definition LeafNodeBool.h:665
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< ValueType, Log2Dim > &other, bool background, TopologyCopy)
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::offTileCount
static Index64 offTileCount()
Definition LeafNodeBool.h:123
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueOff
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition LeafNodeBool.h:237
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueType
bool ValueType
Definition LeafNodeBool.h:33
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endValueOff
ValueOffIter endValueOff()
Definition LeafNodeBool.h:654
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueOff
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNodeBool.h:239
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeConstLeafAndCache
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNodeBool.h:545
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endChildAll
ChildAllCIter endChildAll() const
Definition LeafNodeBool.h:678
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeConstNodeAndCache
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition LeafNodeBool.h:547
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition LeafNodeBool.h:639
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::log2dim
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition LeafNodeBool.h:102
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getNodeLog2Dims
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition LeafNodeBool.h:108
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endChildOn
ChildOnCIter endChildOn() const
Definition LeafNodeBool.h:672
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeConstLeaf
const LeafNode * probeConstLeaf(const Coord &) const
Definition LeafNodeBool.h:543
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::nonLeafCount
static Index32 nonLeafCount()
Definition LeafNodeBool.h:114
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeValueAndCache
bool probeValueAndCache(const Coord &xyz, bool &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val.
Definition LeafNodeBool.h:389
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cendChildOn
ChildOnCIter cendChildOn() const
Definition LeafNodeBool.h:671
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::hasActiveTiles
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition LeafNodeBool.h:282
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cendChildAll
ChildAllCIter cendChildAll() const
Definition LeafNodeBool.h:677
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueOnIter
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition LeafNodeBool.h:626
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueOnlyAndCache
void setValueOnlyAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition LeafNodeBool.h:349
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildAllIter
DenseIter< LeafNode, bool > ChildAllIter
Definition LeafNodeBool.h:636
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endChildAll
ChildAllIter endChildAll()
Definition LeafNodeBool.h:679
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueMask
void setValueMask(Index n, bool on)
Definition LeafNodeBool.h:696
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::valueMask
const NodeMaskType & valueMask() const
Definition LeafNodeBool.h:689
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::offVoxelCount
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition LeafNodeBool.h:119
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::swap
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition LeafNodeBool.h:192
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cendValueAll
ValueAllCIter cendValueAll() const
Definition LeafNodeBool.h:655
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildOnIter
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition LeafNodeBool.h:632
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< ValueType, Log2Dim > &other, TopologyCopy)
Topology copy constructor.
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::negate
void negate()
Definition LeafNodeBool.h:441
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginChildAll
ChildAllCIter beginChildAll() const
Definition LeafNodeBool.h:668
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeLeafAndCache
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNodeBool.h:542
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setActiveStateAndCache
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition LeafNodeBool.h:380
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getOrigin
void getOrigin(Coord &origin) const
Definition LeafNodeBool.h:156
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValuesOn
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition LeafNodeBool.h:272
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setTransientData
void setTransientData(Index32 transientData)
Set the transient data value.
Definition LeafNodeBool.h:172
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::nodeCount
void nodeCount(std::vector< Index32 > &) const
no-op
Definition LeafNodeBool.h:113
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::size
static Index size()
Definition LeafNodeBool.h:105
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cendChildOff
ChildOffCIter cendChildOff() const
Definition LeafNodeBool.h:674
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::MaskDenseIter
typename NodeMaskType::DenseIterator MaskDenseIter
Definition LeafNodeBool.h:562
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isEmpty
bool isEmpty() const
Return true if this node has no active voxels.
Definition LeafNodeBool.h:126
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueAndCache
void setValueAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition LeafNodeBool.h:343
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginValueOff
ValueOffIter beginValueOff()
Definition LeafNodeBool.h:644
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::probeConstNode
const NodeT * probeConstNode(const Coord &) const
Definition LeafNodeBool.h:511
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueOn
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition LeafNodeBool.h:247
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::buffer
Buffer & buffer()
Definition LeafNodeBool.h:194
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setActiveState
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition LeafNodeBool.h:229
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::leafCount
static Index32 leafCount()
Definition LeafNodeBool.h:111
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::allocate
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition LeafNodeBool.h:136
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getValueMask
const NodeMaskType & getValueMask() const
Definition LeafNodeBool.h:688
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getFirstValue
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition LeafNodeBool.h:402
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::addLeafAndCache
void addLeafAndCache(LeafNode *, AccessorT &)
Definition LeafNodeBool.h:505
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getLastValue
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition LeafNodeBool.h:406
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::cendValueOff
ValueOffCIter cendValueOff() const
Definition LeafNodeBool.h:652
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueAllCIter
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition LeafNodeBool.h:631
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::getValueAndCache
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition LeafNodeBool.h:333
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValueMaskOff
void setValueMaskOff(Index n)
Definition LeafNodeBool.h:698
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isDense
bool isDense() const
Return true if this node only contains active voxels.
Definition LeafNodeBool.h:128
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endValueOff
ValueOffCIter endValueOff() const
Definition LeafNodeBool.h:653
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::stealNode
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition LeafNodeBool.h:507
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::setValue
void setValue(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNodeBool.h:254
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::endValueOn
ValueOnCIter endValueOn() const
Definition LeafNodeBool.h:650
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::voxelizeActiveTiles
void voxelizeActiveTiles(bool=true)
No-op.
Definition LeafNodeBool.h:449
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::modifyValueAndActiveStateAndCache
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition LeafNodeBool.h:371
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::touchLeafAndCache
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition LeafNodeBool.h:525
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginValueAll
ValueAllCIter beginValueAll() const
Definition LeafNodeBool.h:646
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::mOrigin
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition LeafNodeBool.h:708
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::dim
static Index dim()
Return the number of voxels in each dimension.
Definition LeafNodeBool.h:104
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildOffIter
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition LeafNodeBool.h:634
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueOffCIter
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition LeafNodeBool.h:629
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::isValueMaskOn
bool isValueMaskOn(Index n) const
Definition LeafNodeBool.h:684
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::beginValueAll
ValueAllIter beginValueAll()
Definition LeafNodeBool.h:647
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::LeafNode
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other)
Value conversion copy constructor.
openvdb::v10_0::tree::LeafNode
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition LeafNode.h:38
openvdb::v10_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:1032
openvdb::v10_0::tree::LeafNode::writeTopology
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition LeafNode.h:1288
openvdb::v10_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:1216
openvdb::v10_0::tree::LeafNode::operator!=
bool operator!=(const LeafNode &other) const
Definition LeafNode.h:203
openvdb::v10_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:1243
openvdb::v10_0::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:1057
openvdb::v10_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:1115
openvdb::v10_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:1708
openvdb::v10_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:1565
openvdb::v10_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:1523
openvdb::v10_0::tree::LeafNode::~LeafNode
~LeafNode()
Destructor.
Definition LeafNode.h:1002
openvdb::v10_0::tree::LeafNode::readTopology
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition LeafNode.h:1280
openvdb::v10_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:1541
openvdb::v10_0::tree::LeafNode::addTile
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition LeafNode.h:1592
openvdb::v10_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:1621
openvdb::v10_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:458
openvdb::v10_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:1699
openvdb::v10_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:1133
openvdb::v10_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:1107
openvdb::v10_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:1691
openvdb::v10_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:1022
openvdb::v10_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:409
openvdb::v10_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:1479
openvdb::v10_0::tree::LeafNode::writeBuffers
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition LeafNode.h:1414
openvdb::v10_0::tree::LeafNode::combine
void combine(const LeafNode &other, CombineOp &op)
Definition LeafNode.h:1732
openvdb::v10_0::tree::LeafNode::memUsageIfLoaded
Index64 memUsageIfLoaded() const
Definition LeafNode.h:1451
openvdb::v10_0::tree::LeafNode::combine2
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1772
openvdb::v10_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:1173
openvdb::v10_0::tree::LeafNode::valueMask
const NodeMaskType & valueMask() const
Definition LeafNode.h:858
openvdb::v10_0::tree::LeafNode::readBuffers
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition LeafNode.h:1316
openvdb::v10_0::tree::LeafNode::isConstant
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition LeafNode.h:1487
openvdb::v10_0::tree::LeafNode::LeafNode
friend class LeafNode
Definition LeafNode.h:835
openvdb::v10_0::tree::LeafNode::offsetToGlobalCoord
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition LeafNode.h:1046
openvdb::v10_0::tree::LeafNode::operator==
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition LeafNode.h:1431
openvdb::v10_0::tree::LeafNode::SIZE
static const Index SIZE
Definition LeafNode.h:53
openvdb::v10_0::tree::LeafNode::evalActiveBoundingBox
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition LeafNode.h:1461
openvdb::v10_0::tree::LeafNode::merge
void merge(const LeafNode &)
Definition LeafNode.h:1642
openvdb::v10_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:419
openvdb::v10_0::tree::LeafNode::getValueMask
const NodeMaskType & getValueMask() const
Definition LeafNode.h:856
openvdb::v10_0::tree::LeafNode::addTileAndCache
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition LeafNode.h:1609
openvdb::v10_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:437
openvdb::v10_0::tree::LeafNode::memUsage
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition LeafNode.h:1441
openvdb::v10_0::tree::LeafNode::str
std::string str() const
Return a string representation of this node.
Definition LeafNode.h:1009
openvdb::v10_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:1073
openvdb::v10_0::util::DenseMaskIterator
Definition NodeMasks.h:271
openvdb::v10_0::util::NodeMask
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition NodeMasks.h:308
openvdb::v10_0::util::NodeMask::countOn
Index32 countOn() const
Return the total number of on bits.
Definition NodeMasks.h:443
openvdb::v10_0::util::NodeMask::beginOn
OnIterator beginOn() const
Definition NodeMasks.h:352
openvdb::v10_0::util::NodeMask::beginOff
OffIterator beginOff() const
Definition NodeMasks.h:354
openvdb::v10_0::util::NodeMask::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition NodeMasks.h:502
openvdb::v10_0::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition NodeMasks.h:452
openvdb::v10_0::util::OffMaskIterator
Definition NodeMasks.h:240
openvdb::v10_0::util::OnMaskIterator
Definition NodeMasks.h:209
openvdb::v10_0::io::getFormatVersion
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
openvdb::v10_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::v10_0::Index
Index32 Index
Definition Types.h:54
openvdb::v10_0::Index32
uint32_t Index32
Definition Types.h:52
openvdb::v10_0::OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION
@ OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION
Definition version.h.in:250
openvdb::v10_0::Int32
int32_t Int32
Definition Types.h:56
openvdb::v10_0::Index64
uint64_t Index64
Definition Types.h:53
openvdb::v10_0::SharedPtr
std::shared_ptr< T > SharedPtr
Definition Types.h:114
openvdb::v10_0::MERGE_NODES
@ MERGE_NODES
Definition Types.h:469
openvdb::v10_0::MERGE_ACTIVE_STATES_AND_NODES
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:470
openvdb
Definition Exceptions.h:13
Types.h
openvdb::v10_0::tree::DenseIteratorBase
Base class for dense iterators over internal and leaf nodes.
Definition Iterator.h:179
openvdb::v10_0::tree::DenseIteratorBase::NonConstValueType
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition Iterator.h:184
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildIter::ChildIter
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNodeBool.h:597
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ChildIter::ChildIter
ChildIter()
Definition LeafNodeBool.h:596
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::DenseIter::getItem
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition LeafNodeBool.h:611
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::DenseIter::DenseIter
DenseIter()
Definition LeafNodeBool.h:608
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::DenseIter::DenseIter
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition LeafNodeBool.h:609
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::DenseIter::NonConstValueT
typename BaseT::NonConstValueType NonConstValueT
Definition LeafNodeBool.h:606
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::DenseIter::unsetItem
void unsetItem(Index pos, const ValueT &val) const
Definition LeafNodeBool.h:622
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::setItem
void setItem(Index pos, bool value) const
Definition LeafNodeBool.h:579
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::modifyValue
void modifyValue(const ModifyOp &op) const
Definition LeafNodeBool.h:588
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::ValueIter
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNodeBool.h:573
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::getValue
const bool & getValue() const
Definition LeafNodeBool.h:576
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::getItem
const bool & getItem(Index pos) const
Definition LeafNodeBool.h:575
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::ValueIter
ValueIter()
Definition LeafNodeBool.h:572
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::setValue
void setValue(bool value) const
Definition LeafNodeBool.h:581
openvdb::v10_0::tree::LeafNode< bool, Log2Dim >::ValueIter::modifyItem
void modifyItem(Index n, const ModifyOp &op) const
Definition LeafNodeBool.h:585
openvdb::v10_0::tree::SameLeafConfig
Definition LeafNode.h:894
openvdb::v10_0::tree::SparseIteratorBase
Base class for sparse iterators over internal and leaf nodes.
Definition Iterator.h:115
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:212