GDAL

viewshed_executor.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#pragma once
15
16#include <array>
17#include <mutex>
18
19#include "gdal_priv.h"
20#include "cpl_worker_thread_pool.h"
21
22#include "viewshed_types.h"
23
24 namespace gdal
25{
26 namespace viewshed
27{
28
29 class Progress;
30
33 class ViewshedExecutor
34{
35 public:
36 ViewshedExecutor(GDALRasterBand &srcBand, GDALRasterBand &dstBand, int nX,
37 int nY, const Window &oOutExtent, const Window &oCurExtent,
38 const Options &opts, Progress &oProgress);
39 bool run();
40
41 private:
42 CPLWorkerThreadPool m_pool;
43 GDALRasterBand &m_srcBand;
44 GDALRasterBand &m_dstBand;
45 const Window oOutExtent;
46 const Window oCurExtent;
47 const int m_nX;
48 const int m_nY;
49 const Options oOpts;
50 Progress &oProgress;
51 double m_dfHeightAdjFactor{0};
52 double m_dfMaxDistance2;
53 double m_dfZObserver{0};
54 std::mutex iMutex{};
55 std::mutex oMutex{};
56 std::array<double, 6> m_adfTransform{0, 1, 0, 0, 0, 1};
57 double (*oZcalc)(int, int, double, double, double){};
58
59 double calcHeightAdjFactor();
60 void setOutput(double &dfResult, double &dfCellVal, double dfZ);
61 bool readLine(int nLine, double *data);
62 bool writeLine(int nLine, std::vector<double> &vResult);
63 bool processLine(int nLine, std::vector<double> &vLastLineVal);
64 bool processFirstLine(std::vector<double> &vLastLineVal);
65 void processFirstLineLeft(int iStart, int iEnd,
66 std::vector<double> &vResult,
67 std::vector<double> &vThisLineVal);
68 void processFirstLineRight(int iStart, int iEnd,
69 std::vector<double> &vResult,
70 std::vector<double> &vThisLineVal);
71 void processFirstLineTopOrBottom(int iLeft, int iRight,
72 std::vector<double> &vResult,
73 std::vector<double> &vThisLineVal);
74 void processLineLeft(int nYOffset, int iStart, int iEnd,
75 std::vector<double> &vResult,
76 std::vector<double> &vThisLineVal,
77 std::vector<double> &vLastLineVal);
78 void processLineRight(int nYOffset, int iStart, int iEnd,
79 std::vector<double> &vResult,
80 std::vector<double> &vThisLineVal,
81 std::vector<double> &vLastLineVal);
82 std::pair<int, int> adjustHeight(int iLine,
83 std::vector<double> &thisLineVal);
84};
85
86} // namespace viewshed
87} // namespace gdal
CPLWorkerThreadPool
Pool of worker threads.
Definition: cpl_worker_thread_pool.h:66
GDALRasterBand
A single raster band (or channel).
Definition: gdal_priv.h:1519
gdal::viewshed::Progress
Support for progress reporting in viewshed construction.
Definition: progress.h:23
gdal::viewshed::ViewshedExecutor
Executes a viewshed computation on a source band, placing the result in the destination band.
Definition: viewshed_executor.h:34
gdal::viewshed::ViewshedExecutor::ViewshedExecutor
ViewshedExecutor(GDALRasterBand &srcBand, GDALRasterBand &dstBand, int nX, int nY, const Window &oOutExtent, const Window &oCurExtent, const Options &opts, Progress &oProgress)
Constructor – the viewshed algorithm executor.
Definition: viewshed_executor.cpp:105
gdal::viewshed::ViewshedExecutor::run
bool run()
Run the viewshed computation.
Definition: viewshed_executor.cpp:626
cpl_worker_thread_pool.h
Class to manage a pool of worker threads.
gdal_priv.h
C++ GDAL entry points.
gdal::viewshed::Options
Options for viewshed generation.
Definition: viewshed_types.h:58
gdal::viewshed::Window
A window in a raster including pixels in [xStart, xStop) and [yStart, yStop).
Definition: viewshed_types.h:83