include/terraingen/sources/sources_fields.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief The field lists of diamond-square options, chain seams and GeoTIFF band reads, and the | ||
| 5 | /// names of their enums. | ||
| 6 | #pragma once | ||
| 7 | |||
| 8 | #include "terraingen/geometry/geometry_fields.h" | ||
| 9 | #include "terraingen/sources/diamond_square.h" | ||
| 10 | #include "terraingen/sources/geotiff_source.h" | ||
| 11 | #include "terraingen/sources/source_chain.h" | ||
| 12 | #include "terraingen/util/option_fields.h" | ||
| 13 | |||
| 14 | #include <array> | ||
| 15 | |||
| 16 | namespace terraingen { | ||
| 17 | |||
| 18 | template <> struct EnumNames<DiamondSquareInterp> { | ||
| 19 | static constexpr std::array<EnumEntry<DiamondSquareInterp>, 2> kValues{{ | ||
| 20 | {"bilinear", DiamondSquareInterp::Bilinear, | ||
| 21 | "Square nodes the mean of their four corners, diamond nodes the mean of their four " | ||
| 22 | "neighbors, samples bilinear between nodes."}, | ||
| 23 | {"catmull_rom", DiamondSquareInterp::CatmullRom, | ||
| 24 | "Catmull-Rom splines over four nodes along each axis, as the VIPER terrain expansion " | ||
| 25 | "does: smoother, with fewer lattice creases."}, | ||
| 26 | }}; | ||
| 27 | }; | ||
| 28 | |||
| 29 | template <> struct EnumNames<ChainSeamMode> { | ||
| 30 | static constexpr std::array<EnumEntry<ChainSeamMode>, 4> kValues{{ | ||
| 31 | {"none", ChainSeamMode::None, | ||
| 32 | "Each cell takes the first source with data, unchanged: a step where a gap begins."}, | ||
| 33 | {"feather", ChainSeamMode::Feather, | ||
| 34 | "Adds the height difference at the nearest edge post to the later source, fading it to " | ||
| 35 | "0 across width_m of the gap: the cheapest, without a solve."}, | ||
| 36 | {"height", ChainSeamMode::Height, | ||
| 37 | "Shifts the later source by the edge's height difference spread smoothly into the gap, " | ||
| 38 | "fading out over decay_length_m beyond an open edge: heights meet (C0), keeping the " | ||
| 39 | "later source's relief."}, | ||
| 40 | {"slope", ChainSeamMode::Slope, | ||
| 41 | "As height, with a biharmonic spread that matches slopes at the edge as well (C1)."}, | ||
| 42 | }}; | ||
| 43 | }; | ||
| 44 | |||
| 45 | /// The fields of diamond-square upsampling, beside its "type". | ||
| 46 | 69 | template <typename IO> void Fields(IO& io, DiamondSquareOptions& options) { | |
| 47 | 69 | io("fractal_dimension", options.fractalDimension, | |
| 48 | "Fractal dimension, 2 smooth and 3 rough: each square or diamond step scales the " | ||
| 49 | "displacement by 2^-((3 - F) / 2). Unset estimates it from the median height differences of " | ||
| 50 | "the posts at lags of 1 to 8 posts.", | ||
| 51 | 69 | "", Between(2.0, 3.0)); | |
| 52 | 68 | io("scale_m", options.scale, | |
| 53 | "Displacement standard deviation in meters at the posts' last step; unset estimates it " | ||
| 54 | "per fit_window_px window.", | ||
| 55 | 68 | "m", AtLeast(0.0)); | |
| 56 | 67 | io("fit_window_px", options.fitWindow, | |
| 57 | "Side in posts of the overlapping windows, centered every half side, that an unset " | ||
| 58 | "scale_m is fitted over; each node's scale is bilinear between the windows around it. 0 " | ||
| 59 | "fits one scale to a sample of the posts; else at least 4.", | ||
| 60 | 67 | "px", Between(0.0, static_cast<double>(kMaxDiamondSquareFitWindow))); | |
| 61 | 76 | io("interp", options.interp, | |
| 62 | "How new nodes are filled from the coarser ones and samples read between the finest " | ||
| 63 | "nodes."); | ||
| 64 | 65 | io("min_pixel_size_m", options.minPixelSize, | |
| 65 | "Finest node spacing in meters the posts are refined to; 0 refines down to the sample " | ||
| 66 | "spacing.", | ||
| 67 | 65 | "m", AtLeast(0.0)); | |
| 68 | 64 | io("seed", options.seed, "Seed of the displacements."); | |
| 69 | 64 | } | |
| 70 | |||
| 71 | /// The fields of how a chain joins each source to the gaps of those before it. | ||
| 72 | 124 | template <typename IO> void Fields(IO& io, ChainSeams& seams) { | |
| 73 | 146 | io("mode", seams.mode, | |
| 74 | "How each source meets the gaps of those before it: none switches outright, feather " | ||
| 75 | "fades the edge's height difference out across the gap, height shifts the later source " | ||
| 76 | "to meet the earlier one's heights (C0) and slope to meet its heights and slopes (C1). " | ||
| 77 | "The match is solved on the posts of the source before each gap."); | ||
| 78 | 123 | io("width_m", seams.width, | |
| 79 | "Width in meters of the band inside a gap over which feather fades the height difference " | ||
| 80 | "at the edge to 0.", | ||
| 81 | 123 | "m", Above(0.0)); | |
| 82 | 122 | io("decay_length_m", seams.decayLength, | |
| 83 | "Length in meters over which height and slope fade the shift out where a gap is open, " | ||
| 84 | "beyond a source's edge; it is 0 from three decay lengths on. A hole much narrower than " | ||
| 85 | "it takes the whole shift.", | ||
| 86 | 122 | "m", Above(0.0)); | |
| 87 | 120 | } | |
| 88 | |||
| 89 | /// The fields of how a GeoTIFF band is read; the upsampler and cache are not configured here. | ||
| 90 | 281 | template <typename IO> void GeoTiffReadFields(IO& io, GeoTiffSourceOptions& read) { | |
| 91 | 281 | io("band", read.band, "Band of the file to read, counting from 0."); | |
| 92 | 281 | io("scale", read.scale, | |
| 93 | "Factor each sample is multiplied by, replacing the band's scale from the file's GDAL " | ||
| 94 | "metadata. Unset keeps the file's."); | ||
| 95 | 281 | io("offset_m", read.offset, | |
| 96 | "Added to each scaled sample, replacing the band's offset from the file's GDAL metadata. " | ||
| 97 | "Unset keeps the file's.", | ||
| 98 | "m"); | ||
| 99 | 281 | io("crop", read.crop, "Box in the raster's CRS units to use; unset uses the whole file."); | |
| 100 | 276 | io("effective_pixel_size_m", read.effectivePixelSize, | |
| 101 | "Cell size in meters the heights truly resolve, for a DEM that was upsampled or smoothed " | ||
| 102 | "before it was saved; it replaces the cell size as the scale below which the source " | ||
| 103 | "resolves no features. Unset uses the cell size.", | ||
| 104 | 276 | "m", Above(0.0)); | |
| 105 | 275 | } | |
| 106 | |||
| 107 | } // namespace terraingen | ||
| 108 |