GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestIndexIterator.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 102 102 100.0%
Functions: 4 4 100.0%
Branches: 129 702 18.4%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/points/IndexIterator.h>
5 #include <openvdb/Types.h>
6 #include <openvdb/tree/LeafNode.h>
7
8 #include <gtest/gtest.h>
9 #include <tbb/tick_count.h>
10
11 #include <sstream>
12 #include <iostream>
13 #include <iomanip>//for setprecision
14
15 using namespace openvdb;
16 using namespace openvdb::points;
17
18 4 class TestIndexIterator: public ::testing::Test
19 {
20 }; // class TestIndexIterator
21
22
23 ////////////////////////////////////////
24
25
26 /// @brief Functionality similar to openvdb::util::CpuTimer except with prefix padding and no decimals.
27 ///
28 /// @code
29 /// ProfileTimer timer("algorithm 1");
30 /// // code to be timed goes here
31 /// timer.stop();
32 /// @endcode
33 class ProfileTimer
34 {
35 public:
36 /// @brief Prints message and starts timer.
37 ///
38 /// @note Should normally be followed by a call to stop()
39 ProfileTimer(const std::string& msg)
40 {
41 (void)msg;
42 #ifdef PROFILE
43 // padd string to 50 characters
44 std::string newMsg(msg);
45 if (newMsg.size() < 50) newMsg.insert(newMsg.end(), 50 - newMsg.size(), ' ');
46 std::cerr << newMsg << " ... ";
47 #endif
48 4 mT0 = tbb::tick_count::now();
49 }
50
51 ~ProfileTimer() { this->stop(); }
52
53 /// Return Time diference in milliseconds since construction or start was called.
54 inline double delta() const
55 {
56 tbb::tick_count::interval_t dt = tbb::tick_count::now() - mT0;
57 return 1000.0*dt.seconds();
58 }
59
60 /// @brief Print time in milliseconds since construction or start was called.
61 inline void stop() const
62 {
63 #ifdef PROFILE
64 std::stringstream ss;
65 ss << std::setw(6) << ::round(this->delta());
66 std::cerr << "completed in " << ss.str() << " ms\n";
67 #endif
68 }
69
70 private:
71 tbb::tick_count mT0;
72 };// ProfileTimer
73
74
75 ////////////////////////////////////////
76
77
78
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestIndexIterator, testNullFilter)
79 {
80 NullFilter filter;
81 EXPECT_TRUE(filter.initialized());
82 EXPECT_TRUE(filter.state() == index::ALL);
83 int a = 0;
84 EXPECT_TRUE(filter.valid(a));
85 1 }
86
87
88
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestIndexIterator, testValueIndexIterator)
89 {
90 using namespace openvdb::tree;
91
92 using LeafNode = LeafNode<unsigned, 1>;
93 using ValueOnIter = LeafNode::ValueOnIter;
94
95 const int size = LeafNode::SIZE;
96
97 { // one per voxel offset, all active
98 LeafNode leafNode;
99
100
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int i = 0; i < size; i++) {
101
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
16 leafNode.setValueOn(i, i+1);
102 }
103
104 ValueOnIter valueIter = leafNode.beginValueOn();
105
106
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 IndexIter<ValueOnIter, NullFilter>::ValueIndexIter iter(valueIter);
107
108
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(iter);
109
110
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(iterCount(iter), Index64(size));
111
112 // check assignment operator
113 1 auto iter2 = iter;
114
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(iterCount(iter2), Index64(size));
115
116
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ++iter;
117
118 // check coord value
119 Coord xyz;
120
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 iter.getCoord(xyz);
121
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(xyz, openvdb::Coord(0, 0, 1));
122
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(iter.getCoord(), openvdb::Coord(0, 0, 1));
123
124 // check iterators retrieval
125
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(iter.valueIter().getCoord(), openvdb::Coord(0, 0, 1));
126
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(iter.end(), Index32(2));
127
128
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ++iter;
129
130 // check coord value
131
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 iter.getCoord(xyz);
132
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(xyz, openvdb::Coord(0, 1, 0));
133
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(iter.getCoord(), openvdb::Coord(0, 1, 0));
134
135 // check iterators retrieval
136
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(iter.valueIter().getCoord(), openvdb::Coord(0, 1, 0));
137
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(iter.end(), Index32(3));
138 }
139
140 { // one per even voxel offsets, only these active
141 LeafNode leafNode;
142
143 int offset = 0;
144
145
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int i = 0; i < size; i++)
146 {
147
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if ((i % 2) == 0) {
148
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 leafNode.setValueOn(i, ++offset);
149 }
150 else {
151
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 leafNode.setValueOff(i, offset);
152 }
153 }
154
155 {
156 ValueOnIter valueIter = leafNode.beginValueOn();
157
158
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 IndexIter<ValueOnIter, NullFilter>::ValueIndexIter iter(valueIter);
159
160
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(iter);
161
162
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(iterCount(iter), Index64(size/2));
163 }
164 }
165
166 { // one per odd voxel offsets, all active
167 LeafNode leafNode;
168
169 int offset = 0;
170
171
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int i = 0; i < size; i++)
172 {
173
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if ((i % 2) == 1) {
174
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 leafNode.setValueOn(i, offset++);
175 }
176 else {
177
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 leafNode.setValueOn(i, offset);
178 }
179 }
180
181 {
182 ValueOnIter valueIter = leafNode.beginValueOn();
183
184
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 IndexIter<ValueOnIter, NullFilter>::ValueIndexIter iter(valueIter);
185
186
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(iter);
187
188
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(iterCount(iter), Index64(3));
189 }
190 }
191
192 { // one per even voxel offsets, all active
193 LeafNode leafNode;
194
195 int offset = 0;
196
197
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int i = 0; i < size; i++)
198 {
199
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if ((i % 2) == 0) {
200
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 leafNode.setValueOn(i, offset++);
201 }
202 else {
203
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 leafNode.setValueOn(i, offset);
204 }
205 }
206
207 {
208 ValueOnIter valueIter = leafNode.beginValueOn();
209
210
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 IndexIter<ValueOnIter, NullFilter>::ValueIndexIter iter(valueIter);
211
212
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(iter);
213
214
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(iterCount(iter), Index64(size/2));
215 }
216 }
217
218 { // one per voxel offset, none active
219 LeafNode leafNode;
220
221
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int i = 0; i < size; i++) {
222
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 leafNode.setValueOff(i, i);
223 }
224
225 ValueOnIter valueIter = leafNode.beginValueOn();
226
227
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 IndexIter<ValueOnIter, NullFilter>::ValueIndexIter iter(valueIter);
228
229
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(!iter);
230
231
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(iterCount(iter), Index64(0));
232 }
233 1 }
234
235
236 struct EvenIndexFilter
237 {
238 static bool initialized() { return true; }
239 static bool all() { return false; }
240 static bool none() { return false; }
241 template <typename IterT>
242 bool valid(const IterT& iter) const {
243
10/14
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
10 return ((*iter) % 2) == 0;
244 }
245 };
246
247
248 struct OddIndexFilter
249 {
250 static bool initialized() { return true; }
251 static bool all() { return false; }
252 static bool none() { return false; }
253 1 OddIndexFilter() : mFilter() { }
254 template <typename IterT>
255 bool valid(const IterT& iter) const {
256 return !mFilter.valid(iter);
257 }
258 private:
259 EvenIndexFilter mFilter;
260 };
261
262
263 struct ConstantIter
264 {
265 ConstantIter(const int _value) : value(_value) { }
266 int operator*() const { return value; }
267 const int value;
268 };
269
270
271
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestIndexIterator, testFilterIndexIterator)
272 {
273 { // index iterator with even filter
274 EvenIndexFilter filter;
275 ValueVoxelCIter indexIter(0, 5);
276 1 IndexIter<ValueVoxelCIter, EvenIndexFilter> iter(indexIter, filter);
277
278
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(iter);
279
2/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ 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(*iter, Index32(0));
280
281
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(iter.next());
282
2/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ 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(*iter, Index32(2));
283
284
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(iter.next());
285
2/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ 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(*iter, Index32(4));
286
287
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(!iter.next());
288
289
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ(iter.end(), Index32(5));
290
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ(filter.valid(ConstantIter(1)), iter.filter().valid(ConstantIter(1)));
291
1/20
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ 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 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.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
1 EXPECT_EQ(filter.valid(ConstantIter(2)), iter.filter().valid(ConstantIter(2)));
292 }
293
294 { // index iterator with odd filter
295 OddIndexFilter filter;
296 ValueVoxelCIter indexIter(0, 5);
297 1 IndexIter<ValueVoxelCIter, OddIndexFilter> iter(indexIter, filter);
298
299
2/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ 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(*iter, Index32(1));
300
301
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(iter.next());
302
2/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ 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(*iter, Index32(3));
303
304
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(!iter.next());
305 }
306 1 }
307
308
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestIndexIterator, testProfile)
309 {
310 using namespace openvdb::util;
311 using namespace openvdb::math;
312 using namespace openvdb::tree;
313
314 #ifdef PROFILE
315 const int elements(1000 * 1000 * 1000);
316
317 std::cerr << std::endl;
318 #else
319 const int elements(10 * 1000 * 1000);
320 #endif
321
322 { // for loop
323 1 ProfileTimer timer("ForLoop: sum");
324 1 volatile uint64_t sum = 0;
325
2/2
✓ Branch 0 taken 10000000 times.
✓ Branch 1 taken 1 times.
10000001 for (int i = 0; i < elements; i++) {
326 10000000 sum += i;
327 }
328
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(sum);
329 }
330
331 { // index iterator
332 1 ProfileTimer timer("IndexIter: sum");
333 1 volatile uint64_t sum = 0;
334 ValueVoxelCIter iter(0, elements);
335
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (; iter; ++iter) {
336 1 sum += *iter;
337 }
338
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(sum);
339 }
340
341 using LeafNode = LeafNode<unsigned, 3>;
342 LeafNode leafNode;
343
344 const int size = LeafNode::SIZE;
345
346
2/2
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 1 times.
512 for (int i = 0; i < size - 1; i++) {
347
1/2
✓ Branch 1 taken 511 times.
✗ Branch 2 not taken.
1022 leafNode.setValueOn(i, (elements / size) * i);
348 }
349
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 leafNode.setValueOn(size - 1, elements);
350
351 { // manual value iteration
352
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ProfileTimer timer("ValueIteratorManual: sum");
353 1 volatile uint64_t sum = 0;
354 auto indexIter(leafNode.cbeginValueOn());
355 int offset = 0;
356
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1 times.
513 for (; indexIter; ++indexIter) {
357
3/4
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 511 times.
✗ Branch 4 not taken.
512 int start = offset > 0 ? leafNode.getValue(offset - 1) : 0;
358
1/2
✓ Branch 1 taken 512 times.
✗ Branch 2 not taken.
512 int end = leafNode.getValue(offset);
359
2/2
✓ Branch 0 taken 10000000 times.
✓ Branch 1 taken 512 times.
10000512 for (int i = start; i < end; i++) {
360 10000000 sum += i;
361 }
362 512 offset++;
363 }
364
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(sum);
365 }
366
367 { // value on iterator (all on)
368
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ProfileTimer timer("ValueIndexIter: sum");
369 1 volatile uint64_t sum = 0;
370 1 auto indexIter(leafNode.cbeginValueAll());
371
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 IndexIter<LeafNode::ValueAllCIter, NullFilter>::ValueIndexIter iter(indexIter);
372
2/2
✓ Branch 0 taken 10000000 times.
✓ Branch 1 taken 1 times.
10000001 for (; iter; ++iter) {
373
1/2
✓ Branch 2 taken 10000000 times.
✗ Branch 3 not taken.
10000000 sum += *iter;
374 }
375
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(sum);
376 }
377 1 }
378