GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestGradient.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 294 294 100.0%
Functions: 13 13 100.0%
Branches: 399 2148 18.6%

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 11 class TestGradient: public ::testing::Test
13 {
14 public:
15 11 void SetUp() override { openvdb::initialize(); }
16 11 void TearDown() override { openvdb::uninitialize(); }
17 };
18
19
20
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testISGradient)
21 {
22 using namespace openvdb;
23
24 using AccessorType = FloatGrid::ConstAccessor;
25
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = createGrid<FloatGrid>(/*background=*/5.0);
26 FloatTree& tree = grid->tree();
27
28 const openvdb::Coord dim(64,64,64);
29 const openvdb::Vec3f center(35.0f ,30.0f, 40.0f);
30 const float radius=10.0f;
31
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
32
33
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());
34
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()));
35 const Coord xyz(10, 20, 30);
36
37
38 // Index Space Gradients: random access and stencil version
39 AccessorType inAccessor = grid->getConstAccessor();
40 Vec3f result;
41
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::CD_2ND>::result(inAccessor, xyz);
42
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(1.0, result.length(), /*tolerance=*/0.01);
43
44
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::CD_4TH>::result(inAccessor, xyz);
45
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(1.0, result.length(), /*tolerance=*/0.01);
46
47
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::CD_6TH>::result(inAccessor, xyz);
48
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(1.0, result.length(), /*tolerance=*/0.01);
49
50
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::FD_1ST>::result(inAccessor, xyz);
51
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(1.0, result.length(), /*tolerance=*/0.02);
52
53
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::FD_2ND>::result(inAccessor, xyz);
54
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(1.0, result.length(), /*tolerance=*/0.01);
55
56
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::FD_3RD>::result(inAccessor, xyz);
57
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(1.0, result.length(), /*tolerance=*/0.01);
58
59
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::BD_1ST>::result(inAccessor, xyz);
60
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(1.0, result.length(), /*tolerance=*/0.02);
61
62
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::BD_2ND>::result(inAccessor, xyz);
63
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(1.0, result.length(), /*tolerance=*/0.01);
64
65
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::BD_3RD>::result(inAccessor, xyz);
66
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(1.0, result.length(), /*tolerance=*/0.01);
67
68
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::FD_WENO5>::result(inAccessor, xyz);
69
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(1.0, result.length(), /*tolerance=*/0.01);
70
71
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::ISGradient<math::BD_WENO5>::result(inAccessor, xyz);
72
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(1.0, result.length(), /*tolerance=*/0.01);
73 1 }
74
75
76
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testISGradientStencil)
77 {
78 using namespace openvdb;
79
80
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = createGrid<FloatGrid>(/*background=*/5.0);
81 FloatTree& tree = grid->tree();
82
83 const openvdb::Coord dim(64,64,64);
84 const openvdb::Vec3f center(35.0f ,30.0f, 40.0f);
85 const float radius = 10.0f;
86
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
87
88
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());
89
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()));
90 const Coord xyz(10, 20, 30);
91
92
93 // Index Space Gradients: stencil version
94 Vec3f result;
95 // this stencil is large enough for all thie different schemes used
96 // in this test
97 math::NineteenPointStencil<FloatGrid> stencil(*grid);
98
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
99
100 1 result = math::ISGradient<math::CD_2ND>::result(stencil);
101
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(1.0, result.length(), /*tolerance=*/0.01);
102
103 1 result = math::ISGradient<math::CD_4TH>::result(stencil);
104
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(1.0, result.length(), /*tolerance=*/0.01);
105
106 1 result = math::ISGradient<math::CD_6TH>::result(stencil);
107
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(1.0, result.length(), /*tolerance=*/0.01);
108
109 result = math::ISGradient<math::FD_1ST>::result(stencil);
110
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(1.0, result.length(), /*tolerance=*/0.02);
111
112 1 result = math::ISGradient<math::FD_2ND>::result(stencil);
113
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(1.0, result.length(), /*tolerance=*/0.01);
114
115 1 result = math::ISGradient<math::FD_3RD>::result(stencil);
116
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(1.0, result.length(), /*tolerance=*/0.01);
117
118 result = math::ISGradient<math::BD_1ST>::result(stencil);
119
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(1.0, result.length(), /*tolerance=*/0.02);
120
121 1 result = math::ISGradient<math::BD_2ND>::result(stencil);
122
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(1.0, result.length(), /*tolerance=*/0.01);
123
124 1 result = math::ISGradient<math::BD_3RD>::result(stencil);
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(1.0, result.length(), /*tolerance=*/0.01);
126
127 1 result = math::ISGradient<math::FD_WENO5>::result(stencil);
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(1.0, result.length(), /*tolerance=*/0.01);
129
130 1 result = math::ISGradient<math::BD_WENO5>::result(stencil);
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(1.0, result.length(), /*tolerance=*/0.01);
132 1 }
133
134
135
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testWSGradient)
136 {
137 using namespace openvdb;
138
139 using AccessorType = FloatGrid::ConstAccessor;
140
141 double voxel_size = 0.5;
142
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
143
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));
144
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());
145
146 const openvdb::Coord dim(32,32,32);
147 const openvdb::Vec3f center(6.0f, 8.0f, 10.0f);//i.e. (12,16,20) in index space
148 const float radius = 10.0f;
149
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
150
151
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());
152
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()));
153 const Coord xyz(11, 17, 26);
154
155 AccessorType inAccessor = grid->getConstAccessor();
156 // try with a map
157
158 // Index Space Gradients: stencil version
159 Vec3f result;
160
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::MapBase::Ptr rotated_map;
161 {
162 math::UniformScaleMap map(voxel_size);
163 result = math::Gradient<math::UniformScaleMap, math::CD_2ND>::result(
164
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 map, inAccessor, xyz);
165
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(1.0, result.length(), /*tolerance=*/0.01);
166
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 rotated_map = map.preRotate(1.5, math::X_AXIS);
167 // verify the new map is an affine map
168
2/18
✓ 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.
1 EXPECT_TRUE(rotated_map->type() == math::AffineMap::mapType());
169 math::AffineMap::Ptr affine_map =
170 StaticPtrCast<math::AffineMap, math::MapBase>(rotated_map);
171 // the gradient should have the same length even after rotation
172 result = math::Gradient<math::AffineMap, math::CD_2ND>::result(
173
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *affine_map, inAccessor, xyz);
174
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(1.0, result.length(), /*tolerance=*/0.01);
175 result = math::Gradient<math::AffineMap, math::CD_4TH>::result(
176
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *affine_map, inAccessor, xyz);
177
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(1.0, result.length(), /*tolerance=*/0.01);
178 }
179 {
180 1 math::UniformScaleTranslateMap map(voxel_size, Vec3d(0,0,0));
181 result = math::Gradient<math::UniformScaleTranslateMap, math::CD_2ND>::result(
182
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 map, inAccessor, xyz);
183
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(1.0, result.length(), /*tolerance=*/0.01);
184 }
185 {
186
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 math::ScaleTranslateMap map(Vec3d(voxel_size, voxel_size, voxel_size), Vec3d(0,0,0));
187 result = math::Gradient<math::ScaleTranslateMap, math::CD_2ND>::result(
188
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 map, inAccessor, xyz);
189
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(1.0, result.length(), /*tolerance=*/0.01);
190 }
191
192 {
193 // this map has no scale, expect result/voxel_spaceing = 1
194 math::TranslationMap map;
195
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Gradient<math::TranslationMap, math::CD_2ND>::result(map, inAccessor, xyz);
196
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(voxel_size, result.length(), /*tolerance=*/0.01);
197 }
198
199 {
200 // test the GenericMap Grid interface
201 math::GenericMap generic_map(*grid);
202 result = math::Gradient<math::GenericMap, math::CD_2ND>::result(
203
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 generic_map, inAccessor, xyz);
204
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(1.0, result.length(), /*tolerance=*/0.01);
205 }
206 {
207 // test the GenericMap Transform interface
208 math::GenericMap generic_map(grid->transform());
209 result = math::Gradient<math::GenericMap, math::CD_2ND>::result(
210
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 generic_map, inAccessor, xyz);
211
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(1.0, result.length(), /*tolerance=*/0.01);
212 }
213 {
214 // test the GenericMap Map interface
215 1 math::GenericMap generic_map(rotated_map);
216 result = math::Gradient<math::GenericMap, math::CD_2ND>::result(
217
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 generic_map, inAccessor, xyz);
218
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(1.0, result.length(), /*tolerance=*/0.01);
219 }
220 {
221 // test a map with non-uniform SCALING AND ROTATION
222 Vec3d voxel_sizes(0.25, 0.45, 0.75);
223
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::MapBase::Ptr base_map( new math::ScaleMap(voxel_sizes));
224 // apply rotation
225
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 rotated_map = base_map->preRotate(1.5, math::X_AXIS);
226
4/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
3 grid->setTransform(math::Transform::Ptr(new math::Transform(rotated_map)));
227 // remake the sphere
228
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(
229 dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
230
231 math::AffineMap::Ptr affine_map =
232 StaticPtrCast<math::AffineMap, math::MapBase>(rotated_map);
233
234 // math::ScaleMap map(voxel_sizes);
235 result = math::Gradient<math::AffineMap, math::CD_2ND>::result(
236
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 *affine_map, inAccessor, xyz);
237
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(1.0, result.length(), /*tolerance=*/0.01);
238 }
239 {
240 // test a map with non-uniform SCALING
241 Vec3d voxel_sizes(0.25, 0.45, 0.75);
242
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::MapBase::Ptr base_map( new math::ScaleMap(voxel_sizes));
243
4/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
3 grid->setTransform(math::Transform::Ptr(new math::Transform(base_map)));
244 // remake the sphere
245
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(
246 dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
247 math::ScaleMap::Ptr scale_map = StaticPtrCast<math::ScaleMap, math::MapBase>(base_map);
248
249 // math::ScaleMap map(voxel_sizes);
250
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Gradient<math::ScaleMap, math::CD_2ND>::result(*scale_map, inAccessor, xyz);
251
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(1.0, result.length(), /*tolerance=*/0.01);
252 }
253 1 }
254
255
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestGradient, testWSGradientStencilFrustum)
256 {
257 using namespace openvdb;
258
259 // Construct a frustum that matches the one in TestMaps::testFrustum()
260
261 1 openvdb::BBoxd bbox(Vec3d(0), Vec3d(100));
262 math::NonlinearFrustumMap frustum(bbox, 1./6., 5);
263 /// frustum will have depth, far plane - near plane = 5
264 /// the frustum has width 1 in the front and 6 in the back
265
266 Vec3d trans(2,2,2);
267 math::NonlinearFrustumMap::Ptr map =
268 StaticPtrCast<math::NonlinearFrustumMap, math::MapBase>(
269
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.
2 frustum.preScale(Vec3d(10,10,10))->postTranslate(trans));
270
271
272 // Create a grid with this frustum
273
274
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.f);
275
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
2 math::Transform::Ptr transform = math::Transform::Ptr( new math::Transform(map));
276
2/6
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 grid->setTransform(transform);
277
278 FloatGrid::Accessor acc = grid->getAccessor();
279 // Totally fill the interior of the frustum with word space distances
280 // from its center.
281
282
283 math::Vec3d isCenter(.5 * 101, .5 * 101, .5 * 101);
284 1 math::Vec3d wsCenter = map->applyMap(isCenter);
285
286 math::Coord ijk;
287
288 // convert to IntType
289 Vec3i min(bbox.min());
290 Vec3i max = Vec3i(bbox.max()) + Vec3i(1, 1, 1);
291
292
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1 times.
102 for (ijk[0] = min.x(); ijk[0] < max.x(); ++ijk[0]) {
293
2/2
✓ Branch 0 taken 10201 times.
✓ Branch 1 taken 101 times.
10302 for (ijk[1] = min.y(); ijk[1] < max.y(); ++ijk[1]) {
294
2/2
✓ Branch 0 taken 1030301 times.
✓ Branch 1 taken 10201 times.
1040502 for (ijk[2] = min.z(); ijk[2] < max.z(); ++ijk[2]) {
295 const math::Vec3d wsLocation = transform->indexToWorld(ijk);
296 1030301 const float dis = float((wsLocation - wsCenter).length());
297
298
1/2
✓ Branch 1 taken 1030301 times.
✗ Branch 2 not taken.
1030301 acc.setValue(ijk, dis);
299 }
300 }
301 }
302
303
304 {
305 // test at location 10, 10, 10 in index space
306 math::Coord xyz(10, 10, 10);
307
308 math::Vec3s result =
309
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::Gradient<math::NonlinearFrustumMap, math::CD_2ND>::result(*map, acc, xyz);
310
311 // The Gradient should be unit lenght for this case
312
1/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ 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 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_NEAR(1.0, result.length(), /*tolerance=*/0.01);
313
314 math::Vec3d wsVec = transform->indexToWorld(xyz);
315 math::Vec3d direction = (wsVec - wsCenter);
316 1 direction.normalize();
317
318 // test the actual direction of the gradient
319
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(direction.eq(result, 0.01 /*tolerance*/));
320 }
321
322 {
323 // test at location 30, 30, 60 in index space
324 math::Coord xyz(30, 30, 60);
325
326 math::Vec3s result =
327
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::Gradient<math::NonlinearFrustumMap, math::CD_2ND>::result(*map, acc, xyz);
328
329 // The Gradient should be unit lenght for this case
330
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(1.0, result.length(), /*tolerance=*/0.01);
331
332 math::Vec3d wsVec = transform->indexToWorld(xyz);
333 math::Vec3d direction = (wsVec - wsCenter);
334 1 direction.normalize();
335
336 // test the actual direction of the gradient
337
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(direction.eq(result, 0.01 /*tolerance*/));
338 }
339 1 }
340
341
342
343
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testWSGradientStencil)
344 {
345 using namespace openvdb;
346
347 double voxel_size = 0.5;
348
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
349
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));
350
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());
351
352 const openvdb::Coord dim(32,32,32);
353 const openvdb::Vec3f center(6.0f, 8.0f ,10.0f);//i.e. (12,16,20) in index space
354 const float radius = 10;
355
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
356
357
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());
358
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()));
359 const Coord xyz(11, 17, 26);
360
361 // try with a map
362 math::SevenPointStencil<FloatGrid> stencil(*grid);
363
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
364
365 math::SecondOrderDenseStencil<FloatGrid> dense_2ndOrder(*grid);
366
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dense_2ndOrder.moveTo(xyz);
367
368 math::FourthOrderDenseStencil<FloatGrid> dense_4thOrder(*grid);
369
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dense_4thOrder.moveTo(xyz);
370
371 Vec3f result;
372
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::MapBase::Ptr rotated_map;
373 {
374 math::UniformScaleMap map(voxel_size);
375 result = math::Gradient<math::UniformScaleMap, math::CD_2ND>::result(
376
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 map, stencil);
377
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(1.0, result.length(), /*tolerance=*/0.01);
378
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 rotated_map = map.preRotate(1.5, math::X_AXIS);
379 // verify the new map is an affine map
380
2/18
✓ 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.
1 EXPECT_TRUE(rotated_map->type() == math::AffineMap::mapType());
381 math::AffineMap::Ptr affine_map =
382 StaticPtrCast<math::AffineMap, math::MapBase>(rotated_map);
383 // the gradient should have the same length even after rotation
384
385 result = math::Gradient<math::AffineMap, math::CD_2ND>::result(
386 1 *affine_map, dense_2ndOrder);
387
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(1.0, result.length(), /*tolerance=*/0.01);
388
389 result = math::Gradient<math::AffineMap, math::CD_4TH>::result(
390 1 *affine_map, dense_4thOrder);
391
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(1.0, result.length(), /*tolerance=*/0.01);
392 }
393 {
394 1 math::UniformScaleTranslateMap map(voxel_size, Vec3d(0,0,0));
395
396
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Gradient<math::UniformScaleTranslateMap, math::CD_2ND>::result(map, stencil);
397
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(1.0, result.length(), /*tolerance=*/0.01);
398 }
399 {
400
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 math::ScaleTranslateMap map(Vec3d(voxel_size, voxel_size, voxel_size), Vec3d(0,0,0));
401 1 result = math::Gradient<math::ScaleTranslateMap, math::CD_2ND>::result(map, stencil);
402
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(1.0, result.length(), /*tolerance=*/0.01);
403 }
404 {
405 math::TranslationMap map;
406
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result = math::Gradient<math::TranslationMap, math::CD_2ND>::result(map, stencil);
407 // value = 1 because the translation map assumes uniform spacing
408
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(0.5, result.length(), /*tolerance=*/0.01);
409 }
410 {
411 // test the GenericMap Grid interface
412 math::GenericMap generic_map(*grid);
413 result = math::Gradient<math::GenericMap, math::CD_2ND>::result(
414
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 generic_map, dense_2ndOrder);
415
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(1.0, result.length(), /*tolerance=*/0.01);
416 }
417 {
418 // test the GenericMap Transform interface
419 math::GenericMap generic_map(grid->transform());
420 result = math::Gradient<math::GenericMap, math::CD_2ND>::result(
421
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 generic_map, dense_2ndOrder);
422
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(1.0, result.length(), /*tolerance=*/0.01);
423 }
424 {
425 // test the GenericMap Map interface
426 1 math::GenericMap generic_map(rotated_map);
427 result = math::Gradient<math::GenericMap, math::CD_2ND>::result(
428
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 generic_map, dense_2ndOrder);
429
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(1.0, result.length(), /*tolerance=*/0.01);
430 }
431 {
432 // test a map with non-uniform SCALING AND ROTATION
433 Vec3d voxel_sizes(0.25, 0.45, 0.75);
434
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::MapBase::Ptr base_map( new math::ScaleMap(voxel_sizes));
435 // apply rotation
436
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 rotated_map = base_map->preRotate(1.5, math::X_AXIS);
437
4/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
3 grid->setTransform(math::Transform::Ptr(new math::Transform(rotated_map)));
438 // remake the sphere
439
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(
440 dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
441 math::AffineMap::Ptr affine_map =
442 StaticPtrCast<math::AffineMap, math::MapBase>(rotated_map);
443
444
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
445 1 result = math::Gradient<math::AffineMap, math::CD_2ND>::result(*affine_map, stencil);
446
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(1.0, result.length(), /*tolerance=*/0.01);
447 }
448 {
449 // test a map with NON-UNIFORM SCALING
450 Vec3d voxel_sizes(0.5, 1.0, 0.75);
451
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 math::MapBase::Ptr base_map( new math::ScaleMap(voxel_sizes));
452
4/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
3 grid->setTransform(math::Transform::Ptr(new math::Transform(base_map)));
453 // remake the sphere
454
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(
455 dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
456
457
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::ScaleMap map(voxel_sizes);
458
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dense_2ndOrder.moveTo(xyz);
459
460 1 result = math::Gradient<math::ScaleMap, math::CD_2ND>::result(map, dense_2ndOrder);
461
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(1.0, result.length(), /*tolerance=*/0.01);
462 }
463 1 }
464
465
466
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testWSGradientNormSqr)
467 {
468 using namespace openvdb;
469
470 using AccessorType = FloatGrid::ConstAccessor;
471 double voxel_size = 0.5;
472
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
473
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));
474
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());
475
476 const openvdb::Coord dim(32,32,32);
477 const openvdb::Vec3f center(6.0f,8.0f,10.0f);//i.e. (12,16,20) in index space
478 const float radius = 10.0f;
479
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
480
481
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());
482
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()));
483 const Coord xyz(11, 17, 26);
484
485 AccessorType inAccessor = grid->getConstAccessor();
486
487 // test gradient in index and world space using the 7-pt stencil
488 math::UniformScaleMap uniform_scale(voxel_size);
489 FloatTree::ValueType normsqrd;
490 normsqrd = math::GradientNormSqrd<math::UniformScaleMap, math::FIRST_BIAS>::result(
491 uniform_scale, inAccessor, xyz);
492
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(1.0, normsqrd, /*tolerance=*/0.07);
493
494 // test world space using the 13pt stencil
495 normsqrd = math::GradientNormSqrd<math::UniformScaleMap, math::SECOND_BIAS>::result(
496 uniform_scale, inAccessor, xyz);
497
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(1.0, normsqrd, /*tolerance=*/0.05);
498
499
1/4
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
1 math::AffineMap affine(voxel_size*math::Mat3d::identity());
500
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 normsqrd = math::GradientNormSqrd<math::AffineMap, math::FIRST_BIAS>::result(
501 affine, inAccessor, xyz);
502
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(1.0, normsqrd, /*tolerance=*/0.07);
503
504 normsqrd = math::GradientNormSqrd<math::UniformScaleMap, math::THIRD_BIAS>::result(
505 uniform_scale, inAccessor, xyz);
506
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(1.0, normsqrd, /*tolerance=*/0.05);
507 1 }
508
509
510
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testWSGradientNormSqrStencil)
511 {
512 using namespace openvdb;
513
514 double voxel_size = 0.5;
515
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/5.0);
516
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));
517
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());
518
519 const openvdb::Coord dim(32,32,32);
520 const openvdb::Vec3f center(6.0f, 8.0f, 10.0f);//i.e. (12,16,20) in index space
521 const float radius = 10.0f;
522
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
523
524
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());
525
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()));
526 const Coord xyz(11, 17, 26);
527
528 math::SevenPointStencil<FloatGrid> sevenpt(*grid);
529
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 sevenpt.moveTo(xyz);
530
531 math::ThirteenPointStencil<FloatGrid> thirteenpt(*grid);
532
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 thirteenpt.moveTo(xyz);
533
534 math::SecondOrderDenseStencil<FloatGrid> dense_2ndOrder(*grid);
535
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dense_2ndOrder.moveTo(xyz);
536
537 math::NineteenPointStencil<FloatGrid> nineteenpt(*grid);
538
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 nineteenpt.moveTo(xyz);
539
540 // test gradient in index and world space using the 7-pt stencil
541 math::UniformScaleMap uniform_scale(voxel_size);
542 FloatTree::ValueType normsqrd;
543 normsqrd = math::GradientNormSqrd<math::UniformScaleMap, math::FIRST_BIAS>::result(
544 uniform_scale, sevenpt);
545
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(1.0, normsqrd, /*tolerance=*/0.07);
546
547
548 // test gradient in index and world space using the 13pt stencil
549 normsqrd = math::GradientNormSqrd<math::UniformScaleMap, math::SECOND_BIAS>::result(
550 uniform_scale, thirteenpt);
551
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(1.0, normsqrd, /*tolerance=*/0.05);
552
553
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 math::AffineMap affine(voxel_size*math::Mat3d::identity());
554 1 normsqrd = math::GradientNormSqrd<math::AffineMap, math::FIRST_BIAS>::result(
555 affine, dense_2ndOrder);
556
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(1.0, normsqrd, /*tolerance=*/0.07);
557
558 normsqrd = math::GradientNormSqrd<math::UniformScaleMap, math::THIRD_BIAS>::result(
559 uniform_scale, nineteenpt);
560
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(1.0, normsqrd, /*tolerance=*/0.05);
561 1 }
562
563
564
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testGradientTool)
565 {
566 using namespace openvdb;
567
568
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = createGrid<FloatGrid>(/*background=*/5.0);
569 FloatTree& tree = grid->tree();
570
571 const openvdb::Coord dim(64, 64, 64);
572 const openvdb::Vec3f center(35.0f, 30.0f, 40.0f);
573 const float radius = 10.0f;
574
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
575
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(!tree.empty());
577
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()));
578 const Coord xyz(10, 20, 30);
579
580
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 Vec3SGrid::Ptr grad = tools::gradient(*grid);
581
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(grad->activeVoxelCount()));
582
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(1.0, grad->getConstAccessor().getValue(xyz).length(),
583 /*tolerance=*/0.01);
584 1 }
585
586
587
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testGradientMaskedTool)
588 {
589 using namespace openvdb;
590
591
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = createGrid<FloatGrid>(/*background=*/5.0);
592 FloatTree& tree = grid->tree();
593
594 const openvdb::Coord dim(64, 64, 64);
595 const openvdb::Vec3f center(35.0f, 30.0f, 40.0f);
596 const float radius = 10.0f;
597
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
598
599
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());
600
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()));
601
602 1 const openvdb::CoordBBox maskbbox(openvdb::Coord(35, 30, 30), openvdb::Coord(41, 41, 41));
603
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);
604
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*/);
605
606
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 Vec3SGrid::Ptr grad = tools::gradient(*grid, *maskGrid);
607 {// outside the masked region
608 const Coord xyz(10, 20, 30);
609
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));
610
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(0.0, grad->getConstAccessor().getValue(xyz).length(),
611 /*tolerance=*/0.01);
612 }
613 {// inside the masked region
614 const Coord xyz(38, 35, 33);
615
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));
616
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(1.0, grad->getConstAccessor().getValue(xyz).length(),
617 /*tolerance=*/0.01);
618 }
619 1 }
620
621
622
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testIntersectsIsoValue)
623 {
624 using namespace openvdb;
625
626 {// test zero crossing in -x
627
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
628 FloatTree& tree = grid.tree();
629 Coord xyz(2,-5,60);
630
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
631
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy(-1,0,0), -2.0f);
632 math::SevenPointStencil<FloatGrid> stencil(grid);
633
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
634
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( stencil.intersects( ));
635
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( stencil.intersects( 0.0f));
636
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( stencil.intersects( 2.0f));
637
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(!stencil.intersects( 5.5f));
638
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(!stencil.intersects(-2.5f));
639 }
640 {// test zero crossing in +x
641
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
642 FloatTree& tree = grid.tree();
643 Coord xyz(2,-5,60);
644
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
645
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy(1,0,0), -2.0f);
646 math::SevenPointStencil<FloatGrid> stencil(grid);
647
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
648
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(stencil.intersects());
649 }
650 {// test zero crossing in -y
651
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
652 FloatTree& tree = grid.tree();
653 Coord xyz(2,-5,60);
654
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
655
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy(0,-1,0), -2.0f);
656 math::SevenPointStencil<FloatGrid> stencil(grid);
657
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
658
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(stencil.intersects());
659 }
660 {// test zero crossing in y
661
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
662 FloatTree& tree = grid.tree();
663 Coord xyz(2,-5,60);
664
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
665
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy(0,1,0), -2.0f);
666 math::SevenPointStencil<FloatGrid> stencil(grid);
667
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
668
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(stencil.intersects());
669 }
670 {// test zero crossing in -z
671
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
672 FloatTree& tree = grid.tree();
673 Coord xyz(2,-5,60);
674
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
675
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy(0,0,-1), -2.0f);
676 math::SevenPointStencil<FloatGrid> stencil(grid);
677
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
678
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(stencil.intersects());
679 }
680 {// test zero crossing in z
681
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
682 FloatTree& tree = grid.tree();
683 Coord xyz(2,-5,60);
684
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
685
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy(0,0,1), -2.0f);
686 math::SevenPointStencil<FloatGrid> stencil(grid);
687
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
688
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(stencil.intersects());
689 }
690 {// test zero crossing in -x & z
691
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
692 FloatTree& tree = grid.tree();
693 Coord xyz(2,-5,60);
694
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
695
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy(-1,0,1), -2.0f);
696 math::SevenPointStencil<FloatGrid> stencil(grid);
697
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
698
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(!stencil.intersects());
699 }
700 {// test zero multiple crossings
701
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 FloatGrid grid(/*backgroundValue=*/5.0);
702 FloatTree& tree = grid.tree();
703 Coord xyz(2,-5,60);
704
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz, 1.3f);
705
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz.offsetBy(-1, 0, 1), -1.0f);
706
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz.offsetBy( 0, 0, 1), -2.0f);
707
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(xyz.offsetBy( 0, 1, 0), -3.0f);
708
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(xyz.offsetBy( 0, 0,-1), -2.0f);
709 math::SevenPointStencil<FloatGrid> stencil(grid);
710
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 stencil.moveTo(xyz);
711
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(stencil.intersects());
712 }
713 1 }
714
715
716
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestGradient, testOldStyleStencils)
717 {
718 using namespace openvdb;
719
720
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*backgroundValue=*/5.0);
721
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));
722
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());
723
724 const openvdb::Coord dim(32,32,32);
725 const openvdb::Vec3f center(6.0f,8.0f,10.0f);//i.e. (12,16,20) in index space
726 const float radius=10.0f;
727
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(dim, center, radius, *grid, unittest_util::SPHERE_DENSE);
728
729
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());
730
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()));
731 const Coord xyz(11, 17, 26);
732
733
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::GradStencil<FloatGrid> gs(*grid);
734
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gs.moveTo(xyz);
735
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(1.0, gs.gradient().length(), /*tolerance=*/0.01);
736
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(1.0, gs.normSqGrad(), /*tolerance=*/0.10);
737
738
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::WenoStencil<FloatGrid> ws(*grid);
739
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ws.moveTo(xyz);
740
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(1.0, ws.gradient().length(), /*tolerance=*/0.01);
741
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(1.0, ws.normSqGrad(), /*tolerance=*/0.01);
742
743
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::CurvatureStencil<FloatGrid> cs(*grid);
744
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 cs.moveTo(xyz);
745
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(1.0, cs.gradient().length(), /*tolerance=*/0.01);
746 1 }
747