GDAL
cumulative.h
1/******************************************************************************
2 * (c) 2024 info@hobu.co
3 *
4 * SPDX-License-Identifier: MIT
5 ****************************************************************************/
6
7#ifndef VIEWSHED_CUMULATIVE_H_INCLUDED
8#define VIEWSHED_CUMULATIVE_H_INCLUDED
9
10#include <atomic>
11#include <vector>
12
13#include "notifyqueue.h"
14#include "progress.h"
15#include "viewshed_types.h"
16
17namespace gdal
18{
19namespace viewshed
20{
21
22class Progress;
23
26{
27 public:
28 CPL_DLL explicit Cumulative(const Options &opts);
29 // We define an explicit destructor, whose implementation is in libgdal,
30 // otherwise with gcc 9.4 of Ubuntu 20.04 in debug mode, this would need to
31 // redefinition of the NotifyQueue class in both libgdal and gdal_viewshed,
32 // leading to weird things related to mutex.
33 CPL_DLL ~Cumulative();
34 CPL_DLL bool run(const std::string &srcFilename,
35 GDALProgressFunc pfnProgress = GDALDummyProgress,
36 void *pProgressArg = nullptr);
37
38 private:
39 friend class Combiner; // Provides access to the queue types.
40
41 struct Location
42 {
43 int x;
44 int y;
45 };
46
47 using Buf32 = std::vector<uint32_t>;
48 using ObserverQueue = NotifyQueue<Location>;
49 using DatasetQueue = NotifyQueue<DatasetPtr>;
50
51 Window m_extent{};
52 Options m_opts;
53 ObserverQueue m_observerQueue{};
54 DatasetQueue m_datasetQueue{};
55 DatasetQueue m_rollupQueue{};
56 Buf32 m_finalBuf{};
57
58 void runExecutor(const std::string &srcFilename, Progress &progress,
59 std::atomic<bool> &err, std::atomic<int> &running);
60 void rollupRasters();
61 void scaleOutput();
62 bool writeOutput(DatasetPtr pDstDS);
63
64 Cumulative(const Cumulative &) = delete;
65 Cumulative &operator=(const Cumulative &) = delete;
66};
67
68} // namespace viewshed
69} // namespace gdal
70
71#endif
Reads completed viewshed rasters and sums them together.
Definition: combiner.h:22
Generates a cumulative viewshed from a matrix of observers.
Definition: cumulative.h:26
Cumulative(const Options &opts)
Constructor.
Definition: cumulative.cpp:27
bool run(const std::string &srcFilename, GDALProgressFunc pfnProgress=GDALDummyProgress, void *pProgressArg=nullptr)
Compute the cumulative viewshed of a raster band.
Definition: cumulative.cpp:41
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