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 tools/LevelSetTracker.h | ||
7 | /// | ||
8 | /// @brief Performs multi-threaded interface tracking of narrow band | ||
9 | /// level sets. This is the building-block for most level set | ||
10 | /// computations that involve dynamic topology, e.g. advection. | ||
11 | |||
12 | #ifndef OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED | ||
13 | #define OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED | ||
14 | |||
15 | #include "openvdb/Types.h" | ||
16 | #include "openvdb/Grid.h" | ||
17 | #include "openvdb/math/Math.h" | ||
18 | #include "openvdb/math/FiniteDifference.h" | ||
19 | #include "openvdb/math/Operators.h" | ||
20 | #include "openvdb/math/Stencils.h" | ||
21 | #include "openvdb/math/Transform.h" | ||
22 | #include "openvdb/util/NullInterrupter.h" | ||
23 | #include "openvdb/thread/Threading.h" | ||
24 | #include "openvdb/tree/ValueAccessor.h" | ||
25 | #include "openvdb/tree/LeafManager.h" | ||
26 | #include "ChangeBackground.h"// for changeLevelSetBackground | ||
27 | #include "Morphology.h"//for dilateActiveValues | ||
28 | #include "Prune.h"// for pruneLevelSet | ||
29 | |||
30 | #include <tbb/parallel_for.h> | ||
31 | |||
32 | #include <functional> | ||
33 | #include <type_traits> | ||
34 | |||
35 | namespace openvdb { | ||
36 | OPENVDB_USE_VERSION_NAMESPACE | ||
37 | namespace OPENVDB_VERSION_NAME { | ||
38 | namespace tools { | ||
39 | |||
40 | namespace lstrack { | ||
41 | |||
42 | /// @brief How to handle voxels that fall outside the narrow band | ||
43 | /// @sa @link LevelSetTracker::trimming() trimming@endlink, | ||
44 | /// @link LevelSetTracker::setTrimming() setTrimming@endlink | ||
45 | enum class TrimMode { | ||
46 | kNone, ///< Leave out-of-band voxels intact | ||
47 | kInterior, ///< Set out-of-band interior voxels to the background value | ||
48 | kExterior, ///< Set out-of-band exterior voxels to the background value | ||
49 | kAll ///< Set all out-of-band voxels to the background value | ||
50 | }; | ||
51 | |||
52 | } // namespace lstrack | ||
53 | |||
54 | |||
55 | /// @brief Performs multi-threaded interface tracking of narrow band level sets | ||
56 | template<typename GridT, typename InterruptT = util::NullInterrupter> | ||
57 | class LevelSetTracker | ||
58 | { | ||
59 | public: | ||
60 | using TrimMode = lstrack::TrimMode; | ||
61 | |||
62 | using GridType = GridT; | ||
63 | using TreeType = typename GridT::TreeType; | ||
64 | using LeafType = typename TreeType::LeafNodeType; | ||
65 | using ValueType = typename TreeType::ValueType; | ||
66 | using LeafManagerType = typename tree::LeafManager<TreeType>; // leafs + buffers | ||
67 | using LeafRange = typename LeafManagerType::LeafRange; | ||
68 | using BufferType = typename LeafManagerType::BufferType; | ||
69 | using MaskTreeType = typename TreeType::template ValueConverter<ValueMask>::Type; | ||
70 | static_assert(std::is_floating_point<ValueType>::value, | ||
71 | "LevelSetTracker requires a level set grid with floating-point values"); | ||
72 | |||
73 | /// Lightweight struct that stores the state of the LevelSetTracker | ||
74 | struct State { | ||
75 | 4 | State(math::BiasedGradientScheme s = math::HJWENO5_BIAS, | |
76 | math::TemporalIntegrationScheme t = math::TVD_RK1, | ||
77 | int n = static_cast<int>(LEVEL_SET_HALF_WIDTH), int g = 1) | ||
78 | 4 | : spatialScheme(s), temporalScheme(t), normCount(n), grainSize(g) {} | |
79 | math::BiasedGradientScheme spatialScheme; | ||
80 | math::TemporalIntegrationScheme temporalScheme; | ||
81 | int normCount;// Number of iterations of normalization | ||
82 | int grainSize; | ||
83 | }; | ||
84 | |||
85 | /// @brief Main constructor | ||
86 | /// @throw RuntimeError if the grid is not a level set | ||
87 | LevelSetTracker(GridT& grid, InterruptT* interrupt = nullptr); | ||
88 | |||
89 | ✗ | virtual ~LevelSetTracker() { delete mLeafs; } | |
90 | |||
91 | /// @brief Iterative normalization, i.e. solving the Eikonal equation | ||
92 | /// @note The mask it optional and by default it is ignored. | ||
93 | template <typename MaskType> | ||
94 | void normalize(const MaskType* mask); | ||
95 | |||
96 | /// @brief Iterative normalization, i.e. solving the Eikonal equation | ||
97 | 34 | void normalize() { this->normalize<MaskTreeType>(nullptr); } | |
98 | |||
99 | /// @brief Track the level set interface, i.e. rebuild and normalize the | ||
100 | /// narrow band of the level set. | ||
101 | void track(); | ||
102 | |||
103 | /// @brief Set voxels that are outside the narrow band to the background value | ||
104 | /// (if trimming is enabled) and prune the grid. | ||
105 | /// @details Pruning is done automatically as a step in tracking. | ||
106 | /// @sa @link setTrimming() setTrimming@endlink, @link trimming() trimming@endlink | ||
107 | void prune(); | ||
108 | |||
109 | /// @brief Fast but approximate dilation of the narrow band - one | ||
110 | /// layer at a time. Normally we recommend using the resize method below | ||
111 | /// which internally calls dilate (or erode) with the correct | ||
112 | /// number of @a iterations to achieve the desired half voxel width | ||
113 | /// of the narrow band (3 is recommended for most level set applications). | ||
114 | /// | ||
115 | /// @note Since many level set applications perform | ||
116 | /// interface-tracking, which in turn rebuilds the narrow-band | ||
117 | /// accurately, this dilate method can often be used with a | ||
118 | /// single iterations of low-order re-normalization. This | ||
119 | /// effectively allows very narrow bands to be created from points | ||
120 | /// or polygons (e.g. with a half voxel width of 1), followed by a | ||
121 | /// fast but approximate dilation (typically with a half voxel | ||
122 | /// width of 3). This can be significantly faster than generating | ||
123 | /// the final width of the narrow band from points or polygons. | ||
124 | void dilate(int iterations = 1); | ||
125 | |||
126 | /// @brief Erodes the width of the narrow-band and update the background values | ||
127 | /// @throw ValueError if @a iterations is larger than the current half-width. | ||
128 | void erode(int iterations = 1); | ||
129 | |||
130 | /// @brief Resize the width of the narrow band, i.e. perform | ||
131 | /// dilation and renormalization or erosion as required. | ||
132 | bool resize(Index halfWidth = static_cast<Index>(LEVEL_SET_HALF_WIDTH)); | ||
133 | |||
134 | /// @brief Return the half width of the narrow band in floating-point voxel units. | ||
135 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
4 | ValueType getHalfWidth() const { return mGrid->background()/mDx; } |
136 | |||
137 | /// @brief Return the state of the tracker (see struct defined above) | ||
138 | ✗ | State getState() const { return mState; } | |
139 | |||
140 | /// @brief Set the state of the tracker (see struct defined above) | ||
141 | ✗ | void setState(const State& s) { mState = s; } | |
142 | |||
143 | /// @return the spatial finite difference scheme | ||
144 | 35 | math::BiasedGradientScheme getSpatialScheme() const { return mState.spatialScheme; } | |
145 | |||
146 | /// @brief Set the spatial finite difference scheme | ||
147 | 2 | void setSpatialScheme(math::BiasedGradientScheme s) { mState.spatialScheme = s; } | |
148 | |||
149 | /// @return the temporal integration scheme | ||
150 | 35 | math::TemporalIntegrationScheme getTemporalScheme() const { return mState.temporalScheme; } | |
151 | |||
152 | /// @brief Set the spatial finite difference scheme | ||
153 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | void setTemporalScheme(math::TemporalIntegrationScheme s) { mState.temporalScheme = s;} |
154 | |||
155 | /// @return The number of normalizations performed per track or | ||
156 | /// normalize call. | ||
157 | 36 | int getNormCount() const { return mState.normCount; } | |
158 | |||
159 | /// @brief Set the number of normalizations performed per track or | ||
160 | /// normalize call. | ||
161 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | void setNormCount(int n) { mState.normCount = n; } |
162 | |||
163 | /// @return the grain-size used for multi-threading | ||
164 |
0/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
375 | int getGrainSize() const { return mState.grainSize; } |
165 | |||
166 | /// @brief Set the grain-size used for multi-threading. | ||
167 | /// @note A grainsize of 0 or less disables multi-threading! | ||
168 | ✗ | void setGrainSize(int grainsize) { mState.grainSize = grainsize; } | |
169 | |||
170 | /// @brief Return the trimming mode for voxels outside the narrow band. | ||
171 | /// @details Trimming is enabled by default and is applied automatically prior to pruning. | ||
172 | /// @sa @link setTrimming() setTrimming@endlink, @link prune() prune@endlink | ||
173 | ✗ | TrimMode trimming() const { return mTrimMode; } | |
174 | /// @brief Specify whether to trim voxels outside the narrow band prior to pruning. | ||
175 | /// @sa @link trimming() trimming@endlink, @link prune() prune@endlink | ||
176 | ✗ | void setTrimming(TrimMode mode) { mTrimMode = mode; } | |
177 | |||
178 |
1/240✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 237 not taken.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
|
67 | ValueType voxelSize() const { return mDx; } |
179 | |||
180 | void startInterrupter(const char* msg); | ||
181 | |||
182 | void endInterrupter(); | ||
183 | |||
184 | /// @return false if the process was interrupted | ||
185 | bool checkInterrupter(); | ||
186 | |||
187 |
0/24✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
|
4962 | const GridType& grid() const { return *mGrid; } |
188 | |||
189 |
3/482✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 128 times.
✓ Branch 18 taken 32 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 255 not taken.
✗ Branch 256 not taken.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 261 not taken.
✗ Branch 263 not taken.
✗ Branch 264 not taken.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 270 not taken.
✗ Branch 271 not taken.
✗ Branch 273 not taken.
✗ Branch 274 not taken.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 291 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 306 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 315 not taken.
✗ Branch 316 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 330 not taken.
✗ Branch 331 not taken.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 336 not taken.
✗ Branch 338 not taken.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 345 not taken.
✗ Branch 346 not taken.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 353 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✗ Branch 358 not taken.
✗ Branch 359 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✗ Branch 366 not taken.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✗ Branch 388 not taken.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✗ Branch 398 not taken.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✗ Branch 403 not taken.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✗ Branch 408 not taken.
✗ Branch 409 not taken.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✗ Branch 413 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✗ Branch 418 not taken.
✗ Branch 419 not taken.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✗ Branch 426 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 455 not taken.
✗ Branch 456 not taken.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 461 not taken.
✗ Branch 463 not taken.
✗ Branch 464 not taken.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✗ Branch 468 not taken.
✗ Branch 469 not taken.
✗ Branch 470 not taken.
✗ Branch 471 not taken.
✗ Branch 473 not taken.
✗ Branch 474 not taken.
✗ Branch 475 not taken.
✗ Branch 476 not taken.
✗ Branch 478 not taken.
✗ Branch 479 not taken.
✗ Branch 480 not taken.
✗ Branch 481 not taken.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✗ Branch 488 not taken.
✗ Branch 489 not taken.
✗ Branch 490 not taken.
✗ Branch 491 not taken.
✗ Branch 493 not taken.
✗ Branch 494 not taken.
✗ Branch 495 not taken.
✗ Branch 496 not taken.
✗ Branch 498 not taken.
✗ Branch 499 not taken.
✗ Branch 500 not taken.
✗ Branch 501 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✗ Branch 505 not taken.
✗ Branch 506 not taken.
✗ Branch 508 not taken.
✗ Branch 509 not taken.
✗ Branch 510 not taken.
✗ Branch 511 not taken.
✗ Branch 513 not taken.
✗ Branch 514 not taken.
✗ Branch 515 not taken.
✗ Branch 516 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✗ Branch 520 not taken.
✗ Branch 521 not taken.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✗ Branch 528 not taken.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✗ Branch 531 not taken.
✗ Branch 533 not taken.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✗ Branch 536 not taken.
✗ Branch 538 not taken.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 568 not taken.
✗ Branch 569 not taken.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✗ Branch 581 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 598 not taken.
✗ Branch 599 not taken.
|
779 | LeafManagerType& leafs() { return *mLeafs; } |
190 | |||
191 | ✗ | const LeafManagerType& leafs() const { return *mLeafs; } | |
192 | |||
193 | private: | ||
194 | // disallow copy construction and copy by assignment! | ||
195 | LevelSetTracker(const LevelSetTracker&);// not implemented | ||
196 | LevelSetTracker& operator=(const LevelSetTracker&);// not implemented | ||
197 | |||
198 | // Private class to perform multi-threaded trimming of | ||
199 | // voxels that are too far away from the zero-crossing. | ||
200 | template<TrimMode Trimming> | ||
201 | struct Trim | ||
202 | { | ||
203 | 34 | Trim(LevelSetTracker& tracker) : mTracker(tracker) {} | |
204 | void trim(); | ||
205 | void operator()(const LeafRange& r) const; | ||
206 | LevelSetTracker& mTracker; | ||
207 | };// Trim | ||
208 | |||
209 | // Private struct to perform multi-threaded normalization | ||
210 | template<math::BiasedGradientScheme SpatialScheme, | ||
211 | math::TemporalIntegrationScheme TemporalScheme, | ||
212 | typename MaskT> | ||
213 | 4272 | struct Normalizer | |
214 | { | ||
215 | using SchemeT = math::BIAS_SCHEME<SpatialScheme>; | ||
216 | using StencilT = typename SchemeT::template ISStencil<GridType>::StencilType; | ||
217 | using MaskLeafT = typename MaskT::LeafNodeType; | ||
218 | using MaskIterT = typename MaskLeafT::ValueOnCIter; | ||
219 | using VoxelIterT = typename LeafType::ValueOnCIter; | ||
220 | |||
221 | Normalizer(LevelSetTracker& tracker, const MaskT* mask); | ||
222 | void normalize(); | ||
223 |
2/60✓ Branch 2 taken 681 times.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✓ Branch 54 taken 8288 times.
✗ Branch 55 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
|
10926 | void operator()(const LeafRange& r) const {mTask(const_cast<Normalizer*>(this), r);} |
224 | void cook(const char* msg, int swapBuffer=0); | ||
225 | template <int Nominator, int Denominator> | ||
226 | void euler(const LeafRange& range, Index phiBuffer, Index resultBuffer); | ||
227 | 11808 | inline void euler01(const LeafRange& r) {this->euler<0,1>(r, 0, 1);} | |
228 | 10044 | inline void euler12(const LeafRange& r) {this->euler<1,2>(r, 1, 1);} | |
229 | ✗ | inline void euler34(const LeafRange& r) {this->euler<3,4>(r, 1, 2);} | |
230 | ✗ | inline void euler13(const LeafRange& r) {this->euler<1,3>(r, 1, 2);} | |
231 | template <int Nominator, int Denominator> | ||
232 | void eval(StencilT& stencil, const ValueType* phi, ValueType* result, Index n) const; | ||
233 | LevelSetTracker& mTracker; | ||
234 | const MaskT* mMask; | ||
235 | const ValueType mDt, mInvDx; | ||
236 | typename std::function<void (Normalizer*, const LeafRange&)> mTask; | ||
237 | }; // Normalizer struct | ||
238 | |||
239 | template<math::BiasedGradientScheme SpatialScheme, typename MaskT> | ||
240 | void normalize1(const MaskT* mask); | ||
241 | |||
242 | template<math::BiasedGradientScheme SpatialScheme, | ||
243 | math::TemporalIntegrationScheme TemporalScheme, typename MaskT> | ||
244 | void normalize2(const MaskT* mask); | ||
245 | |||
246 | // Throughout the methods below mLeafs is always assumed to contain | ||
247 | // a list of the current LeafNodes! The auxiliary buffers on the | ||
248 | // other hand always have to be allocated locally, since some | ||
249 | // methods need them and others don't! | ||
250 | GridType* mGrid; | ||
251 | LeafManagerType* mLeafs; | ||
252 | InterruptT* mInterrupter; | ||
253 | const ValueType mDx; | ||
254 | State mState; | ||
255 | TrimMode mTrimMode = TrimMode::kAll; | ||
256 | }; // end of LevelSetTracker class | ||
257 | |||
258 | template<typename GridT, typename InterruptT> | ||
259 | 8 | LevelSetTracker<GridT, InterruptT>:: | |
260 | LevelSetTracker(GridT& grid, InterruptT* interrupt): | ||
261 | mGrid(&grid), | ||
262 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
8 | mLeafs(new LeafManagerType(grid.tree())), |
263 | mInterrupter(interrupt), | ||
264 | 8 | mDx(static_cast<ValueType>(grid.voxelSize()[0])), | |
265 | 16 | mState() | |
266 | { | ||
267 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
8 | if ( !grid.hasUniformVoxels() ) { |
268 | ✗ | OPENVDB_THROW(RuntimeError, | |
269 | "The transform must have uniform scale for the LevelSetTracker to function"); | ||
270 | } | ||
271 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
8 | if ( grid.getGridClass() != GRID_LEVEL_SET) { |
272 | ✗ | OPENVDB_THROW(RuntimeError, | |
273 | "LevelSetTracker expected a level set, got a grid of class \"" | ||
274 | + grid.gridClassToString(grid.getGridClass()) | ||
275 | + "\" [hint: Grid::setGridClass(openvdb::GRID_LEVEL_SET)]"); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | template<typename GridT, typename InterruptT> | ||
280 | void | ||
281 | 68 | LevelSetTracker<GridT, InterruptT>:: | |
282 | prune() | ||
283 | { | ||
284 | this->startInterrupter("Pruning Level Set"); | ||
285 | |||
286 | // Set voxels that are too far away from the zero crossing to the background value. | ||
287 |
1/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
|
68 | switch (mTrimMode) { |
288 | case TrimMode::kNone: break; | ||
289 | ✗ | case TrimMode::kInterior: Trim<TrimMode::kInterior>(*this).trim(); break; | |
290 | ✗ | case TrimMode::kExterior: Trim<TrimMode::kExterior>(*this).trim(); break; | |
291 | 68 | case TrimMode::kAll: Trim<TrimMode::kAll>(*this).trim(); break; | |
292 | } | ||
293 | |||
294 | // Remove inactive nodes from tree | ||
295 | 68 | tools::pruneLevelSet(mGrid->tree()); | |
296 | |||
297 | // The tree topology has changes so rebuild the list of leafs | ||
298 | 68 | mLeafs->rebuildLeafArray(); | |
299 | this->endInterrupter(); | ||
300 | } | ||
301 | |||
302 | template<typename GridT, typename InterruptT> | ||
303 | void | ||
304 | 64 | LevelSetTracker<GridT, InterruptT>:: | |
305 | track() | ||
306 | { | ||
307 | // Dilate narrow-band (this also rebuilds the leaf array!) | ||
308 | 64 | tools::dilateActiveValues( *mLeafs, 1, tools::NN_FACE, tools::IGNORE_TILES); | |
309 | |||
310 | // Compute signed distances in dilated narrow-band | ||
311 | this->normalize(); | ||
312 | |||
313 | // Remove voxels that are outside the narrow band | ||
314 | 64 | this->prune(); | |
315 | } | ||
316 | |||
317 | template<typename GridT, typename InterruptT> | ||
318 | void | ||
319 | 2 | LevelSetTracker<GridT, InterruptT>:: | |
320 | dilate(int iterations) | ||
321 | { | ||
322 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | if (this->getNormCount() == 0) { |
323 | ✗ | for (int i=0; i < iterations; ++i) { | |
324 | ✗ | tools::dilateActiveValues( *mLeafs, 1, tools::NN_FACE, tools::IGNORE_TILES); | |
325 | ✗ | tools::changeLevelSetBackground(this->leafs(), mDx + mGrid->background()); | |
326 | } | ||
327 | } else { | ||
328 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
4 | for (int i=0; i < iterations; ++i) { |
329 | 4 | MaskTreeType mask0(mGrid->tree(), false, TopologyCopy()); | |
330 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | tools::dilateActiveValues( *mLeafs, 1, tools::NN_FACE, tools::IGNORE_TILES); |
331 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | tools::changeLevelSetBackground(this->leafs(), mDx + mGrid->background()); |
332 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
4 | MaskTreeType mask(mGrid->tree(), false, TopologyCopy()); |
333 | mask.topologyDifference(mask0); | ||
334 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | this->normalize(&mask); |
335 | } | ||
336 | } | ||
337 | } | ||
338 | |||
339 | template<typename GridT, typename InterruptT> | ||
340 | void | ||
341 | ✗ | LevelSetTracker<GridT, InterruptT>:: | |
342 | erode(int iterations) | ||
343 | { | ||
344 | ✗ | tools::erodeActiveValues(*mLeafs, iterations, tools::NN_FACE, tools::IGNORE_TILES); | |
345 | ✗ | tools::pruneLevelSet(mLeafs->tree()); | |
346 | ✗ | mLeafs->rebuildLeafArray(); | |
347 | ✗ | const ValueType background = mGrid->background() - ValueType(iterations) * mDx; | |
348 | ✗ | tools::changeLevelSetBackground(this->leafs(), background); | |
349 | } | ||
350 | |||
351 | template<typename GridT, typename InterruptT> | ||
352 | bool | ||
353 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
4 | LevelSetTracker<GridT, InterruptT>:: |
354 | resize(Index halfWidth) | ||
355 | { | ||
356 | 4 | const int wOld = static_cast<int>(math::RoundDown(this->getHalfWidth())); | |
357 | 4 | const int wNew = static_cast<int>(halfWidth); | |
358 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
4 | if (wOld < wNew) { |
359 | 2 | this->dilate(wNew - wOld); | |
360 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
2 | } else if (wOld > wNew) { |
361 | ✗ | this->erode(wOld - wNew); | |
362 | } | ||
363 | 4 | return wOld != wNew; | |
364 | } | ||
365 | |||
366 | template<typename GridT, typename InterruptT> | ||
367 | inline void | ||
368 | ✗ | LevelSetTracker<GridT, InterruptT>:: | |
369 | startInterrupter(const char* msg) | ||
370 | { | ||
371 |
3/240✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 128 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 33 taken 2 times.
✓ Branch 34 taken 32 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 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ 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.
|
180 | if (mInterrupter) mInterrupter->start(msg); |
372 | } | ||
373 | |||
374 | template<typename GridT, typename InterruptT> | ||
375 | inline void | ||
376 | ✗ | LevelSetTracker<GridT, InterruptT>:: | |
377 | endInterrupter() | ||
378 | { | ||
379 |
3/240✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 128 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 33 taken 2 times.
✓ Branch 34 taken 32 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 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ 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.
|
180 | if (mInterrupter) mInterrupter->end(); |
380 | } | ||
381 | |||
382 | template<typename GridT, typename InterruptT> | ||
383 | inline bool | ||
384 | 38284 | LevelSetTracker<GridT, InterruptT>:: | |
385 | checkInterrupter() | ||
386 | { | ||
387 |
2/2✓ Branch 0 taken 540 times.
✓ Branch 1 taken 18602 times.
|
38284 | if (util::wasInterrupted(mInterrupter)) { |
388 | ✗ | thread::cancelGroupExecution(); | |
389 | ✗ | return false; | |
390 | } | ||
391 | return true; | ||
392 | } | ||
393 | |||
394 | template<typename GridT, typename InterruptT> | ||
395 | template<typename MaskT> | ||
396 | void | ||
397 | 35 | LevelSetTracker<GridT, InterruptT>:: | |
398 | normalize(const MaskT* mask) | ||
399 | { | ||
400 |
2/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
|
35 | switch (this->getSpatialScheme()) { |
401 | 3 | case math::FIRST_BIAS: | |
402 | 3 | this->normalize1<math::FIRST_BIAS , MaskT>(mask); break; | |
403 | ✗ | case math::SECOND_BIAS: | |
404 | ✗ | this->normalize1<math::SECOND_BIAS, MaskT>(mask); break; | |
405 | ✗ | case math::THIRD_BIAS: | |
406 | ✗ | this->normalize1<math::THIRD_BIAS, MaskT>(mask); break; | |
407 | ✗ | case math::WENO5_BIAS: | |
408 | ✗ | this->normalize1<math::WENO5_BIAS, MaskT>(mask); break; | |
409 | 32 | case math::HJWENO5_BIAS: | |
410 | 32 | this->normalize1<math::HJWENO5_BIAS, MaskT>(mask); break; | |
411 | case math::UNKNOWN_BIAS: | ||
412 | default: | ||
413 | ✗ | OPENVDB_THROW(ValueError, "Spatial difference scheme not supported!"); | |
414 | } | ||
415 | 35 | } | |
416 | |||
417 | template<typename GridT, typename InterruptT> | ||
418 | template<math::BiasedGradientScheme SpatialScheme, typename MaskT> | ||
419 | void | ||
420 | 70 | LevelSetTracker<GridT, InterruptT>:: | |
421 | normalize1(const MaskT* mask) | ||
422 | { | ||
423 |
2/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
70 | switch (this->getTemporalScheme()) { |
424 | 6 | case math::TVD_RK1: | |
425 | 6 | this->normalize2<SpatialScheme, math::TVD_RK1, MaskT>(mask); break; | |
426 | 64 | case math::TVD_RK2: | |
427 | 64 | this->normalize2<SpatialScheme, math::TVD_RK2, MaskT>(mask); break; | |
428 | ✗ | case math::TVD_RK3: | |
429 | ✗ | this->normalize2<SpatialScheme, math::TVD_RK3, MaskT>(mask); break; | |
430 | case math::UNKNOWN_TIS: | ||
431 | default: | ||
432 | ✗ | OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!"); | |
433 | } | ||
434 | } | ||
435 | |||
436 | template<typename GridT, typename InterruptT> | ||
437 | template<math::BiasedGradientScheme SpatialScheme, | ||
438 | math::TemporalIntegrationScheme TemporalScheme, | ||
439 | typename MaskT> | ||
440 | void | ||
441 | 70 | LevelSetTracker<GridT, InterruptT>:: | |
442 | normalize2(const MaskT* mask) | ||
443 | { | ||
444 | Normalizer<SpatialScheme, TemporalScheme, MaskT> tmp(*this, mask); | ||
445 |
1/2✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
|
70 | tmp.normalize(); |
446 | } | ||
447 | |||
448 | |||
449 | //////////////////////////////////////////////////////////////////////////// | ||
450 | |||
451 | |||
452 | template<typename GridT, typename InterruptT> | ||
453 | template<lstrack::TrimMode Trimming> | ||
454 | void | ||
455 | 68 | LevelSetTracker<GridT, InterruptT>::Trim<Trimming>::trim() | |
456 | { | ||
457 | OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN | ||
458 | if (Trimming != TrimMode::kNone) { | ||
459 | 68 | const int grainSize = mTracker.getGrainSize(); | |
460 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
68 | const LeafRange range = mTracker.leafs().leafRange(grainSize); |
461 | |||
462 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
68 | if (grainSize>0) { |
463 | 68 | tbb::parallel_for(range, *this); | |
464 | } else { | ||
465 | ✗ | (*this)(range); | |
466 | } | ||
467 | } | ||
468 | OPENVDB_NO_UNREACHABLE_CODE_WARNING_END | ||
469 | } | ||
470 | |||
471 | |||
472 | /// Trim away voxels that have moved outside the narrow band | ||
473 | template<typename GridT, typename InterruptT> | ||
474 | template<lstrack::TrimMode Trimming> | ||
475 | inline void | ||
476 | 3456 | LevelSetTracker<GridT, InterruptT>::Trim<Trimming>::operator()(const LeafRange& range) const | |
477 | { | ||
478 | 3456 | mTracker.checkInterrupter(); | |
479 | 3456 | const ValueType gamma = mTracker.mGrid->background(); | |
480 | |||
481 | OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN | ||
482 |
2/2✓ Branch 1 taken 1728 times.
✓ Branch 2 taken 1728 times.
|
6912 | for (auto leafIter = range.begin(); leafIter; ++leafIter) { |
483 | 3456 | auto& leaf = *leafIter; | |
484 |
2/2✓ Branch 0 taken 293051 times.
✓ Branch 1 taken 1728 times.
|
589558 | for (auto iter = leaf.beginValueOn(); iter; ++iter) { |
485 | 586102 | const auto val = *iter; | |
486 | switch (Trimming) { // resolved at compile time | ||
487 | case TrimMode::kNone: | ||
488 | break; | ||
489 | case TrimMode::kInterior: | ||
490 | ✗ | if (val <= -gamma) { leaf.setValueOff(iter.pos(), -gamma); } | |
491 | break; | ||
492 | case TrimMode::kExterior: | ||
493 | ✗ | if (val >= gamma) { leaf.setValueOff(iter.pos(), gamma); } | |
494 | break; | ||
495 | case TrimMode::kAll: | ||
496 |
2/2✓ Branch 0 taken 11737 times.
✓ Branch 1 taken 281314 times.
|
586102 | if (val <= -gamma) { |
497 | 23474 | leaf.setValueOff(iter.pos(), -gamma); | |
498 |
2/2✓ Branch 0 taken 57474 times.
✓ Branch 1 taken 223840 times.
|
562628 | } else if (val >= gamma) { |
499 | 114948 | leaf.setValueOff(iter.pos(), gamma); | |
500 | } | ||
501 | break; | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | OPENVDB_NO_UNREACHABLE_CODE_WARNING_END | ||
506 | } | ||
507 | |||
508 | |||
509 | //////////////////////////////////////////////////////////////////////////// | ||
510 | |||
511 | template<typename GridT, typename InterruptT> | ||
512 | template<math::BiasedGradientScheme SpatialScheme, | ||
513 | math::TemporalIntegrationScheme TemporalScheme, | ||
514 | typename MaskT> | ||
515 | inline | ||
516 | 35 | LevelSetTracker<GridT, InterruptT>:: | |
517 | Normalizer<SpatialScheme, TemporalScheme, MaskT>:: | ||
518 | Normalizer(LevelSetTracker& tracker, const MaskT* mask) | ||
519 | : mTracker(tracker) | ||
520 | , mMask(mask) | ||
521 | 35 | , mDt(tracker.voxelSize()*(TemporalScheme == math::TVD_RK1 ? 0.3f : | |
522 | TemporalScheme == math::TVD_RK2 ? 0.9f : 1.0f)) | ||
523 | 35 | , mInvDx(1.0f/tracker.voxelSize()) | |
524 |
2/60✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 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 taken 3 times.
✗ 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 not taken.
✗ Branch 89 not taken.
|
35 | , mTask(nullptr) |
525 | { | ||
526 | } | ||
527 | |||
528 | template<typename GridT, typename InterruptT> | ||
529 | template<math::BiasedGradientScheme SpatialScheme, | ||
530 | math::TemporalIntegrationScheme TemporalScheme, | ||
531 | typename MaskT> | ||
532 | inline void | ||
533 | 70 | LevelSetTracker<GridT, InterruptT>:: | |
534 | Normalizer<SpatialScheme, TemporalScheme, MaskT>:: | ||
535 | normalize() | ||
536 | { | ||
537 | namespace ph = std::placeholders; | ||
538 | |||
539 | /// Make sure we have enough temporal auxiliary buffers | ||
540 | 70 | mTracker.mLeafs->rebuildAuxBuffers(TemporalScheme == math::TVD_RK3 ? 2 : 1); | |
541 | |||
542 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 35 times.
|
304 | for (int n=0, e=mTracker.getNormCount(); n < e; ++n) { |
543 | |||
544 | OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN | ||
545 | switch(TemporalScheme) {//switch is resolved at compile-time | ||
546 | 42 | case math::TVD_RK1: | |
547 | // Perform one explicit Euler step: t1 = t0 + dt | ||
548 | // Phi_t1(0) = Phi_t0(0) - dt * VdotG_t0(1) | ||
549 | 42 | mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2); | |
550 | |||
551 | // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1) | ||
552 | 42 | this->cook("Normalizing level set using TVD_RK1", 1); | |
553 | break; | ||
554 | 192 | case math::TVD_RK2: | |
555 | // Perform one explicit Euler step: t1 = t0 + dt | ||
556 | // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1) | ||
557 | 192 | mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2); | |
558 | |||
559 | // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1) | ||
560 | 192 | this->cook("Normalizing level set using TVD_RK1 (step 1 of 2)", 1); | |
561 | |||
562 | // Convex combine explicit Euler step: t2 = t0 + dt | ||
563 | // Phi_t2(1) = 1/2 * Phi_t0(1) + 1/2 * (Phi_t1(0) - dt * V.Grad_t1(0)) | ||
564 | 192 | mTask = std::bind(&Normalizer::euler12, ph::_1, ph::_2); | |
565 | |||
566 | // Cook and swap buffer 0 and 1 such that Phi_t2(0) and Phi_t1(1) | ||
567 | 192 | this->cook("Normalizing level set using TVD_RK1 (step 2 of 2)", 1); | |
568 | break; | ||
569 | ✗ | case math::TVD_RK3: | |
570 | // Perform one explicit Euler step: t1 = t0 + dt | ||
571 | // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1) | ||
572 | ✗ | mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2); | |
573 | |||
574 | // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1) | ||
575 | ✗ | this->cook("Normalizing level set using TVD_RK3 (step 1 of 3)", 1); | |
576 | |||
577 | // Convex combine explicit Euler step: t2 = t0 + dt/2 | ||
578 | // Phi_t2(2) = 3/4 * Phi_t0(1) + 1/4 * (Phi_t1(0) - dt * V.Grad_t1(0)) | ||
579 | ✗ | mTask = std::bind(&Normalizer::euler34, ph::_1, ph::_2); | |
580 | |||
581 | // Cook and swap buffer 0 and 2 such that Phi_t2(0) and Phi_t1(2) | ||
582 | ✗ | this->cook("Normalizing level set using TVD_RK3 (step 2 of 3)", 2); | |
583 | |||
584 | // Convex combine explicit Euler step: t3 = t0 + dt | ||
585 | // Phi_t3(2) = 1/3 * Phi_t0(1) + 2/3 * (Phi_t2(0) - dt * V.Grad_t2(0) | ||
586 | ✗ | mTask = std::bind(&Normalizer::euler13, ph::_1, ph::_2); | |
587 | |||
588 | // Cook and swap buffer 0 and 2 such that Phi_t3(0) and Phi_t2(2) | ||
589 | ✗ | this->cook("Normalizing level set using TVD_RK3 (step 3 of 3)", 2); | |
590 | break; | ||
591 | case math::UNKNOWN_TIS: | ||
592 | default: | ||
593 | OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!"); | ||
594 | } | ||
595 | OPENVDB_NO_UNREACHABLE_CODE_WARNING_END | ||
596 | } | ||
597 | 70 | mTracker.mLeafs->removeAuxBuffers(); | |
598 | } | ||
599 | |||
600 | /// Private method to perform the task (serial or threaded) and | ||
601 | /// subsequently swap the leaf buffers. | ||
602 | template<typename GridT, typename InterruptT> | ||
603 | template<math::BiasedGradientScheme SpatialScheme, | ||
604 | math::TemporalIntegrationScheme TemporalScheme, | ||
605 | typename MaskT> | ||
606 | inline void | ||
607 | 426 | LevelSetTracker<GridT, InterruptT>:: | |
608 | Normalizer<SpatialScheme, TemporalScheme, MaskT>:: | ||
609 | cook(const char* msg, int swapBuffer) | ||
610 | { | ||
611 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 195 times.
|
426 | mTracker.startInterrupter( msg ); |
612 | |||
613 | 426 | const int grainSize = mTracker.getGrainSize(); | |
614 |
1/2✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
|
426 | const LeafRange range = mTracker.leafs().leafRange(grainSize); |
615 | |||
616 |
1/2✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
|
426 | grainSize>0 ? tbb::parallel_for(range, *this) : (*this)(range); |
617 | |||
618 | 426 | mTracker.leafs().swapLeafBuffer(swapBuffer, grainSize==0); | |
619 | |||
620 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 195 times.
|
426 | mTracker.endInterrupter(); |
621 | } | ||
622 | |||
623 | template<typename GridT, typename InterruptT> | ||
624 | template<math::BiasedGradientScheme SpatialScheme, | ||
625 | math::TemporalIntegrationScheme TemporalScheme, | ||
626 | typename MaskT> | ||
627 | template <int Nominator, int Denominator> | ||
628 | inline void | ||
629 | 3586962 | LevelSetTracker<GridT, InterruptT>:: | |
630 | Normalizer<SpatialScheme, TemporalScheme, MaskT>:: | ||
631 | eval(StencilT& stencil, const ValueType* phi, ValueType* result, Index n) const | ||
632 | { | ||
633 | using GradientT = typename math::ISGradientNormSqrd<SpatialScheme>; | ||
634 | static const ValueType alpha = ValueType(Nominator)/ValueType(Denominator); | ||
635 | static const ValueType beta = ValueType(1) - alpha; | ||
636 | |||
637 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58599 times.
|
3586962 | const ValueType normSqGradPhi = GradientT::result(stencil); |
638 | 3586962 | const ValueType phi0 = stencil.getValue(); | |
639 | 3586962 | ValueType v = phi0 / ( math::Sqrt(math::Pow2(phi0) + normSqGradPhi) + | |
640 | math::Tolerance<ValueType>::value() ); | ||
641 | 3586962 | v = phi0 - mDt * v * (math::Sqrt(normSqGradPhi) * mInvDx - 1.0f); | |
642 | 3586962 | result[n] = Nominator ? alpha * phi[n] + beta * v : v; | |
643 | } | ||
644 | |||
645 | template<typename GridT, typename InterruptT> | ||
646 | template<math::BiasedGradientScheme SpatialScheme, | ||
647 | math::TemporalIntegrationScheme TemporalScheme, | ||
648 | typename MaskT> | ||
649 | template <int Nominator, int Denominator> | ||
650 | inline void | ||
651 | 21852 | LevelSetTracker<GridT,InterruptT>:: | |
652 | Normalizer<SpatialScheme, TemporalScheme, MaskT>:: | ||
653 | euler(const LeafRange& range, Index phiBuffer, Index resultBuffer) | ||
654 | { | ||
655 | 21852 | mTracker.checkInterrupter(); | |
656 | |||
657 | 21852 | StencilT stencil(mTracker.grid()); | |
658 | |||
659 |
2/2✓ Branch 1 taken 11061 times.
✓ Branch 2 taken 10926 times.
|
43974 | for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) { |
660 |
1/2✓ Branch 2 taken 11061 times.
✗ Branch 3 not taken.
|
22122 | const ValueType* phi = leafIter.buffer(phiBuffer).data(); |
661 |
1/2✓ Branch 2 taken 11061 times.
✗ Branch 3 not taken.
|
22122 | ValueType* result = leafIter.buffer(resultBuffer).data(); |
662 |
2/2✓ Branch 0 taken 10530 times.
✓ Branch 1 taken 531 times.
|
22122 | if (mMask == nullptr) { |
663 |
2/2✓ Branch 0 taken 1770018 times.
✓ Branch 1 taken 10530 times.
|
3561096 | for (auto iter = leafIter->cbeginValueOn(); iter; ++iter) { |
664 |
1/2✓ Branch 1 taken 1770018 times.
✗ Branch 2 not taken.
|
3540036 | stencil.moveTo(iter); |
665 | 3540036 | this->eval<Nominator, Denominator>(stencil, phi, result, iter.pos()); | |
666 | }//loop over active voxels in the leaf of the level set | ||
667 |
1/2✓ Branch 0 taken 531 times.
✗ Branch 1 not taken.
|
1062 | } else if (const MaskLeafT* mask = mMask->probeLeaf(leafIter->origin())) { |
668 |
1/2✓ Branch 1 taken 531 times.
✗ Branch 2 not taken.
|
1062 | const ValueType* phi0 = leafIter->buffer().data(); |
669 |
2/2✓ Branch 0 taken 23463 times.
✓ Branch 1 taken 531 times.
|
47988 | for (MaskIterT iter = mask->cbeginValueOn(); iter; ++iter) { |
670 | const Index i = iter.pos(); | ||
671 |
1/2✓ Branch 1 taken 23463 times.
✗ Branch 2 not taken.
|
46926 | stencil.moveTo(iter.getCoord(), phi0[i]); |
672 | 46926 | this->eval<Nominator, Denominator>(stencil, phi, result, i); | |
673 | }//loop over active voxels in the leaf of the mask | ||
674 | } | ||
675 | }//loop over leafs of the level set | ||
676 | } | ||
677 | |||
678 | |||
679 | //////////////////////////////////////// | ||
680 | |||
681 | |||
682 | // Explicit Template Instantiation | ||
683 | |||
684 | #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION | ||
685 | |||
686 | #ifdef OPENVDB_INSTANTIATE_LEVELSETTRACKER | ||
687 | #include <openvdb/util/ExplicitInstantiation.h> | ||
688 | #endif | ||
689 | |||
690 | OPENVDB_INSTANTIATE_CLASS LevelSetTracker<FloatGrid, util::NullInterrupter>; | ||
691 | OPENVDB_INSTANTIATE_CLASS LevelSetTracker<DoubleGrid, util::NullInterrupter>; | ||
692 | |||
693 | #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION | ||
694 | |||
695 | |||
696 | } // namespace tools | ||
697 | } // namespace OPENVDB_VERSION_NAME | ||
698 | } // namespace openvdb | ||
699 | |||
700 | #endif // OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED | ||
701 |