GDAL

viewshed_types.h
1/****************************************************************************
2 * (c) 2024 info@hobu.co
3 *
4 * SPDX-License-Identifier: MIT
5 ****************************************************************************/
6#ifndef VIEWSHED_TYPES_H_INCLUDED
7#define VIEWSHED_TYPES_H_INCLUDED
8
9#include <algorithm>
10#include <string>
11
12#include "gdal_priv.h"
13
14 namespace gdal
15{
16 namespace viewshed
17{
18
20 using DatasetPtr = std::unique_ptr<GDALDataset>;
21
25 enum class OutputMode
26{
27 Normal,
28 DEM,
29 Ground,
30 Cumulative
31};
32
36 enum class CellMode
37{
38 Diagonal,
39 Edge,
40 Max,
41 Min
42};
43
47 struct Point
48{
49 double x;
50 double y;
51 double z;
52};
53
57 struct Options
58{
59 Point observer{0, 0, 0};
60 double visibleVal{255};
61 double invisibleVal{0};
62 double outOfRangeVal{
63 0};
64 double nodataVal{-1};
65 double targetHeight{0.0};
66 double maxDistance{
67 0.0};
68 double curveCoeff{.85714};
69 OutputMode outputMode{OutputMode::Normal};
71 std::string outputFormat{};
72 std::string outputFilename{};
73 CPLStringList creationOpts{};
74 CellMode cellMode{CellMode::Edge};
75 int observerSpacing{10};
76 uint8_t numJobs{3};
77};
78
82 struct Window
83{
84 int xStart{};
85 int xStop{};
86 int yStart{};
87 int yStop{};
88
90 int xSize() const
91 {
92 return xStop - xStart;
93 }
94
96 int ySize() const
97 {
98 return yStop - yStart;
99 }
100
102 size_t size() const
103 {
104 return static_cast<size_t>(xSize()) * ySize();
105 }
106
110 bool containsX(int nX) const
111 {
112 return nX >= xStart && nX < xStop;
113 }
114
118 bool containsY(int nY) const
119 {
120 return nY >= xStart && nY < yStop;
121 }
122
127 bool contains(int nX, int nY) const
128 {
129 return containsX(nX) && containsY(nY);
130 }
131
135 int clampX(int nX) const
136 {
137 return xSize() ? std::clamp(nX, xStart, xStop - 1) : xStart;
138 }
139
143 int clampY(int nY) const
144 {
145 return ySize() ? std::clamp(nY, yStart, yStop - 1) : yStart;
146 }
147
150 void shiftX(int nShift)
151 {
152 xStart += nShift;
153 xStop += nShift;
154 }
155};
156
157} // namespace viewshed
158} // namespace gdal
159
160#endif
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:436
gdal_priv.h
C++ GDAL entry points.
gdal::viewshed::Options
Options for viewshed generation.
Definition viewshed_types.h:58
gdal::viewshed::Options::observer
Point observer
x, y, and z of the observer
Definition viewshed_types.h:59
gdal::viewshed::Options::targetHeight
double targetHeight
target height above the DEM surface
Definition viewshed_types.h:65
gdal::viewshed::Options::outOfRangeVal
double outOfRangeVal
raster output value for pixels outside of max distance.
Definition viewshed_types.h:62
gdal::viewshed::Options::creationOpts
CPLStringList creationOpts
options for output raster creation
Definition viewshed_types.h:73
gdal::viewshed::Options::curveCoeff
double curveCoeff
coefficient for atmospheric refraction
Definition viewshed_types.h:68
gdal::viewshed::Options::invisibleVal
double invisibleVal
raster output value for non-visible pixels.
Definition viewshed_types.h:61
gdal::viewshed::Options::nodataVal
double nodataVal
raster output value for pixels with no data
Definition viewshed_types.h:64
gdal::viewshed::Options::numJobs
uint8_t numJobs
Relative number of jobs in cumulative mode.
Definition viewshed_types.h:76
gdal::viewshed::Options::outputFormat
std::string outputFormat
output raster format
Definition viewshed_types.h:71
gdal::viewshed::Options::outputMode
OutputMode outputMode
Output information.
Definition viewshed_types.h:69
gdal::viewshed::Options::outputFilename
std::string outputFilename
output raster filename
Definition viewshed_types.h:72
gdal::viewshed::Options::maxDistance
double maxDistance
maximum distance from observer to compute value
Definition viewshed_types.h:66
gdal::viewshed::Options::visibleVal
double visibleVal
raster output value for visible pixels.
Definition viewshed_types.h:60
gdal::viewshed::Options::cellMode
CellMode cellMode
Mode of cell height calculation.
Definition viewshed_types.h:74
gdal::viewshed::Options::observerSpacing
int observerSpacing
Observer spacing in cumulative mode.
Definition viewshed_types.h:75
gdal::viewshed::Point
A point.
Definition viewshed_types.h:48
gdal::viewshed::Point::y
double y
Y value.
Definition viewshed_types.h:50
gdal::viewshed::Point::x
double x
X value.
Definition viewshed_types.h:49
gdal::viewshed::Point::z
double z
Z value.
Definition viewshed_types.h:51
gdal::viewshed::Window
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition viewshed_types.h:83
gdal::viewshed::Window::shiftX
void shiftX(int nShift)
Shift the X dimension by nShift.
Definition viewshed_types.h:150
gdal::viewshed::Window::xStart
int xStart
X start position.
Definition viewshed_types.h:84
gdal::viewshed::Window::clampX
int clampX(int nX) const
Clamp the argument to be in the window in the X dimension.
Definition viewshed_types.h:135
gdal::viewshed::Window::containsX
bool containsX(int nX) const
Determine if the X window contains the index.
Definition viewshed_types.h:110
gdal::viewshed::Window::yStop
int yStop
Y end position.
Definition viewshed_types.h:87
gdal::viewshed::Window::xStop
int xStop
X end position.
Definition viewshed_types.h:85
gdal::viewshed::Window::yStart
int yStart
Y start position.
Definition viewshed_types.h:86
gdal::viewshed::Window::clampY
int clampY(int nY) const
Clamp the argument to be in the window in the Y dimension.
Definition viewshed_types.h:143
gdal::viewshed::Window::size
size_t size() const
Number of cells.
Definition viewshed_types.h:102
gdal::viewshed::Window::ySize
int ySize() const
Window size in the Y direction.
Definition viewshed_types.h:96
gdal::viewshed::Window::containsY
bool containsY(int nY) const
Determine if the Y window contains the index.
Definition viewshed_types.h:118
gdal::viewshed::Window::contains
bool contains(int nX, int nY) const
Determine if the window contains the index.
Definition viewshed_types.h:127
gdal::viewshed::Window::xSize
int xSize() const
Window size in the X direction.
Definition viewshed_types.h:90