Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright Contributors to the OpenVDB Project | ||
2 | // SPDX-License-Identifier: MPL-2.0 | ||
3 | |||
4 | #include <openvdb/openvdb.h> | ||
5 | #include <openvdb/math/BBox.h> | ||
6 | #include <openvdb/math/Math.h> | ||
7 | #include <openvdb/tree/Tree.h> | ||
8 | #include <openvdb/tools/GridTransformer.h> | ||
9 | #include <openvdb/tools/Prune.h> | ||
10 | |||
11 | #include <gtest/gtest.h> | ||
12 | |||
13 | |||
14 | #define ASSERT_DOUBLES_EXACTLY_EQUAL(expected, actual) \ | ||
15 | EXPECT_NEAR((expected), (actual), /*tolerance=*/0.0); | ||
16 | |||
17 | 11 | class TestGridTransformer: public ::testing::Test | |
18 | { | ||
19 | protected: | ||
20 | template<typename GridType, typename Sampler> void transformGrid(); | ||
21 | }; | ||
22 | |||
23 | |||
24 | //////////////////////////////////////// | ||
25 | |||
26 | |||
27 | template<typename GridType, typename Sampler> | ||
28 | void | ||
29 | 18 | TestGridTransformer::transformGrid() | |
30 | { | ||
31 | using openvdb::Coord; | ||
32 | using openvdb::CoordBBox; | ||
33 | using openvdb::Vec3R; | ||
34 | |||
35 | typedef typename GridType::ValueType ValueT; | ||
36 | |||
37 | const int radius = Sampler::radius(); | ||
38 | const openvdb::Vec3R zeroVec(0, 0, 0), oneVec(1, 1, 1); | ||
39 | const ValueT | ||
40 | 16 | zero = openvdb::zeroVal<ValueT>(), | |
41 | 2 | one = zero + 1, | |
42 | 16 | two = one + 1, | |
43 | 18 | background = one; | |
44 | const bool transformTiles = true; | ||
45 | |||
46 | // Create a sparse test grid comprising the eight corners of a 20 x 20 x 20 cube. | ||
47 | 18 | typename GridType::Ptr inGrid = GridType::create(background); | |
48 | typename GridType::Accessor inAcc = inGrid->getAccessor(); | ||
49 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord( 0, 0, 0), /*value=*/zero); |
50 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord(20, 0, 0), zero); |
51 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord( 0, 20, 0), zero); |
52 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord( 0, 0, 20), zero); |
53 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord(20, 0, 20), zero); |
54 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord( 0, 20, 20), zero); |
55 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord(20, 20, 0), zero); |
56 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
18 | inAcc.setValue(Coord(20, 20, 20), zero); |
57 |
3/20✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 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.
|
18 | EXPECT_EQ(openvdb::Index64(8), inGrid->activeVoxelCount()); |
58 | |||
59 | // For various combinations of scaling, rotation and translation... | ||
60 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 9 times.
|
162 | for (int i = 0; i < 8; ++i) { |
61 | const openvdb::Vec3R | ||
62 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
144 | scale = i & 1 ? openvdb::Vec3R(10, 4, 7.5) : oneVec, |
63 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
144 | rotate = (i & 2 ? openvdb::Vec3R(30, 230, -190) : zeroVec) * (M_PI / 180), |
64 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
144 | translate = i & 4 ? openvdb::Vec3R(-5, 0, 10) : zeroVec, |
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
144 | pivot = i & 8 ? openvdb::Vec3R(0.5, 4, -3.3) : zeroVec; |
66 |
4/8✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 72 times.
✗ Branch 12 not taken.
|
288 | openvdb::tools::GridTransformer transformer(pivot, scale, rotate, translate); |
67 | transformer.setTransformTiles(transformTiles); | ||
68 | |||
69 | // Add a tile (either active or inactive) in the interior of the cube. | ||
70 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | const bool tileIsActive = (i % 2); |
71 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | inGrid->fill(CoordBBox(Coord(8), Coord(15)), two, tileIsActive); |
72 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
144 | if (tileIsActive) { |
73 |
3/18✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 36 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.
|
72 | EXPECT_EQ(openvdb::Index64(512 + 8), inGrid->activeVoxelCount()); |
74 | } else { | ||
75 |
3/18✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 36 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.
|
72 | EXPECT_EQ(openvdb::Index64(8), inGrid->activeVoxelCount()); |
76 | } | ||
77 | // Verify that a voxel outside the cube has the background value. | ||
78 |
3/26✓ Branch 1 taken 64 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
176 | EXPECT_TRUE(openvdb::math::isExactlyEqual(inAcc.getValue(Coord(21, 0, 0)), background)); |
79 |
2/16✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
✗ 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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
|
144 | EXPECT_EQ(false, inAcc.isValueOn(Coord(21, 0, 0))); |
80 | // Verify that a voxel inside the cube has value two. | ||
81 |
3/26✓ Branch 1 taken 64 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
176 | EXPECT_TRUE(openvdb::math::isExactlyEqual(inAcc.getValue(Coord(12)), two)); |
82 |
2/16✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
✗ 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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
|
144 | EXPECT_EQ(tileIsActive, inAcc.isValueOn(Coord(12))); |
83 | |||
84 | // Verify that the bounding box of all active values is 20 x 20 x 20. | ||
85 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | CoordBBox activeVoxelBBox = inGrid->evalActiveVoxelBoundingBox(); |
86 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 72 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.
|
144 | EXPECT_TRUE(!activeVoxelBBox.empty()); |
87 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | const Coord imin = activeVoxelBBox.min(), imax = activeVoxelBBox.max(); |
88 |
1/14✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
144 | EXPECT_EQ(Coord(0), imin); |
89 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
144 | EXPECT_EQ(Coord(20), imax); |
90 | |||
91 | // Transform the corners of the input grid's bounding box | ||
92 | // and compute the enclosing bounding box in the output grid. | ||
93 | 144 | const openvdb::Mat4R xform = transformer.getTransform(); | |
94 | const Vec3R | ||
95 | 144 | inRMin(imin.x(), imin.y(), imin.z()), | |
96 | 144 | inRMax(imax.x(), imax.y(), imax.z()); | |
97 | Vec3R outRMin, outRMax; | ||
98 | 144 | outRMin = outRMax = inRMin * xform; | |
99 |
2/2✓ Branch 0 taken 576 times.
✓ Branch 1 taken 72 times.
|
1296 | for (int j = 0; j < 8; ++j) { |
100 | 3456 | Vec3R corner( | |
101 |
2/2✓ Branch 0 taken 288 times.
✓ Branch 1 taken 288 times.
|
1152 | j & 1 ? inRMax.x() : inRMin.x(), |
102 |
2/2✓ Branch 0 taken 288 times.
✓ Branch 1 taken 288 times.
|
1152 | j & 2 ? inRMax.y() : inRMin.y(), |
103 |
2/2✓ Branch 0 taken 288 times.
✓ Branch 1 taken 288 times.
|
1152 | j & 4 ? inRMax.z() : inRMin.z()); |
104 | 1152 | outRMin = openvdb::math::minComponent(outRMin, corner * xform); | |
105 | 1152 | outRMax = openvdb::math::maxComponent(outRMax, corner * xform); | |
106 | } | ||
107 | |||
108 | 144 | CoordBBox bbox( | |
109 | 144 | Coord(openvdb::tools::local_util::floorVec3(outRMin) - radius), | |
110 | 144 | Coord(openvdb::tools::local_util::ceilVec3(outRMax) + radius)); | |
111 | |||
112 | // Transform the test grid. | ||
113 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | typename GridType::Ptr outGrid = GridType::create(background); |
114 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | transformer.transformGrid<Sampler>(*inGrid, *outGrid); |
115 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | openvdb::tools::prune(outGrid->tree()); |
116 | |||
117 | // Verify that the bounding box of the transformed grid | ||
118 | // matches the transformed bounding box of the original grid. | ||
119 | |||
120 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | activeVoxelBBox = outGrid->evalActiveVoxelBoundingBox(); |
121 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 72 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.
|
144 | EXPECT_TRUE(!activeVoxelBBox.empty()); |
122 | const openvdb::Vec3i | ||
123 | 144 | omin = activeVoxelBBox.min().asVec3i(), | |
124 | 144 | omax = activeVoxelBBox.max().asVec3i(); | |
125 | const int bboxTolerance = 1; // allow for rounding | ||
126 | #if 0 | ||
127 | if (!omin.eq(bbox.min().asVec3i(), bboxTolerance) || | ||
128 | !omax.eq(bbox.max().asVec3i(), bboxTolerance)) | ||
129 | { | ||
130 | std::cerr << "\nS = " << scale << ", R = " << rotate | ||
131 | << ", T = " << translate << ", P = " << pivot << "\n" | ||
132 | << xform.transpose() << "\n" << "computed bbox = " << bbox | ||
133 | << "\nactual bbox = " << omin << " -> " << omax << "\n"; | ||
134 | } | ||
135 | #endif | ||
136 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 72 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.
|
144 | EXPECT_TRUE(omin.eq(bbox.min().asVec3i(), bboxTolerance)); |
137 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 72 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.
|
144 | EXPECT_TRUE(omax.eq(bbox.max().asVec3i(), bboxTolerance)); |
138 | |||
139 | // Verify that (a voxel in) the interior of the cube was | ||
140 | // transformed correctly. | ||
141 |
1/2✓ Branch 3 taken 64 times.
✗ Branch 4 not taken.
|
144 | const Coord center = Coord::round(Vec3R(12) * xform); |
142 | const typename GridType::TreeType& outTree = outGrid->tree(); | ||
143 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 72 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.
|
144 | EXPECT_TRUE(openvdb::math::isExactlyEqual(transformTiles ? two : background, |
144 | outTree.getValue(center))); | ||
145 |
3/18✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
216 | if (transformTiles && tileIsActive) EXPECT_TRUE(outTree.isValueOn(center)); |
146 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 36 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.
|
72 | else EXPECT_TRUE(!outTree.isValueOn(center)); |
147 | } | ||
148 | 18 | } | |
149 | |||
150 | |||
151 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, testTransformBoolPoint) |
152 | 1 | { transformGrid<openvdb::BoolGrid, openvdb::tools::PointSampler>(); } | |
153 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformFloatPoint) |
154 | 1 | { transformGrid<openvdb::FloatGrid, openvdb::tools::PointSampler>(); } | |
155 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformFloatBox) |
156 | 1 | { transformGrid<openvdb::FloatGrid, openvdb::tools::BoxSampler>(); } | |
157 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformFloatQuadratic) |
158 | 1 | { transformGrid<openvdb::FloatGrid, openvdb::tools::QuadraticSampler>(); } | |
159 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformDoubleBox) |
160 | 1 | { transformGrid<openvdb::DoubleGrid, openvdb::tools::BoxSampler>(); } | |
161 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformInt32Box) |
162 | 1 | { transformGrid<openvdb::Int32Grid, openvdb::tools::BoxSampler>(); } | |
163 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformInt64Box) |
164 | 1 | { transformGrid<openvdb::Int64Grid, openvdb::tools::BoxSampler>(); } | |
165 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformVec3SPoint) |
166 | 1 | { transformGrid<openvdb::VectorGrid, openvdb::tools::PointSampler>(); } | |
167 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, TransformVec3DBox) |
168 | 1 | { transformGrid<openvdb::Vec3DGrid, openvdb::tools::BoxSampler>(); } | |
169 | |||
170 | |||
171 | //////////////////////////////////////// | ||
172 | |||
173 | |||
174 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, testResampleToMatch) |
175 | { | ||
176 | using namespace openvdb; | ||
177 | |||
178 | // Create an input grid with an identity transform. | ||
179 | 2 | FloatGrid inGrid; | |
180 | // Populate it with a 20 x 20 x 20 cube. | ||
181 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | inGrid.fill(CoordBBox(Coord(5), Coord(24)), /*value=*/1.0); |
182 |
2/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_EQ(8000, int(inGrid.activeVoxelCount())); |
183 |
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(inGrid.tree().activeTileCount() > 0); |
184 | |||
185 | {//test identity transform | ||
186 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | FloatGrid outGrid; |
187 |
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(outGrid.transform() == inGrid.transform()); |
188 | // Resample the input grid into the output grid using point sampling. | ||
189 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | tools::resampleToMatch<tools::PointSampler>(inGrid, outGrid); |
190 |
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(int(inGrid.activeVoxelCount()), int(outGrid.activeVoxelCount())); |
191 |
2/2✓ Branch 0 taken 3912 times.
✓ Branch 1 taken 1 times.
|
3913 | for (openvdb::FloatTree::ValueOnCIter iter = inGrid.tree().cbeginValueOn(); iter; ++iter) { |
192 |
4/20✓ Branch 1 taken 3912 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3912 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3912 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 3912 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.
|
3912 | ASSERT_DOUBLES_EXACTLY_EQUAL(*iter,outGrid.tree().getValue(iter.getCoord())); |
193 | } | ||
194 | // The output grid's transform should not have changed. | ||
195 |
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(outGrid.transform() == inGrid.transform()); |
196 | } | ||
197 | |||
198 | {//test nontrivial transform | ||
199 | // Create an output grid with a different transform. | ||
200 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | math::Transform::Ptr xform = math::Transform::createLinearTransform(); |
201 |
1/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | xform->preScale(Vec3d(0.5, 0.5, 1.0)); |
202 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | FloatGrid outGrid; |
203 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | outGrid.setTransform(xform); |
204 |
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(outGrid.transform() != inGrid.transform()); |
205 | |||
206 | // Resample the input grid into the output grid using point sampling. | ||
207 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | tools::resampleToMatch<tools::PointSampler>(inGrid, outGrid); |
208 | |||
209 | // The output grid's transform should not have changed. | ||
210 |
1/14✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1 | EXPECT_EQ(*xform, outGrid.transform()); |
211 | |||
212 | // The output grid should have double the resolution of the input grid | ||
213 | // in x and y and the same resolution in z. | ||
214 |
2/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_EQ(32000, int(outGrid.activeVoxelCount())); |
215 |
2/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_EQ(Coord(40, 40, 20), outGrid.evalActiveVoxelDim()); |
216 |
1/14✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1 | EXPECT_EQ(CoordBBox(Coord(9, 9, 5), Coord(48, 48, 24)), |
217 | outGrid.evalActiveVoxelBoundingBox()); | ||
218 |
2/2✓ Branch 0 taken 32000 times.
✓ Branch 1 taken 1 times.
|
32001 | for (auto it = outGrid.tree().cbeginValueOn(); it; ++it) { |
219 |
2/16✓ Branch 1 taken 32000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 32000 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.
|
32000 | EXPECT_NEAR(1.0, *it, 1.0e-6); |
220 | } | ||
221 | } | ||
222 | 1 | } | |
223 | |||
224 | |||
225 | //////////////////////////////////////// | ||
226 | |||
227 | |||
228 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestGridTransformer, testDecomposition) |
229 | { | ||
230 | using namespace openvdb; | ||
231 | using tools::local_util::decompose; | ||
232 | |||
233 | { | ||
234 | Vec3d s, r, t; | ||
235 | 1 | auto m = Mat4d::identity(); | |
236 |
1/16✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
1 | EXPECT_TRUE(decompose(m, s, r, t)); |
237 | 1 | m(1, 3) = 1.0; // add a perspective component | |
238 | // Verify that decomposition fails for perspective transforms. | ||
239 |
1/16✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
1 | EXPECT_TRUE(!decompose(m, s, r, t)); |
240 | } | ||
241 | |||
242 | const auto rad = [](double deg) { return deg * M_PI / 180.0; }; | ||
243 | |||
244 | const Vec3d ix(1, 0, 0), iy(0, 1, 0), iz(0, 0, 1); | ||
245 | |||
246 | const auto translation = { Vec3d(0), Vec3d(100, 0, -100), Vec3d(-50, 100, 250) }; | ||
247 | const auto scale = { 1.0, 0.25, -0.25, -1.0, 10.0, -10.0 }; | ||
248 | const auto angle = { rad(0.0), rad(45.0), rad(90.0), rad(180.0), | ||
249 | 1 | rad(225.0), rad(270.0), rad(315.0), rad(360.0) }; | |
250 | |||
251 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (const auto& t: translation) { |
252 | |||
253 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
|
21 | for (const double sx: scale) { |
254 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 18 times.
|
126 | for (const double sy: scale) { |
255 |
2/2✓ Branch 0 taken 648 times.
✓ Branch 1 taken 108 times.
|
756 | for (const double sz: scale) { |
256 | const Vec3d s(sx, sy, sz); | ||
257 | |||
258 |
2/2✓ Branch 0 taken 5184 times.
✓ Branch 1 taken 648 times.
|
5832 | for (const double rx: angle) { |
259 |
2/2✓ Branch 0 taken 41472 times.
✓ Branch 1 taken 5184 times.
|
46656 | for (const double ry: angle) { |
260 |
2/2✓ Branch 0 taken 331776 times.
✓ Branch 1 taken 41472 times.
|
373248 | for (const double rz: angle) { |
261 | |||
262 | Mat4d m = | ||
263 |
1/2✓ Branch 1 taken 331776 times.
✗ Branch 2 not taken.
|
331776 | math::rotation<Mat4d>(iz, rz) * |
264 |
1/2✓ Branch 1 taken 331776 times.
✗ Branch 2 not taken.
|
663552 | math::rotation<Mat4d>(iy, ry) * |
265 |
1/2✓ Branch 1 taken 331776 times.
✗ Branch 2 not taken.
|
663552 | math::rotation<Mat4d>(ix, rx) * |
266 |
1/2✓ Branch 3 taken 331776 times.
✗ Branch 4 not taken.
|
663552 | math::scale<Mat4d>(s); |
267 | m.setTranslation(t); | ||
268 | |||
269 | Vec3d outS(0), outR(0), outT(0); | ||
270 |
3/4✓ Branch 1 taken 331776 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 74304 times.
✓ Branch 4 taken 257472 times.
|
331776 | if (decompose(m, outS, outR, outT)) { |
271 | // If decomposition succeeds, verify that it produces | ||
272 | // the same matrix. (Most decompositions fail to find | ||
273 | // a unique solution, though.) | ||
274 | Mat4d outM = | ||
275 |
1/2✓ Branch 1 taken 74304 times.
✗ Branch 2 not taken.
|
74304 | math::rotation<Mat4d>(iz, outR.z()) * |
276 |
1/2✓ Branch 1 taken 74304 times.
✗ Branch 2 not taken.
|
148608 | math::rotation<Mat4d>(iy, outR.y()) * |
277 |
1/2✓ Branch 1 taken 74304 times.
✗ Branch 2 not taken.
|
148608 | math::rotation<Mat4d>(ix, outR.x()) * |
278 | 148608 | math::scale<Mat4d>(outS); | |
279 | outM.setTranslation(outT); | ||
280 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 74304 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.
|
74304 | EXPECT_TRUE(outM.eq(m)); |
281 | } | ||
282 |
1/2✓ Branch 1 taken 331776 times.
✗ Branch 2 not taken.
|
331776 | tools::GridTransformer transformer(m); |
283 | const bool transformUnchanged = transformer.getTransform().eq(m); | ||
284 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 331776 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.
|
331776 | EXPECT_TRUE(transformUnchanged); |
285 | } | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | } | ||
291 | } | ||
292 | 1 | } | |
293 | |||
294 |