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/math/Math.h> // for math::Random01 | ||
6 | #include <openvdb/tools/PointsToMask.h> | ||
7 | #include <openvdb/util/CpuTimer.h> | ||
8 | #include "gtest/gtest.h" | ||
9 | #include <vector> | ||
10 | #include <algorithm> | ||
11 | #include <cmath> | ||
12 | #include "util.h" // for genPoints | ||
13 | |||
14 | |||
15 | 1 | struct TestPointsToMask: public ::testing::Test | |
16 | { | ||
17 | }; | ||
18 | |||
19 | |||
20 | //////////////////////////////////////// | ||
21 | |||
22 | namespace { | ||
23 | |||
24 | class PointList | ||
25 | { | ||
26 | public: | ||
27 | 3 | PointList(const std::vector<openvdb::Vec3R>& points) : mPoints(&points) {} | |
28 | |||
29 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
6 | size_t size() const { return mPoints->size(); } |
30 | |||
31 |
3/8✓ Branch 1 taken 14992385 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 29984769 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 10 taken 14992384 times.
✗ Branch 11 not taken.
|
59969538 | void getPos(size_t n, openvdb::Vec3R& xyz) const { xyz = (*mPoints)[n]; } |
32 | protected: | ||
33 | std::vector<openvdb::Vec3R> const * const mPoints; | ||
34 | }; // PointList | ||
35 | |||
36 | } // namespace | ||
37 | |||
38 | |||
39 | |||
40 | //////////////////////////////////////// | ||
41 | |||
42 | |||
43 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | TEST_F(TestPointsToMask, testPointsToMask) |
44 | { | ||
45 | {// BoolGrid | ||
46 | // generate one point | ||
47 | std::vector<openvdb::Vec3R> points; | ||
48 | 1 | points.push_back( openvdb::Vec3R(-19.999, 4.50001, 6.71) ); | |
49 | //points.push_back( openvdb::Vec3R( 20,-4.5,-5.2) ); | ||
50 | PointList pointList(points); | ||
51 | |||
52 | // construct an empty mask grid | ||
53 |
1/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2 | openvdb::BoolGrid grid( false ); |
54 | const float voxelSize = 0.1f; | ||
55 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | grid.setTransform( openvdb::math::Transform::createLinearTransform(voxelSize) ); |
56 |
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( grid.empty() ); |
57 | |||
58 | // generate mask from points | ||
59 | openvdb::tools::PointsToMask<openvdb::BoolGrid> mask( grid ); | ||
60 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | mask.addPoints( pointList ); |
61 |
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(!grid.empty() ); |
62 |
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( 1, int(grid.activeVoxelCount()) ); |
63 | openvdb::BoolGrid::ValueOnCIter iter = grid.cbeginValueOn(); | ||
64 | //std::cerr << "Coord = " << iter.getCoord() << std::endl; | ||
65 | const openvdb::Coord p(-200, 45, 67); | ||
66 |
2/18✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
2 | EXPECT_TRUE( iter.getCoord() == p ); |
67 |
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(grid.tree().isValueOn( p ) ); |
68 | } | ||
69 | |||
70 | {// MaskGrid | ||
71 | // generate one point | ||
72 | std::vector<openvdb::Vec3R> points; | ||
73 | 1 | points.push_back( openvdb::Vec3R(-19.999, 4.50001, 6.71) ); | |
74 | //points.push_back( openvdb::Vec3R( 20,-4.5,-5.2) ); | ||
75 | PointList pointList(points); | ||
76 | |||
77 | // construct an empty mask grid | ||
78 |
1/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2 | openvdb::MaskGrid grid( false ); |
79 | const float voxelSize = 0.1f; | ||
80 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | grid.setTransform( openvdb::math::Transform::createLinearTransform(voxelSize) ); |
81 |
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( grid.empty() ); |
82 | |||
83 | // generate mask from points | ||
84 | openvdb::tools::PointsToMask<> mask( grid ); | ||
85 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | mask.addPoints( pointList ); |
86 |
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(!grid.empty() ); |
87 |
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( 1, int(grid.activeVoxelCount()) ); |
88 | openvdb::TopologyGrid::ValueOnCIter iter = grid.cbeginValueOn(); | ||
89 | //std::cerr << "Coord = " << iter.getCoord() << std::endl; | ||
90 | const openvdb::Coord p(-200, 45, 67); | ||
91 |
2/18✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
2 | EXPECT_TRUE( iter.getCoord() == p ); |
92 |
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(grid.tree().isValueOn( p ) ); |
93 | } | ||
94 | |||
95 | |||
96 | // generate shared transformation | ||
97 | 1 | openvdb::Index64 voxelCount = 0; | |
98 | const float voxelSize = 0.001f; | ||
99 | const openvdb::math::Transform::Ptr xform = | ||
100 | 1 | openvdb::math::Transform::createLinearTransform(voxelSize); | |
101 | |||
102 | // generate lots of points | ||
103 | std::vector<openvdb::Vec3R> points; | ||
104 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | unittest_util::genPoints(15000000, points); |
105 | PointList pointList(points); | ||
106 | |||
107 | //openvdb::util::CpuTimer timer; | ||
108 | {// serial BoolGrid | ||
109 | // construct an empty mask grid | ||
110 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::BoolGrid grid( false ); |
111 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | grid.setTransform( xform ); |
112 |
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( grid.empty() ); |
113 | |||
114 | // generate mask from points | ||
115 | openvdb::tools::PointsToMask<openvdb::BoolGrid> mask( grid ); | ||
116 | //timer.start("\nSerial BoolGrid"); | ||
117 | mask.addPoints( pointList, 0 ); | ||
118 | //timer.stop(); | ||
119 | |||
120 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(!grid.empty() ); |
121 | //grid.print(std::cerr, 3); | ||
122 | 1 | voxelCount = grid.activeVoxelCount(); | |
123 | } | ||
124 | {// parallel BoolGrid | ||
125 | // construct an empty mask grid | ||
126 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | openvdb::BoolGrid grid( false ); |
127 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | grid.setTransform( xform ); |
128 |
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( grid.empty() ); |
129 | |||
130 | // generate mask from points | ||
131 | openvdb::tools::PointsToMask<openvdb::BoolGrid> mask( grid ); | ||
132 | //timer.start("\nParallel BoolGrid"); | ||
133 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | mask.addPoints( pointList ); |
134 | //timer.stop(); | ||
135 | |||
136 |
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(!grid.empty() ); |
137 | //grid.print(std::cerr, 3); | ||
138 |
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( voxelCount, grid.activeVoxelCount() ); |
139 | } | ||
140 | {// parallel MaskGrid | ||
141 | // construct an empty mask grid | ||
142 |
1/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
2 | openvdb::MaskGrid grid( false ); |
143 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | grid.setTransform( xform ); |
144 |
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( grid.empty() ); |
145 | |||
146 | // generate mask from points | ||
147 | openvdb::tools::PointsToMask<> mask( grid ); | ||
148 | //timer.start("\nParallel MaskGrid"); | ||
149 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | mask.addPoints( pointList ); |
150 | //timer.stop(); | ||
151 | |||
152 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(!grid.empty() ); |
153 | //grid.print(std::cerr, 3); | ||
154 |
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( voxelCount, grid.activeVoxelCount() ); |
155 | } | ||
156 | {// parallel create TopologyGrid | ||
157 | //timer.start("\nParallel Create MaskGrid"); | ||
158 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::MaskGrid::Ptr grid = openvdb::tools::createPointMask(pointList, *xform); |
159 | //timer.stop(); | ||
160 | |||
161 |
2/18✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
1 | EXPECT_TRUE(!grid->empty() ); |
162 | //grid->print(std::cerr, 3); | ||
163 |
3/20✓ 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.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
1 | EXPECT_EQ( voxelCount, grid->activeVoxelCount() ); |
164 | } | ||
165 | 1 | } | |
166 |