Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright Contributors to the OpenVDB Project | ||
2 | // SPDX-License-Identifier: MPL-2.0 | ||
3 | |||
4 | #include <openvdb/tools/ParticleAtlas.h> | ||
5 | #include <openvdb/math/Math.h> | ||
6 | |||
7 | #include <gtest/gtest.h> | ||
8 | |||
9 | #include <vector> | ||
10 | #include <algorithm> | ||
11 | #include <cmath> | ||
12 | #include "util.h" // for genPoints | ||
13 | |||
14 | |||
15 | 1 | struct TestParticleAtlas: public ::testing::Test | |
16 | { | ||
17 | }; | ||
18 | |||
19 | |||
20 | //////////////////////////////////////// | ||
21 | |||
22 | namespace { | ||
23 | |||
24 | class ParticleList | ||
25 | { | ||
26 | public: | ||
27 | typedef openvdb::Vec3R PosType; | ||
28 | typedef PosType::value_type ScalarType; | ||
29 | |||
30 | ParticleList(const std::vector<PosType>& points, | ||
31 | const std::vector<ScalarType>& radius) | ||
32 | 1 | : mPoints(&points) | |
33 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | , mRadius(&radius) |
34 | { | ||
35 | } | ||
36 | |||
37 | // Return the number of points in the array | ||
38 | size_t size() const { | ||
39 |
1/10✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
2 | return mPoints->size(); |
40 | } | ||
41 | |||
42 | // Return the world-space position for the nth particle. | ||
43 | void getPos(size_t n, PosType& xyz) const { | ||
44 |
5/12✓ Branch 0 taken 40000 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1514 times.
✓ Branch 5 taken 1433 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 701 times.
✓ Branch 9 taken 339 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
43987 | xyz = (*mPoints)[n]; |
45 | } | ||
46 | |||
47 | // Return the world-space radius for the nth particle. | ||
48 | void getRadius(size_t n, ScalarType& radius) const { | ||
49 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40000 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
120004 | radius = (*mRadius)[n]; |
50 | } | ||
51 | |||
52 | protected: | ||
53 | std::vector<PosType> const * const mPoints; | ||
54 | std::vector<ScalarType> const * const mRadius; | ||
55 | }; // ParticleList | ||
56 | |||
57 | |||
58 | template<typename T> | ||
59 | 3 | bool hasDuplicates(const std::vector<T>& items) | |
60 | { | ||
61 | 3 | std::vector<T> vec(items); | |
62 | 3 | std::sort(vec.begin(), vec.end()); | |
63 | |||
64 | size_t duplicates = 0; | ||
65 |
2/2✓ Branch 0 taken 61964 times.
✓ Branch 1 taken 3 times.
|
61967 | for (size_t n = 1, N = vec.size(); n < N; ++n) { |
66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 61964 times.
|
61964 | if (vec[n] == vec[n-1]) ++duplicates; |
67 | } | ||
68 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | return duplicates != 0; |
69 | } | ||
70 | |||
71 | } // namespace | ||
72 | |||
73 | |||
74 | |||
75 | //////////////////////////////////////// | ||
76 | |||
77 | |||
78 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestParticleAtlas, testParticleAtlas) |
79 | { | ||
80 | // generate points | ||
81 | |||
82 | 1 | const size_t numParticle = 40000; | |
83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const double minVoxelSize = 0.01; |
84 | |||
85 | std::vector<openvdb::Vec3R> points; | ||
86 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | unittest_util::genPoints(numParticle, points); |
87 | |||
88 | std::vector<double> radius; | ||
89 |
2/2✓ Branch 0 taken 20000 times.
✓ Branch 1 taken 1 times.
|
20001 | for (size_t n = 0, N = points.size() / 2; n < N; ++n) { |
90 |
1/2✓ Branch 1 taken 20000 times.
✗ Branch 2 not taken.
|
20000 | radius.push_back(minVoxelSize); |
91 | } | ||
92 | |||
93 |
2/2✓ Branch 0 taken 20000 times.
✓ Branch 1 taken 1 times.
|
20001 | for (size_t n = points.size() / 2, N = points.size(); n < N; ++n) { |
94 |
1/4✓ Branch 1 taken 20000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
20000 | radius.push_back(minVoxelSize * 2.0); |
95 | } | ||
96 | |||
97 | ParticleList particles(points, radius); | ||
98 | |||
99 | // construct data structure | ||
100 | |||
101 | typedef openvdb::tools::ParticleAtlas<> ParticleAtlas; | ||
102 | |||
103 | 1 | ParticleAtlas atlas; | |
104 | |||
105 | EXPECT_TRUE(atlas.empty()); | ||
106 | EXPECT_TRUE(atlas.levels() == 0); | ||
107 | |||
108 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | atlas.construct(particles, minVoxelSize); |
109 | |||
110 |
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(!atlas.empty()); |
111 |
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(atlas.levels() == 2); |
112 | |||
113 |
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( |
114 | openvdb::math::isApproxEqual(atlas.minRadius(0), minVoxelSize)); | ||
115 | |||
116 |
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( |
117 | openvdb::math::isApproxEqual(atlas.minRadius(1), minVoxelSize * 2.0)); | ||
118 | |||
119 | typedef openvdb::tools::ParticleAtlas<>::Iterator ParticleAtlasIterator; | ||
120 | |||
121 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ParticleAtlasIterator it(atlas); |
122 | |||
123 |
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(atlas.levels() == 2); |
124 | |||
125 | std::vector<uint32_t> indices; | ||
126 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | indices.reserve(numParticle); |
127 | |||
128 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | it.updateFromLevel(0); |
129 | |||
130 |
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); |
131 |
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(it.size(), numParticle - (points.size() / 2)); |
132 | |||
133 | |||
134 | for (; it; ++it) { | ||
135 |
1/2✓ Branch 1 taken 20000 times.
✗ Branch 2 not taken.
|
20000 | indices.push_back(*it); |
136 | } | ||
137 | |||
138 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | it.updateFromLevel(1); |
139 | |||
140 |
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); |
141 |
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(it.size(), (points.size() / 2)); |
142 | |||
143 | |||
144 | for (; it; ++it) { | ||
145 |
1/2✓ Branch 1 taken 20000 times.
✗ Branch 2 not taken.
|
20000 | indices.push_back(*it); |
146 | } | ||
147 | |||
148 |
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(numParticle, indices.size()); |
149 | |||
150 |
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(indices)); |
151 | |||
152 | |||
153 | 1 | openvdb::Vec3R center = points[0]; | |
154 | double searchRadius = minVoxelSize * 10.0; | ||
155 | |||
156 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | it.worldSpaceSearchAndUpdate(center, searchRadius, particles); |
157 |
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); |
158 | |||
159 | indices.clear(); | ||
160 | for (; it; ++it) { | ||
161 |
1/2✓ Branch 1 taken 1408 times.
✗ Branch 2 not taken.
|
1408 | indices.push_back(*it); |
162 | } | ||
163 | |||
164 |
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(it.size(), indices.size()); |
165 |
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(indices)); |
166 | |||
167 | |||
168 | openvdb::BBoxd bbox; | ||
169 |
2/2✓ Branch 0 taken 20000 times.
✓ Branch 1 taken 1 times.
|
20001 | for (size_t n = 0, N = points.size() / 2; n < N; ++n) { |
170 | 20000 | bbox.expand(points[n]); | |
171 | } | ||
172 | |||
173 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | it.worldSpaceSearchAndUpdate(bbox, particles); |
174 |
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); |
175 | |||
176 | indices.clear(); | ||
177 | for (; it; ++it) { | ||
178 |
1/2✓ Branch 1 taken 20559 times.
✗ Branch 2 not taken.
|
20559 | indices.push_back(*it); |
179 | } | ||
180 | |||
181 |
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(it.size(), indices.size()); |
182 |
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(indices)); |
183 | 1 | } | |
184 | |||
185 |