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
15 namespace gdal
16{
17 namespace viewshed
18{
19
21 using DatasetPtr = std::unique_ptr<GDALDataset>;
22
26 enum class OutputMode
27{
28 Normal,
29 DEM,
30 Ground,
31 Cumulative
32};
33
37 enum class CellMode
38{
39 Diagonal,
40 Edge,
41 Max,
42 Min
43};
44
48 struct Point
49{
50 double x;
51 double y;
52 double z;
53};
54
58 struct Options
59{
60 Point observer{0, 0, 0};
61 double visibleVal{255};
62 double invisibleVal{0};
63 double outOfRangeVal{
64 0};
65 double nodataVal{-1};
66 double targetHeight{0.0};
67 double maxDistance{
68 0.0};
69 double minDistance{
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{};
82 CPLStringList creationOpts{};
83 CellMode cellMode{CellMode::Edge};
84 int observerSpacing{10};
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
115 struct 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
197 inline 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
207 struct LineLimits
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;
217 int leftMin;
218 int rightMin;
219 int right;
220};
221
222 inline 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
229 constexpr int INVALID_ISECT = std::numeric_limits<int>::max();
230
231} // namespace viewshed
232} // namespace gdal
233
234#endif
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:458
gdal_priv.h
This file is legacy since GDAL 3.12, but will be kept at least in the whole GDAL 3....
gdal::viewshed::LineLimits
Processing limits based on min/max distance restrictions.
Definition viewshed_types.h:208
gdal::viewshed::LineLimits::rightMin
int rightMin
Starting (leftmost) cell on the right side.
Definition viewshed_types.h:218
gdal::viewshed::LineLimits::leftMin
int leftMin
One past the rightmost cell on the left side.
Definition viewshed_types.h:217
gdal::viewshed::LineLimits::right
int right
One past the rightmost cell on the right side.
Definition viewshed_types.h:219
gdal::viewshed::LineLimits::left
int left
Starting (leftmost) cell on the left side.
Definition viewshed_types.h:216
gdal::viewshed::LineLimits::LineLimits
LineLimits(int leftArg, int leftMinArg, int rightMinArg, int rightArg)
Constructor that takes the members in order.
Definition viewshed_types.h:210
gdal::viewshed::Options
Options for viewshed generation.
Definition viewshed_types.h:59
gdal::viewshed::Options::observer
Point observer
x, y, and z of the observer
Definition viewshed_types.h:60
gdal::viewshed::Options::highPitchMasking
bool highPitchMasking() const
True if high pitch masking will occur.
Definition viewshed_types.h:100
gdal::viewshed::Options::startAngle
double startAngle
start angle of observable range
Definition viewshed_types.h:71
gdal::viewshed::Options::targetHeight
double targetHeight
target height above the DEM surface
Definition viewshed_types.h:66
gdal::viewshed::Options::outOfRangeVal
double outOfRangeVal
raster output value for pixels outside of max distance.
Definition viewshed_types.h:63
gdal::viewshed::Options::highPitch
double highPitch
maximum pitch (vertical angle) of observable points
Definition viewshed_types.h:75
gdal::viewshed::Options::creationOpts
CPLStringList creationOpts
options for output raster creation
Definition viewshed_types.h:82
gdal::viewshed::Options::curveCoeff
double curveCoeff
coefficient for atmospheric refraction
Definition viewshed_types.h:77
gdal::viewshed::Options::invisibleVal
double invisibleVal
raster output value for non-visible pixels.
Definition viewshed_types.h:62
gdal::viewshed::Options::endAngle
double endAngle
end angle of observable range
Definition viewshed_types.h:72
gdal::viewshed::Options::lowPitch
double lowPitch
minimum pitch (vertical angle) of observable points
Definition viewshed_types.h:73
gdal::viewshed::Options::lowPitchMasking
bool lowPitchMasking() const
True if low pitch masking will occur.
Definition viewshed_types.h:94
gdal::viewshed::Options::nodataVal
double nodataVal
raster output value for pixels with no data
Definition viewshed_types.h:65
gdal::viewshed::Options::numJobs
uint8_t numJobs
Relative number of jobs in cumulative mode.
Definition viewshed_types.h:85
gdal::viewshed::Options::outputFormat
std::string outputFormat
output raster format
Definition viewshed_types.h:80
gdal::viewshed::Options::outputMode
OutputMode outputMode
Output information.
Definition viewshed_types.h:78
gdal::viewshed::Options::outputFilename
std::string outputFilename
output raster filename
Definition viewshed_types.h:81
gdal::viewshed::Options::angleMasking
bool angleMasking() const
True if angle masking will occur.
Definition viewshed_types.h:88
gdal::viewshed::Options::maxDistance
double maxDistance
maximum distance from observer to compute value
Definition viewshed_types.h:67
gdal::viewshed::Options::visibleVal
double visibleVal
raster output value for visible pixels.
Definition viewshed_types.h:61
gdal::viewshed::Options::cellMode
CellMode cellMode
Mode of cell height calculation.
Definition viewshed_types.h:83
gdal::viewshed::Options::observerSpacing
int observerSpacing
Observer spacing in cumulative mode.
Definition viewshed_types.h:84
gdal::viewshed::Options::pitchMasking
bool pitchMasking() const
True if pitch masking will occur.
Definition viewshed_types.h:106
gdal::viewshed::Options::minDistance
double minDistance
minimum distance from observer to compute value.
Definition viewshed_types.h:69
gdal::viewshed::Point
A point.
Definition viewshed_types.h:49
gdal::viewshed::Point::y
double y
Y value.
Definition viewshed_types.h:51
gdal::viewshed::Point::x
double x
X value.
Definition viewshed_types.h:50
gdal::viewshed::Point::z
double z
Z value.
Definition viewshed_types.h:52
gdal::viewshed::Window
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition viewshed_types.h:116
gdal::viewshed::Window::shiftX
void shiftX(int nShift)
Shift the X dimension by nShift.
Definition viewshed_types.h:190
gdal::viewshed::Window::xStart
int xStart
X start position.
Definition viewshed_types.h:117
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:175
gdal::viewshed::Window::containsX
bool containsX(int nX) const
Determine if the X window contains the index.
Definition viewshed_types.h:150
gdal::viewshed::Window::yStop
int yStop
Y end position.
Definition viewshed_types.h:120
gdal::viewshed::Window::xStop
int xStop
X end position.
Definition viewshed_types.h:118
gdal::viewshed::Window::yStart
int yStart
Y start position.
Definition viewshed_types.h:119
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:183
gdal::viewshed::Window::operator==
bool operator==(const Window &w2) const
Returns true when one window is equal to the other.
Definition viewshed_types.h:123
gdal::viewshed::Window::size
size_t size() const
Number of cells.
Definition viewshed_types.h:142
gdal::viewshed::Window::ySize
int ySize() const
Window size in the Y direction.
Definition viewshed_types.h:136
gdal::viewshed::Window::containsY
bool containsY(int nY) const
Determine if the Y window contains the index.
Definition viewshed_types.h:158
gdal::viewshed::Window::contains
bool contains(int nX, int nY) const
Determine if the window contains the index.
Definition viewshed_types.h:167
gdal::viewshed::Window::xSize
int xSize() const
Window size in the X direction.
Definition viewshed_types.h:130