./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
279 / 303
92.1%
Branches:
65 / 88
73.9%
Functions:
43 / 45, 2 excl
95.6%

src/config/layers.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief A configuration's layers: noise, roughness, bedforms, transforms and masked layers, the
5 /// layer variant, and checking and building every layer in order.
6 #pragma once
7
8 #include "config/boulders.h"
9 #include "config/craters.h"
10 #include "config/layer_context.h"
11
12 #include "terraingen/analysis/spectrum.h"
13 #include "terraingen/layers/bedforms_fields.h"
14 #include "terraingen/layers/dunes_fields.h"
15 #include "terraingen/layers/masked.h"
16 #include "terraingen/layers/pavement_fields.h"
17 #include "terraingen/layers/roughness_estimate.h"
18
19 #include <algorithm>
20 #include <array>
21 #include <cstddef>
22 #include <cstdint>
23 #include <memory>
24 #include <optional>
25 #include <string>
26 #include <string_view>
27 #include <variant>
28 #include <vector>
29
30 namespace terraingen {
31
32 /// Layer "noise": a stack of 1 to `kMaxFractals` noise layers added to the terrain
33 /// (`NoiseLayer`), measured from the source's reference point.
34
16/28
✗ Branch 5 not taken.
✓ Branch 6 taken 110 times.
✓ Branch 7 taken 1 time.
✓ Branch 7 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 110 times.
✓ Branch 10 taken 3 times.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 15 not taken.
✓ Branch 15 taken 14 times.
✓ Branch 16 taken 3 times.
✓ Branch 16 taken 1 time.
✗ Branch 18 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 3 times.
✓ Branch 19 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 20 taken 8 times.
✓ Branch 23 taken 275 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 26 taken 275 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
4291 struct NoiseLayerSpec {
35 std::vector<FractalSpec> stack{FractalSpec{}};
36 /// Whether unset Hurst exponents and amplitudes come from the source (`EstimatedFractals` of
37 /// `EstimateSourceRoughness`); needs a source.
38 bool estimateFromSource = false;
39 /// Source cells across from which the source's measured data holds a noise layer: each layer
40 /// whose wavelength, its longest, is at least that many source cells at a point is left out
41 /// there (`NoiseLayer`). Ignored on a synthetic source; unset adds every layer everywhere.
42 std::optional<double> sourceResolvesPixels{};
43
44 /// The stack as fractals, with each layer's Hurst exponent applied.
45 std::vector<Fractal> Fractals() const;
46
47 /// `Fractals` with each layer's unset Hurst exponent `source.hurst` and unset amplitude the one
48 /// that continues `source` at the layer's Hurst exponent to a lag of its wavelength
49 /// (`MatchedNoiseAmplitude`).
50 /// @throws std::invalid_argument as `MatchedNoiseAmplitude`.
51 std::vector<Fractal> EstimatedFractals(const BaseRoughness& source) const;
52 };
53
54 /// Layer "roughness": fine roughness of a given RMS slope (`RoughnessLayer`), or of the RMS slope
55 /// and Hurst exponent the source's variogram continues to (`EstimateSourceRoughness`).
56 struct RoughnessLayerSpec {
57 /// The roughness; its `rmsSlope` and `hurst` stand in for those below when they are unset and
58 /// nothing is estimated.
59 RoughnessOptions roughness{};
60 std::optional<double> rmsSlope{}; ///< Rise over run; unset for the default or the estimate.
61 std::optional<double> hurst{}; ///< Unset for the default or the estimate.
62 /// Whether unset `rmsSlope` and `hurst` come from the source (`EstimatedOptions` of
63 /// `EstimateSourceRoughness`); needs a source.
64 bool estimateFromSource = false;
65
66 /// `roughness` with `rmsSlope` and `hurst` in place where set.
67 RoughnessOptions Options() const;
68
69 /// `Options` with an unset `hurst` `source.hurst` and an unset `rmsSlope` the RMS slope over
70 /// the baseline that continues `source` at the Hurst exponent (`BaseRoughness::RmsSlope`).
71 RoughnessOptions EstimatedOptions(BaseRoughness source) const;
72 };
73
74 /// Layer "spectral_continuation": detail below the source's resolution continuing its power-law
75 /// spectrum (`SpectralContinuationLayer`), fitted to the source (`EstimatePowerLawSpectrum`) on its
76 /// own grid wherever the slope or amplitude is not given.
77 struct SpectralContinuationLayerSpec {
78 /// The layer's options; the pixel size, slope and amplitude below stand in for theirs.
79 SpectralContinuationOptions options{};
80 std::optional<double> pixelSize{}; ///< Meters; unset for the source's cell size.
81 std::optional<double> slope{}; ///< Spectral slope beta; unset to fit from the source.
82 std::optional<double> octaveRms{}; ///< Meters; unset to fit from the source.
83 SpectrumFitBand fit{}; ///< Wavelengths the source's spectrum is fitted over.
84 };
85
86 /// Layer "scale": height * `scale` + `offset` (`ScaleLayer`).
87 struct ScaleLayerSpec {
88 double scale = 1.0;
89 double offset = 0.0; ///< Meters.
90 };
91
92 /// Layer "clamp": heights clamped to [`min`, `max`], either optional (`ClampLayer`).
93 struct ClampLayerSpec {
94 std::optional<double> min; ///< Meters; unset for no lower bound.
95 std::optional<double> max; ///< Meters; unset for no upper bound.
96 };
97
98 /// Region shape "rectangle": a box in surface coordinates.
99
6/6
✓ Branch 1 taken 5 times.
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 13 times.
✓ Branch 4 taken 30 times.
✓ Branch 7 taken 13 times.
✓ Branch 10 taken 8 times.
70 struct RectangleRegionSpec : Bounds2d {};
100 /// Region shape "circle": centered on (`x`, `y`) in surface coordinates.
101 struct CircleRegionSpec {
102 double x = 0.0;
103 double y = 0.0;
104 double radius = 0.0; ///< Meters.
105 };
106 /// Region shape "polygon": outlined by `points`, less `holes`, in surface coordinates.
107
2/3
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
188 struct PolygonRegionSpec {
108 std::vector<std::array<double, 2>> points{}; ///< [x, y] of each vertex.
109 std::vector<std::vector<std::array<double, 2>>> holes{}; ///< Each hole's vertices.
110 };
111 /// A region shape, named in JSON by its "type".
112 using RegionShapeSpec = std::variant<RectangleRegionSpec, CircleRegionSpec, PolygonRegionSpec>;
113
114 struct MaskedLayerSpec;
115
116 /// A layer, named in JSON by its "type". Layers that take only their library options hold them
117 /// directly: "dunes", "bedforms", "pavement", "strata", "sand_shadow" and "sand_fill".
118 using LayerSpec =
119 std::variant<NoiseLayerSpec, CraterLayerSpec, BoulderLayerSpec, RoughnessLayerSpec,
120 BedformOptions, ScaleLayerSpec, ClampLayerSpec, MaskedLayerSpec,
121 SecondaryLayerSpec, DuneOptions, SandFillOptions, PavementOptions, StrataOptions,
122 SandShadowOptions, SpectralContinuationLayerSpec>;
123
124 /// Layer "masked": `layer` applied only inside `shape` (`MaskedLayer`). Boulder ejecta do not see
125 /// crater layers inside masked layers.
126
11/19
✓ Branch 3 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 time.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 time.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 time.
✗ Branch 25 not taken.
✓ Branch 26 taken 1 time.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 time.
✗ Branch 33 not taken.
✓ Branch 34 taken 1 time.
✗ Branch 39 not taken.
✓ Branch 40 taken 1 time.
383 struct MaskedLayerSpec {
127 RegionShapeSpec shape{};
128 double feather = 0.0; ///< Meters outside the shape over which the layer fades out.
129 BlendShape blend = BlendShape::Smoothstep;
130 Boxed<LayerSpec> layer{};
131 };
132
133 template <> struct SpecName<NoiseLayerSpec> {
134 static constexpr std::string_view kName = "noise";
135 static constexpr std::string_view kDescription =
136 "A stack of fractal noise layers added to the terrain, for hills, ridges and rolling "
137 "relief.";
138 };
139 594 template <typename IO> void Fields(IO& io, NoiseLayerSpec& layer) {
140
4/4
void terraingen::Fields<terraingen::RangeChecker>(terraingen::RangeChecker&, terraingen::NoiseLayerSpec&):
✓ Branch 3 taken 370 times.
void terraingen::Fields<terraingen::config::(anonymous namespace)::SchemaWriter>(terraingen::config::(anonymous namespace)::SchemaWriter&, terraingen::NoiseLayerSpec&):
✓ Branch 3 taken 13 times.
void terraingen::Fields<terraingen::config::Reader>(terraingen::config::Reader&, terraingen::NoiseLayerSpec&):
✓ Branch 3 taken 79 times.
void terraingen::Fields<terraingen::config::Writer>(terraingen::config::Writer&, terraingen::NoiseLayerSpec&):
✓ Branch 3 taken 110 times.
1188 io("stack", layer.stack, std::string(kNoiseStackHelp), "", NoiseStackLength(1));
141 949 io("estimate_from_source", layer.estimateFromSource,
142 "Takes each layer's unset hurst and amplitude from the source's variogram, continued to "
143 "the layer's wavelength; for wavelengths at or below the source's cell size. Needs a "
144 "source with posts.");
145 579 SourceResolvesField(io, layer.sourceResolvesPixels, "noise layers of the stack",
146 "wavelength, the longest of each layer's octaves");
147 578 }
148
149 template <> struct SpecName<RoughnessLayerSpec> {
150 static constexpr std::string_view kName = "roughness";
151 static constexpr std::string_view kDescription =
152 "Fine roughness from octaves of noise, scaled to a given RMS slope over a baseline.";
153 };
154 90 template <typename IO> void Fields(IO& io, RoughnessLayerSpec& spec) {
155
4/4
void terraingen::Fields<terraingen::RangeChecker>(terraingen::RangeChecker&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 14 times.
void terraingen::Fields<terraingen::config::(anonymous namespace)::SchemaWriter>(terraingen::config::(anonymous namespace)::SchemaWriter&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 13 times.
void terraingen::Fields<terraingen::config::Reader>(terraingen::config::Reader&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 17 times.
void terraingen::Fields<terraingen::config::Writer>(terraingen::config::Writer&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 46 times.
180 io("rms_slope", spec.rmsSlope,
156
4/5
void terraingen::Fields<terraingen::(anonymous namespace)::SeedFinder>(terraingen::(anonymous namespace)::SeedFinder&, terraingen::RoughnessLayerSpec&):
✗ Branch 2 not taken.
void terraingen::Fields<terraingen::RangeChecker>(terraingen::RangeChecker&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 14 times.
void terraingen::Fields<terraingen::config::(anonymous namespace)::SchemaWriter>(terraingen::config::(anonymous namespace)::SchemaWriter&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 13 times.
void terraingen::Fields<terraingen::config::Reader>(terraingen::config::Reader&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 17 times.
void terraingen::Fields<terraingen::config::Writer>(terraingen::config::Writer&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 46 times.
180 std::string(kRmsSlopeHelp) +
157 " Unset is 0.15, or with estimate_from_source the source's RMS slope extrapolated to "
158 "the baseline.",
159 180 "", Above(0.0));
160 90 io("baseline_m", spec.roughness.baseline, "Baseline the RMS slope is given over, in meters.",
161 90 "m", Above(0.0));
162
4/4
void terraingen::Fields<terraingen::RangeChecker>(terraingen::RangeChecker&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 12 times.
void terraingen::Fields<terraingen::config::(anonymous namespace)::SchemaWriter>(terraingen::config::(anonymous namespace)::SchemaWriter&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 13 times.
void terraingen::Fields<terraingen::config::Reader>(terraingen::config::Reader&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 17 times.
void terraingen::Fields<terraingen::config::Writer>(terraingen::config::Writer&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 46 times.
178 io("hurst", spec.hurst,
163
4/5
void terraingen::Fields<terraingen::(anonymous namespace)::SeedFinder>(terraingen::(anonymous namespace)::SeedFinder&, terraingen::RoughnessLayerSpec&):
✗ Branch 2 not taken.
void terraingen::Fields<terraingen::RangeChecker>(terraingen::RangeChecker&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 13 times.
void terraingen::Fields<terraingen::config::(anonymous namespace)::SchemaWriter>(terraingen::config::(anonymous namespace)::SchemaWriter&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 13 times.
void terraingen::Fields<terraingen::config::Reader>(terraingen::config::Reader&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 17 times.
void terraingen::Fields<terraingen::config::Writer>(terraingen::config::Writer&, terraingen::RoughnessLayerSpec&):
✓ Branch 2 taken 46 times.
177 std::string(kRoughnessHurstHelp) +
164 " Unset is 0.8, or with estimate_from_source the source's.",
165 89 "", AboveUpTo(0.0, 1.0));
166 88 io("estimate_from_source", spec.estimateFromSource,
167 "Fits unset rms_slope and hurst to the source's variogram at lags of 1 to 8 cells and "
168 "continues it to the baseline; keep max_wavelength_m near the source's cell size. Needs a "
169 "source with posts.");
170 88 RoughnessOctaveFields(io, spec.roughness);
171 88 }
172
173 template <> struct SpecName<DuneOptions> {
174 static constexpr std::string_view kName = "dunes";
175 static constexpr std::string_view kDescription =
176 "Wind-blown dunes added to the terrain: isolated barchans or domes, or fields of "
177 "transverse, barchanoid or linear crests, with slip faces and optional ripples on them.";
178 };
179
180 template <> struct SpecName<PavementOptions> {
181 static constexpr std::string_view kName = "pavement";
182 static constexpr std::string_view kDescription =
183 "Fractured bedrock: polygonal plates, each tilted and stepped, parted by cracks or raised "
184 "ridges, split again by finer octaves of cracks; lays bedrock over the material map.";
185 };
186
187 template <> struct SpecName<StrataOptions> {
188 static constexpr std::string_view kName = "strata";
189 static constexpr std::string_view kDescription =
190 "Layered rock: the ground beneath terraced into dipping beds, each a flat bench below a "
191 "cliff, so hills become stepped buttes and mesas; lays bedrock over the cliffs.";
192 };
193
194 template <> struct SpecName<SandShadowOptions> {
195 static constexpr std::string_view kName = "sand_shadow";
196 static constexpr std::string_view kDescription =
197 "Sand shadows: a tapering sand tail in the lee of each boulder of the nearest boulder "
198 "layer before this one; lays sand over the material map.";
199 };
200
201 template <> struct SpecName<SandFillOptions> {
202 static constexpr std::string_view kName = "sand_fill";
203 static constexpr std::string_view kDescription =
204 "Sand pooled in the lows of the ground beneath: cracks, troughs and hollows between "
205 "rises, laying sand over the material map.";
206 };
207
208 template <> struct SpecName<BedformOptions> {
209 static constexpr std::string_view kName = "bedforms";
210 static constexpr std::string_view kDescription =
211 "Fields of wind-blown ripples or dunes added to the terrain.";
212 };
213
214 template <> struct SpecName<SpectralContinuationLayerSpec> {
215 static constexpr std::string_view kName = "spectral_continuation";
216 static constexpr std::string_view kDescription =
217 "Detail finer than the source continuing its measured power-law spectrum to shorter "
218 "wavelengths with random phases, as sparse Gabor noise: an alternative to diamond-square "
219 "upsampling without lattice artifacts.";
220 };
221 73 template <typename IO> void Fields(IO& io, SpectralContinuationLayerSpec& spec) {
222 73 io("pixel_size_m", spec.pixelSize,
223 "Cell size of the source in meters; the detail starts at twice it. Unset uses the "
224 "source's cell size.",
225 73 "m", Above(0.0));
226 73 io("slope", spec.slope,
227 "Spectral slope beta of the radially averaged power spectrum, P(f) ~ f^-beta: beta = 2 H "
228 "+ 2 for Hurst exponent H. Unset fits it to the source.",
229 73 "", Between(2.0, 4.0));
230 72 io("octave_rms_m", spec.octaveRms,
231 "RMS height in meters the power law holds at wavelengths from one to two source pixels. "
232 "Unset fits it to the source.",
233 72 "m", AtLeast(0.0));
234 72 io("fit_min_pixels", spec.fit.minPixels,
235 "Shortest wavelength, in source pixels, the source's spectrum is fitted over.", "",
236 72 AtLeast(2.0));
237 72 io("fit_max_pixels", spec.fit.maxPixels,
238 "Longest wavelength, in source pixels, the source's spectrum is fitted over; 0 for a "
239 "quarter of the window the spectrum is measured on (at most 512 cells a side).",
240 72 "", AtLeast(0.0));
241 72 SpectralSynthesisFields(io, spec.options.minWavelength, spec.options.taperOctaves,
242 72 spec.options.seed, spec.options.fade);
243 71 }
244
245 template <> struct SpecName<ScaleLayerSpec> {
246 static constexpr std::string_view kName = "scale";
247 static constexpr std::string_view kDescription =
248 "Scales and shifts the heights so far, for vertical exaggeration or a datum shift.";
249 };
250 82 template <typename IO> void Fields(IO& io, ScaleLayerSpec& spec) {
251 82 io("scale", spec.scale,
252 "Factor every height so far is multiplied by, as for vertical exaggeration.");
253 82 io("offset_m", spec.offset, "Meters added to every height after scaling, to shift the datum.",
254 "m");
255 81 }
256
257 template <> struct SpecName<ClampLayerSpec> {
258 static constexpr std::string_view kName = "clamp";
259 static constexpr std::string_view kDescription =
260 "Clamps the heights so far between optional bounds, to flatten a basin floor or cap "
261 "peaks.";
262 };
263 71 template <typename IO> void Fields(IO& io, ClampLayerSpec& spec) {
264 71 io("min_m", spec.min,
265 "Lowest height kept, in meters; lower heights are raised to it, flattening basin floors. "
266 "Unset leaves heights unbounded below.",
267 "m");
268 71 io("max_m", spec.max,
269 "Highest height kept, in meters; higher heights are lowered to it, capping peaks. Unset "
270 "leaves heights unbounded above.",
271 "m");
272 71 }
273
274 template <> struct SpecName<RectangleRegionSpec> {
275 static constexpr std::string_view kName = "rectangle";
276 static constexpr std::string_view kDescription =
277 "An axis-aligned rectangle in the surface's coordinates: meters on a plane, longitude and "
278 "latitude in degrees on a body.";
279 };
280 106 template <typename IO> void Fields(IO& io, RectangleRegionSpec& spec) {
281 106 Fields(io, static_cast<Bounds2d&>(spec));
282 106 }
283
284 template <> struct SpecName<CircleRegionSpec> {
285 static constexpr std::string_view kName = "circle";
286 static constexpr std::string_view kDescription =
287 "A circle in the surface's coordinates, its radius in meters.";
288 };
289 68 template <typename IO> void Fields(IO& io, CircleRegionSpec& spec) {
290 68 io("x", spec.x,
291 "Center along x in the surface's coordinates; the longitude in degrees on a sphere.");
292 68 io("y", spec.y,
293 "Center along y in the surface's coordinates; the latitude in degrees on a sphere.");
294 68 io("radius_m", spec.radius, "Radius of the circle in meters, also on a sphere.", "m",
295 68 AtLeast(0.0));
296 67 }
297
298 template <> struct SpecName<PolygonRegionSpec> {
299 static constexpr std::string_view kName = "polygon";
300 static constexpr std::string_view kDescription =
301 "A simple polygon in the surface's coordinates, concave or with holes: to follow a "
302 "mapped unit or a traverse corridor.";
303 };
304 61 template <typename IO> void Fields(IO& io, PolygonRegionSpec& spec) {
305 61 io("points", spec.points,
306 "Vertices of the outline as [x, y] pairs in the surface's coordinates, closed from the last "
307 "back to the first; points inside an odd number of outlines and holes are inside.",
308 61 "", MinLength(3));
309 57 io("holes", spec.holes,
310 "Outlines cut out of the polygon, each a list of at least 3 [x, y] vertices as `points`; "
311 "the masked layer fades out from their edges as from the outline's.");
312 56 }
313
314 template <> struct SpecName<MaskedLayerSpec> {
315 static constexpr std::string_view kName = "masked";
316 static constexpr std::string_view kDescription =
317 "Another layer applied only inside a rectangle, circle or polygon, feathered outside it: "
318 "to confine craters to an area or flatten a landing pad.";
319 };
320 124 template <typename IO> void Fields(IO& io, MaskedLayerSpec& spec) {
321 124 io("shape", spec.shape,
322 "Area the inner layer is applied in: a rectangle, a circle or a polygon.");
323 117 io("feather_m", spec.feather,
324 "Distance in meters outside the shape over which the inner layer fades back to the "
325 "unchanged height; 0 gives a hard edge.",
326 117 "m", AtLeast(0.0));
327 116 io("blend", spec.blend, "Curve of the fade across the feather.");
328 116 io("layer", spec.layer,
329 "Layer applied only inside the shape. A crater layer here does not count as the crater "
330 "layer for later boulder ejecta or secondaries.");
331 114 }
332
333 /// A layer's JSON "type", with the inner layer's type for a masked one: "masked (boulders)".
334 std::string LayerType(const LayerSpec& layer);
335
336 namespace config {
337
338 /// The number of `layers` of the kinds `Kinds`; layers inside masked layers do not count.
339 108 template <typename... Kinds> std::size_t CountLayers(const std::vector<LayerSpec>& layers) {
340 return static_cast<std::size_t>(
341 108 std::count_if(layers.begin(), layers.end(),
342 108 [](const LayerSpec& layer) { return HoldsAny<Kinds...>(layer); }));
343 }
344
345 /// The indices of the `layers` of the kinds `Kinds`, in order; layers inside masked layers do not
346 /// count.
347 template <typename... Kinds>
348 19 std::vector<std::size_t> LayerIndices(const std::vector<LayerSpec>& layers) {
349 19 std::vector<std::size_t> indices;
350
4/4
std::vector<unsigned long, std::allocator<unsigned long> > terraingen::config::LayerIndices<terraingen::BoulderLayerSpec>(std::vector<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec>, std::allocator<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec> > > const&):
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 4 times.
std::vector<unsigned long, std::allocator<unsigned long> > terraingen::config::LayerIndices<terraingen::CraterLayerSpec>(std::vector<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec>, std::allocator<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec> > > const&):
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 15 times.
68 for (std::size_t i = 0; i < layers.size(); ++i) {
351
4/4
std::vector<unsigned long, std::allocator<unsigned long> > terraingen::config::LayerIndices<terraingen::BoulderLayerSpec>(std::vector<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec>, std::allocator<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec> > > const&):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9 times.
std::vector<unsigned long, std::allocator<unsigned long> > terraingen::config::LayerIndices<terraingen::CraterLayerSpec>(std::vector<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec>, std::allocator<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec> > > const&):
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 16 times.
49 if (HoldsAny<Kinds...>(layers[i])) {
352
2/2
std::vector<unsigned long, std::allocator<unsigned long> > terraingen::config::LayerIndices<terraingen::BoulderLayerSpec>(std::vector<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec>, std::allocator<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec> > > const&):
✓ Branch 1 taken 5 times.
std::vector<unsigned long, std::allocator<unsigned long> > terraingen::config::LayerIndices<terraingen::CraterLayerSpec>(std::vector<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec>, std::allocator<std::variant<terraingen::NoiseLayerSpec, terraingen::CraterLayerSpec, terraingen::BoulderLayerSpec, terraingen::RoughnessLayerSpec, terraingen::BedformOptions, terraingen::ScaleLayerSpec, terraingen::ClampLayerSpec, terraingen::MaskedLayerSpec, terraingen::SecondaryLayerSpec, terraingen::DuneOptions, terraingen::SandFillOptions, terraingen::PavementOptions, terraingen::StrataOptions, terraingen::SandShadowOptions, terraingen::SpectralContinuationLayerSpec> > > const&):
✓ Branch 1 taken 19 times.
24 indices.push_back(i);
353 }
354 }
355 19 return indices;
356 }
357
358 /// The region shape a spec describes, unchecked.
359 RegionShape BuildRegionShape(const RegionShapeSpec& spec);
360
361 /// The sources a terrain's layers are built on.
362 struct LayerSources {
363 /// The terrain's source: the one the configuration or the caller gives, or the default
364 /// synthetic noise.
365 std::shared_ptr<const Source> terrain;
366 /// The source the configuration or the caller gives; null for the default synthetic noise.
367 std::shared_ptr<const Source> given;
368 /// The source's measured data, which layers leave out what it resolves of; null for none.
369 std::shared_ptr<const Source> measured;
370 bool posts = false; ///< Whether the source has posts that layers can estimate settings from.
371 };
372
373 /// A configuration's layers, built in order.
374 748 struct BuiltLayers {
375 std::vector<LayerPtr> layers;
376 /// The most craters the top-level crater layers are expected to generate over one extent;
377 /// none when none generate.
378 std::optional<double> expectedCraters;
379 };
380
381 /// Checks every layer spec, then builds each layer in order on `surface` and checks it against
382 /// what it built, over the outputs' grids.
383 /// @throws ConfigError under "layers" for an invalid layer.
384 BuiltLayers BuildLayers(const std::vector<LayerSpec>& layers,
385 const std::vector<OutputGrid>& outputs, const LayerSources& sources,
386 const std::filesystem::path& directory, const Surface& surface);
387
388 } // namespace config
389
390 } // namespace terraingen
391