GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/tools/Interpolation.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 160 176 90.9%
Functions: 73 117 62.4%
Branches: 545 1139 47.8%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 /// @file Interpolation.h
5 ///
6 /// Sampler classes such as PointSampler and BoxSampler that are intended for use
7 /// with tools::GridTransformer should operate in voxel space and must adhere to
8 /// the interface described in the example below:
9 /// @code
10 /// struct MySampler
11 /// {
12 /// // Return a short name that can be used to identify this sampler
13 /// // in error messages and elsewhere.
14 /// const char* name() { return "mysampler"; }
15 ///
16 /// // Return the radius of the sampling kernel in voxels, not including
17 /// // the center voxel. This is the number of voxels of padding that
18 /// // are added to all sides of a volume as a result of resampling.
19 /// int radius() { return 2; }
20 ///
21 /// // Return true if scaling by a factor smaller than 0.5 (along any axis)
22 /// // should be handled via a mipmapping-like scheme of successive halvings
23 /// // of a grid's resolution, until the remaining scale factor is
24 /// // greater than or equal to 1/2. Set this to false only when high-quality
25 /// // scaling is not required.
26 /// bool mipmap() { return true; }
27 ///
28 /// // Specify if sampling at a location that is collocated with a grid point
29 /// // is guaranteed to return the exact value at that grid point.
30 /// // For most sampling kernels, this should be false.
31 /// bool consistent() { return false; }
32 ///
33 /// // Sample the tree at the given coordinates and return the result in val.
34 /// // Return true if the sampled value is active.
35 /// template<class TreeT>
36 /// bool sample(const TreeT& tree, const Vec3R& coord, typename TreeT::ValueType& val);
37 /// };
38 /// @endcode
39
40 #ifndef OPENVDB_TOOLS_INTERPOLATION_HAS_BEEN_INCLUDED
41 #define OPENVDB_TOOLS_INTERPOLATION_HAS_BEEN_INCLUDED
42
43 #include <openvdb/version.h> // for OPENVDB_VERSION_NAME
44 #include <openvdb/Platform.h> // for round()
45 #include <openvdb/math/Math.h>// for SmoothUnitStep
46 #include <openvdb/math/Transform.h> // for Transform
47 #include <openvdb/Grid.h>
48 #include <openvdb/tree/ValueAccessor.h>
49 #include <cmath>
50 #include <type_traits>
51
52 namespace openvdb {
53 OPENVDB_USE_VERSION_NAMESPACE
54 namespace OPENVDB_VERSION_NAME {
55 namespace tools {
56
57 /// @brief Provises a unified interface for sampling, i.e. interpolation.
58 /// @details Order = 0: closest point
59 /// Order = 1: tri-linear
60 /// Order = 2: tri-quadratic
61 /// Staggered: Set to true for MAC grids
62 template <size_t Order, bool Staggered = false>
63 struct Sampler
64 {
65 static_assert(Order < 3, "Samplers of order higher than 2 are not supported");
66 static const char* name();
67 static int radius();
68 static bool mipmap();
69 static bool consistent();
70 static bool staggered();
71 static size_t order();
72
73 /// @brief Sample @a inTree at the floating-point index coordinate @a inCoord
74 /// and store the result in @a result.
75 ///
76 /// @return @c true if the sampled value is active.
77 template<class TreeT>
78 static bool sample(const TreeT& inTree, const Vec3R& inCoord,
79 typename TreeT::ValueType& result);
80
81 /// @brief Sample @a inTree at the floating-point index coordinate @a inCoord.
82 ///
83 /// @return the reconstructed value
84 template<class TreeT>
85 static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
86 };
87
88 //////////////////////////////////////// Non-Staggered Samplers
89
90 // The following samplers operate in voxel space.
91 // When the samplers are applied to grids holding vector or other non-scalar data,
92 // the data is assumed to be collocated. For example, using the BoxSampler on a grid
93 // with ValueType Vec3f assumes that all three elements in a vector can be assigned
94 // the same physical location. Consider using the GridSampler below instead.
95
96 struct PointSampler
97 {
98 static const char* name() { return "point"; }
99 static int radius() { return 0; }
100 static bool mipmap() { return false; }
101 static bool consistent() { return true; }
102 static bool staggered() { return false; }
103 static size_t order() { return 0; }
104
105 /// @brief Sample @a inTree at the nearest neighbor to @a inCoord
106 /// and store the result in @a result.
107 /// @return @c true if the sampled value is active.
108 template<class TreeT>
109 static bool sample(const TreeT& inTree, const Vec3R& inCoord,
110 typename TreeT::ValueType& result);
111
112 /// @brief Sample @a inTree at the nearest neighbor to @a inCoord
113 /// @return the reconstructed value
114 template<class TreeT>
115 static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
116 };
117
118
119 struct BoxSampler
120 {
121 static const char* name() { return "box"; }
122 static int radius() { return 1; }
123 static bool mipmap() { return true; }
124 static bool consistent() { return true; }
125 static bool staggered() { return false; }
126 static size_t order() { return 1; }
127
128 /// @brief Trilinearly reconstruct @a inTree at @a inCoord
129 /// and store the result in @a result.
130 /// @return @c true if any one of the sampled values is active.
131 template<class TreeT>
132 static bool sample(const TreeT& inTree, const Vec3R& inCoord,
133 typename TreeT::ValueType& result);
134
135 /// @brief Trilinearly reconstruct @a inTree at @a inCoord.
136 /// @return the reconstructed value
137 template<class TreeT>
138 static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
139
140 /// @brief Import all eight values from @a inTree to support
141 /// tri-linear interpolation.
142 template<class ValueT, class TreeT, size_t N>
143 static inline void getValues(ValueT (&data)[N][N][N], const TreeT& inTree, Coord ijk);
144
145 /// @brief Import all eight values from @a inTree to support
146 /// tri-linear interpolation.
147 /// @return @c true if any of the eight values are active
148 template<class ValueT, class TreeT, size_t N>
149 static inline bool probeValues(ValueT (&data)[N][N][N], const TreeT& inTree, Coord ijk);
150
151 /// @brief Find the minimum and maximum values of the eight cell
152 /// values in @ data.
153 template<class ValueT, size_t N>
154 static inline void extrema(ValueT (&data)[N][N][N], ValueT& vMin, ValueT& vMax);
155
156 /// @return the tri-linear interpolation with the unit cell coordinates @a uvw
157 template<class ValueT, size_t N>
158 static inline ValueT trilinearInterpolation(ValueT (&data)[N][N][N], const Vec3R& uvw);
159 };
160
161
162 struct QuadraticSampler
163 {
164 static const char* name() { return "quadratic"; }
165 static int radius() { return 1; }
166 static bool mipmap() { return true; }
167 static bool consistent() { return false; }
168 static bool staggered() { return false; }
169 static size_t order() { return 2; }
170
171 /// @brief Triquadratically reconstruct @a inTree at @a inCoord
172 /// and store the result in @a result.
173 /// @return @c true if any one of the sampled values is active.
174 template<class TreeT>
175 static bool sample(const TreeT& inTree, const Vec3R& inCoord,
176 typename TreeT::ValueType& result);
177
178 /// @brief Triquadratically reconstruct @a inTree at to @a inCoord.
179 /// @return the reconstructed value
180 template<class TreeT>
181 static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
182
183 template<class ValueT, size_t N>
184 static inline ValueT triquadraticInterpolation(ValueT (&data)[N][N][N], const Vec3R& uvw);
185 };
186
187
188 //////////////////////////////////////// Staggered Samplers
189
190
191 // The following samplers operate in voxel space and are designed for Vec3
192 // staggered grid data (e.g., fluid simulations using the Marker-and-Cell approach
193 // associate elements of the velocity vector with different physical locations:
194 // the faces of a cube).
195
196 struct StaggeredPointSampler
197 {
198 static const char* name() { return "point"; }
199 static int radius() { return 0; }
200 static bool mipmap() { return false; }
201 static bool consistent() { return false; }
202 static bool staggered() { return true; }
203 static size_t order() { return 0; }
204
205 /// @brief Sample @a inTree at the nearest neighbor to @a inCoord
206 /// and store the result in @a result.
207 /// @return true if the sampled value is active.
208 template<class TreeT>
209 static bool sample(const TreeT& inTree, const Vec3R& inCoord,
210 typename TreeT::ValueType& result);
211
212 /// @brief Sample @a inTree at the nearest neighbor to @a inCoord
213 /// @return the reconstructed value
214 template<class TreeT>
215 static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
216 };
217
218
219 struct StaggeredBoxSampler
220 {
221 static const char* name() { return "box"; }
222 static int radius() { return 1; }
223 static bool mipmap() { return true; }
224 static bool consistent() { return false; }
225 static bool staggered() { return true; }
226 static size_t order() { return 1; }
227
228 /// @brief Trilinearly reconstruct @a inTree at @a inCoord
229 /// and store the result in @a result.
230 /// @return true if any one of the sampled value is active.
231 template<class TreeT>
232 static bool sample(const TreeT& inTree, const Vec3R& inCoord,
233 typename TreeT::ValueType& result);
234
235 /// @brief Trilinearly reconstruct @a inTree at @a inCoord.
236 /// @return the reconstructed value
237 template<class TreeT>
238 static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
239 };
240
241
242 struct StaggeredQuadraticSampler
243 {
244 static const char* name() { return "quadratic"; }
245 static int radius() { return 1; }
246 static bool mipmap() { return true; }
247 static bool consistent() { return false; }
248 static bool staggered() { return true; }
249 static size_t order() { return 2; }
250
251 /// @brief Triquadratically reconstruct @a inTree at @a inCoord
252 /// and store the result in @a result.
253 /// @return true if any one of the sampled values is active.
254 template<class TreeT>
255 static bool sample(const TreeT& inTree, const Vec3R& inCoord,
256 typename TreeT::ValueType& result);
257
258 /// @brief Triquadratically reconstruct @a inTree at to @a inCoord.
259 /// @return the reconstructed value
260 template<class TreeT>
261 static typename TreeT::ValueType sample(const TreeT& inTree, const Vec3R& inCoord);
262 };
263
264
265 //////////////////////////////////////// GridSampler
266
267
268 /// @brief Class that provides the interface for continuous sampling
269 /// of values in a tree.
270 ///
271 /// @details Since trees support only discrete voxel sampling, TreeSampler
272 /// must be used to sample arbitrary continuous points in (world or
273 /// index) space.
274 ///
275 /// @warning This implementation of the GridSampler stores a pointer
276 /// to a Tree for value access. While this is thread-safe it is
277 /// uncached and hence slow compared to using a
278 /// ValueAccessor. Consequently it is normally advisable to use the
279 /// template specialization below that employs a
280 /// ValueAccessor. However, care must be taken when dealing with
281 /// multi-threading (see warning below).
282 template<typename GridOrTreeType, typename SamplerType>
283 class GridSampler
284 {
285 public:
286 using Ptr = SharedPtr<GridSampler>;
287 using ValueType = typename GridOrTreeType::ValueType;
288 using GridType = typename TreeAdapter<GridOrTreeType>::GridType;
289 using TreeType = typename TreeAdapter<GridOrTreeType>::TreeType;
290 using AccessorType = typename TreeAdapter<GridOrTreeType>::AccessorType;
291
292 /// @param grid a grid to be sampled
293
4/8
✓ 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.
8 explicit GridSampler(const GridType& grid)
294
4/8
✓ 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.
8 : mTree(&(grid.tree())), mTransform(&(grid.transform())) {}
295
296 /// @param tree a tree to be sampled, or a ValueAccessor for the tree
297 /// @param transform is used when sampling world space locations.
298 1 GridSampler(const TreeType& tree, const math::Transform& transform)
299
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 : mTree(&tree), mTransform(&transform) {}
300
301 const math::Transform& transform() const { return *mTransform; }
302
303 /// @brief Sample a point in index space in the grid.
304 /// @param x Fractional x-coordinate of point in index-coordinates of grid
305 /// @param y Fractional y-coordinate of point in index-coordinates of grid
306 /// @param z Fractional z-coordinate of point in index-coordinates of grid
307 template<typename RealType>
308 ValueType sampleVoxel(const RealType& x, const RealType& y, const RealType& z) const
309 {
310
113/224
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 42 times.
✓ 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 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 times.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 1 times.
✓ Branch 42 taken 1 times.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 1 times.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✓ Branch 50 taken 1 times.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 1 times.
✓ Branch 57 taken 1 times.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✓ Branch 60 taken 1 times.
✓ Branch 62 taken 1 times.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✓ Branch 65 taken 1 times.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✓ Branch 70 taken 1 times.
✓ Branch 72 taken 1 times.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✓ Branch 75 taken 1 times.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✓ Branch 80 taken 1 times.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 85 taken 1 times.
✓ Branch 87 taken 1 times.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✓ Branch 90 taken 1 times.
✓ Branch 92 taken 1 times.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✓ Branch 95 taken 1 times.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✓ Branch 100 taken 1 times.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✓ Branch 105 taken 1 times.
✓ Branch 107 taken 1 times.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✓ Branch 110 taken 1 times.
✓ Branch 112 taken 1 times.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✓ Branch 115 taken 1 times.
✓ Branch 117 taken 1 times.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✓ Branch 120 taken 1 times.
✓ Branch 122 taken 1 times.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✓ Branch 125 taken 1 times.
✓ Branch 127 taken 1 times.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✓ Branch 130 taken 1 times.
✓ Branch 132 taken 1 times.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✓ Branch 135 taken 1 times.
✓ Branch 137 taken 1 times.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✓ Branch 140 taken 1 times.
✓ Branch 142 taken 1 times.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✓ Branch 145 taken 1 times.
✓ Branch 147 taken 1 times.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✓ Branch 150 taken 1 times.
✓ Branch 152 taken 1 times.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✓ Branch 155 taken 1 times.
✓ Branch 157 taken 1 times.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✓ Branch 160 taken 1 times.
✓ Branch 162 taken 1 times.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✓ Branch 165 taken 1 times.
✓ Branch 167 taken 1 times.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✓ Branch 170 taken 1 times.
✓ Branch 172 taken 1 times.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✓ Branch 175 taken 1 times.
✓ Branch 177 taken 1 times.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✓ Branch 180 taken 1 times.
✓ Branch 182 taken 1 times.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✓ Branch 185 taken 1 times.
✓ Branch 187 taken 1 times.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✓ Branch 190 taken 1 times.
✓ Branch 192 taken 1 times.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✓ Branch 195 taken 1 times.
✓ Branch 197 taken 1 times.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✓ Branch 200 taken 1 times.
✓ Branch 202 taken 1 times.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✓ Branch 205 taken 1 times.
✓ Branch 207 taken 1 times.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✓ Branch 210 taken 1 times.
✓ Branch 212 taken 1 times.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✓ Branch 215 taken 1 times.
✓ Branch 217 taken 1 times.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✓ Branch 220 taken 1 times.
✓ Branch 222 taken 1 times.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✓ Branch 225 taken 1 times.
✓ Branch 227 taken 1 times.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✓ Branch 230 taken 1 times.
✓ Branch 232 taken 1 times.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✓ Branch 235 taken 1 times.
✓ Branch 237 taken 1 times.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✓ Branch 240 taken 1 times.
✓ Branch 242 taken 1 times.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✓ Branch 245 taken 1 times.
✓ Branch 247 taken 1 times.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✓ Branch 250 taken 1 times.
✓ Branch 252 taken 1 times.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✓ Branch 255 taken 1 times.
✓ Branch 257 taken 1 times.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✓ Branch 260 taken 1 times.
✓ Branch 262 taken 1 times.
✗ Branch 263 not taken.
✗ Branch 264 not taken.
✓ Branch 265 taken 1 times.
✓ Branch 267 taken 1 times.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✓ Branch 270 taken 1 times.
✓ Branch 272 taken 1 times.
✗ Branch 273 not taken.
✗ Branch 274 not taken.
✓ Branch 275 taken 1 times.
✓ Branch 277 taken 1 times.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✓ Branch 280 taken 1 times.
183 return this->isSample(Vec3d(x,y,z));
311 }
312
313 /// @brief Sample value in integer index space
314 /// @param i Integer x-coordinate in index space
315 /// @param j Integer y-coordinate in index space
316 /// @param k Integer x-coordinate in index space
317 ValueType sampleVoxel(typename Coord::ValueType i,
318 typename Coord::ValueType j,
319 typename Coord::ValueType k) const
320 {
321 return this->isSample(Coord(i,j,k));
322 }
323
324 /// @brief Sample value in integer index space
325 /// @param ijk the location in index space
326 ValueType isSample(const Coord& ijk) const { return mTree->getValue(ijk); }
327
328 /// @brief Sample in fractional index space
329 /// @param ispoint the location in index space
330 152 ValueType isSample(const Vec3d& ispoint) const
331 {
332 374 ValueType result = zeroVal<ValueType>();
333
138/276
✓ 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 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 1 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 1 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 1 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 1 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 1 times.
✗ Branch 107 not taken.
✓ Branch 109 taken 1 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 1 times.
✗ Branch 113 not taken.
✓ Branch 115 taken 1 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 1 times.
✗ Branch 119 not taken.
✓ Branch 121 taken 1 times.
✗ Branch 122 not taken.
✓ Branch 124 taken 1 times.
✗ Branch 125 not taken.
✓ Branch 127 taken 1 times.
✗ Branch 128 not taken.
✓ Branch 130 taken 1 times.
✗ Branch 131 not taken.
✓ Branch 133 taken 1 times.
✗ Branch 134 not taken.
✓ Branch 136 taken 1 times.
✗ Branch 137 not taken.
✓ Branch 139 taken 1 times.
✗ Branch 140 not taken.
✓ Branch 142 taken 1 times.
✗ Branch 143 not taken.
✓ Branch 145 taken 1 times.
✗ Branch 146 not taken.
✓ Branch 148 taken 1 times.
✗ Branch 149 not taken.
✓ Branch 151 taken 1 times.
✗ Branch 152 not taken.
✓ Branch 154 taken 1 times.
✗ Branch 155 not taken.
✓ Branch 157 taken 1 times.
✗ Branch 158 not taken.
✓ Branch 160 taken 1 times.
✗ Branch 161 not taken.
✓ Branch 163 taken 1 times.
✗ Branch 164 not taken.
✓ Branch 166 taken 1 times.
✗ Branch 167 not taken.
✓ Branch 169 taken 1 times.
✗ Branch 170 not taken.
✓ Branch 172 taken 1 times.
✗ Branch 173 not taken.
✓ Branch 175 taken 1 times.
✗ Branch 176 not taken.
✓ Branch 178 taken 1 times.
✗ Branch 179 not taken.
✓ Branch 181 taken 1 times.
✗ Branch 182 not taken.
✓ Branch 184 taken 1 times.
✗ Branch 185 not taken.
✓ Branch 187 taken 1 times.
✗ Branch 188 not taken.
✓ Branch 190 taken 1 times.
✗ Branch 191 not taken.
✓ Branch 193 taken 1 times.
✗ Branch 194 not taken.
✓ Branch 196 taken 1 times.
✗ Branch 197 not taken.
✓ Branch 199 taken 1 times.
✗ Branch 200 not taken.
✓ Branch 202 taken 1 times.
✗ Branch 203 not taken.
✓ Branch 205 taken 1 times.
✗ Branch 206 not taken.
✓ Branch 208 taken 1 times.
✗ Branch 209 not taken.
✓ Branch 211 taken 1 times.
✗ Branch 212 not taken.
✓ Branch 214 taken 1 times.
✗ Branch 215 not taken.
✓ Branch 217 taken 1 times.
✗ Branch 218 not taken.
✓ Branch 220 taken 1 times.
✗ Branch 221 not taken.
✓ Branch 223 taken 1 times.
✗ Branch 224 not taken.
✓ Branch 226 taken 1 times.
✗ Branch 227 not taken.
✓ Branch 229 taken 1 times.
✗ Branch 230 not taken.
✓ Branch 232 taken 1 times.
✗ Branch 233 not taken.
✓ Branch 235 taken 1 times.
✗ Branch 236 not taken.
✓ Branch 238 taken 1 times.
✗ Branch 239 not taken.
✓ Branch 241 taken 1 times.
✗ Branch 242 not taken.
✓ Branch 244 taken 1 times.
✗ Branch 245 not taken.
✓ Branch 247 taken 1 times.
✗ Branch 248 not taken.
✓ Branch 250 taken 1 times.
✗ Branch 251 not taken.
✓ Branch 253 taken 1 times.
✗ Branch 254 not taken.
✓ Branch 256 taken 1 times.
✗ Branch 257 not taken.
✓ Branch 259 taken 1 times.
✗ Branch 260 not taken.
✓ Branch 262 taken 1 times.
✗ Branch 263 not taken.
✓ Branch 265 taken 1 times.
✗ Branch 266 not taken.
✓ Branch 268 taken 1 times.
✗ Branch 269 not taken.
✓ Branch 271 taken 1 times.
✗ Branch 272 not taken.
✓ Branch 274 taken 1 times.
✗ Branch 275 not taken.
✓ Branch 277 taken 1 times.
✗ Branch 278 not taken.
✓ Branch 280 taken 1 times.
✗ Branch 281 not taken.
✓ Branch 283 taken 1 times.
✗ Branch 284 not taken.
✓ Branch 286 taken 1 times.
✗ Branch 287 not taken.
✓ Branch 289 taken 1 times.
✗ Branch 290 not taken.
✓ Branch 292 taken 1 times.
✗ Branch 293 not taken.
✓ Branch 295 taken 1 times.
✗ Branch 296 not taken.
✓ Branch 298 taken 1 times.
✗ Branch 299 not taken.
✓ Branch 301 taken 1 times.
✗ Branch 302 not taken.
✓ Branch 304 taken 1 times.
✗ Branch 305 not taken.
✓ Branch 307 taken 1 times.
✗ Branch 308 not taken.
✓ Branch 310 taken 1 times.
✗ Branch 311 not taken.
✓ Branch 313 taken 1 times.
✗ Branch 314 not taken.
✓ Branch 316 taken 1 times.
✗ Branch 317 not taken.
✓ Branch 319 taken 1 times.
✗ Branch 320 not taken.
✓ Branch 322 taken 1 times.
✗ Branch 323 not taken.
✓ Branch 325 taken 1 times.
✗ Branch 326 not taken.
✓ Branch 328 taken 1 times.
✗ Branch 329 not taken.
✓ Branch 331 taken 1 times.
✗ Branch 332 not taken.
✓ Branch 334 taken 1 times.
✗ Branch 335 not taken.
✓ Branch 337 taken 1 times.
✗ Branch 338 not taken.
✓ Branch 340 taken 1 times.
✗ Branch 341 not taken.
✓ Branch 343 taken 1 times.
✗ Branch 344 not taken.
✓ Branch 346 taken 1 times.
✗ Branch 347 not taken.
✓ Branch 349 taken 1 times.
✗ Branch 350 not taken.
✓ Branch 352 taken 1 times.
✗ Branch 353 not taken.
✓ Branch 355 taken 1 times.
✗ Branch 356 not taken.
✓ Branch 358 taken 1 times.
✗ Branch 359 not taken.
✓ Branch 361 taken 1 times.
✗ Branch 362 not taken.
✓ Branch 364 taken 1 times.
✗ Branch 365 not taken.
✓ Branch 367 taken 1 times.
✗ Branch 368 not taken.
✓ Branch 370 taken 1 times.
✗ Branch 371 not taken.
✓ Branch 373 taken 1 times.
✗ Branch 374 not taken.
✓ Branch 376 taken 1 times.
✗ Branch 377 not taken.
✓ Branch 379 taken 1 times.
✗ Branch 380 not taken.
✓ Branch 382 taken 1 times.
✗ Branch 383 not taken.
✓ Branch 385 taken 1 times.
✗ Branch 386 not taken.
✓ Branch 388 taken 1 times.
✗ Branch 389 not taken.
✓ Branch 391 taken 1 times.
✗ Branch 392 not taken.
✓ Branch 394 taken 1 times.
✗ Branch 395 not taken.
✓ Branch 397 taken 1 times.
✗ Branch 398 not taken.
✓ Branch 400 taken 1 times.
✗ Branch 401 not taken.
✓ Branch 403 taken 1 times.
✗ Branch 404 not taken.
✓ Branch 406 taken 1 times.
✗ Branch 407 not taken.
✓ Branch 409 taken 1 times.
✗ Branch 410 not taken.
✓ Branch 412 taken 1 times.
✗ Branch 413 not taken.
374 SamplerType::sample(*mTree, ispoint, result);
334
139/278
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
✓ 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 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 1 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 1 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 1 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 1 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 1 times.
✗ Branch 107 not taken.
✓ Branch 109 taken 1 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 1 times.
✗ Branch 113 not taken.
✓ Branch 115 taken 1 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 1 times.
✗ Branch 119 not taken.
✓ Branch 121 taken 1 times.
✗ Branch 122 not taken.
✓ Branch 124 taken 1 times.
✗ Branch 125 not taken.
✓ Branch 127 taken 1 times.
✗ Branch 128 not taken.
✓ Branch 130 taken 1 times.
✗ Branch 131 not taken.
✓ Branch 133 taken 1 times.
✗ Branch 134 not taken.
✓ Branch 136 taken 1 times.
✗ Branch 137 not taken.
✓ Branch 139 taken 1 times.
✗ Branch 140 not taken.
✓ Branch 142 taken 1 times.
✗ Branch 143 not taken.
✓ Branch 145 taken 1 times.
✗ Branch 146 not taken.
✓ Branch 148 taken 1 times.
✗ Branch 149 not taken.
✓ Branch 151 taken 1 times.
✗ Branch 152 not taken.
✓ Branch 154 taken 1 times.
✗ Branch 155 not taken.
✓ Branch 157 taken 1 times.
✗ Branch 158 not taken.
✓ Branch 160 taken 1 times.
✗ Branch 161 not taken.
✓ Branch 163 taken 1 times.
✗ Branch 164 not taken.
✓ Branch 166 taken 1 times.
✗ Branch 167 not taken.
✓ Branch 169 taken 1 times.
✗ Branch 170 not taken.
✓ Branch 172 taken 1 times.
✗ Branch 173 not taken.
✓ Branch 175 taken 1 times.
✗ Branch 176 not taken.
✓ Branch 178 taken 1 times.
✗ Branch 179 not taken.
✓ Branch 181 taken 1 times.
✗ Branch 182 not taken.
✓ Branch 184 taken 1 times.
✗ Branch 185 not taken.
✓ Branch 187 taken 1 times.
✗ Branch 188 not taken.
✓ Branch 190 taken 1 times.
✗ Branch 191 not taken.
✓ Branch 193 taken 1 times.
✗ Branch 194 not taken.
✓ Branch 196 taken 1 times.
✗ Branch 197 not taken.
✓ Branch 199 taken 1 times.
✗ Branch 200 not taken.
✓ Branch 202 taken 1 times.
✗ Branch 203 not taken.
✓ Branch 205 taken 1 times.
✗ Branch 206 not taken.
✓ Branch 208 taken 1 times.
✗ Branch 209 not taken.
✓ Branch 211 taken 1 times.
✗ Branch 212 not taken.
✓ Branch 214 taken 1 times.
✗ Branch 215 not taken.
✓ Branch 217 taken 1 times.
✗ Branch 218 not taken.
✓ Branch 220 taken 1 times.
✗ Branch 221 not taken.
✓ Branch 223 taken 1 times.
✗ Branch 224 not taken.
✓ Branch 226 taken 1 times.
✗ Branch 227 not taken.
✓ Branch 229 taken 1 times.
✗ Branch 230 not taken.
✓ Branch 232 taken 1 times.
✗ Branch 233 not taken.
✓ Branch 235 taken 1 times.
✗ Branch 236 not taken.
✓ Branch 238 taken 1 times.
✗ Branch 239 not taken.
✓ Branch 241 taken 1 times.
✗ Branch 242 not taken.
✓ Branch 244 taken 1 times.
✗ Branch 245 not taken.
✓ Branch 247 taken 1 times.
✗ Branch 248 not taken.
✓ Branch 250 taken 1 times.
✗ Branch 251 not taken.
✓ Branch 253 taken 1 times.
✗ Branch 254 not taken.
✓ Branch 256 taken 1 times.
✗ Branch 257 not taken.
✓ Branch 259 taken 1 times.
✗ Branch 260 not taken.
✓ Branch 262 taken 1 times.
✗ Branch 263 not taken.
✓ Branch 265 taken 1 times.
✗ Branch 266 not taken.
✓ Branch 268 taken 1 times.
✗ Branch 269 not taken.
✓ Branch 271 taken 1 times.
✗ Branch 272 not taken.
✓ Branch 274 taken 1 times.
✗ Branch 275 not taken.
✓ Branch 277 taken 1 times.
✗ Branch 278 not taken.
✓ Branch 280 taken 1 times.
✗ Branch 281 not taken.
✓ Branch 283 taken 1 times.
✗ Branch 284 not taken.
✓ Branch 286 taken 1 times.
✗ Branch 287 not taken.
✓ Branch 289 taken 1 times.
✗ Branch 290 not taken.
✓ Branch 292 taken 1 times.
✗ Branch 293 not taken.
✓ Branch 295 taken 1 times.
✗ Branch 296 not taken.
✓ Branch 298 taken 1 times.
✗ Branch 299 not taken.
✓ Branch 301 taken 1 times.
✗ Branch 302 not taken.
✓ Branch 304 taken 1 times.
✗ Branch 305 not taken.
✓ Branch 307 taken 1 times.
✗ Branch 308 not taken.
✓ Branch 310 taken 1 times.
✗ Branch 311 not taken.
✓ Branch 313 taken 1 times.
✗ Branch 314 not taken.
✓ Branch 316 taken 1 times.
✗ Branch 317 not taken.
✓ Branch 319 taken 1 times.
✗ Branch 320 not taken.
✓ Branch 322 taken 1 times.
✗ Branch 323 not taken.
✓ Branch 325 taken 1 times.
✗ Branch 326 not taken.
✓ Branch 328 taken 1 times.
✗ Branch 329 not taken.
✓ Branch 331 taken 1 times.
✗ Branch 332 not taken.
✓ Branch 334 taken 1 times.
✗ Branch 335 not taken.
✓ Branch 337 taken 1 times.
✗ Branch 338 not taken.
✓ Branch 340 taken 1 times.
✗ Branch 341 not taken.
✓ Branch 343 taken 1 times.
✗ Branch 344 not taken.
✓ Branch 346 taken 1 times.
✗ Branch 347 not taken.
✓ Branch 349 taken 1 times.
✗ Branch 350 not taken.
✓ Branch 352 taken 1 times.
✗ Branch 353 not taken.
✓ Branch 355 taken 1 times.
✗ Branch 356 not taken.
✓ Branch 358 taken 1 times.
✗ Branch 359 not taken.
✓ Branch 361 taken 1 times.
✗ Branch 362 not taken.
✓ Branch 364 taken 1 times.
✗ Branch 365 not taken.
✓ Branch 367 taken 1 times.
✗ Branch 368 not taken.
✓ Branch 370 taken 1 times.
✗ Branch 371 not taken.
✓ Branch 373 taken 1 times.
✗ Branch 374 not taken.
✓ Branch 376 taken 1 times.
✗ Branch 377 not taken.
✓ Branch 379 taken 1 times.
✗ Branch 380 not taken.
✓ Branch 382 taken 1 times.
✗ Branch 383 not taken.
✓ Branch 385 taken 1 times.
✗ Branch 386 not taken.
✓ Branch 388 taken 1 times.
✗ Branch 389 not taken.
✓ Branch 391 taken 1 times.
✗ Branch 392 not taken.
✓ Branch 394 taken 1 times.
✗ Branch 395 not taken.
✓ Branch 397 taken 1 times.
✗ Branch 398 not taken.
✓ Branch 400 taken 1 times.
✗ Branch 401 not taken.
✓ Branch 403 taken 1 times.
✗ Branch 404 not taken.
✓ Branch 406 taken 1 times.
✗ Branch 407 not taken.
✓ Branch 409 taken 1 times.
✗ Branch 410 not taken.
✓ Branch 412 taken 1 times.
✗ Branch 413 not taken.
332 return result;
335 }
336
337 /// @brief Sample in world space
338 /// @param wspoint the location in world space
339 ValueType wsSample(const Vec3d& wspoint) const
340 {
341 ValueType result = zeroVal<ValueType>();
342 SamplerType::sample(*mTree, mTransform->worldToIndex(wspoint), result);
343 return result;
344 }
345
346 private:
347 const TreeType* mTree;
348 const math::Transform* mTransform;
349 }; // class GridSampler
350
351
352 /// @brief Specialization of GridSampler for construction from a ValueAccessor type
353 ///
354 /// @note This version should normally be favored over the one above
355 /// that takes a Grid or Tree. The reason is this version uses a
356 /// ValueAccessor that performs fast (cached) access where the
357 /// tree-based flavor performs slower (uncached) access.
358 ///
359 /// @warning Since this version stores a pointer to an (externally
360 /// allocated) value accessor it is not threadsafe. Hence each thread
361 /// should have its own instance of a GridSampler constructed from a
362 /// local ValueAccessor. Alternatively the Grid/Tree-based GridSampler
363 /// is threadsafe, but also slower.
364 template<typename TreeT, typename SamplerType>
365 class GridSampler<tree::ValueAccessor<TreeT>, SamplerType>
366 {
367 public:
368 using Ptr = SharedPtr<GridSampler>;
369 using ValueType = typename TreeT::ValueType;
370 using TreeType = TreeT;
371 using GridType = Grid<TreeType>;
372 using AccessorType = typename tree::ValueAccessor<TreeT>;
373
374 /// @param acc a ValueAccessor to be sampled
375 /// @param transform is used when sampling world space locations.
376 61 GridSampler(const AccessorType& acc,
377 const math::Transform& transform)
378
1/97
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
61 : mAccessor(&acc), mTransform(&transform) {}
379
380 const math::Transform& transform() const { return *mTransform; }
381
382 /// @brief Sample a point in index space in the grid.
383 /// @param x Fractional x-coordinate of point in index-coordinates of grid
384 /// @param y Fractional y-coordinate of point in index-coordinates of grid
385 /// @param z Fractional z-coordinate of point in index-coordinates of grid
386 template<typename RealType>
387 ValueType sampleVoxel(const RealType& x, const RealType& y, const RealType& z) const
388 {
389
26/52
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 1 times.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 1 times.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 1 times.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✓ Branch 44 taken 1 times.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 1 times.
✓ Branch 51 taken 1 times.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✓ Branch 54 taken 1 times.
✓ Branch 56 taken 1 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 1 times.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 1 times.
13 return this->isSample(Vec3d(x,y,z));
390 }
391
392 /// @brief Sample value in integer index space
393 /// @param i Integer x-coordinate in index space
394 /// @param j Integer y-coordinate in index space
395 /// @param k Integer x-coordinate in index space
396 ValueType sampleVoxel(typename Coord::ValueType i,
397 typename Coord::ValueType j,
398 typename Coord::ValueType k) const
399 {
400 return this->isSample(Coord(i,j,k));
401 }
402
403 /// @brief Sample value in integer index space
404 /// @param ijk the location in index space
405 ValueType isSample(const Coord& ijk) const { return mAccessor->getValue(ijk); }
406
407 /// @brief Sample in fractional index space
408 /// @param ispoint the location in index space
409 13 ValueType isSample(const Vec3d& ispoint) const
410 {
411 39 ValueType result = zeroVal<ValueType>();
412
26/52
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 1 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 1 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 1 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 1 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 1 times.
✗ Branch 57 not taken.
✓ Branch 59 taken 1 times.
✗ Branch 60 not taken.
✓ Branch 62 taken 1 times.
✗ Branch 63 not taken.
✓ Branch 65 taken 1 times.
✗ Branch 66 not taken.
✓ Branch 68 taken 1 times.
✗ Branch 69 not taken.
✓ Branch 71 taken 1 times.
✗ Branch 72 not taken.
✓ Branch 74 taken 1 times.
✗ Branch 75 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
39 SamplerType::sample(*mAccessor, ispoint, result);
413
26/52
✓ 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 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
26 return result;
414 }
415
416 /// @brief Sample in world space
417 /// @param wspoint the location in world space
418 12444 ValueType wsSample(const Vec3d& wspoint) const
419 {
420 ValueType result = zeroVal<ValueType>();
421 12444 SamplerType::sample(*mAccessor, mTransform->worldToIndex(wspoint), result);
422 12444 return result;
423 }
424
425 private:
426 const AccessorType* mAccessor;//not thread-safe!
427 const math::Transform* mTransform;
428 };//Specialization of GridSampler
429
430
431 //////////////////////////////////////// DualGridSampler
432
433
434 /// @brief This is a simple convenience class that allows for sampling
435 /// from a source grid into the index space of a target grid. At
436 /// construction the source and target grids are checked for alignment
437 /// which potentially renders interpolation unnecessary. Else
438 /// interpolation is performed according to the templated Sampler
439 /// type.
440 ///
441 /// @warning For performance reasons the check for alignment of the
442 /// two grids is only performed at construction time!
443 template<typename GridOrTreeT,
444 typename SamplerT>
445 class DualGridSampler
446 {
447 public:
448 using ValueType = typename GridOrTreeT::ValueType;
449 using GridType = typename TreeAdapter<GridOrTreeT>::GridType;
450 using TreeType = typename TreeAdapter<GridOrTreeT>::TreeType;
451 using AccessorType = typename TreeAdapter<GridType>::AccessorType;
452
453 /// @brief Grid and transform constructor.
454 /// @param sourceGrid Source grid.
455 /// @param targetXform Transform of the target grid.
456 DualGridSampler(const GridType& sourceGrid,
457 const math::Transform& targetXform)
458 : mSourceTree(&(sourceGrid.tree()))
459 , mSourceXform(&(sourceGrid.transform()))
460 , mTargetXform(&targetXform)
461 , mAligned(targetXform == *mSourceXform)
462 {
463 }
464 /// @brief Tree and transform constructor.
465 /// @param sourceTree Source tree.
466 /// @param sourceXform Transform of the source grid.
467 /// @param targetXform Transform of the target grid.
468 DualGridSampler(const TreeType& sourceTree,
469 const math::Transform& sourceXform,
470 const math::Transform& targetXform)
471 : mSourceTree(&sourceTree)
472 , mSourceXform(&sourceXform)
473 , mTargetXform(&targetXform)
474 , mAligned(targetXform == sourceXform)
475 {
476 }
477 /// @brief Return the value of the source grid at the index
478 /// coordinates, ijk, relative to the target grid (or its tranform).
479 inline ValueType operator()(const Coord& ijk) const
480 {
481 if (mAligned) return mSourceTree->getValue(ijk);
482 const Vec3R world = mTargetXform->indexToWorld(ijk);
483 return SamplerT::sample(*mSourceTree, mSourceXform->worldToIndex(world));
484 }
485 /// @brief Return true if the two grids are aligned.
486 inline bool isAligned() const { return mAligned; }
487 private:
488 const TreeType* mSourceTree;
489 const math::Transform* mSourceXform;
490 const math::Transform* mTargetXform;
491 const bool mAligned;
492 };// DualGridSampler
493
494 /// @brief Specialization of DualGridSampler for construction from a ValueAccessor type.
495 template<typename TreeT,
496 typename SamplerT>
497 class DualGridSampler<tree::ValueAccessor<TreeT>, SamplerT>
498 {
499 public:
500 using ValueType = typename TreeT::ValueType;
501 using TreeType = TreeT;
502 using GridType = Grid<TreeType>;
503 using AccessorType = typename tree::ValueAccessor<TreeT>;
504
505 /// @brief ValueAccessor and transform constructor.
506 /// @param sourceAccessor ValueAccessor into the source grid.
507 /// @param sourceXform Transform for the source grid.
508 /// @param targetXform Transform for the target grid.
509 DualGridSampler(const AccessorType& sourceAccessor,
510 const math::Transform& sourceXform,
511 const math::Transform& targetXform)
512 : mSourceAcc(&sourceAccessor)
513 , mSourceXform(&sourceXform)
514 , mTargetXform(&targetXform)
515 , mAligned(targetXform == sourceXform)
516 {
517 }
518 /// @brief Return the value of the source grid at the index
519 /// coordinates, ijk, relative to the target grid.
520 inline ValueType operator()(const Coord& ijk) const
521 {
522 if (mAligned) return mSourceAcc->getValue(ijk);
523 const Vec3R world = mTargetXform->indexToWorld(ijk);
524 return SamplerT::sample(*mSourceAcc, mSourceXform->worldToIndex(world));
525 }
526 /// @brief Return true if the two grids are aligned.
527 inline bool isAligned() const { return mAligned; }
528 private:
529 const AccessorType* mSourceAcc;
530 const math::Transform* mSourceXform;
531 const math::Transform* mTargetXform;
532 const bool mAligned;
533 };//Specialization of DualGridSampler
534
535 //////////////////////////////////////// AlphaMask
536
537
538 // Class to derive the normalized alpha mask
539 template <typename GridT,
540 typename MaskT,
541 typename SamplerT = tools::BoxSampler,
542 typename FloatT = float>
543 class AlphaMask
544 {
545 public:
546 static_assert(std::is_floating_point<FloatT>::value,
547 "AlphaMask requires a floating-point value type");
548 using GridType = GridT;
549 using MaskType = MaskT;
550 using SamlerType = SamplerT;
551 using FloatType = FloatT;
552
553 AlphaMask(const GridT& grid, const MaskT& mask, FloatT min, FloatT max, bool invert)
554 : mAcc(mask.tree())
555 , mSampler(mAcc, mask.transform() , grid.transform())
556 , mMin(min)
557 , mInvNorm(1/(max-min))
558 , mInvert(invert)
559 {
560 assert(min < max);
561 }
562
563 inline bool operator()(const Coord& xyz, FloatT& a, FloatT& b) const
564 {
565 a = math::SmoothUnitStep( (mSampler(xyz) - mMin) * mInvNorm );//smooth mapping to 0->1
566 b = 1 - a;
567 if (mInvert) std::swap(a,b);
568 return a>0;
569 }
570
571 protected:
572 using AccT = typename MaskType::ConstAccessor;
573 AccT mAcc;
574 tools::DualGridSampler<AccT, SamplerT> mSampler;
575 const FloatT mMin, mInvNorm;
576 const bool mInvert;
577 };// AlphaMask
578
579 ////////////////////////////////////////
580
581 namespace local_util {
582
583 inline Vec3i
584 268230279 floorVec3(const Vec3R& v)
585 {
586 268230279 return Vec3i(int(std::floor(v(0))), int(std::floor(v(1))), int(std::floor(v(2))));
587 }
588
589
590 inline Vec3i
591 780 ceilVec3(const Vec3R& v)
592 {
593 780 return Vec3i(int(std::ceil(v(0))), int(std::ceil(v(1))), int(std::ceil(v(2))));
594 }
595
596
597 inline Vec3i
598 79671401 roundVec3(const Vec3R& v)
599 {
600 79671401 return Vec3i(int(::round(v(0))), int(::round(v(1))), int(::round(v(2))));
601 }
602
603 } // namespace local_util
604
605
606 //////////////////////////////////////// PointSampler
607
608
609 template<class TreeT>
610 inline bool
611 159342760 PointSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
612 typename TreeT::ValueType& result)
613 {
614 159342760 return inTree.probeValue(Coord(local_util::roundVec3(inCoord)), result);
615 }
616
617 template<class TreeT>
618 inline typename TreeT::ValueType
619 41 PointSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
620 {
621 41 return inTree.getValue(Coord(local_util::roundVec3(inCoord)));
622 }
623
624
625 //////////////////////////////////////// BoxSampler
626
627 template<class ValueT, class TreeT, size_t N>
628 inline void
629 2870771 BoxSampler::getValues(ValueT (&data)[N][N][N], const TreeT& inTree, Coord ijk)
630 {
631 2870771 data[0][0][0] = inTree.getValue(ijk); // i, j, k
632
633 2870771 ijk[2] += 1;
634 2870771 data[0][0][1] = inTree.getValue(ijk); // i, j, k + 1
635
636 2870771 ijk[1] += 1;
637 2870771 data[0][1][1] = inTree.getValue(ijk); // i, j+1, k + 1
638
639 2870771 ijk[2] -= 1;
640 2870771 data[0][1][0] = inTree.getValue(ijk); // i, j+1, k
641
642 2870771 ijk[0] += 1;
643 2870771 ijk[1] -= 1;
644 2870771 data[1][0][0] = inTree.getValue(ijk); // i+1, j, k
645
646 2870771 ijk[2] += 1;
647 2870771 data[1][0][1] = inTree.getValue(ijk); // i+1, j, k + 1
648
649 2870771 ijk[1] += 1;
650 2870771 data[1][1][1] = inTree.getValue(ijk); // i+1, j+1, k + 1
651
652 2870771 ijk[2] -= 1;
653 2870771 data[1][1][0] = inTree.getValue(ijk); // i+1, j+1, k
654 2870771 }
655
656 template<class ValueT, class TreeT, size_t N>
657 inline bool
658 400531924 BoxSampler::probeValues(ValueT (&data)[N][N][N], const TreeT& inTree, Coord ijk)
659 {
660 bool hasActiveValues = false;
661 400531924 hasActiveValues |= inTree.probeValue(ijk, data[0][0][0]); // i, j, k
662
663 400531924 ijk[2] += 1;
664 400531924 hasActiveValues |= inTree.probeValue(ijk, data[0][0][1]); // i, j, k + 1
665
666 400531924 ijk[1] += 1;
667 400531924 hasActiveValues |= inTree.probeValue(ijk, data[0][1][1]); // i, j+1, k + 1
668
669 400531924 ijk[2] -= 1;
670 400531924 hasActiveValues |= inTree.probeValue(ijk, data[0][1][0]); // i, j+1, k
671
672 400531924 ijk[0] += 1;
673 400531924 ijk[1] -= 1;
674 400531924 hasActiveValues |= inTree.probeValue(ijk, data[1][0][0]); // i+1, j, k
675
676 400531924 ijk[2] += 1;
677 400531924 hasActiveValues |= inTree.probeValue(ijk, data[1][0][1]); // i+1, j, k + 1
678
679 400531924 ijk[1] += 1;
680 400531924 hasActiveValues |= inTree.probeValue(ijk, data[1][1][1]); // i+1, j+1, k + 1
681
682 400531924 ijk[2] -= 1;
683 400531924 hasActiveValues |= inTree.probeValue(ijk, data[1][1][0]); // i+1, j+1, k
684
685 400531924 return hasActiveValues;
686 }
687
688 template<class ValueT, size_t N>
689 inline void
690 652967 BoxSampler::extrema(ValueT (&data)[N][N][N], ValueT& vMin, ValueT &vMax)
691 {
692 652967 vMin = vMax = data[0][0][0];
693
4/4
✓ Branch 0 taken 63987 times.
✓ Branch 1 taken 588980 times.
✓ Branch 2 taken 26138 times.
✓ Branch 3 taken 626829 times.
716954 vMin = math::Min(vMin, data[0][0][1]);
694 652967 vMax = math::Max(vMax, data[0][0][1]);
695
4/4
✓ Branch 0 taken 54846 times.
✓ Branch 1 taken 598121 times.
✓ Branch 2 taken 26138 times.
✓ Branch 3 taken 626829 times.
707813 vMin = math::Min(vMin, data[0][1][0]);
696 652967 vMax = math::Max(vMax, data[0][1][0]);
697
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 652967 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 652967 times.
652967 vMin = math::Min(vMin, data[0][1][1]);
698 652967 vMax = math::Max(vMax, data[0][1][1]);
699
4/4
✓ Branch 0 taken 176940 times.
✓ Branch 1 taken 476027 times.
✓ Branch 2 taken 81732 times.
✓ Branch 3 taken 571235 times.
829907 vMin = math::Min(vMin, data[1][0][0]);
700 652967 vMax = math::Max(vMax, data[1][0][0]);
701
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 652967 times.
✓ Branch 2 taken 11676 times.
✓ Branch 3 taken 641291 times.
652967 vMin = math::Min(vMin, data[1][0][1]);
702 652967 vMax = math::Max(vMax, data[1][0][1]);
703
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 652967 times.
✓ Branch 2 taken 11676 times.
✓ Branch 3 taken 641291 times.
652967 vMin = math::Min(vMin, data[1][1][0]);
704 652967 vMax = math::Max(vMax, data[1][1][0]);
705
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 652967 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 652967 times.
652967 vMin = math::Min(vMin, data[1][1][1]);
706 652967 vMax = math::Max(vMax, data[1][1][1]);
707 652967 }
708
709
710 template<class ValueT, size_t N>
711 inline ValueT
712 404967412 BoxSampler::trilinearInterpolation(ValueT (&data)[N][N][N], const Vec3R& uvw)
713 {
714 708123997 auto _interpolate = [](const ValueT& a, const ValueT& b, double weight)
715 {
716 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
717 279189402 const auto temp = (b - a) * weight;
718 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
719 932352363 return static_cast<ValueT>(a + ValueT(temp));
720 };
721
722 // Trilinear interpolation:
723 // The eight surrounding latice values are used to construct the result. \n
724 // result(x,y,z) =
725 // v000 (1-x)(1-y)(1-z) + v001 (1-x)(1-y)z + v010 (1-x)y(1-z) + v011 (1-x)yz
726 // + v100 x(1-y)(1-z) + v101 x(1-y)z + v110 xy(1-z) + v111 xyz
727
728 125778010 return _interpolate(
729 125778010 _interpolate(
730 125778010 _interpolate(data[0][0][0], data[0][0][1], uvw[2]),
731 125778010 _interpolate(data[0][1][0], data[0][1][1], uvw[2]),
732 uvw[1]),
733 125778010 _interpolate(
734 125778010 _interpolate(data[1][0][0], data[1][0][1], uvw[2]),
735 125778010 _interpolate(data[1][1][0], data[1][1][1], uvw[2]),
736 uvw[1]),
737 404967412 uvw[0]);
738 }
739
740
741 template<class TreeT>
742 inline bool
743 400525470 BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
744 typename TreeT::ValueType& result)
745 {
746 using ValueT = typename TreeT::ValueType;
747
748 400525470 const Vec3i inIdx = local_util::floorVec3(inCoord);
749 const Vec3R uvw = inCoord - inIdx;
750
751 // Retrieve the values of the eight voxels surrounding the
752 // fractional source coordinates.
753
6/6
✓ Branch 0 taken 257269548 times.
✓ Branch 1 taken 128634774 times.
✓ Branch 2 taken 514539096 times.
✓ Branch 3 taken 257269548 times.
✓ Branch 4 taken 1029078192 times.
✓ Branch 5 taken 514539096 times.
2710990590 ValueT data[2][2][2];
754
755 400525470 const bool hasActiveValues = BoxSampler::probeValues(data, inTree, Coord(inIdx));
756
757 400525470 result = BoxSampler::trilinearInterpolation(data, uvw);
758
759 400525470 return hasActiveValues;
760 }
761
762
763 template<class TreeT>
764 inline typename TreeT::ValueType
765 2217804 BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
766 {
767 using ValueT = typename TreeT::ValueType;
768
769 2217804 const Vec3i inIdx = local_util::floorVec3(inCoord);
770 const Vec3R uvw = inCoord - inIdx;
771
772 // Retrieve the values of the eight voxels surrounding the
773 // fractional source coordinates.
774
6/6
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 50 times.
✓ Branch 4 taken 200 times.
✓ Branch 5 taken 100 times.
750 ValueT data[2][2][2];
775
776 2217804 BoxSampler::getValues(data, inTree, Coord(inIdx));
777
778 2217804 return BoxSampler::trilinearInterpolation(data, uvw);
779 }
780
781
782 //////////////////////////////////////// QuadraticSampler
783
784 template<class ValueT, size_t N>
785 inline ValueT
786 27474366 QuadraticSampler::triquadraticInterpolation(ValueT (&data)[N][N][N], const Vec3R& uvw)
787 {
788 741 auto _interpolate = [](const ValueT* value, double weight)
789 {
790 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
791 const ValueT
792 357165276 a = static_cast<ValueT>(0.5 * (value[0] + value[2]) - value[1]),
793 357165276 b = static_cast<ValueT>(0.5 * (value[2] - value[0])),
794 c = static_cast<ValueT>(value[1]);
795 357165276 const auto temp = weight * (weight * a + b) + c;
796 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
797 357164912 return static_cast<ValueT>(temp);
798 };
799
800 /// @todo For vector types, interpolate over each component independently.
801
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 171 times.
456 ValueT vx[3];
802
2/2
✓ Branch 0 taken 82422663 times.
✓ Branch 1 taken 27474221 times.
109897464 for (int dx = 0; dx < 3; ++dx) {
803
2/2
✓ Branch 0 taken 171 times.
✓ Branch 1 taken 513 times.
1368 ValueT vy[3];
804
2/2
✓ Branch 0 taken 247267989 times.
✓ Branch 1 taken 82422663 times.
329692392 for (int dy = 0; dy < 3; ++dy) {
805 // Fit a parabola to three contiguous samples in z
806 // (at z=-1, z=0 and z=1), then evaluate the parabola at z',
807 // where z' is the fractional part of inCoord.z, i.e.,
808 // inCoord.z - inIdx.z. The coefficients come from solving
809 //
810 // | (-1)^2 -1 1 || a | | v0 |
811 // | 0 0 1 || b | = | v1 |
812 // | 1^2 1 1 || c | | v2 |
813 //
814 // for a, b and c.
815 247269294 const ValueT* vz = &data[dx][dy][0];
816 247269294 vy[dy] = _interpolate(vz, uvw.z());
817 }//loop over y
818 // Fit a parabola to three interpolated samples in y, then
819 // evaluate the parabola at y', where y' is the fractional
820 // part of inCoord.y.
821 82423098 vx[dx] = _interpolate(vy, uvw.y());
822 }//loop over x
823 // Fit a parabola to three interpolated samples in x, then
824 // evaluate the parabola at the fractional part of inCoord.x.
825 27474366 return _interpolate(vx, uvw.x());
826 }
827
828 template<class TreeT>
829 inline bool
830 27474201 QuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
831 typename TreeT::ValueType& result)
832 {
833 using ValueT = typename TreeT::ValueType;
834
835 27474201 const Vec3i inIdx = local_util::floorVec3(inCoord), inLoIdx = inIdx - Vec3i(1, 1, 1);
836 const Vec3R uvw = inCoord - inIdx;
837
838 // Retrieve the values of the 27 voxels surrounding the
839 // fractional source coordinates.
840 bool active = false;
841 1680 ValueT data[3][3][3];
842
2/2
✓ Branch 0 taken 82422225 times.
✓ Branch 1 taken 27474075 times.
109896804 for (int dx = 0, ix = inLoIdx.x(); dx < 3; ++dx, ++ix) {
843
2/2
✓ Branch 0 taken 247266675 times.
✓ Branch 1 taken 82422225 times.
329690412 for (int dy = 0, iy = inLoIdx.y(); dy < 3; ++dy, ++iy) {
844
2/2
✓ Branch 0 taken 741800025 times.
✓ Branch 1 taken 247266675 times.
989071236 for (int dz = 0, iz = inLoIdx.z(); dz < 3; ++dz, ++iz) {
845
2/2
✓ Branch 1 taken 2922482 times.
✓ Branch 2 taken 738877543 times.
741803427 if (inTree.probeValue(Coord(ix, iy, iz), data[dx][dy][dz])) active = true;
846 }
847 }
848 }
849
850 27474201 result = QuadraticSampler::triquadraticInterpolation(data, uvw);
851
852 27474201 return active;
853 }
854
855 template<class TreeT>
856 inline typename TreeT::ValueType
857 39 QuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
858 {
859 using ValueT = typename TreeT::ValueType;
860
861 39 const Vec3i inIdx = local_util::floorVec3(inCoord), inLoIdx = inIdx - Vec3i(1, 1, 1);
862 const Vec3R uvw = inCoord - inIdx;
863
864 // Retrieve the values of the 27 voxels surrounding the
865 // fractional source coordinates.
866
6/6
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 135 times.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 405 times.
✓ Branch 5 taken 135 times.
1200 ValueT data[3][3][3];
867
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 20 times.
156 for (int dx = 0, ix = inLoIdx.x(); dx < 3; ++dx, ++ix) {
868
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 60 times.
468 for (int dy = 0, iy = inLoIdx.y(); dy < 3; ++dy, ++iy) {
869
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 180 times.
1404 for (int dz = 0, iz = inLoIdx.z(); dz < 3; ++dz, ++iz) {
870 1053 data[dx][dy][dz] = inTree.getValue(Coord(ix, iy, iz));
871 }
872 }
873 }
874
875 39 return QuadraticSampler::triquadraticInterpolation(data, uvw);
876 }
877
878
879 //////////////////////////////////////// StaggeredPointSampler
880
881
882 template<class TreeT>
883 inline bool
884 StaggeredPointSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
885 typename TreeT::ValueType& result)
886 {
887 using ValueType = typename TreeT::ValueType;
888
889 ValueType tempX, tempY, tempZ;
890 bool active = false;
891
892 active = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0, 0), tempX) || active;
893 active = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0.5, 0), tempY) || active;
894 active = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0, 0.5), tempZ) || active;
895
896 result.x() = tempX.x();
897 result.y() = tempY.y();
898 result.z() = tempZ.z();
899
900 return active;
901 }
902
903 template<class TreeT>
904 inline typename TreeT::ValueType
905 10 StaggeredPointSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
906 {
907 using ValueT = typename TreeT::ValueType;
908
909 10 const ValueT tempX = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0.0, 0.0));
910 10 const ValueT tempY = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.0, 0.5, 0.0));
911 10 const ValueT tempZ = PointSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.0, 0.0, 0.5));
912
913 10 return ValueT(tempX.x(), tempY.y(), tempZ.z());
914 }
915
916
917 //////////////////////////////////////// StaggeredBoxSampler
918
919
920 template<class TreeT>
921 inline bool
922 40 StaggeredBoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
923 typename TreeT::ValueType& result)
924 {
925 using ValueType = typename TreeT::ValueType;
926
927 ValueType tempX, tempY, tempZ;
928 40 tempX = tempY = tempZ = zeroVal<ValueType>();
929 bool active = false;
930
931
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
80 active = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0, 0), tempX) || active;
932
2/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
80 active = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0.5, 0), tempY) || active;
933
2/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
40 active = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0, 0.5), tempZ) || active;
934
935 40 result.x() = tempX.x();
936 40 result.y() = tempY.y();
937 40 result.z() = tempZ.z();
938
939 40 return active;
940 }
941
942 template<class TreeT>
943 inline typename TreeT::ValueType
944 10 StaggeredBoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
945 {
946 using ValueT = typename TreeT::ValueType;
947
948 10 const ValueT tempX = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0.0, 0.0));
949 10 const ValueT tempY = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.0, 0.5, 0.0));
950 10 const ValueT tempZ = BoxSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.0, 0.0, 0.5));
951
952 10 return ValueT(tempX.x(), tempY.y(), tempZ.z());
953 }
954
955
956 //////////////////////////////////////// StaggeredQuadraticSampler
957
958
959 template<class TreeT>
960 inline bool
961 StaggeredQuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
962 typename TreeT::ValueType& result)
963 {
964 using ValueType = typename TreeT::ValueType;
965
966 ValueType tempX, tempY, tempZ;
967 bool active = false;
968
969 active = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0, 0), tempX) || active;
970 active = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0.5, 0), tempY) || active;
971 active = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0, 0, 0.5), tempZ) || active;
972
973 result.x() = tempX.x();
974 result.y() = tempY.y();
975 result.z() = tempZ.z();
976
977 return active;
978 }
979
980 template<class TreeT>
981 inline typename TreeT::ValueType
982 5 StaggeredQuadraticSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
983 {
984 using ValueT = typename TreeT::ValueType;
985
986 5 const ValueT tempX = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.5, 0.0, 0.0));
987 5 const ValueT tempY = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.0, 0.5, 0.0));
988 5 const ValueT tempZ = QuadraticSampler::sample<TreeT>(inTree, inCoord + Vec3R(0.0, 0.0, 0.5));
989
990 5 return ValueT(tempX.x(), tempY.y(), tempZ.z());
991 }
992
993 //////////////////////////////////////// Sampler
994
995 template <>
996 struct Sampler<0, false> : public PointSampler {};
997
998 template <>
999 struct Sampler<1, false> : public BoxSampler {};
1000
1001 template <>
1002 struct Sampler<2, false> : public QuadraticSampler {};
1003
1004 template <>
1005 struct Sampler<0, true> : public StaggeredPointSampler {};
1006
1007 template <>
1008 struct Sampler<1, true> : public StaggeredBoxSampler {};
1009
1010 template <>
1011 struct Sampler<2, true> : public StaggeredQuadraticSampler {};
1012
1013 } // namespace tools
1014 } // namespace OPENVDB_VERSION_NAME
1015 } // namespace openvdb
1016
1017 #endif // OPENVDB_TOOLS_INTERPOLATION_HAS_BEEN_INCLUDED
1018