Line data Source code
1 : /**************************************************************************** 2 : * (c) 2024 info@hobu.co 3 : * 4 : * SPDX-License-Identifier: MIT 5 : ****************************************************************************/ 6 : #ifndef VIEWSHED_TYPES_H_INCLUDED 7 : #define VIEWSHED_TYPES_H_INCLUDED 8 : 9 : #include <algorithm> 10 : #include <string> 11 : 12 : #include "gdal_priv.h" 13 : 14 : namespace gdal 15 : { 16 : namespace viewshed 17 : { 18 : 19 : /// Unique pointer to GDAL dataset. 20 : using DatasetPtr = std::unique_ptr<GDALDataset>; 21 : 22 : /** 23 : * Raster output mode. 24 : */ 25 : enum class OutputMode 26 : { 27 : Normal, //!< Normal output mode (visibility only) 28 : DEM, //!< Output height from DEM 29 : Ground, //!< Output height from ground 30 : Cumulative //!< Output observability heat map 31 : }; 32 : 33 : /** 34 : * Cell height calculation mode. 35 : */ 36 : enum class CellMode 37 : { 38 : Diagonal, //!< Diagonal Mode 39 : Edge, //!< Edge Mode 40 : Max, //!< Maximum value produced by Diagonal and Edge mode 41 : Min //!< Minimum value produced by Diagonal and Edge mode 42 : }; 43 : 44 : /** 45 : * A point. 46 : */ 47 : struct Point 48 : { 49 : double x; //!< X value 50 : double y; //!< Y value 51 : double z; //!< Z value 52 : }; 53 : 54 : /** 55 : * Options for viewshed generation. 56 : */ 57 : struct Options 58 : { 59 : Point observer{0, 0, 0}; //!< x, y, and z of the observer 60 : double visibleVal{255}; //!< raster output value for visible pixels. 61 : double invisibleVal{0}; //!< raster output value for non-visible pixels. 62 : double outOfRangeVal{ 63 : 0}; //!< raster output value for pixels outside of max distance. 64 : double nodataVal{-1}; //!< raster output value for pixels with no data 65 : double targetHeight{0.0}; //!< target height above the DEM surface 66 : double maxDistance{ 67 : 0.0}; //!< maximum distance from observer to compute value 68 : double curveCoeff{.85714}; //!< coefficient for atmospheric refraction 69 : OutputMode outputMode{OutputMode::Normal}; //!< Output information. 70 : //!< Normal, Height from DEM or Height from ground 71 : std::string outputFormat{}; //!< output raster format 72 : std::string outputFilename{}; //!< output raster filename 73 : CPLStringList creationOpts{}; //!< options for output raster creation 74 : CellMode cellMode{CellMode::Edge}; //!< Mode of cell height calculation. 75 : int observerSpacing{10}; //!< Observer spacing in cumulative mode. 76 : uint8_t numJobs{3}; //!< Relative number of jobs in cumulative mode. 77 : }; 78 : 79 : /** 80 : * A window in a raster including pixels in [xStart, xStop) and [yStart, yStop). 81 : */ 82 : struct Window 83 : { 84 : int xStart{}; //!< X start position 85 : int xStop{}; //!< X end position 86 : int yStart{}; //!< Y start position 87 : int yStop{}; //!< Y end position 88 : 89 : /// \brief Window size in the X direction. 90 5236860 : int xSize() const 91 : { 92 5236860 : return xStop - xStart; 93 : } 94 : 95 : /// \brief Window size in the Y direction. 96 45210 : int ySize() const 97 : { 98 45210 : return yStop - yStart; 99 : } 100 : 101 : /// \brief Number of cells. 102 43264 : size_t size() const 103 : { 104 43264 : return static_cast<size_t>(xSize()) * ySize(); 105 : } 106 : 107 : /// \brief Determine if the X window contains the index. 108 : /// \param nX Index to check 109 : /// \return True if the index is contained, false otherwise. 110 83697 : bool containsX(int nX) const 111 : { 112 83697 : return nX >= xStart && nX < xStop; 113 : } 114 : 115 : /// \brief Determine if the Y window contains the index. 116 : /// \param nY Index to check 117 : /// \return True if the index is contained, false otherwise. 118 654 : bool containsY(int nY) const 119 : { 120 654 : return nY >= xStart && nY < yStop; 121 : } 122 : 123 : /// \brief Determine if the window contains the index. 124 : /// \param nX X coordinate of the index to check 125 : /// \param nY Y coordinate of the index to check 126 : /// \return True if the index is contained, false otherwise. 127 37 : bool contains(int nX, int nY) const 128 : { 129 37 : return containsX(nX) && containsY(nY); 130 : } 131 : 132 : /// \brief Clamp the argument to be in the window in the X dimension. 133 : /// \param nX Value to clamp. 134 : /// \return Clamped value. 135 246724 : int clampX(int nX) const 136 : { 137 246724 : return xSize() ? std::clamp(nX, xStart, xStop - 1) : xStart; 138 : } 139 : 140 : /// \brief Clamp the argument to be in the window in the Y dimension. 141 : /// \param nY Value to clamp. 142 : /// \return Clamped value. 143 1246 : int clampY(int nY) const 144 : { 145 1246 : return ySize() ? std::clamp(nY, yStart, yStop - 1) : yStart; 146 : } 147 : 148 : /// \brief Shift the X dimension by nShift. 149 : /// \param nShift Amount to shift 150 37 : void shiftX(int nShift) 151 : { 152 37 : xStart += nShift; 153 37 : xStop += nShift; 154 37 : } 155 : }; 156 : 157 : } // namespace viewshed 158 : } // namespace gdal 159 : 160 : #endif