src/sources/seam_field.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief The correction a source chain's seam adds to a later source in an earlier one's gaps. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/raster/grid.h" | ||
| 8 | #include "terraingen/sources/source.h" | ||
| 9 | #include "terraingen/sources/source_chain.h" | ||
| 10 | |||
| 11 | #include <cstddef> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | namespace terraingen::detail { | ||
| 15 | |||
| 16 | /// A correction in meters at the posts of a lattice, read between them by Catmull-Rom | ||
| 17 | /// interpolation, and 0 at posts never set and off the lattice. Posts are kept in square tiles, | ||
| 18 | /// only those holding a post that was set. | ||
| 19 | 91 | class SeamField { | |
| 20 | public: | ||
| 21 | /// The field that is 0 everywhere. | ||
| 22 | 11 | SeamField() = default; | |
| 23 | |||
| 24 | /// A field over `lattice`, 0 at every post until set. | ||
| 25 | explicit SeamField(const RasterGrid& lattice); | ||
| 26 | |||
| 27 | /// The correction at world point (`x`, `y`). | ||
| 28 | double At(double x, double y) const; | ||
| 29 | |||
| 30 | /// The value at post (`col`, `row`); 0 off the lattice. | ||
| 31 | float Post(std::ptrdiff_t col, std::ptrdiff_t row) const; | ||
| 32 | |||
| 33 | /// Sets the value at post (`col`, `row`) of the lattice. | ||
| 34 | void Set(std::size_t col, std::size_t row, float value); | ||
| 35 | |||
| 36 | private: | ||
| 37 | RasterGrid m_lattice{}; | ||
| 38 | std::size_t m_tileColumns = 0; | ||
| 39 | bool m_set = false; | ||
| 40 | std::vector<std::vector<float>> m_tiles{}; | ||
| 41 | }; | ||
| 42 | |||
| 43 | /// The correction `seams` add to `later` where `earlier` has no data, solved on the posts of | ||
| 44 | /// `grid` widened by the seam's reach (`SeamLattice`) with `earlier` and `later` sampled there at | ||
| 45 | /// the cell size of `grid`. The posts with data near a gap hold `earlier` minus `later`, which the | ||
| 46 | /// gap's posts are solved to meet; the field is 0 for `ChainSeamMode::None`, when `earlier` has | ||
| 47 | /// data at every post or at none, and from the seam's reach on. | ||
| 48 | /// @throws std::invalid_argument as `SeamLattice`. | ||
| 49 | SeamField BuildSeamField(const Source& earlier, const Source& later, const RasterGrid& grid, | ||
| 50 | const ChainSeams& seams); | ||
| 51 | |||
| 52 | } // namespace terraingen::detail | ||
| 53 |