include/terraingen/layers/boulders/boulder_options.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief How a `BoulderLayer` sizes, places, poses and draws its boulders. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/distribution/size_frequency.h" | ||
| 8 | #include "terraingen/layers/boulders/boulder_models.h" | ||
| 9 | #include "terraingen/layers/boulders/boulder_shape.h" | ||
| 10 | #include "terraingen/layers/craters/crater.h" | ||
| 11 | #include "terraingen/layers/density_map.h" | ||
| 12 | #include "terraingen/layers/exposure.h" | ||
| 13 | #include "terraingen/layers/fade.h" | ||
| 14 | |||
| 15 | #include <cstddef> | ||
| 16 | #include <cstdint> | ||
| 17 | #include <memory> | ||
| 18 | #include <optional> | ||
| 19 | #include <vector> | ||
| 20 | |||
| 21 | namespace terraingen { | ||
| 22 | |||
| 23 | /// How the boulders drawn into the heights look there. | ||
| 24 | enum class BoulderRelief { | ||
| 25 | Dome, ///< Each boulder's exposed part as a dome: cheap, and enough for small boulders. | ||
| 26 | Shape, ///< The top surface of each boulder's 3D boulder shape (`GenerateBoulderShape`). | ||
| 27 | /// No rock, only fillets: for programs that place every boulder as a model of its own. | ||
| 28 | None, | ||
| 29 | }; | ||
| 30 | |||
| 31 | /// Which boulders become 3D models of their own: those at or above either lower threshold and | ||
| 32 | /// below every upper one set; no lower threshold means no models. | ||
| 33 | 16 | struct BoulderModelThreshold { | |
| 34 | std::optional<double> minDiameter{}; ///< Boulders at least this wide (m) are models. | ||
| 35 | std::optional<double> minPixels{}; ///< Boulders spanning at least this many samples are. | ||
| 36 | std::optional<double> maxDiameter{}; ///< Boulders this wide (m) or wider are not. | ||
| 37 | std::optional<double> maxPixels{}; ///< Boulders spanning this many samples or more are not. | ||
| 38 | |||
| 39 | /// Whether a boulder of `diameter` meters is a model: at or above a lower threshold and below | ||
| 40 | /// the upper ones. | ||
| 41 | /// @param spacing Sample spacing in meters; 0 for none, when only `minDiameter` counts. | ||
| 42 | bool IsModel(double diameter, double spacing) const; | ||
| 43 | |||
| 44 | 3 | bool operator==(const BoulderModelThreshold& other) const { | |
| 45 | 6 | return minDiameter == other.minDiameter && minPixels == other.minPixels && | |
| 46 | 6 | maxDiameter == other.maxDiameter && maxPixels == other.maxPixels; | |
| 47 | } | ||
| 48 | }; | ||
| 49 | |||
| 50 | /// The boulder sizes a layer has by default between craters and around them: the nominal NASA | ||
| 51 | /// SP-8023 intercrater blocks (`Sp8023IntercraterBlocks`, Li et al. 2017, | ||
| 52 | /// https://doi.org/10.1016/j.pss.2017.08.008), one instance shared by every default. | ||
| 53 | std::shared_ptr<const SizeFrequencyDistribution> DefaultBoulderSizes(); | ||
| 54 | |||
| 55 | /// The sizes of the boulders between craters: `distribution`, or Golombek and Rapp (1997) | ||
| 56 | /// boulders of `coverage` without one, from `minDiameter` up to `maxDiameter`. | ||
| 57 | 48 | struct BoulderSizes { | |
| 58 | /// Golombek-Rapp k, the fractional area covered by boulders, for sizes without a | ||
| 59 | /// `distribution`; unset is 0.02 (`Coverage`). | ||
| 60 | std::optional<double> coverage{}; | ||
| 61 | /// Golombek-Rapp q = qa + qb / k per meter, for Golombek-Rapp sizes here or in the ejecta: | ||
| 62 | /// qa, unset 1.79 (`QConstant`). | ||
| 63 | std::optional<double> qConstant{}; | ||
| 64 | std::optional<double> qCoverageCoefficient{}; ///< qb, unset 0.152 (`QCoverageCoefficient`). | ||
| 65 | /// Sizes per m^2, by default `DefaultBoulderSizes`; null for Golombek-Rapp boulders of | ||
| 66 | /// `coverage`. Patches and bedrock scale its density, or k without it. | ||
| 67 | std::shared_ptr<const SizeFrequencyDistribution> distribution = DefaultBoulderSizes(); | ||
| 68 | double minDiameter = 0.1; ///< Smallest boulder (m). | ||
| 69 | /// Largest boulder (m), exclusive; by default the largest block of `DefaultBoulderSizes`. | ||
| 70 | double maxDiameter = DefaultBoulderSizes()->ValidRange().max; | ||
| 71 | |||
| 72 | /// The Golombek-Rapp k: `coverage`, or 0.02 unset. | ||
| 73 | 637837 | double Coverage() const { | |
| 74 | 1263294 | return coverage.value_or(0.02); | |
| 75 | } | ||
| 76 | /// The Golombek-Rapp qa: `qConstant`, or 1.79 unset. | ||
| 77 | 637228 | double QConstant() const { | |
| 78 | 638764 | return qConstant.value_or(1.79); | |
| 79 | } | ||
| 80 | /// The Golombek-Rapp qb: `qCoverageCoefficient`, or 0.152 unset. | ||
| 81 | 638764 | double QCoverageCoefficient() const { | |
| 82 | 638764 | return qCoverageCoefficient.value_or(0.152); | |
| 83 | } | ||
| 84 | |||
| 85 | 1 | bool operator==(const BoulderSizes& other) const { | |
| 86 | 2 | return coverage == other.coverage && qConstant == other.qConstant && | |
| 87 | 1 | qCoverageCoefficient == other.qCoverageCoefficient && | |
| 88 | 1 | distribution == other.distribution && minDiameter == other.minDiameter && | |
| 89 | 1 | maxDiameter == other.maxDiameter; | |
| 90 | } | ||
| 91 | }; | ||
| 92 | |||
| 93 | /// Patches of richer and poorer boulder cover. | ||
| 94 | 5 | struct BoulderPatches { | |
| 95 | /// Abundance varies from 1 / `spread` to `spread` times its mean; 1 for uniform. | ||
| 96 | double spread = 1.0; | ||
| 97 | double size = 200.0; ///< Typical width of a patch (m). | ||
| 98 | |||
| 99 | 1 | bool operator==(const BoulderPatches& other) const { | |
| 100 | 1 | return spread == other.spread && size == other.size; | |
| 101 | } | ||
| 102 | }; | ||
| 103 | |||
| 104 | /// How boulder cluster centers are laid out and how their clusters combine. | ||
| 105 | enum class BoulderClusterModel { | ||
| 106 | /// One center per cell of a jittered lattice `spacing` apart; each point takes the Gaussian of | ||
| 107 | /// its nearest center only. | ||
| 108 | Nearest, | ||
| 109 | /// A Thomas cluster process: centers scattered as a Poisson process, one per `spacing`^2 on | ||
| 110 | /// average, each spreading its boulders in a Gaussian of `radius`, overlapping clusters adding | ||
| 111 | /// (Thomas 1949, https://doi.org/10.1093/biomet/36.1-2.18). | ||
| 112 | Thomas, | ||
| 113 | }; | ||
| 114 | |||
| 115 | /// Boulders between craters gathered in clusters: `share` of them crowd within about `radius` of | ||
| 116 | /// cluster centers about `spacing` apart and the rest stay scattered. The mean abundance is kept: | ||
| 117 | /// the mean count with a size distribution, the mean coverage with Golombek-Rapp boulders. | ||
| 118 | 5 | struct BoulderClusters { | |
| 119 | double share = 0.0; ///< Share of the boulders in clusters, in [0, 1]; 0 for none. | ||
| 120 | double centerSpacing = 50.0; ///< Typical distance between cluster centers (m). | ||
| 121 | /// Gaussian radius of a cluster (m): below `spacing` for `Nearest`, at most twice it for | ||
| 122 | /// `Thomas`. | ||
| 123 | double radius = 5.0; | ||
| 124 | BoulderClusterModel model = BoulderClusterModel::Nearest; ///< How the clusters are laid out. | ||
| 125 | |||
| 126 | 1 | bool operator==(const BoulderClusters& other) const { | |
| 127 | 1 | return share == other.share && centerSpacing == other.centerSpacing && | |
| 128 | 2 | radius == other.radius && model == other.model; | |
| 129 | } | ||
| 130 | }; | ||
| 131 | |||
| 132 | /// Boulders broken by wear into pieces that replace them. From `splitWear` a boulder at least | ||
| 133 | /// `minDiameter` across is split by near-vertical cracks into pieces that still fit, their gaps | ||
| 134 | /// opening to `gapRatio` of its diameter; from `rubbleWear` the pieces scatter up to `spreadRatio` | ||
| 135 | /// diameters further, turn and sink. | ||
| 136 | 7 | struct BoulderFragmentation { | |
| 137 | double minDiameter = 1.0; ///< Smallest boulder that breaks (m). | ||
| 138 | double splitWear = 0.5; ///< Wear from which boulders are split, in [0, 1]. | ||
| 139 | double rubbleWear = 1.0; ///< Wear from which the pieces scatter, at least `splitWear`. | ||
| 140 | int minPieces = 2; ///< Fewest pieces, at least 2. | ||
| 141 | int maxPieces = 5; ///< Most pieces, at most 12. | ||
| 142 | double gapRatio = 0.04; ///< Widest crack between split pieces, over the diameter. | ||
| 143 | double spreadRatio = 0.6; ///< How far rubble scatters beyond that, over the diameter. | ||
| 144 | /// Share of broken boulders split into slabs by roughly parallel cracks right through them; the | ||
| 145 | /// rest crack out from the middle like a pie. | ||
| 146 | double slabShare = 0.7; | ||
| 147 | |||
| 148 | ✗ | bool operator==(const BoulderFragmentation& other) const { | |
| 149 | ✗ | return minDiameter == other.minDiameter && splitWear == other.splitWear && | |
| 150 | ✗ | rubbleWear == other.rubbleWear && minPieces == other.minPieces && | |
| 151 | ✗ | maxPieces == other.maxPieces && gapRatio == other.gapRatio && | |
| 152 | ✗ | spreadRatio == other.spreadRatio && slabShare == other.slabShare; | |
| 153 | } | ||
| 154 | }; | ||
| 155 | |||
| 156 | /// How the share of a crater's blocks falls off with distance from its center, in radii. | ||
| 157 | enum class EjectaProfile { | ||
| 158 | /// Every block inside the rim, falling along a smoothstep to none at `reach`. | ||
| 159 | Smoothstep, | ||
| 160 | /// exp(-(rho - 1) / `decayRadii`) outside the rim, `floorShare` of the rim's on the floor, and | ||
| 161 | /// none from `reach`: synthterrain's crater probability map (decay 0.7, floor 0.05, reach 2). | ||
| 162 | Exponential, | ||
| 163 | }; | ||
| 164 | |||
| 165 | /// How a crater's blocks wear away with time. | ||
| 166 | enum class EjectaAging { | ||
| 167 | /// By the crater's freshness (`CraterState::Freshness`): all from 1, none at or below | ||
| 168 | /// `minFreshness`, along a smoothstep. | ||
| 169 | Freshness, | ||
| 170 | /// By the crater's age: (1 - age / `lifetimeGyr`)^`agingExponent`, synthterrain's form | ||
| 171 | /// (lifetime 4 Gyr, exponent 3). | ||
| 172 | Age, | ||
| 173 | }; | ||
| 174 | |||
| 175 | /// Blocks thrown out by craters that dug through the regolith, added to the boulders | ||
| 176 | /// between craters: densest at the rim, thinning outward and with age; overlapping ejecta take the | ||
| 177 | /// largest share. They are generated boulders, so a layer without `generateRandom` has none. | ||
| 178 | 221 | struct BoulderEjecta { | |
| 179 | /// Craters at least this large throw blocks out (m); unset, with no `regolithThickness`, no | ||
| 180 | /// crater throws blocks. | ||
| 181 | std::optional<double> minCraterDiameter{}; | ||
| 182 | /// The regolith's thickness (m): craters smaller than `regolithThickness / | ||
| 183 | /// excavationDepthRatio` do not dig through it and throw no blocks. | ||
| 184 | std::optional<double> regolithThickness{}; | ||
| 185 | double excavationDepthRatio = 0.1; ///< Depth of excavation over crater diameter. | ||
| 186 | /// The blocks' sizes at the rim of a fresh crater, per m^2, by default `DefaultBoulderSizes`; | ||
| 187 | /// null for Golombek-Rapp boulders of `coverage`. | ||
| 188 | std::shared_ptr<const SizeFrequencyDistribution> distribution = DefaultBoulderSizes(); | ||
| 189 | /// Golombek-Rapp k at the rim of a fresh crater, for blocks without a `distribution`; unset is | ||
| 190 | /// 0.1 (`Coverage`). | ||
| 191 | std::optional<double> coverage{}; | ||
| 192 | EjectaProfile profile = EjectaProfile::Smoothstep; ///< Falloff with distance. | ||
| 193 | double reach = 3.0; ///< Radii from the center beyond which a crater adds no blocks. | ||
| 194 | double decayRadii = 0.7; ///< e-folding distance of `Exponential`, in radii. | ||
| 195 | double floorShare = 0.05; ///< The floor's share of the rim's blocks with `Exponential`. | ||
| 196 | EjectaAging aging = EjectaAging::Freshness; ///< Wear with time. | ||
| 197 | double minFreshness = 0.7; ///< Freshness at or below which a crater keeps no blocks. | ||
| 198 | double lifetimeGyr = 4.0; ///< Age at which a crater keeps no blocks, for `Age`. | ||
| 199 | double agingExponent = 3.0; ///< Exponent of the `Age` wear. | ||
| 200 | /// Surface gravity (m/s^2): when set with `regolithThickness`, a crater's blocks reach no | ||
| 201 | /// further than `BoulderThrowDistance`. | ||
| 202 | std::optional<double> gravity{}; | ||
| 203 | |||
| 204 | /// The diameter (m) of the smallest crater that throws blocks, from `minCraterDiameter` and the | ||
| 205 | /// regolith; unset when no crater throws blocks. | ||
| 206 | std::optional<double> ThrowingDiameter() const; | ||
| 207 | |||
| 208 | /// The Golombek-Rapp k at the rim: `coverage`, or 0.1 unset. | ||
| 209 | 98 | double Coverage() const { | |
| 210 | 136 | return coverage.value_or(0.1); | |
| 211 | } | ||
| 212 | |||
| 213 | 1 | bool operator==(const BoulderEjecta& other) const { | |
| 214 | 1 | return minCraterDiameter == other.minCraterDiameter && | |
| 215 | 1 | regolithThickness == other.regolithThickness && | |
| 216 | 1 | excavationDepthRatio == other.excavationDepthRatio && | |
| 217 | 1 | distribution == other.distribution && coverage == other.coverage && | |
| 218 | 1 | profile == other.profile && reach == other.reach && decayRadii == other.decayRadii && | |
| 219 | 1 | floorShare == other.floorShare && aging == other.aging && | |
| 220 | 1 | minFreshness == other.minFreshness && lifetimeGyr == other.lifetimeGyr && | |
| 221 | 1 | agingExponent == other.agingExponent && gravity == other.gravity; | |
| 222 | } | ||
| 223 | }; | ||
| 224 | |||
| 225 | /// The greatest throw (m) of blocks from a crater's center over a regolith blanket, Bart and | ||
| 226 | /// Melosh's (2010, eq. 9) (138.5 / g) (D / H)^0.7086, with D and H in meters and g in m/s^2. | ||
| 227 | /// @throws std::invalid_argument unless every argument is positive and finite. | ||
| 228 | double BoulderThrowDistance(double craterDiameter, double regolithThickness, double gravity); | ||
| 229 | |||
| 230 | /// Boulders breaking out of bedrock: abundance scales from 1 on soil to `abundance` on | ||
| 231 | /// bedrock, in proportion to the exposure. | ||
| 232 | 6 | struct BoulderBedrock { | |
| 233 | /// The exposure field; unset for no bedrock boulders. | ||
| 234 | std::optional<ExposureParams> exposure{}; | ||
| 235 | double abundance = 3.0; ///< Abundance on bedrock over that on soil. | ||
| 236 | /// With a density map, the side (m) of the squares bedrock is held to the map's mean over, so | ||
| 237 | /// it gathers boulders without adding any; a raster map's own cells are used instead. | ||
| 238 | double meanSize = 1000.0; | ||
| 239 | |||
| 240 | 1 | bool operator==(const BoulderBedrock& other) const { | |
| 241 | 1 | return exposure == other.exposure && abundance == other.abundance && | |
| 242 | 1 | meanSize == other.meanSize; | |
| 243 | } | ||
| 244 | }; | ||
| 245 | |||
| 246 | /// How each boulder stands, drawn per boulder uniformly between these. | ||
| 247 | 8 | struct BoulderPose { | |
| 248 | double minHeightRatio = 0.4; ///< Least boulder height over diameter. | ||
| 249 | double maxHeightRatio = 0.6; ///< Greatest boulder height over diameter. | ||
| 250 | double minBurial = 0.1; ///< Least buried share of the height. | ||
| 251 | double maxBurial = 0.4; ///< Greatest buried share of the height. | ||
| 252 | double maxLeanDegrees = 0.26 * kRadian; ///< Largest tilt from the vertical, about 15 deg. | ||
| 253 | /// How far wear sets burial, from 0 to 1: the buried share is drawn at (1 - b) u + b w of the | ||
| 254 | /// way from `minBurial` to `maxBurial`, with u uniform and w the boulder's wear. A crater's | ||
| 255 | /// blocks wear with it (0 fresh to 1 gone); boulders between craters span every stage, their | ||
| 256 | /// wear uniform. 0 draws burial uniformly. | ||
| 257 | double burialByWear = 0.0; | ||
| 258 | /// Share of boulders resting on a side, their intermediate axis up, rather than their face. | ||
| 259 | double sideShare = 0.0; | ||
| 260 | /// Share of boulders standing on an end, their long axis up; with `sideShare`, at most 1. | ||
| 261 | double endShare = 0.0; | ||
| 262 | /// Largest tilt of a boulder's up axis from the vertical in a random direction, after its lean | ||
| 263 | /// (degrees); drawn uniformly in the cosine, so steep tilts are as likely as on a sphere cap. | ||
| 264 | double maxTiltDegrees = 0.0; | ||
| 265 | /// Settles each boulder on the slope of the ground beneath it, its up axis along the ground's | ||
| 266 | /// normal before the tilt; needs the ground. | ||
| 267 | bool followSlope = false; | ||
| 268 | /// Tips each boulder model over, from its drawn pose, until it rests stably on level ground | ||
| 269 | /// (`PlaceBoulderModel`), before the tilt and the slope; off leaves shapes as drawn, some | ||
| 270 | /// balanced on an edge or corner. | ||
| 271 | bool settle = true; | ||
| 272 | /// Steepest ground, measured across a boulder's diameter, that boulders stay on (degrees); | ||
| 273 | /// boulders on steeper ground are left out, models and boulders drawn into the heights alike, | ||
| 274 | /// so which boulders exist does not depend on the spacing. Unset keeps boulders on any slope; | ||
| 275 | /// needs the ground. | ||
| 276 | std::optional<double> maxSlopeDegrees{}; | ||
| 277 | /// With `maxSlope`, boulders on steeper ground roll down it instead, in steps along the | ||
| 278 | /// steepest descent, and come to rest where it is no steeper than `maxSlope`, gathering at the | ||
| 279 | /// foot of slopes; those that would roll farther than this many meters are left out. Unset | ||
| 280 | /// leaves out every boulder on steeper ground. | ||
| 281 | std::optional<double> rollDistance{}; | ||
| 282 | |||
| 283 | 2 | bool operator==(const BoulderPose& other) const { | |
| 284 | 2 | return minHeightRatio == other.minHeightRatio && maxHeightRatio == other.maxHeightRatio && | |
| 285 | 2 | minBurial == other.minBurial && maxBurial == other.maxBurial && | |
| 286 | 2 | maxLeanDegrees == other.maxLeanDegrees && burialByWear == other.burialByWear && | |
| 287 | 2 | sideShare == other.sideShare && endShare == other.endShare && | |
| 288 | 2 | maxTiltDegrees == other.maxTiltDegrees && followSlope == other.followSlope && | |
| 289 | 4 | settle == other.settle && maxSlopeDegrees == other.maxSlopeDegrees && | |
| 290 | 2 | rollDistance == other.rollDistance; | |
| 291 | } | ||
| 292 | }; | ||
| 293 | |||
| 294 | /// Regolith piled against each boulder's base, drawn into the heights around boulders drawn | ||
| 295 | /// there and around boulder models alike: it meets the boulder's flank where the rock stands | ||
| 296 | /// `heightShare` of the exposed height (`FilletContact`), then falls as (1 - t)^2 to nothing | ||
| 297 | /// `widthRatio` diameters beyond the boulder's radius. Within that contact the boulder shows. | ||
| 298 | 4 | struct BoulderFillet { | |
| 299 | double heightShare = 0.0; ///< Height over the boulder's exposed height, in [0, 1]; 0 for none. | ||
| 300 | double widthRatio = 0.3; ///< Reach beyond the boulder's radius, over its diameter. | ||
| 301 | |||
| 302 | 1 | bool operator==(const BoulderFillet& other) const { | |
| 303 | 1 | return heightShare == other.heightShare && widthRatio == other.widthRatio; | |
| 304 | } | ||
| 305 | }; | ||
| 306 | |||
| 307 | /// Ventifacts: windward facets planed on boulders by sand-laden wind, set once the boulder has | ||
| 308 | /// settled. A facet faces upwind at `minAngle` to `maxAngle` from horizontal and meets the ground | ||
| 309 | /// at the boulder's upwind edge when fresh, moving in to its center as it wears; boulders with a | ||
| 310 | /// keel carry a second facet facing the second wind. Angles are in degrees. | ||
| 311 | 4 | struct BoulderVentifacts { | |
| 312 | double share = 0.0; ///< Share of boulders with a facet, in [0, 1]; 0 for none. | ||
| 313 | /// Where the wind blows toward, degrees counter-clockwise from east. | ||
| 314 | double windAzimuthDegrees = 0.0; | ||
| 315 | double minAngleDegrees = 50.0; ///< Gentlest facet slope. | ||
| 316 | double maxAngleDegrees = 60.0; ///< Steepest facet slope. | ||
| 317 | /// A second formative wind, where it blows toward; unset gives no keels. | ||
| 318 | std::optional<double> secondWindAzimuthDegrees{}; | ||
| 319 | /// Share of faceted boulders with a second facet and a keel between, in [0, 1]. | ||
| 320 | double keelShare = 0.0; | ||
| 321 | |||
| 322 | 1 | bool operator==(const BoulderVentifacts& other) const { | |
| 323 | 1 | return share == other.share && windAzimuthDegrees == other.windAzimuthDegrees && | |
| 324 | 1 | minAngleDegrees == other.minAngleDegrees && | |
| 325 | 1 | maxAngleDegrees == other.maxAngleDegrees && | |
| 326 | 2 | secondWindAzimuthDegrees == other.secondWindAzimuthDegrees && | |
| 327 | 1 | keelShare == other.keelShare; | |
| 328 | } | ||
| 329 | }; | ||
| 330 | |||
| 331 | /// Checks boulder ventifacts against their field ranges (`CheckRanges`) and facet angles in order. | ||
| 332 | /// @throws std::invalid_argument naming the first field out of its range, or for a minimum facet | ||
| 333 | /// angle above the maximum. | ||
| 334 | void ValidateBoulderVentifacts(const BoulderVentifacts& ventifacts); | ||
| 335 | |||
| 336 | /// The ventifacts of Gale crater's Bradbury Landing to Rocknest traverse: half the rocks are | ||
| 337 | /// ventifacts and 78% of those faceted, 39% faceted in all, 12 of the 39 faceted with keels | ||
| 338 | /// (Bridges et al. 2014), and facets of 50 to 60 deg as on basalt (Laity and Bridges 2009). The | ||
| 339 | /// winds are left to the site: Gale's came from the southwest and north-northeast. | ||
| 340 | BoulderVentifacts GaleVentifacts(); | ||
| 341 | |||
| 342 | /// Where a fillet meets its boulder along one direction from the boulder's center: the rock's | ||
| 343 | /// outermost point there as high as the fillet stands, `heightShare` of the boulder's exposed | ||
| 344 | /// height, or the rock's highest point where it stands lower. | ||
| 345 | 1441685 | struct FilletContact { | |
| 346 | double distance = 0.0; ///< Distance (m) from the boulder's center. | ||
| 347 | double height = 0.0; ///< Height (m) of the rock there, which the fillet rises to. | ||
| 348 | |||
| 349 | bool operator==(const FilletContact& other) const { | ||
| 350 | return distance == other.distance && height == other.height; | ||
| 351 | } | ||
| 352 | }; | ||
| 353 | |||
| 354 | /// Where `fillet` meets `boulder` drawn as an uncut dome, the same in every direction: where the | ||
| 355 | /// dome stands `heightShare` of its exposed height. | ||
| 356 | FilletContact DomeFilletContact(const Boulder& boulder, const BoulderFillet& fillet); | ||
| 357 | |||
| 358 | /// The height (m) of `boulder`'s fillet `distance` meters from its center along a direction where | ||
| 359 | /// it meets the boulder at `contact`: 0 nearer the center, where the rock stands above it, then | ||
| 360 | /// falling from the contact's height as (1 - t)^2 to nothing `widthRatio` diameters beyond the | ||
| 361 | /// farther of the boulder's radius and the contact. | ||
| 362 | double FilletHeight(const Boulder& boulder, double distance, const BoulderFillet& fillet, | ||
| 363 | const FilletContact& contact); | ||
| 364 | |||
| 365 | /// The height (m) of `boulder`'s fillet `distance` meters from its center around `boulder` drawn | ||
| 366 | /// as an uncut dome (`DomeFilletContact`). | ||
| 367 | double FilletHeight(const Boulder& boulder, double distance, const BoulderFillet& fillet); | ||
| 368 | |||
| 369 | /// How far (m) from its center `boulder`'s fillet reaches: its radius plus the fillet's width, or | ||
| 370 | /// that width beyond a contact farther out on a shape wider than its diameter. | ||
| 371 | double FilletReach(const Boulder& boulder, const BoulderFillet& fillet); | ||
| 372 | |||
| 373 | /// Which boulders are drawn into the heights: those from `minDiameter` up to `maxDiameter` that are | ||
| 374 | /// not models, and models too with `models`. Boulders drawn neither way stay in the lists only, | ||
| 375 | /// such as those too small to matter at the grid's scale. | ||
| 376 | ✗ | struct BoulderReliefRange { | |
| 377 | double minDiameter = 0.0; ///< Smallest boulder drawn (m). | ||
| 378 | std::optional<double> maxDiameter{}; ///< Boulders this wide (m) or wider are not drawn. | ||
| 379 | bool includeModels = false; ///< Draw models into the heights as well, as for far views. | ||
| 380 | |||
| 381 | /// Whether a boulder of `diameter` meters, a model or not, is drawn into the heights. | ||
| 382 | 62792 | bool Holds(double diameter, bool model) const { | |
| 383 | 62792 | return diameter >= minDiameter && (!maxDiameter || diameter < *maxDiameter) && | |
| 384 | 3258 | (!model || includeModels); | |
| 385 | } | ||
| 386 | |||
| 387 | 3 | bool operator==(const BoulderReliefRange& other) const { | |
| 388 | 3 | return minDiameter == other.minDiameter && maxDiameter == other.maxDiameter && | |
| 389 | 3 | includeModels == other.includeModels; | |
| 390 | } | ||
| 391 | }; | ||
| 392 | |||
| 393 | /// How boulders are drawn: as relief in the heights or as 3D models, and with which shapes. | ||
| 394 | 22 | struct BoulderRendering { | |
| 395 | BoulderRelief relief = BoulderRelief::Dome; ///< Look of boulders drawn into the heights. | ||
| 396 | BoulderModelThreshold modelThreshold{}; ///< Which boulders are 3D models. | ||
| 397 | BoulderReliefRange reliefRange{}; ///< Which boulders are drawn into the heights. | ||
| 398 | /// The 3D shapes of the boulders, for `BoulderRelief::Shape` and for models. | ||
| 399 | BoulderShapeOptions shapes{}; | ||
| 400 | /// How many shapes the boulders share, for instancing; 0 gives every boulder its own | ||
| 401 | /// (`BoulderShapeSeed`). | ||
| 402 | std::uint32_t shapePrototypes = 64; | ||
| 403 | |||
| 404 | 3 | bool operator==(const BoulderRendering& other) const { | |
| 405 | 3 | return relief == other.relief && modelThreshold == other.modelThreshold && | |
| 406 | 6 | reliefRange == other.reliefRange && shapes == other.shapes && | |
| 407 | 3 | shapePrototypes == other.shapePrototypes; | |
| 408 | } | ||
| 409 | }; | ||
| 410 | |||
| 411 | /// How a `BoulderLayer` sizes, places, poses and draws its boulders. | ||
| 412 | struct BoulderLayerOptions { | ||
| 413 | /// Draws random boulders from `sizes` between craters and from `ejecta` around them; off | ||
| 414 | /// places only the `manual` boulders, draws no candidates and no crater blocks, and leaves | ||
| 415 | /// `sizes`, `ejecta` and the abundance settings unchecked and unused. | ||
| 416 | bool generateRandom = true; | ||
| 417 | BoulderSizes sizes{}; ///< Sizes of the boulders between craters. | ||
| 418 | std::uint32_t seed = 1; ///< Varies the boulders. | ||
| 419 | BoulderPatches patches{}; ///< Richer and poorer patches. | ||
| 420 | BoulderClusters clusters{}; ///< Clusters between craters; none by default. | ||
| 421 | BoulderEjecta ejecta{}; ///< Blocks around fresh craters. | ||
| 422 | BoulderBedrock bedrock{}; ///< Extra boulders on bedrock. | ||
| 423 | BoulderPose pose{}; ///< Heights, burial, lean. | ||
| 424 | BoulderFillet fillet{}; ///< Regolith piled against each boulder; none by default. | ||
| 425 | BoulderVentifacts ventifacts{}; ///< Facets planed by the wind; none by default. | ||
| 426 | std::optional<BoulderFragmentation> fragmentation{}; ///< Boulders broken by wear; none unset. | ||
| 427 | BoulderRendering rendering{}; ///< Relief or models, and shapes. | ||
| 428 | /// Which boulders are drawn into the heights by their size in samples of the evaluation | ||
| 429 | /// spacing: none narrower than `startSamples` (2, the fewest that resolve one), in full from | ||
| 430 | /// `endSamples`. Grids, tiles and points at one spacing agree; the lists and models hold | ||
| 431 | /// every boulder whatever its size. | ||
| 432 | ResolutionFade fade{}; | ||
| 433 | /// Spacing (m) at which the layer reads the ground beneath it, for the exposure field, | ||
| 434 | /// placement, settling, slopes and breaking; fixed so that which boulders exist and how they | ||
| 435 | /// sit does not depend on the level of detail. | ||
| 436 | double groundSpacing = 1.0; | ||
| 437 | /// Most boulder candidates to keep generated cells of; 0 regenerates cells every time. | ||
| 438 | std::size_t cacheBoulders = 4000000; | ||
| 439 | /// A map that sets the abundance of boulders between craters point by point, measuring the | ||
| 440 | /// boulder sizes (`DensityMap`); with `total` the blocks around craters are taken out of what | ||
| 441 | /// it measures first. Patches, clusters and bedrock still spread boulders within it. Unset | ||
| 442 | /// keeps the abundance `sizes` sets everywhere. | ||
| 443 | std::optional<DensityMap> densityMap{}; | ||
| 444 | /// A map of how steeply boulder counts fall with size (`SizeSlopeMap`), such as a mean | ||
| 445 | /// diameter map, bending the sizes between craters into a local power law through their count | ||
| 446 | /// at its reference diameter; needs a size distribution rather than Golombek-Rapp sizes. Unset | ||
| 447 | /// keeps the sizes' own shape everywhere. | ||
| 448 | std::optional<SizeSlopeMap> slopeMap{}; | ||
| 449 | /// Boulders from a catalog or placed by hand, placed as given and never thinned or left out; | ||
| 450 | /// IDs of 0 come from position and size (`ManualCraterId`). Fields they leave unset are drawn | ||
| 451 | /// as for generated boulders; those fixing any field are never broken, and those fixing their | ||
| 452 | /// orientation are not tipped over by `pose.settle`. | ||
| 453 | std::vector<ManualBoulder> manual{}; | ||
| 454 | /// The diameter (m) from which `manual` is a complete catalog at each point: generated boulders | ||
| 455 | /// at least this large centered there are dropped, so the catalog stands in for them. Infinite | ||
| 456 | /// or NaN where there is no catalog; unset keeps every generated boulder. | ||
| 457 | std::shared_ptr<const SurfaceField> completeness{}; | ||
| 458 | /// Source cells across from which the source's measured data already holds a boulder: with a | ||
| 459 | /// source given to the layer, generated boulders at least that many of its cells across are | ||
| 460 | /// dropped (`SourceResolvedLimit`), the minimum with `completeness` when both are set. Unset, | ||
| 461 | /// or without a source, keeps every generated boulder. | ||
| 462 | std::optional<double> sourceResolvesPixels{}; | ||
| 463 | |||
| 464 | 1 | bool operator==(const BoulderLayerOptions& other) const { | |
| 465 | 1 | return generateRandom == other.generateRandom && sizes == other.sizes && | |
| 466 | 2 | seed == other.seed && patches == other.patches && clusters == other.clusters && | |
| 467 | 1 | ejecta == other.ejecta && bedrock == other.bedrock && pose == other.pose && | |
| 468 | 2 | fillet == other.fillet && ventifacts == other.ventifacts && | |
| 469 | 1 | fragmentation == other.fragmentation && rendering == other.rendering && | |
| 470 | 2 | fade == other.fade && groundSpacing == other.groundSpacing && | |
| 471 | 1 | cacheBoulders == other.cacheBoulders && densityMap == other.densityMap && | |
| 472 | 1 | slopeMap == other.slopeMap && manual == other.manual && | |
| 473 | 2 | completeness == other.completeness && | |
| 474 | 1 | sourceResolvesPixels == other.sourceResolvesPixels; | |
| 475 | } | ||
| 476 | }; | ||
| 477 | |||
| 478 | /// Checks boulder patches against their field ranges (`CheckRanges`). | ||
| 479 | /// @throws std::invalid_argument naming the first field out of its range. | ||
| 480 | void ValidateBoulderPatches(const BoulderPatches& patches); | ||
| 481 | |||
| 482 | /// Checks boulder clusters against their field ranges (`CheckRanges`) and the radius against the | ||
| 483 | /// spacing: below it for `Nearest`, at most twice it for `Thomas`. | ||
| 484 | /// @throws std::invalid_argument naming the first field out of its range, or for a radius too | ||
| 485 | /// large for the spacing. | ||
| 486 | void ValidateBoulderClusters(const BoulderClusters& clusters); | ||
| 487 | |||
| 488 | /// Checks boulder fragmentation against its field ranges (`CheckRanges`), with `splitWear` <= | ||
| 489 | /// `rubbleWear` and `minPieces` <= `maxPieces`. | ||
| 490 | /// @throws std::invalid_argument naming the first field out of its range, or for wears or piece | ||
| 491 | /// counts out of order. | ||
| 492 | void ValidateBoulderFragmentation(const BoulderFragmentation& fragmentation); | ||
| 493 | |||
| 494 | /// Checks boulder fillets against their field ranges (`CheckRanges`). | ||
| 495 | /// @throws std::invalid_argument naming the first field out of its range. | ||
| 496 | void ValidateBoulderFillet(const BoulderFillet& fillet); | ||
| 497 | |||
| 498 | /// Checks a manual boulder against its field ranges (`CheckRanges`). | ||
| 499 | /// @throws std::invalid_argument naming the first field out of its range. | ||
| 500 | void ValidateManualBoulder(const ManualBoulder& boulder); | ||
| 501 | |||
| 502 | /// The ID a manual boulder is placed with: its own, or `ManualCraterId` of its position and size | ||
| 503 | /// when it has none (or 0). | ||
| 504 | std::uint64_t ManualBoulderId(const ManualBoulder& boulder); | ||
| 505 | |||
| 506 | /// Checks boulder layer options against their field ranges (`CheckRanges`) and what ties them | ||
| 507 | /// together; size distributions and crater blocks only with `generateRandom`. | ||
| 508 | /// @throws std::invalid_argument naming the first field out of its range, or for any invalid | ||
| 509 | /// part, a coverage that patches and bedrock raise to 1 or more, an unused Golombek-Rapp term, or | ||
| 510 | /// shared IDs. | ||
| 511 | void ValidateBoulderLayerOptions(const BoulderLayerOptions& options); | ||
| 512 | |||
| 513 | } // namespace terraingen | ||
| 514 |