| 257 | } |
| 258 | |
| 259 | void dilateDiamond(std::vector<double>& data, size_t rows, size_t cols, int iterations) |
| 260 | { |
| 261 | std::vector<double> out(data.size(), std::numeric_limits<double>::lowest()); |
| 262 | std::array<size_t, 5> idx; |
| 263 | |
| 264 | for (int iter = 0; iter < iterations; ++iter) |
| 265 | { |
| 266 | for (size_t col = 0; col < cols; ++col) |
| 267 | { |
| 268 | size_t index = col*rows; |
| 269 | for (size_t row = 0; row < rows; ++row) |
| 270 | { |
| 271 | // Find the index into the vector of the current cell. Then |
| 272 | // find the index of the cells to the right/left/above/below |
| 273 | // if they exist. |
| 274 | size_t j = 0; |
| 275 | idx[j++] = index+row; |
| 276 | if (row > 0) |
| 277 | idx[j++] = idx[0]-1; |
| 278 | if (row < rows-1) |
| 279 | idx[j++] = idx[0]+1; |
| 280 | if (col > 0) |
| 281 | idx[j++] = idx[0]-rows; |
| 282 | if (col < cols-1) |
| 283 | idx[j++] = idx[0]+rows; |
| 284 | // If the data at the test cell pos is greater than that |
| 285 | // from the last iteration, set the value to the maximum of |
| 286 | // the value of those cells. |
| 287 | for (size_t i = 0; i < j; ++i) |
| 288 | { |
| 289 | if (data[idx[i]] > out[index+row]) |
| 290 | out[index+row] = data[idx[i]]; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | data.swap(out); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | void erodeDiamond(std::vector<double>& data, size_t rows, size_t cols, |
| 299 | int iterations) |