GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestFastSweeping.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 189 189 100.0%
Functions: 10 10 100.0%
Branches: 202 1304 15.5%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
4 /// @file TestFastSweeping.cc
5 ///
6 /// @author Ken Museth
7
8 //#define BENCHMARK_FAST_SWEEPING
9 //#define TIMING_FAST_SWEEPING
10
11 #include <openvdb/Types.h>
12 #include <openvdb/openvdb.h>
13 #include <openvdb/tools/ChangeBackground.h>
14 #include <openvdb/tools/Diagnostics.h>
15 #include <openvdb/tools/FastSweeping.h>
16 #include <openvdb/tools/LevelSetSphere.h>
17 #include <openvdb/tools/LevelSetTracker.h>
18 #include <openvdb/tools/LevelSetRebuild.h>
19 #include <openvdb/tools/LevelSetPlatonic.h>
20 #include <openvdb/tools/LevelSetUtil.h>
21 #ifdef TIMING_FAST_SWEEPING
22 #include <openvdb/util/CpuTimer.h>
23 #endif
24
25 #include <gtest/gtest.h>
26
27 #include <sstream>
28
29 // Uncomment to test on models from our web-site
30 //#define TestFastSweeping_DATA_PATH "/Users/ken/dev/data/vdb/"
31 //#define TestFastSweeping_DATA_PATH "/home/kmu/dev/data/vdb/"
32 //#define TestFastSweeping_DATA_PATH "/usr/pic1/Data/OpenVDB/LevelSetModels/"
33
34 7 class TestFastSweeping: public ::testing::Test
35 {
36 public:
37 7 void SetUp() override { openvdb::initialize(); }
38 7 void TearDown() override { openvdb::uninitialize(); }
39
40 void writeFile(const std::string &name, openvdb::FloatGrid::Ptr grid)
41 {
42 openvdb::io::File file(name);
43 file.setCompression(openvdb::io::COMPRESS_NONE);
44 openvdb::GridPtrVec grids;
45 grids.push_back(grid);
46 file.write(grids);
47 }
48 };// TestFastSweeping
49
50
51
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestFastSweeping, dilateSignedDistance)
52 {
53 using namespace openvdb;
54 // Define parameters for the level set sphere to be re-normalized
55 const float radius = 60.0f;
56 const Vec3f center(0.0f, 0.0f, 0.0f);
57 const float voxelSize = 1.0f;//half width
58 const int width = 3, new_width = 12;
59
60 1 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, float(width));
61
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t oldVoxelCount = grid->activeVoxelCount();
62
63 2 tools::FastSweeping<FloatGrid> fs;
64
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(0), fs.sweepingVoxelCount());
65
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(0), fs.boundaryVoxelCount());
66
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fs.initDilate(*grid, new_width - width);
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(fs.sweepingVoxelCount() > 0);
68
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(fs.boundaryVoxelCount() > 0);
69
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fs.sweep();
70
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(fs.sweepingVoxelCount() > 0);
71
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(fs.boundaryVoxelCount() > 0);
72 auto grid2 = fs.sdfGrid();
73
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fs.clear();
74
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(0), fs.sweepingVoxelCount());
75
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(0), fs.boundaryVoxelCount());
76
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const Index64 sweepingVoxelCount = grid2->activeVoxelCount();
77
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(sweepingVoxelCount > oldVoxelCount);
78
79 {// Check that the norm of the gradient for all active voxels is close to unity
80
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::Diagnose<FloatGrid> diagnose(*grid2);
81
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 tools::CheckNormGrad<FloatGrid> test(*grid2, 0.99f, 1.01f);
82 const std::string message = diagnose.check(test,
83 false,// don't generate a mask grid
84 true,// check active voxels
85 false,// ignore active tiles since a level set has none
86
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 false);// no need to check the background value
87
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(message.empty());
88
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(Index64(0), diagnose.failureCount());
89 //std::cout << "\nOutput 1: " << message << std::endl;
90 }
91 {// Make sure all active voxels fail the following test
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::Diagnose<FloatGrid> diagnose(*grid2);
93
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 tools::CheckNormGrad<FloatGrid> test(*grid2, std::numeric_limits<float>::min(), 0.99f);
94 const std::string message = diagnose.check(test,
95 false,// don't generate a mask grid
96 true,// check active voxels
97 false,// ignore active tiles since a level set has none
98
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 false);// no need to check the background value
99
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(!message.empty());
100
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(sweepingVoxelCount, diagnose.failureCount());
101 //std::cout << "\nOutput 2: " << message << std::endl;
102 }
103 {// Make sure all active voxels fail the following test
104
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::Diagnose<FloatGrid> diagnose(*grid2);
105
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 tools::CheckNormGrad<FloatGrid> test(*grid2, 1.01f, std::numeric_limits<float>::max());
106 const std::string message = diagnose.check(test,
107 false,// don't generate a mask grid
108 true,// check active voxels
109 false,// ignore active tiles since a level set has none
110
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 false);// no need to check the background value
111
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(!message.empty());
112
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(sweepingVoxelCount, diagnose.failureCount());
113 //std::cout << "\nOutput 3: " << message << std::endl;
114 }
115 1 }// dilateSignedDistance
116
117
118
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestFastSweeping, testMaskSdf)
119 {
120 using namespace openvdb;
121 // Define parameters for the level set sphere to be re-normalized
122 const float radius = 60.0f;
123 const Vec3f center(0.0f, 0.0f, 0.0f);
124 const float voxelSize = 1.0f, width = 3.0f;//half width
125 const float new_width = 12;
126
127 {// Use box as a mask
128 //std::cerr << "\nUse box as a mask" << std::endl;
129 1 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
130 1 CoordBBox bbox(Coord(60,-25,-25), Coord(100,25,25));
131
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 MaskGrid mask;
132
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 mask.sparseFill(bbox, true);
133
134 //this->writeFile("/tmp/box_mask_input.vdb", grid);
135 #ifdef TIMING_FAST_SWEEPING
136 util::CpuTimer timer("\nParallel sparse fast sweeping with a box mask");
137 #endif
138
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 grid = tools::maskSdf(*grid, mask);
139 //tools::FastSweeping<FloatGrid> fs;
140 //fs.initMask(*grid, mask);
141 //fs.sweep();
142 //std::cerr << "voxel count = " << fs.sweepingVoxelCount() << std::endl;
143 //std::cerr << "boundary count = " << fs.boundaryVoxelCount() << std::endl;
144 //EXPECT_TRUE(fs.sweepingVoxelCount() > 0);
145 #ifdef TIMING_FAST_SWEEPING
146 timer.stop();
147 #endif
148 //writeFile("/tmp/box_mask_output.vdb", grid);
149 {// Check that the norm of the gradient for all active voxels is close to unity
150
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::Diagnose<FloatGrid> diagnose(*grid);
151
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 tools::CheckNormGrad<FloatGrid> test(*grid, 0.99f, 1.01f);
152 const std::string message = diagnose.check(test,
153 false,// don't generate a mask grid
154 true,// check active voxels
155 false,// ignore active tiles since a level set has none
156
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 false);// no need to check the background value
157 //std::cerr << message << std::endl;
158
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const double percent = 100.0*double(diagnose.failureCount())/double(grid->activeVoxelCount());
159 //std::cerr << "Failures = " << percent << "%" << std::endl;
160 //std::cerr << "Failed: " << diagnose.failureCount() << std::endl;
161 //std::cerr << "Total : " << grid->activeVoxelCount() << std::endl;
162
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(percent < 0.01);
163 //EXPECT_TRUE(message.empty());
164 //EXPECT_EQ(size_t(0), diagnose.failureCount());
165 }
166 }
167
168 {// Use sphere as a mask
169 //std::cerr << "\nUse sphere as a mask" << std::endl;
170 1 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
171
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr mask = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, new_width);
172
173 //this->writeFile("/tmp/sphere_mask_input.vdb", grid);
174 #ifdef TIMING_FAST_SWEEPING
175 util::CpuTimer timer("\nParallel sparse fast sweeping with a sphere mask");
176 #endif
177
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 grid = tools::maskSdf(*grid, *mask);
178 //tools::FastSweeping<FloatGrid> fs;
179 //fs.initMask(*grid, *mask);
180 //fs.sweep();
181 #ifdef TIMING_FAST_SWEEPING
182 timer.stop();
183 #endif
184 //std::cerr << "voxel count = " << fs.sweepingVoxelCount() << std::endl;
185 //std::cerr << "boundary count = " << fs.boundaryVoxelCount() << std::endl;
186 //EXPECT_TRUE(fs.sweepingVoxelCount() > 0);
187 //this->writeFile("/tmp/sphere_mask_output.vdb", grid);
188 {// Check that the norm of the gradient for all active voxels is close to unity
189
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::Diagnose<FloatGrid> diagnose(*grid);
190
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 tools::CheckNormGrad<FloatGrid> test(*grid, 0.99f, 1.01f);
191 const std::string message = diagnose.check(test,
192 false,// don't generate a mask grid
193 true,// check active voxels
194 false,// ignore active tiles since a level set has none
195
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 false);// no need to check the background value
196 //std::cerr << message << std::endl;
197
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const double percent = 100.0*double(diagnose.failureCount())/double(grid->activeVoxelCount());
198 //std::cerr << "Failures = " << percent << "%" << std::endl;
199 //std::cerr << "Failed: " << diagnose.failureCount() << std::endl;
200 //std::cerr << "Total : " << grid->activeVoxelCount() << std::endl;
201 //EXPECT_TRUE(message.empty());
202 //EXPECT_EQ(size_t(0), diagnose.failureCount());
203
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(percent < 0.01);
204 //std::cout << "\nOutput 1: " << message << std::endl;
205 }
206 }
207
208 {// Use dodecahedron as a mask
209 //std::cerr << "\nUse dodecahedron as a mask" << std::endl;
210 1 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
211
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 FloatGrid::Ptr mask = tools::createLevelSetDodecahedron<FloatGrid>(50, Vec3f(radius, 0.0f, 0.0f),
212
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 voxelSize, 10);
213
214 //this->writeFile("/tmp/dodecahedron_mask_input.vdb", grid);
215 #ifdef TIMING_FAST_SWEEPING
216 util::CpuTimer timer("\nParallel sparse fast sweeping with a dodecahedron mask");
217 #endif
218
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 grid = tools::maskSdf(*grid, *mask);
219 //tools::FastSweeping<FloatGrid> fs;
220 //fs.initMask(*grid, *mask);
221 //std::cerr << "voxel count = " << fs.sweepingVoxelCount() << std::endl;
222 //std::cerr << "boundary count = " << fs.boundaryVoxelCount() << std::endl;
223 //EXPECT_TRUE(fs.sweepingVoxelCount() > 0);
224 //fs.sweep();
225 #ifdef TIMING_FAST_SWEEPING
226 timer.stop();
227 #endif
228 //this->writeFile("/tmp/dodecahedron_mask_output.vdb", grid);
229 {// Check that the norm of the gradient for all active voxels is close to unity
230
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::Diagnose<FloatGrid> diagnose(*grid);
231
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 tools::CheckNormGrad<FloatGrid> test(*grid, 0.99f, 1.01f);
232 const std::string message = diagnose.check(test,
233 false,// don't generate a mask grid
234 true,// check active voxels
235 false,// ignore active tiles since a level set has none
236
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 false);// no need to check the background value
237 //std::cerr << message << std::endl;
238
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const double percent = 100.0*double(diagnose.failureCount())/double(grid->activeVoxelCount());
239 //std::cerr << "Failures = " << percent << "%" << std::endl;
240 //std::cerr << "Failed: " << diagnose.failureCount() << std::endl;
241 //std::cerr << "Total : " << grid->activeVoxelCount() << std::endl;
242 //EXPECT_TRUE(message.empty());
243 //EXPECT_EQ(size_t(0), diagnose.failureCount());
244
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(percent < 0.01);
245 //std::cout << "\nOutput 1: " << message << std::endl;
246 }
247 }
248 #ifdef TestFastSweeping_DATA_PATH
249 {// Use bunny as a mask
250 //std::cerr << "\nUse bunny as a mask" << std::endl;
251 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(10.0f, Vec3f(-10,0,0), 0.05f, width);
252 openvdb::initialize();//required whenever I/O of OpenVDB files is performed!
253 const std::string path(TestFastSweeping_DATA_PATH);
254 io::File file( path + "bunny.vdb" );
255 file.open(false);//disable delayed loading
256 FloatGrid::Ptr mask = openvdb::gridPtrCast<openvdb::FloatGrid>(file.getGrids()->at(0));
257
258 //this->writeFile("/tmp/bunny_mask_input.vdb", grid);
259 tools::FastSweeping<FloatGrid> fs;
260 #ifdef TIMING_FAST_SWEEPING
261 util::CpuTimer timer("\nParallel sparse fast sweeping with a bunny mask");
262 #endif
263 fs.initMask(*grid, *mask);
264 //std::cerr << "voxel count = " << fs.sweepingVoxelCount() << std::endl;
265 //std::cerr << "boundary count = " << fs.boundaryVoxelCount() << std::endl;
266 fs.sweep();
267 auto grid2 = fs.sdfGrid();
268 #ifdef TIMING_FAST_SWEEPING
269 timer.stop();
270 #endif
271 //this->writeFile("/tmp/bunny_mask_output.vdb", grid2);
272 {// Check that the norm of the gradient for all active voxels is close to unity
273 tools::Diagnose<FloatGrid> diagnose(*grid2);
274 tools::CheckNormGrad<FloatGrid> test(*grid2, 0.99f, 1.01f);
275 const std::string message = diagnose.check(test,
276 false,// don't generate a mask grid
277 true,// check active voxels
278 false,// ignore active tiles since a level set has none
279 false);// no need to check the background value
280 //std::cerr << message << std::endl;
281 const double percent = 100.0*double(diagnose.failureCount())/double(grid2->activeVoxelCount());
282 //std::cerr << "Failures = " << percent << "%" << std::endl;
283 //std::cerr << "Failed: " << diagnose.failureCount() << std::endl;
284 //std::cerr << "Total : " << grid2->activeVoxelCount() << std::endl;
285 //EXPECT_TRUE(message.empty());
286 //EXPECT_EQ(size_t(0), diagnose.failureCount());
287 EXPECT_TRUE(percent < 4.5);// crossing characteristics!
288 //std::cout << "\nOutput 1: " << message << std::endl;
289 }
290 }
291 #endif
292 1 }// testMaskSdf
293
294
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestFastSweeping, testSdfToFogVolume)
295 {
296 using namespace openvdb;
297 // Define parameterS FOR the level set sphere to be re-normalized
298 const float radius = 50.0f;
299 const Vec3f center(0.0f, 0.0f, 0.0f);
300 const float voxelSize = 1.0f, width = 3.0f;//half width
301
302 1 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, float(width));
303
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::sdfToFogVolume(*grid);
304
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const Index64 sweepingVoxelCount = grid->activeVoxelCount();
305
306 //this->writeFile("/tmp/fog_input.vdb", grid);
307 2 tools::FastSweeping<FloatGrid> fs;
308 #ifdef TIMING_FAST_SWEEPING
309 util::CpuTimer timer("\nParallel sparse fast sweeping with a fog volume");
310 #endif
311
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fs.initSdf(*grid, /*isoValue*/0.5f,/*isInputSdf*/false);
312
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(fs.sweepingVoxelCount() > 0);
313 //std::cerr << "voxel count = " << fs.sweepingVoxelCount() << std::endl;
314 //std::cerr << "boundary count = " << fs.boundaryVoxelCount() << std::endl;
315
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 fs.sweep();
316 auto grid2 = fs.sdfGrid();
317 #ifdef TIMING_FAST_SWEEPING
318 timer.stop();
319 #endif
320
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(sweepingVoxelCount, grid->activeVoxelCount());
321 //this->writeFile("/tmp/ls_output.vdb", grid2);
322
323 {// Check that the norm of the gradient for all active voxels is close to unity
324
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::Diagnose<FloatGrid> diagnose(*grid2);
325
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 tools::CheckNormGrad<FloatGrid> test(*grid2, 0.99f, 1.01f);
326 const std::string message = diagnose.check(test,
327 false,// don't generate a mask grid
328 true,// check active voxels
329 false,// ignore active tiles since a level set has none
330
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 false);// no need to check the background value
331 //std::cerr << message << std::endl;
332
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const double percent = 100.0*double(diagnose.failureCount())/double(grid2->activeVoxelCount());
333 //std::cerr << "Failures = " << percent << "%" << std::endl;
334 //std::cerr << "Failure count = " << diagnose.failureCount() << std::endl;
335 //std::cerr << "Total active voxel count = " << grid2->activeVoxelCount() << std::endl;
336
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(percent < 10.0);
337 }
338 1 }// testSdfToFogVolume
339
340
341 #ifdef BENCHMARK_FAST_SWEEPING
342 TEST_F(TestFastSweeping, testBenchmarks)
343 {
344 using namespace openvdb;
345 // Define parameterS FOR the level set sphere to be re-normalized
346 const float radius = 200.0f;
347 const Vec3f center(0.0f, 0.0f, 0.0f);
348 const float voxelSize = 1.0f, width = 3.0f;//half width
349 const float new_width = 50;
350
351 {// Use rebuildLevelSet (limited to closed and symmetric narrow-band level sets)
352 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
353 #ifdef TIMING_FAST_SWEEPING
354 util::CpuTimer timer("\nRebuild level set");
355 #endif
356 FloatGrid::Ptr ls = tools::levelSetRebuild(*grid, 0.0f, new_width);
357 #ifdef TIMING_FAST_SWEEPING
358 timer.stop();
359 #endif
360 std::cout << "Diagnostics:\n" << tools::checkLevelSet(*ls, 9) << std::endl;
361 //this->writeFile("/tmp/rebuild_sdf.vdb", ls);
362 }
363 {// Use LevelSetTracker::normalize()
364 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
365 tools::dilateActiveValues(grid->tree(), int(new_width-width), tools::NN_FACE, tools::IGNORE_TILES);
366 tools::changeLevelSetBackground(grid->tree(), new_width);
367 std::cout << "Diagnostics:\n" << tools::checkLevelSet(*grid, 9) << std::endl;
368 //std::cerr << "Number of active tiles = " << grid->tree().activeTileCount() << std::endl;
369 //grid->print(std::cout, 3);
370 tools::LevelSetTracker<FloatGrid> track(*grid);
371 track.setNormCount(int(new_width/0.3f));//CFL is 1/3 for RK1
372 track.setSpatialScheme(math::FIRST_BIAS);
373 track.setTemporalScheme(math::TVD_RK1);
374 #ifdef TIMING_FAST_SWEEPING
375 util::CpuTimer timer("\nConventional re-normalization");
376 #endif
377 track.normalize();
378 #ifdef TIMING_FAST_SWEEPING
379 timer.stop();
380 #endif
381 std::cout << "Diagnostics:\n" << tools::checkLevelSet(*grid, 9) << std::endl;
382 //this->writeFile("/tmp/old_sdf.vdb", grid);
383 }
384 {// Use new sparse and parallel fast sweeping
385 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
386
387 //this->writeFile("/tmp/original_sdf.vdb", grid);
388 #ifdef TIMING_FAST_SWEEPING
389 util::CpuTimer timer("\nParallel sparse fast sweeping");
390 #endif
391 auto grid2 = tools::dilateSdf(*grid, int(new_width - width), tools::NN_FACE_EDGE);
392 //tools::FastSweeping<FloatGrid> fs(*grid);
393 //EXPECT_TRUE(fs.sweepingVoxelCount() > 0);
394 //tbb::task_scheduler_init init(4);//thread count
395 //fs.sweep();
396 #ifdef TIMING_FAST_SWEEPING
397 timer.stop();
398 #endif
399 //std::cout << "Diagnostics:\n" << tools::checkLevelSet(*grid, 9) << std::endl;
400 //this->writeFile("/tmp/new_sdf.vdb", grid2);
401 }
402 }
403 #endif
404
405
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestFastSweeping, testIntersection)
406 {
407 using namespace openvdb;
408 const Coord ijk(1,4,-9);
409
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(0.0f);
410 auto acc = grid.getAccessor();
411
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::GradStencil<FloatGrid> stencil(grid);
412
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 acc.setValue(ijk,-1.0f);
413 1 int cases = 0;
414
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int mx=0; mx<2; ++mx) {
415
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
3 acc.setValue(ijk.offsetBy(-1,0,0), mx ? 1.0f : -1.0f);
416
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int px=0; px<2; ++px) {
417
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
6 acc.setValue(ijk.offsetBy(1,0,0), px ? 1.0f : -1.0f);
418
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 for (int my=0; my<2; ++my) {
419
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
12 acc.setValue(ijk.offsetBy(0,-1,0), my ? 1.0f : -1.0f);
420
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 for (int py=0; py<2; ++py) {
421
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
24 acc.setValue(ijk.offsetBy(0,1,0), py ? 1.0f : -1.0f);
422
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 16 times.
48 for (int mz=0; mz<2; ++mz) {
423
3/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
✓ Branch 3 taken 32 times.
✗ Branch 4 not taken.
48 acc.setValue(ijk.offsetBy(0,0,-1), mz ? 1.0f : -1.0f);
424
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 for (int pz=0; pz<2; ++pz) {
425
3/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
✓ Branch 3 taken 64 times.
✗ Branch 4 not taken.
96 acc.setValue(ijk.offsetBy(0,0,1), pz ? 1.0f : -1.0f);
426
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 ++cases;
427
2/16
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 64 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.
64 EXPECT_EQ(Index64(7), grid.activeVoxelCount());
428
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 stencil.moveTo(ijk);
429 64 const size_t count = mx + px + my + py + mz + pz;// number of intersections
430
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(stencil.intersects() == (count > 0));
431
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
64 auto mask = stencil.intersectionMask();
432
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.none() == (count == 0));
433
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.any() == (count > 0));
434
2/16
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 64 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.
64 EXPECT_EQ(count, mask.count());
435
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.test(0) == mx);
436
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.test(1) == px);
437
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.test(2) == my);
438
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.test(3) == py);
439
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.test(4) == mz);
440
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 64 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.
64 EXPECT_TRUE(mask.test(5) == pz);
441 }//pz
442 }//mz
443 }//py
444 }//my
445 }//px
446 }//mx
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(64, cases);// = 2^6
448 1 }//testIntersection
449
450
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestFastSweeping, fogToSdfAndExt)
451 {
452 using namespace openvdb;
453 const float isoValue = 0.5f;
454 const float radius = 50.0f;
455 1 const float background = 0.0f;
456 const float tolerance = 0.00001f;
457 const Vec3f center(0.0f, 0.0f, 0.0f);
458 const float voxelSize = 1.0f, width = 3.0f;//half width
459 1 FloatGrid::Ptr grid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, float(width));
460
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::sdfToFogVolume(*grid);
461
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);
462
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const float fog[] = {grid->tree().getValue( Coord(52, 0, 0) ),
463
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 grid->tree().getValue( Coord(51, 0, 0) ),
464
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 grid->tree().getValue( Coord(50, 0, 0) ),
465
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 grid->tree().getValue( Coord(49, 0, 0) ),
466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 grid->tree().getValue( Coord(48, 0, 0) )};
467 //for (auto v : fog) std::cerr << v << std::endl;
468
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(fog[0], 0.0f, tolerance) );
469
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(fog[1], 0.0f, tolerance) );
470
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(fog[2], 0.0f, tolerance) );
471
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(fog[3], 1.0f/3.0f, tolerance) );
472
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(fog[4], 2.0f/3.0f, tolerance) );
473 //this->writeFile("/tmp/sphere1_fog_in.vdb", grid);
474
475
3/4
✓ Branch 0 taken 66424 times.
✓ Branch 1 taken 22292 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
88717 auto op = [radius](const Vec3R &xyz) {return math::Sin(2*3.14*(xyz[0]+xyz[1]+xyz[2])/radius);};
476
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.
3 auto grids = tools::fogToSdfAndExt(*grid, op, background, isoValue);
477
478
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto sdf1 = grids.first->tree().getValue( Coord(50, 0, 0) );
479
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto sdf2 = grids.first->tree().getValue( Coord(49, 0, 0) );
480 1 const auto sdf3 = grids.first->tree().getValue( Coord(48, 0, 0) );
481 //std::cerr << "\nsdf1 = " << sdf1 << ", sdf2 = " << sdf2 << ", sdf3 = " << sdf3 << std::endl;
482
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( sdf1 > sdf2 );
483
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( sdf2, 0.5f, tolerance) );
484
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( sdf3,-0.5f, tolerance) );
485
486
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto ext1 = grids.second->tree().getValue( Coord(50, 0, 0) );
487
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto ext2 = grids.second->tree().getValue( Coord(49, 0, 0) );
488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 const auto ext3 = grids.second->tree().getValue( Coord(48, 0, 0) );
489 //std::cerr << "\next1 = " << ext1 << ", ext2 = " << ext2 << ", ext3 = " << ext3 << std::endl;
490
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(ext1, background, tolerance) );
491
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(ext2, ext3, tolerance) );
492 //this->writeFile("/tmp/sphere1_sdf_out.vdb", grids.first);
493 //this->writeFile("/tmp/sphere1_ext_out.vdb", grids.second);
494 1 }// fogToSdfAndExt
495
496
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestFastSweeping, sdfToSdfAndExt)
497 {
498 using namespace openvdb;
499 const float isoValue = 0.0f;
500 const float radius = 100.0f;
501 1 const float background = 1.234f;
502 const float tolerance = 0.00001f;
503 const Vec3f center(0.0f, 0.0f, 0.0f);
504 const float voxelSize = 1.0f, width = 3.0f;//half width
505 1 FloatGrid::Ptr lsGrid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
506 //std::cerr << "\nls(100,0,0) = " << lsGrid->tree().getValue( Coord(100, 0, 0) ) << std::endl;
507
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(lsGrid->tree().getValue( Coord(100, 0, 0) ), 0.0f, tolerance) );
508
509
3/4
✓ Branch 0 taken 282894 times.
✓ Branch 1 taken 93480 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
376525 auto op = [radius](const Vec3R &xyz) {return math::Sin(2*3.14*xyz[0]/radius);};
510
2/6
✓ 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.
3 auto grids = tools::sdfToSdfAndExt(*lsGrid, op, background, isoValue);
511
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(grids.first);
512
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(grids.second);
513
514 //std::cerr << "\nsdf = " << grids.first->tree().getValue( Coord(100, 0, 0) ) << std::endl;
515
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(grids.first->tree().getValue( Coord(100, 0, 0) ), 0.0f, tolerance) );
516
517 //std::cerr << "\nBackground = " << grids.second->background() << std::endl;
518 //std::cerr << "\nBackground = " << grids.second->tree().getValue( Coord(10000) ) << std::endl;
519
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(grids.second->background(), background, tolerance) );
520
521
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto sdf1 = grids.first->tree().getValue( Coord(100, 0, 0) );
522
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto sdf2 = grids.first->tree().getValue( Coord(102, 0, 0) );
523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 const auto sdf3 = grids.first->tree().getValue( Coord(102, 1, 1) );
524 //std::cerr << "\nsdf1 = " << sdf1 << ", sdf2 = " << sdf2 << ", sdf3 = " << sdf3 << std::endl;
525
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( sdf1, 0.0f, tolerance) );
526
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( sdf2, 2.0f, tolerance) );
527
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( sdf3 > 2.0f );
528
529
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto ext1 = grids.second->tree().getValue( Coord(100, 0, 0) );
530
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto ext2 = grids.second->tree().getValue( Coord(102, 0, 0) );
531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 const auto ext3 = grids.second->tree().getValue( Coord(102, 1, 0) );
532 //std::cerr << "\next1 = " << ext1 << ", ext2 = " << ext2 << ", ext3 = " << ext3 << std::endl;
533
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(float(op(Vec3R(100, 0, 0))), ext1, tolerance) );
534
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(ext1, ext2, tolerance) );
535
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(ext1, ext3, tolerance) );
536 //writeFile("/tmp/sphere2_sdf_out.vdb", grids.first);
537 //writeFile("/tmp/sphere2_ext_out.vdb", grids.second);
538 1 }// sdfToSdfAndExt
539
540
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestFastSweeping, sdfToSdfAndExt_velocity)
541 {
542 using namespace openvdb;
543 const float isoValue = 0.0f;
544 const float radius = 100.0f;
545 const Vec3f background(-1.0f, 2.0f, 1.234f);
546 const float tolerance = 0.00001f;
547 const Vec3f center(0.0f, 0.0f, 0.0f);
548 const float voxelSize = 1.0f, width = 3.0f;//half width
549 1 FloatGrid::Ptr lsGrid = tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, width);
550 //std::cerr << "\nls(100,0,0) = " << lsGrid->tree().getValue( Coord(100, 0, 0) ) << std::endl;
551
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(lsGrid->tree().getValue( Coord(100, 0, 0) ), 0.0f, tolerance) );
552 //tools::sdfToFogVolume(*grid);
553 //writeFile("/tmp/sphere1_fog_in.vdb", grid);
554 //tools::fogToSdf(*grid, isoValue);
555
556 // Vector valued extension field, e.g. a velocity field
557
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto op = [radius](const Vec3R &xyz) {
558 376525 return Vec3f(float(xyz[0]), float(-xyz[1]), float(math::Sin(2*3.14*xyz[2]/radius)));
559 };
560
2/6
✓ 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.
3 auto grids = tools::sdfToSdfAndExt(*lsGrid, op, background, isoValue);
561
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(grids.first);
562
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(grids.second);
563
564 //std::cerr << "\nBackground = " << grids.second->background() << std::endl;
565 //std::cerr << "\nBackground = " << grids.second->tree().getValue( Coord(10000) ) << std::endl;
566
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::isApproxZero((grids.second->background()-background).length(), tolerance) );
567 //std::cerr << "\nsdf = " << grids.first->tree().getValue( Coord(100, 0, 0) ) << std::endl;
568
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(grids.first->tree().getValue( Coord(100, 0, 0) ), 0.0f, tolerance) );
569
570
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto sdf1 = grids.first->tree().getValue( Coord(100, 0, 0) );
571
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto sdf2 = grids.first->tree().getValue( Coord(102, 0, 0) );
572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 const auto sdf3 = grids.first->tree().getValue( Coord(102, 1, 1) );
573 //std::cerr << "\nsdf1 = " << sdf1 << ", sdf2 = " << sdf2 << ", sdf3 = " << sdf3 << std::endl;
574
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( sdf1, 0.0f, tolerance) );
575
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( sdf2, 2.0f, tolerance) );
576
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( sdf3 > 2.0f );
577
578
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto ext1 = grids.second->tree().getValue( Coord(100, 0, 0) );
579
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto ext2 = grids.second->tree().getValue( Coord(102, 0, 0) );
580 1 const auto ext3 = grids.second->tree().getValue( Coord(102, 1, 0) );
581 //std::cerr << "\next1 = " << ext1 << ", ext2 = " << ext2 << ", ext3 = " << ext3 << std::endl;
582
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.
2 EXPECT_TRUE( math::isApproxZero((op(Vec3R(100, 0, 0)) - ext1).length(), tolerance) );
583
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::isApproxZero((ext1 - ext2).length(), tolerance) );
584
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::isApproxZero((ext1 - ext3).length(), tolerance) );
585
586 //writeFile("/tmp/sphere2_sdf_out.vdb", grids.first);
587 //writeFile("/tmp/sphere2_ext_out.vdb", grids.second);
588 1 }// sdfToSdfAndExt_velocity
589
590 #ifdef TestFastSweeping_DATA_PATH
591 TEST_F(TestFastSweeping, velocityExtensionOfFogBunny)
592 {
593 using namespace openvdb;
594
595 openvdb::initialize();//required whenever I/O of OpenVDB files is performed!
596 const std::string path(TestFastSweeping_DATA_PATH);
597 io::File file( path + "bunny.vdb" );
598 file.open(false);//disable delayed loading
599 auto grid = openvdb::gridPtrCast<openvdb::FloatGrid>(file.getGrids()->at(0));
600 tools::sdfToFogVolume(*grid);
601 writeFile("/tmp/bunny1_fog_in.vdb", grid);
602 auto bbox = grid->evalActiveVoxelBoundingBox();
603 const double xSize = bbox.dim()[0]*grid->voxelSize()[0];
604 std::cerr << "\ndim=" << bbox.dim() << ", voxelSize="<< grid->voxelSize()[0]
605 << ", xSize=" << xSize << std::endl;
606
607 auto op = [xSize](const Vec3R &xyz) {
608 return math::Sin(2*3.14*xyz[0]/xSize);
609 };
610 auto grids = tools::fogToSdfAndExt(*grid, op, 0.0f, 0.5f);
611 std::cerr << "before writing" << std::endl;
612 writeFile("/tmp/bunny1_sdf_out.vdb", grids.first);
613 writeFile("/tmp/bunny1_ext_out.vdb", grids.second);
614 std::cerr << "after writing" << std::endl;
615 }//velocityExtensionOfFogBunnyevalActiveVoxelBoundingBox
616
617 TEST_F(TestFastSweeping, velocityExtensionOfSdfBunny)
618 {
619 using namespace openvdb;
620 const std::string path(TestFastSweeping_DATA_PATH);
621 io::File file( path + "bunny.vdb" );
622 file.open(false);//disable delayed loading
623 auto grid = openvdb::gridPtrCast<openvdb::FloatGrid>(file.getGrids()->at(0));
624 writeFile("/tmp/bunny2_sdf_in.vdb", grid);
625 auto bbox = grid->evalActiveVoxelBoundingBox();
626 const double xSize = bbox.dim()[0]*grid->voxelSize()[0];
627 std::cerr << "\ndim=" << bbox.dim() << ", voxelSize="<< grid->voxelSize()[0]
628 << ", xSize=" << xSize << std::endl;
629
630 auto op = [xSize](const Vec3R &xyz) {
631 return math::Sin(2*3.14*xyz[0]/xSize);
632 };
633 auto grids = tools::sdfToSdfAndExt(*grid, op, 0.0f);
634 std::cerr << "before writing" << std::endl;
635 writeFile("/tmp/bunny2_sdf_out.vdb", grids.first);
636 writeFile("/tmp/bunny2_ext_out.vdb", grids.second);
637 std::cerr << "after writing" << std::endl;
638
639 }//velocityExtensionOfFogBunnyevalActiveVoxelBoundingBox
640 #endif
641