./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
4 / 5
80.0%
Branches:
3 / 10
30.0%
Functions:
-
-%

include/terraingen/pipeline/report.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Terrain reports: statistics of evaluated grids, layer timings and run details.
5 #pragma once
6
7 #include "terraingen/distribution/size_frequency.h"
8 #include "terraingen/geometry/surface.h"
9 #include "terraingen/layers/boulders/boulder_placer.h"
10 #include "terraingen/layers/craters/crater_placer.h"
11 #include "terraingen/raster/grid.h"
12 #include "terraingen/raster/raster.h"
13 #include "terraingen/util/version.h"
14
15 #include <cstddef>
16 #include <cstdint>
17 #include <limits>
18 #include <string>
19 #include <vector>
20
21 namespace terraingen {
22
23 /// The craters listed in one diameter bin [`minDiameter`, `maxDiameter`) and the count a target
24 /// size-frequency distribution expects there.
25 ✗ struct CraterBin {
26 double minDiameter = 0.0; ///< Smallest diameter in meters, a power of 2.
27 double maxDiameter = 0.0; ///< Largest diameter in meters, twice `minDiameter`.
28 std::size_t count = 0; ///< Craters listed in the bin.
29 /// Craters the target expects over the grid's area in the bin; NaN without a target, for a
30 /// production-rate target or for a bin outside the target's valid range.
31 double expected = std::numeric_limits<double>::quiet_NaN();
32 };
33
34 /// Statistics of one evaluated grid; heights and slopes are over cells with data, NaN without
35 /// any.
36
2/6
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 12 not taken.
45 struct GridReport {
37 RasterGrid grid{}; ///< The grid: its size, pixel size and extent.
38 double heightMin = std::numeric_limits<double>::quiet_NaN(); ///< Lowest height in meters.
39 double heightMax = std::numeric_limits<double>::quiet_NaN(); ///< Highest height in meters.
40 double heightMean = std::numeric_limits<double>::quiet_NaN(); ///< Mean height in meters.
41 /// Population standard deviation of the heights in meters.
42 double heightStd = std::numeric_limits<double>::quiet_NaN();
43 /// Mean slope in degrees, from central differences in the surface's local metric.
44 double slopeMeanDeg = std::numeric_limits<double>::quiet_NaN();
45 double slopeMedianDeg = std::numeric_limits<double>::quiet_NaN(); ///< Median slope, degrees.
46 /// 95th percentile slope in degrees, interpolated between the nearest ranks.
47 double slopeP95Deg = std::numeric_limits<double>::quiet_NaN();
48 /// The listed craters per power-of-2 diameter bin, smallest first, from the bin of the
49 /// smallest crater to that of the largest; empty without craters.
50 std::vector<CraterBin> craterBins{};
51 std::size_t boulderCount = 0; ///< Boulders listed.
52 std::size_t boulderModelCount = 0; ///< Boulders placed as their own 3D models.
53 /// Summed boulder footprints, pi d^2 / 4 each, over the grid's area on its surface; boulders
54 /// that overlap or reach past the grid are counted whole.
55 double boulderCover = 0.0;
56 };
57
58 /// The time one layer took over every grid.
59
1/4
<unknown function 25>:
✗ Branch 3 not taken.
✗ Branch 9 not taken.
<unknown function 36>:
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
78 struct LayerTiming {
60 std::string type; ///< The layer's type, such as "craters".
61 double seconds = 0.0; ///< Wall-clock seconds.
62 };
63
64 /// A generated terrain's report: its grids' statistics, layer timings and how it was run.
65 struct TerrainReport {
66 std::vector<GridReport> grids{}; ///< One per evaluated grid.
67 std::vector<LayerTiming> layers{}; ///< One per layer, in order.
68 std::string backend{}; ///< Where the heights were evaluated, such as "cpu".
69 unsigned threads = 0; ///< Threads requested; 0 for every hardware thread.
70 std::vector<std::uint32_t> seeds{}; ///< The seeds the terrain was generated with.
71 double seconds = 0.0; ///< Wall-clock seconds the generation took.
72 std::string version = TERRAINGEN_FULL_VERSION_STRING; ///< The library version.
73 };
74
75 /// Statistics of `heights`, evaluated over a grid on `surface`, and of the features over it.
76 ///
77 /// Slopes come from central differences (one-sided at edges and beside no-data cells) of the
78 /// heights against the east and north offsets in meters between cell centers on `surface`;
79 /// cells without data, or without a neighbor with data along a grid axis, are skipped.
80 /// @param craters The craters listed over the grid, or null.
81 /// @param boulders The boulders listed over the grid, or null.
82 /// @param craterTarget The crater density the bins' expected counts come from, or null.
83 /// @param threads Threads for the slopes; 0 for every hardware thread. The result does not
84 /// depend on it.
85 GridReport ReportGrid(const Raster<float>& heights, const Surface& surface,
86 const CraterFeatures* craters, const BoulderFeatures* boulders,
87 const SizeFrequencyDistribution* craterTarget, unsigned threads = 0);
88
89 } // namespace terraingen
90