Skip to content

Commit

Permalink
Move root testing from TestTree to TestRootNode
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Bailey <[email protected]>
  • Loading branch information
danrbailey committed Oct 11, 2024
1 parent 5fa0d4b commit 95de511
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 96 deletions.
96 changes: 96 additions & 0 deletions openvdb/openvdb/unittest/TestRootNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,102 @@ class TestRoot: public ::testing::Test


TEST_F(TestRoot, test)
{
using ChildType = RootNodeType::ChildNodeType;
const openvdb::Coord c0(0,0,0), c1(49152, 16384, 28672);

{ // test inserting child nodes directly and indirectly
RootNodeType root(0.0f);
EXPECT_TRUE(root.empty());
EXPECT_EQ(openvdb::Index32(0), root.childCount());

// populate the tree by inserting the two leaf nodes containing c0 and c1
root.touchLeaf(c0);
root.touchLeaf(c1);
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(2), root.childCount());
EXPECT_TRUE(!root.hasActiveTiles());

{ // verify c0 and c1 are the root node coordinates
auto rootIter = root.cbeginChildOn();
EXPECT_EQ(c0, rootIter.getCoord());
++rootIter;
EXPECT_EQ(c1, rootIter.getCoord());
}

// copy the root node
RootNodeType rootCopy(root);

// steal the root node children leaving the root node empty again
std::vector<ChildType*> children;
root.stealNodes(children);
EXPECT_TRUE(root.empty());

// insert the root node children directly
for (ChildType* child : children) {
root.addChild(child);
}
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(2), root.childCount());

{ // verify the coordinates of the root node children
auto rootIter = root.cbeginChildOn();
EXPECT_EQ(c0, rootIter.getCoord());
++rootIter;
EXPECT_EQ(c1, rootIter.getCoord());
}
}

{ // test inserting tiles and replacing them with child nodes
RootNodeType root(0.0f);
EXPECT_TRUE(root.empty());

// no-op
root.addChild(nullptr);

// populate the root node by inserting tiles
root.addTile(c0, /*value=*/1.0f, /*state=*/true);
root.addTile(c1, /*value=*/2.0f, /*state=*/true);
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(0), root.childCount());
EXPECT_TRUE(root.hasActiveTiles());
ASSERT_DOUBLES_EXACTLY_EQUAL(1.0f, root.getValue(c0));
ASSERT_DOUBLES_EXACTLY_EQUAL(2.0f, root.getValue(c1));

// insert child nodes with the same coordinates
root.addChild(new ChildType(c0, 3.0f));
root.addChild(new ChildType(c1, 4.0f));

// insert a new child at c0
root.addChild(new ChildType(c0, 5.0f));

// verify active tiles have been replaced by child nodes
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(2), root.childCount());
EXPECT_TRUE(!root.hasActiveTiles());

{ // verify the coordinates of the root node children
auto rootIter = root.cbeginChildOn();
EXPECT_EQ(c0, rootIter.getCoord());
ASSERT_DOUBLES_EXACTLY_EQUAL(5.0f, root.getValue(c0));
++rootIter;
EXPECT_EQ(c1, rootIter.getCoord());
}
}

{ // test transient data
RootNodeType rootNode(0.0f);
EXPECT_EQ(openvdb::Index32(0), rootNode.transientData());
rootNode.setTransientData(openvdb::Index32(5));
EXPECT_EQ(openvdb::Index32(5), rootNode.transientData());
RootNodeType rootNode2(rootNode);
EXPECT_EQ(openvdb::Index32(5), rootNode2.transientData());
RootNodeType rootNode3 = rootNode;
EXPECT_EQ(openvdb::Index32(5), rootNode3.transientData());
}
}

TEST_F(TestRoot, testMap)
{
using RootNode = FloatTree::RootNodeType;

Expand Down
96 changes: 0 additions & 96 deletions openvdb/openvdb/unittest/TestTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2756,102 +2756,6 @@ TEST_F(TestTree, testNodeCount)
for (size_t i=0; i<nodeCount2.size(); ++i) EXPECT_EQ( nodeCount1[i], nodeCount2[i]);
}

TEST_F(TestTree, testRootNode)
{
using ChildType = RootNodeType::ChildNodeType;
const openvdb::Coord c0(0,0,0), c1(49152, 16384, 28672);

{ // test inserting child nodes directly and indirectly
RootNodeType root(0.0f);
EXPECT_TRUE(root.empty());
EXPECT_EQ(openvdb::Index32(0), root.childCount());

// populate the tree by inserting the two leaf nodes containing c0 and c1
root.touchLeaf(c0);
root.touchLeaf(c1);
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(2), root.childCount());
EXPECT_TRUE(!root.hasActiveTiles());

{ // verify c0 and c1 are the root node coordinates
auto rootIter = root.cbeginChildOn();
EXPECT_EQ(c0, rootIter.getCoord());
++rootIter;
EXPECT_EQ(c1, rootIter.getCoord());
}

// copy the root node
RootNodeType rootCopy(root);

// steal the root node children leaving the root node empty again
std::vector<ChildType*> children;
root.stealNodes(children);
EXPECT_TRUE(root.empty());

// insert the root node children directly
for (ChildType* child : children) {
root.addChild(child);
}
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(2), root.childCount());

{ // verify the coordinates of the root node children
auto rootIter = root.cbeginChildOn();
EXPECT_EQ(c0, rootIter.getCoord());
++rootIter;
EXPECT_EQ(c1, rootIter.getCoord());
}
}

{ // test inserting tiles and replacing them with child nodes
RootNodeType root(0.0f);
EXPECT_TRUE(root.empty());

// no-op
root.addChild(nullptr);

// populate the root node by inserting tiles
root.addTile(c0, /*value=*/1.0f, /*state=*/true);
root.addTile(c1, /*value=*/2.0f, /*state=*/true);
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(0), root.childCount());
EXPECT_TRUE(root.hasActiveTiles());
ASSERT_DOUBLES_EXACTLY_EQUAL(1.0f, root.getValue(c0));
ASSERT_DOUBLES_EXACTLY_EQUAL(2.0f, root.getValue(c1));

// insert child nodes with the same coordinates
root.addChild(new ChildType(c0, 3.0f));
root.addChild(new ChildType(c1, 4.0f));

// insert a new child at c0
root.addChild(new ChildType(c0, 5.0f));

// verify active tiles have been replaced by child nodes
EXPECT_EQ(openvdb::Index(2), root.getTableSize());
EXPECT_EQ(openvdb::Index32(2), root.childCount());
EXPECT_TRUE(!root.hasActiveTiles());

{ // verify the coordinates of the root node children
auto rootIter = root.cbeginChildOn();
EXPECT_EQ(c0, rootIter.getCoord());
ASSERT_DOUBLES_EXACTLY_EQUAL(5.0f, root.getValue(c0));
++rootIter;
EXPECT_EQ(c1, rootIter.getCoord());
}
}

{ // test transient data
RootNodeType rootNode(0.0f);
EXPECT_EQ(openvdb::Index32(0), rootNode.transientData());
rootNode.setTransientData(openvdb::Index32(5));
EXPECT_EQ(openvdb::Index32(5), rootNode.transientData());
RootNodeType rootNode2(rootNode);
EXPECT_EQ(openvdb::Index32(5), rootNode2.transientData());
RootNodeType rootNode3 = rootNode;
EXPECT_EQ(openvdb::Index32(5), rootNode3.transientData());
}
}

TEST_F(TestTree, testInternalNode)
{
const openvdb::Coord c0(1000, 1000, 1000);
Expand Down

0 comments on commit 95de511

Please sign in to comment.