./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
1 / 1
100.0%
Branches:
-
-%
Functions:
-
-%

include/terraingen/pipeline/materials.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Material maps of a terrain: the share of soil, sand, dust, bedrock and rock at each
5 /// point.
6 #pragma once
7
8 #include "terraingen/layers/exposure.h"
9 #include "terraingen/layers/material.h"
10 #include "terraingen/pipeline/terrain.h"
11 #include "terraingen/raster/grid.h"
12 #include "terraingen/raster/raster.h"
13
14 #include <cstdint>
15 #include <optional>
16 #include <vector>
17
18 namespace terraingen {
19
20 /// How a terrain's material map is made from its shape and layers.
21 4 struct MaterialOptions {
22 /// Bedrock where the bare ground, beneath the first layer that lays a material, is bare
23 /// (`ExposureField`); none for no bedrock.
24 std::optional<ExposureParams> exposure{ExposureParams{}};
25 double dustCover = 0.0; ///< About the share of the surface under dust patches, in [0, 1).
26 double dustPatch = 50.0; ///< Typical width of a dust patch (m).
27 std::uint32_t seed = 0; ///< Varies the dust patches.
28 };
29
30 /// Checks material options.
31 /// @throws std::invalid_argument for a dust cover outside [0, 1), a dust patch that is not
32 /// positive and finite, or invalid exposure thresholds.
33 void ValidateMaterialOptions(const MaterialOptions& options);
34
35 /// The material shares of `terrain` at world (x, y): soil, then bedrock where the ground beneath
36 /// the first `MaterialSource` layer is bare, then dust in patches, then each `MaterialSource`
37 /// layer's cover in layer order, each read on the ground beneath it.
38 /// @param spacing Sample spacing in meters; positive.
39 /// @throws std::invalid_argument as `ValidateMaterialOptions`.
40 MaterialShares MaterialsAt(const Terrain& terrain, const MaterialOptions& options, double x,
41 double y, double spacing);
42
43 /// One raster per `MaterialClass` over `grid`, each cell `MaterialsAt` its center at the grid's
44 /// spacing (or `evaluation.spacing` where coarser), on `evaluation.threads` threads to the same
45 /// bits as one. Material layers read the ground beneath them on `evaluation.backend`, and
46 /// `evaluation.onLayer` is called after each with its index and time; the stage cache is unused.
47 /// @throws std::invalid_argument as `MaterialsAt`, or for a negative or non-finite spacing.
48 /// @throws std::runtime_error when a GPU backend is requested but unavailable
49 /// (`ResolveBackend`).
50 std::vector<Raster<float>> EvaluateMaterials(const Terrain& terrain, const MaterialOptions& options,
51 const RasterGrid& grid,
52 const EvaluationOptions& evaluation = {});
53
54 } // namespace terraingen
55