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