Viewshed 6.1.0
A C++ library for calculation of viewshed, inverse viewshed and visibility indices for both of those analyses.
Loading...
Searching...
No Matches
viewshed::AbstractViewshed Class Referenceabstract

Abstract class that represents viewshed calculation from this class specific implementations ( Viewshed and InverseViewshed) are derived. Class provides all the base functions for those algorithms, including implementation of plane sweep algorithm for viewshed according to Van Kreveld(1996) and Haverkort et al(2007), as implemented in GRASS GIS described by Toma et al. (2022). More...

#include <abstractviewshed.h>

Inheritance diagram for viewshed::AbstractViewshed:
Collaboration diagram for viewshed::AbstractViewshed:

Public Member Functions

void initEventList ()
 Create event list for line sweep algorithm from input raster.
void sortEventList ()
 Sort event list for parsing.
void parseEventList (std::function< void(int, int)> progressCallback=[](int, int) {})
 Parse event list by individual events.
bool extractValuesFromEventList (std::shared_ptr< ProjectedSquareCellRaster > dem_, std::string fileName, std::function< double(LoSNode)> func)
 Extract values from event list into a raster and save it to file.
bool isInsideAngles (const double &eventEnterAngle, const double &eventExitAngle)
 Checks if cell with these enter and exit angles falls inside the angle limit.
void setMaximalDistance (double distance)
 Set the Maximal Distance limit value. Limits event list creation to cells within this distance limit. Value is in the same units as CRS of input raster.
void setAngles (double minAngle, double maxAngle)
 Set horizontal angle limits for viewshed calculation. 0.
void setMaxConcurentTasks (int maxTasks)
 Set the number of maximum Concurent Taks that can be prepared in thread pool for processing.
void setMaxThreads (int threads)
 Set the maximal number of threads that can be used for calculation.
void prepareMemoryRasters ()
 Initialized output rasters in memory.
virtual void calculate (std::function< void(std::string, double)> stepsTimingCallback=[](std::string text, double time) {}, std::function< void(int, int)> progressCallback=[](int, int) {})=0
 Calculate the viewshed. Covers all the steps - create list of events, sort list of events, parse list of events.
virtual void addEventsFromCell (int &row, int &column, const double &pixelValue, bool &solveCell)=0
 Function that creates events for event list from given cell.
virtual void submitToThreadpool (const CellEvent &e)=0
 Submit LoS with this CellEvent to threadpool for solving.
std::shared_ptr< SingleBandRaster > resultRaster (int index=0)
 Extract individual result raster.
bool saveResults (std::string location, std::string fileNamePrefix="")
 Save all result rasters into the folder, optionally using name prefix.
LoSNode statusNodeFromPoint (OGRPoint point)
 Create LoSNode from OGRPoint.
OGRPoint point (int row, int col)
 Create OGRPoint with coordinates of given row and column in the raster.
void setDefaultResultDataType (GDALDataType dataType)
 Set the Default Result Data Type to use in output rasters.
long numberOfValidCells ()
 Number of valid cells in raster - cells not containing no data.
long numberOfCellEvents ()
 Number of events in event list.
bool isValid ()
 Check if the viewshed is valid, meaning that the important point is valid.
bool hasError ()
 Check if an error occurred during calculation (e.g. in one of the worker threads).
std::string errorMessage ()
 Message of the first error that occurred during calculation, empty string if there was none.
void setVisibilityMask (std::shared_ptr< ProjectedSquareCellRaster > mask)
 Set the Visibility Mask for viewshed calculation.
long long totalCountOfLoSNodes ()
 Overall number of solved LoSNodes in all evaluated LoS.
long long sizeOfEvents ()
 Size of cell event list in bytes.
long long totalSizeOfLoS ()
 Overall size of all solved LoS in bytes.
long long meanSizeOfLoS ()
 Mean size of solved LoS in bytes.
double initLastedSeconds ()
 Number of seconds the creation of event list lasted.
double sortLastedSeconds ()
 Number of seconds the sort of event list lasted.
double parseLastedSeconds ()
 Number of seconds the parsing of event list lasted.
double processingLastedSeconds ()
 Number of seconds the calculation of viewshed indexes lasted.
