GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/math/Stencils.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 530 567 93.5%
Functions: 97 146 66.4%
Branches: 209 1067 19.6%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
4 /// @author Ken Museth
5 ///
6 /// @file Stencils.h
7 ///
8 /// @brief Defines various finite difference stencils by means of the
9 /// "curiously recurring template pattern" on a BaseStencil
10 /// that caches stencil values and stores a ValueAccessor for
11 /// fast lookup.
12
13 #ifndef OPENVDB_MATH_STENCILS_HAS_BEEN_INCLUDED
14 #define OPENVDB_MATH_STENCILS_HAS_BEEN_INCLUDED
15
16 #include <algorithm>
17 #include <vector> // for std::vector
18 #include <bitset> // for std::bitset
19 #include <openvdb/math/Math.h> // for Pow2, needed by WENO and Godunov
20 #include <openvdb/Types.h> // for Real
21 #include <openvdb/math/Coord.h> // for Coord
22 #include <openvdb/math/FiniteDifference.h> // for WENO5 and GodunovsNormSqrd
23 #include <openvdb/tree/ValueAccessor.h>
24
25 namespace openvdb {
26 OPENVDB_USE_VERSION_NAMESPACE
27 namespace OPENVDB_VERSION_NAME {
28 namespace math {
29
30
31 ////////////////////////////////////////
32
33 template<typename DerivedType, typename GridT, bool IsSafe>
34 class BaseStencil
35 {
36 public:
37 typedef GridT GridType;
38 typedef typename GridT::TreeType TreeType;
39 typedef typename GridT::ValueType ValueType;
40 typedef tree::ValueAccessor<const TreeType, IsSafe> AccessorType;
41 typedef std::vector<ValueType> BufferType;
42 typedef typename BufferType::iterator IterType;
43
44 /// @brief Initialize the stencil buffer with the values of voxel (i, j, k)
45 /// and its neighbors.
46 /// @param ijk Index coordinates of stencil center
47 1608148 inline void moveTo(const Coord& ijk)
48 {
49 1608148 mCenter = ijk;
50 1608148 mValues[0] = mAcc.getValue(ijk);
51 1608148 static_cast<DerivedType&>(*this).init(mCenter);
52 1608148 }
53
54 /// @brief Initialize the stencil buffer with the values of voxel (i, j, k)
55 /// and its neighbors. The method also takes a value of the center
56 /// element of the stencil, assuming it is already known.
57 /// @param ijk Index coordinates of stnecil center
58 /// @param centerValue Value of the center element of the stencil
59 inline void moveTo(const Coord& ijk, const ValueType& centerValue)
60 {
61
5/120
✓ Branch 1 taken 219027 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 219027 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 753990 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 753990 times.
✗ 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 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✓ Branch 88 taken 23463 times.
✗ Branch 89 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
1969497 mCenter = ijk;
62 1969497 mValues[0] = centerValue;
63
5/120
✓ Branch 1 taken 219027 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 219027 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 753990 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 753990 times.
✗ 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 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✓ Branch 88 taken 23463 times.
✗ Branch 89 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
1969497 static_cast<DerivedType&>(*this).init(mCenter);
64 1969497 }
65
66 /// @brief Initialize the stencil buffer with the values of voxel
67 /// (x, y, z) and its neighbors.
68 ///
69 /// @note This version is slightly faster than the one above, since
70 /// the center voxel's value is read directly from the iterator.
71 template<typename IterType>
72 29262568 inline void moveTo(const IterType& iter)
73 {
74 29262568 mCenter = iter.getCoord();
75 29262568 mValues[0] = *iter;
76 29262568 static_cast<DerivedType&>(*this).init(mCenter);
77 29262568 }
78
79 /// @brief Initialize the stencil buffer with the values of voxel (x, y, z)
80 /// and its neighbors.
81 /// @param xyz Floating point voxel coordinates of stencil center
82 /// @details This method will check to see if it is necessary to
83 /// update the stencil based on the cached index coordinates of
84 /// the center point.
85 template<typename RealType>
86 1934820 inline void moveTo(const Vec3<RealType>& xyz)
87 {
88 1934820 Coord ijk = Coord::floor(xyz);
89 1498800 if (ijk != mCenter) this->moveTo(ijk);
90 1934820 }
91
92 /// @brief Return the value from the stencil buffer with linear
93 /// offset pos.
94 ///
95 /// @note The default (@a pos = 0) corresponds to the first element
96 /// which is typically the center point of the stencil.
97 930180 inline const ValueType& getValue(unsigned int pos = 0) const
98 {
99
8/480
✗ Branch 0 not taken.
✓ Branch 1 taken 930181 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 867441 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 867441 times.
✗ 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 taken 221020 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 221020 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 221020 times.
✗ 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 taken 58599 times.
✗ 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.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 237 not taken.
✗ Branch 238 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 252 not taken.
✗ Branch 253 not taken.
✗ Branch 255 not taken.
✗ Branch 256 not taken.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✗ Branch 261 not taken.
✗ Branch 262 not taken.
✗ Branch 264 not taken.
✗ Branch 265 not taken.
✗ Branch 267 not taken.
✗ Branch 268 not taken.
✗ Branch 270 not taken.
✗ Branch 271 not taken.
✗ Branch 273 not taken.
✗ Branch 274 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 291 not taken.
✗ Branch 292 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 297 not taken.
✗ Branch 298 not taken.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 306 not taken.
✗ Branch 307 not taken.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 315 not taken.
✗ Branch 316 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✗ Branch 327 not taken.
✗ Branch 328 not taken.
✗ Branch 330 not taken.
✗ Branch 331 not taken.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✗ Branch 336 not taken.
✗ Branch 337 not taken.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 342 not taken.
✗ Branch 343 not taken.
✗ Branch 345 not taken.
✗ Branch 346 not taken.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 357 not taken.
✗ Branch 358 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 366 not taken.
✗ Branch 367 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 372 not taken.
✗ Branch 373 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 381 not taken.
✗ Branch 382 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 387 not taken.
✗ Branch 388 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 396 not taken.
✗ Branch 397 not taken.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 402 not taken.
✗ Branch 403 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✗ Branch 408 not taken.
✗ Branch 409 not taken.
✗ Branch 411 not taken.
✗ Branch 412 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 417 not taken.
✗ Branch 418 not taken.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 441 not taken.
✗ Branch 442 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 456 not taken.
✗ Branch 457 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 462 not taken.
✗ Branch 463 not taken.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✗ Branch 468 not taken.
✗ Branch 469 not taken.
✗ Branch 471 not taken.
✗ Branch 472 not taken.
✗ Branch 474 not taken.
✗ Branch 475 not taken.
✗ Branch 477 not taken.
✗ Branch 478 not taken.
✗ Branch 480 not taken.
✗ Branch 481 not taken.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 486 not taken.
✗ Branch 487 not taken.
✗ Branch 489 not taken.
✗ Branch 490 not taken.
✗ Branch 492 not taken.
✗ Branch 493 not taken.
✗ Branch 495 not taken.
✗ Branch 496 not taken.
✗ Branch 498 not taken.
✗ Branch 499 not taken.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 504 not taken.
✗ Branch 505 not taken.
✗ Branch 507 not taken.
✗ Branch 508 not taken.
✗ Branch 510 not taken.
✗ Branch 511 not taken.
✗ Branch 513 not taken.
✗ Branch 514 not taken.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✗ Branch 519 not taken.
✗ Branch 520 not taken.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✗ Branch 528 not taken.
✗ Branch 529 not taken.
✗ Branch 531 not taken.
✗ Branch 532 not taken.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✗ Branch 537 not taken.
✗ Branch 538 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 561 not taken.
✗ Branch 562 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 567 not taken.
✗ Branch 568 not taken.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 576 not taken.
✗ Branch 577 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 597 not taken.
✗ Branch 598 not taken.
✗ Branch 600 not taken.
✗ Branch 601 not taken.
✗ Branch 603 not taken.
✗ Branch 604 not taken.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 615 not taken.
✗ Branch 616 not taken.
✗ Branch 618 not taken.
✗ Branch 619 not taken.
✗ Branch 621 not taken.
✗ Branch 622 not taken.
✗ Branch 624 not taken.
✗ Branch 625 not taken.
✗ Branch 627 not taken.
✗ Branch 628 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 678 not taken.
✗ Branch 679 not taken.
✗ Branch 681 not taken.
✗ Branch 682 not taken.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 687 not taken.
✗ Branch 688 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 696 not taken.
✗ Branch 697 not taken.
✗ Branch 699 not taken.
✗ Branch 700 not taken.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 705 not taken.
✗ Branch 706 not taken.
✗ Branch 708 not taken.
✗ Branch 709 not taken.
✗ Branch 711 not taken.
✗ Branch 712 not taken.
✗ Branch 714 not taken.
✗ Branch 715 not taken.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
3386723 assert(pos < mValues.size());
100 930180 return mValues[pos];
101 }
102
103 /// @brief Return the value at the specified location relative to the center of the stencil
104 template<int i, int j, int k>
105 inline const ValueType& getValue() const
106 {
107 return mValues[static_cast<const DerivedType&>(*this).template pos<i,j,k>()];
108 }
109
110 /// @brief Set the value at the specified location relative to the center of the stencil
111 template<int i, int j, int k>
112 inline void setValue(const ValueType& value)
113 {
114 37310668 mValues[static_cast<const DerivedType&>(*this).template pos<i,j,k>()] = value;
115 }
116
117 /// @brief Return the size of the stencil buffer.
118 inline int size() { return mValues.size(); }
119
120 /// @brief Return the median value of the current stencil.
121 1580216 inline ValueType median() const
122 {
123 1580216 BufferType tmp(mValues);//local copy
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1580216 times.
1580216 assert(!tmp.empty());
125 1580216 size_t midpoint = (tmp.size() - 1) >> 1;
126 // Partially sort the vector until the median value is at the midpoint.
127 #if !defined(_MSC_VER) || _MSC_VER < 1924
128 1580216 std::nth_element(tmp.begin(), tmp.begin() + midpoint, tmp.end());
129 #else
130 // Workaround MSVC bool warning C4804 unsafe use of type 'bool'
131 std::nth_element(tmp.begin(), tmp.begin() + midpoint, tmp.end(),
132 std::less<ValueType>());
133 #endif
134
1/2
✓ Branch 0 taken 1580216 times.
✗ Branch 1 not taken.
1580216 return tmp[midpoint];
135 }
136
137 /// @brief Return the mean value of the current stencil.
138 inline ValueType mean() const
139 {
140 ValueType sum = 0.0;
141
6/6
✓ Branch 0 taken 18777960 times.
✓ Branch 1 taken 695480 times.
✓ Branch 2 taken 8000000 times.
✓ Branch 3 taken 64000 times.
✓ Branch 4 taken 8000000 times.
✓ Branch 5 taken 64000 times.
35601440 for (int n = 0, s = int(mValues.size()); n < s; ++n) sum += mValues[n];
142
2/4
✓ Branch 2 taken 64000 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 64000 times.
✗ Branch 6 not taken.
823480 return sum / ValueType(mValues.size());
143 }
144
145 /// @brief Return the smallest value in the stencil buffer.
146 inline ValueType min() const
147 {
148 IterType iter = std::min_element(mValues.begin(), mValues.end());
149 return *iter;
150 }
151
152 /// @brief Return the largest value in the stencil buffer.
153 inline ValueType max() const
154 {
155 IterType iter = std::max_element(mValues.begin(), mValues.end());
156 return *iter;
157 }
158
159 /// @brief Return the coordinates of the center point of the stencil.
160 inline const Coord& getCenterCoord() const { return mCenter; }
161
162 /// @brief Return the value at the center of the stencil
163 inline const ValueType& getCenterValue() const { return mValues[0]; }
164
165 /// @brief Return true if the center of the stencil intersects the
166 /// iso-contour specified by the isoValue
167
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 66 times.
140 inline bool intersects(const ValueType &isoValue = zeroVal<ValueType>()) const
168 {
169 140 const bool less = this->getValue< 0, 0, 0>() < isoValue;
170 214 return (less ^ (this->getValue<-1, 0, 0>() < isoValue)) ||
171
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 34 times.
74 (less ^ (this->getValue< 1, 0, 0>() < isoValue)) ||
172
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 17 times.
40 (less ^ (this->getValue< 0,-1, 0>() < isoValue)) ||
173
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 10 times.
23 (less ^ (this->getValue< 0, 1, 0>() < isoValue)) ||
174
4/4
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 5 times.
153 (less ^ (this->getValue< 0, 0,-1>() < isoValue)) ||
175
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
8 (less ^ (this->getValue< 0, 0, 1>() < isoValue)) ;
176 }
177
178 /// @brief Return true a bit-mask where the 6 bits indicates if the
179 /// center of the stencil intersects the iso-contour specified by the isoValue.
180 ///
181 /// @note There are 2^6 = 64 different possible cases, including no intersections!
182 ///
183 /// @details The ordering of bit mask is ( -x, +x, -y, +y, -z, +z ), so to
184 /// check if there is an intersection in -y use mask.test(2) where mask is
185 /// ther return value from this function. To check if there are any
186 /// intersections use mask.any(), and for no intersections use mask.none().
187 /// To count the number of intersections use mask.count().
188 3892260 inline std::bitset<6> intersectionMask(const ValueType &isoValue = zeroVal<ValueType>()) const
189 {
190
2/2
✓ Branch 0 taken 155224 times.
✓ Branch 1 taken 1790938 times.
3892260 std::bitset<6> mask;
191 3892260 const bool less = this->getValue< 0, 0, 0>() < isoValue;
192
2/2
✓ Branch 0 taken 155224 times.
✓ Branch 1 taken 1790938 times.
3892260 mask[0] = less ^ (this->getValue<-1, 0, 0>() < isoValue);
193
2/2
✓ Branch 0 taken 155224 times.
✓ Branch 1 taken 1790938 times.
3892260 mask[1] = less ^ (this->getValue< 1, 0, 0>() < isoValue);
194
2/2
✓ Branch 0 taken 155224 times.
✓ Branch 1 taken 1790938 times.
3892260 mask[2] = less ^ (this->getValue< 0,-1, 0>() < isoValue);
195
2/2
✓ Branch 0 taken 155224 times.
✓ Branch 1 taken 1790938 times.
3892260 mask[3] = less ^ (this->getValue< 0, 1, 0>() < isoValue);
196
2/2
✓ Branch 0 taken 155224 times.
✓ Branch 1 taken 1790938 times.
3892260 mask[4] = less ^ (this->getValue< 0, 0,-1>() < isoValue);
197
2/2
✓ Branch 0 taken 155224 times.
✓ Branch 1 taken 1790938 times.
3892260 mask[5] = less ^ (this->getValue< 0, 0, 1>() < isoValue);
198 3892260 return mask;
199 }
200
201 /// @brief Return a const reference to the grid from which this
202 /// stencil was constructed.
203 1460326 inline const GridType& grid() const { return *mGrid; }
204
205 /// @brief Return a const reference to the ValueAccessor
206 /// associated with this Stencil.
207 inline const AccessorType& accessor() const { return mAcc; }
208
209 protected:
210 // Constructor is protected to prevent direct instantiation.
211 34041 BaseStencil(const GridType& grid, int size)
212 : mGrid(&grid)
213 , mAcc(grid.tree())
214 , mValues(size)
215
1/4
✓ Branch 2 taken 16140 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
34041 , mCenter(Coord::max())
216 {
217 34041 }
218
219 const GridType* mGrid;
220 AccessorType mAcc;
221 BufferType mValues;
222 Coord mCenter;
223
224 }; // BaseStencil class
225
226
227 ////////////////////////////////////////
228
229
230 namespace { // anonymous namespace for stencil-layout map
231
232 // the seven point stencil
233 template<int i, int j, int k> struct SevenPt {};
234 template<> struct SevenPt< 0, 0, 0> { enum { idx = 0 }; };
235 template<> struct SevenPt< 1, 0, 0> { enum { idx = 1 }; };
236 template<> struct SevenPt< 0, 1, 0> { enum { idx = 2 }; };
237 template<> struct SevenPt< 0, 0, 1> { enum { idx = 3 }; };
238 template<> struct SevenPt<-1, 0, 0> { enum { idx = 4 }; };
239 template<> struct SevenPt< 0,-1, 0> { enum { idx = 5 }; };
240 template<> struct SevenPt< 0, 0,-1> { enum { idx = 6 }; };
241
242 }
243
244
245 template<typename GridT, bool IsSafe = true>
246
4/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
900 class SevenPointStencil: public BaseStencil<SevenPointStencil<GridT, IsSafe>, GridT, IsSafe>
247 {
248 typedef SevenPointStencil<GridT, IsSafe> SelfT;
249 typedef BaseStencil<SelfT, GridT, IsSafe> BaseType;
250 public:
251 typedef GridT GridType;
252 typedef typename GridT::TreeType TreeType;
253 typedef typename GridT::ValueType ValueType;
254
255 static const int SIZE = 7;
256
257
10/20
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 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.
900 SevenPointStencil(const GridT& grid): BaseType(grid, SIZE) {}
258
259 /// Return linear offset for the specified stencil point relative to its center
260 template<int i, int j, int k>
261 unsigned int pos() const { return SevenPt<i,j,k>::idx; }
262
263 private:
264 81946 inline void init(const Coord& ijk)
265 {
266 81946 BaseType::template setValue<-1, 0, 0>(mAcc.getValue(ijk.offsetBy(-1, 0, 0)));
267 81946 BaseType::template setValue< 1, 0, 0>(mAcc.getValue(ijk.offsetBy( 1, 0, 0)));
268
269 81946 BaseType::template setValue< 0,-1, 0>(mAcc.getValue(ijk.offsetBy( 0,-1, 0)));
270 81946 BaseType::template setValue< 0, 1, 0>(mAcc.getValue(ijk.offsetBy( 0, 1, 0)));
271
272 81946 BaseType::template setValue< 0, 0,-1>(mAcc.getValue(ijk.offsetBy( 0, 0,-1)));
273 81946 BaseType::template setValue< 0, 0, 1>(mAcc.getValue(ijk.offsetBy( 0, 0, 1)));
274 81946 }
275
276 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
277 using BaseType::mAcc;
278 using BaseType::mValues;
279 };// SevenPointStencil class
280
281
282 ////////////////////////////////////////
283
284
285 namespace { // anonymous namespace for stencil-layout map
286
287 // the eight point box stencil
288 template<int i, int j, int k> struct BoxPt {};
289 template<> struct BoxPt< 0, 0, 0> { enum { idx = 0 }; };
290 template<> struct BoxPt< 0, 0, 1> { enum { idx = 1 }; };
291 template<> struct BoxPt< 0, 1, 1> { enum { idx = 2 }; };
292 template<> struct BoxPt< 0, 1, 0> { enum { idx = 3 }; };
293 template<> struct BoxPt< 1, 0, 0> { enum { idx = 4 }; };
294 template<> struct BoxPt< 1, 0, 1> { enum { idx = 5 }; };
295 template<> struct BoxPt< 1, 1, 1> { enum { idx = 6 }; };
296 template<> struct BoxPt< 1, 1, 0> { enum { idx = 7 }; };
297 }
298
299 template<typename GridT, bool IsSafe = true>
300 11 class BoxStencil: public BaseStencil<BoxStencil<GridT, IsSafe>, GridT, IsSafe>
301 {
302 typedef BoxStencil<GridT, IsSafe> SelfT;
303 typedef BaseStencil<SelfT, GridT, IsSafe> BaseType;
304 public:
305 typedef GridT GridType;
306 typedef typename GridT::TreeType TreeType;
307 typedef typename GridT::ValueType ValueType;
308
309 static const int SIZE = 8;
310
311
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
11 BoxStencil(const GridType& grid): BaseType(grid, SIZE) {}
312
313 /// Return linear offset for the specified stencil point relative to its center
314 template<int i, int j, int k>
315 unsigned int pos() const { return BoxPt<i,j,k>::idx; }
316
317 /// @brief Return true if the center of the stencil intersects the
318 /// iso-contour specified by the isoValue
319 inline bool intersects(const ValueType &isoValue = zeroVal<ValueType>()) const
320 {
321 const bool less = mValues[0] < isoValue;
322 return (less ^ (mValues[1] < isoValue)) ||
323 (less ^ (mValues[2] < isoValue)) ||
324 (less ^ (mValues[3] < isoValue)) ||
325 (less ^ (mValues[4] < isoValue)) ||
326 (less ^ (mValues[5] < isoValue)) ||
327 (less ^ (mValues[6] < isoValue)) ||
328 (less ^ (mValues[7] < isoValue)) ;
329 }
330
331 /// @brief Return the trilinear interpolation at the normalized position.
332 /// @param xyz Floating point coordinate position.
333 /// @warning It is assumed that the stencil has already been moved
334 /// to the relevant voxel position, e.g. using moveTo(xyz).
335 /// @note Trilinear interpolation kernal reads as:
336 /// v000 (1-u)(1-v)(1-w) + v001 (1-u)(1-v)w + v010 (1-u)v(1-w) + v011 (1-u)vw
337 /// + v100 u(1-v)(1-w) + v101 u(1-v)w + v110 uv(1-w) + v111 uvw
338
1/2
✓ Branch 0 taken 1934818 times.
✗ Branch 1 not taken.
1934820 inline ValueType interpolation(const math::Vec3<ValueType>& xyz) const
339 {
340 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
341 1934820 const ValueType u = xyz[0] - BaseType::mCenter[0];
342 1934820 const ValueType v = xyz[1] - BaseType::mCenter[1];
343 1934820 const ValueType w = xyz[2] - BaseType::mCenter[2];
344 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
345
346
2/4
✓ Branch 0 taken 1934818 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1934818 times.
1934820 assert(u>=0 && u<=1);
347
2/4
✓ Branch 0 taken 1934818 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1934818 times.
1934820 assert(v>=0 && v<=1);
348
2/4
✓ Branch 0 taken 1934818 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1934818 times.
1934820 assert(w>=0 && w<=1);
349
350 1934820 ValueType V = BaseType::template getValue<0,0,0>();
351 1934820 ValueType A = static_cast<ValueType>(V + (BaseType::template getValue<0,0,1>() - V) * w);
352 1934820 V = BaseType::template getValue< 0, 1, 0>();
353 1934820 ValueType B = static_cast<ValueType>(V + (BaseType::template getValue<0,1,1>() - V) * w);
354 1934820 ValueType C = static_cast<ValueType>(A + (B - A) * v);
355
356 1934820 V = BaseType::template getValue<1,0,0>();
357 1934820 A = static_cast<ValueType>(V + (BaseType::template getValue<1,0,1>() - V) * w);
358 1934820 V = BaseType::template getValue<1,1,0>();
359 1934820 B = static_cast<ValueType>(V + (BaseType::template getValue<1,1,1>() - V) * w);
360 1934820 ValueType D = static_cast<ValueType>(A + (B - A) * v);
361
362 1934820 return static_cast<ValueType>(C + (D - C) * u);
363 }
364
365 /// @brief Return the gradient in world space of the trilinear interpolation kernel.
366 /// @param xyz Floating point coordinate position.
367 /// @warning It is assumed that the stencil has already been moved
368 /// to the relevant voxel position, e.g. using moveTo(xyz).
369 /// @note Computed as partial derivatives of the trilinear interpolation kernel:
370 /// v000 (1-u)(1-v)(1-w) + v001 (1-u)(1-v)w + v010 (1-u)v(1-w) + v011 (1-u)vw
371 /// + v100 u(1-v)(1-w) + v101 u(1-v)w + v110 uv(1-w) + v111 uvw
372 inline math::Vec3<ValueType> gradient(const math::Vec3<ValueType>& xyz) const
373 {
374 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
375 const ValueType u = xyz[0] - BaseType::mCenter[0];
376 const ValueType v = xyz[1] - BaseType::mCenter[1];
377 const ValueType w = xyz[2] - BaseType::mCenter[2];
378 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
379
380 assert(u>=0 && u<=1);
381 assert(v>=0 && v<=1);
382 assert(w>=0 && w<=1);
383
384 ValueType D[4]={BaseType::template getValue<0,0,1>()-BaseType::template getValue<0,0,0>(),
385 BaseType::template getValue<0,1,1>()-BaseType::template getValue<0,1,0>(),
386 BaseType::template getValue<1,0,1>()-BaseType::template getValue<1,0,0>(),
387 BaseType::template getValue<1,1,1>()-BaseType::template getValue<1,1,0>()};
388
389 // Z component
390 ValueType A = static_cast<ValueType>(D[0] + (D[1]- D[0]) * v);
391 ValueType B = static_cast<ValueType>(D[2] + (D[3]- D[2]) * v);
392 math::Vec3<ValueType> grad(zeroVal<ValueType>(),
393 zeroVal<ValueType>(),
394 static_cast<ValueType>(A + (B - A) * u));
395
396 D[0] = static_cast<ValueType>(BaseType::template getValue<0,0,0>() + D[0] * w);
397 D[1] = static_cast<ValueType>(BaseType::template getValue<0,1,0>() + D[1] * w);
398 D[2] = static_cast<ValueType>(BaseType::template getValue<1,0,0>() + D[2] * w);
399 D[3] = static_cast<ValueType>(BaseType::template getValue<1,1,0>() + D[3] * w);
400
401 // X component
402 A = static_cast<ValueType>(D[0] + (D[1] - D[0]) * v);
403 B = static_cast<ValueType>(D[2] + (D[3] - D[2]) * v);
404
405 grad[0] = B - A;
406
407 // Y component
408 A = D[1] - D[0];
409 B = D[3] - D[2];
410
411 grad[1] = static_cast<ValueType>(A + (B - A) * u);
412
413 return BaseType::mGrid->transform().baseMap()->applyIJT(grad, xyz);
414 }
415
416 private:
417 1498800 inline void init(const Coord& ijk)
418 {
419 1498800 BaseType::template setValue< 0, 0, 1>(mAcc.getValue(ijk.offsetBy( 0, 0, 1)));
420 1498800 BaseType::template setValue< 0, 1, 1>(mAcc.getValue(ijk.offsetBy( 0, 1, 1)));
421 1498800 BaseType::template setValue< 0, 1, 0>(mAcc.getValue(ijk.offsetBy( 0, 1, 0)));
422 1498800 BaseType::template setValue< 1, 0, 0>(mAcc.getValue(ijk.offsetBy( 1, 0, 0)));
423 1498800 BaseType::template setValue< 1, 0, 1>(mAcc.getValue(ijk.offsetBy( 1, 0, 1)));
424 1498800 BaseType::template setValue< 1, 1, 1>(mAcc.getValue(ijk.offsetBy( 1, 1, 1)));
425 1498800 BaseType::template setValue< 1, 1, 0>(mAcc.getValue(ijk.offsetBy( 1, 1, 0)));
426 1498800 }
427
428 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
429 using BaseType::mAcc;
430 using BaseType::mValues;
431 };// BoxStencil class
432
433
434 ////////////////////////////////////////
435
436
437 namespace { // anonymous namespace for stencil-layout map
438
439 // the dense point stencil
440 template<int i, int j, int k> struct DensePt {};
441 template<> struct DensePt< 0, 0, 0> { enum { idx = 0 }; };
442
443 template<> struct DensePt< 1, 0, 0> { enum { idx = 1 }; };
444 template<> struct DensePt< 0, 1, 0> { enum { idx = 2 }; };
445 template<> struct DensePt< 0, 0, 1> { enum { idx = 3 }; };
446
447 template<> struct DensePt<-1, 0, 0> { enum { idx = 4 }; };
448 template<> struct DensePt< 0,-1, 0> { enum { idx = 5 }; };
449 template<> struct DensePt< 0, 0,-1> { enum { idx = 6 }; };
450
451 template<> struct DensePt<-1,-1, 0> { enum { idx = 7 }; };
452 template<> struct DensePt< 0,-1,-1> { enum { idx = 8 }; };
453 template<> struct DensePt<-1, 0,-1> { enum { idx = 9 }; };
454
455 template<> struct DensePt< 1,-1, 0> { enum { idx = 10 }; };
456 template<> struct DensePt< 0, 1,-1> { enum { idx = 11 }; };
457 template<> struct DensePt<-1, 0, 1> { enum { idx = 12 }; };
458
459 template<> struct DensePt<-1, 1, 0> { enum { idx = 13 }; };
460 template<> struct DensePt< 0,-1, 1> { enum { idx = 14 }; };
461 template<> struct DensePt< 1, 0,-1> { enum { idx = 15 }; };
462
463 template<> struct DensePt< 1, 1, 0> { enum { idx = 16 }; };
464 template<> struct DensePt< 0, 1, 1> { enum { idx = 17 }; };
465 template<> struct DensePt< 1, 0, 1> { enum { idx = 18 }; };
466 }
467
468
469 template<typename GridT, bool IsSafe = true>
470
14/28
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 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 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 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 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 1 times.
✗ Branch 39 not taken.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
23 class SecondOrderDenseStencil
471 : public BaseStencil<SecondOrderDenseStencil<GridT, IsSafe>, GridT, IsSafe >
472 {
473 typedef SecondOrderDenseStencil<GridT, IsSafe> SelfT;
474 typedef BaseStencil<SelfT, GridT, IsSafe > BaseType;
475 public:
476 typedef GridT GridType;
477 typedef typename GridT::TreeType TreeType;
478 typedef typename GridType::ValueType ValueType;
479
480 static const int SIZE = 19;
481
482
5/10
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 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.
13 SecondOrderDenseStencil(const GridType& grid): BaseType(grid, SIZE) {}
483
484 /// Return linear offset for the specified stencil point relative to its center
485 template<int i, int j, int k>
486 unsigned int pos() const { return DensePt<i,j,k>::idx; }
487
488 private:
489 17513 inline void init(const Coord& ijk)
490 {
491 17513 mValues[DensePt< 1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 0));
492 17513 mValues[DensePt< 0, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 0));
493 17513 mValues[DensePt< 0, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 1));
494
495 17513 mValues[DensePt<-1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 0));
496 17513 mValues[DensePt< 0,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, -1, 0));
497 17513 mValues[DensePt< 0, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, -1));
498
499 17513 mValues[DensePt<-1,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, -1, 0));
500 17513 mValues[DensePt< 1,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, -1, 0));
501 17513 mValues[DensePt<-1, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 1, 0));
502 17513 mValues[DensePt< 1, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 1, 0));
503
504 17513 mValues[DensePt<-1, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, -1));
505 17513 mValues[DensePt< 1, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, -1));
506 17513 mValues[DensePt<-1, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 1));
507 17513 mValues[DensePt< 1, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 1));
508
509 17513 mValues[DensePt< 0,-1,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, -1, -1));
510 17513 mValues[DensePt< 0, 1,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, -1));
511 17513 mValues[DensePt< 0,-1, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, -1, 1));
512 17513 mValues[DensePt< 0, 1, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 1));
513 17513 }
514
515 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
516 using BaseType::mAcc;
517 using BaseType::mValues;
518 };// SecondOrderDenseStencil class
519
520
521 ////////////////////////////////////////
522
523
524 namespace { // anonymous namespace for stencil-layout map
525
526 // the dense point stencil
527 template<int i, int j, int k> struct ThirteenPt {};
528 template<> struct ThirteenPt< 0, 0, 0> { enum { idx = 0 }; };
529
530 template<> struct ThirteenPt< 1, 0, 0> { enum { idx = 1 }; };
531 template<> struct ThirteenPt< 0, 1, 0> { enum { idx = 2 }; };
532 template<> struct ThirteenPt< 0, 0, 1> { enum { idx = 3 }; };
533
534 template<> struct ThirteenPt<-1, 0, 0> { enum { idx = 4 }; };
535 template<> struct ThirteenPt< 0,-1, 0> { enum { idx = 5 }; };
536 template<> struct ThirteenPt< 0, 0,-1> { enum { idx = 6 }; };
537
538 template<> struct ThirteenPt< 2, 0, 0> { enum { idx = 7 }; };
539 template<> struct ThirteenPt< 0, 2, 0> { enum { idx = 8 }; };
540 template<> struct ThirteenPt< 0, 0, 2> { enum { idx = 9 }; };
541
542 template<> struct ThirteenPt<-2, 0, 0> { enum { idx = 10 }; };
543 template<> struct ThirteenPt< 0,-2, 0> { enum { idx = 11 }; };
544 template<> struct ThirteenPt< 0, 0,-2> { enum { idx = 12 }; };
545
546 }
547
548
549 template<typename GridT, bool IsSafe = true>
550 5 class ThirteenPointStencil
551 : public BaseStencil<ThirteenPointStencil<GridT, IsSafe>, GridT, IsSafe>
552 {
553 typedef ThirteenPointStencil<GridT, IsSafe> SelfT;
554 typedef BaseStencil<SelfT, GridT, IsSafe > BaseType;
555 public:
556 typedef GridT GridType;
557 typedef typename GridT::TreeType TreeType;
558 typedef typename GridType::ValueType ValueType;
559
560 static const int SIZE = 13;
561
562
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
5 ThirteenPointStencil(const GridType& grid): BaseType(grid, SIZE) {}
563
564 /// Return linear offset for the specified stencil point relative to its center
565 template<int i, int j, int k>
566 unsigned int pos() const { return ThirteenPt<i,j,k>::idx; }
567
568 private:
569 8195 inline void init(const Coord& ijk)
570 {
571 8195 mValues[ThirteenPt< 2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 0));
572 8195 mValues[ThirteenPt< 1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 0));
573 8195 mValues[ThirteenPt<-1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 0));
574 8195 mValues[ThirteenPt<-2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 0));
575
576 8195 mValues[ThirteenPt< 0, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 0));
577 8195 mValues[ThirteenPt< 0, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 0));
578 8195 mValues[ThirteenPt< 0,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, -1, 0));
579 8195 mValues[ThirteenPt< 0,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, -2, 0));
580
581 8195 mValues[ThirteenPt< 0, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 2));
582 8195 mValues[ThirteenPt< 0, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 1));
583 8195 mValues[ThirteenPt< 0, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, -1));
584 8195 mValues[ThirteenPt< 0, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, -2));
585 8195 }
586
587 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
588 using BaseType::mAcc;
589 using BaseType::mValues;
590 };// ThirteenPointStencil class
591
592
593 ////////////////////////////////////////
594
595
596 namespace { // anonymous namespace for stencil-layout map
597
598 // the 4th-order dense point stencil
599 template<int i, int j, int k> struct FourthDensePt {};
600 template<> struct FourthDensePt< 0, 0, 0> { enum { idx = 0 }; };
601
602 template<> struct FourthDensePt<-2, 2, 0> { enum { idx = 1 }; };
603 template<> struct FourthDensePt<-1, 2, 0> { enum { idx = 2 }; };
604 template<> struct FourthDensePt< 0, 2, 0> { enum { idx = 3 }; };
605 template<> struct FourthDensePt< 1, 2, 0> { enum { idx = 4 }; };
606 template<> struct FourthDensePt< 2, 2, 0> { enum { idx = 5 }; };
607
608 template<> struct FourthDensePt<-2, 1, 0> { enum { idx = 6 }; };
609 template<> struct FourthDensePt<-1, 1, 0> { enum { idx = 7 }; };
610 template<> struct FourthDensePt< 0, 1, 0> { enum { idx = 8 }; };
611 template<> struct FourthDensePt< 1, 1, 0> { enum { idx = 9 }; };
612 template<> struct FourthDensePt< 2, 1, 0> { enum { idx = 10 }; };
613
614 template<> struct FourthDensePt<-2, 0, 0> { enum { idx = 11 }; };
615 template<> struct FourthDensePt<-1, 0, 0> { enum { idx = 12 }; };
616 template<> struct FourthDensePt< 1, 0, 0> { enum { idx = 13 }; };
617 template<> struct FourthDensePt< 2, 0, 0> { enum { idx = 14 }; };
618
619 template<> struct FourthDensePt<-2,-1, 0> { enum { idx = 15 }; };
620 template<> struct FourthDensePt<-1,-1, 0> { enum { idx = 16 }; };
621 template<> struct FourthDensePt< 0,-1, 0> { enum { idx = 17 }; };
622 template<> struct FourthDensePt< 1,-1, 0> { enum { idx = 18 }; };
623 template<> struct FourthDensePt< 2,-1, 0> { enum { idx = 19 }; };
624
625 template<> struct FourthDensePt<-2,-2, 0> { enum { idx = 20 }; };
626 template<> struct FourthDensePt<-1,-2, 0> { enum { idx = 21 }; };
627 template<> struct FourthDensePt< 0,-2, 0> { enum { idx = 22 }; };
628 template<> struct FourthDensePt< 1,-2, 0> { enum { idx = 23 }; };
629 template<> struct FourthDensePt< 2,-2, 0> { enum { idx = 24 }; };
630
631
632 template<> struct FourthDensePt<-2, 0, 2> { enum { idx = 25 }; };
633 template<> struct FourthDensePt<-1, 0, 2> { enum { idx = 26 }; };
634 template<> struct FourthDensePt< 0, 0, 2> { enum { idx = 27 }; };
635 template<> struct FourthDensePt< 1, 0, 2> { enum { idx = 28 }; };
636 template<> struct FourthDensePt< 2, 0, 2> { enum { idx = 29 }; };
637
638 template<> struct FourthDensePt<-2, 0, 1> { enum { idx = 30 }; };
639 template<> struct FourthDensePt<-1, 0, 1> { enum { idx = 31 }; };
640 template<> struct FourthDensePt< 0, 0, 1> { enum { idx = 32 }; };
641 template<> struct FourthDensePt< 1, 0, 1> { enum { idx = 33 }; };
642 template<> struct FourthDensePt< 2, 0, 1> { enum { idx = 34 }; };
643
644 template<> struct FourthDensePt<-2, 0,-1> { enum { idx = 35 }; };
645 template<> struct FourthDensePt<-1, 0,-1> { enum { idx = 36 }; };
646 template<> struct FourthDensePt< 0, 0,-1> { enum { idx = 37 }; };
647 template<> struct FourthDensePt< 1, 0,-1> { enum { idx = 38 }; };
648 template<> struct FourthDensePt< 2, 0,-1> { enum { idx = 39 }; };
649
650 template<> struct FourthDensePt<-2, 0,-2> { enum { idx = 40 }; };
651 template<> struct FourthDensePt<-1, 0,-2> { enum { idx = 41 }; };
652 template<> struct FourthDensePt< 0, 0,-2> { enum { idx = 42 }; };
653 template<> struct FourthDensePt< 1, 0,-2> { enum { idx = 43 }; };
654 template<> struct FourthDensePt< 2, 0,-2> { enum { idx = 44 }; };
655
656
657 template<> struct FourthDensePt< 0,-2, 2> { enum { idx = 45 }; };
658 template<> struct FourthDensePt< 0,-1, 2> { enum { idx = 46 }; };
659 template<> struct FourthDensePt< 0, 1, 2> { enum { idx = 47 }; };
660 template<> struct FourthDensePt< 0, 2, 2> { enum { idx = 48 }; };
661
662 template<> struct FourthDensePt< 0,-2, 1> { enum { idx = 49 }; };
663 template<> struct FourthDensePt< 0,-1, 1> { enum { idx = 50 }; };
664 template<> struct FourthDensePt< 0, 1, 1> { enum { idx = 51 }; };
665 template<> struct FourthDensePt< 0, 2, 1> { enum { idx = 52 }; };
666
667 template<> struct FourthDensePt< 0,-2,-1> { enum { idx = 53 }; };
668 template<> struct FourthDensePt< 0,-1,-1> { enum { idx = 54 }; };
669 template<> struct FourthDensePt< 0, 1,-1> { enum { idx = 55 }; };
670 template<> struct FourthDensePt< 0, 2,-1> { enum { idx = 56 }; };
671
672 template<> struct FourthDensePt< 0,-2,-2> { enum { idx = 57 }; };
673 template<> struct FourthDensePt< 0,-1,-2> { enum { idx = 58 }; };
674 template<> struct FourthDensePt< 0, 1,-2> { enum { idx = 59 }; };
675 template<> struct FourthDensePt< 0, 2,-2> { enum { idx = 60 }; };
676
677 }
678
679
680 template<typename GridT, bool IsSafe = true>
681
8/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
19 class FourthOrderDenseStencil
682 : public BaseStencil<FourthOrderDenseStencil<GridT, IsSafe>, GridT, IsSafe>
683 {
684 typedef FourthOrderDenseStencil<GridT, IsSafe> SelfT;
685 typedef BaseStencil<SelfT, GridT, IsSafe > BaseType;
686 public:
687 typedef GridT GridType;
688 typedef typename GridT::TreeType TreeType;
689 typedef typename GridType::ValueType ValueType;
690
691 static const int SIZE = 61;
692
693
5/10
✓ Branch 1 taken 3 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.
7 FourthOrderDenseStencil(const GridType& grid): BaseType(grid, SIZE) {}
694
695 /// Return linear offset for the specified stencil point relative to its center
696 template<int i, int j, int k>
697 unsigned int pos() const { return FourthDensePt<i,j,k>::idx; }
698
699 private:
700 8 inline void init(const Coord& ijk)
701 {
702 8 mValues[FourthDensePt<-2, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 2, 0));
703 8 mValues[FourthDensePt<-1, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 2, 0));
704 8 mValues[FourthDensePt< 0, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 0));
705 8 mValues[FourthDensePt< 1, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 2, 0));
706 8 mValues[FourthDensePt< 2, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 2, 0));
707
708 8 mValues[FourthDensePt<-2, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 1, 0));
709 8 mValues[FourthDensePt<-1, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 1, 0));
710 8 mValues[FourthDensePt< 0, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 0));
711 8 mValues[FourthDensePt< 1, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 1, 0));
712 8 mValues[FourthDensePt< 2, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 1, 0));
713
714 8 mValues[FourthDensePt<-2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 0));
715 8 mValues[FourthDensePt<-1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 0));
716 8 mValues[FourthDensePt< 1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 0));
717 8 mValues[FourthDensePt< 2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 0));
718
719 8 mValues[FourthDensePt<-2,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2,-1, 0));
720 8 mValues[FourthDensePt<-1,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1,-1, 0));
721 8 mValues[FourthDensePt< 0,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1, 0));
722 8 mValues[FourthDensePt< 1,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1,-1, 0));
723 8 mValues[FourthDensePt< 2,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2,-1, 0));
724
725 8 mValues[FourthDensePt<-2,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2,-2, 0));
726 8 mValues[FourthDensePt<-1,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1,-2, 0));
727 8 mValues[FourthDensePt< 0,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2, 0));
728 8 mValues[FourthDensePt< 1,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1,-2, 0));
729 8 mValues[FourthDensePt< 2,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2,-2, 0));
730
731 8 mValues[FourthDensePt<-2, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 2));
732 8 mValues[FourthDensePt<-1, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 2));
733 8 mValues[FourthDensePt< 0, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 2));
734 8 mValues[FourthDensePt< 1, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 2));
735 8 mValues[FourthDensePt< 2, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 2));
736
737 8 mValues[FourthDensePt<-2, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 1));
738 8 mValues[FourthDensePt<-1, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 1));
739 8 mValues[FourthDensePt< 0, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 1));
740 8 mValues[FourthDensePt< 1, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 1));
741 8 mValues[FourthDensePt< 2, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 1));
742
743 8 mValues[FourthDensePt<-2, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0,-1));
744 8 mValues[FourthDensePt<-1, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0,-1));
745 8 mValues[FourthDensePt< 0, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0,-1));
746 8 mValues[FourthDensePt< 1, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0,-1));
747 8 mValues[FourthDensePt< 2, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0,-1));
748
749 8 mValues[FourthDensePt<-2, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0,-2));
750 8 mValues[FourthDensePt<-1, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0,-2));
751 8 mValues[FourthDensePt< 0, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0,-2));
752 8 mValues[FourthDensePt< 1, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0,-2));
753 8 mValues[FourthDensePt< 2, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0,-2));
754
755
756 8 mValues[FourthDensePt< 0,-2, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2, 2));
757 8 mValues[FourthDensePt< 0,-1, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1, 2));
758 8 mValues[FourthDensePt< 0, 1, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 2));
759 8 mValues[FourthDensePt< 0, 2, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 2));
760
761 8 mValues[FourthDensePt< 0,-2, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2, 1));
762 8 mValues[FourthDensePt< 0,-1, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1, 1));
763 8 mValues[FourthDensePt< 0, 1, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 1));
764 8 mValues[FourthDensePt< 0, 2, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 1));
765
766 8 mValues[FourthDensePt< 0,-2,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2,-1));
767 8 mValues[FourthDensePt< 0,-1,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1,-1));
768 8 mValues[FourthDensePt< 0, 1,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1,-1));
769 8 mValues[FourthDensePt< 0, 2,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2,-1));
770
771 8 mValues[FourthDensePt< 0,-2,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2,-2));
772 8 mValues[FourthDensePt< 0,-1,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1,-2));
773 8 mValues[FourthDensePt< 0, 1,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1,-2));
774 8 mValues[FourthDensePt< 0, 2,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2,-2));
775 8 }
776
777 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
778 using BaseType::mAcc;
779 using BaseType::mValues;
780 };// FourthOrderDenseStencil class
781
782
783 ////////////////////////////////////////
784
785
786 namespace { // anonymous namespace for stencil-layout map
787
788 // the dense point stencil
789 template<int i, int j, int k> struct NineteenPt {};
790 template<> struct NineteenPt< 0, 0, 0> { enum { idx = 0 }; };
791
792 template<> struct NineteenPt< 1, 0, 0> { enum { idx = 1 }; };
793 template<> struct NineteenPt< 0, 1, 0> { enum { idx = 2 }; };
794 template<> struct NineteenPt< 0, 0, 1> { enum { idx = 3 }; };
795
796 template<> struct NineteenPt<-1, 0, 0> { enum { idx = 4 }; };
797 template<> struct NineteenPt< 0,-1, 0> { enum { idx = 5 }; };
798 template<> struct NineteenPt< 0, 0,-1> { enum { idx = 6 }; };
799
800 template<> struct NineteenPt< 2, 0, 0> { enum { idx = 7 }; };
801 template<> struct NineteenPt< 0, 2, 0> { enum { idx = 8 }; };
802 template<> struct NineteenPt< 0, 0, 2> { enum { idx = 9 }; };
803
804 template<> struct NineteenPt<-2, 0, 0> { enum { idx = 10 }; };
805 template<> struct NineteenPt< 0,-2, 0> { enum { idx = 11 }; };
806 template<> struct NineteenPt< 0, 0,-2> { enum { idx = 12 }; };
807
808 template<> struct NineteenPt< 3, 0, 0> { enum { idx = 13 }; };
809 template<> struct NineteenPt< 0, 3, 0> { enum { idx = 14 }; };
810 template<> struct NineteenPt< 0, 0, 3> { enum { idx = 15 }; };
811
812 template<> struct NineteenPt<-3, 0, 0> { enum { idx = 16 }; };
813 template<> struct NineteenPt< 0,-3, 0> { enum { idx = 17 }; };
814 template<> struct NineteenPt< 0, 0,-3> { enum { idx = 18 }; };
815
816 }
817
818
819 template<typename GridT, bool IsSafe = true>
820
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
14916 class NineteenPointStencil
821 : public BaseStencil<NineteenPointStencil<GridT, IsSafe>, GridT, IsSafe>
822 {
823 typedef NineteenPointStencil<GridT, IsSafe> SelfT;
824 typedef BaseStencil<SelfT, GridT, IsSafe > BaseType;
825 public:
826 typedef GridT GridType;
827 typedef typename GridT::TreeType TreeType;
828 typedef typename GridType::ValueType ValueType;
829
830 static const int SIZE = 19;
831
832
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
14916 NineteenPointStencil(const GridType& grid): BaseType(grid, SIZE) {}
833
834 /// Return linear offset for the specified stencil point relative to its center
835 template<int i, int j, int k>
836 unsigned int pos() const { return NineteenPt<i,j,k>::idx; }
837
838 private:
839 2403434 inline void init(const Coord& ijk)
840 {
841 2403434 mValues[NineteenPt< 3, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0, 0));
842 2403434 mValues[NineteenPt< 2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 0));
843 2403434 mValues[NineteenPt< 1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 0));
844 2403434 mValues[NineteenPt<-1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 0));
845 2403434 mValues[NineteenPt<-2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 0));
846 2403434 mValues[NineteenPt<-3, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0, 0));
847
848 2403434 mValues[NineteenPt< 0, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3, 0));
849 2403434 mValues[NineteenPt< 0, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 0));
850 2403434 mValues[NineteenPt< 0, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 0));
851 2403434 mValues[NineteenPt< 0,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, -1, 0));
852 2403434 mValues[NineteenPt< 0,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, -2, 0));
853 2403434 mValues[NineteenPt< 0,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, -3, 0));
854
855 2403434 mValues[NineteenPt< 0, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 3));
856 2403434 mValues[NineteenPt< 0, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 2));
857 2403434 mValues[NineteenPt< 0, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 1));
858 2403434 mValues[NineteenPt< 0, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, -1));
859 2403434 mValues[NineteenPt< 0, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, -2));
860 2403434 mValues[NineteenPt< 0, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, -3));
861 2403434 }
862
863 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
864 using BaseType::mAcc;
865 using BaseType::mValues;
866 };// NineteenPointStencil class
867
868
869 ////////////////////////////////////////
870
871
872 namespace { // anonymous namespace for stencil-layout map
873
874 // the 4th-order dense point stencil
875 template<int i, int j, int k> struct SixthDensePt { };
876 template<> struct SixthDensePt< 0, 0, 0> { enum { idx = 0 }; };
877
878 template<> struct SixthDensePt<-3, 3, 0> { enum { idx = 1 }; };
879 template<> struct SixthDensePt<-2, 3, 0> { enum { idx = 2 }; };
880 template<> struct SixthDensePt<-1, 3, 0> { enum { idx = 3 }; };
881 template<> struct SixthDensePt< 0, 3, 0> { enum { idx = 4 }; };
882 template<> struct SixthDensePt< 1, 3, 0> { enum { idx = 5 }; };
883 template<> struct SixthDensePt< 2, 3, 0> { enum { idx = 6 }; };
884 template<> struct SixthDensePt< 3, 3, 0> { enum { idx = 7 }; };
885
886 template<> struct SixthDensePt<-3, 2, 0> { enum { idx = 8 }; };
887 template<> struct SixthDensePt<-2, 2, 0> { enum { idx = 9 }; };
888 template<> struct SixthDensePt<-1, 2, 0> { enum { idx = 10 }; };
889 template<> struct SixthDensePt< 0, 2, 0> { enum { idx = 11 }; };
890 template<> struct SixthDensePt< 1, 2, 0> { enum { idx = 12 }; };
891 template<> struct SixthDensePt< 2, 2, 0> { enum { idx = 13 }; };
892 template<> struct SixthDensePt< 3, 2, 0> { enum { idx = 14 }; };
893
894 template<> struct SixthDensePt<-3, 1, 0> { enum { idx = 15 }; };
895 template<> struct SixthDensePt<-2, 1, 0> { enum { idx = 16 }; };
896 template<> struct SixthDensePt<-1, 1, 0> { enum { idx = 17 }; };
897 template<> struct SixthDensePt< 0, 1, 0> { enum { idx = 18 }; };
898 template<> struct SixthDensePt< 1, 1, 0> { enum { idx = 19 }; };
899 template<> struct SixthDensePt< 2, 1, 0> { enum { idx = 20 }; };
900 template<> struct SixthDensePt< 3, 1, 0> { enum { idx = 21 }; };
901
902 template<> struct SixthDensePt<-3, 0, 0> { enum { idx = 22 }; };
903 template<> struct SixthDensePt<-2, 0, 0> { enum { idx = 23 }; };
904 template<> struct SixthDensePt<-1, 0, 0> { enum { idx = 24 }; };
905 template<> struct SixthDensePt< 1, 0, 0> { enum { idx = 25 }; };
906 template<> struct SixthDensePt< 2, 0, 0> { enum { idx = 26 }; };
907 template<> struct SixthDensePt< 3, 0, 0> { enum { idx = 27 }; };
908
909
910 template<> struct SixthDensePt<-3,-1, 0> { enum { idx = 28 }; };
911 template<> struct SixthDensePt<-2,-1, 0> { enum { idx = 29 }; };
912 template<> struct SixthDensePt<-1,-1, 0> { enum { idx = 30 }; };
913 template<> struct SixthDensePt< 0,-1, 0> { enum { idx = 31 }; };
914 template<> struct SixthDensePt< 1,-1, 0> { enum { idx = 32 }; };
915 template<> struct SixthDensePt< 2,-1, 0> { enum { idx = 33 }; };
916 template<> struct SixthDensePt< 3,-1, 0> { enum { idx = 34 }; };
917
918
919 template<> struct SixthDensePt<-3,-2, 0> { enum { idx = 35 }; };
920 template<> struct SixthDensePt<-2,-2, 0> { enum { idx = 36 }; };
921 template<> struct SixthDensePt<-1,-2, 0> { enum { idx = 37 }; };
922 template<> struct SixthDensePt< 0,-2, 0> { enum { idx = 38 }; };
923 template<> struct SixthDensePt< 1,-2, 0> { enum { idx = 39 }; };
924 template<> struct SixthDensePt< 2,-2, 0> { enum { idx = 40 }; };
925 template<> struct SixthDensePt< 3,-2, 0> { enum { idx = 41 }; };
926
927
928 template<> struct SixthDensePt<-3,-3, 0> { enum { idx = 42 }; };
929 template<> struct SixthDensePt<-2,-3, 0> { enum { idx = 43 }; };
930 template<> struct SixthDensePt<-1,-3, 0> { enum { idx = 44 }; };
931 template<> struct SixthDensePt< 0,-3, 0> { enum { idx = 45 }; };
932 template<> struct SixthDensePt< 1,-3, 0> { enum { idx = 46 }; };
933 template<> struct SixthDensePt< 2,-3, 0> { enum { idx = 47 }; };
934 template<> struct SixthDensePt< 3,-3, 0> { enum { idx = 48 }; };
935
936
937 template<> struct SixthDensePt<-3, 0, 3> { enum { idx = 49 }; };
938 template<> struct SixthDensePt<-2, 0, 3> { enum { idx = 50 }; };
939 template<> struct SixthDensePt<-1, 0, 3> { enum { idx = 51 }; };
940 template<> struct SixthDensePt< 0, 0, 3> { enum { idx = 52 }; };
941 template<> struct SixthDensePt< 1, 0, 3> { enum { idx = 53 }; };
942 template<> struct SixthDensePt< 2, 0, 3> { enum { idx = 54 }; };
943 template<> struct SixthDensePt< 3, 0, 3> { enum { idx = 55 }; };
944
945
946 template<> struct SixthDensePt<-3, 0, 2> { enum { idx = 56 }; };
947 template<> struct SixthDensePt<-2, 0, 2> { enum { idx = 57 }; };
948 template<> struct SixthDensePt<-1, 0, 2> { enum { idx = 58 }; };
949 template<> struct SixthDensePt< 0, 0, 2> { enum { idx = 59 }; };
950 template<> struct SixthDensePt< 1, 0, 2> { enum { idx = 60 }; };
951 template<> struct SixthDensePt< 2, 0, 2> { enum { idx = 61 }; };
952 template<> struct SixthDensePt< 3, 0, 2> { enum { idx = 62 }; };
953
954 template<> struct SixthDensePt<-3, 0, 1> { enum { idx = 63 }; };
955 template<> struct SixthDensePt<-2, 0, 1> { enum { idx = 64 }; };
956 template<> struct SixthDensePt<-1, 0, 1> { enum { idx = 65 }; };
957 template<> struct SixthDensePt< 0, 0, 1> { enum { idx = 66 }; };
958 template<> struct SixthDensePt< 1, 0, 1> { enum { idx = 67 }; };
959 template<> struct SixthDensePt< 2, 0, 1> { enum { idx = 68 }; };
960 template<> struct SixthDensePt< 3, 0, 1> { enum { idx = 69 }; };
961
962
963 template<> struct SixthDensePt<-3, 0,-1> { enum { idx = 70 }; };
964 template<> struct SixthDensePt<-2, 0,-1> { enum { idx = 71 }; };
965 template<> struct SixthDensePt<-1, 0,-1> { enum { idx = 72 }; };
966 template<> struct SixthDensePt< 0, 0,-1> { enum { idx = 73 }; };
967 template<> struct SixthDensePt< 1, 0,-1> { enum { idx = 74 }; };
968 template<> struct SixthDensePt< 2, 0,-1> { enum { idx = 75 }; };
969 template<> struct SixthDensePt< 3, 0,-1> { enum { idx = 76 }; };
970
971
972 template<> struct SixthDensePt<-3, 0,-2> { enum { idx = 77 }; };
973 template<> struct SixthDensePt<-2, 0,-2> { enum { idx = 78 }; };
974 template<> struct SixthDensePt<-1, 0,-2> { enum { idx = 79 }; };
975 template<> struct SixthDensePt< 0, 0,-2> { enum { idx = 80 }; };
976 template<> struct SixthDensePt< 1, 0,-2> { enum { idx = 81 }; };
977 template<> struct SixthDensePt< 2, 0,-2> { enum { idx = 82 }; };
978 template<> struct SixthDensePt< 3, 0,-2> { enum { idx = 83 }; };
979
980
981 template<> struct SixthDensePt<-3, 0,-3> { enum { idx = 84 }; };
982 template<> struct SixthDensePt<-2, 0,-3> { enum { idx = 85 }; };
983 template<> struct SixthDensePt<-1, 0,-3> { enum { idx = 86 }; };
984 template<> struct SixthDensePt< 0, 0,-3> { enum { idx = 87 }; };
985 template<> struct SixthDensePt< 1, 0,-3> { enum { idx = 88 }; };
986 template<> struct SixthDensePt< 2, 0,-3> { enum { idx = 89 }; };
987 template<> struct SixthDensePt< 3, 0,-3> { enum { idx = 90 }; };
988
989
990 template<> struct SixthDensePt< 0,-3, 3> { enum { idx = 91 }; };
991 template<> struct SixthDensePt< 0,-2, 3> { enum { idx = 92 }; };
992 template<> struct SixthDensePt< 0,-1, 3> { enum { idx = 93 }; };
993 template<> struct SixthDensePt< 0, 1, 3> { enum { idx = 94 }; };
994 template<> struct SixthDensePt< 0, 2, 3> { enum { idx = 95 }; };
995 template<> struct SixthDensePt< 0, 3, 3> { enum { idx = 96 }; };
996
997 template<> struct SixthDensePt< 0,-3, 2> { enum { idx = 97 }; };
998 template<> struct SixthDensePt< 0,-2, 2> { enum { idx = 98 }; };
999 template<> struct SixthDensePt< 0,-1, 2> { enum { idx = 99 }; };
1000 template<> struct SixthDensePt< 0, 1, 2> { enum { idx = 100 }; };
1001 template<> struct SixthDensePt< 0, 2, 2> { enum { idx = 101 }; };
1002 template<> struct SixthDensePt< 0, 3, 2> { enum { idx = 102 }; };
1003
1004 template<> struct SixthDensePt< 0,-3, 1> { enum { idx = 103 }; };
1005 template<> struct SixthDensePt< 0,-2, 1> { enum { idx = 104 }; };
1006 template<> struct SixthDensePt< 0,-1, 1> { enum { idx = 105 }; };
1007 template<> struct SixthDensePt< 0, 1, 1> { enum { idx = 106 }; };
1008 template<> struct SixthDensePt< 0, 2, 1> { enum { idx = 107 }; };
1009 template<> struct SixthDensePt< 0, 3, 1> { enum { idx = 108 }; };
1010
1011 template<> struct SixthDensePt< 0,-3,-1> { enum { idx = 109 }; };
1012 template<> struct SixthDensePt< 0,-2,-1> { enum { idx = 110 }; };
1013 template<> struct SixthDensePt< 0,-1,-1> { enum { idx = 111 }; };
1014 template<> struct SixthDensePt< 0, 1,-1> { enum { idx = 112 }; };
1015 template<> struct SixthDensePt< 0, 2,-1> { enum { idx = 113 }; };
1016 template<> struct SixthDensePt< 0, 3,-1> { enum { idx = 114 }; };
1017
1018 template<> struct SixthDensePt< 0,-3,-2> { enum { idx = 115 }; };
1019 template<> struct SixthDensePt< 0,-2,-2> { enum { idx = 116 }; };
1020 template<> struct SixthDensePt< 0,-1,-2> { enum { idx = 117 }; };
1021 template<> struct SixthDensePt< 0, 1,-2> { enum { idx = 118 }; };
1022 template<> struct SixthDensePt< 0, 2,-2> { enum { idx = 119 }; };
1023 template<> struct SixthDensePt< 0, 3,-2> { enum { idx = 120 }; };
1024
1025 template<> struct SixthDensePt< 0,-3,-3> { enum { idx = 121 }; };
1026 template<> struct SixthDensePt< 0,-2,-3> { enum { idx = 122 }; };
1027 template<> struct SixthDensePt< 0,-1,-3> { enum { idx = 123 }; };
1028 template<> struct SixthDensePt< 0, 1,-3> { enum { idx = 124 }; };
1029 template<> struct SixthDensePt< 0, 2,-3> { enum { idx = 125 }; };
1030 template<> struct SixthDensePt< 0, 3,-3> { enum { idx = 126 }; };
1031
1032 }
1033
1034
1035 template<typename GridT, bool IsSafe = true>
1036 5 class SixthOrderDenseStencil
1037 : public BaseStencil<SixthOrderDenseStencil<GridT, IsSafe>, GridT, IsSafe>
1038 {
1039 typedef SixthOrderDenseStencil<GridT, IsSafe> SelfT;
1040 typedef BaseStencil<SelfT, GridT, IsSafe > BaseType;
1041 public:
1042 typedef GridT GridType;
1043 typedef typename GridT::TreeType TreeType;
1044 typedef typename GridType::ValueType ValueType;
1045
1046 static const int SIZE = 127;
1047
1048
4/8
✓ Branch 1 taken 2 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.
5 SixthOrderDenseStencil(const GridType& grid): BaseType(grid, SIZE) {}
1049
1050 /// Return linear offset for the specified stencil point relative to its center
1051 template<int i, int j, int k>
1052 unsigned int pos() const { return SixthDensePt<i,j,k>::idx; }
1053
1054 private:
1055 8 inline void init(const Coord& ijk)
1056 {
1057 8 mValues[SixthDensePt<-3, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3, 3, 0));
1058 8 mValues[SixthDensePt<-2, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 3, 0));
1059 8 mValues[SixthDensePt<-1, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 3, 0));
1060 8 mValues[SixthDensePt< 0, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3, 0));
1061 8 mValues[SixthDensePt< 1, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 3, 0));
1062 8 mValues[SixthDensePt< 2, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 3, 0));
1063 8 mValues[SixthDensePt< 3, 3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3, 3, 0));
1064
1065 8 mValues[SixthDensePt<-3, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3, 2, 0));
1066 8 mValues[SixthDensePt<-2, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 2, 0));
1067 8 mValues[SixthDensePt<-1, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 2, 0));
1068 8 mValues[SixthDensePt< 0, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 0));
1069 8 mValues[SixthDensePt< 1, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 2, 0));
1070 8 mValues[SixthDensePt< 2, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 2, 0));
1071 8 mValues[SixthDensePt< 3, 2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3, 2, 0));
1072
1073 8 mValues[SixthDensePt<-3, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3, 1, 0));
1074 8 mValues[SixthDensePt<-2, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 1, 0));
1075 8 mValues[SixthDensePt<-1, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 1, 0));
1076 8 mValues[SixthDensePt< 0, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 0));
1077 8 mValues[SixthDensePt< 1, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 1, 0));
1078 8 mValues[SixthDensePt< 2, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 1, 0));
1079 8 mValues[SixthDensePt< 3, 1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3, 1, 0));
1080
1081 8 mValues[SixthDensePt<-3, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0, 0));
1082 8 mValues[SixthDensePt<-2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 0));
1083 8 mValues[SixthDensePt<-1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 0));
1084 8 mValues[SixthDensePt< 1, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 0));
1085 8 mValues[SixthDensePt< 2, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 0));
1086 8 mValues[SixthDensePt< 3, 0, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0, 0));
1087
1088 8 mValues[SixthDensePt<-3,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3,-1, 0));
1089 8 mValues[SixthDensePt<-2,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2,-1, 0));
1090 8 mValues[SixthDensePt<-1,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1,-1, 0));
1091 8 mValues[SixthDensePt< 0,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1, 0));
1092 8 mValues[SixthDensePt< 1,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1,-1, 0));
1093 8 mValues[SixthDensePt< 2,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2,-1, 0));
1094 8 mValues[SixthDensePt< 3,-1, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3,-1, 0));
1095
1096 8 mValues[SixthDensePt<-3,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3,-2, 0));
1097 8 mValues[SixthDensePt<-2,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2,-2, 0));
1098 8 mValues[SixthDensePt<-1,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1,-2, 0));
1099 8 mValues[SixthDensePt< 0,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2, 0));
1100 8 mValues[SixthDensePt< 1,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1,-2, 0));
1101 8 mValues[SixthDensePt< 2,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2,-2, 0));
1102 8 mValues[SixthDensePt< 3,-2, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3,-2, 0));
1103
1104 8 mValues[SixthDensePt<-3,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy(-3,-3, 0));
1105 8 mValues[SixthDensePt<-2,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy(-2,-3, 0));
1106 8 mValues[SixthDensePt<-1,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy(-1,-3, 0));
1107 8 mValues[SixthDensePt< 0,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 0,-3, 0));
1108 8 mValues[SixthDensePt< 1,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 1,-3, 0));
1109 8 mValues[SixthDensePt< 2,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 2,-3, 0));
1110 8 mValues[SixthDensePt< 3,-3, 0>::idx] = mAcc.getValue(ijk.offsetBy( 3,-3, 0));
1111
1112 8 mValues[SixthDensePt<-3, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0, 3));
1113 8 mValues[SixthDensePt<-2, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 3));
1114 8 mValues[SixthDensePt<-1, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 3));
1115 8 mValues[SixthDensePt< 0, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 3));
1116 8 mValues[SixthDensePt< 1, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 3));
1117 8 mValues[SixthDensePt< 2, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 3));
1118 8 mValues[SixthDensePt< 3, 0, 3>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0, 3));
1119
1120 8 mValues[SixthDensePt<-3, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0, 2));
1121 8 mValues[SixthDensePt<-2, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 2));
1122 8 mValues[SixthDensePt<-1, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 2));
1123 8 mValues[SixthDensePt< 0, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 2));
1124 8 mValues[SixthDensePt< 1, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 2));
1125 8 mValues[SixthDensePt< 2, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 2));
1126 8 mValues[SixthDensePt< 3, 0, 2>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0, 2));
1127
1128 8 mValues[SixthDensePt<-3, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0, 1));
1129 8 mValues[SixthDensePt<-2, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0, 1));
1130 8 mValues[SixthDensePt<-1, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0, 1));
1131 8 mValues[SixthDensePt< 0, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0, 1));
1132 8 mValues[SixthDensePt< 1, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0, 1));
1133 8 mValues[SixthDensePt< 2, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0, 1));
1134 8 mValues[SixthDensePt< 3, 0, 1>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0, 1));
1135
1136 8 mValues[SixthDensePt<-3, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0,-1));
1137 8 mValues[SixthDensePt<-2, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0,-1));
1138 8 mValues[SixthDensePt<-1, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0,-1));
1139 8 mValues[SixthDensePt< 0, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0,-1));
1140 8 mValues[SixthDensePt< 1, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0,-1));
1141 8 mValues[SixthDensePt< 2, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0,-1));
1142 8 mValues[SixthDensePt< 3, 0,-1>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0,-1));
1143
1144 8 mValues[SixthDensePt<-3, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0,-2));
1145 8 mValues[SixthDensePt<-2, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0,-2));
1146 8 mValues[SixthDensePt<-1, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0,-2));
1147 8 mValues[SixthDensePt< 0, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0,-2));
1148 8 mValues[SixthDensePt< 1, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0,-2));
1149 8 mValues[SixthDensePt< 2, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0,-2));
1150 8 mValues[SixthDensePt< 3, 0,-2>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0,-2));
1151
1152 8 mValues[SixthDensePt<-3, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy(-3, 0,-3));
1153 8 mValues[SixthDensePt<-2, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy(-2, 0,-3));
1154 8 mValues[SixthDensePt<-1, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy(-1, 0,-3));
1155 8 mValues[SixthDensePt< 0, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 0,-3));
1156 8 mValues[SixthDensePt< 1, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy( 1, 0,-3));
1157 8 mValues[SixthDensePt< 2, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy( 2, 0,-3));
1158 8 mValues[SixthDensePt< 3, 0,-3>::idx] = mAcc.getValue(ijk.offsetBy( 3, 0,-3));
1159
1160 8 mValues[SixthDensePt< 0,-3, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0,-3, 3));
1161 8 mValues[SixthDensePt< 0,-2, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2, 3));
1162 8 mValues[SixthDensePt< 0,-1, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1, 3));
1163 8 mValues[SixthDensePt< 0, 1, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 3));
1164 8 mValues[SixthDensePt< 0, 2, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 3));
1165 8 mValues[SixthDensePt< 0, 3, 3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3, 3));
1166
1167 8 mValues[SixthDensePt< 0,-3, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-3, 2));
1168 8 mValues[SixthDensePt< 0,-2, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2, 2));
1169 8 mValues[SixthDensePt< 0,-1, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1, 2));
1170 8 mValues[SixthDensePt< 0, 1, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 2));
1171 8 mValues[SixthDensePt< 0, 2, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 2));
1172 8 mValues[SixthDensePt< 0, 3, 2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3, 2));
1173
1174 8 mValues[SixthDensePt< 0,-3, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-3, 1));
1175 8 mValues[SixthDensePt< 0,-2, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2, 1));
1176 8 mValues[SixthDensePt< 0,-1, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1, 1));
1177 8 mValues[SixthDensePt< 0, 1, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1, 1));
1178 8 mValues[SixthDensePt< 0, 2, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2, 1));
1179 8 mValues[SixthDensePt< 0, 3, 1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3, 1));
1180
1181 8 mValues[SixthDensePt< 0,-3,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-3,-1));
1182 8 mValues[SixthDensePt< 0,-2,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2,-1));
1183 8 mValues[SixthDensePt< 0,-1,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1,-1));
1184 8 mValues[SixthDensePt< 0, 1,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1,-1));
1185 8 mValues[SixthDensePt< 0, 2,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2,-1));
1186 8 mValues[SixthDensePt< 0, 3,-1>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3,-1));
1187
1188 8 mValues[SixthDensePt< 0,-3,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-3,-2));
1189 8 mValues[SixthDensePt< 0,-2,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2,-2));
1190 8 mValues[SixthDensePt< 0,-1,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1,-2));
1191 8 mValues[SixthDensePt< 0, 1,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1,-2));
1192 8 mValues[SixthDensePt< 0, 2,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2,-2));
1193 8 mValues[SixthDensePt< 0, 3,-2>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3,-2));
1194
1195 8 mValues[SixthDensePt< 0,-3,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0,-3,-3));
1196 8 mValues[SixthDensePt< 0,-2,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0,-2,-3));
1197 8 mValues[SixthDensePt< 0,-1,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0,-1,-3));
1198 8 mValues[SixthDensePt< 0, 1,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 1,-3));
1199 8 mValues[SixthDensePt< 0, 2,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 2,-3));
1200 8 mValues[SixthDensePt< 0, 3,-3>::idx] = mAcc.getValue(ijk.offsetBy( 0, 3,-3));
1201 8 }
1202
1203 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
1204 using BaseType::mAcc;
1205 using BaseType::mValues;
1206 };// SixthOrderDenseStencil class
1207
1208
1209 //////////////////////////////////////////////////////////////////////
1210
1211 namespace { // anonymous namespace for stencil-layout map
1212
1213 // the seven point stencil with a different layout from SevenPt
1214 template<int i, int j, int k> struct GradPt {};
1215 template<> struct GradPt< 0, 0, 0> { enum { idx = 0 }; };
1216 template<> struct GradPt< 1, 0, 0> { enum { idx = 2 }; };
1217 template<> struct GradPt< 0, 1, 0> { enum { idx = 4 }; };
1218 template<> struct GradPt< 0, 0, 1> { enum { idx = 6 }; };
1219 template<> struct GradPt<-1, 0, 0> { enum { idx = 1 }; };
1220 template<> struct GradPt< 0,-1, 0> { enum { idx = 3 }; };
1221 template<> struct GradPt< 0, 0,-1> { enum { idx = 5 }; };
1222 }
1223
1224 /// This is a simple 7-point nearest neighbor stencil that supports
1225 /// gradient by second-order central differencing, first-order upwinding,
1226 /// Laplacian, closest-point transform and zero-crossing test.
1227 ///
1228 /// @note For optimal random access performance this class
1229 /// includes its own grid accessor.
1230 template<typename GridT, bool IsSafe = true>
1231
2/3
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
5 class GradStencil : public BaseStencil<GradStencil<GridT, IsSafe>, GridT, IsSafe>
1232 {
1233 typedef GradStencil<GridT, IsSafe> SelfT;
1234 typedef BaseStencil<SelfT, GridT, IsSafe > BaseType;
1235 public:
1236 typedef GridT GridType;
1237 typedef typename GridT::TreeType TreeType;
1238 typedef typename GridType::ValueType ValueType;
1239
1240 static const int SIZE = 7;
1241
1242 874 GradStencil(const GridType& grid)
1243 : BaseType(grid, SIZE)
1244 874 , mInv2Dx(ValueType(0.5 / grid.voxelSize()[0]))
1245 874 , mInvDx2(ValueType(4.0 * mInv2Dx * mInv2Dx))
1246 {
1247 874 }
1248
1249 GradStencil(const GridType& grid, Real dx)
1250 : BaseType(grid, SIZE)
1251 , mInv2Dx(ValueType(0.5 / dx))
1252 , mInvDx2(ValueType(4.0 * mInv2Dx * mInv2Dx))
1253 {
1254 }
1255
1256 /// @brief Return the norm square of the single-sided upwind gradient
1257 /// (computed via Godunov's scheme) at the previously buffered location.
1258 ///
1259 /// @note This method should not be called until the stencil
1260 /// buffer has been populated via a call to moveTo(ijk).
1261 1 inline ValueType normSqGrad() const
1262 {
1263 1 return mInvDx2 * math::GodunovsNormSqrd(mValues[0] > zeroVal<ValueType>(),
1264 mValues[0] - mValues[1],
1265 mValues[2] - mValues[0],
1266 mValues[0] - mValues[3],
1267 mValues[4] - mValues[0],
1268 mValues[0] - mValues[5],
1269 1 mValues[6] - mValues[0]);
1270 }
1271
1272 /// @brief Return the gradient computed at the previously buffered
1273 /// location by second order central differencing.
1274 ///
1275 /// @note This method should not be called until the stencil
1276 /// buffer has been populated via a call to moveTo(ijk).
1277 2441735 inline math::Vec3<ValueType> gradient() const
1278 {
1279 return math::Vec3<ValueType>(mValues[2] - mValues[1],
1280 mValues[4] - mValues[3],
1281 1 mValues[6] - mValues[5])*mInv2Dx;
1282 }
1283 /// @brief Return the first-order upwind gradient corresponding to the direction V.
1284 ///
1285 /// @note This method should not be called until the stencil
1286 /// buffer has been populated via a call to moveTo(ijk).
1287 inline math::Vec3<ValueType> gradient(const math::Vec3<ValueType>& V) const
1288 {
1289 return math::Vec3<ValueType>(
1290 V[0]>0 ? mValues[0] - mValues[1] : mValues[2] - mValues[0],
1291 V[1]>0 ? mValues[0] - mValues[3] : mValues[4] - mValues[0],
1292 V[2]>0 ? mValues[0] - mValues[5] : mValues[6] - mValues[0])*2*mInv2Dx;
1293 }
1294
1295 /// Return the Laplacian computed at the previously buffered
1296 /// location by second-order central differencing.
1297 inline ValueType laplacian() const
1298 {
1299
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 return mInvDx2 * (mValues[1] + mValues[2] +
1300 2 mValues[3] + mValues[4] +
1301
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 mValues[5] + mValues[6] - 6*mValues[0]);
1302 }
1303
1304 /// Return @c true if the sign of the value at the center point of the stencil
1305 /// is different from the signs of any of its six nearest neighbors.
1306 inline bool zeroCrossing() const
1307 {
1308 const typename BaseType::BufferType& v = mValues;
1309 return (v[0]>0 ? (v[1]<0 || v[2]<0 || v[3]<0 || v[4]<0 || v[5]<0 || v[6]<0)
1310 : (v[1]>0 || v[2]>0 || v[3]>0 || v[4]>0 || v[5]>0 || v[6]>0));
1311 }
1312
1313 /// @brief Compute the closest-point transform to a level set.
1314 /// @return the closest point in index space to the surface
1315 /// from which the level set was derived.
1316 ///
1317 /// @note This method assumes that the grid represents a level set
1318 /// with distances in world units and a simple affine transfrom
1319 /// with uniform scaling.
1320 2 inline math::Vec3<ValueType> cpt()
1321 {
1322 const Coord& ijk = BaseType::getCenterCoord();
1323 2 const ValueType d = ValueType(mValues[0] * 0.5 * mInvDx2); // distance in voxels / (2dx^2)
1324 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
1325 2 const auto value = math::Vec3<ValueType>( ijk[0] - d*(mValues[2] - mValues[1]),
1326 2 ijk[1] - d*(mValues[4] - mValues[3]),
1327 2 ijk[2] - d*(mValues[6] - mValues[5]));
1328 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
1329 2 return value;
1330 }
1331
1332 /// Return linear offset for the specified stencil point relative to its center
1333 template<int i, int j, int k>
1334 unsigned int pos() const { return GradPt<i,j,k>::idx; }
1335
1336 private:
1337
1338 8775733 inline void init(const Coord& ijk)
1339 {
1340 8775733 BaseType::template setValue<-1, 0, 0>(mAcc.getValue(ijk.offsetBy(-1, 0, 0)));
1341 8775733 BaseType::template setValue< 1, 0, 0>(mAcc.getValue(ijk.offsetBy( 1, 0, 0)));
1342
1343 8775733 BaseType::template setValue< 0,-1, 0>(mAcc.getValue(ijk.offsetBy( 0,-1, 0)));
1344 8775733 BaseType::template setValue< 0, 1, 0>(mAcc.getValue(ijk.offsetBy( 0, 1, 0)));
1345
1346 8775733 BaseType::template setValue< 0, 0,-1>(mAcc.getValue(ijk.offsetBy( 0, 0,-1)));
1347 8775733 BaseType::template setValue< 0, 0, 1>(mAcc.getValue(ijk.offsetBy( 0, 0, 1)));
1348 8775733 }
1349
1350 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
1351 using BaseType::mAcc;
1352 using BaseType::mValues;
1353 const ValueType mInv2Dx, mInvDx2;
1354 }; // GradStencil class
1355
1356 ////////////////////////////////////////
1357
1358
1359 /// @brief This is a special 19-point stencil that supports optimal fifth-order WENO
1360 /// upwinding, second-order central differencing, Laplacian, and zero-crossing test.
1361 ///
1362 /// @note For optimal random access performance this class
1363 /// includes its own grid accessor.
1364 template<typename GridT, bool IsSafe = true>
1365 8 class WenoStencil: public BaseStencil<WenoStencil<GridT, IsSafe>, GridT, IsSafe>
1366 {
1367 typedef WenoStencil<GridT, IsSafe> SelfT;
1368 typedef BaseStencil<SelfT, GridT, IsSafe > BaseType;
1369 public:
1370 typedef GridT GridType;
1371 typedef typename GridT::TreeType TreeType;
1372 typedef typename GridType::ValueType ValueType;
1373
1374 static const int SIZE = 19;
1375
1376 8 WenoStencil(const GridType& grid)
1377 : BaseType(grid, SIZE)
1378
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 , _mDx2(ValueType(math::Pow2(grid.voxelSize()[0])))
1379 8 , mInv2Dx(ValueType(0.5 / grid.voxelSize()[0]))
1380 8 , mInvDx2(ValueType(1.0 / _mDx2))
1381
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
16 , mDx2(static_cast<float>(_mDx2))
1382 {
1383 8 }
1384
1385 WenoStencil(const GridType& grid, Real dx)
1386 : BaseType(grid, SIZE)
1387 , _mDx2(ValueType(dx * dx))
1388 , mInv2Dx(ValueType(0.5 / dx))
1389 , mInvDx2(ValueType(1.0 / _mDx2))
1390 , mDx2(static_cast<float>(_mDx2))
1391 {
1392 }
1393
1394 /// @brief Return the norm-square of the WENO upwind gradient (computed via
1395 /// WENO upwinding and Godunov's scheme) at the previously buffered location.
1396 ///
1397 /// @note This method should not be called until the stencil
1398 /// buffer has been populated via a call to moveTo(ijk).
1399 76613 inline ValueType normSqGrad(const ValueType &isoValue = zeroVal<ValueType>()) const
1400 {
1401 const typename BaseType::BufferType& v = mValues;
1402 #ifdef DWA_OPENVDB
1403 // SSE optimized
1404 const simd::Float4
1405 v1(v[2]-v[1], v[ 8]-v[ 7], v[14]-v[13], 0),
1406 v2(v[3]-v[2], v[ 9]-v[ 8], v[15]-v[14], 0),
1407 v3(v[0]-v[3], v[ 0]-v[ 9], v[ 0]-v[15], 0),
1408 v4(v[4]-v[0], v[10]-v[ 0], v[16]-v[ 0], 0),
1409 v5(v[5]-v[4], v[11]-v[10], v[17]-v[16], 0),
1410 v6(v[6]-v[5], v[12]-v[11], v[18]-v[17], 0),
1411 dP_m = math::WENO5(v1, v2, v3, v4, v5, mDx2),
1412 dP_p = math::WENO5(v6, v5, v4, v3, v2, mDx2);
1413
1414 return mInvDx2 * math::GodunovsNormSqrd(mValues[0] > isoValue, dP_m, dP_p);
1415 #else
1416 const Real
1417 76613 dP_xm = math::WENO5(v[ 2]-v[ 1],v[ 3]-v[ 2],v[ 0]-v[ 3],v[ 4]-v[ 0],v[ 5]-v[ 4],mDx2),
1418 76613 dP_xp = math::WENO5(v[ 6]-v[ 5],v[ 5]-v[ 4],v[ 4]-v[ 0],v[ 0]-v[ 3],v[ 3]-v[ 2],mDx2),
1419 76613 dP_ym = math::WENO5(v[ 8]-v[ 7],v[ 9]-v[ 8],v[ 0]-v[ 9],v[10]-v[ 0],v[11]-v[10],mDx2),
1420 76613 dP_yp = math::WENO5(v[12]-v[11],v[11]-v[10],v[10]-v[ 0],v[ 0]-v[ 9],v[ 9]-v[ 8],mDx2),
1421 76613 dP_zm = math::WENO5(v[14]-v[13],v[15]-v[14],v[ 0]-v[15],v[16]-v[ 0],v[17]-v[16],mDx2),
1422 76613 dP_zp = math::WENO5(v[18]-v[17],v[17]-v[16],v[16]-v[ 0],v[ 0]-v[15],v[15]-v[14],mDx2);
1423 return static_cast<ValueType>(
1424 76613 mInvDx2*math::GodunovsNormSqrd(v[0]>isoValue, dP_xm, dP_xp, dP_ym, dP_yp, dP_zm, dP_zp));
1425 #endif
1426 }
1427
1428 /// Return the optimal fifth-order upwind gradient corresponding to the
1429 /// direction V.
1430 ///
1431 /// @note This method should not be called until the stencil
1432 /// buffer has been populated via a call to moveTo(ijk).
1433 inline math::Vec3<ValueType> gradient(const math::Vec3<ValueType>& V) const
1434 {
1435 const typename BaseType::BufferType& v = mValues;
1436 return 2*mInv2Dx * math::Vec3<ValueType>(
1437 V[0]>0 ? math::WENO5(v[ 2]-v[ 1],v[ 3]-v[ 2],v[ 0]-v[ 3], v[ 4]-v[ 0],v[ 5]-v[ 4],mDx2)
1438 : math::WENO5(v[ 6]-v[ 5],v[ 5]-v[ 4],v[ 4]-v[ 0], v[ 0]-v[ 3],v[ 3]-v[ 2],mDx2),
1439 V[1]>0 ? math::WENO5(v[ 8]-v[ 7],v[ 9]-v[ 8],v[ 0]-v[ 9], v[10]-v[ 0],v[11]-v[10],mDx2)
1440 : math::WENO5(v[12]-v[11],v[11]-v[10],v[10]-v[ 0], v[ 0]-v[ 9],v[ 9]-v[ 8],mDx2),
1441 V[2]>0 ? math::WENO5(v[14]-v[13],v[15]-v[14],v[ 0]-v[15], v[16]-v[ 0],v[17]-v[16],mDx2)
1442 : math::WENO5(v[18]-v[17],v[17]-v[16],v[16]-v[ 0], v[ 0]-v[15],v[15]-v[14],mDx2));
1443 }
1444 /// Return the gradient computed at the previously buffered
1445 /// location by second-order central differencing.
1446 ///
1447 /// @note This method should not be called until the stencil
1448 /// buffer has been populated via a call to moveTo(ijk).
1449 1 inline math::Vec3<ValueType> gradient() const
1450 {
1451 1 return mInv2Dx * math::Vec3<ValueType>(mValues[ 4] - mValues[ 3],
1452 mValues[10] - mValues[ 9],
1453 1 mValues[16] - mValues[15]);
1454 }
1455
1456 /// Return the Laplacian computed at the previously buffered
1457 /// location by second-order central differencing.
1458 ///
1459 /// @note This method should not be called until the stencil
1460 /// buffer has been populated via a call to moveTo(ijk).
1461 inline ValueType laplacian() const
1462 {
1463
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 return mInvDx2 * (
1464 2 mValues[ 3] + mValues[ 4] +
1465 2 mValues[ 9] + mValues[10] +
1466
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 mValues[15] + mValues[16] - 6*mValues[0]);
1467 }
1468
1469 /// Return @c true if the sign of the value at the center point of the stencil
1470 /// differs from the sign of any of its six nearest neighbors
1471
2/2
✓ Branch 0 taken 123294 times.
✓ Branch 1 taken 109438 times.
232732 inline bool zeroCrossing() const
1472 {
1473 const typename BaseType::BufferType& v = mValues;
1474
14/14
✓ Branch 0 taken 123294 times.
✓ Branch 1 taken 109438 times.
✓ Branch 2 taken 111990 times.
✓ Branch 3 taken 11304 times.
✓ Branch 4 taken 100686 times.
✓ Branch 5 taken 11304 times.
✓ Branch 6 taken 95694 times.
✓ Branch 7 taken 4992 times.
✓ Branch 8 taken 90702 times.
✓ Branch 9 taken 4992 times.
✓ Branch 10 taken 87694 times.
✓ Branch 11 taken 3008 times.
✓ Branch 12 taken 3008 times.
✓ Branch 13 taken 84686 times.
232732 return (v[ 0]>0 ? (v[ 3]<0 || v[ 4]<0 || v[ 9]<0 || v[10]<0 || v[15]<0 || v[16]<0)
1475
12/12
✓ Branch 0 taken 97860 times.
✓ Branch 1 taken 11578 times.
✓ Branch 2 taken 86290 times.
✓ Branch 3 taken 11570 times.
✓ Branch 4 taken 81622 times.
✓ Branch 5 taken 4668 times.
✓ Branch 6 taken 76954 times.
✓ Branch 7 taken 4668 times.
✓ Branch 8 taken 74194 times.
✓ Branch 9 taken 2760 times.
✓ Branch 10 taken 2760 times.
✓ Branch 11 taken 71434 times.
109438 : (v[ 3]>0 || v[ 4]>0 || v[ 9]>0 || v[10]>0 || v[15]>0 || v[16]>0));
1476 }
1477
1478 private:
1479 232735 inline void init(const Coord& ijk)
1480 {
1481 232735 mValues[ 1] = mAcc.getValue(ijk.offsetBy(-3, 0, 0));
1482 232735 mValues[ 2] = mAcc.getValue(ijk.offsetBy(-2, 0, 0));
1483 232735 mValues[ 3] = mAcc.getValue(ijk.offsetBy(-1, 0, 0));
1484 232735 mValues[ 4] = mAcc.getValue(ijk.offsetBy( 1, 0, 0));
1485 232735 mValues[ 5] = mAcc.getValue(ijk.offsetBy( 2, 0, 0));
1486 232735 mValues[ 6] = mAcc.getValue(ijk.offsetBy( 3, 0, 0));
1487
1488 232735 mValues[ 7] = mAcc.getValue(ijk.offsetBy( 0, -3, 0));
1489 232735 mValues[ 8] = mAcc.getValue(ijk.offsetBy( 0, -2, 0));
1490 232735 mValues[ 9] = mAcc.getValue(ijk.offsetBy( 0, -1, 0));
1491 232735 mValues[10] = mAcc.getValue(ijk.offsetBy( 0, 1, 0));
1492 232735 mValues[11] = mAcc.getValue(ijk.offsetBy( 0, 2, 0));
1493 232735 mValues[12] = mAcc.getValue(ijk.offsetBy( 0, 3, 0));
1494
1495 232735 mValues[13] = mAcc.getValue(ijk.offsetBy( 0, 0, -3));
1496 232735 mValues[14] = mAcc.getValue(ijk.offsetBy( 0, 0, -2));
1497 232735 mValues[15] = mAcc.getValue(ijk.offsetBy( 0, 0, -1));
1498 232735 mValues[16] = mAcc.getValue(ijk.offsetBy( 0, 0, 1));
1499 232735 mValues[17] = mAcc.getValue(ijk.offsetBy( 0, 0, 2));
1500 232735 mValues[18] = mAcc.getValue(ijk.offsetBy( 0, 0, 3));
1501 232735 }
1502
1503 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
1504 using BaseType::mAcc;
1505 using BaseType::mValues;
1506 const ValueType _mDx2, mInv2Dx, mInvDx2;
1507 const float mDx2;
1508 }; // WenoStencil class
1509
1510
1511 //////////////////////////////////////////////////////////////////////
1512
1513
1514 template<typename GridT, bool IsSafe = true>
1515
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
4 class CurvatureStencil: public BaseStencil<CurvatureStencil<GridT, IsSafe>, GridT, IsSafe>
1516 {
1517 typedef CurvatureStencil<GridT, IsSafe> SelfT;
1518 typedef BaseStencil<SelfT, GridT, IsSafe> BaseType;
1519 public:
1520 typedef GridT GridType;
1521 typedef typename GridT::TreeType TreeType;
1522 typedef typename GridT::ValueType ValueType;
1523
1524 static const int SIZE = 19;
1525
1526 918 CurvatureStencil(const GridType& grid)
1527 : BaseType(grid, SIZE)
1528 918 , mInv2Dx(ValueType(0.5 / grid.voxelSize()[0]))
1529 918 , mInvDx2(ValueType(4.0 * mInv2Dx * mInv2Dx))
1530 {
1531 918 }
1532
1533 CurvatureStencil(const GridType& grid, Real dx)
1534 : BaseType(grid, SIZE)
1535 , mInv2Dx(ValueType(0.5 / dx))
1536 , mInvDx2(ValueType(4.0 * mInv2Dx * mInv2Dx))
1537 {
1538 }
1539
1540 /// @brief Return the mean curvature at the previously buffered location.
1541 ///
1542 /// @note This method should not be called until the stencil
1543 /// buffer has been populated via a call to moveTo(ijk).
1544 4 inline ValueType meanCurvature() const
1545 {
1546 Real alpha, normGrad;
1547
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
4 return this->meanCurvature(alpha, normGrad) ?
1548 3 ValueType(alpha*mInv2Dx/math::Pow3(normGrad)) : 0;
1549 }
1550
1551 /// @brief Return the Gaussian curvature at the previously buffered location.
1552 ///
1553 /// @note This method should not be called until the stencil
1554 /// buffer has been populated via a call to moveTo(ijk).
1555 3 inline ValueType gaussianCurvature() const
1556 {
1557 Real alpha, normGrad;
1558
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 return this->gaussianCurvature(alpha, normGrad) ?
1559 3 ValueType(alpha*mInvDx2/math::Pow4(normGrad)) : 0;
1560 }
1561
1562 /// @brief Return both the mean and the Gaussian curvature at the
1563 /// previously buffered location.
1564 ///
1565 /// @note This method should not be called until the stencil
1566 /// buffer has been populated via a call to moveTo(ijk).
1567 19280214 inline void curvatures(ValueType &mean, ValueType& gauss) const
1568 {
1569 Real alphaM, alphaG, normGrad;
1570
1/2
✓ Branch 1 taken 9640108 times.
✗ Branch 2 not taken.
19280214 if (this->curvatures(alphaM, alphaG, normGrad)) {
1571 19280214 mean = ValueType(alphaM*mInv2Dx/math::Pow3(normGrad));
1572 19280214 gauss = ValueType(alphaG*mInvDx2/math::Pow4(normGrad));
1573 } else {
1574 mean = gauss = 0;
1575 }
1576 19280214 }
1577
1578 /// Return the mean curvature multiplied by the norm of the
1579 /// central-difference gradient. This method is very useful for
1580 /// mean-curvature flow of level sets!
1581 ///
1582 /// @note This method should not be called until the stencil
1583 /// buffer has been populated via a call to moveTo(ijk).
1584 3 inline ValueType meanCurvatureNormGrad() const
1585 {
1586 Real alpha, normGrad;
1587
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
3 return this->meanCurvature(alpha, normGrad) ?
1588 2 ValueType(alpha*mInvDx2/(2*math::Pow2(normGrad))) : 0;
1589 }
1590
1591 /// Return the mean Gaussian multiplied by the norm of the
1592 /// central-difference gradient.
1593 ///
1594 /// @note This method should not be called until the stencil
1595 /// buffer has been populated via a call to moveTo(ijk).
1596 2 inline ValueType gaussianCurvatureNormGrad() const
1597 {
1598 Real alpha, normGrad;
1599
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 return this->gaussianCurvature(alpha, normGrad) ?
1600 2 ValueType(2*alpha*mInv2Dx*mInvDx2/math::Pow3(normGrad)) : 0;
1601 }
1602
1603 /// @brief Return both the mean and the Gaussian curvature at the
1604 /// previously buffered location.
1605 ///
1606 /// @note This method should not be called until the stencil
1607 /// buffer has been populated via a call to moveTo(ijk).
1608 1 inline void curvaturesNormGrad(ValueType &mean, ValueType& gauss) const
1609 {
1610 Real alphaM, alphaG, normGrad;
1611
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (this->curvatures(alphaM, alphaG, normGrad)) {
1612 1 mean = ValueType(alphaM*mInvDx2/(2*math::Pow2(normGrad)));
1613 1 gauss = ValueType(2*alphaG*mInv2Dx*mInvDx2/math::Pow3(normGrad));
1614 } else {
1615 mean = gauss = 0;
1616 }
1617 1 }
1618
1619 /// @brief Return the pair (minimum, maximum) principal curvature at the
1620 /// previously buffered location.
1621 ///
1622 /// @note This method should not be called until the stencil
1623 /// buffer has been populated via a call to moveTo(ijk).
1624 2 inline std::pair<ValueType, ValueType> principalCurvatures() const
1625 {
1626 2 std::pair<ValueType, ValueType> pair(0, 0);// min, max
1627 Real alphaM, alphaG, normGrad;
1628
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (this->curvatures(alphaM, alphaG, normGrad)) {
1629 2 const Real mean = alphaM*mInv2Dx/math::Pow3(normGrad);
1630 2 const Real tmp = std::sqrt(mean*mean - alphaG*mInvDx2/math::Pow4(normGrad));
1631 2 pair.first = ValueType(mean - tmp);
1632 2 pair.second = ValueType(mean + tmp);
1633 }
1634 2 return pair;// min, max
1635 }
1636
1637 /// Return the Laplacian computed at the previously buffered
1638 /// location by second-order central differencing.
1639 ///
1640 /// @note This method should not be called until the stencil
1641 /// buffer has been populated via a call to moveTo(ijk).
1642 inline ValueType laplacian() const
1643 {
1644
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 return mInvDx2 * (
1645 2 mValues[1] + mValues[2] +
1646 2 mValues[3] + mValues[4] +
1647
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 mValues[5] + mValues[6] - 6*mValues[0]);
1648 }
1649
1650 /// Return the gradient computed at the previously buffered
1651 /// location by second-order central differencing.
1652 ///
1653 /// @note This method should not be called until the stencil
1654 /// buffer has been populated via a call to moveTo(ijk).
1655 9640107 inline math::Vec3<ValueType> gradient() const
1656 {
1657 return math::Vec3<ValueType>(
1658 mValues[2] - mValues[1],
1659 mValues[4] - mValues[3],
1660 1 mValues[6] - mValues[5])*mInv2Dx;
1661 }
1662
1663 private:
1664 19280219 inline void init(const Coord &ijk)
1665 {
1666 19280219 mValues[ 1] = mAcc.getValue(ijk.offsetBy(-1, 0, 0));
1667 19280219 mValues[ 2] = mAcc.getValue(ijk.offsetBy( 1, 0, 0));
1668
1669 19280219 mValues[ 3] = mAcc.getValue(ijk.offsetBy( 0, -1, 0));
1670 19280219 mValues[ 4] = mAcc.getValue(ijk.offsetBy( 0, 1, 0));
1671
1672 19280219 mValues[ 5] = mAcc.getValue(ijk.offsetBy( 0, 0, -1));
1673 19280219 mValues[ 6] = mAcc.getValue(ijk.offsetBy( 0, 0, 1));
1674
1675 19280219 mValues[ 7] = mAcc.getValue(ijk.offsetBy(-1, -1, 0));
1676 19280219 mValues[ 8] = mAcc.getValue(ijk.offsetBy( 1, -1, 0));
1677 19280219 mValues[ 9] = mAcc.getValue(ijk.offsetBy(-1, 1, 0));
1678 19280219 mValues[10] = mAcc.getValue(ijk.offsetBy( 1, 1, 0));
1679
1680 19280219 mValues[11] = mAcc.getValue(ijk.offsetBy(-1, 0, -1));
1681 19280219 mValues[12] = mAcc.getValue(ijk.offsetBy( 1, 0, -1));
1682 19280219 mValues[13] = mAcc.getValue(ijk.offsetBy(-1, 0, 1));
1683 19280219 mValues[14] = mAcc.getValue(ijk.offsetBy( 1, 0, 1));
1684
1685 19280219 mValues[15] = mAcc.getValue(ijk.offsetBy( 0, -1, -1));
1686 19280219 mValues[16] = mAcc.getValue(ijk.offsetBy( 0, 1, -1));
1687 19280219 mValues[17] = mAcc.getValue(ijk.offsetBy( 0, -1, 1));
1688 19280219 mValues[18] = mAcc.getValue(ijk.offsetBy( 0, 1, 1));
1689 19280219 }
1690
1691 9640123 inline Real Dx() const { return 0.5*(mValues[2] - mValues[1]); }// * 1/dx
1692 9640123 inline Real Dy() const { return 0.5*(mValues[4] - mValues[3]); }// * 1/dx
1693 9640123 inline Real Dz() const { return 0.5*(mValues[6] - mValues[5]); }// * 1/dx
1694 9640121 inline Real Dxx() const { return mValues[2] - 2 * mValues[0] + mValues[1]; }// * 1/dx2
1695 9640121 inline Real Dyy() const { return mValues[4] - 2 * mValues[0] + mValues[3]; }// * 1/dx2}
1696 9640121 inline Real Dzz() const { return mValues[6] - 2 * mValues[0] + mValues[5]; }// * 1/dx2
1697 9640121 inline Real Dxy() const { return 0.25 * (mValues[10] - mValues[ 8] + mValues[ 7] - mValues[ 9]); }// * 1/dx2
1698 9640121 inline Real Dxz() const { return 0.25 * (mValues[14] - mValues[12] + mValues[11] - mValues[13]); }// * 1/dx2
1699 9640121 inline Real Dyz() const { return 0.25 * (mValues[18] - mValues[16] + mValues[15] - mValues[17]); }// * 1/dx2
1700
1701
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
7 inline bool meanCurvature(Real& alpha, Real& normGrad) const
1702 {
1703 // For performance all finite differences are unscaled wrt dx
1704 const Real Dx = this->Dx(), Dy = this->Dy(), Dz = this->Dz(),
1705 7 Dx2 = Dx*Dx, Dy2 = Dy*Dy, Dz2 = Dz*Dz, normGrad2 = Dx2 + Dy2 + Dz2;
1706
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
7 if (normGrad2 <= math::Tolerance<Real>::value()) {
1707 2 alpha = normGrad = 0;
1708 2 return false;
1709 }
1710 const Real Dxx = this->Dxx(), Dyy = this->Dyy(), Dzz = this->Dzz();
1711 5 alpha = Dx2*(Dyy + Dzz) + Dy2*(Dxx + Dzz) + Dz2*(Dxx + Dyy) -
1712 5 2*(Dx*(Dy*this->Dxy() + Dz*this->Dxz()) + Dy*Dz*this->Dyz());// * 1/dx^4
1713 5 normGrad = std::sqrt(normGrad2); // * 1/dx
1714 5 return true;
1715 }
1716
1717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 inline bool gaussianCurvature(Real& alpha, Real& normGrad) const
1718 {
1719 // For performance all finite differences are unscaled wrt dx
1720 const Real Dx = this->Dx(), Dy = this->Dy(), Dz = this->Dz(),
1721 5 Dx2 = Dx*Dx, Dy2 = Dy*Dy, Dz2 = Dz*Dz, normGrad2 = Dx2 + Dy2 + Dz2;
1722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (normGrad2 <= math::Tolerance<Real>::value()) {
1723 alpha = normGrad = 0;
1724 return false;
1725 }
1726 const Real Dxx = this->Dxx(), Dyy = this->Dyy(), Dzz = this->Dzz(),
1727 Dxy = this->Dxy(), Dxz = this->Dxz(), Dyz = this->Dyz();
1728 5 alpha = Dx2*(Dyy*Dzz - Dyz*Dyz) + Dy2*(Dxx*Dzz - Dxz*Dxz) + Dz2*(Dxx*Dyy - Dxy*Dxy) +
1729 5 2*( Dy*Dz*(Dxy*Dxz - Dyz*Dxx) + Dx*Dz*(Dxy*Dyz - Dxz*Dyy) + Dx*Dy*(Dxz*Dyz - Dxy*Dzz) );// * 1/dx^6
1730 5 normGrad = std::sqrt(normGrad2); // * 1/dx
1731 5 return true;
1732 }
1733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
9640111 inline bool curvatures(Real& alphaM, Real& alphaG, Real& normGrad) const
1734 {
1735 // For performance all finite differences are unscaled wrt dx
1736 const Real Dx = this->Dx(), Dy = this->Dy(), Dz = this->Dz(),
1737 9640111 Dx2 = Dx*Dx, Dy2 = Dy*Dy, Dz2 = Dz*Dz, normGrad2 = Dx2 + Dy2 + Dz2;
1738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
9640111 if (normGrad2 <= math::Tolerance<Real>::value()) {
1739 alphaM = alphaG =normGrad = 0;
1740 return false;
1741 }
1742 const Real Dxx = this->Dxx(), Dyy = this->Dyy(), Dzz = this->Dzz(),
1743 Dxy = this->Dxy(), Dxz = this->Dxz(), Dyz = this->Dyz();
1744 9640111 alphaM = Dx2*(Dyy + Dzz) + Dy2*(Dxx + Dzz) + Dz2*(Dxx + Dyy) -
1745 9640111 2*(Dx*(Dy*Dxy + Dz*Dxz) + Dy*Dz*Dyz);// *1/dx^4
1746 9640111 alphaG = Dx2*(Dyy*Dzz - Dyz*Dyz) + Dy2*(Dxx*Dzz - Dxz*Dxz) + Dz2*(Dxx*Dyy - Dxy*Dxy) +
1747 9640111 2*( Dy*Dz*(Dxy*Dxz - Dyz*Dxx) + Dx*Dz*(Dxy*Dyz - Dxz*Dyy) + Dx*Dy*(Dxz*Dyz - Dxy*Dzz) );// *1/dx^6
1748 9640111 normGrad = std::sqrt(normGrad2); // * 1/dx
1749 9640111 return true;
1750 }
1751
1752 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
1753 using BaseType::mAcc;
1754 using BaseType::mValues;
1755 const ValueType mInv2Dx, mInvDx2;
1756 }; // CurvatureStencil class
1757
1758
1759 //////////////////////////////////////////////////////////////////////
1760
1761
1762 /// @brief Dense stencil of a given width
1763 template<typename GridT, bool IsSafe = true>
1764
10/20
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 2 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 2 times.
✗ Branch 28 not taken.
✓ Branch 31 taken 2 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 2 times.
✗ Branch 35 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
381 class DenseStencil: public BaseStencil<DenseStencil<GridT, IsSafe>, GridT, IsSafe>
1765 {
1766 typedef DenseStencil<GridT, IsSafe> SelfT;
1767 typedef BaseStencil<SelfT, GridT, IsSafe> BaseType;
1768 public:
1769 typedef GridT GridType;
1770 typedef typename GridT::TreeType TreeType;
1771 typedef typename GridType::ValueType ValueType;
1772
1773 526 DenseStencil(const GridType& grid, int halfWidth)
1774 524 : BaseType(grid, /*size=*/math::Pow3(2 * halfWidth + 1))
1775
4/8
✓ 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.
526 , mHalfWidth(halfWidth)
1776 {
1777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264 times.
524 assert(halfWidth>0);
1778 524 }
1779
1780 inline const ValueType& getCenterValue() const { return mValues[(mValues.size()-1)>>1]; }
1781
1782 /// @brief Initialize the stencil buffer with the values of voxel (x, y, z)
1783 /// and its neighbors.
1784 inline void moveTo(const Coord& ijk)
1785 {
1786 1518960 BaseType::mCenter = ijk;
1787
2/4
✓ Branch 3 taken 64000 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 64000 times.
✗ Branch 7 not taken.
1518960 this->init(ijk);
1788 128000 }
1789 /// @brief Initialize the stencil buffer with the values of voxel
1790 /// (x, y, z) and its neighbors.
1791 template<typename IterType>
1792 inline void moveTo(const IterType& iter)
1793 {
1794
1/8
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 10 taken 756736 times.
✗ Branch 11 not taken.
756736 BaseType::mCenter = iter.getCoord();
1795
1/8
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 10 taken 756736 times.
✗ Branch 11 not taken.
756736 this->init(BaseType::mCenter);
1796 756736 }
1797
1798 private:
1799 /// Initialize the stencil buffer centered at (i, j, k).
1800 /// @warning The center point is NOT at mValues[0] for this DenseStencil!
1801 3032432 inline void init(const Coord& ijk)
1802 {
1803 int n = 0;
1804
2/2
✓ Branch 0 taken 7211088 times.
✓ Branch 1 taken 2275696 times.
12641728 for (Coord p=ijk.offsetBy(-mHalfWidth), q=ijk.offsetBy(mHalfWidth); p[0] <= q[0]; ++p[0]) {
1805
2/2
✓ Branch 0 taken 23553264 times.
✓ Branch 1 taken 7211088 times.
40997184 for (p[1] = ijk[1]-mHalfWidth; p[1] <= q[1]; ++p[1]) {
1806
2/2
✓ Branch 0 taken 80259792 times.
✓ Branch 1 taken 23553264 times.
138351552 for (p[2] = ijk[2]-mHalfWidth; p[2] <= q[2]; ++p[2]) {
1807 106963664 mValues[n++] = mAcc.getValue(p);
1808 }
1809 }
1810 }
1811 3032432 }
1812
1813 template<typename, typename, bool> friend class BaseStencil; // allow base class to call init()
1814 using BaseType::mAcc;
1815 using BaseType::mValues;
1816 const int mHalfWidth;
1817 };// DenseStencil class
1818
1819
1820 } // end math namespace
1821 } // namespace OPENVDB_VERSION_NAME
1822 } // end openvdb namespace
1823
1824 #endif // OPENVDB_MATH_STENCILS_HAS_BEEN_INCLUDED
1825