Skip to content

Commit 1ba2520

Browse files
committed
Added a unittest for LeafManager construction from different tree configurations
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
1 parent 2908fd3 commit 1ba2520

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

openvdb/openvdb/unittest/TestLeafManager.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: MPL-2.0
33

44
#include <openvdb/Types.h>
5+
#include <openvdb/TypeList.h>
56
#include <openvdb/tree/LeafManager.h>
67
#include <openvdb/util/CpuTimer.h>
78
#include "util.h" // for unittest_util::makeSphere()
@@ -304,3 +305,36 @@ TEST_F(TestLeafManager, testReduce)
304305
}
305306
EXPECT_EQ(FloatTree::LeafNodeType::numValues(), n);
306307
}
308+
309+
TEST_F(TestLeafManager, testTreeConfigurations)
310+
{
311+
using Tree2Type = openvdb::tree::Tree<
312+
openvdb::tree::RootNode<
313+
openvdb::tree::LeafNode<float, 3> > >;
314+
using Tree3Type = openvdb::tree::Tree3<float, 4, 3>::Type;
315+
using Tree4Type = openvdb::tree::Tree4<float, 5, 4, 3>::Type;
316+
using Tree5Type = openvdb::tree::Tree5<float, 5, 5, 4, 3>::Type;
317+
318+
using TestConfigurations = openvdb::TypeList<
319+
Tree2Type, Tree3Type, Tree4Type, Tree5Type
320+
>;
321+
322+
TestConfigurations::foreach([](auto tree) {
323+
using TreeType = typename std::decay<decltype(tree)>::type;
324+
using LeafNodeType = typename TreeType::LeafNodeType;
325+
using LeafManagerT = openvdb::tree::LeafManager<TreeType>;
326+
327+
// Add 20 leaf nodes and make sure they are parsed correctly
328+
constexpr int64_t Count = 20;
329+
std::array<LeafNodeType*, Count> ptrs;
330+
331+
const int64_t start = -(Count/2)*LeafNodeType::DIM;
332+
const int64_t end = (Count/2)*LeafNodeType::DIM;
333+
for (int64_t idx = start; idx < end; idx+=LeafNodeType::DIM) {
334+
ptrs[idx] = tree.touchLeaf(openvdb::math::Coord(idx));
335+
}
336+
EXPECT_EQ(tree.leafCount(), Count);
337+
LeafManagerT manager(tree);
338+
EXPECT_EQ(manager.leafCount(), Count);
339+
});
340+
}

0 commit comments

Comments
 (0)