long long sizeOfOutputRaster ()
 Size in bytes that one output raster takes.
int numberOfResultRasters ()
 Number of output rasters. Equals number of input algorithms.
long long sizeOfOutputRasters ()
 Size in bytes that all output raster takes.
CellEvent cellEvent (size_t i)
 Extract individual cell event from cell events.
virtual void calculateVisibilityRaster ()=0
 Calculate visibility mask of areas which are visible from point (visibility), or from which the points is visible (inverse visibility). The visibility raster is calculated using fast algorithm, significantly faster than algorithms with visibility indices.
bool saveVisibilityRaster (std::string filePath)
 Save visibility raster to file.
void calculateVisibilityMask ()
 Calculate visibility mask raster.

Protected Member Functions

void recordTaskError (const std::string &message)
 Store error message from a calculation task, keeping only the first one recorded.
std::vector< LoSNodeprepareLoSWithPoint (OGRPoint point)
bool validAngles ()

Protected Attributes

std::vector< LoSNodemLosNodes
 LoSNodes in currently solved LoS while parsing event list.
std::vector< CellEventmCellEvents
 Event list. All cell events for the input raster.
std::shared_ptr< ProjectedSquareCellRaster > mInputDsm
 Input raster with digital surface model.
std::shared_ptr< ProjectedSquareCellRaster > mVisibilityMask = nullptr
 Input raster with visibility calculation mask.
std::shared_ptr< PointmPoint
 Important point for visibility calculation. Either viewpoint (normal viewshed) or target point (inverse viewshed).
std::shared_ptr< ViewshedAlgorithms > mVisibilityIndices
 Visibility indexes to calculate while calculating this viewshed. As AbstractViewshedAlgorithm.
GDALDataType mDataType = OUTPUT_RASTER_DATA_TYPE
 Data type of output rasters.
int mDefaultBand = 1
 Default band to read from rasters.
long mValidCells = 0
long mTotalLosNodesCount = 0
long mNumberOfLos = 0
bool mInverseViewshed = false
double mMaxDistance = std::numeric_limits<double>::max()
double mMinAngle = std::numeric_limits<double>::quiet_NaN()
double mMaxAngle = std::numeric_limits<double>::quiet_NaN()
int mMaxNumberOfTasks = 100
 Maximal number of LoS to solve, that can be stored in threadpool.
double mCellSize = 0
bool mValid = false
std::mutex mTaskErrorMutex
 Guards access to mTaskError, which can be written from worker threads.
std::string mTaskError
 First error that occurred during calculation, empty if there was none.
bool mCurvatureCorrections = false
double mEarthDiameter = EARTH_DIAMETER
double mRefractionCoefficient = REFRACTION_COEFFICIENT
LoSNode mLosNodePoint
BS::thread_pool mThreadPool
 Threadpool that takes care of preparing individual threads with LoS to be solved.
std::shared_ptr< ResultRasters > mResults = std::make_shared<ResultRasters>()
std::shared_ptr< ProjectedSquareCellRaster > mVisibilityRaster = nullptr
std::chrono::nanoseconds mTimeInit
std::chrono::nanoseconds mTimeSort
std::chrono::nanoseconds mTimeParse
double mCellElevs [3]
double mAngleCenter
double mAngleEnter
double mAngleExit
double mEventDistance
CellEvent mEventCenter
CellEvent mEventEnter
CellEvent mEventExit = CellEvent()
CellEvent mEventEnterOpposite
CellEvent mEventExitOpposite = CellEvent()
double mOppositeAngleEnter
double mOppositeAngleExit
LoSNode mLoSNodeTemp = LoSNode()

Detailed Description

Abstract class that represents viewshed calculation from this class specific implementations ( Viewshed and InverseViewshed) are derived. Class provides all the base functions for those algorithms, including implementation of plane sweep algorithm for viewshed according to Van Kreveld(1996) and Haverkort et al(2007), as implemented in GRASS GIS described by Toma et al. (2022).

VAN KREVELD, M. Variations on Sweep Algorithms: efficient computation of extended viewsheds and class intervals. Utrecht: Utrecht University: Information and Computing Sciences, 1996.

