./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
54 / 54
100.0%
Branches:
13 / 16
81.2%
Functions:
5 / 5, 1 excl
100.0%

src/config/terrain.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief A whole terrain configuration: its spec and fields, and the one pass that checks and
5 /// builds it.
6 #pragma once
7
8 #include "config/albedo.h"
9 #include "config/body.h"
10 #include "config/layers.h"
11 #include "config/materials.h"
12 #include "config/outputs.h"
13 #include "config/sources.h"
14
15 #include "terraingen/config/config.h"
16 #include "terraingen/config/validate.h"
17 #include "terraingen/pipeline/terrain.h"
18
19 #include <filesystem>
20 #include <memory>
21 #include <optional>
22 #include <vector>
23
24 namespace terraingen {
25
26 /// Everything a terrain configuration holds: the body it lies on, optionally its source of heights,
27 /// the layers added to them in order, the outputs to write, and optionally its albedo and
28 /// materials. `TerrainGenConfig` holds one as a value.
29 struct ConfigSpec {
30 int schemaVersion = kConfigSchemaVersion;
31 SurfaceSpec body{};
32 /// None for the default synthetic source, `DefaultBaseNoise` at the body's datum.
33 std::optional<SourceSpec> source{};
34 std::vector<LayerSpec> layers;
35 std::vector<OutputSpec> outputs;
36 std::optional<AlbedoSpec> albedo; ///< None by default.
37 std::optional<MaterialsSpec> materials; ///< None by default.
38 /// The folder the configuration was read from (`LoadConfig`), which its relative paths
39 /// resolve against when a call gives no folder; not part of its JSON.
40 std::filesystem::path directory{};
41 };
42
43 1345 template <typename IO> void Fields(IO& io, ConfigSpec& config) {
44 1345 io("schema_version", config.schemaVersion,
45 1345 "Version of the configuration format, which this library reads.", "", Required());
46 1345 io("body", config.body,
47 "What the terrain lies on: a plane in meters, or a whole body (a sphere, ellipsoid or "
48 "shape model) in longitude and latitude degrees.");
49 1330 io("source", config.source,
50 "Where the heights come from: a GeoTIFF, a chain of sources or synthetic noise, with its "
51 "upsampling; unset is fBm noise 400 m in wavelength and 12 m in amplitude at the datum.");
52 1292 io("layers", config.layers,
53 "Relief and features added to the source's heights, applied in order: noise, craters, "
54 "boulders and more.");
55 1164 io("outputs", config.outputs,
56 "What to produce, at what resolution and where, each over its own extent or the whole "
57 "body: heightmaps, crater and boulder lists, boulder models, albedo, meshes and reports. "
58 "Each is returned, and written to its path when it has one.");
59 1138 io("albedo", config.albedo,
60 "The terrain's albedo: a source and the layers that change it, written by albedo outputs; "
61 "none when unset.");
62 1122 io("materials", config.materials,
63 "The material map: soil, sand, dust, bedrock and rock shares, and their Hapke parameters, "
64 "written by materials and photometry outputs; none when unset.");
65 1120 }
66
67 /// The folder relative paths of `config` resolve against: `given`, or without one the folder
68 /// `config` was read from.
69 599 inline std::filesystem::path ConfigDirectory(const ConfigSpec& config,
70 const std::filesystem::path& given) {
71
13/16
<unknown function 69>:
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 27 times.
✓ Branch 3 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✓ Branch 8 taken 1 time.
void terraingen::Fields<terraingen::RangeChecker>(terraingen::RangeChecker&, terraingen::ConfigSpec&):
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
✓ Branch 6 taken 56 times.
✓ Branch 7 taken 30 times.
✓ Branch 9 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 12 taken 279 times.
✓ Branch 13 taken 99 times.
600 return given.empty() ? config.directory : given;
72 }
73
74 namespace config {
75
76 /// A configuration's terrain and summary, from one pass that checks each part as it builds it.
77 struct CheckedTerrain {
78 Terrain terrain;
79 ConfigSummary summary;
80 std::vector<OutputGrid> outputs; ///< What each output covers, in order.
81 };
82
83 /// Checks and builds `config` in one pass, on `external` in place of its source when given: every
84 /// field range, the body, the source, the outputs, the layers, the albedo and the materials.
85 /// @throws ConfigError naming the first invalid value by its JSON path.
86 CheckedTerrain BuildCheckedTerrain(const ConfigSpec& config, const std::filesystem::path& directory,
87 const std::shared_ptr<const Source>& external = nullptr);
88
89 } // namespace config
90
91 } // namespace terraingen
92