./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
3 / 3
100.0%
Branches:
1 / 4
25.0%
Functions:
-
-%

include/terraingen/albedo/slope_albedo.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Slope maturity: steep ground kept fresh, and bright, by regolith moving downslope.
5 #pragma once
6
7 #include "terraingen/albedo/albedo.h"
8 #include "terraingen/albedo/maturity.h"
9 #include "terraingen/geometry/surface.h"
10
11 #include <vector>
12
13 namespace terraingen {
14
15 /// How steep ground stays immature as regolith moves downslope (Ikeda et al. 2022; Lucey et al.
16 /// 2014; Boyd and Robinson 2019): OMAT rises by `maturityPerDegree` beyond `onsetDegrees`, capped
17 /// at `maxMaturity`, and the albedo moves with it (`ReflectanceAtMaturity`).
18 2 struct SlopeAlbedoOptions {
19 double onsetDegrees = 20.0; ///< Slope from which ground freshens, in [0, 90).
20 double maturityPerDegree = 0.0065; ///< OMAT gained per degree beyond the onset; >= 0.
21 double backgroundMaturity = 0.10; ///< OMAT of gentler ground; positive.
22 double maxMaturity = 0.42; ///< Cap on OMAT; >= `backgroundMaturity`.
23 double baseline = 10.0; ///< Meters slopes are measured over; positive.
24 /// Reflectance of the optical maturity origin (`ReflectanceAtMaturity`).
25 double originReflectance = kOpticalMaturityOriginReflectance;
26
27 bool operator==(const SlopeAlbedoOptions& other) const {
28 return onsetDegrees == other.onsetDegrees && maturityPerDegree == other.maturityPerDegree &&
29 backgroundMaturity == other.backgroundMaturity && maxMaturity == other.maxMaturity &&
30 baseline == other.baseline && originReflectance == other.originReflectance;
31 }
32 bool operator!=(const SlopeAlbedoOptions& other) const {
33 return !(*this == other);
34 }
35 };
36
37 /// Checks slope maturity options.
38 /// @throws std::invalid_argument naming the first field out of its range, or for a cap below the
39 /// background maturity.
40 void ValidateSlopeAlbedoOptions(const SlopeAlbedoOptions& options);
41
42 /// The albedo of steep ground moved toward fresher material: slopes are read on the ground at the
43 /// nodes of a lattice `baseline` meters apart, fixed to the surface, and interpolated between
44 /// them, so grids, tiles and points agree. Without a ground the albedo is left alone.
45
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7 class SlopeAlbedo final : public AlbedoLayer {
46 public:
47 /// @throws std::invalid_argument for options invalid as `ValidateSlopeAlbedoOptions`.
48 explicit SlopeAlbedo(SlopeAlbedoOptions options = {});
49
50 /// Moves `value` to the maturity of the slope at (`x`, `y`); NaN stays NaN.
51 void ApplyAt(AlbedoSample& value, std::size_t bands, double x, double y,
52 const LayerContext& context) const override;
53
54 /// `ApplyAt` at every cell center, the lattice read once.
55 void Apply(std::vector<Raster<float>>& bands, const LayerContext& context) const override;
56
57 /// The slope in degrees at (`x`, `y`) on `ground` lying on `surface`, interpolated between
58 /// lattice nodes.
59 double SlopeAt(double x, double y, const Ground& ground, const Surface& surface = {}) const;
60
61 /// The OMAT of ground of `slopeDegrees`.
62 double MaturityAt(double slopeDegrees) const;
63
64 private:
65 struct Lattice;
66
67 /// The lattice nodes on `surface` covering `region` and one node beyond, their heights read on
68 /// `ground`.
69 Lattice ReadLattice(const Bounds2d& region, const Ground& ground, const Surface& surface) const;
70 /// The slope at (`x`, `y`) from the nodes of `lattice` around it.
71 static double Interpolate(const Lattice& lattice, double x, double y);
72 void Mature(AlbedoSample& value, std::size_t bands, double slopeDegrees) const;
73
74 SlopeAlbedoOptions m_options;
75 };
76
77 } // namespace terraingen
78