HAVERKORT, H., TOMA, L., ZHUANG, Y. Computing Visibility on Terrains in External Memory. ACM Journal on Experimental Algorithmics, 13, 2009.

TOMA, L., ZHUANG, Y., RICHARD, W., METZ, M. Grass gis manual: r.viewshed, 2022. https://grass.osgeo.org/grass82/manuals/r.viewshed.html.

Member Function Documentation

◆ addEventsFromCell()

virtual void viewshed::AbstractViewshed::addEventsFromCell ( int & row,
int & column,
const double & pixelValue,
bool & solveCell )
pure virtual

Function that creates events for event list from given cell.

Parameters
row
column
pixelValue
rasterBlock
solveCellBased on mask value, information whether center event for this cell should be created.

Implemented in InverseViewshed, Viewshed, viewshed::InverseViewshed, and viewshed::Viewshed.

◆ calculate()

virtual void viewshed::AbstractViewshed::calculate ( std::function< void(std::string, double)> stepsTimingCallback = [](std::string text, double time) {},
std::function< void(int, int)> progressCallback = [](int, int) {} )
pure virtual

Calculate the viewshed. Covers all the steps - create list of events, sort list of events, parse list of events.

Parameters
stepsTimingCallbackCallback function outputing message how long individual step takes.
progressCallbackCallback function outputing processes part of event list.

Implemented in InverseViewshed, Viewshed, viewshed::InverseViewshed, and viewshed::Viewshed.

◆ calculateVisibilityRaster()

virtual void viewshed::AbstractViewshed::calculateVisibilityRaster ( )
pure virtual

Calculate visibility mask of areas which are visible from point (visibility), or from which the points is visible (inverse visibility). The visibility raster is calculated using fast algorithm, significantly faster than algorithms with visibility indices.

Implemented in InverseViewshed, Viewshed, viewshed::InverseViewshed, and viewshed::Viewshed.

◆ cellEvent()

CellEvent viewshed::AbstractViewshed::cellEvent ( size_t i)
inline

Extract individual cell event from cell events.

Parameters
i
Returns
CellEvent

◆ errorMessage()

std::string viewshed::AbstractViewshed::errorMessage ( )
inline

Message of the first error that occurred during calculation, empty string if there was none.

Returns
std::string

◆ extractValuesFromEventList()

bool AbstractViewshed::extractValuesFromEventList ( std::shared_ptr< ProjectedSquareCellRaster > dem_,
std::string fileName,
std::function< double(LoSNode)> func )

Extract values from event list into a raster and save it to file.

Returns
true if the raster was successfully saved, false otherwise.

◆ hasError()

bool viewshed::AbstractViewshed::hasError ( )
inline

Check if an error occurred during calculation (e.g. in one of the worker threads).

Returns
true
false

◆ initLastedSeconds()

double viewshed::AbstractViewshed::initLastedSeconds ( )
inline

Number of seconds the creation of event list lasted.

Returns
double

◆ isInsideAngles()

bool AbstractViewshed::isInsideAngles ( const double & eventEnterAngle,
const double & eventExitAngle )

Checks if cell with these enter and exit angles falls inside the angle limit.

Parameters
eventEnterAngle
eventExitAngle
Returns
true
false

◆ isValid()

bool viewshed::AbstractViewshed::isValid ( )
inline

Check if the viewshed is valid, meaning that the important point is valid.

Returns
true
false

◆ meanSizeOfLoS()

long long viewshed::AbstractViewshed::meanSizeOfLoS ( )
inline

Mean size of solved LoS in bytes.

Returns
long long

◆ numberOfCellEvents()

long viewshed::AbstractViewshed::numberOfCellEvents ( )
inline

Number of events in event list.

Returns
long

◆ numberOfResultRasters()

int viewshed::AbstractViewshed::numberOfResultRasters ( )
inline

Number of output rasters. Equals number of input algorithms.

Returns
int

◆ numberOfValidCells()

long viewshed::AbstractViewshed::numberOfValidCells ( )
inline

Number of valid cells in raster - cells not containing no data.

Returns
long

◆ parseEventList()

void AbstractViewshed::parseEventList ( std::function< void(int, int)> progressCallback = []( int, int ) {})

Parse event list by individual events.

Parameters
progressCallbackCall function with arguments of elements done from total elements (both as intereger).

