GDAL
viewshed.h
1/******************************************************************************
2 *
3 * Project: Viewshed Generation
4 * Purpose: Core algorithm implementation for viewshed generation.
5 * Author: Tamas Szekeres, szekerest@gmail.com
6 *
7 * (c) 2024 info@hobu.co
8 *
9 ******************************************************************************
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef VIEWSHED_H_INCLUDED
15#define VIEWSHED_H_INCLUDED
16
17#include <algorithm>
18#include <array>
19#include <cstdint>
20#include <functional>
21#include <limits>
22#include <memory>
23#include <mutex>
24#include <queue>
25#include <string>
26
27#include "cpl_progress.h"
28#include "gdal_priv.h"
29#include "viewshed_types.h"
30
31namespace gdal
32{
33namespace viewshed
34{
35
40{
41 public:
47 CPL_DLL explicit Viewshed(const Options &opts);
48
50 CPL_DLL ~Viewshed();
51
52 CPL_DLL bool run(GDALRasterBandH hBand,
53 GDALProgressFunc pfnProgress = GDALDummyProgress,
54 void *pProgressArg = nullptr);
55
61 CPL_DLL DatasetPtr output()
62 {
63 return std::move(poDstDS);
64 }
65
66 private:
67 Options oOpts;
68 Window oOutExtent{};
69 Window oCurExtent{};
70 DatasetPtr poDstDS{};
71 GDALRasterBand *pSrcBand = nullptr;
72
73 DatasetPtr execute(int nX, int nY, const std::string &outFilename);
74 void setOutput(double &dfResult, double &dfCellVal, double dfZ);
75 double calcHeight(double dfZ, double dfZ2);
76 bool readLine(int nLine, double *data);
77 std::pair<int, int> adjustHeight(int iLine, int nX,
78 std::vector<double> &thisLineVal);
79 bool calcExtents(int nX, int nY,
80 const std::array<double, 6> &adfInvTransform);
81
82 Viewshed(const Viewshed &) = delete;
83 Viewshed &operator=(const Viewshed &) = delete;
84};
85
86} // namespace viewshed
87} // namespace gdal
88
89#endif
A single raster band (or channel).
Definition: gdal_priv.h:1519
Class to support viewshed raster generation.
Definition: viewshed.h:40
DatasetPtr output()
Fetch a pointer to the created raster band.
Definition: viewshed.h:61
Viewshed(const Options &opts)
Constructor.
Definition: viewshed.cpp:221
bool run(GDALRasterBandH hBand, GDALProgressFunc pfnProgress=GDALDummyProgress, void *pProgressArg=nullptr)
Compute the viewshed of a raster band.
Definition: viewshed.cpp:300
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition: gdal.h:379
C++ GDAL entry points.
Options for viewshed generation.
Definition: viewshed_types.h:58
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition: viewshed_types.h:83