include/terraingen/layers/noise_layer.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief `NoiseLayer`, a stack of fractals added to the terrain. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/layers/field.h" | ||
| 8 | #include "terraingen/layers/kernels/noise_layer.h" | ||
| 9 | #include "terraingen/layers/layer.h" | ||
| 10 | #include "terraingen/noise/fractals.h" | ||
| 11 | |||
| 12 | #include <cstdint> | ||
| 13 | #include <memory> | ||
| 14 | #include <optional> | ||
| 15 | #include <utility> | ||
| 16 | #include <vector> | ||
| 17 | |||
| 18 | namespace terraingen { | ||
| 19 | |||
| 20 | /// The noise a `NoiseLayer` adds: its stack of fractals and what of it a source already holds. | ||
| 21 | 1064 | struct NoiseLayerOptions { | |
| 22 | std::vector<Fractal> fractals{}; ///< The stack, at least one fractal. | ||
| 23 | /// Source cells across from which its measured data already holds a fractal: with a source, | ||
| 24 | /// each fractal of the stack whose `wavelength`, its longest, is at least that many of the | ||
| 25 | /// source's cells at a point is left out there (`SourceResolvedLimit`); unset adds every | ||
| 26 | /// fractal everywhere. | ||
| 27 | std::optional<double> sourceResolvesPixels{}; | ||
| 28 | }; | ||
| 29 | |||
| 30 | /// A stack of fractals added to the terrain, rolling relief on a flat source or detail on a DEM, | ||
| 31 | /// measured from the context's `ReferencePoint`. Grids on a plane follow the context's backend; on | ||
| 32 | /// a body or over a resolving source it runs on the CPU. | ||
| 33 | class NoiseLayer final : public Layer { | ||
| 34 | public: | ||
| 35 | /// @throws std::invalid_argument for a stack without fractals or otherwise invalid, or for a | ||
| 36 | /// `sourceResolvesPixels` that is not positive and finite. | ||
| 37 | explicit NoiseLayer(NoiseLayerOptions options); | ||
| 38 | |||
| 39 | /// Noise of the stack `fractals`. | ||
| 40 | /// @throws std::invalid_argument as the options constructor. | ||
| 41 | 136 | explicit NoiseLayer(std::vector<Fractal> fractals) | |
| 42 | 269 | : NoiseLayer(NoiseLayerOptions{std::move(fractals), std::nullopt}) {} | |
| 43 | |||
| 44 | /// Noise of the one fractal `fractal`. | ||
| 45 | /// @throws std::invalid_argument as the options constructor. | ||
| 46 | 56 | explicit NoiseLayer(Fractal fractal) : NoiseLayer(std::vector<Fractal>{fractal}) {} | |
| 47 | |||
| 48 | /// The fractals and source limit the layer was made with. | ||
| 49 | 4 | const NoiseLayerOptions& Options() const { | |
| 50 | 4 | return m_options; | |
| 51 | } | ||
| 52 | |||
| 53 | /// The layer with the seed of fractal n `ReseedWord(seed, n)`. | ||
| 54 | LayerPtr Reseeded(std::uint64_t seed) const override; | ||
| 55 | |||
| 56 | protected: | ||
| 57 | void ApplySamples(SampleBlock& samples, const LayerContext& context) const override; | ||
| 58 | |||
| 59 | private: | ||
| 60 | NoiseLayerOptions m_options; | ||
| 61 | NoiseLayerKernel m_kernel; | ||
| 62 | std::vector<double> | ||
| 63 | m_wavelengths; ///< The fractals' distinct wavelengths in meters, ascending. | ||
| 64 | /// The stack with the fractals of `m_wavelengths[i]` and longer disabled, the whole stack last. | ||
| 65 | std::vector<std::vector<Fractal>> m_stacks; | ||
| 66 | }; | ||
| 67 | |||
| 68 | } // namespace terraingen | ||
| 69 |