include/terraingen/layers/material.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief Surface material classes, and `MaterialSource`, the layers that lay one down. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/layers/layer.h" | ||
| 8 | #include "terraingen/raster/grid.h" | ||
| 9 | #include "terraingen/raster/raster.h" | ||
| 10 | |||
| 11 | #include <array> | ||
| 12 | #include <cstddef> | ||
| 13 | #include <cstdint> | ||
| 14 | |||
| 15 | namespace terraingen { | ||
| 16 | |||
| 17 | /// What the surface is made of at a point. | ||
| 18 | enum class MaterialClass : std::uint8_t { | ||
| 19 | Soil, ///< Unconsolidated regolith, the default everywhere. | ||
| 20 | Sand, ///< Wind-sorted sand: dunes, ripples, sand sheets and fill. | ||
| 21 | Dust, ///< Bright airfall dust. | ||
| 22 | Bedrock, ///< Exposed bedrock and outcrop. | ||
| 23 | Rock, ///< Loose rocks and boulders. | ||
| 24 | }; | ||
| 25 | |||
| 26 | /// The number of `MaterialClass` values. | ||
| 27 | inline constexpr std::size_t kMaterialClasses = 5; | ||
| 28 | |||
| 29 | /// The share of each material class at a point, indexed by `MaterialClass`; they sum to 1. | ||
| 30 | using MaterialShares = std::array<double, kMaterialClasses>; | ||
| 31 | |||
| 32 | /// Shares all of soil, the default before anything covers it. | ||
| 33 | MaterialShares SoilShares(); | ||
| 34 | |||
| 35 | /// Lays `cover`, in [0, 1], of class `material` over `shares`: every other share shrinks by | ||
| 36 | /// (1 - cover), so the shares still sum to 1. | ||
| 37 | void CoverWith(MaterialShares& shares, MaterialClass material, double cover); | ||
| 38 | |||
| 39 | /// A layer that lays a material over the surface beneath it, such as sand from dunes. | ||
| 40 | /// | ||
| 41 | /// `MaterialCoverAt` must be a function of position like the layer's heights, so material maps | ||
| 42 | /// agree on every grid and tile. | ||
| 43 | 692 | class MaterialSource { | |
| 44 | public: | ||
| 45 | 201 | virtual ~MaterialSource() = default; | |
| 46 | |||
| 47 | /// The class the layer lays down. | ||
| 48 | virtual MaterialClass Material() const = 0; | ||
| 49 | |||
| 50 | /// How fully the layer covers world (x, y) with its material, in [0, 1], evaluated as its | ||
| 51 | /// heights are in `context`: its sample spacing in meters, surface, and the ground beneath | ||
| 52 | /// it, which layers that read it need. | ||
| 53 | virtual double MaterialCoverAt(double x, double y, const LayerContext& context) const = 0; | ||
| 54 | |||
| 55 | /// `MaterialCoverAt` at every cell center of `grid` on `context.threads` threads, at | ||
| 56 | /// `context.spacing`, at least the grid's cell size. By default cell by cell; layers that | ||
| 57 | /// place features override it to find them once for the whole grid. | ||
| 58 | virtual Raster<double> MaterialCoverOver(const RasterGrid& grid, | ||
| 59 | const LayerContext& context) const; | ||
| 60 | }; | ||
| 61 | |||
| 62 | } // namespace terraingen | ||
| 63 |