./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
6 / 6
100.0%
Branches:
-
-%
Functions:
-
-%

include/terraingen/albedo/rock_albedo.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Rock albedo: boulders and the rocks too small to resolve, brighter than the regolith.
5 #pragma once
6
7 #include "terraingen/albedo/albedo.h"
8 #include "terraingen/layers/boulders/boulder_layer.h"
9
10 #include <cstdint>
11 #include <memory>
12 #include <vector>
13
14 namespace terraingen {
15
16 /// How rocks, brighter than mature regolith (Holt 1981; Clark et al. 2002; Marshal et al. 2023),
17 /// brighten the albedo: resolved boulders where they stand, unresolved rock by a per-sample draw
18 /// of the share it covers.
19 5 struct RockAlbedoOptions {
20 std::uint32_t seed = 0; ///< Seed of the per-sample draws of unresolved rock.
21 double reflectanceRatio = 2.5; ///< Rock over regolith reflectance; positive.
22 bool unresolved = true; ///< Whether rocks too small to resolve brighten samples.
23
24 bool operator==(const RockAlbedoOptions& other) const {
25 return seed == other.seed && reflectanceRatio == other.reflectanceRatio &&
26 unresolved == other.unresolved;
27 }
28 bool operator!=(const RockAlbedoOptions& other) const {
29 return !(*this == other);
30 }
31 };
32
33 /// Checks rock albedo options.
34 /// @throws std::invalid_argument naming the first field out of its range.
35 void ValidateRockAlbedoOptions(const RockAlbedoOptions& options);
36
37 /// A boulder layer whose rock brightens the albedo, and the ground beneath it.
38 6 struct RockSource {
39 std::shared_ptr<const BoulderLayer> layer; ///< The boulders; must not be null.
40 /// The ground the layer was applied to, read under its boulders; must not be null.
41 std::shared_ptr<const Ground> ground;
42 };
43
44 /// The share of a sample rock covers, from the share its resolved boulders cover and a draw
45 /// `normal` (standard normal) of the share unresolved rock covers of the rest: log-normal with
46 /// the mean and variance of `unresolved`, at most 1.
47 double RockShare(double resolved, const UnresolvedCover& unresolved, double normal);
48
49 /// The albedo brightened by the rock of boulder layers: each band times 1 + `share`
50 /// (`reflectanceRatio` - 1), for the share of each sample rock covers over every layer.
51 8 class RockAlbedo final : public AlbedoLayer {
52 public:
53 /// @throws std::invalid_argument for options invalid as `ValidateRockAlbedoOptions`, or a
54 /// source without a layer or ground.
55 RockAlbedo(RockAlbedoOptions options, std::vector<RockSource> sources);
56
57 void ApplyAt(AlbedoSample& value, std::size_t bands, double x, double y,
58 const LayerContext& context) const override;
59
60 void Apply(std::vector<Raster<float>>& bands, const LayerContext& context) const override;
61
62 /// The share of the sample at (`x`, `y`) rock covers, over every layer.
63 double ShareAt(double x, double y, const LayerContext& context) const;
64
65 private:
66 /// The standard normal drawn for unresolved rock of source `source` at (`x`, `y`).
67 double UnresolvedNormal(double x, double y, std::size_t source) const;
68 /// The share of each cell of the grid of `first` that no source's rock covers, row-major.
69 std::vector<double> BareShares(const Raster<float>& first, const LayerContext& context) const;
70
71 RockAlbedoOptions m_options;
72 std::vector<RockSource> m_sources;
73 };
74
75 } // namespace terraingen
76