GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestLaplacian.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 159 159 100.0%
Functions: 10 10 100.0%
Branches: 204 1290 15.8%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/Types.h>
5 #include <openvdb/openvdb.h>
6 #include <openvdb/tools/GridOperators.h>
7 #include "util.h" // for unittest_util::makeSphere()
8 #include "gtest/gtest.h"
9 #include <sstream>
10
11
12 8 class TestLaplacian: public ::testing::Test
13 {
14 public:
15 8 void SetUp() override { openvdb::initialize(); }
16 8 void TearDown() override { openvdb::uninitialize(); }
17 };
18
19
20
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLaplacian, testISLaplacian)
21 {
22 using namespace openvdb;
23
24 1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
25 FloatTree& tree = grid->tree();
26
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(tree.empty());
27
28 const Coord dim(64,64,64);
29 const Coord c(35,30,40);
30 const openvdb::Vec3f
31 center(static_cast<float>(c[0]), static_cast<float>(c[1]), static_cast<float>(c[2]));
32 const float radius=0.0f;//point at {35,30,40}
33
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
34
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(!tree.empty());
35
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(dim[0]*dim[1]*dim[2], int(tree.activeVoxelCount()));
36
37 Coord xyz(35,10,40);
38
39 // Index Space Laplacian random access
40 FloatGrid::ConstAccessor inAccessor = grid->getConstAccessor();
41 FloatGrid::ValueType result;
42
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISLaplacian<math::CD_SECOND>::result(inAccessor, xyz);
43
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20.0, result, /*tolerance=*/0.01);
44
45
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISLaplacian<math::CD_FOURTH>::result(inAccessor, xyz);
46
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20.0, result, /*tolerance=*/0.01);
47
48
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISLaplacian<math::CD_SIXTH>::result(inAccessor, xyz);
49
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20.0, result, /*tolerance=*/0.01);
50 1 }
51
52
53
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLaplacian, testISLaplacianStencil)
54 {
55 using namespace openvdb;
56
57 1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
58 FloatTree& tree = grid->tree();
59
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(tree.empty());
60
61 const Coord dim(64,64,64);
62 const Coord c(35,30,40);
63 const openvdb::Vec3f
64 center(static_cast<float>(c[0]), static_cast<float>(c[1]), static_cast<float>(c[2]));
65 const float radius=0;//point at {35,30,40}
66
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
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(!tree.empty());
68
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(dim[0]*dim[1]*dim[2], int(tree.activeVoxelCount()));
69
70 Coord xyz(35,10,40);
71
72 // Index Space Laplacian stencil access
73 FloatGrid::ValueType result;
74
75 math::SevenPointStencil<FloatGrid> sevenpt(*grid);
76
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 sevenpt.moveTo(xyz);
77 result = math::ISLaplacian<math::CD_SECOND>::result(sevenpt);
78
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20.0, result, /*tolerance=*/0.01);
79
80 math::ThirteenPointStencil<FloatGrid> thirteenpt(*grid);
81
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 thirteenpt.moveTo(xyz);
82 1 result = math::ISLaplacian<math::CD_FOURTH>::result(thirteenpt);
83
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20.0, result, /*tolerance=*/0.01);
84
85 math::NineteenPointStencil<FloatGrid> nineteenpt(*grid);
86
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 nineteenpt.moveTo(xyz);
87 1 result = math::ISLaplacian<math::CD_SIXTH>::result(nineteenpt);
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_NEAR(2.0/20.0, result, /*tolerance=*/0.01);
89 1 }
90
91
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLaplacian, testWSLaplacian)
93 {
94 using namespace openvdb;
95
96 1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
97 FloatTree& tree = grid->tree();
98
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(tree.empty());
99
100 const Coord dim(64,64,64);
101 const Coord c(35,30,40);
102 const openvdb::Vec3f
103 center(static_cast<float>(c[0]), static_cast<float>(c[1]), static_cast<float>(c[2]));
104 const float radius=0.0f;//point at {35,30,40}
105
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
106
107
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(!tree.empty());
108
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(dim[0]*dim[1]*dim[2], int(tree.activeVoxelCount()));
109
110 Coord xyz(35,10,40);
111
112 FloatGrid::ValueType result;
113 FloatGrid::ConstAccessor inAccessor = grid->getConstAccessor();
114
115 // try with a map
116 math::UniformScaleMap map;
117
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::MapBase::Ptr rotated_map = map.preRotate(1.5, math::X_AXIS);
118 // verify the new map is an affine map
119
2/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ 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 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(rotated_map->type() == math::AffineMap::mapType());
120 math::AffineMap::Ptr affine_map = StaticPtrCast<math::AffineMap, math::MapBase>(rotated_map);
121
122 // the laplacian is invariant to rotation
123
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::AffineMap, math::CD_SECOND>::result(
124 *affine_map, inAccessor, xyz);
125
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
126
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::AffineMap, math::CD_FOURTH>::result(
127 *affine_map, inAccessor, xyz);
128
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
129
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::AffineMap, math::CD_SIXTH>::result(
130 *affine_map, inAccessor, xyz);
131
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
132
133 // test uniform map
134 math::UniformScaleMap uniform;
135
136 result = math::Laplacian<math::UniformScaleMap, math::CD_SECOND>::result(
137 uniform, inAccessor, xyz);
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_NEAR(2.0/20., result, /*tolerance=*/0.01);
139 result = math::Laplacian<math::UniformScaleMap, math::CD_FOURTH>::result(
140 uniform, inAccessor, xyz);
141
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
142 result = math::Laplacian<math::UniformScaleMap, math::CD_SIXTH>::result(
143 uniform, inAccessor, xyz);
144
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
145
146 // test the GenericMap Grid interface
147 {
148 math::GenericMap generic_map(*grid);
149
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_SECOND>::result(
150 generic_map, inAccessor, xyz);
151
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
152
153
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_FOURTH>::result(
154 generic_map, inAccessor, xyz);
155
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
156 }
157 {
158 // test the GenericMap Transform interface
159 math::GenericMap generic_map(grid->transform());
160
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_SECOND>::result(
161 generic_map, inAccessor, xyz);
162
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
163
164 }
165 {
166 // test the GenericMap Map interface
167 1 math::GenericMap generic_map(rotated_map);
168
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_SECOND>::result(
169 generic_map, inAccessor, xyz);
170
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
171 }
172
173 1 }
174
175
176
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLaplacian, testWSLaplacianFrustum)
177 {
178 using namespace openvdb;
179
180 // Create a Frustum Map:
181
182 1 openvdb::BBoxd bbox(Vec3d(0), Vec3d(100));
183 math::NonlinearFrustumMap frustum(bbox, 1./6., 5);
184 /// frustum will have depth, far plane - near plane = 5
185 /// the frustum has width 1 in the front and 6 in the back
186
187 math::Vec3d trans(2,2,2);
188 math::NonlinearFrustumMap::Ptr map =
189 StaticPtrCast<math::NonlinearFrustumMap, math::MapBase>(
190
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
3 frustum.preScale(Vec3d(10,10,10))->postTranslate(trans));
191
192 EXPECT_TRUE(!map->hasUniformScale());
193
194 math::Vec3d result;
195 1 result = map->voxelSize();
196
197
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(result.x(), 0.1));
198
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(result.y(), 0.1));
199
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(result.z(), 0.5, 0.0001));
200
201
202 // Create a tree
203
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/0.0);
204 FloatTree& tree = grid->tree();
205
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(tree.empty());
206
207 // Load cos(x)sin(y)cos(z)
208 Coord ijk(10,10,10);
209
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for (Int32& i=ijk.x(); i < 20; ++i) {
210
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 for (Int32& j=ijk.y(); j < 20; ++j) {
211
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 for (Int32& k=ijk.z(); k < 20; ++k) {
212 // world space image of the ijk coord
213
1/2
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 const Vec3d ws = map->applyMap(ijk.asVec3d());
214
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const float value = float(cos(ws.x() ) * sin( ws.y()) * cos(ws.z()));
215 tree.setValue(ijk, value);
216 }
217 }
218 }
219
220 const Coord testloc(16,16,16);
221
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 float test_result = math::Laplacian<math::NonlinearFrustumMap, math::CD_SECOND>::result(
222 *map, tree, testloc);
223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 float expected_result = -3.f * tree.getValue(testloc);
224
225 // The exact solution of Laplacian( cos(x)sin(y)cos(z) ) = -3 cos(x) sin(y) cos(z)
226
227
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(test_result, expected_result, /*tolerance=*/0.02f) );
228 1 }
229
230
231
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLaplacian, testWSLaplacianStencil)
232 {
233 using namespace openvdb;
234
235 1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
236 FloatTree& tree = grid->tree();
237
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(tree.empty());
238
239 const Coord dim(64,64,64);
240 const Coord c(35,30,40);
241 const openvdb::Vec3f
242 center(static_cast<float>(c[0]), static_cast<float>(c[1]), static_cast<float>(c[2]));
243 const float radius=0.0f;//point at {35,30,40}
244
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
245
246
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(!tree.empty());
247
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(dim[0]*dim[1]*dim[2], int(tree.activeVoxelCount()));
248
249 Coord xyz(35,10,40);
250
251 FloatGrid::ValueType result;
252
253 // try with a map
254 math::UniformScaleMap map;
255
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::MapBase::Ptr rotated_map = map.preRotate(1.5, math::X_AXIS);
256 // verify the new map is an affine map
257
2/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ 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 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
1 EXPECT_TRUE(rotated_map->type() == math::AffineMap::mapType());
258 math::AffineMap::Ptr affine_map = StaticPtrCast<math::AffineMap, math::MapBase>(rotated_map);
259
260 // the laplacian is invariant to rotation
261 math::SevenPointStencil<FloatGrid> sevenpt(*grid);
262 math::ThirteenPointStencil<FloatGrid> thirteenpt(*grid);
263 math::NineteenPointStencil<FloatGrid> nineteenpt(*grid);
264 math::SecondOrderDenseStencil<FloatGrid> dense_2nd(*grid);
265 math::FourthOrderDenseStencil<FloatGrid> dense_4th(*grid);
266 math::SixthOrderDenseStencil<FloatGrid> dense_6th(*grid);
267
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 sevenpt.moveTo(xyz);
268
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 thirteenpt.moveTo(xyz);
269
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 nineteenpt.moveTo(xyz);
270
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dense_2nd.moveTo(xyz);
271
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dense_4th.moveTo(xyz);
272
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dense_6th.moveTo(xyz);
273
274 1 result = math::Laplacian<math::AffineMap, math::CD_SECOND>::result(*affine_map, dense_2nd);
275
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
276 1 result = math::Laplacian<math::AffineMap, math::CD_FOURTH>::result(*affine_map, dense_4th);
277
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
278 1 result = math::Laplacian<math::AffineMap, math::CD_SIXTH>::result(*affine_map, dense_6th);
279
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
280
281 // test uniform map
282 math::UniformScaleMap uniform;
283
284 result = math::Laplacian<math::UniformScaleMap, math::CD_SECOND>::result(uniform, sevenpt);
285
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
286 result = math::Laplacian<math::UniformScaleMap, math::CD_FOURTH>::result(uniform, thirteenpt);
287
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
288 result = math::Laplacian<math::UniformScaleMap, math::CD_SIXTH>::result(uniform, nineteenpt);
289
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
290
291 // test the GenericMap Grid interface
292 {
293 math::GenericMap generic_map(*grid);
294
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_SECOND>::result(generic_map, dense_2nd);
295
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
296
297
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_FOURTH>::result(generic_map, dense_4th);
298
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
299 }
300 {
301 // test the GenericMap Transform interface
302 math::GenericMap generic_map(grid->transform());
303
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_SECOND>::result(generic_map, dense_2nd);
304
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
305
306 }
307 {
308 // test the GenericMap Map interface
309 1 math::GenericMap generic_map(rotated_map);
310
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Laplacian<math::GenericMap, math::CD_SECOND>::result(generic_map, dense_2nd);
311
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/20., result, /*tolerance=*/0.01);
312 }
313 1 }
314
315
316
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLaplacian, testOldStyleStencils)
317 {
318 using namespace openvdb;
319
320
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*backgroundValue=*/5.0);
321
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 grid->setTransform(math::Transform::createLinearTransform(/*voxel size=*/0.5));
322
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());
323
324 const Coord dim(32, 32, 32);
325 const Coord c(35,30,40);
326 const openvdb::Vec3f center(6.0f, 8.0f, 10.0f);//i.e. (12,16,20) in index space
327 const float radius=10.0f;
328
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
329
330
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());
331
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(dim[0]*dim[1]*dim[2], int(grid->activeVoxelCount()));
332
333
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::GradStencil<FloatGrid> gs(*grid);
334
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::WenoStencil<FloatGrid> ws(*grid);
335
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::CurvatureStencil<FloatGrid> cs(*grid);
336
337 Coord xyz(20,16,20);//i.e. 8 voxel or 4 world units away from the center
338
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gs.moveTo(xyz);
339
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/4.0, gs.laplacian(), 0.01);// 2/distance from center
340
341
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ws.moveTo(xyz);
342
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/4.0, ws.laplacian(), 0.01);// 2/distance from center
343
344
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 cs.moveTo(xyz);
345
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/4.0, cs.laplacian(), 0.01);// 2/distance from center
346
347 xyz.reset(12,16,10);//i.e. 10 voxel or 5 world units away from the center
348
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gs.moveTo(xyz);
349
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/5.0, gs.laplacian(), 0.01);// 2/distance from center
350
351
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ws.moveTo(xyz);
352
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/5.0, ws.laplacian(), 0.01);// 2/distance from center
353
354
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 cs.moveTo(xyz);
355
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(2.0/5.0, cs.laplacian(), 0.01);// 2/distance from center
356 1 }
357
358
359
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLaplacian, testLaplacianTool)
360 {
361 using namespace openvdb;
362
363 1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
364 FloatTree& tree = grid->tree();
365
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(tree.empty());
366
367 const Coord dim(64, 64, 64);
368 const openvdb::Vec3f center(35.0f, 30.0f, 40.0f);
369 const float radius=0.0f;
370
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
371
372
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(!tree.empty());
373
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(dim[0]*dim[1]*dim[2], int(tree.activeVoxelCount()));
374
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr lap = tools::laplacian(*grid);
375
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(int(tree.activeVoxelCount()), int(lap->activeVoxelCount()));
376
377 Coord xyz(35,30,30);
378
379
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.
2 EXPECT_NEAR(
380 2.0/10.0, lap->getConstAccessor().getValue(xyz), 0.01);// 2/distance from center
381
382 xyz.reset(35,10,40);
383
384
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.
2 EXPECT_NEAR(
385 2.0/20.0, lap->getConstAccessor().getValue(xyz),0.01);// 2/distance from center
386 1 }
387
388
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestLaplacian, testLaplacianMaskedTool)
389 {
390 using namespace openvdb;
391
392 1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
393 FloatTree& tree = grid->tree();
394
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(tree.empty());
395
396 const Coord dim(64, 64, 64);
397 const openvdb::Vec3f center(35.0f, 30.0f, 40.0f);
398 const float radius=0.0f;
399
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
400
401
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(!tree.empty());
402
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(dim[0]*dim[1]*dim[2], int(tree.activeVoxelCount()));
403
404 1 const openvdb::CoordBBox maskbbox(openvdb::Coord(35, 30, 30), openvdb::Coord(41, 41, 41));
405
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 BoolGrid::Ptr maskGrid = BoolGrid::create(false);
406
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 maskGrid->fill(maskbbox, true/*value*/, true/*activate*/);
407
408
409
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr lap = tools::laplacian(*grid, *maskGrid);
410
411 {// outside the masked region
412 Coord xyz(34,30,30);
413
414
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(!maskbbox.isInside(xyz));
415
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.
2 EXPECT_NEAR(
416 0, lap->getConstAccessor().getValue(xyz), 0.01);// 2/distance from center
417
418 xyz.reset(35,10,40);
419
420
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.
2 EXPECT_NEAR(
421 0, lap->getConstAccessor().getValue(xyz),0.01);// 2/distance from center
422 }
423
424 {// inside the masked region
425 Coord xyz(35,30,30);
426
427
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(maskbbox.isInside(xyz));
428
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.
2 EXPECT_NEAR(
429 2.0/10.0, lap->getConstAccessor().getValue(xyz), 0.01);// 2/distance from center
430
431 }
432 1 }
433