37 #include "cpl_progress.h"
183 : oOpts{opts}, oOutExtent{}, oCurExtent{},
184 dfMaxDistance2{opts.maxDistance * opts.maxDistance},
185 dfZObserver{0}, poDstDS{}, pSrcBand{}, pDstBand{},
186 dfHeightAdjFactor{0}, nLineCount{0}, adfTransform{0, 1, 0, 0, 0, 1},
187 adfInvTransform{}, oProgress{}, oZcalc{}, oMutex{}, iMutex{}
189 if (dfMaxDistance2 == 0)
190 dfMaxDistance2 = std::numeric_limits<double>::max();
197 GDALProgressFunc pfnProgress = GDALDummyProgress,
198 void *pProgressArg =
nullptr);
205 CPL_DLL std::unique_ptr<GDALDataset>
output()
207 return std::move(poDstDS);
214 double dfMaxDistance2;
216 std::unique_ptr<GDALDataset> poDstDS;
219 double dfHeightAdjFactor;
221 std::array<double, 6> adfTransform;
222 std::array<double, 6> adfInvTransform;
223 using ProgressFunc = std::function<bool(
double frac,
const char *msg)>;
224 ProgressFunc oProgress;
225 using ZCalc = std::function<double(
int,
int,
double,
double,
double)>;
230 void setOutput(
double &dfResult,
double &dfCellVal,
double dfZ);
231 double calcHeight(
double dfZ,
double dfZ2);
232 bool readLine(
int nLine,
double *data);
233 bool writeLine(
int nLine, std::vector<double> &vResult);
234 bool processLine(
int nX,
int nY,
int nLine,
235 std::vector<double> &vLastLineVal);
236 bool processFirstLine(
int nX,
int nY, std::vector<double> &vLastLineVal);
237 void processFirstLineLeft(
int nX,
int iStart,
int iEnd,
238 std::vector<double> &vResult,
239 std::vector<double> &vThisLineVal);
240 void processFirstLineRight(
int nX,
int iStart,
int iEnd,
241 std::vector<double> &vResult,
242 std::vector<double> &vThisLineVal);
243 void processFirstLineTopOrBottom(
int iLeft,
int iRight,
244 std::vector<double> &vResult,
245 std::vector<double> &vThisLineVal);
246 void processLineLeft(
int nX,
int nYOffset,
int iStart,
int iEnd,
247 std::vector<double> &vResult,
248 std::vector<double> &vThisLineVal,
249 std::vector<double> &vLastLineVal);
250 void processLineRight(
int nX,
int nYOffset,
int iStart,
int iEnd,
251 std::vector<double> &vResult,
252 std::vector<double> &vThisLineVal,
253 std::vector<double> &vLastLineVal);
254 std::pair<int, int> adjustHeight(
int iLine,
int nX,
255 std::vector<double> &thisLineVal);
256 bool calcOutputExtent(
int nX,
int nY);
257 bool createOutputDataset();
259 bool emitProgress(
double fraction);
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:449
A single raster band (or channel).
Definition: gdal_priv.h:1504
Class to support viewshed raster generation.
Definition: viewshed.h:47
std::unique_ptr< GDALDataset > output()
Fetch a pointer to the created raster band.
Definition: viewshed.h:205
bool run(GDALRasterBandH hBand, GDALProgressFunc pfnProgress=GDALDummyProgress, void *pProgressArg=nullptr)
Compute the viewshed of a raster band.
Definition: viewshed.cpp:959
Viewshed(const Options &opts)
Constructor.
Definition: viewshed.h:182
CellMode
Cell height calculation mode.
Definition: viewshed.h:63
@ Max
Maximum value produced by Diagonal and Edge mode.
@ Min
Minimum value produced by Diagonal and Edge mode.
OutputMode
Raster output mode.
Definition: viewshed.h:53
@ Ground
Output height from ground.
@ DEM
Output height from DEM.
@ Normal
Normal output mode (visibility only)
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:294
Options for viewshed generation.
Definition: viewshed.h:156
double maxDistance
maximum distance from observer to compute value
Definition: viewshed.h:165
double nodataVal
raster output value for pixels with no data
Definition: viewshed.h:163
double curveCoeff
coefficient for atmospheric refraction
Definition: viewshed.h:167
CellMode cellMode
Mode of cell height calculation.
Definition: viewshed.h:173
CPLStringList creationOpts
options for output raster creation
Definition: viewshed.h:172
OutputMode outputMode
Output information.
Definition: viewshed.h:168
std::string outputFormat
output raster format
Definition: viewshed.h:170
double outOfRangeVal
raster output value for pixels outside of max distance.
Definition: viewshed.h:161
double visibleVal
raster output value for visible pixels.
Definition: viewshed.h:158
double invisibleVal
raster output value for non-visible pixels.
Definition: viewshed.h:159
double targetHeight
target height above the DEM surface
Definition: viewshed.h:164
std::string outputFilename
output raster filename
Definition: viewshed.h:171
Point observer
x, y, and z of the observer
Definition: viewshed.h:157
A point.
Definition: viewshed.h:74
double y
Y value.
Definition: viewshed.h:76
double x
X value.
Definition: viewshed.h:75
double z
Z value.
Definition: viewshed.h:77
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition: viewshed.h:84
int clampY(int nY) const
Clamp the argument to be in the window in the Y dimension.
Definition: viewshed.h:138
bool contains(int nX, int nY) const
Determine if the window contains the index.
Definition: viewshed.h:122
bool containsX(int nX) const
Determine if the X window contains the index.
Definition: viewshed.h:105
int clampX(int nX) const
Clamp the argument to be in the window in the X dimension.
Definition: viewshed.h:130
bool containsY(int nY) const
Determine if the Y window contains the index.
Definition: viewshed.h:113
int xStart
X start position.
Definition: viewshed.h:85
int xSize() const
Window size in the X direction.
Definition: viewshed.h:91
int xStop
X end position.
Definition: viewshed.h:86
int yStop
Y end position.
Definition: viewshed.h:88
void shiftX(int nShift)
Shift the X dimension by nShift.
Definition: viewshed.h:145
int yStart
Y start position.
Definition: viewshed.h:87
int ySize() const
Window size in the Y direction.
Definition: viewshed.h:97