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

include/terraingen/layers/roughness_estimate.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Self-affine roughness of a base's heights by the variogram method, for layers that
5 /// continue it below the base's resolution.
6 #pragma once
7
8 #include "terraingen/analysis/variogram.h"
9 #include "terraingen/geometry/geometry.h"
10 #include "terraingen/geometry/surface.h"
11 #include "terraingen/noise/fractals.h"
12 #include "terraingen/raster/raster.h"
13 #include "terraingen/sources/source.h"
14
15 namespace terraingen {
16
17 /// Self-affine roughness: the RMS height difference at a lag L is nu(L) = `deviation` (L /
18 /// `cellSize`)^H, so the RMS slope over a baseline b is nu(b) / b = s(c) (b / c)^(H - 1)
19 /// (Shepard et al. 2001; Rosenburg et al. 2011, eq. 4, https://doi.org/10.1029/2010JE003716).
20 1 struct BaseRoughness {
21 double hurst = 1.0; ///< Hurst exponent H, in (0, 1].
22 double deviation = 0.0; ///< RMS height difference at a lag of `cellSize`, in meters.
23 double cellSize = 1.0; ///< Lag `deviation` is given at, in meters.
24
25 /// The RMS height difference in meters at a lag of `lag` meters.
26 double Deviation(double lag) const;
27
28 /// The RMS slope (rise over run) over a baseline of `baseline` meters.
29 double RmsSlope(double baseline) const;
30 };
31
32 /// The heights of `source` on a lattice of `cellSize` cells with a node at `origin`, at a sample
33 /// spacing of `cellSize`, centered on the source's grid, as many cells a side as its grid spans,
34 /// from 3 up to 512; 512 a side centered on its reference point for a source without bounds.
35 /// @param cellSize Cell side in the source's units, positive.
36 Raster<float> SampleSourceWindow(const Source& source, double cellSize, const Vec2d& origin);
37
38 /// The roughness of `source` at its native resolution, fitted by `FitDeviogram` over
39 /// `SampleSourceWindow`; H is clamped to at most 1 and no-data cells are skipped.
40 /// @throws std::invalid_argument for too little relief, a non-positive fitted H, or a source
41 /// without bounds or a finite resolution.
42 BaseRoughness EstimateSourceRoughness(const Source& source, const Surface& surface = {});
43
44 /// The amplitude in meters that gives `fractal` the RMS height difference `roughness` has at a lag
45 /// of the fractal's wavelength: `roughness.Deviation(wavelength)` over the fractal's RMS height
46 /// difference at that lag with unit amplitude, measured on a fixed lattice of 64 x 64 points
47 /// 0.618 wavelengths apart in the plane.
48 /// @throws std::invalid_argument for a fractal that shows no relief at unit amplitude.
49 float MatchedNoiseAmplitude(const Fractal& fractal, const BaseRoughness& roughness);
50
51 } // namespace terraingen
52