GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestPointPartitioner.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 27 27 100.0%
Functions: 1 1 100.0%
Branches: 28 184 15.2%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/tools/PointPartitioner.h>
5 #include <gtest/gtest.h>
6
7 #include <vector>
8
9
10 1 class TestPointPartitioner: public ::testing::Test
11 {
12 };
13
14
15 ////////////////////////////////////////
16
17 namespace {
18
19 struct PointList {
20 typedef openvdb::Vec3s PosType;
21
22 1 PointList(const std::vector<PosType>& points) : mPoints(&points) {}
23
24
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
6 size_t size() const { return mPoints->size(); }
25
26
1/2
✓ Branch 0 taken 10000 times.
✗ Branch 1 not taken.
10000 void getPos(size_t n, PosType& xyz) const { xyz = (*mPoints)[n]; }
27
28 protected:
29 std::vector<PosType> const * const mPoints;
30 }; // PointList
31
32 } // namespace
33
34 ////////////////////////////////////////
35
36
37
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestPointPartitioner, testPartitioner)
38 {
39 const size_t pointCount = 10000;
40 const float voxelSize = 0.1f;
41
42 1 std::vector<openvdb::Vec3s> points(pointCount, openvdb::Vec3s(0.f));
43
2/2
✓ Branch 0 taken 9999 times.
✓ Branch 1 taken 1 times.
10000 for (size_t n = 1; n < pointCount; ++n) {
44 9999 points[n].x() = points[n-1].x() + voxelSize;
45 }
46
47 PointList pointList(points);
48
49 const openvdb::math::Transform::Ptr transform =
50
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(voxelSize);
51
52 typedef openvdb::tools::UInt32PointPartitioner PointPartitioner;
53
54 PointPartitioner::Ptr partitioner =
55
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointPartitioner::create(pointList, *transform);
56
57
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(!partitioner->empty());
58
59 // The default interpretation should be cell-centered.
60
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(partitioner->usingCellCenteredTransform());
61
62
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t expectedPageCount = pointCount / (1u << PointPartitioner::LOG2DIM);
63
64
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.
1 EXPECT_EQ(expectedPageCount, partitioner->size());
65
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(openvdb::Coord(0), partitioner->origin(0));
66
67 1 PointPartitioner::IndexIterator it = partitioner->indices(0);
68
69
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(it.test());
70
2/18
✓ 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.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ(it.size(), size_t(1 << PointPartitioner::LOG2DIM));
71
72 1 PointPartitioner::IndexIterator itB = partitioner->indices(0);
73
74
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(++it, ++itB);
75
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(it != ++itB);
76
77 std::vector<PointPartitioner::IndexType> indices;
78
79
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (it.reset(); it; ++it) {
80
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 indices.push_back(*it);
81 }
82
83
2/18
✓ 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.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ(it.size(), indices.size());
84
85 size_t idx = 0;
86
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (itB.reset(); itB; ++itB) {
87
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(indices[idx++], *itB);
88 }
89 1 }
90
91