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
31 namespace gdal
32{
33 namespace viewshed
34{
35
39 class Viewshed
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, const GDALGeoTransform &invGT);
80
81 Viewshed(const Viewshed &) = delete;
82 Viewshed &operator=(const Viewshed &) = delete;
83};
84
85 double CPL_DLL adjustCurveCoeff(double curveCoeff, GDALDatasetH hSrcDS);
86
87} // namespace viewshed
88} // namespace gdal
89
90#endif
GDALGeoTransform
Class that encapsulates a geotransform matrix.
Definition gdal_geotransform.h:42
GDALRasterBand
A single raster band (or channel).
Definition gdal_rasterband.h:105
gdal::viewshed::Viewshed
Class to support viewshed raster generation.
Definition viewshed.h:40
gdal::viewshed::Viewshed::output
DatasetPtr output()
Fetch a pointer to the created raster band.
Definition viewshed.h:61
gdal::viewshed::Viewshed::run
bool run(GDALRasterBandH hBand, GDALProgressFunc pfnProgress=GDALDummyProgress, void *pProgressArg=nullptr)
Compute the viewshed of a raster band.
Definition viewshed.cpp:399
gdal::viewshed::Viewshed::~Viewshed
~Viewshed()
Destructor.
GDALDatasetH
void * GDALDatasetH
Opaque type used for the C bindings of the C++ GDALDataset class.
Definition gdal_fwd.h:42
GDALRasterBandH
void * GDALRasterBandH
Opaque type used for the C bindings of the C++ GDALRasterBand class.
Definition gdal_fwd.h:45
gdal_priv.h
This file is legacy since GDAL 3.12, but will be kept at least in the whole GDAL 3....
gdal::viewshed::Options
Options for viewshed generation.
Definition viewshed_types.h:59
gdal::viewshed::Window
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition viewshed_types.h:116