include/terraingen/sources/flat_source.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief A source of constant elevation, the start of a fully synthetic terrain. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/geometry/surface.h" | ||
| 8 | #include "terraingen/sources/source.h" | ||
| 9 | |||
| 10 | #include <cstddef> | ||
| 11 | |||
| 12 | namespace terraingen { | ||
| 13 | |||
| 14 | /// A level datum at `elevation` over a `width` x `height` north-up grid of square | ||
| 15 | /// `pixelSize` cells centered on `center`: the start of a fully synthetic terrain. | ||
| 16 | 202 | class FlatSource final : public Source { | |
| 17 | public: | ||
| 18 | /// The flat source over the given grid. | ||
| 19 | /// @param width Columns, at least 1. | ||
| 20 | /// @param height Rows, at least 1. | ||
| 21 | /// @param pixelSize Cell size in world units (meters), positive and finite. | ||
| 22 | /// @param elevation Height of every cell in meters, finite. | ||
| 23 | /// @param center Grid center in world units, finite; the origin by default. | ||
| 24 | /// @throws std::invalid_argument if `width` or `height` is zero, `pixelSize` is not positive | ||
| 25 | /// and finite, or `elevation` or `center` is not finite. | ||
| 26 | FlatSource(std::size_t width, std::size_t height, double pixelSize, float elevation = 0.0f, | ||
| 27 | Vec2d center = {}); | ||
| 28 | |||
| 29 | /// The flat source over a grid on `surface` whose cell size is given in meters, as for a site | ||
| 30 | /// on a body: the grid is in the surface's coordinates. | ||
| 31 | /// @param pixelSize Cell size in meters, positive and finite; on a body it is converted to | ||
| 32 | /// degrees along a meridian (`Surface::UnitLength`). | ||
| 33 | /// @param center Grid center in the surface's coordinates (longitude and latitude in degrees on | ||
| 34 | /// a body). | ||
| 35 | /// @throws std::invalid_argument as the constructor in world units. | ||
| 36 | 111 | FlatSource(std::size_t width, std::size_t height, double pixelSize, float elevation, | |
| 37 | Vec2d center, const Surface& surface) | ||
| 38 | 123 | : FlatSource(width, height, pixelSize / surface.UnitLength(), elevation, center) {} | |
| 39 | |||
| 40 | /// The grid given at construction. | ||
| 41 | 187 | RasterGrid Grid() const override { | |
| 42 | 187 | return m_grid; | |
| 43 | } | ||
| 44 | |||
| 45 | protected: | ||
| 46 | /// Sets every sample to the elevation. | ||
| 47 | void FillSamples(SampleBlock& samples, double spacing, unsigned threads) const override; | ||
| 48 | |||
| 49 | private: | ||
| 50 | RasterGrid m_grid; | ||
| 51 | float m_elevation; | ||
| 52 | }; | ||
| 53 | |||
| 54 | } // namespace terraingen | ||
| 55 |