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 <limits>
11#include <string>
12
13#include "gdal_priv.h"
14
15namespace gdal
16{
17namespace viewshed
18{
19
21using DatasetPtr = std::unique_ptr<GDALDataset>;
22
26enum class OutputMode
27{
28 Normal,
29 DEM,
30 Ground,
32};
33
37enum class CellMode
38{
39 Diagonal,
40 Edge,
41 Max,
42 Min
43};
44
48struct Point
49{
50 double x;
51 double y;
52 double z;
53};
54
58struct Options
59{
60 Point observer{0, 0, 0};
61 double visibleVal{255};
62 double invisibleVal{0};
64 0};
65 double nodataVal{-1};
66 double targetHeight{0.0};
68 0.0};
70 0.0};
71 double startAngle{0.0};
72 double endAngle{0.0};
73 double lowPitch{
74 -90.0};
75 double highPitch{
76 90.0};
77 double curveCoeff{.85714};
78 OutputMode outputMode{OutputMode::Normal};
80 std::string outputFormat{};
81 std::string outputFilename{};
83 CellMode cellMode{CellMode::Edge};
85 uint8_t numJobs{3};
86
88 bool angleMasking() const
89 {
90 return startAngle != endAngle;
91 }
92
94 bool lowPitchMasking() const
95 {
96 return lowPitch > -90.0;
97 }
98
100 bool highPitchMasking() const
101 {
102 return highPitch < 90.0;
103 }
104
106 bool pitchMasking() const
107 {
108 return lowPitchMasking() || highPitchMasking();
109 }
110};
111
115struct Window
116{
117 int xStart{};
118 int xStop{};
119 int yStart{};
120 int yStop{};
121
123 bool operator==(const Window &w2) const
124 {
125 return xStart == w2.xStart && xStop == w2.xStop &&
126 yStart == w2.yStart && yStop == w2.yStop;
127 }
128
130 int xSize() const
131 {
132 return xStop - xStart;
133 }
134
136 int ySize() const
137 {
138 return yStop - yStart;
139 }
140
142 size_t size() const
143 {
144 return static_cast<size_t>(xSize()) * ySize();
145 }
146
150 bool containsX(int nX) const
151 {
152 return nX >= xStart && nX < xStop;
153 }
154
158 bool containsY(int nY) const
159 {
160 return nY >= xStart && nY < yStop;
161 }
162
167 bool contains(int nX, int nY) const
168 {
169 return containsX(nX) && containsY(nY);
170 }
171
175 int clampX(int nX) const
176 {
177 return xSize() ? std::clamp(nX, xStart, xStop - 1) : xStart;
178 }
179
183 int clampY(int nY) const
184 {
185 return ySize() ? std::clamp(nY, yStart, yStop - 1) : yStart;
186 }
187
190 void shiftX(int nShift)
191 {
192 xStart += nShift;
193 xStop += nShift;
194 }
195};
196
197inline std::ostream &operator<<(std::ostream &out, const Window &w)
198{
199 out << "Xstart/stop Ystart/stop = " << w.xStart << "/" << w.xStop << " "
200 << w.yStart << "/" << w.yStop;
201 return out;
202}
203
208{
210 LineLimits(int leftArg, int leftMinArg, int rightMinArg, int rightArg)
211 : left(leftArg), leftMin(leftMinArg), rightMin(rightMinArg),
212 right(rightArg)
213 {
214 }
215
216 int left;
219 int right;
220};
221
222inline std::ostream &operator<<(std::ostream &out, const LineLimits &ll)
223{
224 out << "Left/LeftMin RightMin/Right = " << ll.left << "/" << ll.leftMin
225 << " " << ll.rightMin << "/" << ll.right;
226 return out;
227}
228
229constexpr int INVALID_ISECT = std::numeric_limits<int>::max();
230
231} // namespace viewshed
232} // namespace gdal
233
234#endif
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:454
Generates a cumulative viewshed from a matrix of observers.
Definition cumulative.h:26
This file is legacy since GDAL 3.12, but will be kept at least in the whole GDAL 3....
Processing limits based on min/max distance restrictions.
Definition viewshed_types.h:208
int rightMin
Starting (leftmost) cell on the right side.
Definition viewshed_types.h:218
int leftMin
One past the rightmost cell on the left side.
Definition viewshed_types.h:217
int right
One past the rightmost cell on the right side.
Definition viewshed_types.h:219
int left
Starting (leftmost) cell on the left side.
Definition viewshed_types.h:216
LineLimits(int leftArg, int leftMinArg, int rightMinArg, int rightArg)
Constructor that takes the members in order.
Definition viewshed_types.h:210
Options for viewshed generation.
Definition viewshed_types.h:59
Point observer
x, y, and z of the observer
Definition viewshed_types.h:60
bool highPitchMasking() const
True if high pitch masking will occur.
Definition viewshed_types.h:100
double startAngle
start angle of observable range
Definition viewshed_types.h:71
double targetHeight
target height above the DEM surface
Definition viewshed_types.h:66
double outOfRangeVal
raster output value for pixels outside of max distance.
Definition viewshed_types.h:63
double highPitch
maximum pitch (vertical angle) of observable points
Definition viewshed_types.h:75
CPLStringList creationOpts
options for output raster creation
Definition viewshed_types.h:82
double curveCoeff
coefficient for atmospheric refraction
Definition viewshed_types.h:77
double invisibleVal
raster output value for non-visible pixels.
Definition viewshed_types.h:62
double endAngle
end angle of observable range
Definition viewshed_types.h:72
double lowPitch
minimum pitch (vertical angle) of observable points
Definition viewshed_types.h:73
bool lowPitchMasking() const
True if low pitch masking will occur.
Definition viewshed_types.h:94
double nodataVal
raster output value for pixels with no data
Definition viewshed_types.h:65
uint8_t numJobs
Relative number of jobs in cumulative mode.
Definition viewshed_types.h:85
std::string outputFormat
output raster format
Definition viewshed_types.h:80
OutputMode outputMode
Normal, Height from DEM or Height from ground.
Definition viewshed_types.h:78
std::string outputFilename
output raster filename
Definition viewshed_types.h:81
bool angleMasking() const
True if angle masking will occur.
Definition viewshed_types.h:88
double maxDistance
maximum distance from observer to compute value
Definition viewshed_types.h:67
double visibleVal
raster output value for visible pixels.
Definition viewshed_types.h:61
CellMode cellMode
Mode of cell height calculation.
Definition viewshed_types.h:83
int observerSpacing
Observer spacing in cumulative mode.
Definition viewshed_types.h:84
bool pitchMasking() const
True if pitch masking will occur.
Definition viewshed_types.h:106
double minDistance
minimum distance from observer to compute value.
Definition viewshed_types.h:69
A point.
Definition viewshed_types.h:49
double y
Y value.
Definition viewshed_types.h:51
double x
X value.
Definition viewshed_types.h:50
double z
Z value.
Definition viewshed_types.h:52
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition viewshed_types.h:116
void shiftX(int nShift)
Shift the X dimension by nShift.
Definition viewshed_types.h:190
int xStart
X start position.
Definition viewshed_types.h:117
int clampX(int nX) const
Clamp the argument to be in the window in the X dimension.
Definition viewshed_types.h:175
bool containsX(int nX) const
Determine if the X window contains the index.
Definition viewshed_types.h:150
int yStop
Y end position.
Definition viewshed_types.h:120
int xStop
X end position.
Definition viewshed_types.h:118
int yStart
Y start position.
Definition viewshed_types.h:119
int clampY(int nY) const
Clamp the argument to be in the window in the Y dimension.
Definition viewshed_types.h:183
bool operator==(const Window &w2) const
Returns true when one window is equal to the other.
Definition viewshed_types.h:123
size_t size() const
Number of cells.
Definition viewshed_types.h:142
int ySize() const
Window size in the Y direction.
Definition viewshed_types.h:136
bool containsY(int nY) const
Determine if the Y window contains the index.
Definition viewshed_types.h:158
bool contains(int nX, int nY) const
Determine if the window contains the index.
Definition viewshed_types.h:167
int xSize() const
Window size in the X direction.
Definition viewshed_types.h:130