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
14namespace gdal
15{
16namespace viewshed
17{
18
20using DatasetPtr = std::unique_ptr<GDALDataset>;
21
25enum class OutputMode
26{
27 Normal,
28 DEM,
29 Ground,
30 Cumulative
31};
32
36enum class CellMode
37{
38 Diagonal,
39 Edge,
40 Max,
41 Min
42};
43
47struct Point
48{
49 double x;
50 double y;
51 double z;
52};
53
57struct Options
58{
59 Point observer{0, 0, 0};
60 double visibleVal{255};
61 double invisibleVal{0};
63 0};
64 double nodataVal{-1};
65 double targetHeight{0.0};
67 0.0};
68 double curveCoeff{.85714};
69 OutputMode outputMode{OutputMode::Normal};
71 std::string outputFormat{};
72 std::string outputFilename{};
74 CellMode cellMode{CellMode::Edge};
76 uint8_t numJobs{3};
77};
78
82struct 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
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:436
C++ GDAL entry points.
Options for viewshed generation.
Definition: viewshed_types.h:58
Point observer
x, y, and z of the observer
Definition: viewshed_types.h:59
double targetHeight
target height above the DEM surface
Definition: viewshed_types.h:65
double outOfRangeVal
raster output value for pixels outside of max distance.
Definition: viewshed_types.h:62
CPLStringList creationOpts
options for output raster creation
Definition: viewshed_types.h:73
double curveCoeff
coefficient for atmospheric refraction
Definition: viewshed_types.h:68
double invisibleVal
raster output value for non-visible pixels.
Definition: viewshed_types.h:61
double nodataVal
raster output value for pixels with no data
Definition: viewshed_types.h:64
uint8_t numJobs
Relative number of jobs in cumulative mode.
Definition: viewshed_types.h:76
std::string outputFormat
output raster format
Definition: viewshed_types.h:71
OutputMode outputMode
Output information.
Definition: viewshed_types.h:69
std::string outputFilename
output raster filename
Definition: viewshed_types.h:72
double maxDistance
maximum distance from observer to compute value
Definition: viewshed_types.h:66
double visibleVal
raster output value for visible pixels.
Definition: viewshed_types.h:60
CellMode cellMode
Mode of cell height calculation.
Definition: viewshed_types.h:74
int observerSpacing
Observer spacing in cumulative mode.
Definition: viewshed_types.h:75
A point.
Definition: viewshed_types.h:48
double y
Y value.
Definition: viewshed_types.h:50
double x
X value.
Definition: viewshed_types.h:49
double z
Z value.
Definition: viewshed_types.h:51
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition: viewshed_types.h:83
void shiftX(int nShift)
Shift the X dimension by nShift.
Definition: viewshed_types.h:150
int xStart
X start position.
Definition: viewshed_types.h:84
int clampX(int nX) const
Clamp the argument to be in the window in the X dimension.
Definition: viewshed_types.h:135
bool containsX(int nX) const
Determine if the X window contains the index.
Definition: viewshed_types.h:110
int yStop
Y end position.
Definition: viewshed_types.h:87
int xStop
X end position.
Definition: viewshed_types.h:85
int yStart
Y start position.
Definition: viewshed_types.h:86
int clampY(int nY) const
Clamp the argument to be in the window in the Y dimension.
Definition: viewshed_types.h:143
size_t size() const
Number of cells.
Definition: viewshed_types.h:102
int ySize() const
Window size in the Y direction.
Definition: viewshed_types.h:96
bool containsY(int nY) const
Determine if the Y window contains the index.
Definition: viewshed_types.h:118
bool contains(int nX, int nY) const
Determine if the window contains the index.
Definition: viewshed_types.h:127
int xSize() const
Window size in the X direction.
Definition: viewshed_types.h:90