src/config/boulders.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief Boulder layers in a configuration: their size models, fields, checks and building. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "config/craters.h" | ||
| 8 | #include "config/layer_context.h" | ||
| 9 | |||
| 10 | #include "terraingen/distribution/sp8023.h" | ||
| 11 | #include "terraingen/distribution/synthterrain.h" | ||
| 12 | #include "terraingen/layers/boulders/boulder_fields.h" | ||
| 13 | #include "terraingen/layers/boulders/boulder_layer.h" | ||
| 14 | |||
| 15 | #include <filesystem> | ||
| 16 | #include <optional> | ||
| 17 | #include <string> | ||
| 18 | #include <string_view> | ||
| 19 | #include <variant> | ||
| 20 | #include <vector> | ||
| 21 | |||
| 22 | namespace terraingen { | ||
| 23 | |||
| 24 | /// Boulder sizes "golombek_rapp": the layer's coverage, qa and qb. | ||
| 25 | struct GolombekRappBouldersSpec {}; | ||
| 26 | /// Boulder sizes "sp8023_intercrater": `Sp8023IntercraterBlocks(curve)`. | ||
| 27 | struct Sp8023IntercraterBouldersSpec { | ||
| 28 | SpecificationCurve curve = SpecificationCurve::Nominal; | ||
| 29 | }; | ||
| 30 | /// Boulder sizes "sp8023_crater": `Sp8023CraterBlocks(curve)`. | ||
| 31 | struct Sp8023CraterBouldersSpec { | ||
| 32 | SpecificationCurve curve = SpecificationCurve::Nominal; | ||
| 33 | }; | ||
| 34 | /// Boulder sizes "synthterrain": `SynthterrainBoulderDistribution(model)`. | ||
| 35 | struct SynthterrainBouldersSpec { | ||
| 36 | SynthterrainBoulders model = SynthterrainBoulders::InterCrater; | ||
| 37 | }; | ||
| 38 | /// A boulder size distribution, named in JSON by its "type"; "power_law", "piecewise_power_law", | ||
| 39 | /// "tabulated" and "piecewise_uniform" are as for crater densities. | ||
| 40 | using BoulderSizesSpec = | ||
| 41 | std::variant<GolombekRappBouldersSpec, Sp8023IntercraterBouldersSpec, Sp8023CraterBouldersSpec, | ||
| 42 | SynthterrainBouldersSpec, PowerLawSpec, PiecewisePowerLawSpec, TabulatedSpec, | ||
| 43 | PiecewiseUniformSpec>; | ||
| 44 | |||
| 45 | /// Layer "boulders": boulders scattered over the terrain (`BoulderLayer`). | ||
| 46 | /// | ||
| 47 | /// Ejecta come from every top-level crater layer before this one, at least one of which must exist | ||
| 48 | /// when crater blocks are enabled. `boulders.cacheBoulders` is not part of the configuration. | ||
| 49 | struct BoulderLayerSpec { | ||
| 50 | BoulderLayerOptions boulders{}; | ||
| 51 | /// Gives `boulders.sizes.distribution`; by default the nominal NASA SP-8023 intercrater blocks | ||
| 52 | /// (SLS-SPEC-159 Rev. I, 3.4.1.4). | ||
| 53 | BoulderSizesSpec sizes{Sp8023IntercraterBouldersSpec{SpecificationCurve::Nominal}}; | ||
| 54 | /// Gives `boulders.ejecta.distribution`; unset follows `sizes`. | ||
| 55 | std::optional<BoulderSizesSpec> ejectaSizes{}; | ||
| 56 | bool extrapolate = false; ///< Let tables be evaluated beyond their published diameters. | ||
| 57 | /// Rock meshes (.obj, .gltf or .glb) that replace the procedural shapes, as | ||
| 58 | /// `BoulderShapeOptions::library`; relative to the configuration's folder. | ||
| 59 | std::vector<std::string> shapeFiles{}; | ||
| 60 | std::optional<DensityMapSpec> densityMap{}; ///< Gives `boulders.densityMap`. | ||
| 61 | std::optional<SizeSlopeMapSpec> slopeMap{}; ///< Gives `boulders.slopeMap`. | ||
| 62 | std::optional<FieldSpec> completeness{}; ///< Gives `boulders.completeness`. | ||
| 63 | }; | ||
| 64 | |||
| 65 | /// Description of the curve of an SP-8023 boulder size model. | ||
| 66 | inline constexpr std::string_view kCurveHelp = | ||
| 67 | "Which of the model's minimum, nominal and maximum curves to use, from fewest to most " | ||
| 68 | "boulders."; | ||
| 69 | |||
| 70 | template <> struct SpecName<GolombekRappBouldersSpec> { | ||
| 71 | static constexpr std::string_view kName = "golombek_rapp"; | ||
| 72 | static constexpr std::string_view kDescription = | ||
| 73 | "Golombek and Rapp boulder sizes, set by the fraction of ground the boulders cover and the " | ||
| 74 | "layer's qa and qb."; | ||
| 75 | }; | ||
| 76 | template <typename IO> void Fields(IO& /*io*/, GolombekRappBouldersSpec& /*spec*/) {} | ||
| 77 | |||
| 78 | template <> struct SpecName<Sp8023IntercraterBouldersSpec> { | ||
| 79 | static constexpr std::string_view kName = "sp8023_intercrater"; | ||
| 80 | static constexpr std::string_view kDescription = | ||
| 81 | "Blocks between craters from NASA SP-8023, the lunar surface design model (Figure 7)."; | ||
| 82 | }; | ||
| 83 | 163 | template <typename IO> void Fields(IO& io, Sp8023IntercraterBouldersSpec& spec) { | |
| 84 | 163 | io("curve", spec.curve, kCurveHelp); | |
| 85 | 163 | } | |
| 86 | |||
| 87 | template <> struct SpecName<Sp8023CraterBouldersSpec> { | ||
| 88 | static constexpr std::string_view kName = "sp8023_crater"; | ||
| 89 | static constexpr std::string_view kDescription = | ||
| 90 | "Blocks around blocky craters from NASA SP-8023 (Figure 9), for the ejecta of craters " | ||
| 91 | "that reached bedrock."; | ||
| 92 | }; | ||
| 93 | 57 | template <typename IO> void Fields(IO& io, Sp8023CraterBouldersSpec& spec) { | |
| 94 | 57 | io("curve", spec.curve, kCurveHelp); | |
| 95 | 57 | } | |
| 96 | |||
| 97 | template <> struct SpecName<SynthterrainBouldersSpec> { | ||
| 98 | static constexpr std::string_view kName = "synthterrain"; | ||
| 99 | static constexpr std::string_view kDescription = | ||
| 100 | "One of the power-law boulder distributions synthterrain offers, for comparison with it."; | ||
| 101 | }; | ||
| 102 | 50 | template <typename IO> void Fields(IO& io, SynthterrainBouldersSpec& spec) { | |
| 103 | 50 | io("model", spec.model, "Which of synthterrain's power-law boulder distributions to use."); | |
| 104 | 50 | } | |
| 105 | |||
| 106 | /// The fields of the sizes of a boulder layer's boulders between craters. | ||
| 107 | 283 | template <typename IO> void BoulderSizeFields(IO& io, BoulderLayerSpec& spec) { | |
| 108 | 283 | BoulderSizeRangeFields(io, spec.boulders); | |
| 109 | 282 | io("sizes", spec.sizes, | |
| 110 | "Size distribution of the boulders between craters, per m^2; patches and bedrock scale its " | ||
| 111 | "density."); | ||
| 112 | 281 | } | |
| 113 | |||
| 114 | /// The fields of where a boulder layer's boulders gather, and the sizes of crater ejecta blocks. | ||
| 115 | 284 | template <typename IO> void BoulderPlacementFields(IO& io, BoulderLayerSpec& spec) { | |
| 116 | 284 | BoulderGatheringFields(io, spec.boulders); | |
| 117 | 284 | io("ejecta_sizes", spec.ejectaSizes, | |
| 118 | "Size distribution of the blocks at the rim of a fresh crater, per m^2; golombek_rapp uses " | ||
| 119 | "the ejecta's coverage with qa and qb. Unset follows sizes."); | ||
| 120 | 283 | io("extrapolate", spec.extrapolate, | |
| 121 | "Lets the size distributions be evaluated outside their valid diameters, such as beyond a " | ||
| 122 | "table's published ones; otherwise they must cover the boulder sizes."); | ||
| 123 | 283 | } | |
| 124 | |||
| 125 | /// The fields of the files and maps a boulder layer reads, and its catalog boulders. | ||
| 126 | 278 | template <typename IO> void BoulderInputFields(IO& io, BoulderLayerSpec& spec) { | |
| 127 | 278 | io("shape_files", spec.shapeFiles, | |
| 128 | "Rock meshes (.obj with its .mtl, .gltf or .glb) the boulder shapes are drawn from instead " | ||
| 129 | "of the procedural styles, each boulder picking one by its shape seed; paths relative to " | ||
| 130 | "the configuration. Empty keeps the procedural shapes."); | ||
| 131 | 278 | io("density_map", spec.densityMap, | |
| 132 | "Map that sets the abundance of boulders between craters point by point, scaling the " | ||
| 133 | "sizes to what it measures; unset keeps the abundance the sizes set everywhere."); | ||
| 134 | 278 | io("slope_map", spec.slopeMap, | |
| 135 | "Map of how steeply boulder counts fall with size, such as a mean diameter map, bending the " | ||
| 136 | "sizes into a local power law through their count at its reference diameter; needs a size " | ||
| 137 | "distribution. Unset keeps the sizes' shape everywhere."); | ||
| 138 | 278 | io("manual", spec.boulders.manual, | |
| 139 | "Catalog or hand-placed boulders placed as given and never thinned or left out; fields " | ||
| 140 | "left unset are drawn as for generated boulders. Boulders fixing any field never break."); | ||
| 141 | 271 | io("completeness", spec.completeness, | |
| 142 | "Where the manual boulders are a complete catalog: the diameter in meters from which they " | ||
| 143 | "stand in for generated boulders, infinite or no value where there is no catalog. Unset " | ||
| 144 | "keeps every generated boulder."); | ||
| 145 | 271 | } | |
| 146 | |||
| 147 | template <> struct SpecName<BoulderLayerSpec> { | ||
| 148 | static constexpr std::string_view kName = "boulders"; | ||
| 149 | static constexpr std::string_view kDescription = | ||
| 150 | "Boulders scattered over the ground from a size distribution, in patches and around fresh " | ||
| 151 | "craters, as relief or 3D models."; | ||
| 152 | }; | ||
| 153 | 286 | template <typename IO> void Fields(IO& io, BoulderLayerSpec& spec) { | |
| 154 | 286 | BoulderLayerOptions& boulders = spec.boulders; | |
| 155 | 283 | BoulderSizeFields(io, spec); | |
| 156 | 284 | BoulderPlacementFields(io, spec); | |
| 157 | 280 | BoulderBedrockFields(io, boulders.bedrock); | |
| 158 | 279 | BoulderPoseFields(io, boulders.pose); | |
| 159 | 279 | BoulderWearFields(io, boulders); | |
| 160 | 279 | BoulderRenderingFields(io, boulders.rendering); | |
| 161 | 278 | BoulderInputFields(io, spec); | |
| 162 | 274 | BoulderSharingFields(io, boulders); | |
| 163 | 271 | } | |
| 164 | |||
| 165 | namespace config { | ||
| 166 | |||
| 167 | /// The boulder options a layer describes, with its size distributions, maps and completeness | ||
| 168 | /// built and its shape files read; the options themselves are checked by the layer. | ||
| 169 | /// @param path The layer's JSON path, which errors are reported under. | ||
| 170 | /// @param directory Folder the shape files resolve against. | ||
| 171 | /// @throws ConfigError at `path`.sizes, .ejecta_sizes or .shape_files[i] for an invalid | ||
| 172 | /// distribution or an unreadable mesh, and at a map's or the completeness' field for an unreadable | ||
| 173 | /// GeoTIFF or an invalid map. | ||
| 174 | BoulderLayerOptions BuildBoulderOptions(const BoulderLayerSpec& spec, const std::string& path, | ||
| 175 | const std::filesystem::path& directory = {}); | ||
| 176 | |||
| 177 | /// @name Boulder layers | ||
| 178 | /// Checks a boulder layer spec before building, builds it, and checks the candidates the built | ||
| 179 | /// layer is expected to draw over each output. | ||
| 180 | /// @throws ConfigError under `path` for what the checks or the layer reject. | ||
| 181 | /// @{ | ||
| 182 | void CheckSpec(const BoulderLayerSpec& spec, const std::string& path, LayerChecks& checks); | ||
| 183 | LayerPtr BuildSpec(const BoulderLayerSpec& spec, const std::string& path, | ||
| 184 | const LayerInputs& inputs); | ||
| 185 | void CheckBuilt(const BoulderLayerSpec& spec, const Layer& built, const std::string& path, | ||
| 186 | LayerChecks& checks); | ||
| 187 | /// @} | ||
| 188 | |||
| 189 | } // namespace config | ||
| 190 | |||
| 191 | } // namespace terraingen | ||
| 192 |