13 #ifndef OPENVDB_TREE_NODEMANAGER_HAS_BEEN_INCLUDED
14 #define OPENVDB_TREE_NODEMANAGER_HAS_BEEN_INCLUDED
18 #include <tbb/parallel_for.h>
19 #include <tbb/parallel_reduce.h>
30 template<
typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
36 template<
typename TreeOrLeafManagerT, Index _LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
47 static bool valid(
size_t) {
return true; }
54 template<
typename NodeT>
74 template <
typename RootT>
97 for (
auto iter = root.beginChildOn(); iter; ++iter) {
98 *nodePtr++ = &iter.getValue();
105 template <
typename ParentsT,
typename NodeFilterT>
106 bool initNodeChildren(ParentsT& parents,
const NodeFilterT& nodeFilter = NodeFilterT(),
bool serial =
false)
110 std::vector<Index64> nodeCounts;
112 nodeCounts.reserve(parents.nodeCount());
113 for (
size_t i = 0; i < parents.nodeCount(); i++) {
114 if (!nodeFilter.valid(i)) nodeCounts.push_back(0);
115 else nodeCounts.push_back(parents(i).childCount());
118 nodeCounts.resize(parents.nodeCount());
123 tbb::blocked_range<Index64>(0, parents.nodeCount(), 64),
124 [&](tbb::blocked_range<Index64>&
range)
126 for (
Index64 i = range.begin(); i < range.end(); i++) {
127 if (!nodeFilter.valid(i)) nodeCounts[i] = 0;
128 else nodeCounts[i] = parents(i).childCount();
136 for (
size_t i = 1; i < nodeCounts.size(); i++) {
137 nodeCounts[i] += nodeCounts[i-1];
140 const size_t nodeCount = nodeCounts.empty() ? 0 : nodeCounts.back();
161 for (
size_t i = 0; i < parents.nodeCount(); i++) {
162 if (!nodeFilter.valid(i))
continue;
163 for (
auto iter = parents(i).beginChildOn(); iter; ++iter) {
164 *nodePtr++ = &iter.getValue();
169 tbb::blocked_range<Index64>(0, parents.nodeCount()),
170 [&](tbb::blocked_range<Index64>&
range)
174 if (i > 0) nodePtr += nodeCounts[i-1];
175 for ( ; i < range.end(); i++) {
176 if (!nodeFilter.valid(i))
continue;
177 for (
auto iter = parents(i).beginChildOn(); iter; ++iter) {
178 *nodePtr++ = &iter.getValue();
193 mEnd(end), mBegin(begin), mGrainSize(grainSize), mNodeList(nodeList) {}
196 mEnd(r.mEnd), mBegin(doSplit(r)), mGrainSize(r.mGrainSize),
197 mNodeList(r.mNodeList) {}
199 size_t size()
const {
return mEnd - mBegin; }
205 bool empty()
const {
return !(mBegin < mEnd);}
221 NodeT&
operator*()
const {
return mRange.mNodeList(mPos); }
225 size_t pos()
const {
return mPos; }
226 bool isValid()
const {
return mPos>=mRange.mBegin && mPos<=mRange.mEnd; }
228 bool test()
const {
return mPos < mRange.mEnd; }
235 return (mPos != other.mPos) || (&mRange != &other.mRange);
250 size_t mEnd, mBegin, mGrainSize;
256 size_t middle = r.mBegin + (r.mEnd - r.mBegin) / 2u;
265 return NodeRange(0, this->
nodeCount(), *
this, grainsize);
268 template<
typename NodeOp>
269 void foreach(
const NodeOp&
op,
bool threaded =
true,
size_t grainSize=1)
271 NodeTransformerCopy<NodeOp>
transform(op);
275 template<
typename NodeOp>
284 template<
typename NodeOp>
287 NodeTransformer<NodeOp, OpWithIndex>
transform(op);
292 template<
typename NodeOp>
295 NodeReducer<NodeOp, OpWithIndex>
transform(op);
303 struct OpWithoutIndex
305 template <
typename T>
306 static void eval(T& node,
typename NodeRange::Iterator& iter) { node(*iter); }
313 template <
typename T>
314 static void eval(T& node,
typename NodeRange::Iterator& iter) { node(*iter, iter.pos()); }
318 template<
typename NodeOp,
typename OpT = OpWithoutIndex>
319 struct NodeTransformerCopy
321 NodeTransformerCopy(
const NodeOp& nodeOp) : mNodeOp(nodeOp)
330 for (
typename NodeRange::Iterator it = range.begin(); it; ++it) {
334 const NodeOp mNodeOp;
338 template<
typename NodeOp,
typename OpT = OpWithoutIndex>
339 struct NodeTransformer
341 NodeTransformer(
const NodeOp& nodeOp) : mNodeOp(nodeOp)
344 void run(
const NodeRange& range,
bool threaded =
true)
350 for (
typename NodeRange::Iterator it = range.begin(); it; ++it) {
354 const NodeOp& mNodeOp;
358 template<
typename NodeOp,
typename OpT = OpWithoutIndex>
361 NodeReducer(NodeOp& nodeOp) : mNodeOp(&nodeOp)
364 NodeReducer(
const NodeReducer& other,
tbb::split)
365 : mNodeOpPtr(std::make_unique<NodeOp>(*(other.mNodeOp), tbb::
split()))
366 , mNodeOp(mNodeOpPtr.
get())
369 void run(
const NodeRange& range,
bool threaded =
true)
371 threaded ? tbb::parallel_reduce(range, *
this) : (*
this)(range);
375 for (
typename NodeRange::Iterator it = range.begin(); it; ++it) {
379 void join(
const NodeReducer& other)
381 mNodeOp->join(*(other.mNodeOp));
383 std::unique_ptr<NodeOp> mNodeOpPtr;
384 NodeOp *mNodeOp =
nullptr;
402 template<
typename NodeT, Index LEVEL>
413 template <
typename RootT>
416 mList.initRootChildren(root);
420 template<
typename ParentsT>
431 return i==NodeT::LEVEL ?
mList.nodeCount() :
mNext.nodeCount(i);
434 template<
typename NodeOp>
437 mNext.foreachBottomUp(op, threaded, grainSize);
438 mList.foreach(op, threaded, grainSize);
441 template<
typename NodeOp>
444 mList.foreach(op, threaded, grainSize);
445 mNext.foreachTopDown(op, threaded, grainSize);
448 template<
typename NodeOp>
451 mNext.reduceBottomUp(op, threaded, grainSize);
452 mList.reduce(op, threaded, grainSize);
455 template<
typename NodeOp>
458 mList.reduce(op, threaded, grainSize);
459 mNext.reduceTopDown(op, threaded, grainSize);
474 template<
typename NodeT>
483 template <
typename RootT>
486 template<
typename ParentsT>
487 void initNodeChildren(ParentsT& parents,
bool serial =
false) {
mList.initNodeChildren(parents, NodeFilter(), serial); }
493 template<
typename NodeOp>
496 mList.foreach(op, threaded, grainSize);
499 template<
typename NodeOp>
500 void foreachTopDown(
const NodeOp& op,
bool threaded,
size_t grainSize)
502 mList.foreach(op, threaded, grainSize);
505 template<
typename NodeOp>
508 mList.reduce(op, threaded, grainSize);
511 template<
typename NodeOp>
512 void reduceTopDown(NodeOp& op,
bool threaded,
size_t grainSize)
514 mList.reduce(op, threaded, grainSize);
518 NodeList<NodeT>
mList;
530 template<
typename TreeOrLeafManagerT, Index _LEVELS>
536 "expected instantiation of template specialization");
541 static_assert(RootNodeType::LEVEL >=
LEVELS,
"number of levels exceeds root node height");
624 template<
typename NodeOp>
631 template<
typename NodeOp>
698 template<
typename NodeOp>
705 template<
typename NodeOp>
724 template <
typename OpT>
729 , mValidPtr(std::make_unique<
bool[]>(size))
730 , mValid(mValidPtr.
get()) { }
734 , mValid(other.mValid) { }
736 template<
typename NodeT>
739 mValid[idx] = mOp(node, idx);
742 bool valid(
size_t idx)
const {
return mValid[idx]; }
744 const OpT&
op()
const {
return mOp; }
748 std::unique_ptr<bool[]> mValidPtr;
749 bool* mValid =
nullptr;
755 template <
typename OpT>
760 , mValidPtr(std::make_unique<
bool[]>(size))
761 , mValid(mValidPtr.
get()) { }
765 , mValid(other.mValid) { }
768 : mOpPtr(std::make_unique<OpT>(*(other.mOp), tbb::
split()))
770 , mValid(other.mValid) { }
772 template<
typename NodeT>
775 mValid[idx] = (*mOp)(node, idx);
780 mOp->join(*(other.mOp));
788 OpT&
op() {
return *mOp; }
791 std::unique_ptr<OpT> mOpPtr;
793 std::unique_ptr<bool[]> mValidPtr;
794 bool* mValid =
nullptr;
802 template<
typename NodeT, Index LEVEL>
811 template<
typename NodeOpT,
typename RootT>
813 size_t leafGrainSize,
size_t nonLeafGrainSize)
815 if (!
op(root, 0))
return;
816 if (!
mList.initRootChildren(root))
return;
818 mList.foreachWithIndex(filterOp, threaded, LEVEL == 0 ? leafGrainSize : nonLeafGrainSize);
819 mNext.foreachTopDownRecurse(filterOp,
mList, threaded, leafGrainSize, nonLeafGrainSize);
822 template<
typename FilterOpT,
typename ParentT>
824 size_t leafGrainSize,
size_t nonLeafGrainSize)
826 if (!
mList.initNodeChildren(parent, filterOp, !threaded))
return;
827 FilterOpT childFilterOp(filterOp.op(),
mList.nodeCount());
828 mList.foreachWithIndex(childFilterOp, threaded, LEVEL == 0 ? leafGrainSize : nonLeafGrainSize);
829 mNext.foreachTopDownRecurse(childFilterOp,
mList, threaded, leafGrainSize, nonLeafGrainSize);
832 template<
typename NodeOpT,
typename RootT>
834 size_t leafGrainSize,
size_t nonLeafGrainSize)
836 if (!
op(root, 0))
return;
837 if (!
mList.initRootChildren(root))
return;
839 mList.reduceWithIndex(filterOp, threaded, LEVEL == 0 ? leafGrainSize : nonLeafGrainSize);
840 mNext.reduceTopDownRecurse(filterOp,
mList, threaded, leafGrainSize, nonLeafGrainSize);
843 template<
typename FilterOpT,
typename ParentT>
845 size_t leafGrainSize,
size_t nonLeafGrainSize)
847 if (!
mList.initNodeChildren(parent, filterOp, !threaded))
return;
848 FilterOpT childFilterOp(filterOp.op(),
mList.nodeCount());
849 mList.reduceWithIndex(childFilterOp, threaded, LEVEL == 0 ? leafGrainSize : nonLeafGrainSize);
850 mNext.reduceTopDownRecurse(childFilterOp,
mList, threaded, leafGrainSize, nonLeafGrainSize);
862 template<
typename NodeT>
868 template<
typename NodeFilterOp,
typename ParentT>
870 size_t leafGrainSize,
size_t )
872 if (!
mList.initNodeChildren(parent, nodeFilterOp, !threaded))
return;
873 mList.foreachWithIndex(nodeFilterOp.op(),
threaded, leafGrainSize);
876 template<
typename NodeFilterOp,
typename ParentT>
878 size_t leafGrainSize,
size_t )
880 if (!
mList.initNodeChildren(parent, nodeFilterOp, !threaded))
return;
881 mList.reduceWithIndex(nodeFilterOp.op(),
threaded, leafGrainSize);
885 NodeList<NodeT>
mList;
889 template<
typename TreeOrLeafManagerT, Index _LEVELS>
890 class DynamicNodeManager
895 "expected instantiation of template specialization");
900 static_assert(RootNodeType::LEVEL >=
LEVELS,
"number of levels exceeds root node height");
976 template<
typename NodeOp>
978 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1043 template<
typename NodeOp>
1045 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1062 template<
typename TreeOrLeafManagerT>
1070 NodeManager(TreeOrLeafManagerT& tree,
bool =
false) :
mRoot(tree.root()) { }
1079 void rebuild(
bool =
false) { }
1089 template<
typename NodeOp>
1092 template<
typename NodeOp>
1095 template<
typename NodeOp>
1098 template<
typename NodeOp>
1111 template<
typename TreeOrLeafManagerT>
1112 class NodeManager<TreeOrLeafManagerT, 1>
1117 static_assert(RootNodeType::LEVEL > 0,
"expected instantiation of template specialization");
1120 NodeManager(TreeOrLeafManagerT& tree,
bool serial =
false)
1121 :
mRoot(tree.root())
1129 void clear() { mList0.clear(); }
1133 void rebuild(
bool =
false) { mList0.initRootChildren(
mRoot); }
1145 template<
typename NodeOp>
1146 void foreachBottomUp(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1148 mList0.foreach(op, threaded, grainSize);
1152 template<
typename NodeOp>
1153 void foreachTopDown(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1156 mList0.foreach(op, threaded, grainSize);
1159 template<
typename NodeOp>
1160 void reduceBottomUp(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1162 mList0.reduce(op, threaded, grainSize);
1166 template<
typename NodeOp>
1167 void reduceTopDown(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1170 mList0.reduce(op, threaded, grainSize);
1175 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1177 using ListT0 = NodeList<NodeT0>;
1189 template<
typename TreeOrLeafManagerT>
1190 class NodeManager<TreeOrLeafManagerT, 2>
1195 static_assert(RootNodeType::LEVEL > 1,
"expected instantiation of template specialization");
1198 NodeManager(TreeOrLeafManagerT& tree,
bool serial =
false) :
mRoot(tree.root())
1206 void clear() { mList0.clear(); mList1.clear(); }
1210 void rebuild(
bool serial =
false)
1212 mList1.initRootChildren(
mRoot);
1213 mList0.initNodeChildren(mList1, NodeFilter(), serial);
1220 Index64 nodeCount()
const {
return mList0.nodeCount() + mList1.nodeCount(); }
1226 return i==0 ? mList0.nodeCount() : i==1 ? mList1.nodeCount() : 0;
1229 template<
typename NodeOp>
1230 void foreachBottomUp(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1232 mList0.foreach(op, threaded, grainSize);
1233 mList1.foreach(op, threaded, grainSize);
1237 template<
typename NodeOp>
1238 void foreachTopDown(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1241 mList1.foreach(op, threaded, grainSize);
1242 mList0.foreach(op, threaded, grainSize);
1245 template<
typename NodeOp>
1246 void reduceBottomUp(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1248 mList0.reduce(op, threaded, grainSize);
1249 mList1.reduce(op, threaded, grainSize);
1253 template<
typename NodeOp>
1254 void reduceTopDown(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1257 mList1.reduce(op, threaded, grainSize);
1258 mList0.reduce(op, threaded, grainSize);
1263 using NonConstNodeT1 =
typename NodeT2::ChildNodeType;
1265 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1268 using ListT1 = NodeList<NodeT1>;
1269 using ListT0 = NodeList<NodeT0>;
1282 template<
typename TreeOrLeafManagerT>
1283 class NodeManager<TreeOrLeafManagerT, 3>
1288 static_assert(RootNodeType::LEVEL > 2,
"expected instantiation of template specialization");
1291 NodeManager(TreeOrLeafManagerT& tree,
bool serial =
false) :
mRoot(tree.root())
1299 void clear() { mList0.clear(); mList1.clear(); mList2.clear(); }
1303 void rebuild(
bool serial =
false)
1305 mList2.initRootChildren(
mRoot);
1306 mList1.initNodeChildren(mList2, NodeFilter(), serial);
1307 mList0.initNodeChildren(mList1, NodeFilter(), serial);
1314 Index64 nodeCount()
const {
return mList0.nodeCount()+mList1.nodeCount()+mList2.nodeCount(); }
1320 return i==0 ? mList0.nodeCount() : i==1 ? mList1.nodeCount()
1321 : i==2 ? mList2.nodeCount() : 0;
1324 template<
typename NodeOp>
1325 void foreachBottomUp(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1327 mList0.foreach(op, threaded, grainSize);
1328 mList1.foreach(op, threaded, grainSize);
1329 mList2.foreach(op, threaded, grainSize);
1333 template<
typename NodeOp>
1334 void foreachTopDown(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1337 mList2.foreach(op, threaded, grainSize);
1338 mList1.foreach(op, threaded, grainSize);
1339 mList0.foreach(op, threaded, grainSize);
1342 template<
typename NodeOp>
1343 void reduceBottomUp(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1345 mList0.reduce(op, threaded, grainSize);
1346 mList1.reduce(op, threaded, grainSize);
1347 mList2.reduce(op, threaded, grainSize);
1351 template<
typename NodeOp>
1352 void reduceTopDown(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1355 mList2.reduce(op, threaded, grainSize);
1356 mList1.reduce(op, threaded, grainSize);
1357 mList0.reduce(op, threaded, grainSize);
1362 using NonConstNodeT2 =
typename NodeT3::ChildNodeType;
1364 using NonConstNodeT1 =
typename NodeT2::ChildNodeType;
1366 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1369 using ListT2 = NodeList<NodeT2>;
1370 using ListT1 = NodeList<NodeT1>;
1371 using ListT0 = NodeList<NodeT0>;
1385 template<
typename TreeOrLeafManagerT>
1386 class NodeManager<TreeOrLeafManagerT, 4>
1391 static_assert(RootNodeType::LEVEL > 3,
"expected instantiation of template specialization");
1394 NodeManager(TreeOrLeafManagerT& tree,
bool serial =
false) :
mRoot(tree.root())
1402 void clear() { mList0.clear(); mList1.clear(); mList2.clear(); mList3.clear(); }
1406 void rebuild(
bool serial =
false)
1408 mList3.initRootChildren(
mRoot);
1409 mList2.initNodeChildren(mList3, NodeFilter(), serial);
1410 mList1.initNodeChildren(mList2, NodeFilter(), serial);
1411 mList0.initNodeChildren(mList1, NodeFilter(), serial);
1420 return mList0.nodeCount() + mList1.nodeCount()
1421 + mList2.nodeCount() + mList3.nodeCount();
1428 return i==0 ? mList0.nodeCount() : i==1 ? mList1.nodeCount() :
1429 i==2 ? mList2.nodeCount() : i==3 ? mList3.nodeCount() : 0;
1432 template<
typename NodeOp>
1433 void foreachBottomUp(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1435 mList0.foreach(op, threaded, grainSize);
1436 mList1.foreach(op, threaded, grainSize);
1437 mList2.foreach(op, threaded, grainSize);
1438 mList3.foreach(op, threaded, grainSize);
1442 template<
typename NodeOp>
1443 void foreachTopDown(
const NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1446 mList3.foreach(op, threaded, grainSize);
1447 mList2.foreach(op, threaded, grainSize);
1448 mList1.foreach(op, threaded, grainSize);
1449 mList0.foreach(op, threaded, grainSize);
1452 template<
typename NodeOp>
1453 void reduceBottomUp(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1455 mList0.reduce(op, threaded, grainSize);
1456 mList1.reduce(op, threaded, grainSize);
1457 mList2.reduce(op, threaded, grainSize);
1458 mList3.reduce(op, threaded, grainSize);
1462 template<
typename NodeOp>
1463 void reduceTopDown(NodeOp& op,
bool threaded =
true,
size_t grainSize=1)
1466 mList3.reduce(op, threaded, grainSize);
1467 mList2.reduce(op, threaded, grainSize);
1468 mList1.reduce(op, threaded, grainSize);
1469 mList0.reduce(op, threaded, grainSize);
1474 using NonConstNodeT3 =
typename NodeT4::ChildNodeType;
1476 using NonConstNodeT2 =
typename NodeT3::ChildNodeType;
1478 using NonConstNodeT1 =
typename NodeT2::ChildNodeType;
1480 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1483 using ListT3 = NodeList<NodeT3>;
1484 using ListT2 = NodeList<NodeT2>;
1485 using ListT1 = NodeList<NodeT1>;
1486 using ListT0 = NodeList<NodeT0>;
1501 template<
typename TreeOrLeafManagerT>
1502 class DynamicNodeManager<TreeOrLeafManagerT, 0>
1507 static_assert(RootNodeType::LEVEL > 0,
"expected instantiation of template specialization");
1517 template<
typename NodeOp>
1524 template<
typename NodeOp>
1543 template<
typename TreeOrLeafManagerT>
1544 class DynamicNodeManager<TreeOrLeafManagerT, 1>
1549 static_assert(RootNodeType::LEVEL > 0,
"expected instantiation of template specialization");
1559 template<
typename NodeOp>
1561 size_t leafGrainSize=1,
size_t =1)
1566 if (!mList0.initRootChildren(
mRoot))
return;
1567 ForeachFilterOp<NodeOp> nodeOp(op, mList0.nodeCount());
1568 mList0.foreachWithIndex(nodeOp, threaded, leafGrainSize);
1571 template<
typename NodeOp>
1573 size_t leafGrainSize=1,
size_t =1)
1578 if (!mList0.initRootChildren(
mRoot))
return;
1579 ReduceFilterOp<NodeOp> nodeOp(op, mList0.nodeCount());
1580 mList0.reduceWithIndex(nodeOp, threaded, leafGrainSize);
1585 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1587 using ListT0 = NodeList<NodeT0>;
1599 template<
typename TreeOrLeafManagerT>
1600 class DynamicNodeManager<TreeOrLeafManagerT, 2>
1605 static_assert(RootNodeType::LEVEL > 1,
"expected instantiation of template specialization");
1615 template<
typename NodeOp>
1617 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1622 if (!mList1.initRootChildren(
mRoot))
return;
1623 ForeachFilterOp<NodeOp> nodeOp(op, mList1.nodeCount());
1624 mList1.foreachWithIndex(nodeOp, threaded, nonLeafGrainSize);
1626 if (!mList0.initNodeChildren(mList1, nodeOp, !threaded))
return;
1627 mList0.foreachWithIndex(op, threaded, leafGrainSize);
1630 template<
typename NodeOp>
1632 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1637 if (!mList1.initRootChildren(
mRoot))
return;
1638 ReduceFilterOp<NodeOp> nodeOp(op, mList1.nodeCount());
1639 mList1.reduceWithIndex(nodeOp, threaded, nonLeafGrainSize);
1641 if (!mList0.initNodeChildren(mList1, nodeOp, !threaded))
return;
1642 mList0.reduceWithIndex(op, threaded, leafGrainSize);
1647 using NonConstNodeT1 =
typename NodeT2::ChildNodeType;
1649 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1652 using ListT1 = NodeList<NodeT1>;
1653 using ListT0 = NodeList<NodeT0>;
1666 template<
typename TreeOrLeafManagerT>
1667 class DynamicNodeManager<TreeOrLeafManagerT, 3>
1672 static_assert(RootNodeType::LEVEL > 2,
"expected instantiation of template specialization");
1682 template<
typename NodeOp>
1684 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1689 if (!mList2.initRootChildren(
mRoot))
return;
1690 ForeachFilterOp<NodeOp> nodeOp2(op, mList2.nodeCount());
1691 mList2.foreachWithIndex(nodeOp2, threaded, nonLeafGrainSize);
1693 if (!mList1.initNodeChildren(mList2, nodeOp2, !threaded))
return;
1694 ForeachFilterOp<NodeOp> nodeOp1(op, mList1.nodeCount());
1695 mList1.foreachWithIndex(nodeOp1, threaded, nonLeafGrainSize);
1697 if (!mList0.initNodeChildren(mList1, nodeOp1, !threaded))
return;
1698 mList0.foreachWithIndex(op, threaded, leafGrainSize);
1701 template<
typename NodeOp>
1703 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1708 if (!mList2.initRootChildren(
mRoot))
return;
1709 ReduceFilterOp<NodeOp> nodeOp2(op, mList2.nodeCount());
1710 mList2.reduceWithIndex(nodeOp2, threaded, nonLeafGrainSize);
1712 if (!mList1.initNodeChildren(mList2, nodeOp2, !threaded))
return;
1713 ReduceFilterOp<NodeOp> nodeOp1(op, mList1.nodeCount());
1714 mList1.reduceWithIndex(nodeOp1, threaded, nonLeafGrainSize);
1716 if (!mList0.initNodeChildren(mList1, nodeOp1, !threaded))
return;
1717 mList0.reduceWithIndex(op, threaded, leafGrainSize);
1722 using NonConstNodeT2 =
typename NodeT3::ChildNodeType;
1724 using NonConstNodeT1 =
typename NodeT2::ChildNodeType;
1726 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1729 using ListT2 = NodeList<NodeT2>;
1730 using ListT1 = NodeList<NodeT1>;
1731 using ListT0 = NodeList<NodeT0>;
1745 template<
typename TreeOrLeafManagerT>
1746 class DynamicNodeManager<TreeOrLeafManagerT, 4>
1751 static_assert(RootNodeType::LEVEL > 3,
"expected instantiation of template specialization");
1761 template<
typename NodeOp>
1763 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1768 if (!mList3.initRootChildren(
mRoot))
return;
1769 ForeachFilterOp<NodeOp> nodeOp3(op, mList3.nodeCount());
1770 mList3.foreachWithIndex(nodeOp3, threaded, nonLeafGrainSize);
1772 if (!mList2.initNodeChildren(mList3, nodeOp3, !threaded))
return;
1773 ForeachFilterOp<NodeOp> nodeOp2(op, mList2.nodeCount());
1774 mList2.foreachWithIndex(nodeOp2, threaded, nonLeafGrainSize);
1776 if (!mList1.initNodeChildren(mList2, nodeOp2, !threaded))
return;
1777 ForeachFilterOp<NodeOp> nodeOp1(op, mList1.nodeCount());
1778 mList1.foreachWithIndex(nodeOp1, threaded, nonLeafGrainSize);
1780 if (!mList0.initNodeChildren(mList1, nodeOp1, !threaded))
return;
1781 mList0.foreachWithIndex(op, threaded, leafGrainSize);
1784 template<
typename NodeOp>
1786 size_t leafGrainSize=1,
size_t nonLeafGrainSize=1)
1791 if (!mList3.initRootChildren(
mRoot))
return;
1792 ReduceFilterOp<NodeOp> nodeOp3(op, mList3.nodeCount());
1793 mList3.reduceWithIndex(nodeOp3, threaded, nonLeafGrainSize);
1795 if (!mList2.initNodeChildren(mList3, nodeOp3, !threaded))
return;
1796 ReduceFilterOp<NodeOp> nodeOp2(op, mList2.nodeCount());
1797 mList2.reduceWithIndex(nodeOp2, threaded, nonLeafGrainSize);
1799 if (!mList1.initNodeChildren(mList2, nodeOp2, !threaded))
return;
1800 ReduceFilterOp<NodeOp> nodeOp1(op, mList1.nodeCount());
1801 mList1.reduceWithIndex(nodeOp1, threaded, nonLeafGrainSize);
1803 if (!mList0.initNodeChildren(mList1, nodeOp1, !threaded))
return;
1804 mList0.reduceWithIndex(op, threaded, leafGrainSize);
1809 using NonConstNodeT3 =
typename NodeT4::ChildNodeType;
1811 using NonConstNodeT2 =
typename NodeT3::ChildNodeType;
1813 using NonConstNodeT1 =
typename NodeT2::ChildNodeType;
1815 using NonConstNodeT0 =
typename NodeT1::ChildNodeType;
1818 using ListT3 = NodeList<NodeT3>;
1819 using ListT2 = NodeList<NodeT2>;
1820 using ListT1 = NodeList<NodeT1>;
1821 using ListT0 = NodeList<NodeT0>;
1835 #endif // OPENVDB_TREE_NODEMANAGER_HAS_BEEN_INCLUDED
NodeRange(size_t begin, size_t end, const NodeList &nodeList, size_t grainSize=1)
NodeT * operator->() const
Return a pointer to the node to which this iterator is pointing.
void reduceTopDown(NodeOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that processes nodes with a user supplied functor.
bool valid(size_t idx) const
static const Index LEVELS
void foreachTopDown(const NodeOpT &op, RootT &root, bool threaded, size_t leafGrainSize, size_t nonLeafGrainSize)
ReduceFilterOp(const ReduceFilterOp &other)
static bool valid(size_t)
Index64 nodeCount() const
Return the total number of cached nodes (excluding the root node)
NodeRange(NodeRange &r, tbb::split)
const NonConstRootNodeType & root() const
Return a reference to the root node.
typename ChildNodeType::ChildNodeType NonConstChildNodeType
void foreachTopDownRecurse(const FilterOpT &filterOp, ParentT &parent, bool threaded, size_t leafGrainSize, size_t nonLeafGrainSize)
NodeT & operator*() const
Return a reference to the node to which this iterator is pointing.
bool is_divisible() const
void reduceTopDown(NodeOpT &op, RootT &root, bool threaded, size_t leafGrainSize, size_t nonLeafGrainSize)
Iterator & operator++()
Advance to the next node.
Iterator(const NodeRange &range, size_t pos)
#define OPENVDB_USE_VERSION_NAMESPACE
ForeachFilterOp(const OpT &op, openvdb::Index64 size)
Index64 nodeCount(Index i) const
**But if you need a or simply need to know when the task has note that the like this
bool valid(size_t idx) const
void reduceTopDown(NodeOp &op, bool threaded, size_t grainSize)
NodeManager(TreeOrLeafManagerT &tree, bool serial=false)
void clear()
Clear all the cached tree nodes.
This class caches tree nodes of a specific type in a linear array.
void reduceTopDown(NodeOp &op, bool threaded=true, size_t leafGrainSize=1, size_t nonLeafGrainSize=1)
Threaded method that processes nodes with a user supplied functor.
ForeachFilterOp(const ForeachFilterOp &other)
NodeT & operator()(size_t n) const
NodeT *& operator[](size_t n)
typename CopyConstness< TreeOrLeafManagerT, NonConstChildNodeType >::Type ChildNodeType
NodeManagerLink()=default
#define OPENVDB_ASSERT(X)
void foreachTopDown(const NodeOp &op, bool threaded=true, size_t leafGrainSize=1, size_t nonLeafGrainSize=1)
Threaded method that applies a user-supplied functor to all the nodes in the tree.
Index64 nodeCount() const
To facilitate threading over the nodes of a tree, cache node pointers in linear arrays, one for each level of the tree.
typename CopyConstness< TreeOrLeafManagerT, NonConstChildNodeType >::Type ChildNodeType
void reduce(NodeOp &op, bool threaded=true, size_t grainSize=1)
void foreachWithIndex(const NodeOp &op, bool threaded=true, size_t grainSize=1)
void rebuild(bool serial=false)
Clear and recache all the tree nodes from the tree. This is required if tree nodes have been added or...
void foreachBottomUp(const NodeOp &op, bool threaded, size_t grainSize)
DynamicNodeManagerLink< ChildNodeType, LEVEL-1 > mNext
void operator()(NodeT &node, size_t idx) const
void foreachBottomUp(const NodeOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to all the nodes in the tree.
typename RootNodeType::ChildNodeType NonConstChildNodeType
void initRootChildren(RootT &root, bool serial=false)
size_t pos() const
Return the index into the list of the current node.
void operator()(NodeT &node, size_t idx) const
typename std::remove_const< ToType >::type Type
ReduceFilterOp(OpT &op, openvdb::Index64 size)
OIIO_UTIL_API void parallel_for(int32_t begin, int32_t end, function_view< void(int32_t)> task, paropt opt=0)
void reduceBottomUp(NodeOp &op, bool threaded, size_t grainSize)
void foreachTopDown(const NodeOp &op, bool threaded, size_t grainSize)
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
void join(const ReduceFilterOp &other)
typename CopyConstness< TreeOrLeafManagerT, NonConstRootNodeType >::Type RootNodeType
HUSD_API bool eval(VtValue &val, T &ret_val)
Index64 nodeCount(Index i) const
Return the number of cached nodes at level i, where 0 corresponds to the lowest level.
bool operator==(const Iterator &other) const
GA_API const UT_StringHolder transform
const RootNodeType & root() const
Return a reference to the root node.
bool initRootChildren(RootT &root)
typename TreeOrLeafManagerT::RootNodeType NonConstRootNodeType
typename CopyConstness< TreeOrLeafManagerT, NonConstRootNodeType >::Type RootNodeType
typename TreeOrLeafManagerT::RootNodeType NonConstRootNodeType
typename CopyConstness< ChildNodeType, NonConstChildNodeType >::Type ChildNodeType
bool initNodeChildren(ParentsT &parents, const NodeFilterT &nodeFilter=NodeFilterT(), bool serial=false)
void reduceBottomUp(NodeOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that processes nodes with a user supplied functor.
DynamicNodeManager(TreeOrLeafManagerT &tree)
Index64 nodeCount() const
static const Index LEVELS
DynamicNodeManagerLink< ChildNodeType, LEVELS-1 > mChain
void initNodeChildren(ParentsT &parents, bool serial=false)
std::unique_ptr< NodeT *[]> mNodePtrs
bool empty() const
Return true if this iterator is exhausted.
typename RootNodeType::ChildNodeType NonConstChildNodeType
This class is a link in a chain that each caches tree nodes of a specific type in a linear array...
Iterator & operator=(const Iterator &)=default
typename CopyConstness< ChildNodeType, NonConstChildNodeType >::Type ChildNodeType
void reduceWithIndex(NodeOp &op, bool threaded=true, size_t grainSize=1)
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
NodeManagerLink< ChildNodeType, LEVEL-1 > mNext
void reduceTopDownRecurse(FilterOpT &filterOp, ParentT &parent, bool threaded, size_t leafGrainSize, size_t nonLeafGrainSize)
ReduceFilterOp(const ReduceFilterOp &other, tbb::split)
const NodeRange & nodeRange() const
This class is a link in a chain that each caches tree nodes of a specific type in a linear array...
DynamicNodeManagerLink()=default
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
const NodeList & nodeList() const
bool operator!=(const Iterator &other) const
void foreachTopDown(const NodeOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to all the nodes in the tree.
NodeRange nodeRange(size_t grainsize=1) const
Return a TBB-compatible NodeRange.
bool test() const
Return true if this iterator is not yet exhausted.
typename ChildNodeType::ChildNodeType NonConstChildNodeType
NodeManagerLink< ChildNodeType, LEVELS-1 > mChain