GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestLeafOrigin.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 37 38 97.4%
Functions: 5 5 100.0%
Branches: 38 160 23.8%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/Exceptions.h>
5 #include <openvdb/tree/Tree.h>
6 #include <openvdb/tree/LeafNode.h>
7 #include <openvdb/math/Transform.h>
8 #include <openvdb/openvdb.h>
9 #include <openvdb/Types.h>
10
11 #include <gtest/gtest.h>
12
13 #include <set>
14
15
16 3 class TestLeafOrigin: public ::testing::Test
17 {
18 public:
19 3 void SetUp() override { openvdb::initialize(); }
20 3 void TearDown() override { openvdb::uninitialize(); }
21 };
22
23
24 ////////////////////////////////////////
25
26
27
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 TEST_F(TestLeafOrigin, test)
28 {
29 using namespace openvdb;
30
31 std::set<Coord> indices;
32
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 indices.insert(Coord( 0, 0, 0));
33
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 indices.insert(Coord( 1, 0, 0));
34
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 indices.insert(Coord( 0, 100, 8));
35
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 indices.insert(Coord(-9, 0, 8));
36
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 indices.insert(Coord(32, 0, 16));
37
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 indices.insert(Coord(33, -5, 16));
38
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 indices.insert(Coord(42, 17, 35));
39 indices.insert(Coord(43, 17, 64));
40
41 2 FloatTree tree(/*bg=*/256.0);
42 1 std::set<Coord>::iterator iter = indices.begin();
43
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
9 for ( ; iter != indices.end(); ++iter) tree.setValue(*iter, 1.0);
44
45
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 for (FloatTree::LeafCIter leafIter = tree.cbeginLeaf(); leafIter; ++leafIter) {
46 const Int32 mask = ~((1 << leafIter->log2dim()) - 1);
47 const Coord leafOrigin = leafIter->origin();
48 for (FloatTree::LeafNodeType::ValueOnCIter valIter = leafIter->cbeginValueOn();
49
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 7 times.
15 valIter; ++valIter)
50 {
51
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 Coord xyz = valIter.getCoord();
52
2/16
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
8 EXPECT_EQ(leafOrigin, xyz & mask);
53
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 iter = indices.find(xyz);
55
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
8 EXPECT_TRUE(iter != indices.end());
56 8 indices.erase(iter);
57 }
58 }
59
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(indices.empty());
60 1 }
61
62
63
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLeafOrigin, test2Values)
64 {
65 using namespace openvdb;
66
67
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = createGrid<FloatGrid>(/*bg=*/1.0f);
68 FloatTree& tree = grid->tree();
69
70
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(Coord(0, 0, 0), 5);
71
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(Coord(100, 0, 0), 6);
72
73
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
2 grid->setTransform(math::Transform::createLinearTransform(0.1));
74
75 FloatTree::LeafCIter iter = tree.cbeginLeaf();
76
1/14
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(Coord(0, 0, 0), iter->origin());
77 ++iter;
78
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
1 EXPECT_EQ(Coord(96, 0, 0), iter->origin());
79 1 }
80
81
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLeafOrigin, testGetValue)
82 {
83 const openvdb::Coord c0(0,-10,0), c1(100,13,0);
84 1 const float v0=5.0f, v1=6.0f, v2=1.0f;
85 1 openvdb::FloatTree::Ptr tree(new openvdb::FloatTree(v2));
86
87 tree->setValue(c0, v0);
88 tree->setValue(c1, v1);
89
90 openvdb::FloatTree::LeafCIter iter = tree->cbeginLeaf();
91
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
2 EXPECT_EQ(v0, iter->getValue(c0));
92 ++iter;
93
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
2 EXPECT_EQ(v1, iter->getValue(c1));
94 1 }
95