TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
4 / 4
100.0%
Branches:
3 / 6
50.0%
Functions:
1 / 1, 1 excl
100.0%

albedo/rock_albedo.h
Line Branch Exec Source
1 /// @file
2 /// @brief Rock albedo: boulders and the rocks too small to resolve, brighter than the regolith.
3 #pragma once
4
5 #include "terraingen/albedo/albedo.h"
6 #include "terraingen/layers/boulders/boulder_layer.h"
7
8 #include <cstdint>
9 #include <memory>
10 #include <vector>
11
12 namespace terraingen {
13
14 /// How rocks brighten the albedo. Rock reflects more than mature regolith: Holt (1981) measured
15 /// normal albedos of 18 to 51% for rocks at the Apollo 16 site against 14 to 15% for its most
16 /// mature soils; Marshal et al. (2023) model rock about 2.5 times as reflective as regolith,
17 /// within the near 3 times of Apollo 16 fragmental breccias (Clark et al. 2002), and earlier
18 /// models took about 1.5 times. Boulders an albedo resolves brighten where their rock stands;
19 /// smaller ones brighten each sample by the share of it they cover, drawn per sample about its
20 /// expected share with the variance of Poisson-scattered rocks, which unresolved cobbles show as
21 /// bright pixels (Marshal et al. 2023).
22 struct RockAlbedoOptions {
23 1 std::uint32_t seed = 0; ///< Seed of the per-sample draws of unresolved rock.
24 1 double reflectanceRatio = 2.5; ///< Rock over regolith reflectance; positive.
25 1 bool unresolved = true; ///< Whether rocks too small to resolve brighten samples.
26
27
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
1 bool operator==(const RockAlbedoOptions&) const = default;
28 };
29
30 /// Checks rock albedo options.
31 /// @throws std::invalid_argument for a reflectance ratio that is not positive and finite.
32 void ValidateRockAlbedo(const RockAlbedoOptions& options);
33
34 /// A boulder layer whose rock brightens the albedo, and the ground beneath it.
35 struct RockSource {
36 std::shared_ptr<const BoulderLayer> layer;
37 /// The ground the layer was applied to, read under its boulders; must not be null.
38 std::shared_ptr<const Ground> ground;
39 };
40
41 /// The share of a sample rock covers, from the share its resolved boulders cover and a draw
42 /// `normal` (standard normal) of the share unresolved rock covers of the rest: log-normal with
43 /// the mean and variance of `unresolved`, at most 1.
44 double RockShare(double resolved, const UnresolvedCover& unresolved, double normal);
45
46 /// The albedo brightened by the rock of boulder layers: each band times 1 + `share`
47 /// (`reflectanceRatio` - 1), for the share of each sample rock covers over every layer.
48 class RockAlbedo final : public AlbedoLayer {
49 public:
50 /// @throws std::invalid_argument for options invalid as `ValidateRockAlbedo`, or a source
51 /// without a layer or ground.
52 RockAlbedo(RockAlbedoOptions options, std::vector<RockSource> sources);
53
54 /// Brightens `value` by the rock at (`x`, `y`); NaN stays NaN.
55 void ApplyAt(AlbedoSample& value, std::size_t bands, double x, double y,
56 const AlbedoContext& context) const override;
57
58 /// `ApplyAt` at every cell centre, the boulders found once per layer.
59 void Apply(std::vector<Raster<float>>& bands, const AlbedoContext& context) const override;
60
61 /// The share of the sample at (`x`, `y`) rock covers, over every layer.
62 double ShareAt(double x, double y, const AlbedoContext& context) const;
63
64 private:
65 /// The standard normal drawn for unresolved rock of source `source` at (`x`, `y`).
66 double Draw(double x, double y, std::size_t source) const;
67
68 RockAlbedoOptions options_;
69 std::vector<RockSource> sources_;
70 };
71
72 } // namespace terraingen
73