sources/source_chain.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// @file | ||
| 2 | /// @brief Sources tried in order, each filling the gaps of those before it. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "terraingen/sources/source.h" | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | namespace terraingen { | ||
| 11 | |||
| 12 | /// Sources tried in order, each filling where those before it have no data, such as a site | ||
| 13 | /// DEM over a regional one or a DEM over a flat datum. The sources must share coordinates; the | ||
| 14 | /// chain takes its grid and reference point from the first. | ||
| 15 | class SourceChain final : public Source { | ||
| 16 | public: | ||
| 17 | /// The chain of `sources`, first first. | ||
| 18 | /// @throws std::invalid_argument for no sources or a null one. | ||
| 19 | explicit SourceChain(std::vector<std::shared_ptr<const Source>> sources); | ||
| 20 | |||
| 21 | /// The first source's grid. | ||
| 22 | 5 | RasterGrid Grid() const override { | |
| 23 | 5 | return sources_.front()->Grid(); | |
| 24 | } | ||
| 25 | |||
| 26 | /// The first source's reference point. | ||
| 27 | 1 | Vec2d ReferencePoint() const override { | |
| 28 | 1 | return sources_.front()->ReferencePoint(); | |
| 29 | } | ||
| 30 | |||
| 31 | /// The first source's projection. | ||
| 32 | 1 | GeoKeys Keys() const override { | |
| 33 | 1 | return sources_.front()->Keys(); | |
| 34 | } | ||
| 35 | |||
| 36 | /// Fills from the first source, then each cell still without data from the next source | ||
| 37 | /// that has data there, keeping the first source's no-data value. | ||
| 38 | void Fill(Raster<float>& heights) const override; | ||
| 39 | |||
| 40 | /// The first height in metres at world point (`x`, `y`) that is not NaN; NaN if no source has | ||
| 41 | /// one. | ||
| 42 | float HeightAt(double x, double y) const override; | ||
| 43 | |||
| 44 | /// The sources in the order they are tried. | ||
| 45 | 1 | const std::vector<std::shared_ptr<const Source>>& Sources() const { | |
| 46 | 1 | return sources_; | |
| 47 | } | ||
| 48 | |||
| 49 | private: | ||
| 50 | std::vector<std::shared_ptr<const Source>> sources_; | ||
| 51 | }; | ||
| 52 | |||
| 53 | } // namespace terraingen | ||
| 54 |