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> 17 #include <type_traits> 29 template<Index Log2Dim>
41 static const Index LOG2DIM = Log2Dim;
42 static const Index TOTAL = Log2Dim;
43 static const Index DIM = 1 << TOTAL;
44 static const Index NUM_VALUES = 1 << 3 * Log2Dim;
45 static const Index NUM_VOXELS = NUM_VALUES;
46 static const Index SIZE = NUM_VALUES;
51 template<
typename OtherValueType>
56 template<
typename OtherNodeType>
57 struct SameConfiguration {
68 explicit LeafNode(
const Coord& xyz,
bool value =
false,
bool dummy =
false);
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(); }
149 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
156 void setOrigin(
const Coord& origin) { mOrigin = origin; }
159 const Coord&
origin()
const {
return mOrigin; }
160 void getOrigin(Coord& origin)
const { origin = mOrigin; }
165 static Index coordToOffset(
const Coord& xyz);
168 static Coord offsetToLocalCoord(
Index n);
170 Coord offsetToGlobalCoord(
Index n)
const;
172 #if OPENVDB_ABI_VERSION_NUMBER >= 9 180 std::string str()
const;
184 template<
typename OtherType, Index OtherLog2Dim>
204 void readTopology(std::istream&,
bool fromHalf =
false);
206 void writeTopology(std::ostream&,
bool toHalf =
false)
const;
209 void readBuffers(std::istream&,
bool fromHalf =
false);
210 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
212 void writeBuffers(std::ostream&,
bool toHalf =
false)
const;
218 const bool& getValue(
const Coord& xyz)
const;
220 const bool& getValue(
Index offset)
const;
225 bool probeValue(
const Coord& xyz,
bool& val)
const;
231 void setActiveState(
const Coord& xyz,
bool on);
236 void setValueOnly(
const Coord& xyz,
bool val);
238 void setValueOnly(
Index offset,
bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
241 void setValueOff(
const Coord& xyz) { mBuffer.mData.setOff(this->coordToOffset(xyz)); }
246 void setValueOff(
const Coord& xyz,
bool val);
248 void setValueOff(
Index offset,
bool val);
251 void setValueOn(
const Coord& xyz) { mBuffer.mData.setOn(this->coordToOffset(xyz)); }
256 void setValueOn(
const Coord& xyz,
bool val);
258 void setValue(
const Coord& xyz,
bool val) { this->setValueOn(xyz, val); }
260 void setValueOn(
Index offset,
bool val);
264 template<
typename ModifyOp>
265 void modifyValue(
Index offset,
const ModifyOp& op);
268 template<
typename ModifyOp>
269 void modifyValue(
const Coord& xyz,
const ModifyOp& op);
272 template<
typename ModifyOp>
273 void modifyValueAndActiveState(
const Coord& xyz,
const ModifyOp& op);
281 bool isValueOn(
const Coord& xyz)
const {
return mBuffer.mData.isOn(this->coordToOffset(xyz)); }
283 bool isValueOn(
Index offset)
const { assert(offset < SIZE);
return mBuffer.mData.isOn(offset); }
297 void fill(
const bool& value,
bool dummy =
false);
310 template<
typename DenseT>
329 template<
typename DenseT>
334 template<
typename AccessorT>
335 const bool&
getValueAndCache(
const Coord& xyz, AccessorT&)
const {
return this->getValue(xyz);}
339 template<
typename AccessorT>
344 template<
typename AccessorT>
345 void setValueAndCache(
const Coord& xyz,
bool val, AccessorT&) { this->setValueOn(xyz, val); }
350 template<
typename AccessorT>
355 template<
typename AccessorT>
358 this->setValueOff(xyz, value);
364 template<
typename ModifyOp,
typename AccessorT>
367 this->modifyValue(xyz, op);
372 template<
typename ModifyOp,
typename AccessorT>
375 this->modifyValueAndActiveState(xyz, op);
381 template<
typename AccessorT>
384 this->setActiveState(xyz, on);
390 template<
typename AccessorT>
393 return this->probeValue(xyz, val);
398 template<
typename AccessorT>
404 const bool&
getFirstValue()
const {
if (mBuffer.mData.isOn(0))
return Buffer::sOn;
else return Buffer::sOff; }
408 const bool&
getLastValue()
const {
if (mBuffer.mData.isOn(SIZE-1))
return Buffer::sOn;
else return Buffer::sOff; }
413 bool isConstant(
bool& constValue,
bool& state,
bool tolerance = 0)
const;
420 bool medianAll()
const;
449 void negate() { mBuffer.mData.toggle(); }
451 template<MergePolicy Policy>
452 void merge(
const LeafNode& other,
bool bg =
false,
bool otherBG =
false);
453 template<MergePolicy Policy>
void merge(
bool tileValue,
bool tileActive=
false);
465 template<
typename OtherType>
479 template<
typename OtherType>
493 template<
typename OtherType>
496 template<
typename CombineOp>
498 template<
typename CombineOp>
499 void combine(
bool,
bool valueIsActive, CombineOp& op);
501 template<
typename CombineOp,
typename OtherType >
502 void combine2(
const LeafNode& other,
const OtherType&,
bool valueIsActive, CombineOp&);
503 template<
typename CombineOp,
typename OtherNodeT >
504 void combine2(
bool,
const OtherNodeT& other,
bool valueIsActive, CombineOp&);
505 template<
typename CombineOp,
typename OtherNodeT >
506 void combine2(
const LeafNode& b0,
const OtherNodeT& b1, CombineOp&);
512 template<
typename AccessorT>
514 template<
typename NodeT>
516 template<
typename NodeT>
518 template<
typename NodeT>
520 template<
typename ArrayT>
void getNodes(ArrayT&)
const {}
524 void addTile(
Index level,
const Coord&,
bool val,
bool active);
525 void addTile(
Index offset,
bool val,
bool active);
526 template<
typename AccessorT>
527 void addTileAndCache(
Index level,
const Coord&,
bool val,
bool active, AccessorT&);
532 template<
typename AccessorT>
535 template<
typename AccessorT>
537 template<
typename NodeT,
typename AccessorT>
542 return reinterpret_cast<NodeT*
>(
this);
549 template<
typename AccessorT>
552 template<
typename AccessorT>
554 template<
typename NodeT,
typename AccessorT>
559 return reinterpret_cast<const NodeT*
>(
this);
572 template<
typename MaskIterT,
typename NodeT,
typename ValueT>
576 public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
583 const bool&
getItem(
Index pos)
const {
return this->parent().getValue(pos); }
584 const bool&
getValue()
const {
return this->getItem(this->pos()); }
587 void setItem(
Index pos,
bool value)
const { this->parent().setValueOnly(pos, value); }
589 void setValue(
bool value)
const { this->setItem(this->pos(), value); }
592 template<
typename ModifyOp>
593 void modifyItem(
Index n,
const ModifyOp& op)
const { this->parent().modifyValue(n, op); }
595 template<
typename ModifyOp>
596 void modifyValue(
const ModifyOp& op)
const { this->modifyItem(this->pos(), op); }
600 template<
typename MaskIterT,
typename NodeT>
606 MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
609 template<
typename NodeT,
typename ValueT>
611 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, void, ValueT>
621 value = this->parent().getValue(pos);
630 void unsetItem(
Index pos,
const ValueT& val)
const {this->parent().setValueOnly(pos, val);}
635 using ValueOnCIter = ValueIter<MaskOnIter, const LeafNode, const bool>;
715 #if OPENVDB_ABI_VERSION_NUMBER >= 9 748 template<Index Log2Dim>
755 template<Index Log2Dim>
758 : mBuffer(value || active)
759 , mOrigin(xyz & (~(DIM - 1)))
764 template<Index Log2Dim>
767 : mBuffer(value || active)
768 , mOrigin(xyz & (~(DIM - 1)))
773 template<Index Log2Dim>
776 : mBuffer(other.mBuffer)
777 , mOrigin(other.mOrigin)
778 #if OPENVDB_ABI_VERSION_NUMBER >= 9
779 , mTransientData(other.mTransientData)
786 template<Index Log2Dim>
787 template<
typename ValueT>
792 #if OPENVDB_ABI_VERSION_NUMBER >= 9
793 , mTransientData(other.mTransientData)
799 template<Index Log2Dim>
800 template<
typename ValueT>
806 #if OPENVDB_ABI_VERSION_NUMBER >= 9
807 , mTransientData(other.mTransientData)
813 template<Index Log2Dim>
814 template<
typename ValueT>
819 #if OPENVDB_ABI_VERSION_NUMBER >= 9
820 , mTransientData(other.mTransientData)
826 template<Index Log2Dim>
827 template<
typename ValueT>
833 #if OPENVDB_ABI_VERSION_NUMBER >= 9
834 , mTransientData(other.mTransientData)
837 if (offValue==
true) {
838 if (onValue==
false) {
839 mBuffer.mData.toggle();
841 mBuffer.mData.setOn();
847 template<Index Log2Dim>
857 template<Index Log2Dim>
862 return sizeof(*this);
866 template<Index Log2Dim>
871 return sizeof(*this);
875 template<Index Log2Dim>
880 if (bbox.isInside(this_bbox))
return;
884 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
885 this_bbox.translate(this->
origin());
887 bbox.expand(this_bbox);
892 template<Index Log2Dim>
893 template<
typename OtherType, Index OtherLog2Dim>
898 return (Log2Dim == OtherLog2Dim && mBuffer.mData == other->
getValueMask());
902 template<Index Log2Dim>
906 std::ostringstream ostr;
907 ostr <<
"LeafNode @" << mOrigin <<
": ";
908 for (
Index32 n = 0; n <
SIZE; ++n) ostr << (mBuffer.mData.isOn(n) ?
'#' :
'.');
916 template<Index Log2Dim>
920 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
921 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
922 + ((xyz[1] & (DIM-1u)) << Log2Dim)
923 + (xyz[2] & (DIM-1u));
927 template<Index Log2Dim>
931 assert(n < (1 << 3*Log2Dim));
933 xyz.setX(n >> 2*Log2Dim);
934 n &= ((1 << 2*Log2Dim) - 1);
935 xyz.setY(n >> Log2Dim);
936 xyz.setZ(n & ((1 << Log2Dim) - 1));
941 template<Index Log2Dim>
952 template<Index Log2Dim>
956 mBuffer.mData.load(is);
960 template<Index Log2Dim>
964 mBuffer.mData.save(os);
968 template<Index Log2Dim>
978 bool background =
false;
980 background = *
static_cast<const bool*
>(bgPtr);
982 this->
clip(clipBBox, background);
986 template<Index Log2Dim>
991 mBuffer.mData.load(is);
993 is.read(reinterpret_cast<char*>(&mOrigin),
sizeof(Coord::ValueType) * 3);
997 template<Index Log2Dim>
1002 mBuffer.mData.save(os);
1004 os.write(reinterpret_cast<const char*>(&mOrigin),
sizeof(Coord::ValueType) * 3);
1011 template<Index Log2Dim>
1015 return mOrigin == other.mOrigin && mBuffer == other.mBuffer;
1019 template<Index Log2Dim>
1030 template<Index Log2Dim>
1034 if (!mBuffer.mData.isConstant(state))
return false;
1043 template<Index Log2Dim>
1047 const Index countTrue = mBuffer.mData.countOn();
1048 return countTrue > (NUM_VALUES >> 1);
1051 template<Index Log2Dim>
1055 const Index countTrueOn = mBuffer.mData.countOn();
1060 template<Index Log2Dim>
1064 const Index countFalseOff = mBuffer.mData.countOff();
1066 return countFalseOff;
1073 template<Index Log2Dim>
1080 template<Index Log2Dim>
1084 assert(offset < SIZE);
1089 template<Index Log2Dim>
1090 template<
typename AccessorT>
1093 bool val,
bool active, AccessorT&)
1095 this->
addTile(level, xyz, val, active);
1102 template<Index Log2Dim>
1107 if (mBuffer.mData.isOn(this->coordToOffset(xyz)))
return Buffer::sOn;
else return Buffer::sOff;
1111 template<Index Log2Dim>
1115 assert(offset < SIZE);
1117 if (mBuffer.mData.isOn(offset))
return Buffer::sOn;
else return Buffer::sOff;
1121 template<Index Log2Dim>
1126 val = mBuffer.mData.isOn(offset);
1131 template<Index Log2Dim>
1139 template<Index Log2Dim>
1143 assert(offset < SIZE);
1144 mBuffer.mData.set(offset, val);
1148 template<Index Log2Dim>
1156 template<Index Log2Dim>
1164 template<Index Log2Dim>
1172 template<Index Log2Dim>
1176 assert(offset < SIZE);
1177 mBuffer.mData.set(offset, val);
1181 template<Index Log2Dim>
1182 template<
typename ModifyOp>
1186 bool val = mBuffer.mData.isOn(offset);
1188 mBuffer.mData.set(offset, val);
1192 template<Index Log2Dim>
1193 template<
typename ModifyOp>
1201 template<Index Log2Dim>
1202 template<
typename ModifyOp>
1207 bool val = mBuffer.mData.isOn(offset), state = val;
1209 mBuffer.mData.set(offset, val);
1216 template<Index Log2Dim>
1217 template<MergePolicy Policy>
1223 mBuffer.mData |= other.mBuffer.mData;
1227 template<Index Log2Dim>
1228 template<MergePolicy Policy>
1234 if (tileValue) mBuffer.mData.setOn();
1242 template<Index Log2Dim>
1243 template<
typename OtherType>
1251 template<Index Log2Dim>
1252 template<
typename OtherType>
1261 template<Index Log2Dim>
1262 template<
typename OtherType>
1274 template<Index Log2Dim>
1279 if (!clipBBox.hasOverlap(nodeBBox)) {
1281 this->
fill(nodeBBox, background,
false);
1282 }
else if (clipBBox.isInside(nodeBBox)) {
1292 nodeBBox.intersect(clipBBox);
1294 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1295 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1296 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1297 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1314 template<Index Log2Dim>
1319 clippedBBox.intersect(bbox);
1320 if (!clippedBBox)
return;
1322 for (
Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1323 const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1324 for (
Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1325 const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1326 for (
Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1327 const Index offset = offsetXY + (z & (DIM-1u));
1328 mBuffer.mData.set(offset, value);
1334 template<Index Log2Dim>
1338 mBuffer.
fill(value);
1345 template<Index Log2Dim>
1346 template<
typename DenseT>
1350 using DenseValueType =
typename DenseT::ValueType;
1352 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1353 const Coord&
min = dense.bbox().min();
1354 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1355 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1356 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1357 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1359 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1360 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1362 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1363 *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1370 template<Index Log2Dim>
1371 template<
typename DenseT>
1374 bool background,
bool tolerance)
1376 using DenseValueType =
typename DenseT::ValueType;
1378 inline static bool toBool(
const DenseValueType& v) {
return !
math::isZero(v); }
1381 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1382 const Coord&
min = dense.bbox().min();
1383 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1384 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1385 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1386 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1388 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1389 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1391 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1393 if (tolerance || (background == Local::toBool(*s2))) {
1394 mBuffer.mData.set(n2, background);
1396 mBuffer.mData.set(n2, Local::toBool(*s2));
1407 template<Index Log2Dim>
1408 template<
typename CombineOp>
1414 bool result =
false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1419 .setResultRef(result));
1420 mBuffer.mData.set(i, result);
1425 template<Index Log2Dim>
1426 template<
typename CombineOp>
1431 args.
setBRef(value).setBIsActive(valueIsActive);
1433 bool result =
false, aVal = mBuffer.mData.isOn(i);
1436 .setResultRef(result));
1437 mBuffer.mData.set(i, result);
1445 template<Index Log2Dim>
1446 template<
typename CombineOp,
typename OtherType>
1449 bool valueIsActive, CombineOp& op)
1452 args.
setBRef(value).setBIsActive(valueIsActive);
1454 bool result =
false, aVal = other.mBuffer.mData.isOn(i);
1457 .setResultRef(result));
1458 mBuffer.mData.set(i, result);
1463 template<Index Log2Dim>
1464 template<
typename CombineOp,
typename OtherNodeT>
1467 bool valueIsActive, CombineOp& op)
1470 args.
setARef(value).setAIsActive(valueIsActive);
1472 bool result =
false, bVal = other.mBuffer.mData.isOn(i);
1475 .setResultRef(result));
1476 mBuffer.mData.set(i, result);
1481 template<Index Log2Dim>
1482 template<
typename CombineOp,
typename OtherNodeT>
1488 bool result =
false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1490 .setAIsActive(b0Val)
1492 .setBIsActive(b1Val)
1493 .setResultRef(result));
1494 mBuffer.mData.set(i, result);
1503 #endif // OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeMask.h:619
ChildAllIter beginChildAll()
Definition: LeafNodeMask.h:677
ValueIter()
Definition: LeafNodeMask.h:580
Index32 Index
Definition: Types.h:54
ChildAllCIter endChildAll() const
Definition: LeafNodeMask.h:686
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1431
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:513
void fill(const CoordBBox &bbox, const ValueType &, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNode.h:1173
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:29
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of the voxels that lie within a given bounding box.
Definition: LeafNode.h:1216
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeMask.h:640
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:356
ChildT * child
Definition: GridBuilder.h:1289
uint64_t Index64
Definition: Types.h:53
ValueOnCIter endValueOn() const
Definition: LeafNodeMask.h:658
void modifyValue(Index offset, const ModifyOp &op)
Apply a functor to the value of the voxel at the given offset and mark the voxel as active...
Definition: LeafNode.h:437
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition: LeafNode.h:1523
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1316
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeMask.h:653
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNodeMask.h:442
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:365
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:409
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:458
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
void stealNodes(ArrayT &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:521
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:184
void setValueMask(Index n, bool on)
Definition: LeafNodeMask.h:704
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:519
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNodeMask.h:243
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: LeafNode.h:1107
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeMask.h:335
LeafNode()
Default constructor.
Definition: LeafNode.h:906
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1732
void setValueMaskOn(Index n)
Definition: LeafNodeMask.h:705
ChildAllIter endChildAll()
Definition: LeafNodeMask.h:687
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1280
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1057
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:159
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:345
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNodeMask.h:108
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:511
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: LeafNode.h:1032
bool isValueMaskOn() const
Definition: LeafNodeMask.h:693
typename BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeMask.h:614
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.
Definition: LeafNode.h:1699
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:167
bool isValueMaskOff() const
Definition: LeafNodeMask.h:695
Definition: NodeMasks.h:270
bool isChildMaskOff() const
Definition: LeafNodeMask.h:702
typename NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeMask.h:568
void negate()
Invert the bits of the voxels, i.e. states and values.
Definition: LeafNodeMask.h:449
bool ValueType
Definition: LeafNodeMask.h:35
ChildOnCIter beginChildOn() const
Definition: LeafNodeMask.h:670
Definition: PointDataGrid.h:170
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeMask.h:593
ValueOffCIter cendValueOff() const
Definition: LeafNodeMask.h:660
bool isChildMaskOn(Index) const
Definition: LeafNodeMask.h:700
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeMask.h:672
bool isChildMaskOff(Index) const
Definition: LeafNodeMask.h:701
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:173
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeMask.h:644
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:280
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:419
const bool & getValue() const
Definition: LeafNodeMask.h:584
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:351
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNodeMask.h:114
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeMask.h:675
void denseFill(const CoordBBox &bbox, bool value, bool=false)
Set all voxels within an axis-aligned box to the specified value.
Definition: LeafNodeMask.h:294
void copyFromDense(const CoordBBox &bbox, const DenseT &dense, const ValueType &background, const ValueType &tolerance)
Copy from a dense grid into this node the values of the voxels that lie within a given bounding box...
Definition: LeafNode.h:1243
ChildAllCIter cendChildAll() const
Definition: LeafNodeMask.h:685
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:161
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNodeMask.h:118
ValueOnCIter beginValueOn() const
Definition: LeafNodeMask.h:648
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeMask.h:283
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1592
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeMask.h:645
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:196
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeMask.h:637
static const Index SIZE
Definition: LeafNode.h:53
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1022
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:258
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeMask.h:650
ValueAllCIter beginValueAll() const
Definition: LeafNodeMask.h:654
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeMask.h:617
ValueAllCIter endValueAll() const
Definition: LeafNodeMask.h:664
typename NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeMask.h:570
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:582
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:538
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNodeMask.h:110
ValueAllCIter cendValueAll() const
Definition: LeafNodeMask.h:663
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeMask.h:596
void setValueMaskOff(Index n)
Definition: LeafNodeMask.h:706
BBox< Coord > CoordBBox
Definition: NanoVDB.h:1809
int32_t Int32
Definition: Types.h:56
ValueOffCIter endValueOff() const
Definition: LeafNodeMask.h:661
void merge(const LeafNode &)
Definition: LeafNode.h:1642
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition: LeafNodeMask.h:638
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition: LeafNode.h:1479
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNodeMask.h:457
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1441
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeMask.h:639
ChildOffIter beginChildOff()
Definition: LeafNodeMask.h:674
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeMask.h:699
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:553
ValueOnIter beginValueOn()
Definition: LeafNodeMask.h:649
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeMask.h:709
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1461
ChildOnCIter endChildOn() const
Definition: LeafNodeMask.h:680
static const Index LOG2DIM
Definition: LeafNode.h:48
ValueOffIter beginValueOff()
Definition: LeafNodeMask.h:652
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition: LeafNodeMask.h:636
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:203
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeMask.h:714
void setValue(bool value) const
Definition: LeafNodeMask.h:589
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition: LeafNode.h:1115
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1414
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeMask.h:643
const NodeMaskType & valueMask() const
Definition: LeafNodeMask.h:697
bool isValueMaskOn(Index n) const
Definition: LeafNodeMask.h:692
void setTransientData(Index32 transientData)
Set the transient data value.
Definition: LeafNodeMask.h:176
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeMask.h:669
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.
Definition: LeafNode.h:1708
const LeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:548
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeMask.h:102
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition: LeafNode.h:1541
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNodeMask.h:104
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNodeMask.h:153
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeMask.h:408
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeMask.h:373
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:481
LeafNode specialization for values of type ValueMask that encodes both the active states and the bool...
Definition: LeafNodeMask.h:30
Definition: Exceptions.h:13
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeMask.h:286
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeMask.h:399
Buffer & buffer()
Definition: LeafNodeMask.h:198
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:233
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:337
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1288
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeMask.h:121
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1009
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:550
ValueT value
Definition: GridBuilder.h:1290
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNodeMask.h:278
ValueOffIter endValueOff()
Definition: LeafNodeMask.h:662
ChildOffCIter cendChildOff() const
Definition: LeafNodeMask.h:682
ChildOnCIter cendChildOn() const
Definition: LeafNodeMask.h:679
ValueOnCIter cendValueOn() const
Definition: LeafNodeMask.h:657
uint32_t Index32
Definition: Types.h:52
Index64 memUsageIfLoaded() const
Definition: LeafNode.h:1451
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeMask.h:534
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:160
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeMask.h:647
OffIterator beginOff() const
Definition: NodeMasks.h:354
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeMask.h:100
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:856
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:473
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeMask.h:132
ChildIter()
Definition: LeafNodeMask.h:604
Definition: NodeMasks.h:239
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1046
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeMask.h:630
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:517
ValueOnIter endValueOn()
Definition: LeafNodeMask.h:659
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:536
ValueOffCIter beginValueOff() const
Definition: LeafNodeMask.h:651
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNodeMask.h:140
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1487
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1609
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:391
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition: LeafNodeMask.h:634
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other, const bool preserveTiles=false)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition: LeafNode.h:1691
Definition: NodeMasks.h:208
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:533
ChildAllCIter beginChildAll() const
Definition: LeafNodeMask.h:676
ChildOffCIter endChildOff() const
Definition: LeafNodeMask.h:683
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:551
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
ChildOnIter beginChildOn()
Definition: LeafNodeMask.h:671
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1073
const bool & getItem(Index pos) const
Definition: LeafNodeMask.h:583
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNodeMask.h:112
static Index64 onTileCount()
Definition: LeafNodeMask.h:126
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNodeMask.h:276
const NodeMaskType & valueMask() const
Definition: LeafNode.h:858
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeMask.h:123
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:644
ChildOffCIter beginChildOff() const
Definition: LeafNodeMask.h:673
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeMask.h:531
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeMask.h:404
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition: LeafNodeMask.h:136
void resetBackground(bool, bool)
no-op since for this template specialization voxel values and states are indistinguishable.
Definition: LeafNodeMask.h:446
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeMask.h:130
static Index64 offTileCount()
Definition: LeafNodeMask.h:127
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeMask.h:635
Index64 onLeafVoxelCount() const
Definition: LeafNodeMask.h:124
void setItem(Index pos, bool value) const
Definition: LeafNodeMask.h:587
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeMask.h:581
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition: LeafNode.h:1565
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1133
const NodeMaskType & getValueMask() const
Definition: LeafNodeMask.h:696
Buffer mBuffer
Bitmask representing the values AND state of voxels.
Definition: LeafNodeMask.h:712
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeMask.h:642
ChildOffIter endChildOff()
Definition: LeafNodeMask.h:684
~LeafNode()
Destructor.
Definition: LeafNode.h:1002
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...
ChildOnIter endChildOn()
Definition: LeafNodeMask.h:681
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1772
SharedPtr< LeafNodeType > Ptr
Definition: LeafNodeMask.h:38
const Buffer & buffer() const
Definition: LeafNodeMask.h:197
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNodeMask.h:251
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeMask.h:340
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:584
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:555
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:529
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeMask.h:641
Index64 offLeafVoxelCount() const
Definition: LeafNodeMask.h:125
void nodeCount(std::vector< Index32 > &) const
no-op
Definition: LeafNodeMask.h:116
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:37
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeMask.h:605
ValueType combine(const ValueType &v0, const ValueType &v1, const ValueType &v2, const openvdb::Vec3d &w)
Combine different value types.
Definition: AttributeTransferUtil.h:141
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:156
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:114
NodeMaskType & getValueMask()
Definition: LeafNodeMask.h:698
typename NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeMask.h:569
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:382
DenseIter()
Definition: LeafNodeMask.h:616
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:178
Index32 transientData() const
Return the transient data value.
Definition: LeafNodeMask.h:174
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeMask.h:281
ValueAllIter endValueAll()
Definition: LeafNodeMask.h:665
ValueAllIter beginValueAll()
Definition: LeafNodeMask.h:655
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:515
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNodeMask.h:253
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:238
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:510
bool isValueMaskOff(Index n) const
Definition: LeafNodeMask.h:694
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNodeMask.h:241
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:650
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:520
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNodeMask.h:106
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeMask.h:228
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:452
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:299