GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestPointConversion.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 539 545 98.9%
Functions: 12 12 100.0%
Branches: 786 3514 22.4%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/io/TempFile.h>
5 #include <openvdb/points/PointDataGrid.h>
6 #include <openvdb/points/PointAttribute.h>
7 #include <openvdb/points/PointConversion.h>
8 #include <openvdb/points/PointCount.h>
9 #include <openvdb/points/PointGroup.h>
10
11 #include <gtest/gtest.h>
12
13
14 using namespace openvdb;
15 using namespace openvdb::points;
16
17 6 class TestPointConversion: public ::testing::Test
18 {
19 public:
20 6 void SetUp() override { openvdb::initialize(); }
21 6 void TearDown() override { openvdb::uninitialize(); }
22 }; // class TestPointConversion
23
24
25 // Simple Attribute Wrapper
26 template <typename T>
27
28/56
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 1 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 1 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 1 times.
✗ Branch 55 not taken.
✓ Branch 56 taken 1 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
28 struct AttributeWrapper
28 {
29 using ValueType = T;
30 using PosType = T;
31 using value_type = T;
32
33 struct Handle
34 {
35 1578 Handle(AttributeWrapper<T>& attribute)
36 1574 : mBuffer(attribute.mAttribute)
37 1587 , mStride(attribute.mStride) { }
38
39 template <typename ValueType>
40 5160092 void set(size_t n, openvdb::Index m, const ValueType& value) {
41 8360134 mBuffer[n * mStride + m] = static_cast<T>(value);
42 5160092 }
43
44 template <typename ValueType>
45 void set(size_t n, openvdb::Index m, const openvdb::math::Vec3<ValueType>& value) {
46 1545031 mBuffer[n * mStride + m] = static_cast<T>(value);
47 }
48
49 private:
50 std::vector<T>& mBuffer;
51 Index mStride;
52 }; // struct Handle
53
54
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 explicit AttributeWrapper(const Index stride) : mStride(stride) { }
55
56 void expand() { }
57 void compact() { }
58
59
22/44
✓ 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.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
20 void resize(const size_t n) { mAttribute.resize(n); }
60 size_t size() const { return mAttribute.size(); }
61
62 std::vector<T>& buffer() { return mAttribute; }
63
64 template <typename ValueT>
65
8/20
✓ Branch 1 taken 1160021 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1000021 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1000021 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 8412090 times.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1388025 times.
✓ Branch 18 taken 4 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 26 taken 1000025 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 1388025 times.
✗ Branch 30 not taken.
16456311 void get(ValueT& value, size_t n, openvdb::Index m = 0) const { value = mAttribute[n * mStride + m]; }
66 template <typename ValueT>
67 void getPos(size_t n, ValueT& value) const { this->get<ValueT>(value, n); }
68
69 private:
70 std::vector<T> mAttribute;
71 Index mStride;
72 }; // struct AttributeWrapper
73
74
75 6 struct GroupWrapper
76 {
77 GroupWrapper() = default;
78
79 void setOffsetOn(openvdb::Index index) {
80 61 mGroup[index] = short(1);
81 999948 }
82
83 void finalize() { }
84
85
4/8
✓ 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.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
7 void resize(const size_t n) { mGroup.resize(n, short(0)); }
86 size_t size() const { return mGroup.size(); }
87
88 std::vector<short>& buffer() { return mGroup; }
89
90 private:
91 std::vector<short> mGroup;
92 }; // struct GroupWrapper
93
94
95
0/2
✗ Branch 20 not taken.
✗ Branch 21 not taken.
15092341 struct PointData
96 {
97 int id;
98 Vec3f position;
99 Vec3i xyz;
100 float uniform;
101 openvdb::Name string;
102 short group;
103
104
18/24
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4125561 times.
✓ Branch 5 taken 1540007 times.
✓ Branch 6 taken 10884270 times.
✓ Branch 7 taken 5846694 times.
✓ Branch 8 taken 8995244 times.
✓ Branch 9 taken 5846694 times.
✓ Branch 10 taken 78663 times.
✓ Branch 11 taken 80925 times.
✓ Branch 12 taken 38111 times.
✓ Branch 13 taken 40552 times.
✓ Branch 14 taken 20713 times.
✓ Branch 15 taken 19839 times.
✓ Branch 16 taken 36072 times.
✓ Branch 17 taken 44853 times.
✓ Branch 18 taken 22420 times.
✓ Branch 19 taken 22433 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 10 times.
✓ Branch 23 taken 50 times.
37398118 bool operator<(const PointData& other) const { return id < other.id; }
105 }; // PointData
106
107
108 // Generate random points by uniformly distributing points
109 // on a unit-sphere.
110 inline void
111 4 genPoints(const int numPoints, const double scale, const bool stride,
112 AttributeWrapper<Vec3f>& position,
113 AttributeWrapper<int>& xyz,
114 AttributeWrapper<int>& id,
115 AttributeWrapper<float>& uniform,
116 AttributeWrapper<openvdb::Name>& string,
117 GroupWrapper& group)
118 {
119 // init
120 openvdb::math::Random01 randNumber(0);
121 4 const int n = int(std::sqrt(double(numPoints)));
122 4 const double xScale = (2.0 * M_PI) / double(n);
123 4 const double yScale = M_PI / double(n);
124
125 double x, y, theta, phi;
126 openvdb::Vec3f pos;
127
128 4 position.resize(n*n);
129
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 xyz.resize(stride ? n*n*3 : 1);
130 id.resize(n*n);
131 uniform.resize(n*n);
132 string.resize(n*n);
133 group.resize(n*n);
134
135 AttributeWrapper<Vec3f>::Handle positionHandle(position);
136 AttributeWrapper<int>::Handle xyzHandle(xyz);
137 AttributeWrapper<int>::Handle idHandle(id);
138 AttributeWrapper<float>::Handle uniformHandle(uniform);
139 AttributeWrapper<openvdb::Name>::Handle stringHandle(string);
140
141 size_t i = 0;
142
143 // loop over a [0 to n) x [0 to n) grid.
144
2/2
✓ Branch 0 taken 1405 times.
✓ Branch 1 taken 4 times.
1409 for (int a = 0; a < n; ++a) {
145
2/2
✓ Branch 0 taken 1080025 times.
✓ Branch 1 taken 1405 times.
1081430 for (int b = 0; b < n; ++b) {
146
147 // jitter, move to random pos. inside the current cell
148 1080025 x = double(a) + randNumber();
149 1080025 y = double(b) + randNumber();
150
151 // remap to a lat/long map
152 1080025 theta = y * yScale; // [0 to PI]
153 1080025 phi = x * xScale; // [0 to 2PI]
154
155 // convert to cartesian coordinates on a unit sphere.
156 // spherical coordinate triplet (r=1, theta, phi)
157 1080025 pos[0] = static_cast<float>(std::sin(theta)*std::cos(phi)*scale);
158 1080025 pos[1] = static_cast<float>(std::sin(theta)*std::sin(phi)*scale);
159
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 1040025 times.
1080025 pos[2] = static_cast<float>(std::cos(theta)*scale);
160
161 positionHandle.set(i, /*stride*/0, pos);
162 idHandle.set(i, /*stride*/0, i);
163 uniformHandle.set(i, /*stride*/0, 100.0f);
164
165
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 1040025 times.
1080025 if (stride)
166 {
167 xyzHandle.set(i, 0, static_cast<int>(i));
168 40000 xyzHandle.set(i, 1, static_cast<int>(i*i));
169 40000 xyzHandle.set(i, 2, static_cast<int>(i*i*i));
170 }
171
172 // add points with even id to the group
173
2/2
✓ Branch 0 taken 540013 times.
✓ Branch 1 taken 540012 times.
1080025 if ((i % 2) == 0) {
174 group.setOffsetOn(static_cast<int>(i));
175 540013 stringHandle.set(i, /*stride*/0, "testA");
176 }
177 else {
178 540012 stringHandle.set(i, /*stride*/0, "testB");
179 }
180
181 1080025 i++;
182 }
183 }
184 4 }
185
186
187 ////////////////////////////////////////
188
189
190
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPointConversion, testPointConversion)
191 {
192 // generate points
193
194
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t count(1000000);
195
196 AttributeWrapper<Vec3f> position(1);
197 AttributeWrapper<int> xyz(1);
198 AttributeWrapper<int> id(1);
199 AttributeWrapper<float> uniform(1);
200 AttributeWrapper<openvdb::Name> string(1);
201 GroupWrapper group;
202
203
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 genPoints(count, /*scale=*/ 100.0, /*stride=*/false,
204 position, xyz, id, uniform, string, group);
205
206
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(position.size(), count);
207
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(id.size(), count);
208
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(uniform.size(), count);
209
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(string.size(), count);
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 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(group.size(), count);
211
212 // convert point positions into a Point Data Grid
213
214 const float voxelSize = 1.0f;
215
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::Ptr transform(openvdb::math::Transform::createLinearTransform(voxelSize));
216
217
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::PointIndexGrid::Ptr pointIndexGrid = tools::createPointIndexGrid<tools::PointIndexGrid>(position, *transform);
218
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr pointDataGrid = createPointDataGrid<NullCodec, PointDataGrid>(*pointIndexGrid, position, *transform);
219
220 tools::PointIndexTree& indexTree = pointIndexGrid->tree();
221 PointDataTree& tree = pointDataGrid->tree();
222
223 // add id and populate
224
225
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendAttribute<int>(tree, "id");
226
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<int>>(tree, indexTree, "id", id);
227
228 // add uniform and populate
229
230
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendAttribute<float>(tree, "uniform");
231
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 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<float>>(tree, indexTree, "uniform", uniform);
232
233 // add string and populate
234
235
3/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
2 appendAttribute<Name>(tree, "string");
236
237 // reset the descriptors
238 PointDataTree::LeafIter leafIter = tree.beginLeaf();
239 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
240
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
241
2/2
✓ Branch 0 taken 2900 times.
✓ Branch 1 taken 1 times.
2901 for (; leafIter; ++leafIter) {
242 leafIter->resetDescriptor(newDescriptor);
243 }
244
245
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<openvdb::Name>>(
246 tree, indexTree, "string", string);
247
248 // add group and set membership
249
250
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendGroup(tree, "test");
251
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 setGroup(tree, indexTree, group.buffer(), "test");
252
253
4/20
✓ 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.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ 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 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(indexTree.leafCount(), tree.leafCount());
254
255 // read/write grid to a temp file
256
257
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 io::TempFile file;
258
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const std::string filename = file.filename();
259
260
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 io::File fileOut(filename);
261
262 1 GridCPtrVec grids;
263
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 grids.push_back(pointDataGrid);
264
265 fileOut.write(grids);
266
267
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fileOut.close();
268
269
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 io::File fileIn(filename);
270
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fileIn.open();
271
272
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GridPtrVecPtr readGrids = fileIn.getGrids();
273
274
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fileIn.close();
275
276
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(readGrids->size(), size_t(1));
277
278
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 pointDataGrid = GridBase::grid<PointDataGrid>((*readGrids)[0]);
279 PointDataTree& inputTree = pointDataGrid->tree();
280
281 // create accessor and iterator for Point Data Tree
282
283 PointDataTree::LeafCIter leafCIter = inputTree.cbeginLeaf();
284
285
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(5, int(leafCIter->attributeSet().size()));
286
287
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("id") != AttributeSet::INVALID_POS);
288
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("uniform") != AttributeSet::INVALID_POS);
289
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("P") != AttributeSet::INVALID_POS);
290
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("string") != AttributeSet::INVALID_POS);
291
292
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto idIndex = static_cast<Index>(leafCIter->attributeSet().find("id"));
293
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto uniformIndex = static_cast<Index>(leafCIter->attributeSet().find("uniform"));
294
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto stringIndex = static_cast<Index>(leafCIter->attributeSet().find("string"));
295 const AttributeSet::Descriptor::GroupIndex groupIndex =
296
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 leafCIter->attributeSet().groupIndex("test");
297
298 // convert back into linear point attribute data
299
300 AttributeWrapper<Vec3f> outputPosition(1);
301 AttributeWrapper<int> outputId(1);
302 AttributeWrapper<float> outputUniform(1);
303 AttributeWrapper<openvdb::Name> outputString(1);
304 GroupWrapper outputGroup;
305
306 // test offset the whole point block by an arbitrary amount
307
308 Index64 startOffset = 10;
309
310
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputPosition.resize(startOffset + position.size());
311
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputId.resize(startOffset + id.size());
312
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputUniform.resize(startOffset + uniform.size());
313
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputString.resize(startOffset + string.size());
314
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputGroup.resize(startOffset + group.size());
315
316 1 std::vector<Name> includeGroups;
317 1 std::vector<Name> excludeGroups;
318
319 std::vector<Index64> offsets;
320
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 MultiGroupFilter filter(includeGroups, excludeGroups, inputTree.cbeginLeaf()->attributeSet());
321
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pointOffsets(offsets, inputTree, filter);
322
323
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridPosition(outputPosition, *pointDataGrid, offsets, startOffset, filter);
324
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputId, inputTree, offsets, startOffset, idIndex, 1, filter);
325
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputUniform, inputTree, offsets, startOffset, uniformIndex, 1, filter);
326
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputString, inputTree, offsets, startOffset, stringIndex, 1, filter);
327
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridGroup(outputGroup, inputTree, offsets, startOffset, groupIndex, filter);
328
329 // pack and sort the new buffers based on id
330
331
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::vector<PointData> pointData(count);
332
333
2/2
✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 1 times.
1000001 for (unsigned int i = 0; i < count; i++) {
334
1/2
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
1000000 pointData[i].id = outputId.buffer()[startOffset + i];
335 1000000 pointData[i].position = outputPosition.buffer()[startOffset + i];
336 1000000 pointData[i].uniform = outputUniform.buffer()[startOffset + i];
337
1/2
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
1000000 pointData[i].string = outputString.buffer()[startOffset + i];
338 1000000 pointData[i].group = outputGroup.buffer()[startOffset + i];
339 }
340
341 1 std::sort(pointData.begin(), pointData.end());
342
343 // compare old and new buffers
344
345
2/2
✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 1 times.
1000001 for (unsigned int i = 0; i < count; i++)
346 {
347
2/16
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 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.
1000000 EXPECT_EQ(id.buffer()[i], pointData[i].id);
348
2/16
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 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.
1000000 EXPECT_EQ(group.buffer()[i], pointData[i].group);
349
2/16
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 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.
1000000 EXPECT_EQ(uniform.buffer()[i], pointData[i].uniform);
350
2/16
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 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.
1000000 EXPECT_EQ(string.buffer()[i], pointData[i].string);
351
2/16
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 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.
1000000 EXPECT_NEAR(position.buffer()[i].x(), pointData[i].position.x(), /*tolerance=*/1e-6);
352
2/16
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 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.
1000000 EXPECT_NEAR(position.buffer()[i].y(), pointData[i].position.y(), /*tolerance=*/1e-6);
353
2/16
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 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.
1000000 EXPECT_NEAR(position.buffer()[i].z(), pointData[i].position.z(), /*tolerance=*/1e-6);
354 }
355
356 // convert based on even group
357
358 const size_t halfCount = count / 2;
359
360 outputPosition.resize(startOffset + halfCount);
361 outputId.resize(startOffset + halfCount);
362 outputUniform.resize(startOffset + halfCount);
363 outputString.resize(startOffset + halfCount);
364 outputGroup.resize(startOffset + halfCount);
365
366
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 includeGroups.push_back("test");
367
368 offsets.clear();
369
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 MultiGroupFilter filter2(includeGroups, excludeGroups, inputTree.cbeginLeaf()->attributeSet());
370
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pointOffsets(offsets, inputTree, filter2);
371
372
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridPosition(outputPosition, *pointDataGrid, offsets, startOffset, filter2);
373
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputId, inputTree, offsets, startOffset, idIndex, /*stride*/1, filter2);
374
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputUniform, inputTree, offsets, startOffset, uniformIndex, /*stride*/1, filter2);
375
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputString, inputTree, offsets, startOffset, stringIndex, /*stride*/1, filter2);
376
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridGroup(outputGroup, inputTree, offsets, startOffset, groupIndex, filter2);
377
378
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(size_t(outputPosition.size() - startOffset), size_t(halfCount));
379
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(size_t(outputId.size() - startOffset), size_t(halfCount));
380
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(size_t(outputUniform.size() - startOffset), size_t(halfCount));
381
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(size_t(outputString.size() - startOffset), size_t(halfCount));
382
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(size_t(outputGroup.size() - startOffset), size_t(halfCount));
383
384 pointData.clear();
385
386
2/2
✓ Branch 0 taken 500000 times.
✓ Branch 1 taken 1 times.
500001 for (unsigned int i = 0; i < halfCount; i++) {
387 PointData data;
388
1/2
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
500000 data.id = outputId.buffer()[startOffset + i];
389 500000 data.position = outputPosition.buffer()[startOffset + i];
390
1/2
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
500000 data.uniform = outputUniform.buffer()[startOffset + i];
391 data.string = outputString.buffer()[startOffset + i];
392 500000 data.group = outputGroup.buffer()[startOffset + i];
393
1/2
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
500000 pointData.push_back(data);
394 }
395
396 1 std::sort(pointData.begin(), pointData.end());
397
398 // compare old and new buffers
399
400
2/2
✓ Branch 0 taken 500000 times.
✓ Branch 1 taken 1 times.
500001 for (unsigned int i = 0; i < halfCount; i++)
401 {
402
2/16
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 500000 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.
500000 EXPECT_EQ(id.buffer()[i*2], pointData[i].id);
403
2/16
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 500000 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.
500000 EXPECT_EQ(group.buffer()[i*2], pointData[i].group);
404
2/16
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 500000 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.
500000 EXPECT_EQ(uniform.buffer()[i*2], pointData[i].uniform);
405
2/16
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 500000 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.
500000 EXPECT_EQ(string.buffer()[i*2], pointData[i].string);
406
2/16
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 500000 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.
500000 EXPECT_NEAR(position.buffer()[i*2].x(), pointData[i].position.x(), /*tolerance=*/1e-6);
407
2/16
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 500000 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.
500000 EXPECT_NEAR(position.buffer()[i*2].y(), pointData[i].position.y(), /*tolerance=*/1e-6);
408
2/16
✓ Branch 1 taken 500000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 500000 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.
500000 EXPECT_NEAR(position.buffer()[i*2].z(), pointData[i].position.z(), /*tolerance=*/1e-6);
409 }
410
411
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 file.close();
412 1 std::remove(filename.c_str());
413 1 }
414
415
416 ////////////////////////////////////////
417
418
419
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPointConversion, testPointConversionNans)
420 {
421 // generate points
422
423
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t count(25);
424
425 AttributeWrapper<Vec3f> position(1);
426 AttributeWrapper<int> xyz(1);
427 AttributeWrapper<int> id(1);
428 AttributeWrapper<float> uniform(1);
429 AttributeWrapper<openvdb::Name> string(1);
430 GroupWrapper group;
431
432
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 genPoints(count, /*scale=*/ 1.0, /*stride=*/false,
433 position, xyz, id, uniform, string, group);
434
435 // set point numbers 0, 10, 20 and 24 to a nan position
436
437
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 const std::vector<int> nanIndices = { 0, 10, 20, 24 };
438
439 AttributeWrapper<Vec3f>::Handle positionHandle(position);
440 const Vec3f nanPos(std::nan("0"));
441
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(nanPos.isNan());
442
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (const int& idx : nanIndices) {
443 4 positionHandle.set(idx, /*stride*/0, nanPos);
444 }
445
446
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(count, position.size());
447
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(count, id.size());
448
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(count, uniform.size());
449
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(count, string.size());
450
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(count, group.size());
451
452 // convert point positions into a Point Data Grid
453
454 openvdb::math::Transform::Ptr transform =
455
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(/*voxelsize*/1.0f);
456
457
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::PointIndexGrid::Ptr pointIndexGrid = tools::createPointIndexGrid<tools::PointIndexGrid>(position, *transform);
458
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr pointDataGrid = createPointDataGrid<NullCodec, PointDataGrid>(*pointIndexGrid, position, *transform);
459
460 tools::PointIndexTree& indexTree = pointIndexGrid->tree();
461 PointDataTree& tree = pointDataGrid->tree();
462
463 // set expected point count to the total minus the number of nan positions
464 1 const size_t expected = count - nanIndices.size();
465
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(expected, static_cast<size_t>(pointCount(tree)));
466
467 // add id and populate
468
469
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendAttribute<int>(tree, "id");
470
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<int>>(tree, indexTree, "id", id);
471
472 // add uniform and populate
473
474
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendAttribute<float>(tree, "uniform");
475
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 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<float>>(tree, indexTree, "uniform", uniform);
476
477 // add string and populate
478
479
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 appendAttribute<Name>(tree, "string");
480
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<openvdb::Name>>(
481 tree, indexTree, "string", string);
482
483 // add group and set membership
484
485
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendGroup(tree, "test");
486
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 setGroup(tree, indexTree, group.buffer(), "test");
487
488 // create accessor and iterator for Point Data Tree
489
490 const auto leafCIter = tree.cbeginLeaf();
491
492
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(5, int(leafCIter->attributeSet().size()));
493
494
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("id") != AttributeSet::INVALID_POS);
495
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("uniform") != AttributeSet::INVALID_POS);
496
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("P") != AttributeSet::INVALID_POS);
497
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("string") != AttributeSet::INVALID_POS);
498
499
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto idIndex = static_cast<Index>(leafCIter->attributeSet().find("id"));
500
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto uniformIndex = static_cast<Index>(leafCIter->attributeSet().find("uniform"));
501
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto stringIndex = static_cast<Index>(leafCIter->attributeSet().find("string"));
502 const AttributeSet::Descriptor::GroupIndex groupIndex =
503
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 leafCIter->attributeSet().groupIndex("test");
504
505 // convert back into linear point attribute data
506
507 AttributeWrapper<Vec3f> outputPosition(1);
508 AttributeWrapper<int> outputId(1);
509 AttributeWrapper<float> outputUniform(1);
510 AttributeWrapper<openvdb::Name> outputString(1);
511 GroupWrapper outputGroup;
512
513 outputPosition.resize(position.size());
514 outputId.resize(id.size());
515 outputUniform.resize(uniform.size());
516 outputString.resize(string.size());
517 outputGroup.resize(group.size());
518
519 std::vector<Index64> offsets;
520
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 pointOffsets(offsets, tree);
521
522
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridPosition(outputPosition, *pointDataGrid, offsets, 0);
523
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputId, tree, offsets, 0, idIndex, 1);
524
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputUniform, tree, offsets, 0, uniformIndex, 1);
525
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputString, tree, offsets, 0, stringIndex, 1);
526
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridGroup(outputGroup, tree, offsets, 0, groupIndex);
527
528 // pack and sort the new buffers based on id
529
530
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
2 std::vector<PointData> pointData(expected);
531
532
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 1 times.
22 for (unsigned int i = 0; i < expected; i++) {
533 21 pointData[i].id = outputId.buffer()[i];
534 21 pointData[i].position = outputPosition.buffer()[i];
535 21 pointData[i].uniform = outputUniform.buffer()[i];
536
1/2
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
21 pointData[i].string = outputString.buffer()[i];
537 21 pointData[i].group = outputGroup.buffer()[i];
538 }
539
540 1 std::sort(pointData.begin(), pointData.end());
541
542 // compare old and new buffers, taking into account the nan position
543 // which should not have been converted
544
545
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 1 times.
22 for (unsigned int i = 0; i < expected; ++i)
546 {
547 size_t iOffset = i;
548
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 21 times.
105 for (const int& idx : nanIndices) {
549
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 48 times.
84 if (int(iOffset) >= idx) iOffset += 1;
550 }
551
552
2/16
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 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.
21 EXPECT_EQ(id.buffer()[iOffset], pointData[i].id);
553
2/16
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 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.
21 EXPECT_EQ(group.buffer()[iOffset], pointData[i].group);
554
2/16
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 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.
21 EXPECT_EQ(uniform.buffer()[iOffset], pointData[i].uniform);
555
2/16
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 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.
21 EXPECT_EQ(string.buffer()[iOffset], pointData[i].string);
556
2/16
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 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.
21 EXPECT_NEAR(position.buffer()[iOffset].x(), pointData[i].position.x(), /*tolerance=*/1e-6);
557
2/16
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 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.
21 EXPECT_NEAR(position.buffer()[iOffset].y(), pointData[i].position.y(), /*tolerance=*/1e-6);
558
2/16
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 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.
21 EXPECT_NEAR(position.buffer()[iOffset].z(), pointData[i].position.z(), /*tolerance=*/1e-6);
559 }
560 1 }
561
562
563 ////////////////////////////////////////
564
565
566
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPointConversion, testStride)
567 {
568 // generate points
569
570
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t count(40000);
571
572 AttributeWrapper<Vec3f> position(1);
573 AttributeWrapper<int> xyz(3);
574 AttributeWrapper<int> id(1);
575 AttributeWrapper<float> uniform(1);
576 AttributeWrapper<openvdb::Name> string(1);
577 GroupWrapper group;
578
579
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 genPoints(count, /*scale=*/ 100.0, /*stride=*/true,
580 position, xyz, id, uniform, string, group);
581
582
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(position.size(), count);
583
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(xyz.size(), count*3);
584
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(id.size(), count);
585
586 // convert point positions into a Point Data Grid
587
588 const float voxelSize = 1.0f;
589
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::Ptr transform(openvdb::math::Transform::createLinearTransform(voxelSize));
590
591
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::PointIndexGrid::Ptr pointIndexGrid = tools::createPointIndexGrid<tools::PointIndexGrid>(position, *transform);
592
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr pointDataGrid = createPointDataGrid<NullCodec, PointDataGrid>(*pointIndexGrid, position, *transform);
593
594 tools::PointIndexTree& indexTree = pointIndexGrid->tree();
595 PointDataTree& tree = pointDataGrid->tree();
596
597 // add id and populate
598
599
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendAttribute<int>(tree, "id");
600
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<int>>(tree, indexTree, "id", id);
601
602 // add xyz and populate
603
604
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendAttribute<int>(tree, "xyz", 0, /*stride=*/3);
605
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 populateAttribute<PointDataTree, tools::PointIndexTree, AttributeWrapper<int>>(tree, indexTree, "xyz", xyz, /*stride=*/3);
606
607 // create accessor and iterator for Point Data Tree
608
609 PointDataTree::LeafCIter leafCIter = tree.cbeginLeaf();
610
611
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(3, int(leafCIter->attributeSet().size()));
612
613
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("id") != AttributeSet::INVALID_POS);
614
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("P") != AttributeSet::INVALID_POS);
615
3/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ 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 23 not taken.
✗ Branch 24 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(leafCIter->attributeSet().find("xyz") != AttributeSet::INVALID_POS);
616
617
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto idIndex = static_cast<Index>(leafCIter->attributeSet().find("id"));
618
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 const auto xyzIndex = static_cast<Index>(leafCIter->attributeSet().find("xyz"));
619
620 // convert back into linear point attribute data
621
622 AttributeWrapper<Vec3f> outputPosition(1);
623 AttributeWrapper<int> outputXyz(3);
624 AttributeWrapper<int> outputId(1);
625
626 // test offset the whole point block by an arbitrary amount
627
628 Index64 startOffset = 10;
629
630
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputPosition.resize(startOffset + position.size());
631
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputXyz.resize((startOffset + id.size())*3);
632
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputId.resize(startOffset + id.size());
633
634 std::vector<Index64> offsets;
635
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 pointOffsets(offsets, tree);
636
637
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridPosition(outputPosition, *pointDataGrid, offsets, startOffset);
638
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 convertPointDataGridAttribute(outputId, tree, offsets, startOffset, idIndex);
639
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 convertPointDataGridAttribute(outputXyz, tree, offsets, startOffset, xyzIndex, /*stride=*/3);
640
641 // pack and sort the new buffers based on id
642
643 1 std::vector<PointData> pointData;
644
645
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pointData.resize(count);
646
647
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 1 times.
40001 for (unsigned int i = 0; i < count; i++) {
648 40000 pointData[i].id = outputId.buffer()[startOffset + i];
649 40000 pointData[i].position = outputPosition.buffer()[startOffset + i];
650
2/2
✓ Branch 0 taken 120000 times.
✓ Branch 1 taken 40000 times.
160000 for (unsigned int j = 0; j < 3; j++) {
651 120000 pointData[i].xyz[j] = outputXyz.buffer()[startOffset * 3 + i * 3 + j];
652 }
653 }
654
655 1 std::sort(pointData.begin(), pointData.end());
656
657 // compare old and new buffers
658
659
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 1 times.
40001 for (unsigned int i = 0; i < count; i++)
660 {
661
2/16
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 40000 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.
40000 EXPECT_EQ(id.buffer()[i], pointData[i].id);
662
2/16
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 40000 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.
40000 EXPECT_NEAR(position.buffer()[i].x(), pointData[i].position.x(), /*tolerance=*/1e-6);
663
2/16
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 40000 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.
40000 EXPECT_NEAR(position.buffer()[i].y(), pointData[i].position.y(), /*tolerance=*/1e-6);
664
2/16
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 40000 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.
40000 EXPECT_NEAR(position.buffer()[i].z(), pointData[i].position.z(), /*tolerance=*/1e-6);
665
2/16
✓ Branch 1 taken 40000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 40000 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.
40000 EXPECT_EQ(Vec3i(xyz.buffer()[i*3], xyz.buffer()[i*3+1], xyz.buffer()[i*3+2]), pointData[i].xyz);
666 }
667 1 }
668
669
670 ////////////////////////////////////////
671
672
673
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPointConversion, testComputeVoxelSize)
674 {
675 struct Local {
676
677 6 static PointDataGrid::Ptr genPointsGrid(const float voxelSize, const AttributeWrapper<Vec3f>& positions)
678 {
679 6 math::Transform::Ptr transform(math::Transform::createLinearTransform(voxelSize));
680
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 tools::PointIndexGrid::Ptr pointIndexGrid = tools::createPointIndexGrid<tools::PointIndexGrid>(positions, *transform);
681
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 return createPointDataGrid<NullCodec, PointDataGrid>(*pointIndexGrid, positions, *transform);
682 }
683 };
684
685 // minimum and maximum voxel sizes
686
687 1 const auto minimumVoxelSize = static_cast<float>(math::Pow(double(3e-15), 1.0/3.0));
688 const auto maximumVoxelSize =
689 1 static_cast<float>(math::Pow(double(std::numeric_limits<float>::max()), 1.0/3.0));
690
691 AttributeWrapper<Vec3f> position(/*stride*/1);
692 AttributeWrapper<Vec3d> positionD(/*stride*/1);
693
694 // test with no positions
695
696 {
697
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 const float voxelSize = computeVoxelSize(position, /*points per voxel*/8);
698
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(voxelSize, 0.1f);
699 }
700
701 // test with one point
702
703 {
704 position.resize(1);
705 AttributeWrapper<Vec3f>::Handle positionHandle(position);
706 1 positionHandle.set(0, 0, Vec3f(0.0f));
707
708
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 const float voxelSize = computeVoxelSize(position, /*points per voxel*/8);
709
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(voxelSize, 0.1f);
710 }
711
712 // test with n points, where n > 1 && n <= num points per voxel
713
714 {
715 position.resize(7);
716 AttributeWrapper<Vec3f>::Handle positionHandle(position);
717 1 positionHandle.set(0, 0, Vec3f(-8.6f, 0.0f,-23.8f));
718 1 positionHandle.set(1, 0, Vec3f( 8.6f, 7.8f, 23.8f));
719
720
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 for (size_t i = 2; i < 7; ++ i)
721 5 positionHandle.set(i, 0, Vec3f(0.0f));
722
723
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/8);
724
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(18.5528f, voxelSize, /*tolerance=*/1e-4);
725
726
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
727
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(5.51306f, voxelSize, /*tolerance=*/1e-4);
728
729 // test decimal place accuracy
730
731
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1, math::Mat4d::identity(), 10);
732
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(5.5130610466f, voxelSize, /*tolerance=*/1e-9);
733
734
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1, math::Mat4d::identity(), 1);
735
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(5.5f, voxelSize);
736
737
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1, math::Mat4d::identity(), 0);
738
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(6.0f, voxelSize);
739 }
740
741 // test coplanar points (Y=0)
742
743 {
744 position.resize(5);
745 AttributeWrapper<Vec3f>::Handle positionHandle(position);
746 1 positionHandle.set(0, 0, Vec3f(0.0f, 0.0f, 10.0f));
747 1 positionHandle.set(1, 0, Vec3f(0.0f, 0.0f, -10.0f));
748 1 positionHandle.set(2, 0, Vec3f(20.0f, 0.0f, -10.0f));
749 1 positionHandle.set(3, 0, Vec3f(20.0f, 0.0f, 10.0f));
750 1 positionHandle.set(4, 0, Vec3f(10.0f, 0.0f, 0.0f));
751
752
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/5);
753
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(20.0f, voxelSize, /*tolerance=*/1e-4);
754
755
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
756
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(11.696f, voxelSize, /*tolerance=*/1e-4);
757 }
758
759 // test collinear points (X=0, Y=0)
760
761 {
762 position.resize(5);
763 AttributeWrapper<Vec3f>::Handle positionHandle(position);
764 1 positionHandle.set(0, 0, Vec3f(0.0f, 0.0f, 10.0f));
765 1 positionHandle.set(1, 0, Vec3f(0.0f, 0.0f, -10.0f));
766 1 positionHandle.set(2, 0, Vec3f(0.0f, 0.0f, -10.0f));
767 1 positionHandle.set(3, 0, Vec3f(0.0f, 0.0f, 10.0f));
768 1 positionHandle.set(4, 0, Vec3f(0.0f, 0.0f, 0.0f));
769
770
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/5);
771
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(20.0f, voxelSize, /*tolerance=*/1e-4);
772
773
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
774
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(8.32034f, voxelSize, /*tolerance=*/1e-4);
775 }
776
777 // test min limit collinear points (X=0, Y=0, Z=+/-float min)
778
779 {
780 position.resize(2);
781 AttributeWrapper<Vec3f>::Handle positionHandle(position);
782 1 positionHandle.set(0, 0, Vec3f(0.0f, 0.0f, -std::numeric_limits<float>::min()));
783 1 positionHandle.set(1, 0, Vec3f(0.0f, 0.0f, std::numeric_limits<float>::min()));
784
785
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/2);
786
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(minimumVoxelSize, voxelSize, /*tolerance=*/1e-4);
787
788
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
789
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(minimumVoxelSize, voxelSize, /*tolerance=*/1e-4);
790 }
791
792 // test max limit collinear points (X=+/-float max, Y=0, Z=0)
793
794 {
795 position.resize(2);
796 AttributeWrapper<Vec3f>::Handle positionHandle(position);
797 1 positionHandle.set(0, 0, Vec3f(-std::numeric_limits<float>::max(), 0.0f, 0.0f));
798 1 positionHandle.set(1, 0, Vec3f(std::numeric_limits<float>::max(), 0.0f, 0.0f));
799
800
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/2);
801
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(maximumVoxelSize, voxelSize, /*tolerance=*/1e-4);
802
803
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
804
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(maximumVoxelSize, voxelSize, /*tolerance=*/1e-4);
805 }
806
807 // max pointsPerVoxel
808
809 {
810 position.resize(2);
811 AttributeWrapper<Vec3f>::Handle positionHandle(position);
812 1 positionHandle.set(0, 0, Vec3f(0));
813 1 positionHandle.set(1, 0, Vec3f(1));
814
815
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/std::numeric_limits<uint32_t>::max());
816
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(voxelSize, 1.0f);
817 }
818
819 // limits test
820
821 {
822 positionD.resize(2);
823 AttributeWrapper<Vec3d>::Handle positionHandleD(positionD);
824 1 positionHandleD.set(0, 0, Vec3d(0));
825 1 positionHandleD.set(1, 0, Vec3d(std::numeric_limits<double>::max()));
826
827
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 float voxelSize = computeVoxelSize(positionD, /*points per voxel*/2);
828
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(voxelSize, maximumVoxelSize);
829 }
830
831 {
832 const float smallest(std::numeric_limits<float>::min());
833
834 position.resize(4);
835 AttributeWrapper<Vec3f>::Handle positionHandle(position);
836 1 positionHandle.set(0, 0, Vec3f(0.0f));
837 1 positionHandle.set(1, 0, Vec3f(smallest));
838 1 positionHandle.set(2, 0, Vec3f(smallest, 0.0f, 0.0f));
839 1 positionHandle.set(3, 0, Vec3f(smallest, 0.0f, smallest));
840
841
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/4);
842
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(voxelSize, minimumVoxelSize);
843
844
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
845
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(minimumVoxelSize, voxelSize, /*tolerance=*/1e-4);
846
847
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr grid = Local::genPointsGrid(voxelSize, position);
848
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(grid->activeVoxelCount(), Index64(1));
849 }
850
851 // the smallest possible vector extent that can exist from an input set
852 // without being clamped to the minimum voxel size
853 // is Tolerance<Real>::value() + std::numeric_limits<Real>::min()
854
855 {
856 position.resize(2);
857 AttributeWrapper<Vec3f>::Handle positionHandle(position);
858 1 positionHandle.set(0, 0, Vec3f(0.0f));
859 1 positionHandle.set(1, 0, Vec3f(math::Tolerance<Real>::value() + std::numeric_limits<Real>::min()));
860
861
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/1);
862
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(voxelSize, minimumVoxelSize);
863 }
864
865 // in-between smallest extent and ScaleMap determinant test
866
867 {
868 position.resize(2);
869 AttributeWrapper<Vec3f>::Handle positionHandle(position);
870 1 positionHandle.set(0, 0, Vec3f(0.0f));
871 1 positionHandle.set(1, 0, Vec3f(math::Tolerance<Real>::value()*1e8 + std::numeric_limits<Real>::min()));
872
873
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/1);
874
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(voxelSize, float(math::Pow(double(3e-15), 1.0/3.0)));
875 }
876
877 {
878 const float smallValue(1e-5f);
879
880 position.resize(300000);
881 AttributeWrapper<Vec3f>::Handle positionHandle(position);
882
883
2/2
✓ Branch 0 taken 100000 times.
✓ Branch 1 taken 1 times.
100001 for (size_t i = 0; i < 100000; ++ i) {
884 100000 positionHandle.set(i, 0, Vec3f(smallValue*float(i), 0, 0));
885 100000 positionHandle.set(i+100000, 0, Vec3f(0, smallValue*float(i), 0));
886 100000 positionHandle.set(i+200000, 0, Vec3f(0, 0, smallValue*float(i)));
887 }
888
889
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/10);
890
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(0.00012f, voxelSize, /*tolerance=*/1e-4);
891
892
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
893
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(2e-5, voxelSize, /*tolerance=*/1e-6);
894
895
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr grid = Local::genPointsGrid(voxelSize, position);
896
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(grid->activeVoxelCount(), Index64(150001));
897
898 // check zero decimal place still returns valid result
899
900
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1, math::Mat4d::identity(), 0);
901
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(2e-5, voxelSize, /*tolerance=*/1e-6);
902 }
903
904 // random position generation within two bounds of equal size.
905 // This test distributes 1000 points within a 1x1x1 box centered at (0,0,0)
906 // and another 1000 points within a separate 1x1x1 box centered at (20,20,20).
907 // Points are randomly positioned however can be defined as having a stochastic
908 // distribution. Tests that sparsity between these data sets causes no issues
909 // and that computeVoxelSize produces accurate results
910
911 {
912 position.resize(2000);
913 AttributeWrapper<Vec3f>::Handle positionHandle(position);
914 openvdb::math::Random01 randNumber(0);
915
916 // positions between -0.5 and 0.5
917
918
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
1001 for (size_t i = 0; i < 1000; ++ i) {
919 1000 const Vec3f pos(randNumber() - 0.5f);
920 positionHandle.set(i, 0, pos);
921 }
922
923 // positions between 19.5 and 20.5
924
925
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
1001 for (size_t i = 1000; i < 2000; ++ i) {
926 1000 const Vec3f pos(randNumber() - 0.5f + 20.0f);
927 positionHandle.set(i, 0, pos);
928 }
929
930
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/1);
931
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(0.00052f, voxelSize, /*tolerance=*/1e-4);
932
933
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr grid = Local::genPointsGrid(voxelSize, position);
934 1 const auto pointsPerVoxel = static_cast<Index64>(
935
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::Round(2000.0f / static_cast<float>(grid->activeVoxelCount())));
936
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(pointsPerVoxel, Index64(1));
937 }
938
939 // random position generation within three bounds of varying size.
940 // This test distributes 1000 points within a 1x1x1 box centered at (0.5,0.5,0,5)
941 // another 1000 points within a separate 10x10x10 box centered at (15,15,15) and
942 // a final 1000 points within a separate 50x50x50 box centered at (75,75,75)
943 // Points are randomly positioned however can be defined as having a stochastic
944 // distribution. Tests that sparsity between these data sets causes no issues as
945 // well as computeVoxelSize producing a good average result
946
947 {
948 position.resize(3000);
949 AttributeWrapper<Vec3f>::Handle positionHandle(position);
950 openvdb::math::Random01 randNumber(0);
951
952 // positions between 0 and 1
953
954
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
1001 for (size_t i = 0; i < 1000; ++ i) {
955 const Vec3f pos(randNumber());
956 positionHandle.set(i, 0, pos);
957 }
958
959 // positions between 10 and 20
960
961
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
1001 for (size_t i = 1000; i < 2000; ++ i) {
962 1000 const Vec3f pos((randNumber() * 10.0f) + 10.0f);
963 positionHandle.set(i, 0, pos);
964 }
965
966 // positions between 50 and 100
967
968
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
1001 for (size_t i = 2000; i < 3000; ++ i) {
969 1000 const Vec3f pos((randNumber() * 50.0f) + 50.0f);
970 positionHandle.set(i, 0, pos);
971 }
972
973
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 float voxelSize = computeVoxelSize(position, /*points per voxel*/10);
974
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(0.24758f, voxelSize, /*tolerance=*/1e-3);
975
976
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr grid = Local::genPointsGrid(voxelSize, position);
977
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 auto pointsPerVoxel = static_cast<Index64>(
978
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 math::Round(3000.0f/ static_cast<float>(grid->activeVoxelCount())));
979
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(math::isApproxEqual(pointsPerVoxel, Index64(10), Index64(2)));
980
981
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 voxelSize = computeVoxelSize(position, /*points per voxel*/1);
982
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(0.00231f, voxelSize, /*tolerance=*/1e-4);
983
984
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 grid = Local::genPointsGrid(voxelSize, position);
985 1 pointsPerVoxel = static_cast<Index64>(
986
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::Round(3000.0f/ static_cast<float>(grid->activeVoxelCount())));
987
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(pointsPerVoxel, Index64(1));
988 }
989
990 // Generate a sphere
991 // NOTE: The sphere does NOT provide uniform distribution
992
993
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t count(40000);
994
995 position.resize(0);
996
997 AttributeWrapper<int> xyz(1);
998 AttributeWrapper<int> id(1);
999 AttributeWrapper<float> uniform(1);
1000 AttributeWrapper<openvdb::Name> string(1);
1001 GroupWrapper group;
1002
1003
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 genPoints(count, /*scale=*/ 100.0, /*stride=*/false, position, xyz, id, uniform, string, group);
1004
1005
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(position.size(), count);
1006
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(id.size(), count);
1007
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(uniform.size(), count);
1008
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(string.size(), count);
1009
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(group.size(), count);
1010
1011 // test a distributed point set around a sphere
1012
1013 {
1014
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 const float voxelSize = computeVoxelSize(position, /*points per voxel*/2);
1015
1016
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(2.6275f, voxelSize, /*tolerance=*/0.01);
1017
1018
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 PointDataGrid::Ptr grid = Local::genPointsGrid(voxelSize, position);
1019
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const Index64 pointsPerVoxel = count / grid->activeVoxelCount();
1020
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(pointsPerVoxel, Index64(2));
1021 }
1022
1023 // test with given target transforms
1024
1025 {
1026 // test that a different scale doesn't change the result
1027
1028
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::Ptr transform1(openvdb::math::Transform::createLinearTransform(0.33));
1029
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::Ptr transform2(openvdb::math::Transform::createLinearTransform(0.87));
1030
1031 math::UniformScaleMap::ConstPtr scaleMap1 = transform1->constMap<math::UniformScaleMap>();
1032 math::UniformScaleMap::ConstPtr scaleMap2 = transform2->constMap<math::UniformScaleMap>();
1033
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(scaleMap1.get());
1034
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(scaleMap2.get());
1035
1036
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::AffineMap::ConstPtr affineMap1 = scaleMap1->getAffineMap();
1037
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::AffineMap::ConstPtr affineMap2 = scaleMap2->getAffineMap();
1038
1039
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 float voxelSize1 = computeVoxelSize(position, /*points per voxel*/2, affineMap1->getMat4());
1040
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 float voxelSize2 = computeVoxelSize(position, /*points per voxel*/2, affineMap2->getMat4());
1041
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(voxelSize1, voxelSize2);
1042
1043 // test that applying a rotation roughly calculates to the same result for this example
1044 // NOTE: distribution is not uniform
1045
1046 // Rotate by 45 degrees in X, Y, Z
1047
1048
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 transform1->postRotate(M_PI / 4.0, math::X_AXIS);
1049
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 transform1->postRotate(M_PI / 4.0, math::Y_AXIS);
1050
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 transform1->postRotate(M_PI / 4.0, math::Z_AXIS);
1051
1052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 affineMap1 = transform1->constMap<math::AffineMap>();
1053
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(affineMap1.get());
1054
1055
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 float voxelSize3 = computeVoxelSize(position, /*points per voxel*/2, affineMap1->getMat4());
1056
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(voxelSize1, voxelSize3, 0.1);
1057
1058 // test that applying a translation roughly calculates to the same result for this example
1059
1060
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 transform1->postTranslate(Vec3d(-5.0f, 3.3f, 20.1f));
1061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 affineMap1 = transform1->constMap<math::AffineMap>();
1062
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(affineMap1.get());
1063
1064
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 float voxelSize4 = computeVoxelSize(position, /*points per voxel*/2, affineMap1->getMat4());
1065
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(voxelSize1, voxelSize4, 0.1);
1066 }
1067 1 }
1068
1069
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPointConversion, testPrecision)
1070 {
1071 const double tolerance = math::Tolerance<float>::value();
1072
1073 { // test values far from origin
1074 const double voxelSize = 0.5;
1075 const float halfVoxelSize = 0.25f;
1076 1 auto transform = math::Transform::createLinearTransform(voxelSize);
1077
1078 float onBorder = 1000.0f + halfVoxelSize; // can be represented exactly in floating-point
1079 float beforeBorder = std::nextafterf(onBorder, /*to=*/0.0f);
1080 float afterBorder = std::nextafterf(onBorder, /*to=*/2000.0f);
1081
1082 const Vec3f positionBefore(beforeBorder, afterBorder, onBorder);
1083
1084
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<Vec3f> points{positionBefore};
1085 PointAttributeVector<Vec3f> wrapper(points);
1086 auto pointIndexGrid = tools::createPointIndexGrid<tools::PointIndexGrid>(
1087
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 wrapper, *transform);
1088
1089 Vec3f positionAfterNull;
1090 Vec3f positionAfterFixed16;
1091
1092 { // null codec
1093 auto points = createPointDataGrid<NullCodec, PointDataGrid>(
1094
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *pointIndexGrid, wrapper, *transform);
1095
1096 auto leafIter = points->tree().cbeginLeaf();
1097
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto indexIter = leafIter->beginIndexOn();
1098
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
3 auto handle = AttributeHandle<Vec3f>(leafIter->constAttributeArray("P"));
1099
1100
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto& ijk = indexIter.getCoord();
1101
1102
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(ijk.x(), 2000);
1103
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(ijk.y(), 2001);
1104
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(ijk.z(), 2001); // on border value is stored in the higher voxel
1105
1106
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 const Vec3f positionVoxelSpace = handle.get(*indexIter);
1107
1108 // voxel-space range: -0.5f >= value > 0.5f
1109
1110
3/20
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_TRUE(positionVoxelSpace.x() > 0.49f && positionVoxelSpace.x() < 0.5f);
1111
3/20
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_TRUE(positionVoxelSpace.y() > -0.5f && positionVoxelSpace.y() < -0.49f);
1112
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(positionVoxelSpace.z() == -0.5f); // on border value is stored at -0.5f
1113
1114 positionAfterNull = Vec3f(transform->indexToWorld(positionVoxelSpace + ijk.asVec3d()));
1115
1116
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(positionAfterNull.x(), positionBefore.x(), tolerance);
1117
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(positionAfterNull.y(), positionBefore.y(), tolerance);
1118
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(positionAfterNull.z(), positionBefore.z(), tolerance);
1119 }
1120
1121 { // fixed 16-bit codec
1122 auto points = createPointDataGrid<FixedPointCodec<false>, PointDataGrid>(
1123
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *pointIndexGrid, wrapper, *transform);
1124
1125 auto leafIter = points->tree().cbeginLeaf();
1126
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto indexIter = leafIter->beginIndexOn();
1127
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
3 auto handle = AttributeHandle<Vec3f>(leafIter->constAttributeArray("P"));
1128
1129
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto& ijk = indexIter.getCoord();
1130
1131
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(ijk.x(), 2000);
1132
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(ijk.y(), 2001);
1133
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(ijk.z(), 2001); // on border value is stored in the higher voxel
1134
1135
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 const Vec3f positionVoxelSpace = handle.get(*indexIter);
1136
1137 // voxel-space range: -0.5f >= value > 0.5f
1138
1139
3/20
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_TRUE(positionVoxelSpace.x() > 0.49f && positionVoxelSpace.x() < 0.5f);
1140
3/20
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_TRUE(positionVoxelSpace.y() > -0.5f && positionVoxelSpace.y() < -0.49f);
1141
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(positionVoxelSpace.z() == -0.5f); // on border value is stored at -0.5f
1142
1143 1 positionAfterFixed16 = Vec3f(transform->indexToWorld(
1144 positionVoxelSpace + ijk.asVec3d()));
1145
1146
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(positionAfterFixed16.x(), positionBefore.x(), tolerance);
1147
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(positionAfterFixed16.y(), positionBefore.y(), tolerance);
1148
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(positionAfterFixed16.z(), positionBefore.z(), tolerance);
1149 }
1150
1151 // at this precision null codec == fixed-point 16-bit codec
1152
1153
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(positionAfterNull.x(), positionAfterFixed16.x());
1154
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(positionAfterNull.y(), positionAfterFixed16.y());
1155
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(positionAfterNull.z(), positionAfterFixed16.z());
1156 }
1157
1158 { // test values near to origin
1159 const double voxelSize = 0.5;
1160 const float halfVoxelSize = 0.25f;
1161 1 auto transform = math::Transform::createLinearTransform(voxelSize);
1162
1163 float onBorder = 0.0f+halfVoxelSize;
1164 float beforeBorder = std::nextafterf(onBorder, /*to=*/0.0f);
1165 float afterBorder = std::nextafterf(onBorder, /*to=*/2000.0f);
1166
1167 const Vec3f positionBefore(beforeBorder, afterBorder, onBorder);
1168
1169
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<Vec3f> points{positionBefore};
1170 PointAttributeVector<Vec3f> wrapper(points);
1171 auto pointIndexGrid = tools::createPointIndexGrid<tools::PointIndexGrid>(
1172
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 wrapper, *transform);
1173
1174 Vec3f positionAfterNull;
1175 Vec3f positionAfterFixed16;
1176
1177 { // null codec
1178 auto points = createPointDataGrid<NullCodec, PointDataGrid>(
1179
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *pointIndexGrid, wrapper, *transform);
1180
1181 auto leafIter = points->tree().cbeginLeaf();
1182
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto indexIter = leafIter->beginIndexOn();
1183
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
3 auto handle = AttributeHandle<Vec3f>(leafIter->constAttributeArray("P"));
1184
1185
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto& ijk = indexIter.getCoord();
1186
1187
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(ijk.x(), 0);
1188
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(ijk.y(), 1);
1189
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(ijk.z(), 1); // on border value is stored in the higher voxel
1190
1191
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 const Vec3f positionVoxelSpace = handle.get(*indexIter);
1192
1193 // voxel-space range: -0.5f >= value > 0.5f
1194
1195
3/20
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_TRUE(positionVoxelSpace.x() > 0.49f && positionVoxelSpace.x() < 0.5f);
1196
3/20
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_TRUE(positionVoxelSpace.y() > -0.5f && positionVoxelSpace.y() < -0.49f);
1197
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(positionVoxelSpace.z() == -0.5f); // on border value is stored at -0.5f
1198
1199 positionAfterNull = Vec3f(transform->indexToWorld(positionVoxelSpace + ijk.asVec3d()));
1200
1201
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(positionAfterNull.x(), positionBefore.x(), tolerance);
1202
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(positionAfterNull.y(), positionBefore.y(), tolerance);
1203
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(positionAfterNull.z(), positionBefore.z(), tolerance);
1204 }
1205
1206 { // fixed 16-bit codec - at this precision, this codec results in lossy compression
1207 auto points = createPointDataGrid<FixedPointCodec<false>, PointDataGrid>(
1208
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *pointIndexGrid, wrapper, *transform);
1209
1210 auto leafIter = points->tree().cbeginLeaf();
1211
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto indexIter = leafIter->beginIndexOn();
1212
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
3 auto handle = AttributeHandle<Vec3f>(leafIter->constAttributeArray("P"));
1213
1214
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto& ijk = indexIter.getCoord();
1215
1216
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(ijk.x(), 0);
1217
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(ijk.y(), 1);
1218
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(ijk.z(), 1); // on border value is stored in the higher voxel
1219
1220
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 const Vec3f positionVoxelSpace = handle.get(*indexIter);
1221
1222 // voxel-space range: -0.5f >= value > 0.5f
1223
1224
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(positionVoxelSpace.x() == 0.5f); // before border is clamped to 0.5f
1225
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(positionVoxelSpace.y() == -0.5f); // after border is clamped to -0.5f
1226
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(positionVoxelSpace.z() == -0.5f); // on border is stored at -0.5f
1227
1228 1 positionAfterFixed16 = Vec3f(transform->indexToWorld(
1229 positionVoxelSpace + ijk.asVec3d()));
1230
1231 // reduce tolerance to handle lack of precision
1232
1233
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(positionAfterFixed16.x(), positionBefore.x(), 1e-6);
1234
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(positionAfterFixed16.y(), positionBefore.y(), 1e-6);
1235
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(positionAfterFixed16.z(), positionBefore.z(), tolerance);
1236 }
1237
1238 // only z matches precisely due to lossy compression
1239
1240
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(positionAfterNull.x() != positionAfterFixed16.x());
1241
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(positionAfterNull.y() != positionAfterFixed16.y());
1242
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(positionAfterNull.z(), positionAfterFixed16.z());
1243 }
1244 1 }
1245
1246
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 TEST_F(TestPointConversion, testExample)
1247 {
1248 // this is the example from the documentation using both Vec3R and Vec3f
1249
1250 { // Vec3R
1251 // Create a vector with four point positions.
1252 std::vector<openvdb::Vec3R> positions;
1253
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3R(0, 1, 0));
1254
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3R(1.5, 3.5, 1));
1255
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3R(-1, 6, -2));
1256
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3R(1.1, 1.25, 0.06));
1257
1258 // The VDB Point-Partioner is used when bucketing points and requires a
1259 // specific interface. For convenience, we use the PointAttributeVector
1260 // wrapper around an stl vector wrapper here, however it is also possible to
1261 // write one for a custom data structure in order to match the interface
1262 // required.
1263 openvdb::points::PointAttributeVector<openvdb::Vec3R> positionsWrapper(positions);
1264
1265 // This method computes a voxel-size to match the number of
1266 // points / voxel requested. Although it won't be exact, it typically offers
1267 // a good balance of memory against performance.
1268 int pointsPerVoxel = 8;
1269 float voxelSize =
1270
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 openvdb::points::computeVoxelSize(positionsWrapper, pointsPerVoxel);
1271
1272 // Create a transform using this voxel-size.
1273 openvdb::math::Transform::Ptr transform =
1274
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(voxelSize);
1275
1276 // Create a PointDataGrid containing these four points and using the
1277 // transform given. This function has two template parameters, (1) the codec
1278 // to use for storing the position, (2) the grid we want to create
1279 // (ie a PointDataGrid).
1280 // We use no compression here for the positions.
1281 openvdb::points::PointDataGrid::Ptr grid =
1282 openvdb::points::createPointDataGrid<openvdb::points::NullCodec,
1283
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::points::PointDataGrid>(positions, *transform);
1284
1285 // Set the name of the grid
1286
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 grid->setName("Points");
1287
1288 // Create a VDB file object and write out the grid.
1289
6/14
✓ 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.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
4 openvdb::io::File("mypoints.vdb").write({grid});
1290
1291 // Create a new VDB file object for reading.
1292
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 openvdb::io::File newFile("mypoints.vdb");
1293
1294 // Open the file. This reads the file header, but not any grids.
1295
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 newFile.open();
1296
1297 // Read the grid by name.
1298
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 openvdb::GridBase::Ptr baseGrid = newFile.readGrid("Points");
1299
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 newFile.close();
1300
1301 // From the example above, "Points" is known to be a PointDataGrid,
1302 // so cast the generic grid pointer to a PointDataGrid pointer.
1303
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 grid = openvdb::gridPtrCast<openvdb::points::PointDataGrid>(baseGrid);
1304
1305 std::vector<Vec3R> resultingPositions;
1306
1307 // Iterate over all the leaf nodes in the grid.
1308
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (auto leafIter = grid->tree().cbeginLeaf(); leafIter; ++leafIter) {
1309
1310 // Extract the position attribute from the leaf by name (P is position).
1311 const openvdb::points::AttributeArray& array =
1312
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 leafIter->constAttributeArray("P");
1313
1314 // Create a read-only AttributeHandle. Position always uses Vec3f.
1315
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 openvdb::points::AttributeHandle<openvdb::Vec3f> positionHandle(array);
1316
1317 // Iterate over the point indices in the leaf.
1318
3/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
8 for (auto indexIter = leafIter->beginIndexOn(); indexIter; ++indexIter) {
1319
1320 // Extract the voxel-space position of the point.
1321
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 openvdb::Vec3f voxelPosition = positionHandle.get(*indexIter);
1322
1323 // Extract the index-space position of the voxel.
1324
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 const openvdb::Vec3d xyz = indexIter.getCoord().asVec3d();
1325
1326 // Compute the world-space position of the point.
1327 openvdb::Vec3f worldPosition =
1328
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 grid->transform().indexToWorld(voxelPosition + xyz);
1329
1330
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 resultingPositions.push_back(worldPosition);
1331 }
1332 }
1333
1334
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(size_t(4), resultingPositions.size());
1335
1336 // remap the position order
1337
1338 std::vector<size_t> remap;
1339
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 remap.push_back(1);
1340
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 remap.push_back(3);
1341
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 remap.push_back(0);
1342
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 remap.push_back(2);
1343
1344
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = 0; i < 4; i++) {
1345
2/16
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 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.
4 EXPECT_NEAR(positions[i].x(), resultingPositions[remap[i]].x(), /*tolerance=*/1e-6);
1346
2/16
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 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.
4 EXPECT_NEAR(positions[i].y(), resultingPositions[remap[i]].y(), /*tolerance=*/1e-6);
1347
2/16
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 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.
4 EXPECT_NEAR(positions[i].z(), resultingPositions[remap[i]].z(), /*tolerance=*/1e-6);
1348 }
1349
1350 1 remove("mypoints.vdb");
1351 }
1352
1353 { // Vec3f
1354 // Create a vector with four point positions.
1355 std::vector<openvdb::Vec3f> positions;
1356
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3f(0.0f, 1.0f, 0.0f));
1357
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3f(1.5f, 3.5f, 1.0f));
1358
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3f(-1.0f, 6.0f, -2.0f));
1359
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1 positions.push_back(openvdb::Vec3f(1.1f, 1.25f, 0.06f));
1360
1361 // The VDB Point-Partioner is used when bucketing points and requires a
1362 // specific interface. For convenience, we use the PointAttributeVector
1363 // wrapper around an stl vector wrapper here, however it is also possible to
1364 // write one for a custom data structure in order to match the interface
1365 // required.
1366 openvdb::points::PointAttributeVector<openvdb::Vec3f> positionsWrapper(positions);
1367
1368 // This method computes a voxel-size to match the number of
1369 // points / voxel requested. Although it won't be exact, it typically offers
1370 // a good balance of memory against performance.
1371 int pointsPerVoxel = 8;
1372 float voxelSize =
1373
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 openvdb::points::computeVoxelSize(positionsWrapper, pointsPerVoxel);
1374
1375 // Create a transform using this voxel-size.
1376 openvdb::math::Transform::Ptr transform =
1377
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(voxelSize);
1378
1379 // Create a PointDataGrid containing these four points and using the
1380 // transform given. This function has two template parameters, (1) the codec
1381 // to use for storing the position, (2) the grid we want to create
1382 // (ie a PointDataGrid).
1383 // We use no compression here for the positions.
1384 openvdb::points::PointDataGrid::Ptr grid =
1385 openvdb::points::createPointDataGrid<openvdb::points::NullCodec,
1386
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::points::PointDataGrid>(positions, *transform);
1387
1388 // Set the name of the grid
1389
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 grid->setName("Points");
1390
1391 // Create a VDB file object and write out the grid.
1392
6/14
✓ 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.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
4 openvdb::io::File("mypoints.vdb").write({grid});
1393
1394 // Create a new VDB file object for reading.
1395
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 openvdb::io::File newFile("mypoints.vdb");
1396
1397 // Open the file. This reads the file header, but not any grids.
1398
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 newFile.open();
1399
1400 // Read the grid by name.
1401
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 openvdb::GridBase::Ptr baseGrid = newFile.readGrid("Points");
1402
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 newFile.close();
1403
1404 // From the example above, "Points" is known to be a PointDataGrid,
1405 // so cast the generic grid pointer to a PointDataGrid pointer.
1406
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 grid = openvdb::gridPtrCast<openvdb::points::PointDataGrid>(baseGrid);
1407
1408 std::vector<Vec3f> resultingPositions;
1409
1410 // Iterate over all the leaf nodes in the grid.
1411
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (auto leafIter = grid->tree().cbeginLeaf(); leafIter; ++leafIter) {
1412
1413 // Extract the position attribute from the leaf by name (P is position).
1414 const openvdb::points::AttributeArray& array =
1415
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 leafIter->constAttributeArray("P");
1416
1417 // Create a read-only AttributeHandle. Position always uses Vec3f.
1418
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 openvdb::points::AttributeHandle<openvdb::Vec3f> positionHandle(array);
1419
1420 // Iterate over the point indices in the leaf.
1421
4/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
12 for (auto indexIter = leafIter->beginIndexOn(); indexIter; ++indexIter) {
1422
1423 // Extract the voxel-space position of the point.
1424
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 openvdb::Vec3f voxelPosition = positionHandle.get(*indexIter);
1425
1426 // Extract the index-space position of the voxel.
1427
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 const openvdb::Vec3d xyz = indexIter.getCoord().asVec3d();
1428
1429 // Compute the world-space position of the point.
1430 openvdb::Vec3f worldPosition =
1431 grid->transform().indexToWorld(voxelPosition + xyz);
1432
1433
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 resultingPositions.push_back(worldPosition);
1434 }
1435 }
1436
1437
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(size_t(4), resultingPositions.size());
1438
1439 // remap the position order
1440
1441 std::vector<size_t> remap;
1442
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 remap.push_back(1);
1443
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 remap.push_back(3);
1444
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 remap.push_back(0);
1445
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 remap.push_back(2);
1446
1447
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = 0; i < 4; i++) {
1448
2/16
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 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.
4 EXPECT_NEAR(positions[i].x(), resultingPositions[remap[i]].x(), /*tolerance=*/1e-6f);
1449
2/16
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 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.
4 EXPECT_NEAR(positions[i].y(), resultingPositions[remap[i]].y(), /*tolerance=*/1e-6f);
1450
2/16
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 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.
4 EXPECT_NEAR(positions[i].z(), resultingPositions[remap[i]].z(), /*tolerance=*/1e-6f);
1451 }
1452
1453 1 remove("mypoints.vdb");
1454 }
1455 1 }
1456