17 #include "../NanoVDB.h" 20 #ifndef NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED 21 #define NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED 26 template<
typename Gr
idT>
30 template<
typename Gr
idT>
34 template<
typename Gr
idT>
38 template<
typename Gr
idT>
45 template<
typename Gr
idT>
51 using RootT = NodeT<3>;
52 using Node2 = NodeT<2>;
53 using Node1 = NodeT<1>;
54 using Node0 = NodeT<0>;
57 void sequential(T **nodes);
82 bool empty()
const {
return mGrid ==
nullptr; }
88 GridT*
grid() {
return mGrid; }
91 TreeT*
tree() {
return mTree; }
94 RootT*
root() {
return mRoot; }
97 uint64_t
nodeCount(
int level)
const {
return mNodeCount[level]; }
102 Node0*
leaf( uint32_t i)
const {
return mLeafs[i]; }
107 Node1*
lower(uint32_t i)
const {
return mLower[i]; }
112 Node2*
upper(uint32_t i)
const {
return mUpper[i]; }
121 uint64_t mNodeCount[3];
127 template<
typename Gr
idT>
139 template<
typename Gr
idT>
142 , mTree(&grid.
tree())
144 , mNodeCount{mTree->nodeCount(0), mTree->nodeCount(1), mTree->nodeCount(2)}
145 , mUpper(
new Node2*[mNodeCount[2]])
146 , mLower(
new Node1*[mNodeCount[1]])
147 , mLeafs(
new Node0*[mNodeCount[0]])
150 if (Node0::FIXED_SIZE && Node1::FIXED_SIZE && Node2::FIXED_SIZE &&
151 grid.isBreadthFirst()) {
153 invoke([&](){this->sequential(mLeafs);},
154 [&](){this->sequential(mLower);},
155 [&](){this->sequential(mUpper);});
157 this->sequential(mLeafs);
158 this->sequential(mLower);
159 this->sequential(mUpper);
162 auto **ptr2 = mUpper;
163 auto **ptr1 = mLower;
164 auto **ptr0 = mLeafs;
165 auto *data3 = mRoot->data();
167 for (uint32_t i=0, size=data3->mTableSize; i<size; ++i) {
168 auto *tile = data3->tile(i);
169 if (!tile->isChild())
continue;
170 Node2 *node2 = data3->getChild(tile);
172 auto *data2 = node2->data();
173 for (
auto it2 = data2->mChildMask.beginOn(); it2; ++it2) {
174 Node1 *node1 = data2->getChild(*it2);
176 auto *data1 = node1->data();
177 for (
auto it1 = data1->mChildMask.beginOn(); it1; ++it1) {
178 Node0 *node0 = data1->getChild(*it1);
186 template<
typename Gr
idT>
191 , mNodeCount{other.mNodeCount[0],other.mNodeCount[1],other.mNodeCount[2]}
192 , mUpper(other.mUpper)
193 , mLower(other.mLower)
194 , mLeafs(other.mLeafs)
196 other.mGrid =
nullptr;
197 other.mTree =
nullptr;
198 other.mRoot =
nullptr;
199 other.mNodeCount[0] = 0;
200 other.mNodeCount[1] = 0;
201 other.mNodeCount[2] = 0;
202 other.mUpper =
nullptr;
203 other.mLower =
nullptr;
204 other.mLeafs =
nullptr;
207 template<
typename Gr
idT>
214 mNodeCount[0] = other.mNodeCount[0];
215 mNodeCount[1] = other.mNodeCount[1];
216 mNodeCount[2] = other.mNodeCount[2];
217 mUpper = other.mUpper;
218 mLower = other.mLower;
219 mLeafs = other.mLeafs;
221 other.mGrid =
nullptr;
222 other.mTree =
nullptr;
223 other.mRoot =
nullptr;
224 other.mNodeCount[0] = 0;
225 other.mNodeCount[1] = 0;
226 other.mNodeCount[2] = 0;
227 other.mUpper =
nullptr;
228 other.mLower =
nullptr;
229 other.mLeafs =
nullptr;
234 template<
typename Gr
idT>
242 template<
typename Gr
idT>
245 return sizeof(*this) +
246 mNodeCount[0]*
sizeof(Node0*) +
247 mNodeCount[1]*
sizeof(Node1*) +
248 mNodeCount[2]*
sizeof(Node2*);
251 template<
typename Gr
idT>
259 template<
typename Gr
idT>
260 template <
typename T>
264 auto *ptr = mTree->template getFirstNode<T>();
265 uint64_t n = mNodeCount[T::LEVEL] / 4;
272 n = mNodeCount[T::LEVEL] % 4;
280 template<
typename Gr
idT>
308 bool empty()
const {
return mGrid ==
nullptr; }
311 size_t memUsage()
const {
return sizeof(*this) + mSize*
sizeof(LeafT*); }
314 GridT*
grid() {
return mGrid; }
317 uint32_t
size()
const {
return mSize; };
332 template<
typename Gr
idT>
334 : mGrid(&grid), mSize(grid.
tree().
nodeCount(0)), mLeafs(nullptr)
337 mLeafs =
new LeafT*[mSize];
338 auto **leafs = mLeafs;
339 if (grid.template isSequential<LeafT>()) {
340 auto *ptr = grid.tree().template getFirstNode<LeafT>();
341 uint64_t n = mSize / 4;
353 auto *data3 = grid.tree().root().data();
354 for (uint32_t i=0,
size=data3->mTableSize; i<
size; ++i) {
355 auto *tile = data3->tile(i);
356 if (!tile->isChild())
continue;
357 auto *data2 = data3->getChild(tile)->data();
358 for (
auto it2 = data2->mChildMask.beginOn(); it2; ++it2) {
359 auto *data1 = data2->getChild(*it2)->data();
360 for (
auto it1 = data1->mChildMask.beginOn(); it1; ++it1) {
361 *leafs++ = data1->getChild(*it1);
369 template<
typename Gr
idT>
374 mLeafs = other.mLeafs;
375 other.mGrid =
nullptr;
377 other.mLeafs =
nullptr;
380 template<
typename Gr
idT>
386 mLeafs = other.mLeafs;
387 other.mGrid =
nullptr;
389 other.mLeafs =
nullptr;
393 template<
typename Gr
idT>
402 #endif // NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED GridT * grid()
Return a pointer to the grid, or NULL if it is uninitialized.
Definition: NodeManager.h:314
A unified wrapper for tbb::parallel_invoke and a naive std::thread analog.
LeafNanager maintains a linear array of leaf nodes.
Definition: NodeManager.h:31
Node2 * upper(uint32_t i) const
Return the i'th upper internal node.
Definition: NodeManager.h:112
NodeManager< GridT > createNodeMgr(GridT &grid)
creates a NodeManager from a grid. Move semantics is used.
Definition: NodeManager.h:252
Definition: NanoVDB.h:184
Struct to derive node type from its level in a given grid, tree or root while perserving constness...
Definition: NanoVDB.h:2096
typename GridT::TreeType type
Definition: NanoVDB.h:2529
LeafManager & operator=(const LeafManager &)=delete
Disallow copy assignment operator.
NodeManager & operator=(const NodeManager &)=delete
Disallow copy assignment operator.
GridT * grid()
Return a pointer to the grid, or NULL if it is uninitialized.
Definition: NodeManager.h:88
bool empty() const
Return true of this instance is uninitialized.
Definition: NodeManager.h:82
bool empty() const
Return true of this instance is un-initialized.
Definition: NodeManager.h:308
~LeafManager()
Destructor.
Definition: NodeManager.h:299
Node0 * leaf(uint32_t i) const
Return the i'th leaf node.
Definition: NodeManager.h:102
#define NANOVDB_ASSERT(x)
Definition: NanoVDB.h:149
RootT * root()
Return a pointer to the root, or NULL if it is uninitialized.
Definition: NodeManager.h:94
size_t memUsage() const
Return the memory footprint in bytes of this instance.
Definition: NodeManager.h:243
NodeNanager maintains separate linear arrays of the three nodes types.
Definition: NodeManager.h:27
LeafT * operator[](uint32_t i) const
Return the i'th leaf node.
Definition: NodeManager.h:322
uint64_t nodeCount(int level) const
Return the number of tree nodes at the specified level.
Definition: NodeManager.h:97
Node1 * lower(uint32_t i) const
Return the i'th lower internal node.
Definition: NodeManager.h:107
NodeManager()
Empty constructor.
Definition: NodeManager.h:128
size_t memUsage() const
Return the memory footprint in bytes of this instance.
Definition: NodeManager.h:311
~NodeManager()
Destructor.
Definition: NodeManager.h:73
uint32_t size() const
Return the number of leaf nodes.
Definition: NodeManager.h:317
TreeT * tree()
Return a pointer to the tree, or NULL if it is uninitialized.
Definition: NodeManager.h:91
LeafManager< GridT > createLeafMgr(GridT &grid)
creates a LeafManager from a grid. Move semantics is used.
Definition: NodeManager.h:394
LeafManager()
Empty constructor.
Definition: NodeManager.h:287
int invoke(const Func &taskFunc1, Rest...taskFuncN)
Definition: Invoke.h:64