GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestPointMask.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 115 117 98.3%
Functions: 4 4 100.0%
Branches: 169 730 23.2%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/openvdb.h>
5 #include <openvdb/points/PointDataGrid.h>
6 #include <openvdb/points/PointConversion.h>
7 #include <openvdb/points/PointMask.h>
8
9 #include <gtest/gtest.h>
10
11 #include <algorithm>
12 #include <string>
13 #include <vector>
14
15 using namespace openvdb;
16 using namespace openvdb::points;
17
18 2 class TestPointMask: public ::testing::Test
19 {
20 public:
21 2 void SetUp() override { openvdb::initialize(); }
22 2 void TearDown() override { openvdb::uninitialize(); }
23 }; // class TestPointMask
24
25
26
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestPointMask, testMask)
27 {
28 std::vector<Vec3s> positions = {
29 {1, 1, 1},
30 {1, 5, 1},
31 {2, 1, 1},
32 {2, 2, 1},
33
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 };
34
35 const PointAttributeVector<Vec3s> pointList(positions);
36
37 const float voxelSize = 0.1f;
38 openvdb::math::Transform::Ptr transform(
39
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(voxelSize));
40
41 tools::PointIndexGrid::Ptr pointIndexGrid =
42
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::createPointIndexGrid<tools::PointIndexGrid>(pointList, *transform);
43
44 PointDataGrid::Ptr points =
45 createPointDataGrid<NullCodec, PointDataGrid>(*pointIndexGrid,
46
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pointList, *transform);
47
48 { // simple topology copy
49
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto mask = convertPointsToMask(*points);
50
51
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(points->tree().activeVoxelCount(), Index64(4));
52
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(mask->tree().activeVoxelCount(), Index64(4));
53
54 // also test tree function signature
55 auto maskTree = convertPointsToMask(points->tree());
56
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(maskTree->activeVoxelCount(), Index64(4));
57
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(maskTree->hasSameTopology(mask->tree()));
58 }
59
60 { // mask grid instead of bool grid
61
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto mask = convertPointsToMask<PointDataGrid, MaskGrid>(*points);
62
63
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(points->tree().activeVoxelCount(), Index64(4));
64
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(mask->tree().activeVoxelCount(), Index64(4));
65 }
66
67 { // identical transform
68 1 auto mask = convertPointsToMask(*points, *transform);
69
70
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(points->tree().activeVoxelCount(), Index64(4));
71
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(mask->tree().activeVoxelCount(), Index64(4));
72 }
73
74 // assign point 3 to new group "test"
75
76
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendGroup(points->tree(), "test");
77
78
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 std::vector<short> groups{0,0,1,0};
79
80
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 setGroup(points->tree(), pointIndexGrid->tree(), groups, "test");
81
82
3/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
3 std::vector<std::string> includeGroups{"test"};
83 1 std::vector<std::string> excludeGroups;
84
85 { // convert in turn "test" and not "test"
86 MultiGroupFilter filter(includeGroups, excludeGroups,
87
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 points->tree().cbeginLeaf()->attributeSet());
88
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto mask = convertPointsToMask(*points, filter);
89
90
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(points->tree().activeVoxelCount(), Index64(4));
91
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(mask->tree().activeVoxelCount(), Index64(1));
92
93 MultiGroupFilter filter2(excludeGroups, includeGroups,
94
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
2 points->tree().cbeginLeaf()->attributeSet());
95
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mask = convertPointsToMask(*points, filter2);
96
97
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(mask->tree().activeVoxelCount(), Index64(3));
98 }
99
100 { // use a much larger voxel size that splits the points into two regions
101 const float newVoxelSize(4);
102 openvdb::math::Transform::Ptr newTransform(
103
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(newVoxelSize));
104
105 auto mask = convertPointsToMask(*points, *newTransform);
106
107
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(mask->tree().activeVoxelCount(), Index64(2));
108
109 MultiGroupFilter filter(includeGroups, excludeGroups,
110
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 points->tree().cbeginLeaf()->attributeSet());
111 1 mask = convertPointsToMask(*points, *newTransform, filter);
112
113
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(mask->tree().activeVoxelCount(), Index64(1));
114
115 MultiGroupFilter filter2(excludeGroups, includeGroups,
116
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 points->tree().cbeginLeaf()->attributeSet());
117 1 mask = convertPointsToMask(*points, *newTransform, filter2);
118
119
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(mask->tree().activeVoxelCount(), Index64(2));
120 }
121 1 }
122
123
124 struct StaticVoxelDeformer
125 {
126 StaticVoxelDeformer(const Vec3d& position)
127 1 : mPosition(position) { }
128
129 template <typename LeafT>
130 void reset(LeafT& /*leaf*/, size_t /*idx*/) { }
131
132 template <typename IterT>
133
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 void apply(Vec3d& position, IterT&) const { position = mPosition; }
134
135 private:
136 Vec3d mPosition;
137 };
138
139 template <bool WorldSpace = true>
140 struct YOffsetDeformer
141 {
142
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 YOffsetDeformer(const Vec3d& offset) : mOffset(offset) { }
143
144 template <typename LeafT>
145 void reset(LeafT& /*leaf*/, size_t /*idx*/) { }
146
147 template <typename IterT>
148 void apply(Vec3d& position, IterT&) const { position += mOffset; }
149
150 Vec3d mOffset;
151 };
152
153 namespace openvdb {
154 OPENVDB_USE_VERSION_NAMESPACE
155 namespace OPENVDB_VERSION_NAME {
156 namespace points {
157
158 // configure both voxel deformers to be applied in index-space
159
160 template<>
161 struct DeformerTraits<StaticVoxelDeformer> {
162 static const bool IndexSpace = true;
163 };
164
165 template<>
166 struct DeformerTraits<YOffsetDeformer<false>> {
167 static const bool IndexSpace = true;
168 };
169
170 } // namespace points
171 } // namespace OPENVDB_VERSION_NAME
172 } // namespace openvdb
173
174
175
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestPointMask, testMaskDeformer)
176 {
177 // This test validates internal functionality that is used in various applications, such as
178 // building masks and producing count grids. Note that by convention, methods that live
179 // in an "internal" namespace are typically not promoted as part of the public API
180 // and thus do not receive the same level of rigour in avoiding breaking API changes.
181
182 std::vector<Vec3s> positions = {
183 {1, 1, 1},
184 {1, 5, 1},
185 {2, 1, 1},
186 {2, 2, 1},
187
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 };
188
189 const PointAttributeVector<Vec3s> pointList(positions);
190
191 const float voxelSize = 0.1f;
192 openvdb::math::Transform::Ptr transform(
193
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(voxelSize));
194
195 tools::PointIndexGrid::Ptr pointIndexGrid =
196
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::createPointIndexGrid<tools::PointIndexGrid>(pointList, *transform);
197
198 PointDataGrid::Ptr points =
199 createPointDataGrid<NullCodec, PointDataGrid>(*pointIndexGrid,
200
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pointList, *transform);
201
202 // assign point 3 to new group "test"
203
204
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 appendGroup(points->tree(), "test");
205
206
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 std::vector<short> groups{0,0,1,0};
207
208
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(points->tree(), pointIndexGrid->tree(), groups, "test");
209
210 NullFilter nullFilter;
211
212 { // null deformer
213 NullDeformer deformer;
214
215 auto mask = point_mask_internal::convertPointsToScalar<MaskGrid>(
216
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *points, *transform, nullFilter, deformer);
217
218
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 auto mask2 = convertPointsToMask(*points);
219
220
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(points->tree().activeVoxelCount(), Index64(4));
221
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(mask->tree().activeVoxelCount(), Index64(4));
222
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(mask->tree().hasSameTopology(mask2->tree()));
223
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(mask->tree().hasSameTopology(points->tree()));
224 }
225
226 { // static voxel deformer
227 // collapse all points into a random voxel at (9, 13, 106)
228
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 StaticVoxelDeformer deformer(Vec3d(9, 13, 106));
229
230 auto mask = point_mask_internal::convertPointsToScalar<MaskGrid>(
231
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *points, *transform, nullFilter, deformer);
232
233
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(mask->tree().activeVoxelCount(), Index64(1));
234
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(!mask->tree().cbeginLeaf()->isValueOn(Coord(9, 13, 105)));
235
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(mask->tree().cbeginLeaf()->isValueOn(Coord(9, 13, 106)));
236 }
237
238 { // +y offset deformer
239 Vec3d offset(0, 41.7, 0);
240 YOffsetDeformer</*world-space*/false> deformer(offset);
241
242 auto mask = point_mask_internal::convertPointsToScalar<MaskGrid>(
243
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *points, *transform, nullFilter, deformer);
244
245 // (repeat with deformer configured as world-space)
246
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 YOffsetDeformer</*world-space*/true> deformerWS(offset * voxelSize);
247
248 auto maskWS = point_mask_internal::convertPointsToScalar<MaskGrid>(
249
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *points, *transform, nullFilter, deformerWS);
250
251
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(mask->tree().activeVoxelCount(), Index64(4));
252
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(maskWS->tree().activeVoxelCount(), Index64(4));
253
254 std::vector<Coord> maskVoxels;
255 std::vector<Coord> maskVoxelsWS;
256 std::vector<Coord> pointVoxels;
257
258
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (auto leaf = mask->tree().cbeginLeaf(); leaf; ++leaf) {
259
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
260
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 maskVoxels.emplace_back(iter.getCoord());
261 }
262 }
263
264
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (auto leaf = maskWS->tree().cbeginLeaf(); leaf; ++leaf) {
265
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
266
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 maskVoxelsWS.emplace_back(iter.getCoord());
267 }
268 }
269
270
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (auto leaf = points->tree().cbeginLeaf(); leaf; ++leaf) {
271
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
272
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 pointVoxels.emplace_back(iter.getCoord());
273 }
274 }
275
276 1 std::sort(maskVoxels.begin(), maskVoxels.end());
277 1 std::sort(maskVoxelsWS.begin(), maskVoxelsWS.end());
278 1 std::sort(pointVoxels.begin(), pointVoxels.end());
279
280
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(maskVoxels.size(), size_t(4));
281
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(maskVoxelsWS.size(), size_t(4));
282
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(pointVoxels.size(), size_t(4));
283
284
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = 0; i < int(pointVoxels.size()); i++) {
285
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 Coord newCoord(pointVoxels[i]);
286 4 newCoord.x() = static_cast<Int32>(newCoord.x() + offset.x());
287
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 newCoord.y() = static_cast<Int32>(math::Round(newCoord.y() + offset.y()));
288
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 newCoord.z() = static_cast<Int32>(newCoord.z() + offset.z());
289
1/14
✗ Branch 0 not taken.
✓ Branch 1 taken 4 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.
4 EXPECT_EQ(maskVoxels[i], newCoord);
290
1/14
✗ Branch 0 not taken.
✓ Branch 1 taken 4 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.
4 EXPECT_EQ(maskVoxelsWS[i], newCoord);
291 }
292
293 // use a different transform to verify deformers and transforms can be used together
294
295 const float newVoxelSize = 0.02f;
296 openvdb::math::Transform::Ptr newTransform(
297
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::math::Transform::createLinearTransform(newVoxelSize));
298
299 auto mask2 = point_mask_internal::convertPointsToScalar<MaskGrid>(
300
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *points, *newTransform, nullFilter, deformer);
301
302
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(mask2->tree().activeVoxelCount(), Index64(4));
303
304 std::vector<Coord> maskVoxels2;
305
306
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (auto leaf = mask2->tree().cbeginLeaf(); leaf; ++leaf) {
307
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
308
2/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
4 maskVoxels2.emplace_back(iter.getCoord());
309 }
310 }
311
312 1 std::sort(maskVoxels2.begin(), maskVoxels2.end());
313
314
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (int i = 0; i < int(maskVoxels.size()); i++) {
315
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 Coord newCoord(pointVoxels[i]);
316 4 newCoord.x() = static_cast<Int32>((newCoord.x() + offset.x()) * 5);
317
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 newCoord.y() = static_cast<Int32>(math::Round((newCoord.y() + offset.y()) * 5));
318
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 newCoord.z() = static_cast<Int32>((newCoord.z() + offset.z()) * 5);
319
1/14
✗ Branch 0 not taken.
✓ Branch 1 taken 4 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.
4 EXPECT_EQ(maskVoxels2[i], newCoord);
320 }
321
322 // only use points in group "test"
323
324
3/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
3 std::vector<std::string> includeGroups{"test"};
325 1 std::vector<std::string> excludeGroups;
326 MultiGroupFilter filter(includeGroups, excludeGroups,
327
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 points->tree().cbeginLeaf()->attributeSet());
328
329 auto mask3 = point_mask_internal::convertPointsToScalar<MaskGrid>(
330
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *points, *transform, filter, deformer);
331
332
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(mask3->tree().activeVoxelCount(), Index64(1));
333
334
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (auto leaf = mask3->tree().cbeginLeaf(); leaf; ++leaf) {
335
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
336 1 Coord newCoord(pointVoxels[2]);
337 1 newCoord.x() = static_cast<Int32>(newCoord.x() + offset.x());
338
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 newCoord.y() = static_cast<Int32>(math::Round(newCoord.y() + offset.y()));
339 1 newCoord.z() = static_cast<Int32>(newCoord.z() + offset.z());
340
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
2 EXPECT_EQ(iter.getCoord(), newCoord);
341 }
342 }
343 }
344 1 }
345