include/terraingen/layers/boulders/boulder_layer.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief `BoulderLayer`, boulders scattered over the ground and around fresh craters. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/distribution/size_frequency.h" | ||
| 8 | #include "terraingen/layers/boulders/boulder.h" | ||
| 9 | #include "terraingen/layers/boulders/boulder_abundance.h" | ||
| 10 | #include "terraingen/layers/boulders/boulder_fragments.h" | ||
| 11 | #include "terraingen/layers/boulders/boulder_models.h" | ||
| 12 | #include "terraingen/layers/boulders/boulder_options.h" | ||
| 13 | #include "terraingen/layers/boulders/boulder_placer.h" | ||
| 14 | #include "terraingen/layers/boulders/ejecta_index.h" | ||
| 15 | #include "terraingen/layers/craters/crater_layer.h" | ||
| 16 | #include "terraingen/layers/craters/generation/population.h" | ||
| 17 | #include "terraingen/layers/exposure.h" | ||
| 18 | #include "terraingen/layers/layer.h" | ||
| 19 | #include "terraingen/layers/material.h" | ||
| 20 | #include "terraingen/random/stream.h" | ||
| 21 | #include "terraingen/sources/source.h" | ||
| 22 | #include "terraingen/util/lru_cache.h" | ||
| 23 | |||
| 24 | #include <array> | ||
| 25 | #include <cstdint> | ||
| 26 | #include <memory> | ||
| 27 | #include <optional> | ||
| 28 | #include <unordered_map> | ||
| 29 | #include <vector> | ||
| 30 | |||
| 31 | namespace terraingen { | ||
| 32 | |||
| 33 | class CraterCellCache; | ||
| 34 | |||
| 35 | /// How rich the boulders are at a point. | ||
| 36 | struct BoulderAbundance { | ||
| 37 | /// Density of the boulders between craters over its mean, from patches and bedrock. | ||
| 38 | double background = 1.0; | ||
| 39 | /// Share of fresh crater blocks, from the profile and age of the craters around. | ||
| 40 | double ejecta = 0.0; | ||
| 41 | /// Wear of the crater the ejecta share comes from, from 0 (fresh) to 1 (its blocks gone). | ||
| 42 | double ejectaWear = 0.0; | ||
| 43 | /// The size exponent a size slope map gives here (`SizeSlopeAt`); none keeps the sizes' shape. | ||
| 44 | std::optional<double> exponent; | ||
| 45 | |||
| 46 | 1 | bool operator==(const BoulderAbundance& other) const { | |
| 47 | 1 | return background == other.background && ejecta == other.ejecta && | |
| 48 | 2 | ejectaWear == other.ejectaWear && exponent == other.exponent; | |
| 49 | } | ||
| 50 | }; | ||
| 51 | |||
| 52 | /// The share of a sample's area covered by boulders too small to resolve in it. | ||
| 53 | 330024 | struct UnresolvedCover { | |
| 54 | double mean = 0.0; ///< Expected share. | ||
| 55 | double variance = 0.0; ///< Variance of the share from the boulders' Poisson scatter. | ||
| 56 | |||
| 57 | 100 | bool operator==(const UnresolvedCover& other) const { | |
| 58 | 100 | return mean == other.mean && variance == other.variance; | |
| 59 | } | ||
| 60 | }; | ||
| 61 | |||
| 62 | /// Boulders scattered over the ground, in patches and richer on bedrock, plus blocks around fresh | ||
| 63 | /// craters; they depend only on position, so every grid, tile and point agrees. | ||
| 64 | class BoulderLayer final : public Layer, public BoulderPlacer, public MaterialSource { | ||
| 65 | public: | ||
| 66 | /// A layer of only `boulders`, with `generateRandom` off: no random boulders or crater blocks. | ||
| 67 | /// @param options How the boulders are posed and drawn, such as `rendering`, `pose` and | ||
| 68 | /// `fillet`; its `manual` must be empty, `boulders` taking its place. | ||
| 69 | /// @throws std::invalid_argument as the constructor, or for `options.manual` not empty. | ||
| 70 | static std::shared_ptr<BoulderLayer> Manual(std::vector<ManualBoulder> boulders, | ||
| 71 | BoulderLayerOptions options = {}, | ||
| 72 | TerrainBase base = {}); | ||
| 73 | |||
| 74 | /// Builds the layer; on a sphere each boulder lies in its local east, north and up frame. | ||
| 75 | /// @param craters The layer whose craters throw blocks; may be null without ejecta. | ||
| 76 | /// @param base The surface, which must be the crater layer's, and the source. | ||
| 77 | /// @throws std::invalid_argument for invalid options, ejecta without `craters`, or a crater | ||
| 78 | /// layer on another surface. | ||
| 79 | BoulderLayer(BoulderLayerOptions options, std::shared_ptr<const CraterLayer> craters = nullptr, | ||
| 80 | TerrainBase base = {}); | ||
| 81 | |||
| 82 | /// Boulders whose ejecta come from every one of `craters`, each crater's blocks worn by its | ||
| 83 | /// own layer's degradation; overlapping ejecta take the largest share as within one layer. | ||
| 84 | /// @throws std::invalid_argument as the single-layer constructor, or for a null layer. | ||
| 85 | BoulderLayer(BoulderLayerOptions options, | ||
| 86 | std::vector<std::shared_ptr<const CraterLayer>> craters, TerrainBase base); | ||
| 87 | |||
| 88 | /// The boulders centered in or reaching `region` (surface coordinates), in a fixed order. | ||
| 89 | /// @param spacing Sample spacing in meters; boulders too narrow to resolve at it are left out, | ||
| 90 | /// and 0 keeps every boulder. | ||
| 91 | /// @param ground Needed with the exposure field. | ||
| 92 | /// @throws std::invalid_argument if the exposure field is enabled and `ground` is null. | ||
| 93 | BoulderList Boulders(const Bounds2d& region, double spacing = 0.0, | ||
| 94 | const Ground* ground = nullptr) const; | ||
| 95 | |||
| 96 | /// The background and ejecta abundance at surface (x, y); both 0 without `generateRandom`. | ||
| 97 | /// @param ground Needed with the exposure field. | ||
| 98 | /// @throws std::invalid_argument if the exposure field is enabled and `ground` is null. | ||
| 99 | BoulderAbundance AbundanceAt(double x, double y, const Ground* ground = nullptr) const; | ||
| 100 | |||
| 101 | /// The plan-area share of a sample `spacing` meters across at surface (x, y) covered by | ||
| 102 | /// boulders too small to resolve, with its Poisson variance. | ||
| 103 | /// @param ground Needed with the exposure field. | ||
| 104 | /// @throws std::invalid_argument if the exposure field is enabled and `ground` is null. | ||
| 105 | UnresolvedCover UnresolvedCoverAt(double x, double y, double spacing, | ||
| 106 | const Ground* ground = nullptr) const; | ||
| 107 | /// `UnresolvedCoverAt` at every cell center of `grid`, row-major, the ejecta craters found | ||
| 108 | /// once. | ||
| 109 | /// @throws std::invalid_argument as `UnresolvedCoverAt`. | ||
| 110 | std::vector<UnresolvedCover> UnresolvedCoverOver(const RasterGrid& grid, double spacing, | ||
| 111 | const Ground* ground, unsigned threads) const; | ||
| 112 | |||
| 113 | /// The largest boulder (m): `sizes.maxDiameter` with `generateRandom`, or the largest manual | ||
| 114 | /// boulder when larger. | ||
| 115 | double MaxFeatureDiameter() const; | ||
| 116 | |||
| 117 | /// The options the layer was made with. | ||
| 118 | 80 | const BoulderLayerOptions& Options() const { | |
| 119 | 80 | return m_options; | |
| 120 | } | ||
| 121 | |||
| 122 | 180 | std::optional<TerrainBase> LayerBase() const override { | |
| 123 | 214 | return TerrainBase{m_surface, m_source}; | |
| 124 | } | ||
| 125 | |||
| 126 | /// How far beyond the samples the largest boulder's center can start and roll, plus how far | ||
| 127 | /// around it its gradient and exposure field read. | ||
| 128 | double GroundReach(double spacing) const override; | ||
| 129 | |||
| 130 | /// The crater layers whose craters throw blocks, which must come before this layer. | ||
| 131 | 146 | std::vector<const Layer*> Dependencies() const override { | |
| 132 | 146 | std::vector<const Layer*> layers; | |
| 133 | 213 | for (const std::shared_ptr<const CraterLayer>& craters : m_craters) { | |
| 134 | 67 | layers.push_back(craters.get()); | |
| 135 | } | ||
| 136 | 146 | return layers; | |
| 137 | } | ||
| 138 | |||
| 139 | /// The layer with its seed `ReseedWord(seed, 0)` and its shapes' seed | ||
| 140 | /// (`rendering.shapes.seed`) `ReseedWord(seed, 1)`, on the same crater layers. | ||
| 141 | LayerPtr Reseeded(std::uint64_t seed) const override; | ||
| 142 | |||
| 143 | /// A copy reading the replacements of its crater layers; null when none is replaced. | ||
| 144 | LayerPtr Rebound(const LayerReplacements& replaced) const override; | ||
| 145 | |||
| 146 | /// The layer built again from its options and crater layers on `base`. | ||
| 147 | /// @throws std::invalid_argument as the constructor. | ||
| 148 | LayerPtr Rebased(const TerrainBase& base) const override; | ||
| 149 | |||
| 150 | /// The 3D shape of a boulder, shared between boulders with the same shape seed; for a | ||
| 151 | /// fragment, its piece of its parent's shape. | ||
| 152 | std::shared_ptr<const BoulderShape> Shape(const Boulder& boulder) const; | ||
| 153 | |||
| 154 | /// The boulders of `boulders` to place as their own 3D models: those marked `model` whose | ||
| 155 | /// ground is known, placed on it. | ||
| 156 | std::vector<BoulderModel> Models(const std::vector<Boulder>& boulders) const; | ||
| 157 | |||
| 158 | BoulderFeatures BouldersOver(const RasterGrid& grid, double spacing, | ||
| 159 | const Ground* ground) const override; | ||
| 160 | |||
| 161 | 3074 | MaterialClass Material() const override { | |
| 162 | 3074 | return MaterialClass::Rock; | |
| 163 | } | ||
| 164 | /// The weight at `context.spacing` of the boulder whose rock stands at surface (x, y), a | ||
| 165 | /// model's over its footprint; 0 between boulders and on fillets. | ||
| 166 | /// @throws std::invalid_argument if the exposure field is enabled and `context.ground` is | ||
| 167 | /// null. | ||
| 168 | double MaterialCoverAt(double x, double y, const LayerContext& context) const override; | ||
| 169 | /// `MaterialCoverAt` over `grid`, the boulders found once for the whole grid. | ||
| 170 | /// @throws std::invalid_argument as `MaterialCoverAt`. | ||
| 171 | Raster<double> MaterialCoverOver(const RasterGrid& grid, | ||
| 172 | const LayerContext& context) const override; | ||
| 173 | |||
| 174 | protected: | ||
| 175 | /// Draws the exposed parts of non-model boulders into the samples. | ||
| 176 | /// @throws std::invalid_argument if the exposure field is enabled and `context.ground` is null. | ||
| 177 | void ApplySamples(SampleBlock& samples, const LayerContext& context) const override; | ||
| 178 | |||
| 179 | private: | ||
| 180 | /// The purposes a boulder draws numbers for, each its own substream of its ID. | ||
| 181 | enum class BoulderDraw : std::uint32_t { Keep, Pose, Wear, Settle, Abrade, Fragments }; | ||
| 182 | /// The substream of `kBoulderAttributeStream` for boulder or shape `id` and purpose `draw`. | ||
| 183 | RandomStream AttributeStream(std::uint64_t id, BoulderDraw draw) const; | ||
| 184 | /// Builds the background abundance models, the candidate sizes and the cluster mean. | ||
| 185 | void SetUpAbundance(); | ||
| 186 | /// Sets the lattice bedrock means are taken over and their cache. | ||
| 187 | void SetUpBedrockMeans(); | ||
| 188 | /// Makes the caches of shared shapes and their fragments. | ||
| 189 | void SetUpShapeCaches(); | ||
| 190 | /// The boulders centered in `region` or reaching it, as `Boulders`, leaving out those and the | ||
| 191 | /// pieces narrower than `smallest` meters (0 keeps every one) and marking models at `spacing`. | ||
| 192 | std::vector<Boulder> PlaceBoulders(const Bounds2d& region, double spacing, double smallest, | ||
| 193 | const Ground* ground, unsigned threads) const; | ||
| 194 | /// The candidates of `region` at least `smallest` meters across (0 for all), before thinning; | ||
| 195 | /// only the manual boulders reaching it without `generateRandom`. | ||
| 196 | CraterList ScatterBoulderCandidates(const Bounds2d& region, double smallest) const; | ||
| 197 | /// A candidate thinning keeps, with what it was kept by. | ||
| 198 | struct ThinnedCandidate { | ||
| 199 | Crater candidate; | ||
| 200 | BoulderAbundance abundance; | ||
| 201 | double density = 0.0; | ||
| 202 | }; | ||
| 203 | /// `candidate` with its abundance and density, or nothing when thinning drops it. | ||
| 204 | std::optional<ThinnedCandidate> Thin(const Crater& candidate, const Ground* ground, | ||
| 205 | const EjectaIndex& ejecta) const; | ||
| 206 | /// The boulder a thinned candidate becomes before it meets the ground: its size, burial, | ||
| 207 | /// yaw, lean and wear drawn by its ID, then those `fixed` sets (null for none) and its shape | ||
| 208 | /// seed, and whether it is a model at `spacing`. | ||
| 209 | Boulder DrawPose(const ThinnedCandidate& thinned, double spacing, | ||
| 210 | const ManualBoulder* fixed) const; | ||
| 211 | /// The manual boulder of ID `id` that fixes any of its fields, or null. | ||
| 212 | const ManualBoulder* Fixed(std::uint64_t id) const; | ||
| 213 | /// Whether `boulder`'s model is tipped over to rest stably: with `pose.settle`, unless it is | ||
| 214 | /// a manual boulder that fixes its orientation. | ||
| 215 | bool Settles(const Boulder& boulder) const; | ||
| 216 | /// A thinned candidate as a boulder on `ground`, or nothing when it is left out on steep | ||
| 217 | /// ground. | ||
| 218 | std::optional<Boulder> PlaceCandidate(const ThinnedCandidate& thinned, double spacing, | ||
| 219 | const Ground* ground) const; | ||
| 220 | /// Sets `boulder`'s ground height from `ground` under its center; unset without a ground or | ||
| 221 | /// where the ground is missing. | ||
| 222 | void ReadGround(Boulder& boulder, const Ground* ground) const; | ||
| 223 | /// The boulders `candidates` give, in their order: those thinning keeps, their ground read in | ||
| 224 | /// one pass (`Ground::HeightsAt`) and then placed. | ||
| 225 | std::vector<Boulder> DrawBoulders(const CraterList& candidates, double spacing, | ||
| 226 | const Ground* ground, const EjectaIndex& ejecta, | ||
| 227 | unsigned threads) const; | ||
| 228 | /// Margin in radii a boulder's own relief and fillet reach beyond its center. | ||
| 229 | double OwnMarginRadii() const; | ||
| 230 | /// Margin in radii its pieces may scatter beyond that when boulders break. | ||
| 231 | double BreakMarginRadii() const; | ||
| 232 | /// Sets `boulder`'s resting axis and tilt from the pose options, or those `fixed` sets (null | ||
| 233 | /// for none), on the slope of `ground` when they follow it; a fixed tilt and azimuth come out | ||
| 234 | /// exactly off a followed slope. | ||
| 235 | void Settle(Boulder& boulder, const Ground* ground, const ManualBoulder* fixed) const; | ||
| 236 | /// The up axis drawn from `random` by the pose's tilt, or set by `fixedTilt`'s tilt and | ||
| 237 | /// azimuth when not null. | ||
| 238 | Vec3d UpAxis(RandomStream& random, const ManualBoulder* fixedTilt) const; | ||
| 239 | /// The rise east and north (m/m) of `ground` across `boulder`'s diameter; none where the | ||
| 240 | /// ground is missing. | ||
| 241 | std::optional<Vec2d> Gradient(const Boulder& boulder, const Ground& ground) const; | ||
| 242 | /// Rolls `boulder` down ground steeper than `maxSlope` until it rests, as `rollDistance` | ||
| 243 | /// allows; false when it would roll farther, or with no roll distance on steep ground. | ||
| 244 | bool Roll(Boulder& boulder, const Ground& ground) const; | ||
| 245 | /// The pieces `parent` breaks into at its wear, those at least `smallest` meters across, models | ||
| 246 | /// marked at `spacing` and their ground left to `ReadGrounds`; `parent` alone when it is too | ||
| 247 | /// small or too fresh to break, or a manual boulder fixing any field. | ||
| 248 | std::vector<Boulder> Break(const Boulder& parent, double spacing, double smallest) const; | ||
| 249 | /// Sets the ground of the boulders `indices` of `boulders` from `ground`, read in one pass; | ||
| 250 | /// unset without a ground or where it is missing. | ||
| 251 | void ReadGrounds(std::vector<Boulder>& boulders, const std::vector<std::size_t>& indices, | ||
| 252 | const Ground* ground, unsigned threads) const; | ||
| 253 | /// How far a breaking boulder has come apart: its cracks' opening, 0 to 1 from `splitWear` | ||
| 254 | /// to `rubbleWear`, and its pieces' scatter, 0 to 1 beyond. | ||
| 255 | struct BreakStage { | ||
| 256 | double opening = 0.0; | ||
| 257 | double scatter = 0.0; | ||
| 258 | }; | ||
| 259 | /// The stage `parent` has reached at its wear. | ||
| 260 | BreakStage Stage(const Boulder& parent) const; | ||
| 261 | /// What every piece of a breaking boulder shares: its parent's shape placed at the origin on | ||
| 262 | /// level ground, its stage and the shape's short axis. | ||
| 263 | struct PieceFrame { | ||
| 264 | BoulderPlacement placement; | ||
| 265 | BreakStage stage; | ||
| 266 | double shortAxis = 1.0; | ||
| 267 | }; | ||
| 268 | /// Piece `k`, `fragment`, of `parent`, moved out by `frame`'s stage with the uniforms `push` | ||
| 269 | /// and `twist`; its model mark and ground are left to the caller. | ||
| 270 | Boulder PlacePiece(const Boulder& parent, const BoulderFragment& fragment, std::size_t k, | ||
| 271 | const PieceFrame& frame, double push, double twist) const; | ||
| 272 | /// The pieces of the shape of seed `shapeSeed`, shared by every boulder of that shape. | ||
| 273 | std::shared_ptr<const std::vector<BoulderFragment>> | ||
| 274 | CachedFragments(std::uint64_t shapeSeed) const; | ||
| 275 | /// The shape of seed `shapeSeed`. | ||
| 276 | std::shared_ptr<const BoulderShape> CachedShape(std::uint64_t shapeSeed) const; | ||
| 277 | /// The wear (0 fresh to 1 worn) of a boulder of `diameter` keyed by `id`: that of the crater | ||
| 278 | /// its block came from, drawn by each source's share of `density`, or uniform between craters. | ||
| 279 | double Wear(double diameter, const BoulderAbundance& abundance, double density, | ||
| 280 | std::uint64_t id) const; | ||
| 281 | /// `height` at (`x`, `y`) raised to at least `base` (the height before any boulder) plus the | ||
| 282 | /// boulder's exposed part and its fillet, so boulders and fillets form a union instead of | ||
| 283 | /// stacking; `placed` is its shape placed on level ground at 0 for `BoulderRelief::Shape`, a | ||
| 284 | /// dome is averaged over `width` meters, without `rock` only the fillet is drawn, and the | ||
| 285 | /// fillet meets the boulder at `contacts` as in `Relief`. | ||
| 286 | float AddRelief(float height, float base, double x, double y, const Boulder& boulder, | ||
| 287 | const TriangleMesh* placed, double weight, bool rock, double width, | ||
| 288 | const std::vector<FilletContact>& contacts) const; | ||
| 289 | /// The height of `boulder`'s exposed rock above the ground at (`x`, `y`), 0 off it; `placed` | ||
| 290 | /// and `width` as in `AddRelief`. | ||
| 291 | double RockRelief(double x, double y, const Boulder& boulder, const TriangleMesh* placed, | ||
| 292 | double width) const; | ||
| 293 | /// `boulder` in its local frame: centered at the origin on a sphere, unchanged on a plane. | ||
| 294 | Boulder InLocalFrame(const Boulder& boulder) const; | ||
| 295 | /// `boulder`'s shape placed on level ground at 0, cut by its facets. | ||
| 296 | TriangleMesh PlacedOnLevel(const Boulder& boulder) const; | ||
| 297 | /// Gives `boulder` its ventifact facets, drawn by its ID. | ||
| 298 | void Abrade(Boulder& boulder) const; | ||
| 299 | /// Moves the points of `placed` (a mesh in `local`'s frame, on ground at height `base`) above | ||
| 300 | /// `local`'s facets onto them. | ||
| 301 | void CutFacets(TriangleMesh& placed, const Boulder& local, double base) const; | ||
| 302 | /// `shape` cut by `local`'s facets where `placement` puts it, still in the shape's own frame. | ||
| 303 | BoulderShape Abraded(const BoulderShape& shape, const BoulderPlacement& placement, | ||
| 304 | const Boulder& local, double base) const; | ||
| 305 | /// A boulder drawn into the heights: its weight at the spacing, whether its rock is drawn or | ||
| 306 | /// only its fillet, its shape placed on level ground (for `BoulderRelief::Shape`) and the box | ||
| 307 | /// its relief covers. | ||
| 308 | struct Relief { | ||
| 309 | const Boulder* boulder; | ||
| 310 | double weight; | ||
| 311 | bool rock; | ||
| 312 | double width; ///< Width a dome is averaged over: the spacing, or 0 for shapes. | ||
| 313 | std::optional<TriangleMesh> placed; | ||
| 314 | Bounds2d box; | ||
| 315 | /// Where the fillet meets the boulder: one contact for every direction around a round | ||
| 316 | /// dome, contacts at even steps of azimuth from east around a shape or model, and none | ||
| 317 | /// for a dome cut by facets, met where each sample is drawn. | ||
| 318 | std::vector<FilletContact> contacts{}; | ||
| 319 | |||
| 320 | /// The placed shape, or null for a dome. | ||
| 321 | 387512 | const TriangleMesh* Shape() const { | |
| 322 | 387512 | return placed ? &*placed : nullptr; | |
| 323 | } | ||
| 324 | }; | ||
| 325 | /// The weight of `relief` where its drawn rock stands at `p`, else 0. | ||
| 326 | double RockCover(const Relief& relief, const Vec2d& p) const; | ||
| 327 | /// The weight at `spacing` of `boulder` where it is a model over `p`, else 0. | ||
| 328 | double ModelCover(const Boulder& boulder, const Vec2d& p, double spacing) const; | ||
| 329 | /// `Boulders` as records, for the layer's own use. | ||
| 330 | std::vector<Boulder> BoulderRecords(const Bounds2d& region, double spacing, | ||
| 331 | const Ground* ground, unsigned threads) const; | ||
| 332 | /// The boulders whose relief at `spacing` can reach `region`. | ||
| 333 | std::vector<Boulder> ReliefBoulders(const Bounds2d& region, double spacing, | ||
| 334 | const Ground* ground, unsigned threads) const; | ||
| 335 | /// The boxes of `reliefs`, in order. | ||
| 336 | static std::vector<Bounds2d> Boxes(const std::vector<Relief>& reliefs); | ||
| 337 | /// The boulders of `boulders` resolved at `spacing` with relief or a fillet to draw, in order, | ||
| 338 | /// with where their fillets meet them when `fillets` is set. | ||
| 339 | std::vector<Relief> PrepareRelief(const std::vector<Boulder>& boulders, double spacing, | ||
| 340 | bool fillets) const; | ||
| 341 | |||
| 342 | /// The ejecta craters that can add blocks in `region`, indexed by how far their blocks reach. | ||
| 343 | EjectaIndex EjectaCraters(const Bounds2d& region) const; | ||
| 344 | /// The abundance at (`x`, `y`) with the ejecta craters `ejecta` around. | ||
| 345 | BoulderAbundance Abundance(double x, double y, const Ground* ground, | ||
| 346 | const EjectaIndex& ejecta) const; | ||
| 347 | /// The distance (m) from surface (x, y) to the nearest cluster center. | ||
| 348 | double NearestClusterDistance(double x, double y) const; | ||
| 349 | /// The sum at surface (x, y) of the Gaussians of the `Thomas` cluster centers around it. | ||
| 350 | double ThomasClusterField(double x, double y) const; | ||
| 351 | /// The abundance between craters at (`x`, `y`), where the crater blocks hold `ejecta` of | ||
| 352 | /// theirs. | ||
| 353 | double BackgroundAbundance(double x, double y, const Ground* ground, double ejecta) const; | ||
| 354 | /// Sets `abundance`'s ejecta share and wear at (`x`, `y`) from the craters `ejecta`. | ||
| 355 | void EjectaAbundance(double x, double y, const EjectaIndex& ejecta, | ||
| 356 | BoulderAbundance& abundance) const; | ||
| 357 | double Density(double diameter, const BoulderAbundance& abundance) const; | ||
| 358 | /// A diameter `UnresolvedCoverAt` integrates over, its plan area, and its quadrature weight | ||
| 359 | /// times the share of it left unresolved. | ||
| 360 | struct UnresolvedNode { | ||
| 361 | double diameter; | ||
| 362 | double footprint; | ||
| 363 | double weight; | ||
| 364 | }; | ||
| 365 | /// The nodes of `UnresolvedCoverAt` at `spacing`: Simpson's rule in log diameter, split where | ||
| 366 | /// the resolution fade begins. | ||
| 367 | std::vector<UnresolvedNode> UnresolvedNodes(double spacing) const; | ||
| 368 | /// Whether boulders too small to resolve at `spacing` are left; throws for a `spacing` that is | ||
| 369 | /// not positive. | ||
| 370 | bool LeavesUnresolved(double spacing) const; | ||
| 371 | /// `UnresolvedCoverAt` with the abundance there. | ||
| 372 | UnresolvedCover UnresolvedCoverWith(const BoulderAbundance& abundance, | ||
| 373 | const std::vector<UnresolvedNode>& nodes, | ||
| 374 | double spacing) const; | ||
| 375 | /// The mean bedrock factor around (`x`, `y`) on `ground` over the cells of the density map, | ||
| 376 | /// or squares of `BoulderBedrock::meanSize`, blended between the four nearest cell centers. | ||
| 377 | double BedrockMean(double x, double y, const Ground& ground) const; | ||
| 378 | |||
| 379 | /// A cell of the lattice bedrock means are taken over, on one ground. | ||
| 380 | struct BedrockCell { | ||
| 381 | const Ground* ground = nullptr; | ||
| 382 | std::int64_t i = 0; | ||
| 383 | std::int64_t j = 0; | ||
| 384 | 319936 | bool operator==(const BedrockCell& other) const { | |
| 385 | 319936 | return ground == other.ground && i == other.i && j == other.j; | |
| 386 | } | ||
| 387 | }; | ||
| 388 | struct BedrockCellHash { | ||
| 389 | std::size_t operator()(const BedrockCell& cell) const; | ||
| 390 | }; | ||
| 391 | |||
| 392 | BoulderLayerOptions m_options; | ||
| 393 | std::vector<std::shared_ptr<const CraterLayer>> m_craters; | ||
| 394 | double m_minCraterDiameter = 0.0; ///< Smallest crater throwing blocks (m); 0 for none. | ||
| 395 | double m_largestManual = 0.0; ///< Largest manual boulder (m); 0 for none. | ||
| 396 | double m_clusterMean = 1.0; | ||
| 397 | std::uint32_t m_clusterSeed = 0; ///< Seed of the cluster centers' Worley noise. | ||
| 398 | std::uint32_t m_patchSeed = 0; ///< Seed of the abundance patch noise. | ||
| 399 | double m_referenceCount = 0.0; ///< N(>=D0) of the sizes at a size slope map's D0, per m^2. | ||
| 400 | std::optional<BoulderBackground> m_background; ///< Set with `generateRandom`. | ||
| 401 | Vec2d m_bedrockOrigin{}; ///< Corner of the bedrock mean lattice, in surface units. | ||
| 402 | Vec2d m_bedrockCellSize{}; ///< Its cell sides, in surface units; signed as the map's. | ||
| 403 | std::shared_ptr<LruCache<BedrockCell, double, BedrockCellHash>> m_bedrockMeans; | ||
| 404 | std::shared_ptr<const SizeFrequencyDistribution> m_candidates; | ||
| 405 | std::shared_ptr<const SizeFrequencyDistribution> m_ejectaSizes; | ||
| 406 | std::shared_ptr<CraterCellCache> m_cache; | ||
| 407 | std::shared_ptr<LruCache<std::uint64_t, BoulderShape>> m_shapes; | ||
| 408 | std::shared_ptr<LruCache<std::uint64_t, std::vector<BoulderFragment>>> m_fragments; | ||
| 409 | LayerExposure m_exposure; | ||
| 410 | /// The manual boulders that fix any field, by the ID they are placed with. | ||
| 411 | std::unordered_map<std::uint64_t, ManualBoulder> m_fixed; | ||
| 412 | Surface m_surface; | ||
| 413 | std::shared_ptr<const Source> m_source; | ||
| 414 | /// `m_options.completeness`, the least with what the source resolves. | ||
| 415 | std::shared_ptr<const SurfaceField> m_completeness; | ||
| 416 | std::shared_ptr<const SurfaceCells> m_cells; | ||
| 417 | }; | ||
| 418 | |||
| 419 | } // namespace terraingen | ||
| 420 |