4#ifndef OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
5#define OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
7#include <openvdb/version.h>
30template<Index Log2Dim>
52 template<
typename OtherValueType>
57 template<
typename OtherNodeType>
69 explicit LeafNode(
const Coord& xyz,
bool value =
false,
bool dummy =
false);
78 template<
typename OtherValueType>
82 template<
typename ValueType>
88 template<
typename ValueType>
90 template<
typename ValueType>
147 Index64 memUsageIfLoaded()
const;
152 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
181 std::string str()
const;
185 template<
typename OtherType, Index OtherLog2Dim>
189 bool operator==(
const LeafNode&)
const;
190 bool operator!=(
const LeafNode&)
const;
205 void readTopology(std::istream&,
bool fromHalf =
false);
207 void writeTopology(std::ostream&,
bool toHalf =
false)
const;
210 void readBuffers(std::istream&,
bool fromHalf =
false);
211 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
213 void writeBuffers(std::ostream&,
bool toHalf =
false)
const;
219 const bool& getValue(
const Coord& xyz)
const;
221 const bool& getValue(
Index offset)
const;
226 bool probeValue(
const Coord& xyz,
bool& val)
const;
230 bool probeValue(
Index offset,
bool& val)
const;
236 void setActiveState(
const Coord& xyz,
bool on);
241 void setValueOnly(
const Coord& xyz,
bool val);
251 void setValueOff(
const Coord& xyz,
bool val);
253 void setValueOff(
Index offset,
bool val);
261 void setValueOn(
const Coord& xyz,
bool val);
265 void setValueOn(
Index offset,
bool val);
269 template<
typename ModifyOp>
270 void modifyValue(
Index offset,
const ModifyOp& op);
273 template<
typename ModifyOp>
274 void modifyValue(
const Coord& xyz,
const ModifyOp& op);
277 template<
typename ModifyOp>
278 void modifyValueAndActiveState(
const Coord& xyz,
const ModifyOp& op);
298 void clip(
const CoordBBox&,
bool background);
301 void fill(
const CoordBBox& bbox,
bool value,
bool =
false);
306 void fill(
const bool& value,
bool dummy =
false);
319 template<
typename DenseT>
320 void copyToDense(
const CoordBBox& bbox, DenseT& dense)
const;
338 template<
typename DenseT>
339 void copyFromDense(
const CoordBBox& bbox,
const DenseT& dense,
bool background,
bool tolerance);
343 template<
typename AccessorT>
348 template<
typename AccessorT>
353 template<
typename AccessorT>
359 template<
typename AccessorT>
364 template<
typename AccessorT>
373 template<
typename ModifyOp,
typename AccessorT>
381 template<
typename ModifyOp,
typename AccessorT>
390 template<
typename AccessorT>
399 template<
typename AccessorT>
407 template<
typename AccessorT>
422 bool isConstant(
bool& constValue,
bool& state,
bool tolerance = 0)
const;
429 bool medianAll()
const;
438 Index medianOn(ValueType &value)
const;
448 Index medianOff(ValueType &value)
const;
483 template<MergePolicy Policy>
484 void merge(
const LeafNode& other,
bool bg =
false,
bool otherBG =
false);
485 template<MergePolicy Policy>
void merge(
bool tileValue,
bool tileActive=
false);
497 template<
typename OtherType>
511 template<
typename OtherType>
525 template<
typename OtherType>
528 template<
typename CombineOp>
529 void combine(
const LeafNode& other, CombineOp& op);
530 template<
typename CombineOp>
531 void combine(
bool,
bool valueIsActive, CombineOp& op);
533 template<
typename CombineOp,
typename OtherType >
534 void combine2(
const LeafNode& other,
const OtherType&,
bool valueIsActive, CombineOp&);
535 template<
typename CombineOp,
typename OtherNodeT >
536 void combine2(
bool,
const OtherNodeT& other,
bool valueIsActive, CombineOp&);
537 template<
typename CombineOp,
typename OtherNodeT >
538 void combine2(
const LeafNode& b0,
const OtherNodeT& b1, CombineOp&);
544 template<
typename AccessorT>
546 template<
typename NodeT>
548 template<
typename NodeT>
550 template<
typename NodeT>
552 template<
typename ArrayT>
void getNodes(ArrayT&)
const {}
556 void addTile(
Index level,
const Coord&,
bool val,
bool active);
557 void addTile(
Index offset,
bool val,
bool active);
558 template<
typename AccessorT>
559 void addTileAndCache(
Index level,
const Coord&,
bool val,
bool active, AccessorT&);
564 template<
typename AccessorT>
567 template<
typename AccessorT>
569 template<
typename NodeT,
typename AccessorT>
573 if (!(std::is_same<NodeT, LeafNode>::value))
return nullptr;
574 return reinterpret_cast<NodeT*
>(
this);
581 template<
typename AccessorT>
584 template<
typename AccessorT>
586 template<
typename NodeT,
typename AccessorT>
590 if (!(std::is_same<NodeT, LeafNode>::value))
return nullptr;
591 return reinterpret_cast<const NodeT*
>(
this);
604 template<
typename MaskIterT,
typename NodeT,
typename ValueT>
608 public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
624 template<
typename ModifyOp>
627 template<
typename ModifyOp>
632 template<
typename MaskIterT,
typename NodeT>
641 template<
typename NodeT,
typename ValueT>
643 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, void, ValueT>
778template<Index Log2Dim>
785template<Index Log2Dim>
794template<Index Log2Dim>
803template<Index Log2Dim>
814template<Index Log2Dim>
815template<
typename ValueT>
825template<Index Log2Dim>
826template<
typename ValueT>
837template<Index Log2Dim>
838template<
typename ValueT>
848template<Index Log2Dim>
849template<
typename ValueT>
857 if (offValue==
true) {
858 if (onValue==
false) {
867template<Index Log2Dim>
877template<Index Log2Dim>
882 return sizeof(*this);
886template<Index Log2Dim>
891 return sizeof(*this);
895template<Index Log2Dim>
900 if (bbox.
isInside(this_bbox))
return;
912template<Index Log2Dim>
913template<
typename OtherType, Index OtherLog2Dim>
922template<Index Log2Dim>
926 std::ostringstream ostr;
927 ostr <<
"LeafNode @" <<
mOrigin <<
": ";
936template<Index Log2Dim>
941 return ((xyz[0] & (
DIM-1u)) << 2*Log2Dim)
942 + ((xyz[1] & (
DIM-1u)) << Log2Dim)
943 + (xyz[2] & (
DIM-1u));
947template<Index Log2Dim>
953 xyz.
setX(n >> 2*Log2Dim);
954 n &= ((1 << 2*Log2Dim) - 1);
955 xyz.
setY(n >> Log2Dim);
956 xyz.
setZ(n & ((1 << Log2Dim) - 1));
961template<Index Log2Dim>
972template<Index Log2Dim>
980template<Index Log2Dim>
988template<Index Log2Dim>
998 bool background =
false;
1000 background = *
static_cast<const bool*
>(bgPtr);
1002 this->
clip(clipBBox, background);
1006template<Index Log2Dim>
1017template<Index Log2Dim>
1031template<Index Log2Dim>
1039template<Index Log2Dim>
1050template<Index Log2Dim>
1054 if (!
mBuffer.mData.isConstant(state))
return false;
1063template<Index Log2Dim>
1071template<Index Log2Dim>
1080template<Index Log2Dim>
1086 return countFalseOff;
1093template<Index Log2Dim>
1100template<Index Log2Dim>
1109template<Index Log2Dim>
1110template<
typename AccessorT>
1113 bool val,
bool active, AccessorT&)
1115 this->
addTile(level, xyz, val, active);
1122template<Index Log2Dim>
1127 if (
mBuffer.mData.isOn(this->coordToOffset(xyz)))
return Buffer::sOn;
else return Buffer::sOff;
1131template<Index Log2Dim>
1137 if (
mBuffer.mData.isOn(offset))
return Buffer::sOn;
else return Buffer::sOff;
1141template<Index Log2Dim>
1149template<Index Log2Dim>
1153 val =
mBuffer.mData.isOn(offset);
1158template<Index Log2Dim>
1166template<Index Log2Dim>
1171 mBuffer.mData.set(offset, val);
1175template<Index Log2Dim>
1183template<Index Log2Dim>
1191template<Index Log2Dim>
1199template<Index Log2Dim>
1204 mBuffer.mData.set(offset, val);
1208template<Index Log2Dim>
1209template<
typename ModifyOp>
1213 bool val =
mBuffer.mData.isOn(offset);
1215 mBuffer.mData.set(offset, val);
1219template<Index Log2Dim>
1220template<
typename ModifyOp>
1228template<Index Log2Dim>
1229template<
typename ModifyOp>
1234 bool val =
mBuffer.mData.isOn(offset), state = val;
1236 mBuffer.mData.set(offset, val);
1243template<Index Log2Dim>
1244template<MergePolicy Policy>
1250 mBuffer.mData |= other.mBuffer.mData;
1254template<Index Log2Dim>
1255template<MergePolicy Policy>
1261 if (tileValue)
mBuffer.mData.setOn();
1269template<Index Log2Dim>
1270template<
typename OtherType>
1278template<Index Log2Dim>
1279template<
typename OtherType>
1288template<Index Log2Dim>
1289template<
typename OtherType>
1301template<Index Log2Dim>
1308 this->
fill(nodeBBox, background,
false);
1309 }
else if (clipBBox.
isInside(nodeBBox)) {
1321 int &x = xyz.
x(), &y = xyz.
y(), &z = xyz.
z();
1322 for (x = nodeBBox.
min().
x(); x <= nodeBBox.
max().
x(); ++x) {
1323 for (y = nodeBBox.
min().
y(); y <= nodeBBox.
max().
y(); ++y) {
1324 for (z = nodeBBox.
min().
z(); z <= nodeBBox.
max().
z(); ++z) {
1341template<Index Log2Dim>
1346 clippedBBox.intersect(bbox);
1347 if (!clippedBBox)
return;
1349 for (
Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1350 const Index offsetX = (x & (
DIM-1u))<<2*Log2Dim;
1351 for (
Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1352 const Index offsetXY = offsetX + ((y & (
DIM-1u))<< Log2Dim);
1353 for (
Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1354 const Index offset = offsetXY + (z & (
DIM-1u));
1355 mBuffer.mData.set(offset, value);
1361template<Index Log2Dim>
1372template<Index Log2Dim>
1373template<
typename DenseT>
1377 using DenseValueType =
typename DenseT::ValueType;
1379 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1380 const Coord& min = dense.bbox().min();
1381 DenseValueType* t0 = dense.data() + zStride * (bbox.
min()[2] - min[2]);
1383 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0] + 1; x < ex; ++x) {
1384 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1386 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1] + 1; y < ey; ++y) {
1387 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1389 for (
Int32 z = bbox.
min()[2], ez = bbox.
max()[2] + 1; z < ez; ++z, t2 += zStride) {
1390 *t2 = DenseValueType(
mBuffer.mData.isOn(n2++));
1397template<Index Log2Dim>
1398template<
typename DenseT>
1401 bool background,
bool tolerance)
1403 using DenseValueType =
typename DenseT::ValueType;
1405 inline static bool toBool(
const DenseValueType& v) {
return !
math::isZero(v); }
1408 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1409 const Coord& min = dense.bbox().min();
1410 const DenseValueType* s0 = dense.data() + zStride * (bbox.
min()[2] - min[2]);
1412 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0] + 1; x < ex; ++x) {
1413 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1415 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1] + 1; y < ey; ++y) {
1416 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1418 for (
Int32 z = bbox.
min()[2], ez = bbox.
max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1420 if (tolerance || (background == Local::toBool(*s2))) {
1421 mBuffer.mData.set(n2, background);
1423 mBuffer.mData.set(n2, Local::toBool(*s2));
1434template<Index Log2Dim>
1435template<
typename CombineOp>
1441 bool result =
false, aVal =
mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1452template<Index Log2Dim>
1453template<
typename CombineOp>
1460 bool result =
false, aVal =
mBuffer.mData.isOn(i);
1472template<Index Log2Dim>
1473template<
typename CombineOp,
typename OtherType>
1476 bool valueIsActive, CombineOp& op)
1481 bool result =
false, aVal = other.mBuffer.mData.isOn(i);
1490template<Index Log2Dim>
1491template<
typename CombineOp,
typename OtherNodeT>
1494 bool valueIsActive, CombineOp& op)
1499 bool result =
false, bVal = other.mBuffer.mData.isOn(i);
1508template<Index Log2Dim>
1509template<
typename CombineOp,
typename OtherNodeT>
1515 bool result =
false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:640
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:692
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:708
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition Types.h:696
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:694
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:706
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition Coord.h:316
Int32 ValueType
Definition Coord.h:33
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:760
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:754
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition Coord.h:461
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition Coord.h:421
const Coord & min() const
Definition Coord.h:324
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition Coord.h:415
const Coord & max() const
Definition Coord.h:325
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition Coord.h:403
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:447
void reset()
Definition Coord.h:330
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Int32 y() const
Definition Coord.h:132
Int32 x() const
Definition Coord.h:131
Coord & setZ(Int32 z)
Definition Coord.h:82
Coord & setY(Int32 y)
Definition Coord.h:81
Int32 z() const
Definition Coord.h:133
Coord & setX(Int32 x)
Definition Coord.h:80
Base class for iterators over internal and leaf nodes.
Definition Iterator.h:30
Index pos() const
Definition Iterator.h:60
LeafNode & parent() const
Definition Iterator.h:50
void stealNodes(ArrayT &, const ValueType &, bool)
Definition LeafNodeMask.h:553
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition LeafNodeMask.h:288
static Index64 onTileCount()
Definition LeafNodeMask.h:129
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition LeafNodeMask.h:164
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition LeafNodeMask.h:949
ChildOnCIter cbeginChildOn() const
Definition LeafNodeMask.h:701
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition LeafNodeMask.h:156
NodeMaskType & getValueMask()
Definition LeafNodeMask.h:730
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNodeMask.h:258
bool isChildMaskOn(Index) const
Definition LeafNodeMask.h:732
ChildOnCIter beginChildOn() const
Definition LeafNodeMask.h:702
ChildOnIter beginChildOn()
Definition LeafNodeMask.h:703
static Index64 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition LeafNodeMask.h:121
bool operator==(const LeafNode &) const
Check for buffer equivalence by value.
Definition LeafNodeMask.h:1033
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition LeafNodeMask.h:286
ValueOnIter endValueOn()
Definition LeafNodeMask.h:691
util::NodeMask< Log2Dim > NodeMaskType
Definition LeafNodeMask.h:38
bool isChildMaskOff() const
Definition LeafNodeMask.h:734
ValueOffCIter cbeginValueOff() const
Definition LeafNodeMask.h:682
Index32 transientData() const
Return the transient data value.
Definition LeafNodeMask.h:176
SharedPtr< LeafNodeType > Ptr
Definition LeafNodeMask.h:39
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition LeafNodeMask.h:113
static Index64 leafCount()
Return the leaf count for this node, which is one.
Definition LeafNodeMask.h:115
void setValueMask(const NodeMaskType &mask)
Definition LeafNodeMask.h:731
ChildOnIter endChildOn()
Definition LeafNodeMask.h:713
ValueAllIter endValueAll()
Definition LeafNodeMask.h:697
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition LeafNodeMask.h:563
LeafNode * probeLeaf(const Coord &)
Definition LeafNodeMask.h:566
bool isValueMaskOff() const
Definition LeafNodeMask.h:727
LeafNode(const LeafNode< ValueType, Log2Dim > &other, bool offValue, bool onValue, TopologyCopy)
Topology copy constructor.
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition LeafNodeMask.h:542
bool isValueMaskOn() const
Definition LeafNodeMask.h:725
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition LeafNodeMask.h:677
LeafBuffer< ValueType, Log2Dim > Buffer
Definition LeafNodeMask.h:37
void getNodes(ArrayT &) const
Definition LeafNodeMask.h:552
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition LeafNodeMask.h:283
ValueAllCIter endValueAll() const
Definition LeafNodeMask.h:696
void setValueOnlyUnsafe(Index offset, const bool &value)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition LeafNodeMask.h:466
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition LeafNodeMask.h:673
Index64 onLeafVoxelCount() const
Definition LeafNodeMask.h:127
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don't change its active state.
Definition LeafNodeMask.h:243
ChildOffCIter endChildOff() const
Definition LeafNodeMask.h:715
ValueAllCIter cbeginValueAll() const
Definition LeafNodeMask.h:685
NodeT * probeNode(const Coord &)
Definition LeafNodeMask.h:549
bool probeValue(const Coord &xyz, bool &val) const
Return true if the voxel at the given coordinates is active.
Definition LeafNodeMask.h:1143
ValueOnCIter beginValueOn() const
Definition LeafNodeMask.h:680
ValueMask BuildType
Definition LeafNodeMask.h:35
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition LeafNodeMask.h:741
const Buffer & buffer() const
Definition LeafNodeMask.h:198
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition LeafNodeMask.h:568
void setValueMaskOn(Index n)
Definition LeafNodeMask.h:737
Index64 offLeafVoxelCount() const
Definition LeafNodeMask.h:128
const LeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition LeafNodeMask.h:580
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition LeafNodeMask.h:159
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition LeafNodeMask.h:162
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition LeafNodeMask.h:233
typename NodeMaskType::OnIterator MaskOnIter
Definition LeafNodeMask.h:600
bool isInactive() const
Return true if all of this node's values are inactive.
Definition LeafNodeMask.h:451
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition LeafNodeMask.h:1231
Buffer mBuffer
Bitmask representing the values AND state of voxels.
Definition LeafNodeMask.h:744
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition LeafNodeMask.h:667
bool isValueMaskOff(Index n) const
Definition LeafNodeMask.h:726
ValueOnCIter cendValueOn() const
Definition LeafNodeMask.h:689
LeafNode< ValueMask, Log2Dim > LeafNodeType
Definition LeafNodeMask.h:34
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition LeafNodeMask.h:139
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition LeafNodeMask.h:408
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition LeafNodeMask.h:107
void setValueOffUnsafe(Index offset, const bool &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNodeMask.h:474
void setActiveStateUnsafe(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition LeafNodeMask.h:464
ValueOffCIter beginValueOff() const
Definition LeafNodeMask.h:683
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition LeafNodeMask.h:668
ChildAllCIter cbeginChildAll() const
Definition LeafNodeMask.h:707
ChildOffIter endChildOff()
Definition LeafNodeMask.h:716
static const Index NUM_VOXELS
Definition LeafNodeMask.h:46
ChildAllIter beginChildAll()
Definition LeafNodeMask.h:709
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition LeafNodeMask.h:109
bool getValueUnsafe(Index offset, bool &value) const
Return true if the voxel at the given offset is active and set value.
Definition LeafNodeMask.h:462
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition LeafNodeMask.h:349
void denseFill(const CoordBBox &bbox, bool value, bool=false)
Set all voxels within an axis-aligned box to the specified value.
Definition LeafNodeMask.h:303
void addLeaf(LeafNode *)
Definition LeafNodeMask.h:543
static const Index DIM
Definition LeafNodeMask.h:44
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 LeafNodeMask.h:1185
ValueOnIter beginValueOn()
Definition LeafNodeMask.h:681
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 LeafNodeMask.h:374
void setValueOffAndCache(const Coord &xyz, bool value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition LeafNodeMask.h:365
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition LeafNodeMask.h:675
static const Index LEVEL
Definition LeafNodeMask.h:48
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition LeafNodeMask.h:570
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition LeafNodeMask.h:670
ChildOffCIter cbeginChildOff() const
Definition LeafNodeMask.h:704
ChildOffIter beginChildOff()
Definition LeafNodeMask.h:706
bool isChildMaskOff(Index) const
Definition LeafNodeMask.h:733
Index64 onVoxelCount() const
Return the number of active voxels.
Definition LeafNodeMask.h:124
typename NodeMaskType::OffIterator MaskOffIter
Definition LeafNodeMask.h:601
ChildOffCIter beginChildOff() const
Definition LeafNodeMask.h:705
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition LeafNodeMask.h:938
LeafNode(const LeafNode< ValueType, Log2Dim > &other, bool background, TopologyCopy)
static Index64 offTileCount()
Definition LeafNodeMask.h:130
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition LeafNodeMask.h:246
bool ValueType
Definition LeafNodeMask.h:36
ValueOffIter endValueOff()
Definition LeafNodeMask.h:694
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNodeMask.h:248
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNodeMask.h:585
void setValueOnly(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition LeafNodeMask.h:1177
ChildAllCIter endChildAll() const
Definition LeafNodeMask.h:718
void nodeCount(std::vector< Index64 > &) const
no-op
Definition LeafNodeMask.h:117
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition LeafNodeMask.h:587
ValueOnCIter cbeginValueOn() const
Definition LeafNodeMask.h:679
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition LeafNodeMask.h:101
void resetBackground(bool, bool)
no-op since for this template specialization voxel values and states are indistinguishable.
Definition LeafNodeMask.h:478
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition LeafNodeMask.h:111
ChildOnCIter endChildOn() const
Definition LeafNodeMask.h:712
const LeafNode * probeConstLeaf(const Coord &) const
Definition LeafNodeMask.h:583
void setValueOnUnsafe(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNodeMask.h:468
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 LeafNodeMask.h:400
ChildOnCIter cendChildOn() const
Definition LeafNodeMask.h:711
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition LeafNodeMask.h:295
ChildAllCIter cendChildAll() const
Definition LeafNodeMask.h:717
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition LeafNodeMask.h:666
void setValueOnlyAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition LeafNodeMask.h:360
void setValueOnUnsafe(Index offset, const bool &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNodeMask.h:470
DenseIter< LeafNode, bool > ChildAllIter
Definition LeafNodeMask.h:676
ChildAllIter endChildAll()
Definition LeafNodeMask.h:719
void setValueMask(Index n, bool on)
Definition LeafNodeMask.h:736
const NodeMaskType & valueMask() const
Definition LeafNodeMask.h:729
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition LeafNodeMask.h:126
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition LeafNodeMask.h:197
ValueAllCIter cendValueAll() const
Definition LeafNodeMask.h:695
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition LeafNodeMask.h:672
friend class LeafNode
During topology-only construction, access is needed to protected/private members of other template in...
Definition LeafNodeMask.h:753
Index32 mTransientData
Transient data (not serialized).
Definition LeafNodeMask.h:748
static const Index NUM_VALUES
Definition LeafNodeMask.h:45
LeafNode(const LeafNode< ValueType, Log2Dim > &other, TopologyCopy)
Topology copy constructor.
void negate()
Invert the bits of the voxels, i.e. states and values.
Definition LeafNodeMask.h:481
ChildAllCIter beginChildAll() const
Definition LeafNodeMask.h:708
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNodeMask.h:582
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition LeafNodeMask.h:391
void getOrigin(Coord &origin) const
Definition LeafNodeMask.h:163
const bool & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition LeafNodeMask.h:1124
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition LeafNodeMask.h:281
friend class LeafBuffer
Definition LeafNodeMask.h:770
void setTransientData(Index32 transientData)
Set the transient data value.
Definition LeafNodeMask.h:178
void fill(const CoordBBox &bbox, bool value, bool=false)
Set all voxels within an axis-aligned box to the specified value.
Definition LeafNodeMask.h:1343
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition LeafNodeMask.h:105
ChildOffCIter cendChildOff() const
Definition LeafNodeMask.h:714
const bool & getValueUnsafe(Index offset) const
Return the value of the voxel at the given offset.
Definition LeafNodeMask.h:460
typename NodeMaskType::DenseIterator MaskDenseIter
Definition LeafNodeMask.h:602
static const Index LOG2DIM
Definition LeafNodeMask.h:42
static const Index SIZE
Definition LeafNodeMask.h:47
bool isEmpty() const
Return true if this node has no active voxels.
Definition LeafNodeMask.h:133
void setValueAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition LeafNodeMask.h:354
ValueOffIter beginValueOff()
Definition LeafNodeMask.h:684
const NodeT * probeConstNode(const Coord &) const
Definition LeafNodeMask.h:551
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition LeafNodeMask.h:256
Buffer & buffer()
Definition LeafNodeMask.h:199
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition LeafNodeMask.h:238
void addTile(Index level, const Coord &, bool val, bool active)
Definition LeafNodeMask.h:1095
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition LeafNodeMask.h:143
const NodeMaskType & getValueMask() const
Definition LeafNodeMask.h:728
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition LeafNodeMask.h:413
static const Index TOTAL
Definition LeafNodeMask.h:43
void addLeafAndCache(LeafNode *, AccessorT &)
Definition LeafNodeMask.h:545
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition LeafNodeMask.h:417
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 LeafNodeMask.h:1211
ValueOffCIter cendValueOff() const
Definition LeafNodeMask.h:692
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition LeafNodeMask.h:671
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition LeafNodeMask.h:344
void setValueMaskOff(Index n)
Definition LeafNodeMask.h:738
bool isDense() const
Return true if this node only contains active voxels.
Definition LeafNodeMask.h:135
ValueOffCIter endValueOff() const
Definition LeafNodeMask.h:693
bool isValueOff(const Coord &xyz) const
Return true if the voxel at the given coordinates is inactive.
Definition LeafNodeMask.h:290
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition LeafNodeMask.h:547
void setValueOffUnsafe(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNodeMask.h:472
void setValue(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNodeMask.h:263
void readBuffers(std::istream &, bool fromHalf=false)
Read in the topology and the origin.
Definition LeafNodeMask.h:1008
ValueOnCIter endValueOn() const
Definition LeafNodeMask.h:690
void voxelizeActiveTiles(bool=true)
No-op.
Definition LeafNodeMask.h:489
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition LeafNodeMask.h:382
bool isValueOff(Index offset) const
Return true if the voxel at the given offset is inactive.
Definition LeafNodeMask.h:292
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition LeafNodeMask.h:565
ValueAllCIter beginValueAll() const
Definition LeafNodeMask.h:686
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition LeafNodeMask.h:746
static Index dim()
Return the number of voxels in each dimension.
Definition LeafNodeMask.h:103
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition LeafNodeMask.h:674
void clip(const CoordBBox &, bool background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition LeafNodeMask.h:1303
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition LeafNodeMask.h:669
bool isValueMaskOn(Index n) const
Definition LeafNodeMask.h:724
ValueAllIter beginValueAll()
Definition LeafNodeMask.h:687
LeafNode(const LeafNode< OtherValueType, Log2Dim > &other)
Value conversion copy constructor.
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:1756
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition LeafNode.h:1612
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition LeafNode.h:1570
~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:1588
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition LeafNode.h:1639
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:1747
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:1739
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:1526
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition LeafNode.h:1461
void combine(const LeafNode &other, CombineOp &op)
Definition LeafNode.h:1780
Index64 memUsageIfLoaded() const
Definition LeafNode.h:1498
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1820
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
const NodeMaskType & valueMask() const
Definition LeafNode.h:915
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:1534
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:1478
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition LeafNode.h:1508
void merge(const LeafNode &)
Definition LeafNode.h:1690
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition LeafNode.h:449
const NodeMaskType & getValueMask() const
Definition LeafNode.h:913
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition LeafNode.h:1656
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:1488
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
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition NodeMasks.h:308
OffIterator beginOff() const
Definition NodeMasks.h:354
DenseMaskIterator< NodeMask > DenseIterator
Definition NodeMasks.h:350
OnMaskIterator< NodeMask > OnIterator
Definition NodeMasks.h:348
void setOn(Index32 n)
Set the nth bit on.
Definition NodeMasks.h:452
OffMaskIterator< NodeMask > OffIterator
Definition NodeMasks.h:349
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 isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition Math.h:337
Definition TreeIterator.h:30
Index32 Index
Definition Types.h:54
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
uint32_t Index32
Definition Types.h:52
int32_t Int32
Definition Types.h:56
uint64_t Index64
Definition Types.h:53
std::shared_ptr< T > SharedPtr
Definition Types.h:114
@ MERGE_NODES
Definition Types.h:579
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:580
Definition Exceptions.h:13
typename std::remove_const< ValueT >::type NonConstValueType
Definition Iterator.h:184
DenseIteratorBase()
Definition Iterator.h:188
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition LeafNodeMask.h:635
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNodeMask.h:637
ChildIter()
Definition LeafNodeMask.h:636
Definition LeafNodeMask.h:644
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition LeafNodeMask.h:651
DenseIter()
Definition LeafNodeMask.h:648
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition LeafNodeMask.h:649
typename BaseT::NonConstValueType NonConstValueT
Definition LeafNodeMask.h:646
DenseIteratorBase< MaskDenseIter, DenseIter, NodeT, void, ValueT > BaseT
Definition LeafNodeMask.h:645
void unsetItem(Index pos, const ValueT &val) const
Definition LeafNodeMask.h:662
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition LeafNodeMask.h:58
static const bool value
Definition LeafNodeMask.h:59
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition LeafNodeMask.h:53
LeafNode< OtherValueType, Log2Dim > Type
Definition LeafNodeMask.h:53
Definition LeafNodeMask.h:609
void setItem(Index pos, bool value) const
Definition LeafNodeMask.h:619
void modifyValue(const ModifyOp &op) const
Definition LeafNodeMask.h:628
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNodeMask.h:613
const bool & getValue() const
Definition LeafNodeMask.h:616
const bool & getItem(Index pos) const
Definition LeafNodeMask.h:615
ValueIter()
Definition LeafNodeMask.h:612
void setValue(bool value) const
Definition LeafNodeMask.h:621
void modifyItem(Index n, const ModifyOp &op) const
Definition LeafNodeMask.h:625
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition LeafNodeMask.h:610
static const bool value
Definition LeafNode.h:949
SparseIteratorBase()
Definition Iterator.h:122
#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