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>
42 static const Index LOG2DIM = Log2Dim;
43 static const Index TOTAL = Log2Dim;
44 static const Index DIM = 1 << TOTAL;
45 static const Index NUM_VALUES = 1 << 3 * Log2Dim;
46 static const Index NUM_VOXELS = NUM_VALUES;
47 static const Index SIZE = NUM_VALUES;
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>
133 bool isEmpty()
const {
return mBuffer.mData.isOff(); }
135 bool isDense()
const {
return mBuffer.mData.isOn(); }
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>
367 this->setValueOff(xyz, value);
373 template<
typename ModifyOp,
typename AccessorT>
376 this->modifyValue(xyz, op);
381 template<
typename ModifyOp,
typename AccessorT>
384 this->modifyValueAndActiveState(xyz, op);
390 template<
typename AccessorT>
393 this->setActiveState(xyz, on);
399 template<
typename AccessorT>
402 return this->probeValue(xyz, val);
407 template<
typename AccessorT>
413 const bool&
getFirstValue()
const {
if (mBuffer.mData.isOn(0))
return Buffer::sOn;
else return Buffer::sOff; }
417 const bool&
getLastValue()
const {
if (mBuffer.mData.isOn(SIZE-1))
return Buffer::sOn;
else return Buffer::sOff; }
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;
481 void negate() { mBuffer.mData.toggle(); }
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>
615 const bool&
getItem(
Index pos)
const {
return this->parent().getValue(pos); }
616 const bool&
getValue()
const {
return this->getItem(this->pos()); }
619 void setItem(
Index pos,
bool value)
const { this->parent().setValueOnly(pos, value); }
621 void setValue(
bool value)
const { this->setItem(this->pos(), value); }
624 template<
typename ModifyOp>
625 void modifyItem(
Index n,
const ModifyOp& op)
const { this->parent().modifyValue(n, op); }
627 template<
typename ModifyOp>
628 void modifyValue(
const ModifyOp& op)
const { this->modifyItem(this->pos(), op); }
632 template<
typename MaskIterT,
typename NodeT>
638 MaskIterT,
ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
641 template<
typename NodeT,
typename ValueT>
643 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, void, ValueT>
653 value = this->parent().getValue(pos);
662 void unsetItem(
Index pos,
const ValueT& val)
const {this->parent().setValueOnly(pos, val);}
778template<Index Log2Dim>
785template<Index Log2Dim>
788 : mBuffer(value || active)
789 , mOrigin(xyz & (~(DIM - 1)))
794template<Index Log2Dim>
797 : mBuffer(value || active)
798 , mOrigin(xyz & (~(DIM - 1)))
803template<Index Log2Dim>
806 : mBuffer(other.mBuffer)
807 , mOrigin(other.mOrigin)
808 , mTransientData(other.mTransientData)
814template<Index Log2Dim>
815template<
typename ValueT>
818 : mBuffer(other.valueMask())
819 , mOrigin(other.origin())
820 , mTransientData(other.mTransientData)
825template<Index Log2Dim>
826template<
typename ValueT>
830 : mBuffer(other.valueMask())
831 , mOrigin(other.origin())
832 , mTransientData(other.mTransientData)
837template<Index Log2Dim>
838template<
typename ValueT>
841 : mBuffer(other.valueMask())
842 , mOrigin(other.origin())
843 , mTransientData(other.mTransientData)
848template<Index Log2Dim>
849template<
typename ValueT>
853 : mBuffer(other.valueMask())
854 , mOrigin(other.origin())
855 , mTransientData(other.mTransientData)
857 if (offValue==
true) {
858 if (onValue==
false) {
859 mBuffer.mData.toggle();
861 mBuffer.mData.setOn();
867template<Index Log2Dim>
877template<Index Log2Dim>
882 return sizeof(*this);
886template<Index Log2Dim>
891 return sizeof(*this);
895template<Index Log2Dim>
899 CoordBBox this_bbox = this->getNodeBoundingBox();
900 if (bbox.
isInside(this_bbox))
return;
904 for(; iter; ++iter) this_bbox.
expand(this->offsetToLocalCoord(iter.pos()));
912template<Index Log2Dim>
913template<
typename OtherType, Index OtherLog2Dim>
918 return (Log2Dim == OtherLog2Dim && mBuffer.mData == other->
getValueMask());
922template<Index Log2Dim>
926 std::ostringstream ostr;
927 ostr <<
"LeafNode @" << mOrigin <<
": ";
928 for (
Index32 n = 0; n < SIZE; ++n) ostr << (mBuffer.mData.isOn(n) ?
'#' :
'.');
936template<Index Log2Dim>
940 OPENVDB_ASSERT((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
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>
965 return (this->offsetToLocalCoord(n) + this->origin());
972template<Index Log2Dim>
976 mBuffer.mData.load(is);
980template<Index Log2Dim>
984 mBuffer.mData.save(os);
988template<Index Log2Dim>
995 this->readBuffers(is, fromHalf);
998 bool background =
false;
1000 background = *
static_cast<const bool*
>(bgPtr);
1002 this->clip(clipBBox, background);
1006template<Index Log2Dim>
1011 mBuffer.mData.load(is);
1017template<Index Log2Dim>
1022 mBuffer.mData.save(os);
1024 os.write(
reinterpret_cast<const char*
>(&mOrigin),
sizeof(
Coord::ValueType) * 3);
1031template<Index Log2Dim>
1035 return mOrigin == other.mOrigin && mBuffer == other.mBuffer;
1039template<Index Log2Dim>
1043 return !(this->operator==(other));
1050template<Index Log2Dim>
1054 if (!mBuffer.mData.isConstant(state))
return false;
1063template<Index Log2Dim>
1067 const Index countTrue = mBuffer.mData.countOn();
1068 return countTrue > (NUM_VALUES >> 1);
1071template<Index Log2Dim>
1075 const Index countTrueOn = mBuffer.mData.countOn();
1080template<Index Log2Dim>
1084 const Index countFalseOff = mBuffer.mData.countOff();
1086 return countFalseOff;
1093template<Index Log2Dim>
1097 this->addTile(this->coordToOffset(xyz), val, active);
1100template<Index Log2Dim>
1105 this->setValueOnly(offset, val);
1106 this->setActiveState(offset, active);
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>
1145 return this->probeValue(this->coordToOffset(xyz), val);
1149template<Index Log2Dim>
1153 val = mBuffer.mData.isOn(offset);
1158template<Index Log2Dim>
1162 this->setValueOn(this->coordToOffset(xyz), val);
1166template<Index Log2Dim>
1171 mBuffer.mData.set(offset, val);
1175template<Index Log2Dim>
1179 this->setValueOnly(this->coordToOffset(xyz), val);
1183template<Index Log2Dim>
1187 mBuffer.mData.set(this->coordToOffset(xyz), on);
1191template<Index Log2Dim>
1195 this->setValueOff(this->coordToOffset(xyz), val);
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>
1224 this->modifyValue(this->coordToOffset(xyz), op);
1228template<Index Log2Dim>
1229template<
typename ModifyOp>
1233 const Index offset = this->coordToOffset(xyz);
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>
1305 CoordBBox nodeBBox = this->getNodeBoundingBox();
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) {
1325 mask.
setOn(
static_cast<Index32>(this->coordToOffset(xyz)));
1333 this->setValueOff(maskIter.pos(), background);
1341template<Index Log2Dim>
1345 auto clippedBBox = this->getNodeBoundingBox();
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>
1365 mBuffer.fill(value);
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]);
1382 const Int32 n0 = bbox.
min()[2] & (DIM-1u);
1383 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0] + 1; x < ex; ++x) {
1384 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1385 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1386 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1] + 1; y < ey; ++y) {
1387 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1388 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
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]);
1411 const Int32 n0 = bbox.
min()[2] & (DIM-1u);
1412 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0] + 1; x < ex; ++x) {
1413 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1414 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1415 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1] + 1; y < ey; ++y) {
1416 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1417 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
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>
1440 for (
Index i = 0; i < SIZE; ++i) {
1441 bool result =
false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1447 mBuffer.mData.set(i, result);
1452template<Index Log2Dim>
1453template<
typename CombineOp>
1459 for (
Index i = 0; i < SIZE; ++i) {
1460 bool result =
false, aVal = mBuffer.mData.isOn(i);
1464 mBuffer.mData.set(i, result);
1472template<Index Log2Dim>
1473template<
typename CombineOp,
typename OtherType>
1476 bool valueIsActive, CombineOp& op)
1480 for (
Index i = 0; i < SIZE; ++i) {
1481 bool result =
false, aVal = other.mBuffer.mData.isOn(i);
1485 mBuffer.mData.set(i, result);
1490template<Index Log2Dim>
1491template<
typename CombineOp,
typename OtherNodeT>
1494 bool valueIsActive, CombineOp& op)
1498 for (
Index i = 0; i < SIZE; ++i) {
1499 bool result =
false, bVal = other.mBuffer.mData.isOn(i);
1503 mBuffer.mData.set(i, result);
1508template<Index Log2Dim>
1509template<
typename CombineOp,
typename OtherNodeT>
1514 for (
Index i = 0; i < SIZE; ++i) {
1515 bool result =
false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1521 mBuffer.mData.set(i, result);
#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:569
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:621
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:637
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition Types.h:625
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:623
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:635
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:689
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:683
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 ValueType
Definition Coord.h:33
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
LeafNode specialization for values of type ValueMask that encodes both the active states and the bool...
Definition LeafNodeMask.h:32
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
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 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
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
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
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
ValueOnCIter beginValueOn() const
Definition LeafNodeMask.h:680
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
Buffer mBuffer
Bitmask representing the values AND state of voxels.
Definition LeafNodeMask.h:744
bool isValueMaskOff(Index n) const
Definition LeafNodeMask.h:726
ValueOnCIter cendValueOn() const
Definition LeafNodeMask.h:689
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
ChildAllCIter cbeginChildAll() const
Definition LeafNodeMask.h:707
ChildOffIter endChildOff()
Definition LeafNodeMask.h:716
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
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
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition LeafNodeMask.h:570
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
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
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
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
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
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
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition LeafNodeMask.h:281
void setTransientData(Index32 transientData)
Set the transient data value.
Definition LeafNodeMask.h:178
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
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
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
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
ValueOffCIter cendValueOff() const
Definition LeafNodeMask.h:692
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
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
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:1050
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition LeafNode.h:1306
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:1234
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:1261
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:1075
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:1133
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node's set of active values with the active values of the other node,...
Definition LeafNode.h:1727
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition LeafNode.h:1583
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition LeafNode.h:1541
~LeafNode()
Destructor.
Definition LeafNode.h:1020
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition LeafNode.h:1298
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition LeafNode.h:1559
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition LeafNode.h:1610
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition LeafNode.h:459
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node's set of active values with the active values of the other node,...
Definition LeafNode.h:1718
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition LeafNode.h:1151
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:1125
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other, const bool preserveTiles=false)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition LeafNode.h:1710
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition LeafNode.h:1040
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition LeafNode.h:410
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:1497
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition LeafNode.h:1432
void combine(const LeafNode &other, CombineOp &op)
Definition LeafNode.h:1751
Index64 memUsageIfLoaded() const
Definition LeafNode.h:1469
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1791
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:1191
const NodeMaskType & valueMask() const
Definition LeafNode.h:886
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition LeafNode.h:1334
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition LeafNode.h:1505
friend class LeafNode
Definition LeafNode.h:863
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition LeafNode.h:1064
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition LeafNode.h:1449
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition LeafNode.h:1479
void merge(const LeafNode &)
Definition LeafNode.h:1661
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition LeafNode.h:420
const NodeMaskType & getValueMask() const
Definition LeafNode.h:884
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition LeafNode.h:1627
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:438
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition LeafNode.h:1459
std::string str() const
Return a string representation of this node.
Definition LeafNode.h:1027
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:1091
Definition NodeMasks.h:271
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
void setOn(Index32 n)
Set the nth bit on.
Definition NodeMasks.h:452
Definition NodeMasks.h:240
Definition NodeMasks.h:209
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...
Index32 Index
Definition Types.h:54
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:508
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:509
Definition Exceptions.h:13
Base class for dense iterators over internal and leaf nodes.
Definition Iterator.h:179
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition Iterator.h:184
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
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
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
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
Definition LeafNode.h:920
Base class for sparse iterators over internal and leaf nodes.
Definition Iterator.h:115
#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