8#ifndef OPENVDB_TREE_INTERNALNODE_HAS_BEEN_INCLUDED
9#define OPENVDB_TREE_INTERNALNODE_HAS_BEEN_INCLUDED
15#include <openvdb/version.h>
19#include <tbb/parallel_for.h>
29template<
typename, Index,
typename>
struct SameInternalConfig;
32template<
typename _ChildNodeType, Index Log2Dim>
38 using ValueType =
typename ChildNodeType::ValueType;
39 using BuildType =
typename ChildNodeType::BuildType;
45 TOTAL = Log2Dim + ChildNodeType::TOTAL,
48 LEVEL = 1 + ChildNodeType::LEVEL;
54 template<
typename OtherValueType>
57 OtherValueType>
::Type, Log2Dim>;
63 template<
typename OtherNodeType>
94 template<
typename OtherChildNodeType>
100 template<
typename OtherChildNodeType>
107 template<
typename OtherChildNodeType>
126 template<
typename NodeT,
typename ChildT,
typename MaskIterT,
typename TagT>
128 MaskIterT, ChildIter<NodeT, ChildT, MaskIterT, TagT>, NodeT, ChildT>
137 return *(this->
parent().getChildNode(
pos));
147 template<
typename NodeT,
typename ValueT,
typename MaskIterT,
typename TagT>
149 MaskIterT, ValueIter<NodeT, ValueT, MaskIterT, TagT>, NodeT, ValueT>
161 template<
typename ModifyOp>
169 template<
typename NodeT,
typename ChildT,
typename ValueT,
typename TagT>
171 MaskDenseIterator, DenseIter<NodeT, ChildT, ValueT, TagT>, NodeT, ChildT, ValueT>
206 using ChildOnIter = ChildIter<InternalNode, ChildNodeType, MaskOnIterator, ChildOn>;
207 using ChildOnCIter = ChildIter<const InternalNode,const ChildNodeType,MaskOnIterator,ChildOn>;
208 using ChildOffIter = ValueIter<InternalNode, const ValueType, MaskOffIterator, ChildOff>;
209 using ChildOffCIter = ValueIter<const InternalNode,const ValueType,MaskOffIterator,ChildOff>;
210 using ChildAllIter = DenseIter<InternalNode, ChildNodeType, ValueType, ChildAll>;
211 using ChildAllCIter = DenseIter<const InternalNode,const ChildNodeType, ValueType, ChildAll>;
213 using ValueOnIter = ValueIter<InternalNode, const ValueType, MaskOnIterator, ValueOn>;
214 using ValueOnCIter = ValueIter<const InternalNode, const ValueType, MaskOnIterator, ValueOn>;
215 using ValueOffIter = ValueIter<InternalNode, const ValueType, MaskOffIterator, ValueOff>;
216 using ValueOffCIter = ValueIter<const InternalNode,const ValueType,MaskOffIterator,ValueOff>;
217 using ValueAllIter = ValueIter<InternalNode, const ValueType, MaskOffIterator, ValueAll>;
218 using ValueAllCIter = ValueIter<const InternalNode,const ValueType,MaskOffIterator,ValueAll>;
271#if OPENVDB_ABI_VERSION_NUMBER >= 9
369 template<
typename ModifyOp>
372 template<
typename ModifyOp>
379 template<
typename AccessorT>
386 template<
typename AccessorT>
393 template<
typename AccessorT>
400 template<
typename AccessorT>
408 template<
typename ModifyOp,
typename AccessorT>
415 template<
typename ModifyOp,
typename AccessorT>
422 template<
typename AccessorT>
429 template<
typename AccessorT>
437 template<
typename AccessorT>
446 template<
typename AccessorT>
500 template<
typename DenseT>
505 template<MergePolicy Policy>
510 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive);
524 template<
typename OtherChildNodeType>
540 template<
typename OtherChildNodeType>
555 template<
typename OtherChildNodeType>
559 template<
typename CombineOp>
561 template<
typename CombineOp>
564 template<
typename CombineOp,
typename OtherNodeType >
566 template<
typename CombineOp,
typename OtherNodeType >
568 template<
typename CombineOp,
typename OtherValueType>
585 template<
typename AccessorT>
596 template<
typename NodeT>
616 template<
typename AccessorT>
629 template<
typename NodeType,
typename AccessorT>
631 template<
typename NodeType,
typename AccessorT>
646 template<
typename AccessorT>
648 template<
typename AccessorT>
650 template<
typename AccessorT>
664 template<
typename AccessorT>
690 template<
typename ArrayT>
692 template<
typename ArrayT>
719 template<
typename ArrayT>
728 template<
typename OtherChildNodeType, Index OtherLog2Dim>
785 struct VoxelizeActiveTiles;
786 template<
typename OtherInternalNode>
struct DeepCopy;
787 template<
typename OtherInternalNode>
struct TopologyCopy1;
788 template<
typename OtherInternalNode>
struct TopologyCopy2;
789 template<
typename OtherInternalNode>
struct TopologyUnion;
790 template<
typename OtherInternalNode>
struct TopologyDifference;
791 template<
typename OtherInternalNode>
struct TopologyIntersection;
798#if OPENVDB_ABI_VERSION_NUMBER >= 9
811template<
typename ChildT1, Index Dim1,
typename NodeT2>
816template<
typename ChildT1, Index Dim1,
typename ChildT2>
818 static const bool value = ChildT1::template SameConfiguration<ChildT2>::value;
826template<
typename ChildT, Index Log2Dim>
834template<
typename ChildT, Index Log2Dim>
848template<
typename ChildT, Index Log2Dim>
858template<
typename ChildT, Index Log2Dim>
859template<
typename OtherInternalNode>
863 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
867 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
868 if (
s->mChildMask.isOff(i)) {
869 t->mNodes[i].setValue(
ValueType(
s->mNodes[i].getValue()));
875 const OtherInternalNode*
s;
879template<
typename ChildT, Index Log2Dim>
885#if OPENVDB_ABI_VERSION_NUMBER >= 9
894template<
typename ChildT, Index Log2Dim>
895template<
typename OtherChildNodeType>
901#if OPENVDB_ABI_VERSION_NUMBER >= 9
908template<
typename ChildT, Index Log2Dim>
909template<
typename OtherInternalNode>
913 const ValueType& background) :
s(source),
t(target),
b(background) {
914 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
918 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
919 if (
s->isChildMaskOn(i)) {
923 t->mNodes[i].setValue(
b);
927 const OtherInternalNode*
s;
932template<
typename ChildT, Index Log2Dim>
933template<
typename OtherChildNodeType>
940#if OPENVDB_ABI_VERSION_NUMBER >= 9
947template<
typename ChildT, Index Log2Dim>
948template<
typename OtherInternalNode>
953 :
s(source),
t(target),
offV(offValue),
onV(onValue) {
954 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
957 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
958 if (
s->isChildMaskOn(i)) {
962 t->mNodes[i].setValue(
s->isValueMaskOn(i) ?
onV :
offV);
966 const OtherInternalNode*
s;
971template<
typename ChildT, Index Log2Dim>
972template<
typename OtherChildNodeType>
980#if OPENVDB_ABI_VERSION_NUMBER >= 9
988template<
typename ChildT, Index Log2Dim>
1001template<
typename ChildT, Index Log2Dim>
1005 if (ChildNodeType::getLevel() == 0)
return mChildMask.countOn();
1008 sum +=
iter->leafCount();
1013template<
typename ChildT, Index Log2Dim>
1017 assert(vec.size() > ChildNodeType::LEVEL);
1019 if (ChildNodeType::LEVEL > 0 && count > 0) {
1022 vec[ChildNodeType::LEVEL] += count;
1026template<
typename ChildT, Index Log2Dim>
1031 if (ChildNodeType::getLevel() == 0)
return sum;
1033 sum +=
iter->nonLeafCount();
1039template<
typename ChildT, Index Log2Dim>
1047template<
typename ChildT, Index Log2Dim>
1053 sum +=
iter->onVoxelCount();
1059template<
typename ChildT, Index Log2Dim>
1065 sum +=
iter->offVoxelCount();
1071template<
typename ChildT, Index Log2Dim>
1077 sum +=
mNodes[
iter.pos()].getChild()->onLeafVoxelCount();
1083template<
typename ChildT, Index Log2Dim>
1089 sum +=
mNodes[
iter.pos()].getChild()->offLeafVoxelCount();
1094template<
typename ChildT, Index Log2Dim>
1100 sum +=
iter->onTileCount();
1105template<
typename ChildT, Index Log2Dim>
1112 sum +=
iter->memUsage();
1118template<
typename ChildT, Index Log2Dim>
1122 if (bbox.
isInside(this->getNodeBoundingBox()))
return;
1125 bbox.
expand(i.getCoord(), ChildT::DIM);
1128 i->evalActiveBoundingBox(bbox, visitVoxels);
1136template<
typename ChildT, Index Log2Dim>
1145 child->prune(tolerance);
1146 if (
child->isConstant(
value, state, tolerance)) {
1159template<
typename ChildT, Index Log2Dim>
1160template<
typename NodeT>
1164 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1165 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1170 if (std::is_same<NodeT, ChildT>::value) {
1175 return (std::is_same<NodeT, ChildT>::value)
1176 ?
reinterpret_cast<NodeT*
>(
child)
1185template<
typename ChildT, Index Log2Dim>
1186template<
typename NodeT>
1190 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1191 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1196 return (std::is_same<NodeT, ChildT>::value)
1197 ?
reinterpret_cast<NodeT*
>(
child)
1203template<
typename ChildT, Index Log2Dim>
1204template<
typename NodeT,
typename AccessorT>
1208 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1209 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1214 acc.insert(xyz,
child);
1215 return (std::is_same<NodeT, ChildT>::value)
1216 ?
reinterpret_cast<NodeT*
>(
child)
1222template<
typename ChildT, Index Log2Dim>
1223template<
typename NodeT>
1227 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1228 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1233 return (std::is_same<NodeT, ChildT>::value)
1234 ?
reinterpret_cast<const NodeT*
>(
child)
1240template<
typename ChildT, Index Log2Dim>
1241template<
typename NodeT,
typename AccessorT>
1245 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1246 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1251 acc.insert(xyz,
child);
1252 return (std::is_same<NodeT, ChildT>::value)
1253 ?
reinterpret_cast<const NodeT*
>(
child)
1262template<
typename ChildT, Index Log2Dim>
1263inline typename ChildT::LeafNodeType*
1270template<
typename ChildT, Index Log2Dim>
1271template<
typename AccessorT>
1272inline typename ChildT::LeafNodeType*
1279template<
typename ChildT, Index Log2Dim>
1280template<
typename AccessorT>
1281inline const typename ChildT::LeafNodeType*
1288template<
typename ChildT, Index Log2Dim>
1289inline const typename ChildT::LeafNodeType*
1296template<
typename ChildT, Index Log2Dim>
1297template<
typename AccessorT>
1298inline const typename ChildT::LeafNodeType*
1308template<
typename ChildT, Index Log2Dim>
1312 assert(leaf !=
nullptr);
1313 const Coord& xyz = leaf->origin();
1315 ChildT*
child =
nullptr;
1317 if (ChildT::LEVEL>0) {
1320 child =
reinterpret_cast<ChildT*
>(leaf);
1324 if (ChildT::LEVEL>0) {
1327 delete mNodes[n].getChild();
1328 child =
reinterpret_cast<ChildT*
>(leaf);
1332 child->addLeaf(leaf);
1336template<
typename ChildT, Index Log2Dim>
1337template<
typename AccessorT>
1341 assert(leaf !=
nullptr);
1342 const Coord& xyz = leaf->origin();
1344 ChildT*
child =
nullptr;
1346 if (ChildT::LEVEL>0) {
1348 acc.insert(xyz,
child);
1350 child =
reinterpret_cast<ChildT*
>(leaf);
1354 if (ChildT::LEVEL>0) {
1356 acc.insert(xyz,
child);
1358 delete mNodes[n].getChild();
1359 child =
reinterpret_cast<ChildT*
>(leaf);
1363 child->addLeafAndCache(leaf, acc);
1370template<
typename ChildT, Index Log2Dim>
1386template<
typename ChildT, Index Log2Dim>
1396template<
typename ChildT, Index Log2Dim>
1401 if (
LEVEL >= level) {
1404 if (
LEVEL > level) {
1414 if (
LEVEL > level) {
1427template<
typename ChildT, Index Log2Dim>
1428template<
typename AccessorT>
1433 if (
LEVEL >= level) {
1436 if (
LEVEL > level) {
1439 acc.insert(xyz,
child);
1440 child->addTileAndCache(level, xyz,
value, state, acc);
1447 if (
LEVEL > level) {
1448 acc.insert(xyz,
child);
1449 child->addTileAndCache(level, xyz,
value, state, acc);
1464template<
typename ChildT, Index Log2Dim>
1465inline typename ChildT::LeafNodeType*
1469 ChildT*
child =
nullptr;
1476 return child->touchLeaf(xyz);
1480template<
typename ChildT, Index Log2Dim>
1481template<
typename AccessorT>
1482inline typename ChildT::LeafNodeType*
1489 acc.insert(xyz,
mNodes[n].getChild());
1490 return mNodes[n].getChild()->touchLeafAndCache(xyz, acc);
1497template<
typename ChildT, Index Log2Dim>
1504 firstValue =
mNodes[0].getValue();
1517template<
typename ChildT, Index Log2Dim>
1526 minValue = maxValue =
mNodes[0].getValue();
1530 if ((maxValue - v) > tolerance)
return false;
1532 }
else if (v > maxValue) {
1533 if ((v - minValue) > tolerance)
return false;
1544template<
typename ChildT, Index Log2Dim>
1549 const bool anyActiveTiles = !
mValueMask.isOff();
1550 if (
LEVEL==1 || anyActiveTiles)
return anyActiveTiles;
1552 if (
iter->hasActiveTiles())
return true;
1559template<
typename ChildT, Index Log2Dim>
1565 return mNodes[n].getChild()->isValueOn(xyz);
1568template<
typename ChildT, Index Log2Dim>
1569template<
typename AccessorT>
1575 acc.insert(xyz,
mNodes[n].getChild());
1576 return mNodes[n].getChild()->isValueOnAndCache(xyz, acc);
1580template<
typename ChildT, Index Log2Dim>
1581inline const typename ChildT::ValueType&
1586 :
mNodes[n].getChild()->getValue(xyz);
1589template<
typename ChildT, Index Log2Dim>
1590template<
typename AccessorT>
1591inline const typename ChildT::ValueType&
1596 acc.insert(xyz,
mNodes[n].getChild());
1597 return mNodes[n].getChild()->getValueAndCache(xyz, acc);
1599 return mNodes[n].getValue();
1603template<
typename ChildT, Index Log2Dim>
1611template<
typename ChildT, Index Log2Dim>
1612template<
typename AccessorT>
1618 acc.insert(xyz,
mNodes[n].getChild());
1619 return mNodes[n].getChild()->getValueLevelAndCache(xyz, acc);
1625template<
typename ChildT, Index Log2Dim>
1634 return mNodes[n].getChild()->probeValue(xyz,
value);
1637template<
typename ChildT, Index Log2Dim>
1638template<
typename AccessorT>
1645 acc.insert(xyz,
mNodes[n].getChild());
1646 return mNodes[n].getChild()->probeValueAndCache(xyz,
value, acc);
1653template<
typename ChildT, Index Log2Dim>
1665 if (hasChild)
mNodes[n].getChild()->setValueOff(xyz);
1669template<
typename ChildT, Index Log2Dim>
1681 if (hasChild)
mNodes[n].getChild()->setValueOn(xyz);
1685template<
typename ChildT, Index Log2Dim>
1701 if (hasChild)
mNodes[n].getChild()->setValueOff(xyz,
value);
1704template<
typename ChildT, Index Log2Dim>
1705template<
typename AccessorT>
1724 acc.insert(xyz,
child);
1730template<
typename ChildT, Index Log2Dim>
1746 if (hasChild)
mNodes[n].getChild()->setValueOn(xyz,
value);
1749template<
typename ChildT, Index Log2Dim>
1750template<
typename AccessorT>
1768 acc.insert(xyz,
mNodes[n].getChild());
1769 mNodes[n].getChild()->setValueAndCache(xyz,
value, acc);
1774template<
typename ChildT, Index Log2Dim>
1787 if (hasChild)
mNodes[n].getChild()->setValueOnly(xyz,
value);
1790template<
typename ChildT, Index Log2Dim>
1791template<
typename AccessorT>
1806 acc.insert(xyz,
mNodes[n].getChild());
1807 mNodes[n].getChild()->setValueOnlyAndCache(xyz,
value, acc);
1812template<
typename ChildT, Index Log2Dim>
1827 if (hasChild)
mNodes[n].getChild()->setActiveState(xyz, on);
1830template<
typename ChildT, Index Log2Dim>
1831template<
typename AccessorT>
1848 acc.insert(xyz,
child);
1849 child->setActiveStateAndCache(xyz, on, acc);
1854template<
typename ChildT, Index Log2Dim>
1860 mNodes[
iter.pos()].getChild()->setValuesOn();
1865template<
typename ChildT, Index Log2Dim>
1866template<
typename ModifyOp>
1876 bool createChild = !active;
1890 if (hasChild)
mNodes[n].getChild()->modifyValue(xyz, op);
1893template<
typename ChildT, Index Log2Dim>
1894template<
typename ModifyOp,
typename AccessorT>
1905 bool createChild = !active;
1921 acc.insert(xyz,
child);
1922 child->modifyValueAndCache(xyz, op, acc);
1927template<
typename ChildT, Index Log2Dim>
1928template<
typename ModifyOp>
1937 bool modifiedState = !tileState;
1939 op(modifiedVal, modifiedState);
1947 if (hasChild)
mNodes[n].getChild()->modifyValueAndActiveState(xyz, op);
1950template<
typename ChildT, Index Log2Dim>
1951template<
typename ModifyOp,
typename AccessorT>
1954 const Coord& xyz,
const ModifyOp& op, AccessorT& acc)
1961 bool modifiedState = !tileState;
1963 op(modifiedVal, modifiedState);
1973 acc.insert(xyz,
child);
1974 child->modifyValueAndActiveStateAndCache(xyz, op, acc);
1982template<
typename ChildT, Index Log2Dim>
1989 this->
fill(nodeBBox, background,
false);
1990 }
else if (clipBBox.
isInside(nodeBBox)) {
2007 }
else if (!clipBBox.
isInside(tileBBox)) {
2011 mNodes[pos].getChild()->clip(clipBBox, background);
2018 mNodes[pos].setValue(background);
2020 this->
fill(tileBBox, val, on);
2032template<
typename ChildT, Index Log2Dim>
2037 clippedBBox.intersect(bbox);
2038 if (!clippedBBox)
return;
2042 Coord xyz, tileMin, tileMax;
2043 for (
int x = clippedBBox.min().x(); x <= clippedBBox.max().x(); x = tileMax.
x() + 1) {
2045 for (
int y = clippedBBox.min().y(); y <= clippedBBox.max().y(); y = tileMax.
y() + 1) {
2047 for (
int z = clippedBBox.min().z(); z <= clippedBBox.max().z(); z = tileMax.
z() + 1) {
2053 tileMax = tileMin.
offsetBy(ChildT::DIM - 1);
2059 ChildT*
child =
nullptr;
2088template<
typename ChildT, Index Log2Dim>
2093 clippedBBox.intersect(bbox);
2094 if (!clippedBBox)
return;
2098 Coord xyz, tileMin, tileMax;
2099 for (
int x = clippedBBox.min().x(); x <= clippedBBox.max().x(); x = tileMax.
x() + 1) {
2101 for (
int y = clippedBBox.min().y(); y <= clippedBBox.max().y(); y = tileMax.
y() + 1) {
2103 for (
int z = clippedBBox.min().z(); z <= clippedBBox.max().z(); z = tileMax.
z() + 1) {
2110 ChildT*
child =
nullptr;
2122 tileMax = tileMin.
offsetBy(ChildT::DIM - 1);
2135template<
typename ChildT, Index Log2Dim>
2136template<
typename DenseT>
2140 using DenseValueType =
typename DenseT::ValueType;
2142 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
2143 const Coord& min = dense.bbox().min();
2144 for (
Coord xyz = bbox.
min(), max; xyz[0] <= bbox.
max()[0]; xyz[0] = max[0] + 1) {
2145 for (xyz[1] = bbox.
min()[1]; xyz[1] <= bbox.
max()[1]; xyz[1] = max[1] + 1) {
2146 for (xyz[2] = bbox.
min()[2]; xyz[2] <= bbox.
max()[2]; xyz[2] = max[2] + 1) {
2155 mNodes[n].getChild()->copyToDense(sub, dense);
2159 DenseValueType* a0 = dense.data() + zStride*sub.
min()[2];
2160 for (
Int32 x=sub.
min()[0], ex=sub.
max()[0]+1; x<ex; ++x) {
2161 DenseValueType* a1 = a0 + x*xStride;
2162 for (
Int32 y=sub.
min()[1], ey=sub.
max()[1]+1; y<ey; ++y) {
2163 DenseValueType* a2 = a1 + y*yStride;
2165 z < ez; ++z, a2 += zStride)
2167 *a2 = DenseValueType(
value);
2181template<
typename ChildT, Index Log2Dim>
2201 iter->writeTopology(os, toHalf);
2206template<
typename ChildT, Index Log2Dim>
2222 child->readTopology(is);
2230 const bool oldVersion =
2236 std::unique_ptr<ValueType[]> valuePtr(
new ValueType[numValues]);
2246 assert(n == numValues);
2257 child->readTopology(is, fromHalf);
2266template<
typename ChildT, Index Log2Dim>
2267inline const typename ChildT::ValueType&
2274template<
typename ChildT, Index Log2Dim>
2275inline const typename ChildT::ValueType&
2286template<
typename ChildT, Index Log2Dim>
2292 mNodes[i].getChild()->negate();
2304template<
typename ChildT, Index Log2Dim>
2309 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2316 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2317 if (
mNode->mChildMask.isOn(i)) {
2318 mNode->mNodes[i].getChild()->voxelizeActiveTiles(
true);
2319 }
else if (
mNode->mValueMask.isOn(i)) {
2320 const Coord &ijk =
mNode->offsetToGlobalCoord(i);
2322 child->voxelizeActiveTiles(
true);
2330template<
typename ChildT, Index Log2Dim>
2342 iter->voxelizeActiveTiles(
false);
2350template<
typename ChildT, Index Log2Dim>
2351template<MergePolicy Policy>
2368 background, otherBackground);
2376 child->resetBackground(otherBackground, background);
2407 child->resetBackground(otherBackground, background);
2428 child->resetBackground(otherBackground, background);
2459template<
typename ChildT, Index Log2Dim>
2460template<MergePolicy Policy>
2469 if (!tileActive)
return;
2479 iter.setValue(tileValue);
2490template<
typename ChildT, Index Log2Dim>
2491template<
typename OtherInternalNode>
2496 { tV = (tV | sV) & ~tC; }
2501 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2505 else t->mChildMask |= (
s->mChildMask & !
t->mValueMask);
2508 t->mValueMask.foreach(
s->mValueMask,
t->mChildMask, op);
2509 assert((
t->mValueMask &
t->mChildMask).isOff());
2512 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2513 if (
s->mChildMask.isOn(i)) {
2514 const typename OtherInternalNode::ChildNodeType& other = *(
s->mNodes[i].getChild());
2515 if (
t->mChildMask.isOn(i)) {
2520 if (
t->mValueMask.isOn(i))
child->setValuesOn();
2521 t->mNodes[i].setChild(
child);
2524 }
else if (
s->mValueMask.isOn(i) &&
t->mChildMask.isOn(i)) {
2525 t->mNodes[i].getChild()->setValuesOn();
2529 const OtherInternalNode*
s;
2534template<
typename ChildT, Index Log2Dim>
2535template<
typename OtherChildT>
2539 TopologyUnion<InternalNode<OtherChildT, Log2Dim> > tmp(&other,
this, preserveTiles);
2542template<
typename ChildT, Index Log2Dim>
2543template<
typename OtherInternalNode>
2548 { tC = (tC & (sC | sV)) | (tV & sC); }
2551 const ValueType& background) :
s(source),
t(target),
b(background) {
2553 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2557 t->mChildMask.foreach(
s->mChildMask,
s->mValueMask,
t->mValueMask, op);
2559 t->mValueMask &=
s->mValueMask;
2560 assert((
t->mValueMask &
t->mChildMask).isOff());
2563 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2564 if (
t->mChildMask.isOn(i)) {
2565 ChildT*
child =
t->mNodes[i].getChild();
2566 if (
s->mChildMask.isOn(i)) {
2567 child->topologyIntersection(*(
s->mNodes[i].getChild()),
b);
2568 }
else if (
s->mValueMask.isOff(i)) {
2570 t->mNodes[i].setValue(
b);
2572 }
else if (
t->mValueMask.isOn(i) &&
s->mChildMask.isOn(i)) {
2573 t->mNodes[i].setChild(
new ChildT(*(
s->mNodes[i].getChild()),
2578 const OtherInternalNode*
s;
2583template<
typename ChildT, Index Log2Dim>
2584template<
typename OtherChildT>
2589 TopologyIntersection<InternalNode<OtherChildT, Log2Dim> > tmp(&other,
this, background);
2592template<
typename ChildT, Index Log2Dim>
2593template<
typename OtherInternalNode>
2598 { tC = (tC & (sC | ~sV)) | (tV & sC); }
2601 { tV &= ~((tC & sV) | (sC | sV)); }
2604 const ValueType& background) :
s(source),
t(target),
b(background) {
2606 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2611 t->mChildMask.foreach(
s->mChildMask,
s->mValueMask,
t->mValueMask, op1);
2614 t->mValueMask.foreach(
t->mChildMask,
s->mValueMask, oldChildMask, op2);
2615 assert((
t->mValueMask &
t->mChildMask).isOff());
2618 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2619 if (
t->mChildMask.isOn(i)) {
2620 ChildT*
child =
t->mNodes[i].getChild();
2621 if (
s->mChildMask.isOn(i)) {
2622 child->topologyDifference(*(
s->mNodes[i].getChild()),
b);
2623 }
else if (
s->mValueMask.isOn(i)) {
2625 t->mNodes[i].setValue(
b);
2627 }
else if (
t->mValueMask.isOn(i)) {
2628 if (
s->mChildMask.isOn(i)) {
2629 const typename OtherInternalNode::ChildNodeType& other =
2630 *(
s->mNodes[i].getChild());
2631 ChildT*
child =
new ChildT(other.origin(),
t->mNodes[i].getValue(),
true);
2632 child->topologyDifference(other,
b);
2633 t->mNodes[i].setChild(
child);
2638 const OtherInternalNode*
s;
2643template<
typename ChildT, Index Log2Dim>
2644template<
typename OtherChildT>
2649 TopologyDifference<InternalNode<OtherChildT, Log2Dim> > tmp(&other,
this, background);
2656template<
typename ChildT, Index Log2Dim>
2657template<
typename CombineOp>
2706 if (
child && otherChild) {
2707 child->combine(*otherChild, op);
2714template<
typename ChildT, Index Log2Dim>
2715template<
typename CombineOp>
2727 .setBIsActive(valueIsActive));
2743template<
typename ChildT, Index Log2Dim>
2744template<
typename CombineOp,
typename OtherNodeType>
2755 .
setBRef(other1.mNodes[i].getValue())
2765 : other1.mNodes[i].getChild()->origin();
2774 }
else if (other1.isChildMaskOff(i)) {
2778 other1.mNodes[i].getValue(), other1.isValueMaskOn(i), op);
2783 *other1.mNodes[i].getChild(), op);
2790template<
typename ChildT, Index Log2Dim>
2791template<
typename CombineOp,
typename OtherNodeType>
2794 bool valueIsActive, CombineOp& op)
2799 if (other.isChildMaskOff(i)) {
2802 .
setBRef(other.mNodes[i].getValue())
2808 typename OtherNodeType::ChildNodeType* otherChild = other.mNodes[i].getChild();
2817 mNodes[i].getChild()->combine2(
value, *otherChild, valueIsActive, op);
2823template<
typename ChildT, Index Log2Dim>
2824template<
typename CombineOp,
typename OtherValueType>
2827 bool valueIsActive, CombineOp& op)
2850 mNodes[i].getChild()->combine2(*otherChild,
value, valueIsActive, op);
2859template<
typename ChildT, Index Log2Dim>
2864 iter->writeBuffers(os, toHalf);
2869template<
typename ChildT, Index Log2Dim>
2874 iter->readBuffers(is, fromHalf);
2879template<
typename ChildT, Index Log2Dim>
2882 const CoordBBox& clipBBox,
bool fromHalf)
2889 iter->readBuffers(is, clipBBox, fromHalf);
2895 background = *
static_cast<const ValueType*
>(bgPtr);
2897 this->
clip(clipBBox, background);
2904template<
typename ChildT, Index Log2Dim>
2908 dims.push_back(Log2Dim);
2909 ChildNodeType::getNodeLog2Dims(dims);
2913template<
typename ChildT, Index Log2Dim>
2917 assert(n<(1<<3*Log2Dim));
2918 xyz.
setX(n >> 2*Log2Dim);
2919 n &= ((1<<2*Log2Dim)-1);
2920 xyz.
setY(n >> Log2Dim);
2921 xyz.
setZ(n & ((1<<Log2Dim)-1));
2925template<
typename ChildT, Index Log2Dim>
2929 return (((xyz[0] & (
DIM-1u)) >> ChildNodeType::TOTAL) << 2*Log2Dim)
2930 + (((xyz[1] & (
DIM-1u)) >> ChildNodeType::TOTAL) << Log2Dim)
2931 + ((xyz[2] & (
DIM-1u)) >> ChildNodeType::TOTAL);
2935template<
typename ChildT, Index Log2Dim>
2941 local <<= ChildT::TOTAL;
2942 return local + this->
origin();
2949template<
typename ChildT, Index Log2Dim>
2950template<
typename ArrayT>
2954 using T =
typename ArrayT::value_type;
2955 static_assert(std::is_pointer<T>::value,
"argument to getNodes() must be a pointer array");
2956 using ArrayChildT =
typename std::conditional<
2957 std::is_const<typename std::remove_pointer<T>::type>
::value,
const ChildT, ChildT>::type;
2960 if (std::is_same<T, ArrayChildT*>::value) {
2961 array.push_back(
reinterpret_cast<T
>(
mNodes[
iter.pos()].getChild()));
2963 iter->getNodes(array);
2969template<
typename ChildT, Index Log2Dim>
2970template<
typename ArrayT>
2974 using T =
typename ArrayT::value_type;
2975 static_assert(std::is_pointer<T>::value,
"argument to getNodes() must be a pointer array");
2976 static_assert(std::is_const<typename std::remove_pointer<T>::type>
::value,
2977 "argument to getNodes() must be an array of const node pointers");
2980 if (std::is_same<T, const ChildT*>::value) {
2981 array.push_back(
reinterpret_cast<T
>(
mNodes[
iter.pos()].getChild()));
2983 iter->getNodes(array);
2993template<
typename ChildT, Index Log2Dim>
2994template<
typename ArrayT>
2998 using T =
typename ArrayT::value_type;
2999 static_assert(std::is_pointer<T>::value,
"argument to stealNodes() must be a pointer array");
3000 using ArrayChildT =
typename std::conditional<
3001 std::is_const<typename std::remove_pointer<T>::type>
::value,
const ChildT, ChildT>::type;
3005 if (std::is_same<T, ArrayChildT*>::value) {
3006 array.push_back(
reinterpret_cast<T
>(
mNodes[n].getChild()));
3013 if (std::is_same<T, ArrayChildT*>::value)
mChildMask.setOff();
3021template<
typename ChildT, Index Log2Dim>
3029 mNodes[i].getChild()->resetBackground(oldBackground, newBackground);
3032 mNodes[i].setValue(newBackground);
3040template<
typename ChildT, Index Log2Dim>
3041template<
typename OtherChildNodeType, Index OtherLog2Dim>
3055template<
typename ChildT, Index Log2Dim>
3061 delete mNodes[i].getChild();
3069template<
typename ChildT, Index Log2Dim>
3081template<
typename ChildT, Index Log2Dim>
3096template<
typename ChildT, Index Log2Dim>
3103template<
typename ChildT, Index Log2Dim>
3108 return mNodes[n].getChild();
3112template<
typename ChildT, Index Log2Dim>
3117 return mNodes[n].getChild();
ValueT value
Definition GridBuilder.h:1290
ChildT * child
Definition GridBuilder.h:1289
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:530
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:582
const AValueType & result() const
Get the output value.
Definition Types.h:574
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:598
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:584
bool resultIsActive() const
Definition Types.h:593
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:596
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition Coord.h:313
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition Coord.h:175
static bool lessThan(const Coord &a, const Coord &b)
Definition Coord.h:208
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:650
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:644
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:249
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition Coord.h:458
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition Coord.h:418
const Coord & min() const
Definition Coord.h:321
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition Coord.h:412
const Coord & max() const
Definition Coord.h:322
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition Coord.h:400
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:444
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:25
Int32 y() const
Definition Coord.h:131
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition Coord.h:91
Int32 x() const
Definition Coord.h:130
Coord & setZ(Int32 z)
Definition Coord.h:81
Coord & setY(Int32 y)
Definition Coord.h:80
static Coord max()
Return the largest possible coordinate.
Definition Coord.h:46
Int32 z() const
Definition Coord.h:132
Coord & setX(Int32 x)
Definition Coord.h:79
Definition InternalNode.h:34
void setValueAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition InternalNode.h:1752
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition InternalNode.h:335
void merge(InternalNode &other, const ValueType &background, const ValueType &otherBackground)
Efficiently merge another tree into this tree using one of several schemes.
Definition InternalNode.h:2353
ChildOnCIter cbeginChildOn() const
Definition InternalNode.h:220
const ValueType & getFirstValue() const
If the first entry in this node's table is a tile, return the tile's value. Otherwise,...
Definition InternalNode.h:2268
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by the node regardless of it...
Definition InternalNode.h:299
bool isConstant(ValueType &minValue, ValueType &maxValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition InternalNode.h:1519
ValueIter< const InternalNode, const ValueType, MaskOffIterator, ValueOff > ValueOffCIter
Definition InternalNode.h:216
ChildOnCIter beginChildOn() const
Definition InternalNode.h:223
ValueIter< InternalNode, const ValueType, MaskOffIterator, ValueAll > ValueAllIter
Definition InternalNode.h:217
ChildOnIter beginChildOn()
Definition InternalNode.h:226
NodeType * probeNode(const Coord &xyz)
Return a pointer to the node that contains voxel (x, y, z). If no such node exists,...
bool isChildMaskOff(Index n) const
Definition InternalNode.h:751
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition InternalNode.h:1561
void writeTopology(std::ostream &, bool toHalf=false) const
Definition InternalNode.h:2183
util::NodeMask< Log2Dim > NodeMaskType
Definition InternalNode.h:41
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 InternalNode.h:2138
void setChildNode(Index i, ChildNodeType *child)
Definition InternalNode.h:3071
bool isChildMaskOff() const
Definition InternalNode.h:752
ValueOffCIter cbeginValueOff() const
Definition InternalNode.h:232
LeafNodeType * probeLeafAndCache(const Coord &xyz, AccessorT &acc)
Same as probeLeaf() except, if necessary, update the accessor with pointers to the nodes along the pa...
Index32 transientData() const
Return the transient data value.
Definition InternalNode.h:273
InternalNode(const InternalNode< OtherChildNodeType, Log2Dim > &other)
Value conversion copy constructor.
Definition InternalNode.h:897
InternalNode(const Coord &origin, const ValueType &fillValue, bool active=false)
Constructs an InternalNode with dense tiles.
Definition InternalNode.h:836
void addLeafAndCache(LeafNodeType *leaf, AccessorT &)
Same as addLeaf() except, if necessary, update the accessor with pointers to the nodes along the path...
Definition InternalNode.h:1339
static Index getChildDim()
Definition InternalNode.h:256
const NodeMaskType & getChildMask() const
Definition InternalNode.h:754
Index32 nonLeafCount() const
Definition InternalNode.h:1028
void topologyIntersection(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &background)
Intersects this tree's set of active values with the active values of the other tree,...
NodeUnion< ValueType, ChildNodeType > UnionType
Definition InternalNode.h:40
NodeMaskType mChildMask
Definition InternalNode.h:795
bool isValueMaskOff() const
Definition InternalNode.h:749
InternalNode(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &offValue, const ValueType &onValue, TopologyCopy)
Topology copy constructor.
Definition InternalNode.h:974
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition InternalNode.h:2952
bool isValueMaskOn() const
Definition InternalNode.h:747
NodeT * stealNode(const Coord &xyz, const ValueType &value, bool state)
Return a pointer to the node of type NodeT that contains voxel (x, y, z) and replace it with a tile o...
Definition InternalNode.h:1162
void voxelizeActiveTiles(bool threaded=true)
Densify active tiles, i.e., replace them with leaf-level active voxels.
Definition InternalNode.h:2332
NodeMaskType mValueMask
Definition InternalNode.h:795
InternalNode()
Default constructor.
Definition InternalNode.h:72
bool isChildMaskOn(Index n) const
Definition InternalNode.h:750
~InternalNode()
Definition InternalNode.h:990
Index64 onLeafVoxelCount() const
Definition InternalNode.h:1073
const LeafNodeType * probeConstLeafAndCache(const Coord &xyz, AccessorT &acc) const
NodeMaskType getValueOffMask() const
Definition InternalNode.h:755
void merge(const ValueType &tileValue, bool tileActive)
Merge, using one of several schemes, this node (and its descendants) with a tile of the same dimensio...
Definition InternalNode.h:2462
LeafNodeType * probeLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists,...
Definition InternalNode.h:1264
ValueAllCIter cbeginValueAll() const
Definition InternalNode.h:233
void prune(const ValueType &tolerance=zeroVal< ValueType >())
Reduce the memory footprint of this tree by replacing with tiles any nodes whose values are all the s...
Definition InternalNode.h:1138
ValueIter< const InternalNode, const ValueType, MaskOffIterator, ValueAll > ValueAllCIter
Definition InternalNode.h:218
ValueOnCIter beginValueOn() const
Definition InternalNode.h:234
Index64 offLeafVoxelCount() const
Definition InternalNode.h:1085
void combine2(const InternalNode &other, const OtherValueType &, bool valIsActive, CombineOp &)
Definition InternalNode.h:2826
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Change inactive tiles or voxels with value oldBackground to newBackground or -oldBackground to -newBa...
Definition InternalNode.h:3023
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly creating a parent bran...
Definition InternalNode.h:1398
void combine2(const ValueType &value, const OtherNodeType &other, bool valIsActive, CombineOp &)
Definition InternalNode.h:2793
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition InternalNode.h:269
const Coord & origin() const
Definition InternalNode.h:267
bool isInactive() const
Return true if this node has no children and only contains inactive values.
Definition InternalNode.h:330
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition InternalNode.h:1930
void setValueOnlyAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition InternalNode.h:1793
void combine2(const InternalNode &other0, const OtherNodeType &other1, CombineOp &)
Definition InternalNode.h:2746
friend class InternalNode
During topology-only construction, access is needed to protected/private members of other template in...
Definition InternalNode.h:742
bool isValueMaskOff(Index n) const
Definition InternalNode.h:748
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition InternalNode.h:1776
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Definition InternalNode.h:1290
Index getValueLevelAndCache(const Coord &xyz, AccessorT &) const
Return the level of the tree (0 = leaf) at which the value at the given coordinates resides.
Definition InternalNode.h:1614
const NodeType * probeConstNodeAndCache(const Coord &xyz, AccessorT &) const
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition InternalNode.h:2034
ValueOffCIter beginValueOff() const
Definition InternalNode.h:236
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition InternalNode.h:1707
void addLeaf(LeafNodeType *leaf)
Add the specified leaf to this node, possibly creating a child branch in the process....
Definition InternalNode.h:1310
InternalNode(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &background, TopologyCopy)
Topology copy constructor.
Definition InternalNode.h:935
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
ChildAllCIter cbeginChildAll() const
Definition InternalNode.h:222
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition InternalNode.h:1984
ChildAllIter beginChildAll()
Definition InternalNode.h:228
ValueIter< InternalNode, const ValueType, MaskOnIterator, ValueOn > ValueOnIter
Definition InternalNode.h:213
static Index getLevel()
Definition InternalNode.h:249
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition InternalNode.h:1687
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Definition InternalNode.h:1571
void topologyDifference(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &background)
Difference this node's set of active values with the active values of the other node,...
static const Index DIM
Definition InternalNode.h:46
bool probeValue(const Coord &xyz, ValueType &value) const
Definition InternalNode.h:1627
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 InternalNode.h:1814
ValueOnIter beginValueOn()
Definition InternalNode.h:238
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 InternalNode.h:1896
static const Index LEVEL
Definition InternalNode.h:48
void topologyUnion(const InternalNode< OtherChildNodeType, Log2Dim > &other, const bool preserveTiles=false)
Union this branch's set of active values with the other branch's active values. The value type of the...
ChildOffCIter cbeginChildOff() const
Definition InternalNode.h:221
ChildOffIter beginChildOff()
Definition InternalNode.h:227
ChildIter< InternalNode, ChildNodeType, MaskOnIterator, ChildOn > ChildOnIter
Definition InternalNode.h:206
Index64 onVoxelCount() const
Definition InternalNode.h:1049
ChildOffCIter beginChildOff() const
Definition InternalNode.h:224
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition InternalNode.h:2927
void addTileAndCache(Index level, const Coord &xyz, const ValueType &, bool state, AccessorT &)
Same as addTile() except, if necessary, update the accessor with pointers to the nodes along the path...
Definition InternalNode.h:1430
typename ChildNodeType::LeafNodeType LeafNodeType
Definition InternalNode.h:37
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition InternalNode.h:1655
NodeType * probeNodeAndCache(const Coord &xyz, AccessorT &)
Same as probeNode() except, if necessary, update the accessor with pointers to the nodes along the pa...
void writeBuffers(std::ostream &, bool toHalf=false) const
Definition InternalNode.h:2861
ValueOnCIter cbeginValueOn() const
Definition InternalNode.h:230
typename ChildNodeType::ValueType ValueType
Definition InternalNode.h:38
Index32 leafCount() const
Definition InternalNode.h:1003
const LeafNodeType * probeLeaf(const Coord &xyz) const
void resetChildNode(Index i, ChildNodeType *child)
Definition InternalNode.h:3057
void readBuffers(std::istream &, const CoordBBox &, bool fromHalf=false)
Definition InternalNode.h:2881
Index32 childCount() const
Definition InternalNode.h:1041
DenseIter< const InternalNode, const ChildNodeType, ValueType, ChildAll > ChildAllCIter
Definition InternalNode.h:211
Index getValueLevel(const Coord &xyz) const
Return the level of the tree (0 = leaf) at which the value at the given coordinates resides.
Definition InternalNode.h:1605
Index64 onTileCount() const
Definition InternalNode.h:1096
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition InternalNode.h:1868
bool hasSameTopology(const InternalNode< OtherChildNodeType, OtherLog2Dim > *other) const
Return true if the given tree branch has the same node and active value topology as this tree branch ...
Definition InternalNode.h:3043
void setValueMask(Index n, bool on)
Definition InternalNode.h:767
Index64 offVoxelCount() const
Definition InternalNode.h:1061
typename NodeMaskType::OffIterator MaskOffIterator
Definition InternalNode.h:115
ChildIter< const InternalNode, const ChildNodeType, MaskOnIterator, ChildOn > ChildOnCIter
Definition InternalNode.h:207
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition InternalNode.h:1499
LeafNodeType * touchLeaf(const Coord &xyz)
Return the leaf node that contains voxel (x, y, z). If no such node exists, create one,...
Definition InternalNode.h:1466
void getNodes(ArrayT &array) const
Definition InternalNode.h:2972
Index32 mTransientData
Definition InternalNode.h:800
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value and ensure that those voxels are a...
Definition InternalNode.h:2090
static const Index NUM_VALUES
Definition InternalNode.h:47
ValueIter< InternalNode, const ValueType, MaskOffIterator, ChildOff > ChildOffIter
Definition InternalNode.h:208
UnionType mNodes[NUM_VALUES]
Definition InternalNode.h:794
void negate()
Change the sign of all the values represented in this node and its child nodes.
Definition InternalNode.h:2288
void readTopology(std::istream &, bool fromHalf=false)
Definition InternalNode.h:2208
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition InternalNode.h:2937
ValueIter< const InternalNode, const ValueType, MaskOffIterator, ChildOff > ChildOffCIter
Definition InternalNode.h:209
ChildAllCIter beginChildAll() const
Definition InternalNode.h:225
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Definition InternalNode.h:1833
void setValuesOn()
Mark all values (both tiles and voxels) as active.
Definition InternalNode.h:1856
void makeChildNodeEmpty(Index n, const ValueType &value)
Definition InternalNode.h:3098
void setTransientData(Index32 transientData)
Set the transient data value.
Definition InternalNode.h:275
typename ChildNodeType::BuildType BuildType
Definition InternalNode.h:39
LeafNodeType * touchLeafAndCache(const Coord &xyz, AccessorT &)
Same as touchLeaf() except, if necessary, update the accessor with pointers to the nodes along the pa...
void stealNodes(ArrayT &array, const ValueType &value, bool state)
Steals all nodes of a certain type from the tree and adds them to a container with the following API:
Definition InternalNode.h:2996
ChildNodeType * getChildNode(Index n)
Returns a pointer to the child node at the linear offset n.
Definition InternalNode.h:3105
typename NodeMaskType::OnIterator MaskOnIterator
Definition InternalNode.h:114
const LeafNodeType * probeLeafAndCache(const Coord &xyz, AccessorT &acc) const
bool probeValueAndCache(const Coord &xyz, ValueType &value, AccessorT &) const
Definition InternalNode.h:1640
static const Index LOG2DIM
Definition InternalNode.h:44
bool addChild(ChildNodeType *child)
Add the given child node at this level deducing the offset from it's origin. If a child node with thi...
Definition InternalNode.h:1372
DenseIter< InternalNode, ChildNodeType, ValueType, ChildAll > ChildAllIter
Definition InternalNode.h:210
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Expand the specified bounding box so that it includes the active tiles of this internal node as well ...
Definition InternalNode.h:1120
ValueIter< const InternalNode, const ValueType, MaskOnIterator, ValueOn > ValueOnCIter
Definition InternalNode.h:214
bool isEmpty() const
Definition InternalNode.h:302
InternalNode(const ValueType &offValue)
Constructor of an InternalNode with dense inactive tiles of the specified value.
Definition InternalNode.h:828
const UnionType * getTable() const
Definition InternalNode.h:762
static void getNodeLog2Dims(std::vector< Index > &dims)
Populated an std::vector with the dimension of all the nodes in the branch starting with this node.
Definition InternalNode.h:2906
ValueOffIter beginValueOff()
Definition InternalNode.h:240
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition InternalNode.h:1671
ValueIter< InternalNode, const ValueType, MaskOffIterator, ValueOff > ValueOffIter
Definition InternalNode.h:215
typename SubtreeT::Back ChildNodeType
Definition InternalNode.h:36
static void offsetToLocalCoord(Index n, Coord &xyz)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition InternalNode.h:2915
const NodeMaskType & getValueMask() const
Definition InternalNode.h:753
static const Index TOTAL
Definition InternalNode.h:45
const ChildNodeType * getChildNode(Index n) const
Returns a pointer to the child node at the linear offset n.
Definition InternalNode.h:3114
const NodeType * probeConstNode(const Coord &xyz) const
bool hasActiveTiles() const
Return true if this node or any of its child nodes have any active tiles.
Definition InternalNode.h:1546
void combine(InternalNode &other, CombineOp &)
Definition InternalNode.h:2659
InternalNode(const InternalNode &)
Deep copy constructor.
Definition InternalNode.h:881
const ValueType & getValue(const Coord &xyz) const
Definition InternalNode.h:1582
void nodeCount(std::vector< Index32 > &vec) const
Definition InternalNode.h:1015
Index64 memUsage() const
Return the total amount of memory in bytes occupied by this node and its children.
Definition InternalNode.h:1107
void setValueOn(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition InternalNode.h:1732
static const Index64 NUM_VOXELS
Definition InternalNode.h:50
ChildNodeType * unsetChildNode(Index i, const ValueType &value)
Definition InternalNode.h:3083
void readBuffers(std::istream &, bool fromHalf=false)
Definition InternalNode.h:2871
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition InternalNode.h:116
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition InternalNode.h:1953
ValueAllCIter beginValueAll() const
Definition InternalNode.h:237
Coord mOrigin
Definition InternalNode.h:797
static Index dim()
Definition InternalNode.h:246
InternalNode(PartialCreate, const Coord &, const ValueType &fillValue, bool active=false)
Definition InternalNode.h:850
void addTile(Index offset, const ValueType &value, bool state)
Delete any existing child branch at the specified offset and add a tile.
Definition InternalNode.h:1388
bool isValueMaskOn(Index n) const
Definition InternalNode.h:746
ValueAllIter beginValueAll()
Definition InternalNode.h:241
void combine(const ValueType &value, bool valueIsActive, CombineOp &)
Definition InternalNode.h:2717
const ValueType & getLastValue() const
If the last entry in this node's table is a tile, return the tile's value. Otherwise,...
Definition InternalNode.h:2276
Base class for iterators over internal and leaf nodes.
Definition Iterator.h:30
Index pos() const
Definition Iterator.h:60
InternalNode & parent() const
Definition Iterator.h:50
Default implementation of a NodeUnion that stores the child pointer and the value separately (i....
Definition NodeUnion.h:32
const ValueT & getValue() const
Definition NodeUnion.h:43
ChildT * getChild() const
Definition NodeUnion.h:40
void setValue(const ValueT &val)
Definition NodeUnion.h:45
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition NodeMasks.h:308
Index64 Word
Definition NodeMasks.h:316
DenseMaskIterator< NodeMask > DenseIterator
Definition NodeMasks.h:350
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition NodeMasks.h:483
OnMaskIterator< NodeMask > OnIterator
Definition NodeMasks.h:348
void setOff(Index32 n)
Set the nth bit off.
Definition NodeMasks.h:457
OffMaskIterator< NodeMask > OffIterator
Definition NodeMasks.h:349
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition Compression.h:645
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition Compression.h:465
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 isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:406
T negative(const T &val)
Return the unary negation of the given value.
Definition Math.h:128
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
Definition TreeIterator.h:29
Index32 Index
Definition Types.h:54
@ OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
Definition version.h.in:256
@ OPENVDB_FILE_VERSION_INTERNALNODE_COMPRESSION
Definition version.h.in:247
uint32_t Index32
Definition Types.h:52
T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
int32_t Int32
Definition Types.h:56
uint64_t Index64
Definition Types.h:53
@ MERGE_ACTIVE_STATES
Definition Types.h:468
@ MERGE_NODES
Definition Types.h:469
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:470
Definition Exceptions.h:13
typename std::remove_const< ValueT >::type NonConstValueType
Definition Iterator.h:184
DenseIteratorBase()
Definition Iterator.h:188
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition InternalNode.h:131
ChildIter()
Definition InternalNode.h:130
ChildT & getItem(Index pos) const
Definition InternalNode.h:134
void setItem(Index pos, const ChildT &c) const
Definition InternalNode.h:141
Definition InternalNode.h:120
Definition InternalNode.h:120
Definition InternalNode.h:861
DeepCopy(const OtherInternalNode *source, InternalNode *target)
Definition InternalNode.h:862
InternalNode * t
Definition InternalNode.h:876
const OtherInternalNode * s
Definition InternalNode.h:875
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:866
DenseIteratorBase< MaskDenseIterator, DenseIter, NodeT, ChildT, ValueT > BaseT
Definition InternalNode.h:173
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition InternalNode.h:177
void unsetItem(Index pos, const ValueT &value) const
Definition InternalNode.h:198
void setItem(Index pos, ChildT *child) const
Definition InternalNode.h:192
DenseIter()
Definition InternalNode.h:176
bool getItem(Index pos, ChildT *&child, NonConstValueT &value) const
Definition InternalNode.h:180
typename BaseT::NonConstValueType NonConstValueT
Definition InternalNode.h:174
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of an Intern...
Definition InternalNode.h:64
static const bool value
Definition InternalNode.h:65
Definition InternalNode.h:911
TopologyCopy1(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition InternalNode.h:912
InternalNode * t
Definition InternalNode.h:928
const OtherInternalNode * s
Definition InternalNode.h:927
const ValueType & b
Definition InternalNode.h:929
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:917
Definition InternalNode.h:950
const ValueType & offV
Definition InternalNode.h:968
TopologyCopy2(const OtherInternalNode *source, InternalNode *target, const ValueType &offValue, const ValueType &onValue)
Definition InternalNode.h:951
InternalNode * t
Definition InternalNode.h:967
const OtherInternalNode * s
Definition InternalNode.h:966
const ValueType & onV
Definition InternalNode.h:968
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:956
Definition InternalNode.h:2597
void operator()(W &tC, const W &sC, const W &sV, const W &tV) const
Definition InternalNode.h:2597
Definition InternalNode.h:2600
void operator()(W &tV, const W &sC, const W &sV, const W &tC) const
Definition InternalNode.h:2600
TopologyDifference(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition InternalNode.h:2603
typename NodeMaskType::Word W
Definition InternalNode.h:2596
InternalNode * t
Definition InternalNode.h:2639
const OtherInternalNode * s
Definition InternalNode.h:2638
const ValueType & b
Definition InternalNode.h:2640
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2617
Definition InternalNode.h:2547
void operator()(W &tC, const W &sC, const W &sV, const W &tV) const
Definition InternalNode.h:2547
TopologyIntersection(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition InternalNode.h:2550
typename NodeMaskType::Word W
Definition InternalNode.h:2546
InternalNode * t
Definition InternalNode.h:2579
const OtherInternalNode * s
Definition InternalNode.h:2578
const ValueType & b
Definition InternalNode.h:2580
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2562
Definition InternalNode.h:2495
void operator()(W &tV, const W &sV, const W &tC) const
Definition InternalNode.h:2495
Definition InternalNode.h:2493
typename NodeMaskType::Word W
Definition InternalNode.h:2494
InternalNode * t
Definition InternalNode.h:2530
const bool mPreserveTiles
Definition InternalNode.h:2531
const OtherInternalNode * s
Definition InternalNode.h:2529
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2511
TopologyUnion(const OtherInternalNode *source, InternalNode *target, const bool preserveTiles)
Definition InternalNode.h:2498
ValueConverter<T>::Type is the type of an InternalNode having the same child hierarchy and dimensions...
Definition InternalNode.h:55
InternalNode< typename ChildNodeType::template ValueConverter< OtherValueType >::Type, Log2Dim > Type
Definition InternalNode.h:56
void modifyItem(Index pos, const ModifyOp &op) const
Definition InternalNode.h:162
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition InternalNode.h:152
const ValueT & getItem(Index pos) const
Definition InternalNode.h:155
ValueIter()
Definition InternalNode.h:151
void setItem(Index pos, const ValueT &v) const
Definition InternalNode.h:158
Definition InternalNode.h:119
Definition InternalNode.h:119
Definition InternalNode.h:2306
InternalNode * mNode
Definition InternalNode.h:2327
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2314
VoxelizeActiveTiles(InternalNode &node)
Definition InternalNode.h:2307
static const bool value
Definition InternalNode.h:818
Definition InternalNode.h:812
static const bool value
Definition InternalNode.h:813
SparseIteratorBase()
Definition Iterator.h:122
const ValueType & getValue() const
Definition Iterator.h:139
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212