GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestPointIndexGrid.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 93 93 100.0%
Functions: 5 5 100.0%
Branches: 101 454 22.2%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/tools/PointIndexGrid.h>
5
6 #include <gtest/gtest.h>
7
8 #include <vector>
9 #include <algorithm>
10 #include <cmath>
11 #include "util.h" // for genPoints
12
13
14 3 struct TestPointIndexGrid: public ::testing::Test
15 {
16 };
17
18
19 ////////////////////////////////////////
20
21 namespace {
22
23 class PointList
24 {
25 public:
26 typedef openvdb::Vec3R PosType;
27
28 PointList(const std::vector<PosType>& points)
29
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.
3 : mPoints(&points)
30 {
31 }
32
33 size_t size() const {
34
5/10
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
36 return mPoints->size();
35 }
36
37 void getPos(size_t n, PosType& xyz) const {
38
5/6
✓ Branch 0 taken 1090000 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 40084 times.
✓ Branch 4 taken 91 times.
✓ Branch 6 taken 56648 times.
✓ Branch 7 taken 41046 times.
1369432 xyz = (*mPoints)[n];
39 }
40
41 protected:
42 std::vector<PosType> const * const mPoints;
43 }; // PointList
44
45
46 template<typename T>
47 3 bool hasDuplicates(const std::vector<T>& items)
48 {
49 3 std::vector<T> vec(items);
50 3 std::sort(vec.begin(), vec.end());
51
52 size_t duplicates = 0;
53
2/2
✓ Branch 0 taken 82209 times.
✓ Branch 1 taken 3 times.
82212 for (size_t n = 1, N = vec.size(); n < N; ++n) {
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82209 times.
82209 if (vec[n] == vec[n-1]) ++duplicates;
55 }
56
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 return duplicates != 0;
57 }
58
59
60 template<typename T>
61 struct WeightedAverageAccumulator {
62 typedef T ValueType;
63 1 WeightedAverageAccumulator(T const * const array, const T radius)
64 1 : mValues(array), mInvRadius(1.0/radius), mWeightSum(0.0), mValueSum(0.0) {}
65
66
1/2
✓ Branch 1 taken 10000 times.
✗ Branch 2 not taken.
10000 void reset() { mWeightSum = mValueSum = T(0.0); }
67
68 56648 void operator()(const T distSqr, const size_t pointIndex) {
69 56648 const T weight = T(1.0) - openvdb::math::Sqrt(distSqr) * mInvRadius;
70 56648 mWeightSum += weight;
71 56648 mValueSum += weight * mValues[pointIndex];
72 56648 }
73
74
1/2
✓ Branch 0 taken 10000 times.
✗ Branch 1 not taken.
10000 T result() const { return mWeightSum > T(0.0) ? mValueSum / mWeightSum : T(0.0); }
75
76 private:
77 T const * const mValues;
78 const T mInvRadius;
79 T mWeightSum, mValueSum;
80 }; // struct WeightedAverageAccumulator
81
82 } // namespace
83
84
85
86 ////////////////////////////////////////
87
88
89
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPointIndexGrid, testPointIndexGrid)
90 {
91 const float voxelSize = 0.01f;
92 const openvdb::math::Transform::Ptr transform =
93 1 openvdb::math::Transform::createLinearTransform(voxelSize);
94
95 // generate points
96
97 std::vector<openvdb::Vec3R> points;
98
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::genPoints(40000, points);
99
100 PointList pointList(points);
101
102
103 // construct data structure
104 typedef openvdb::tools::PointIndexGrid PointIndexGrid;
105
106 PointIndexGrid::Ptr pointGridPtr =
107
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::tools::createPointIndexGrid<PointIndexGrid>(pointList, *transform);
108
109 1 openvdb::CoordBBox bbox;
110
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pointGridPtr->tree().evalActiveVoxelBoundingBox(bbox);
111
112 // coord bbox search
113
114 typedef PointIndexGrid::ConstAccessor ConstAccessor;
115 typedef openvdb::tools::PointIndexIterator<> PointIndexIterator;
116
117 ConstAccessor acc = pointGridPtr->getConstAccessor();
118
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 PointIndexIterator it(bbox, acc);
119
120
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());
121
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1 EXPECT_EQ(points.size(), it.size());
122
123 // fractional bbox search
124
125 1 openvdb::BBoxd region(bbox.min().asVec3d(), bbox.max().asVec3d());
126
127 // points are bucketed in a cell-centered fashion, we need to pad the
128 // coordinate range to get the same search region in the fractional bbox.
129 1 region.expand(voxelSize * 0.5);
130
131
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 it.searchAndUpdate(region, acc, pointList, *transform);
132
133
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());
134
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1 EXPECT_EQ(points.size(), it.size());
135
136 {
137 std::vector<uint32_t> vec;
138
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 vec.reserve(it.size());
139 for (; it; ++it) {
140
1/2
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
40000 vec.push_back(*it);
141 }
142
143
2/18
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(vec.size(), it.size());
144
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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(!hasDuplicates(vec));
145 }
146
147 // radial search
148 openvdb::Vec3d center = region.getCenter();
149
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 double radius = region.extents().x() * 0.5;
150
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 it.searchAndUpdate(center, radius, acc, pointList, *transform);
151
152
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());
153
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1 EXPECT_EQ(points.size(), it.size());
154
155 {
156 std::vector<uint32_t> vec;
157
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 vec.reserve(it.size());
158 for (; it; ++it) {
159
1/2
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
40000 vec.push_back(*it);
160 }
161
162
2/18
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(vec.size(), it.size());
163
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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(!hasDuplicates(vec));
164 }
165
166
167
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 center = region.min();
168
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 it.searchAndUpdate(center, radius, acc, pointList, *transform);
169
170
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());
171
172 {
173 std::vector<uint32_t> vec;
174
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 vec.reserve(it.size());
175 for (; it; ++it) {
176
1/2
✓ Branch 1 taken 2212 times.
✗ Branch 2 not taken.
2212 vec.push_back(*it);
177 }
178
179
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1 EXPECT_EQ(vec.size(), it.size());
180
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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(!hasDuplicates(vec));
181
182 // check that no points where missed.
183
184
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 std::vector<unsigned char> indexMask(points.size(), 0);
185
2/2
✓ Branch 0 taken 2212 times.
✓ Branch 1 taken 1 times.
2213 for (size_t n = 0, N = vec.size(); n < N; ++n) {
186 2212 indexMask[vec[n]] = 1;
187 }
188
189 1 const double r2 = radius * radius;
190 openvdb::Vec3R v;
191
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 1 times.
40001 for (size_t n = 0, N = indexMask.size(); n < N; ++n) {
192
2/2
✓ Branch 0 taken 37788 times.
✓ Branch 1 taken 2212 times.
40000 v = center - transform->worldToIndex(points[n]);
193
2/2
✓ Branch 0 taken 37788 times.
✓ Branch 1 taken 2212 times.
40000 if (indexMask[n] == 0) {
194
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 37788 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.
37788 EXPECT_TRUE(!(v.lengthSqr() < r2));
195 } else {
196
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 2212 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.
2212 EXPECT_TRUE(v.lengthSqr() < r2);
197 }
198 }
199 }
200
201
202 // Check partitioning
203
204
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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(openvdb::tools::isValidPartition(pointList, *pointGridPtr));
205
206 1 points[10000].x() += 1.5; // manually modify a few points.
207 1 points[20000].x() += 1.5;
208
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points[30000].x() += 1.5;
209
210
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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(!openvdb::tools::isValidPartition(pointList, *pointGridPtr));
211
212 PointIndexGrid::Ptr pointGrid2Ptr =
213
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::tools::getValidPointIndexGrid<PointIndexGrid>(pointList, pointGridPtr);
214
215
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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(openvdb::tools::isValidPartition(pointList, *pointGrid2Ptr));
216 1 }
217
218
219
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPointIndexGrid, testPointIndexFilter)
220 {
221 // generate points
222 const float voxelSize = 0.01f;
223 const size_t pointCount = 10000;
224 const openvdb::math::Transform::Ptr transform =
225 1 openvdb::math::Transform::createLinearTransform(voxelSize);
226
227 std::vector<openvdb::Vec3d> points;
228
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::genPoints(pointCount, points);
229
230 PointList pointList(points);
231
232 // construct data structure
233 typedef openvdb::tools::PointIndexGrid PointIndexGrid;
234
235 PointIndexGrid::Ptr pointGridPtr =
236
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::tools::createPointIndexGrid<PointIndexGrid>(pointList, *transform);
237
238
239
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 std::vector<double> pointDensity(pointCount, 1.0);
240
241 openvdb::tools::PointIndexFilter<PointList>
242
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 filter(pointList, pointGridPtr->tree(), pointGridPtr->transform());
243
244 const double radius = 3.0 * voxelSize;
245
246 WeightedAverageAccumulator<double>
247 accumulator(&pointDensity.front(), radius);
248
249 double sum = 0.0;
250
2/2
✓ Branch 0 taken 10000 times.
✓ Branch 1 taken 1 times.
10001 for (size_t n = 0, N = points.size(); n < N; ++n) {
251 accumulator.reset();
252
1/2
✓ Branch 1 taken 10000 times.
✗ Branch 2 not taken.
10000 filter.searchAndApply(points[n], radius, accumulator);
253 10000 sum += accumulator.result();
254 }
255
256
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_NEAR(sum, double(points.size()), 1e-6);
257 1 }
258
259
260
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestPointIndexGrid, testWorldSpaceSearchAndUpdate)
261 {
262 // Create random particles in a cube.
263 openvdb::math::Rand01<> rnd(0);
264
265 const size_t N = 1000000;
266 std::vector<openvdb::Vec3d> pos;
267
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pos.reserve(N);
268
269 // Create a box to query points.
270 1 openvdb::BBoxd wsBBox(openvdb::Vec3d(0.25), openvdb::Vec3d(0.75));
271
272 std::set<size_t> indexListA;
273
274
2/2
✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 1 times.
1000001 for (size_t i = 0; i < N; ++i) {
275 openvdb::Vec3d p(rnd(), rnd(), rnd());
276
1/2
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
1000000 pos.push_back(p);
277
278
2/2
✓ Branch 0 taken 124979 times.
✓ Branch 1 taken 875021 times.
1000000 if (wsBBox.isInside(p)) {
279 indexListA.insert(i);
280 }
281 }
282
283 // Create a point index grid
284 const double dx = 0.025;
285
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform(dx);
286
287 PointList pointArray(pos);
288 openvdb::tools::PointIndexGrid::Ptr pointIndexGrid
289
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 = openvdb::tools::createPointIndexGrid<openvdb::tools::PointIndexGrid, PointList>(pointArray, *transform);
290
291 // Search for points within the box.
292 openvdb::tools::PointIndexGrid::ConstAccessor acc = pointIndexGrid->getConstAccessor();
293
294
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 openvdb::tools::PointIndexIterator<openvdb::tools::PointIndexTree> pointIndexIter;
295
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pointIndexIter.worldSpaceSearchAndUpdate<PointList>(wsBBox, acc, pointArray, pointIndexGrid->transform());
296
297 std::set<size_t> indexListB;
298 for (; pointIndexIter; ++pointIndexIter) {
299
1/2
✓ Branch 1 taken 124979 times.
✗ Branch 2 not taken.
124979 indexListB.insert(*pointIndexIter);
300 }
301
302
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(indexListA.size(), indexListB.size());
303 1 }
304
305