◆ parseLastedSeconds()

double viewshed::AbstractViewshed::parseLastedSeconds ( )
inline

Number of seconds the parsing of event list lasted.

Returns
double

◆ point()

OGRPoint AbstractViewshed::point ( int row,
int col )

Create OGRPoint with coordinates of given row and column in the raster.

Parameters
row
col
Returns
OGRPoint

◆ processingLastedSeconds()

double viewshed::AbstractViewshed::processingLastedSeconds ( )
inline

Number of seconds the calculation of viewshed indexes lasted.

Returns
double

◆ resultRaster()

std::shared_ptr< SingleBandRaster > AbstractViewshed::resultRaster ( int index = 0)

Extract individual result raster.

Parameters
index
Returns
std::shared_ptr<SingleBandRaster>

◆ saveResults()

bool AbstractViewshed::saveResults ( std::string location,
std::string fileNamePrefix = "" )

Save all result rasters into the folder, optionally using name prefix.

Parameters
location
fileNamePrefix
Returns
true if all rasters were successfully saved, false if any save failed.

◆ saveVisibilityRaster()

bool AbstractViewshed::saveVisibilityRaster ( std::string filePath)

Save visibility raster to file.

Parameters
filePath
Returns
true if the raster was successfully saved, false otherwise.

◆ setAngles()

void AbstractViewshed::setAngles ( double minAngle,
double maxAngle )

Set horizontal angle limits for viewshed calculation. 0.

Parameters
minAngle
maxAngle

◆ setDefaultResultDataType()

void AbstractViewshed::setDefaultResultDataType ( GDALDataType dataType)

Set the Default Result Data Type to use in output rasters.

Parameters
dataType

◆ setMaxConcurentTasks()

void AbstractViewshed::setMaxConcurentTasks ( int maxTasks)

Set the number of maximum Concurent Taks that can be prepared in thread pool for processing.

Parameters
maxTasks

◆ setMaximalDistance()

void AbstractViewshed::setMaximalDistance ( double distance)

Set the Maximal Distance limit value. Limits event list creation to cells within this distance limit. Value is in the same units as CRS of input raster.

Parameters
distance

◆ setMaxThreads()

void AbstractViewshed::setMaxThreads ( int threads)

Set the maximal number of threads that can be used for calculation.

Parameters
threads

◆ setVisibilityMask()

void viewshed::AbstractViewshed::setVisibilityMask ( std::shared_ptr< ProjectedSquareCellRaster > mask)
inline

Set the Visibility Mask for viewshed calculation.

Parameters
mask

◆ sizeOfEvents()

long long viewshed::AbstractViewshed::sizeOfEvents ( )
inline

Size of cell event list in bytes.

Returns
long long

◆ sizeOfOutputRaster()

long long viewshed::AbstractViewshed::sizeOfOutputRaster ( )
inline

Size in bytes that one output raster takes.

Returns
long long

◆ sizeOfOutputRasters()

long long viewshed::AbstractViewshed::sizeOfOutputRasters ( )
inline

Size in bytes that all output raster takes.

Returns
long long

◆ sortLastedSeconds()

double viewshed::AbstractViewshed::sortLastedSeconds ( )
inline

Number of seconds the sort of event list lasted.

Returns
double

◆ statusNodeFromPoint()

LoSNode AbstractViewshed::statusNodeFromPoint ( OGRPoint point)

Create LoSNode from OGRPoint.

Parameters
point
Returns
LoSNode

◆ submitToThreadpool()

virtual void viewshed::AbstractViewshed::submitToThreadpool ( const CellEvent & e)
pure virtual

Submit LoS with this CellEvent to threadpool for solving.

Parameters
e

Implemented in viewshed::InverseViewshed, Viewshed, and viewshed::Viewshed.

◆ totalCountOfLoSNodes()

long long viewshed::AbstractViewshed::totalCountOfLoSNodes ( )
inline

Overall number of solved LoSNodes in all evaluated LoS.

Returns
long long

◆ totalSizeOfLoS()

long long viewshed::AbstractViewshed::totalSizeOfLoS ( )
inline

Overall size of all solved LoS in bytes.

Returns
long long

The documentation for this class was generated from the following files: