4 #ifndef OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
5 #define OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
17 #include <type_traits>
29 template<Index Log2Dim>
51 template<
typename OtherValueType>
56 template<
typename OtherNodeType>
57 struct SameConfiguration {
77 template<
typename OtherValueType>
81 template<
typename ValueType>
87 template<
typename ValueType>
89 template<
typename ValueType>
130 bool isEmpty()
const {
return mBuffer.mData.isOff(); }
132 bool isDense()
const {
return mBuffer.mData.isOn(); }
159 const Coord&
origin()
const {
return mOrigin; }
182 template<
typename OtherType, Index OtherLog2Dim>
202 void readTopology(std::istream&,
bool fromHalf =
false);
204 void writeTopology(std::ostream&,
bool toHalf =
false)
const;
207 void readBuffers(std::istream&,
bool fromHalf =
false);
210 void writeBuffers(std::ostream&,
bool toHalf =
false)
const;
216 const bool&
getValue(
const Coord& xyz)
const;
262 template<
typename ModifyOp>
266 template<
typename ModifyOp>
267 void modifyValue(
const Coord& xyz,
const ModifyOp& op);
270 template<
typename ModifyOp>
308 template<
typename DenseT>
327 template<
typename DenseT>
332 template<
typename AccessorT>
337 template<
typename AccessorT>
342 template<
typename AccessorT>
348 template<
typename AccessorT>
353 template<
typename AccessorT>
362 template<
typename ModifyOp,
typename AccessorT>
370 template<
typename ModifyOp,
typename AccessorT>
379 template<
typename AccessorT>
388 template<
typename AccessorT>
396 template<
typename AccessorT>
402 const bool&
getFirstValue()
const {
if (mBuffer.mData.isOn(0))
return Buffer::sOn;
else return Buffer::sOff; }
406 const bool&
getLastValue()
const {
if (mBuffer.mData.isOn(
SIZE-1))
return Buffer::sOn;
else return Buffer::sOff; }
411 bool isConstant(
bool& constValue,
bool& state,
bool tolerance = 0)
const;
447 void negate() { mBuffer.mData.toggle(); }
449 template<MergePolicy Policy>
450 void merge(
const LeafNode& other,
bool bg =
false,
bool otherBG =
false);
451 template<MergePolicy Policy>
void merge(
bool tileValue,
bool tileActive=
false);
463 template<
typename OtherType>
477 template<
typename OtherType>
491 template<
typename OtherType>
494 template<
typename CombineOp>
496 template<
typename CombineOp>
497 void combine(
bool,
bool valueIsActive, CombineOp& op);
499 template<
typename CombineOp,
typename OtherType >
500 void combine2(
const LeafNode& other,
const OtherType&,
bool valueIsActive, CombineOp&);
501 template<
typename CombineOp,
typename OtherNodeT >
502 void combine2(
bool,
const OtherNodeT& other,
bool valueIsActive, CombineOp&);
503 template<
typename CombineOp,
typename OtherNodeT >
510 template<
typename AccessorT>
512 template<
typename NodeT>
514 template<
typename NodeT>
516 template<
typename NodeT>
518 template<
typename ArrayT>
void getNodes(ArrayT&)
const {}
524 template<
typename AccessorT>
530 template<
typename AccessorT>
533 template<
typename AccessorT>
535 template<
typename NodeT,
typename AccessorT>
540 return reinterpret_cast<NodeT*
>(
this);
547 template<
typename AccessorT>
550 template<
typename AccessorT>
552 template<
typename NodeT,
typename AccessorT>
557 return reinterpret_cast<const NodeT*
>(
this);
570 template<
typename MaskIterT,
typename NodeT,
typename ValueT>
574 public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
590 template<
typename ModifyOp>
593 template<
typename ModifyOp>
598 template<
typename MaskIterT,
typename NodeT>
604 MaskIterT,
ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
607 template<
typename NodeT,
typename ValueT>
609 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, void, ValueT>
619 value = this->
parent().getValue(pos);
633 using ValueOnCIter = ValueIter<MaskOnIter, const LeafNode, const bool>;
744 template<Index Log2Dim>
751 template<Index Log2Dim>
754 : mBuffer(value || active)
755 , mOrigin(xyz & (~(DIM - 1)))
760 template<Index Log2Dim>
763 : mBuffer(value || active)
764 , mOrigin(xyz & (~(DIM - 1)))
769 template<Index Log2Dim>
772 : mBuffer(other.mBuffer)
773 , mOrigin(other.mOrigin)
774 , mTransientData(other.mTransientData)
780 template<Index Log2Dim>
781 template<
typename ValueT>
784 : mBuffer(other.valueMask())
785 , mOrigin(other.origin())
786 , mTransientData(other.mTransientData)
791 template<Index Log2Dim>
792 template<
typename ValueT>
796 : mBuffer(other.valueMask())
797 , mOrigin(other.origin())
798 , mTransientData(other.mTransientData)
803 template<Index Log2Dim>
804 template<
typename ValueT>
807 : mBuffer(other.valueMask())
808 , mOrigin(other.origin())
809 , mTransientData(other.mTransientData)
814 template<Index Log2Dim>
815 template<
typename ValueT>
819 : mBuffer(other.valueMask())
820 , mOrigin(other.origin())
821 , mTransientData(other.mTransientData)
823 if (offValue==
true) {
824 if (onValue==
false) {
825 mBuffer.mData.toggle();
827 mBuffer.mData.setOn();
833 template<Index Log2Dim>
843 template<Index Log2Dim>
848 return sizeof(*this);
852 template<Index Log2Dim>
857 return sizeof(*this);
861 template<Index Log2Dim>
866 if (bbox.isInside(this_bbox))
return;
870 for(; iter; ++iter) this_bbox.expand(
this->offsetToLocalCoord(iter.pos()));
871 this_bbox.translate(this->
origin());
873 bbox.expand(this_bbox);
878 template<Index Log2Dim>
879 template<
typename OtherType, Index OtherLog2Dim>
884 return (Log2Dim == OtherLog2Dim && mBuffer.mData == other->
getValueMask());
888 template<Index Log2Dim>
892 std::ostringstream ostr;
893 ostr <<
"LeafNode @" << mOrigin <<
": ";
894 for (
Index32 n = 0;
n <
SIZE; ++
n) ostr << (mBuffer.mData.isOn(
n) ?
'#' :
'.');
902 template<Index Log2Dim>
906 assert ((xyz[0] & (
DIM-1u)) <
DIM && (xyz[1] & (
DIM-1u)) <
DIM && (xyz[2] & (
DIM-1u)) <
DIM);
907 return ((xyz[0] & (
DIM-1u)) << 2*Log2Dim)
908 + ((xyz[1] & (
DIM-1u)) << Log2Dim)
909 + (xyz[2] & (
DIM-1u));
913 template<Index Log2Dim>
917 assert(n < (1 << 3*Log2Dim));
919 xyz.setX(n >> 2*Log2Dim);
920 n &= ((1 << 2*Log2Dim) - 1);
921 xyz.setY(n >> Log2Dim);
922 xyz.setZ(n & ((1 << Log2Dim) - 1));
927 template<Index Log2Dim>
938 template<Index Log2Dim>
942 mBuffer.mData.load(is);
946 template<Index Log2Dim>
950 mBuffer.mData.save(os);
954 template<Index Log2Dim>
964 bool background =
false;
966 background = *
static_cast<const bool*
>(bgPtr);
968 this->
clip(clipBBox, background);
972 template<Index Log2Dim>
977 mBuffer.mData.load(is);
983 template<Index Log2Dim>
988 mBuffer.mData.save(os);
990 os.write(reinterpret_cast<const char*>(&mOrigin),
sizeof(
Coord::ValueType) * 3);
997 template<Index Log2Dim>
1001 return mOrigin == other.mOrigin && mBuffer == other.mBuffer;
1005 template<Index Log2Dim>
1016 template<Index Log2Dim>
1020 if (!mBuffer.mData.isConstant(state))
return false;
1029 template<Index Log2Dim>
1033 const Index countTrue = mBuffer.mData.countOn();
1037 template<Index Log2Dim>
1041 const Index countTrueOn = mBuffer.mData.countOn();
1046 template<Index Log2Dim>
1050 const Index countFalseOff = mBuffer.mData.countOff();
1052 return countFalseOff;
1059 template<Index Log2Dim>
1066 template<Index Log2Dim>
1070 assert(offset <
SIZE);
1075 template<Index Log2Dim>
1076 template<
typename AccessorT>
1081 this->
addTile(level, xyz, val, active);
1088 template<Index Log2Dim>
1093 if (mBuffer.mData.isOn(
this->coordToOffset(xyz)))
return Buffer::sOn;
else return Buffer::sOff;
1097 template<Index Log2Dim>
1101 assert(offset <
SIZE);
1103 if (mBuffer.mData.isOn(offset))
return Buffer::sOn;
else return Buffer::sOff;
1107 template<Index Log2Dim>
1112 val = mBuffer.mData.isOn(offset);
1117 template<Index Log2Dim>
1125 template<Index Log2Dim>
1129 assert(offset <
SIZE);
1130 mBuffer.mData.set(offset, val);
1134 template<Index Log2Dim>
1142 template<Index Log2Dim>
1150 template<Index Log2Dim>
1158 template<Index Log2Dim>
1162 assert(offset <
SIZE);
1163 mBuffer.mData.set(offset, val);
1167 template<Index Log2Dim>
1168 template<
typename ModifyOp>
1172 bool val = mBuffer.mData.isOn(offset);
1174 mBuffer.mData.set(offset, val);
1178 template<Index Log2Dim>
1179 template<
typename ModifyOp>
1187 template<Index Log2Dim>
1188 template<
typename ModifyOp>
1193 bool val = mBuffer.mData.isOn(offset), state =
val;
1195 mBuffer.mData.set(offset, val);
1202 template<Index Log2Dim>
1203 template<MergePolicy Policy>
1209 mBuffer.mData |= other.mBuffer.mData;
1213 template<Index Log2Dim>
1214 template<MergePolicy Policy>
1220 if (tileValue) mBuffer.mData.setOn();
1228 template<Index Log2Dim>
1229 template<
typename OtherType>
1237 template<Index Log2Dim>
1238 template<
typename OtherType>
1247 template<Index Log2Dim>
1248 template<
typename OtherType>
1260 template<Index Log2Dim>
1265 if (!clipBBox.hasOverlap(nodeBBox)) {
1267 this->
fill(nodeBBox, background,
false);
1268 }
else if (clipBBox.isInside(nodeBBox)) {
1278 nodeBBox.intersect(clipBBox);
1280 int &
x = xyz.x(), &
y = xyz.y(), &
z = xyz.z();
1281 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++
x) {
1282 for (
y = nodeBBox.min().y();
y <= nodeBBox.max().y(); ++
y) {
1283 for (
z = nodeBBox.min().z();
z <= nodeBBox.max().z(); ++
z) {
1300 template<Index Log2Dim>
1305 clippedBBox.intersect(bbox);
1306 if (!clippedBBox)
return;
1308 for (
Int32 x = clippedBBox.min().x();
x <= clippedBBox.max().x(); ++
x) {
1309 const Index offsetX = (
x & (
DIM-1u))<<2*Log2Dim;
1310 for (
Int32 y = clippedBBox.min().y();
y <= clippedBBox.max().y(); ++
y) {
1311 const Index offsetXY = offsetX + ((
y & (
DIM-1u))<< Log2Dim);
1312 for (
Int32 z = clippedBBox.min().z();
z <= clippedBBox.max().z(); ++
z) {
1314 mBuffer.mData.set(offset, value);
1320 template<Index Log2Dim>
1324 mBuffer.
fill(value);
1331 template<Index Log2Dim>
1332 template<
typename DenseT>
1338 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1339 const Coord&
min = dense.bbox().min();
1340 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1341 const Int32 n0 = bbox.min()[2] & (
DIM-1u);
1342 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1;
x < ex; ++
x) {
1343 DenseValueType* t1 = t0 + xStride * (
x - min[0]);
1345 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1;
y < ey; ++
y) {
1346 DenseValueType* t2 = t1 + yStride * (
y - min[1]);
1348 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1;
z < ez; ++
z, t2 += zStride) {
1349 *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1356 template<Index Log2Dim>
1357 template<
typename DenseT>
1360 bool background,
bool tolerance)
1364 inline static bool toBool(
const DenseValueType&
v) {
return !
math::isZero(v); }
1367 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1368 const Coord&
min = dense.bbox().min();
1369 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1370 const Int32 n0 = bbox.min()[2] & (
DIM-1u);
1371 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1;
x < ex; ++
x) {
1372 const DenseValueType* s1 = s0 + xStride * (
x - min[0]);
1374 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1;
y < ey; ++
y) {
1375 const DenseValueType* s2 = s1 + yStride * (
y - min[1]);
1377 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2]+1;
z < ez; ++
z, ++n2, s2 += zStride) {
1379 if (tolerance || (background == Local::toBool(*s2))) {
1380 mBuffer.mData.set(n2, background);
1382 mBuffer.mData.set(n2, Local::toBool(*s2));
1393 template<Index Log2Dim>
1394 template<
typename CombineOp>
1400 bool result =
false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1405 .setResultRef(result));
1406 mBuffer.mData.set(i, result);
1411 template<Index Log2Dim>
1412 template<
typename CombineOp>
1417 args.
setBRef(value).setBIsActive(valueIsActive);
1419 bool result =
false, aVal = mBuffer.mData.isOn(i);
1422 .setResultRef(result));
1423 mBuffer.mData.set(i, result);
1431 template<Index Log2Dim>
1432 template<
typename CombineOp,
typename OtherType>
1435 bool valueIsActive, CombineOp& op)
1438 args.
setBRef(value).setBIsActive(valueIsActive);
1440 bool result =
false, aVal = other.mBuffer.mData.isOn(i);
1443 .setResultRef(result));
1444 mBuffer.mData.set(i, result);
1449 template<Index Log2Dim>
1450 template<
typename CombineOp,
typename OtherNodeT>
1453 bool valueIsActive, CombineOp& op)
1456 args.
setARef(value).setAIsActive(valueIsActive);
1458 bool result =
false, bVal = other.mBuffer.mData.isOn(i);
1461 .setResultRef(result));
1462 mBuffer.mData.set(i, result);
1467 template<Index Log2Dim>
1468 template<
typename CombineOp,
typename OtherNodeT>
1474 bool result =
false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1476 .setAIsActive(b0Val)
1478 .setBIsActive(b1Val)
1479 .setResultRef(result));
1480 mBuffer.mData.set(i, result);
1489 #endif // OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
ChildOffCIter beginChildOff() const
void setTransientData(Index32 transientData)
Set the transient data value.
void modifyValue(const ModifyOp &op) const
static Index dim()
Return the number of voxels in each dimension.
static Index64 onTileCount()
Index64 memUsageIfLoaded() const
void merge(const LeafNode &)
LeafNode specialization for values of type ValueMask that encodes both the active states and the bool...
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
bool isValueMaskOn() const
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
void stealNodes(ArrayT &, const ValueType &, bool)
This function exists only to enable template instantiation.
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 ...
ValueOffIter endValueOff()
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
static const Index NUM_VOXELS
ValueOnIter beginValueOn()
ValueOffCIter beginValueOff() const
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
ValueOffCIter cendValueOff() const
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 allocate()
Allocate memory for this node's buffer if it has not already been allocated.
ChildIter(const MaskIterT &iter, NodeT *parent)
const NodeMaskType & valueMask() const
bool getItem(Index pos, void *&child, NonConstValueT &value) const
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
ChildAllIter beginChildAll()
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
void setValueAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
ChildIter< MaskOffIterator, LeafNode, ChildOff > ChildOffIter
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.
DenseIter< const LeafNode, const bool > ChildAllCIter
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
const NodeMaskType & valueMask() const
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value. ...
NodeMaskType & getValueMask()
ChildAllCIter endChildAll() const
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
ValueAllCIter cbeginValueAll() const
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
static Index size()
Return the total number of voxels represented by this LeafNode.
const LeafNode * probeConstLeaf(const Coord &) const
Return a pointer to this node.
Buffer mBuffer
Bitmask representing the values AND state of voxels.
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
void setValueMaskOn(Index n)
static const Index NUM_VALUES
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a pointer to this node.
SharedPtr< LeafNodeType > Ptr
GLdouble GLdouble GLdouble z
bool isChildMaskOff(Index) const
Index pos() const
Identical to offset.
const NodeMaskType & getValueMask() const
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Index64 memUsage() const
Return the memory in bytes occupied by this node.
ChildAllCIter cendChildAll() const
#define OPENVDB_USE_VERSION_NAMESPACE
typename NodeMaskType::DenseIterator MaskDenseIter
Index64 offLeafVoxelCount() const
ValueOnCIter endValueOn() const
Base class for iterators over internal and leaf nodes.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
ChildIter< MaskOnIterator, const LeafNode, ChildOn > ChildOnCIter
**But if you need a or simply need to know when the task has note that the like this
ValueT & getItem(Index pos) const
ChildAllCIter beginChildAll() const
ChildIter< MaskOnIterator, LeafNode, ChildOn > ChildOnIter
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
void setValue(bool value) const
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
**But if you need a result
static Index log2dim()
Return log2 of the size of the buffer storage.
ChildOnCIter beginChildOn() const
NodeT & parent() const
Return a reference to the node over which this iterator is iterating.
void setValueMaskOff(Index n)
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, whose ValueType may be different. So a resulting voxel will be active only if both of the original voxels were active.
bool isChildMaskOff() const
DenseIter< LeafNode, bool > ChildAllIter
void setValuesOn()
Mark all voxels as active but don't change their values.
ValueIter(const MaskIterT &iter, NodeT *parent)
Tag dispatch class that distinguishes constructors during file input.
ValueOffCIter endValueOff() const
ValueOnCIter cbeginValueOn() const
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
bool isValueMaskOn(Index n) const
void setItem(Index pos, bool value) const
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
ValueIter< MaskOffIterator, const LeafNode, const ValueType, ValueOff > ValueOffCIter
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a pointer to this node.
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
void nodeCount(std::vector< Index32 > &) const
no-op
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
ValueIter< MaskDenseIterator, LeafNode, const ValueType, ValueAll > ValueAllIter
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
std::shared_ptr< T > SharedPtr
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
ValueOnCIter cendValueOn() const
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
const bool & getItem(Index pos) const
ChildOffIter beginChildOff()
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
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...
bool isDense() const
Return true if this node only contains active voxels.
void modifyItem(Index n, const ModifyOp &op) const
OffMaskIterator< NodeMask > OffIterator
ChildOnCIter cbeginChildOn() const
Index64 onVoxelCount() const
Return the number of active voxels.
typename BaseT::NonConstValueType NonConstValueT
ValueAllCIter beginValueAll() const
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
void swap(LeafBuffer &)
Exchange this buffer's values with the other buffer's values.
void addTile(Index level, const Coord &, const ValueType &, bool)
Index64 onVoxelCount() const
Return the number of voxels marked On.
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
ChildOnIter beginChildOn()
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, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this LeafNode and inactive in the other LeafNode.
ChildOnCIter cendChildOn() const
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const LeafNode * probeLeaf(const Coord &) const
Return a pointer to this node.
ValueAllCIter endValueAll() const
ValueIter< MaskOnIterator, LeafNode, const ValueType, ValueOn > ValueOnIter
void unsetItem(Index pos, const ValueT &val) const
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.
void modifyItem(Index n, const ModifyOp &op) const
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
const NodeMaskType & getValueMask() const
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
bool operator!=(const LeafNode &other) const
const Buffer & buffer() const
void setValueMask(const NodeMaskType &mask)
constexpr enabler dummy
An instance to use in EnableIf.
bool isValueMaskOff(Index n) const
ValueAllCIter cendValueAll() const
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node's local origin.
ChildIter< MaskOnIter, LeafNode > ChildOnIter
ChildAllCIter cbeginChildAll() const
std::string str() const
Return a string representation of this node.
typename std::remove_const< UnsetItemT >::type NonConstValueType
bool isEmpty() const
Return true if this node has no active voxels.
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
static const Index LOG2DIM
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
void setOn(Index32 n)
Set the nth bit on.
ValueAllIter endValueAll()
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Index64 offVoxelCount() const
Return the number of voxels marked Off.
ChildOnCIter endChildOn() const
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
void setValueOffAndCache(const Coord &xyz, bool value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
OffIterator beginOff() const
static Index32 leafCount()
Return the leaf count for this node, which is one.
void denseFill(const CoordBBox &bbox, bool value, bool=false)
Set all voxels within an axis-aligned box to the specified value.
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don't change its active state. ...
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Base class for sparse iterators over internal and leaf nodes.
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Index32 transientData() const
Return the transient data value.
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
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...
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
LeafNode()
Default constructor.
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a pointer to this node.
static Index64 offTileCount()
Base class for dense iterators over internal and leaf nodes.
void fill(const ValueType &)
Populate this buffer with a constant value.
bool isInactive() const
Return true if all of this node's values are inactive.
DenseMaskIterator< NodeMask > DenseIterator
Library and file format version numbers.
void negate()
Invert the bits of the voxels, i.e. states and values.
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...
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
ValueIter< MaskOnIterator, const LeafNode, const ValueType, ValueOn > ValueOnCIter
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
void setValueMask(Index n, bool on)
void setItem(Index pos, const ValueT &value) const
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
void combine(const LeafNode &other, CombineOp &op)
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Index64 offVoxelCount() const
Return the number of inactive voxels.
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
void voxelizeActiveTiles(bool=true)
No-op.
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
ValueOnCIter cbeginValueOn() const
ValueIter< MaskDenseIterator, const LeafNode, const ValueType, ValueAll > ValueAllCIter
OnMaskIterator< NodeMask > OnIterator
const bool & getValue() const
ChildOffCIter cendChildOff() const
ValueAllIter beginValueAll()
void setValueOnlyAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
**If you just want to fire and args
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
ChildOffCIter cbeginChildOff() const
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
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...
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
ChildIter< MaskOffIter, LeafNode > ChildOffIter
ChildOffIter endChildOff()
void setValuesOff()
Mark all voxels as inactive but don't change their values.
DenseIter(const MaskDenseIter &iter, NodeT *parent)
bool isValueMaskOff() const
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
ValueOffIter beginValueOff()
typename NodeMaskType::OffIterator MaskOffIter
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
void setValue(Index i, const ValueType &)
Set the i'th value of this buffer to the specified value.
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
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...
ChildAllIter endChildAll()
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
ValueOffCIter cbeginValueOff() const
Index64 onLeafVoxelCount() const
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
static Index numValues()
Return the total number of voxels represented by this LeafNode.
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
bool isChildMaskOn(Index) const
ChildIter< MaskOffIterator, const LeafNode, ChildOff > ChildOffCIter
void setValue(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
ChildOffCIter endChildOff() const
typename NodeMaskType::OnIterator MaskOnIter
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
void resetBackground(bool, bool)
no-op since for this template specialization voxel values and states are indistinguishable.
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node's local origin.
ValueOnCIter beginValueOn() const
ValueIter< MaskOffIterator, LeafNode, const ValueType, ValueOff > ValueOffIter
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
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.
Index32 transientData() const
Return the transient data value.