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> 18 #include <type_traits> 30 template<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>
58 struct SameConfiguration {
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(); }
152 void evalActiveBoundingBox(CoordBBox& bbox,
bool visitVoxels =
true)
const;
159 void setOrigin(
const Coord& origin) { mOrigin = origin; }
162 const Coord&
origin()
const {
return mOrigin; }
163 void getOrigin(Coord& origin)
const { origin = mOrigin; }
168 static Index coordToOffset(
const Coord& xyz);
171 static Coord offsetToLocalCoord(
Index n);
173 Coord offsetToGlobalCoord(
Index n)
const;
181 std::string str()
const;
185 template<
typename OtherType, Index OtherLog2Dim>
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);
246 void setValueOff(
const Coord& xyz) { mBuffer.mData.setOff(this->coordToOffset(xyz)); }
251 void setValueOff(
const Coord& xyz,
bool val);
253 void setValueOff(
Index offset,
bool val);
256 void setValueOn(
const Coord& xyz) { mBuffer.mData.setOn(this->coordToOffset(xyz)); }
261 void setValueOn(
const Coord& xyz,
bool val);
263 void setValue(
const Coord& xyz,
bool val) { this->setValueOn(xyz, 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);
303 void denseFill(
const CoordBBox& bbox,
bool value,
bool =
false) { this->fill(bbox, value); }
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>
344 const bool&
getValueAndCache(
const Coord& xyz, AccessorT&)
const {
return this->getValue(xyz);}
348 template<
typename AccessorT>
353 template<
typename AccessorT>
354 void setValueAndCache(
const Coord& xyz,
bool val, AccessorT&) { this->setValueOn(xyz, val); }
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;
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>
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);}
667 using ValueOnCIter = ValueIter<MaskOnIter, const LeafNode, const bool>;
778 template<Index Log2Dim>
785 template<Index Log2Dim>
788 : mBuffer(value || active)
789 , mOrigin(xyz & (~(
DIM - 1)))
794 template<Index Log2Dim>
797 : mBuffer(value || active)
798 , mOrigin(xyz & (~(
DIM - 1)))
803 template<Index Log2Dim>
806 : mBuffer(other.mBuffer)
807 , mOrigin(other.mOrigin)
808 , mTransientData(other.mTransientData)
814 template<Index Log2Dim>
815 template<
typename ValueT>
820 , mTransientData(other.mTransientData)
825 template<Index Log2Dim>
826 template<
typename ValueT>
832 , mTransientData(other.mTransientData)
837 template<Index Log2Dim>
838 template<
typename ValueT>
843 , mTransientData(other.mTransientData)
848 template<Index Log2Dim>
849 template<
typename ValueT>
855 , mTransientData(other.mTransientData)
857 if (offValue==
true) {
858 if (onValue==
false) {
859 mBuffer.mData.toggle();
861 mBuffer.mData.setOn();
867 template<Index Log2Dim>
877 template<Index Log2Dim>
882 return sizeof(*this);
886 template<Index Log2Dim>
891 return sizeof(*this);
895 template<Index Log2Dim>
900 if (bbox.isInside(this_bbox))
return;
904 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
905 this_bbox.translate(this->
origin());
907 bbox.expand(this_bbox);
912 template<Index Log2Dim>
913 template<
typename OtherType, Index OtherLog2Dim>
918 return (Log2Dim == OtherLog2Dim && mBuffer.mData == other->
getValueMask());
922 template<Index Log2Dim>
926 std::ostringstream ostr;
927 ostr <<
"LeafNode @" << mOrigin <<
": ";
928 for (
Index32 n = 0; n <
SIZE; ++n) ostr << (mBuffer.mData.isOn(n) ?
'#' :
'.');
936 template<Index Log2Dim>
941 return ((xyz[0] & (
DIM-1u)) << 2*Log2Dim)
942 + ((xyz[1] & (
DIM-1u)) << Log2Dim)
943 + (xyz[2] & (
DIM-1u));
947 template<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));
961 template<Index Log2Dim>
972 template<Index Log2Dim>
976 mBuffer.mData.load(is);
980 template<Index Log2Dim>
984 mBuffer.mData.save(os);
988 template<Index Log2Dim>
998 bool background =
false;
1000 background = *
static_cast<const bool*
>(bgPtr);
1002 this->
clip(clipBBox, background);
1006 template<Index Log2Dim>
1011 mBuffer.mData.load(is);
1013 is.read(reinterpret_cast<char*>(&mOrigin),
sizeof(Coord::ValueType) * 3);
1017 template<Index Log2Dim>
1022 mBuffer.mData.save(os);
1024 os.write(reinterpret_cast<const char*>(&mOrigin),
sizeof(Coord::ValueType) * 3);
1031 template<Index Log2Dim>
1035 return mOrigin == other.mOrigin && mBuffer == other.mBuffer;
1039 template<Index Log2Dim>
1050 template<Index Log2Dim>
1054 if (!mBuffer.mData.isConstant(state))
return false;
1063 template<Index Log2Dim>
1067 const Index countTrue = mBuffer.mData.countOn();
1071 template<Index Log2Dim>
1075 const Index countTrueOn = mBuffer.mData.countOn();
1080 template<Index Log2Dim>
1084 const Index countFalseOff = mBuffer.mData.countOff();
1086 return countFalseOff;
1093 template<Index Log2Dim>
1100 template<Index Log2Dim>
1109 template<Index Log2Dim>
1110 template<
typename AccessorT>
1113 bool val,
bool active, AccessorT&)
1115 this->
addTile(level, xyz, val, active);
1122 template<Index Log2Dim>
1127 if (mBuffer.mData.isOn(this->coordToOffset(xyz)))
return Buffer::sOn;
else return Buffer::sOff;
1131 template<Index Log2Dim>
1137 if (mBuffer.mData.isOn(offset))
return Buffer::sOn;
else return Buffer::sOff;
1141 template<Index Log2Dim>
1149 template<Index Log2Dim>
1153 val = mBuffer.mData.isOn(offset);
1158 template<Index Log2Dim>
1166 template<Index Log2Dim>
1171 mBuffer.mData.set(offset, val);
1175 template<Index Log2Dim>
1183 template<Index Log2Dim>
1191 template<Index Log2Dim>
1199 template<Index Log2Dim>
1204 mBuffer.mData.set(offset, val);
1208 template<Index Log2Dim>
1209 template<
typename ModifyOp>
1213 bool val = mBuffer.mData.isOn(offset);
1215 mBuffer.mData.set(offset, val);
1219 template<Index Log2Dim>
1220 template<
typename ModifyOp>
1228 template<Index Log2Dim>
1229 template<
typename ModifyOp>
1234 bool val = mBuffer.mData.isOn(offset), state = val;
1236 mBuffer.mData.set(offset, val);
1243 template<Index Log2Dim>
1244 template<MergePolicy Policy>
1250 mBuffer.mData |= other.mBuffer.mData;
1254 template<Index Log2Dim>
1255 template<MergePolicy Policy>
1261 if (tileValue) mBuffer.mData.setOn();
1269 template<Index Log2Dim>
1270 template<
typename OtherType>
1278 template<Index Log2Dim>
1279 template<
typename OtherType>
1288 template<Index Log2Dim>
1289 template<
typename OtherType>
1301 template<Index Log2Dim>
1306 if (!clipBBox.hasOverlap(nodeBBox)) {
1308 this->
fill(nodeBBox, background,
false);
1309 }
else if (clipBBox.isInside(nodeBBox)) {
1319 nodeBBox.intersect(clipBBox);
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) {
1341 template<Index Log2Dim>
1346 clippedBBox.intersect(bbox);
1347 if (!clippedBBox)
return;
1349 for (
Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1350 const Index offsetX = (x & (
DIM-1u))<<2*Log2Dim;
1351 for (
Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1352 const Index offsetXY = offsetX + ((y & (
DIM-1u))<< Log2Dim);
1353 for (
Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1354 const Index offset = offsetXY + (z & (
DIM-1u));
1355 mBuffer.mData.set(offset, value);
1361 template<Index Log2Dim>
1365 mBuffer.
fill(value);
1372 template<Index Log2Dim>
1373 template<
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]);
1386 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1387 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1389 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1390 *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1397 template<Index Log2Dim>
1398 template<
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]);
1415 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1416 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1418 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1420 if (tolerance || (background == Local::toBool(*s2))) {
1421 mBuffer.mData.set(n2, background);
1423 mBuffer.mData.set(n2, Local::toBool(*s2));
1434 template<Index Log2Dim>
1435 template<
typename CombineOp>
1441 bool result =
false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1446 .setResultRef(result));
1447 mBuffer.mData.set(i, result);
1452 template<Index Log2Dim>
1453 template<
typename CombineOp>
1458 args.
setBRef(value).setBIsActive(valueIsActive);
1460 bool result =
false, aVal = mBuffer.mData.isOn(i);
1463 .setResultRef(result));
1464 mBuffer.mData.set(i, result);
1472 template<Index Log2Dim>
1473 template<
typename CombineOp,
typename OtherType>
1476 bool valueIsActive, CombineOp& op)
1479 args.
setBRef(value).setBIsActive(valueIsActive);
1481 bool result =
false, aVal = other.mBuffer.mData.isOn(i);
1484 .setResultRef(result));
1485 mBuffer.mData.set(i, result);
1490 template<Index Log2Dim>
1491 template<
typename CombineOp,
typename OtherNodeT>
1494 bool valueIsActive, CombineOp& op)
1497 args.
setARef(value).setAIsActive(valueIsActive);
1499 bool result =
false, bVal = other.mBuffer.mData.isOn(i);
1502 .setResultRef(result));
1503 mBuffer.mData.set(i, result);
1508 template<Index Log2Dim>
1509 template<
typename CombineOp,
typename OtherNodeT>
1515 bool result =
false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1517 .setAIsActive(b0Val)
1519 .setBIsActive(b1Val)
1520 .setResultRef(result));
1521 mBuffer.mData.set(i, result);
1530 #endif // OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeMask.h:673
Index64 offLeafVoxelCount() const
Definition: LeafNodeMask.h:128
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:38
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
void setValueMask(Index n, bool on)
Definition: LeafNodeMask.h:736
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:551
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition: LeafNode.h:1541
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNodeMask.h:248
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1334
NodeMaskType & getValueMask()
Definition: LeafNodeMask.h:730
typename NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeMask.h:601
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:300
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:459
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeMask.h:286
void setValue(bool value) const
Definition: LeafNodeMask.h:621
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:568
ValueAllIter endValueAll()
Definition: LeafNodeMask.h:697
ValueAllIter beginValueAll()
Definition: LeafNodeMask.h:687
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1449
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNodeMask.h:258
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:1234
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
LeafNode()
Default constructor.
Definition: LeafNode.h:932
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNodeMask.h:246
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNodeMask.h:107
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:543
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeMask.h:233
bool isValueMaskOn() const
Definition: LeafNodeMask.h:725
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1298
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
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeMask.h:662
bool isValueMaskOff() const
Definition: LeafNodeMask.h:727
bool isChildMaskOff() const
Definition: LeafNodeMask.h:734
typename NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeMask.h:600
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
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeMask.h:637
uint64_t Index64
Definition: Types.h:53
bool isChildMaskOn(Index) const
Definition: LeafNodeMask.h:732
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeMask.h:704
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:452
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:1718
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:410
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:170
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
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
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
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNodeMask.h:451
static const Index DIM
Definition: LeafNode.h:51
ChildAllCIter cendChildAll() const
Definition: LeafNodeMask.h:717
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1751
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1075
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:553
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:420
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeMask.h:677
Definition: NodeMasks.h:270
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
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeMask.h:682
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeMask.h:344
typename NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeMask.h:602
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
Definition: NodeMasks.h:239
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 setItem(Index pos, bool value) const
Definition: LeafNodeMask.h:619
void setValueMaskOn(Index n)
Definition: LeafNodeMask.h:737
ChildAllIter endChildAll()
Definition: LeafNodeMask.h:719
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeMask.h:613
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:570
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:162
static const Index SIZE
Definition: LeafNode.h:54
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
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNodeMask.h:109
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNodeMask.h:111
ValueAllCIter cendValueAll() const
Definition: LeafNodeMask.h:695
int32_t Int32
Definition: Types.h:56
Index32 Index
Definition: Types.h:54
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:176
static Index64 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNodeMask.h:121
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition: LeafNodeMask.h:670
void negate()
Invert the bits of the voxels, i.e. states and values.
Definition: LeafNodeMask.h:481
bool ValueType
Definition: LeafNodeMask.h:36
const bool & getItem(Index pos) const
Definition: LeafNodeMask.h:615
ChildOnCIter beginChildOn() const
Definition: LeafNodeMask.h:702
ChildOffIter beginChildOff()
Definition: LeafNodeMask.h:706
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeMask.h:731
ValueOffCIter cendValueOff() const
Definition: LeafNodeMask.h:692
bool isChildMaskOff(Index) const
Definition: LeafNodeMask.h:733
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeMask.h:741
ValueOffIter beginValueOff()
Definition: LeafNodeMask.h:684
static Index64 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNodeMask.h:115
void merge(const LeafNode &)
Definition: LeafNode.h:1661
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeMask.h:676
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition: LeafNodeMask.h:668
void setValueOffUnsafe(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNodeMask.h:472
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1610
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1040
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1459
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeMask.h:707
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
DenseIter()
Definition: LeafNodeMask.h:648
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:474
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeMask.h:675
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1479
static const Index LOG2DIM
Definition: LeafNode.h:49
bool isValueMaskOn(Index n) const
Definition: LeafNodeMask.h:724
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeMask.h:701
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:164
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeMask.h:103
ValueOnCIter beginValueOn() const
Definition: LeafNodeMask.h:680
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeMask.h:288
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:204
ChildIter()
Definition: LeafNodeMask.h:636
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeMask.h:669
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
ValueAllCIter beginValueAll() const
Definition: LeafNodeMask.h:686
ValueAllCIter endValueAll() const
Definition: LeafNodeMask.h:696
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:623
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
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNodeMask.h:105
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1432
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
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeMask.h:382
Definition: NodeMasks.h:208
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:621
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:1727
LeafNode specialization for values of type ValueMask that encodes both the active states and the bool...
Definition: LeafNodeMask.h:31
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:337
Buffer & buffer()
Definition: LeafNodeMask.h:199
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
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
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeMask.h:124
void setValueMaskOff(Index n)
Definition: LeafNodeMask.h:738
ValueOffCIter endValueOff() const
Definition: LeafNodeMask.h:693
ChildOnCIter cendChildOn() const
Definition: LeafNodeMask.h:711
ValueOnCIter cendValueOn() const
Definition: LeafNodeMask.h:689
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1306
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNodeMask.h:489
static const Index NUM_VALUES
Definition: LeafNode.h:52
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeMask.h:671
bool isValueOff(Index offset) const
Return true if the voxel at the given offset is inactive.
Definition: LeafNodeMask.h:292
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:585
ValueOnIter beginValueOn()
Definition: LeafNodeMask.h:681
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:163
ChildOnCIter endChildOn() const
Definition: LeafNodeMask.h:712
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeMask.h:101
Definition: Exceptions.h:13
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeMask.h:135
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeMask.h:746
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeMask.h:651
ValueIter()
Definition: LeafNodeMask.h:612
ValueOnIter endValueOn()
Definition: LeafNodeMask.h:691
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition: LeafNode.h:1559
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:568
const NodeMaskType & valueMask() const
Definition: LeafNodeMask.h:729
void setTransientData(Index32 transientData)
Set the transient data value.
Definition: LeafNodeMask.h:178
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNodeMask.h:143
const LeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:580
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
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition: LeafNodeMask.h:666
void setValueOnUnsafe(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNodeMask.h:468
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1027
typename BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeMask.h:646
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeMask.h:417
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
ChildAllCIter beginChildAll() const
Definition: LeafNodeMask.h:708
ChildOffCIter endChildOff() const
Definition: LeafNodeMask.h:715
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:583
ChildOnIter beginChildOn()
Definition: LeafNodeMask.h:703
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1627
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeMask.h:295
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeMask.h:408
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeMask.h:625
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNodeMask.h:281
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
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeMask.h:126
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:582
Index64 memUsageIfLoaded() const
Definition: LeafNode.h:1469
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
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNodeMask.h:283
ValueOffIter endValueOff()
Definition: LeafNodeMask.h:694
ChildOffCIter cendChildOff() const
Definition: LeafNodeMask.h:714
const bool & getValue() const
Definition: LeafNodeMask.h:616
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1091
OffIterator beginOff() const
Definition: NodeMasks.h:354
void resetBackground(bool, bool)
no-op since for this template specialization voxel values and states are indistinguishable.
Definition: LeafNodeMask.h:478
static Index64 offTileCount()
Definition: LeafNodeMask.h:130
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:884
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeMask.h:667
uint32_t Index32
Definition: Types.h:52
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeMask.h:566
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1064
Buffer mBuffer
Bitmask representing the values AND state of voxels.
Definition: LeafNodeMask.h:744
ChildOffIter endChildOff()
Definition: LeafNodeMask.h:716
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeMask.h:679
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 isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1505
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeMask.h:649
ChildOnIter endChildOn()
Definition: LeafNodeMask.h:713
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
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:549
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
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:184
bool isValueOff(const Coord &xyz) const
Return true if the voxel at the given coordinates is inactive.
Definition: LeafNodeMask.h:290
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeMask.h:349
ValueOffCIter beginValueOff() const
Definition: LeafNodeMask.h:683
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:587
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeMask.h:628
const NodeMaskType & valueMask() const
Definition: LeafNode.h:886
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNodeMask.h:159
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:565
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
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNodeMask.h:113
Index32 transientData() const
Return the transient data value.
Definition: LeafNodeMask.h:176
static Index64 onTileCount()
Definition: LeafNodeMask.h:129
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:683
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:547
ChildOffCIter beginChildOff() const
Definition: LeafNodeMask.h:705
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition: LeafNode.h:1583
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeMask.h:563
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:542
bool isValueMaskOff(Index n) const
Definition: LeafNodeMask.h:726
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeMask.h:413
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:552
~LeafNode()
Destructor.
Definition: LeafNode.h:1020
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition: LeafNodeMask.h:139
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeMask.h:133
Index64 onLeafVoxelCount() const
Definition: LeafNodeMask.h:127
ChildAllIter beginChildAll()
Definition: LeafNodeMask.h:709
ChildAllCIter endChildAll() const
Definition: LeafNodeMask.h:718
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:545
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1791
ValueType combine(const ValueType &v0, const ValueType &v1, const ValueType &v2, const openvdb::Vec3d &w)
Combine different value types.
Definition: AttributeTransferUtil.h:141
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeMask.h:672
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
const NodeMaskType & getValueMask() const
Definition: LeafNodeMask.h:728
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeMask.h:674
Definition: PointDataGrid.h:171
ValueOnCIter endValueOn() const
Definition: LeafNodeMask.h:690
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:178
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:275
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
void nodeCount(std::vector< Index64 > &) const
no-op
Definition: LeafNodeMask.h:117
SharedPtr< LeafNodeType > Ptr
Definition: LeafNodeMask.h:39
const Buffer & buffer() const
Definition: LeafNodeMask.h:198
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNodeMask.h:256
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:482
const bool & getValueUnsafe(Index offset) const
Return the value of the voxel at the given offset.
Definition: LeafNodeMask.h:460
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:114
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeMask.h:685
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:689
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