Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/alg/viewshed/viewshed.h
Line
Count
Source
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
36
/**
37
 * Class to support viewshed raster generation.
38
 */
39
class Viewshed
40
{
41
  public:
42
    /**
43
     * Constructor.
44
     *
45
     * @param opts Options to use when calculating viewshed.
46
    */
47
    CPL_DLL explicit Viewshed(const Options &opts);
48
49
    /** Destructor */
50
    CPL_DLL ~Viewshed();
51
52
    CPL_DLL bool run(GDALRasterBandH hBand,
53
                     GDALProgressFunc pfnProgress = GDALDummyProgress,
54
                     void *pProgressArg = nullptr);
55
56
    CPL_DLL bool run(GDALRasterBandH hBand, GDALRasterBandH hSdBand,
57
                     GDALProgressFunc pfnProgress = GDALDummyProgress,
58
                     void *pProgressArg = nullptr);
59
60
    /**
61
     * Fetch a pointer to the created raster band.
62
     *
63
     * @return  Unique pointer to the viewshed dataset.
64
    */
65
    CPL_DLL DatasetPtr output()
66
0
    {
67
0
        return std::move(poDstDS);
68
0
    }
69
70
  private:
71
    Options oOpts;
72
    Window oOutExtent{};
73
    Window oCurExtent{};
74
    DatasetPtr poDstDS{};
75
    GDALRasterBand *pSrcBand = nullptr;
76
    GDALRasterBand *pSdBand = nullptr;
77
78
    DatasetPtr execute(int nX, int nY, const std::string &outFilename);
79
    void setOutput(double &dfResult, double &dfCellVal, double dfZ);
80
    double calcHeight(double dfZ, double dfZ2);
81
    bool readLine(int nLine, double *data);
82
    std::pair<int, int> adjustHeight(int iLine, int nX,
83
                                     std::vector<double> &thisLineVal);
84
    bool calcExtents(int nX, int nY, const GDALGeoTransform &invGT);
85
86
    Viewshed(const Viewshed &) = delete;
87
    Viewshed &operator=(const Viewshed &) = delete;
88
};
89
90
double CPL_DLL adjustCurveCoeff(double curveCoeff, GDALDatasetH hSrcDS);
91
92
}  // namespace viewshed
93
}  // namespace gdal
94
95
#endif