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,
31 Cumulative
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 2};
66 0};
67 double nodataVal{-1};
68 double targetHeight{0.0};
70 0.0};
72 0.0};
73 double startAngle{0.0};
74 double endAngle{0.0};
75 double lowPitch{
76 -90.0};
77 double highPitch{
78 90.0};
79 double curveCoeff{.85714};
80 OutputMode outputMode{OutputMode::Normal};
82 std::string outputFormat{};
83 std::string outputFilename{};
85 CellMode cellMode{CellMode::Edge};
87 uint8_t numJobs{3};
88
90 bool angleMasking() const
91 {
92 return startAngle != endAngle;
93 }
94
96 bool lowPitchMasking() const
97 {
98 return lowPitch > -90.0;
99 }
100
102 bool highPitchMasking() const
103 {
104 return highPitch < 90.0;
105 }
106
108 bool pitchMasking() const
109 {
110 return lowPitchMasking() || highPitchMasking();
111 }
112};
113
117struct Window
118{
119 int xStart{};
120 int xStop{};
121 int yStart{};
122 int yStop{};
123
125 bool operator==(const Window &w2) const
126 {
127 return xStart == w2.xStart && xStop == w2.xStop &&
128 yStart == w2.yStart && yStop == w2.yStop;
129 }
130
132 int xSize() const
133 {
134 return xStop - xStart;
135 }
136
138 int ySize() const
139 {
140 return yStop - yStart;
141 }
142
144 size_t size() const
145 {
146 return static_cast<size_t>(xSize()) * ySize();
147 }
148
152 bool containsX(int nX) const
153 {
154 return nX >= xStart && nX < xStop;
155 }
156
160 bool containsY(int nY) const
161 {
162 return nY >= xStart && nY < yStop;
163 }
164
169 bool contains(int nX, int nY) const
170 {
171 return containsX(nX) && containsY(nY);
172 }
173
177 int clampX(int nX) const
178 {
179 return xSize() ? std::clamp(nX, xStart, xStop - 1) : xStart;
180 }
181
185 int clampY(int nY) const
186 {
187 return ySize() ? std::clamp(nY, yStart, yStop - 1) : yStart;
188 }
189
192 void shiftX(int nShift)
193 {
194 xStart += nShift;
195 xStop += nShift;
196 }
197};
198
199inline std::ostream &operator<<(std::ostream &out, const Window &w)
200{
201 out << "Xstart/stop Ystart/stop = " << w.xStart << "/" << w.xStop << " "
202 << w.yStart << "/" << w.yStop;
203 return out;
204}
205
210{
212 LineLimits(int leftArg, int leftMinArg, int rightMinArg, int rightArg)
213 : left(leftArg), leftMin(leftMinArg), rightMin(rightMinArg),
214 right(rightArg)
215 {
216 }
217
218 int left;
221 int right;
222};
223
224inline std::ostream &operator<<(std::ostream &out, const LineLimits &ll)
225{
226 out << "Left/LeftMin RightMin/Right = " << ll.left << "/" << ll.leftMin
227 << " " << ll.rightMin << "/" << ll.right;
228 return out;
229}
230
231constexpr int INVALID_ISECT = std::numeric_limits<int>::max();
232
233} // namespace viewshed
234} // namespace gdal
235
236#endif
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:476
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:210
int rightMin
Starting (leftmost) cell on the right side.
Definition viewshed_types.h:220
int leftMin
One past the rightmost cell on the left side.
Definition viewshed_types.h:219
int right
One past the rightmost cell on the right side.
Definition viewshed_types.h:221
int left
Starting (leftmost) cell on the left side.
Definition viewshed_types.h:218
LineLimits(int leftArg, int leftMinArg, int rightMinArg, int rightArg)
Constructor that takes the members in order.
Definition viewshed_types.h:212
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:102
double startAngle
start angle of observable range
Definition viewshed_types.h:73
double targetHeight
target height above the DEM surface
Definition viewshed_types.h:68
double outOfRangeVal
raster output value for pixels outside of max distance.
Definition viewshed_types.h:65
double highPitch
maximum pitch (vertical angle) of observable points
Definition viewshed_types.h:77
CPLStringList creationOpts
options for output raster creation
Definition viewshed_types.h:84
double curveCoeff
coefficient for atmospheric refraction
Definition viewshed_types.h:79
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:74
double lowPitch
minimum pitch (vertical angle) of observable points
Definition viewshed_types.h:75
bool lowPitchMasking() const
True if low pitch masking will occur.
Definition viewshed_types.h:96
double nodataVal
raster output value for pixels with no data
Definition viewshed_types.h:67
uint8_t numJobs
Relative number of jobs in cumulative mode.
Definition viewshed_types.h:87
std::string outputFormat
output raster format
Definition viewshed_types.h:82
OutputMode outputMode
Output information.
Definition viewshed_types.h:80
std::string outputFilename
output raster filename
Definition viewshed_types.h:83
bool angleMasking() const
True if angle masking will occur.
Definition viewshed_types.h:90
double maybeVisibleVal
raster output for potentially visible pixels.
Definition viewshed_types.h:63
double maxDistance
maximum distance from observer to compute value
Definition viewshed_types.h:69
double visibleVal
raster output value for visible pixels.
Definition viewshed_types.h:61
CellMode cellMode
Mode of cell height calculation.
Definition viewshed_types.h:85
int observerSpacing
Observer spacing in cumulative mode.
Definition viewshed_types.h:86
bool pitchMasking() const
True if pitch masking will occur.
Definition viewshed_types.h:108
double minDistance
minimum distance from observer to compute value.
Definition viewshed_types.h:71
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:118
void shiftX(int nShift)
Shift the X dimension by nShift.
Definition viewshed_types.h:192
int xStart
X start position.
Definition viewshed_types.h:119
int clampX(int nX) const
Clamp the argument to be in the window in the X dimension.
Definition viewshed_types.h:177
bool containsX(int nX) const
Determine if the X window contains the index.
Definition viewshed_types.h:152
int yStop
Y end position.
Definition viewshed_types.h:122
int xStop
X end position.
Definition viewshed_types.h:120
int yStart
Y start position.
Definition viewshed_types.h:121
int clampY(int nY) const
Clamp the argument to be in the window in the Y dimension.
Definition viewshed_types.h:185
bool operator==(const Window &w2) const
Returns true when one window is equal to the other.
Definition viewshed_types.h:125
size_t size() const
Number of cells.
Definition viewshed_types.h:144
int ySize() const
Window size in the Y direction.
Definition viewshed_types.h:138
bool containsY(int nY) const
Determine if the Y window contains the index.
Definition viewshed_types.h:160
bool contains(int nX, int nY) const
Determine if the window contains the index.
Definition viewshed_types.h:169
int xSize() const
Window size in the X direction.
Definition viewshed_types.h:132