2#include "viewshed_export.h"
8#include "BS_thread_pool.hpp"
10#include "simplerasters.h"
12#include "abstractviewshedalgorithm.h"
14#include "celleventposition.h"
15#include "defaultdatatypes.h"
18#include "viewshedtypes.h"
19#include "viewshedvalues.h"
20#include "visibility.h"
23using viewshed::ViewshedAlgorithms;
65 void parseEventList( std::function<
void(
int,
int )> progressCallback = [](
int,
int ) {} );
73 std::function<
double(
LoSNode )> func );
83 bool isInsideAngles(
const double &eventEnterAngle,
const double &eventExitAngle );
99 void setAngles(
double minAngle,
double maxAngle );
129 std::function<
void( std::string,
double )> stepsTimingCallback = []( std::string text,
double time ) {},
130 std::function<void(
int,
int )> progressCallback = []( int, int ) {} ) = 0;
141 virtual void addEventsFromCell(
int &row,
int &column,
const double &pixelValue,
bool &solveCell ) = 0;
156 std::shared_ptr<SingleBandRaster>
resultRaster(
int index = 0 );
165 bool saveResults( std::string location, std::string fileNamePrefix =
"" );
182 OGRPoint
point(
int row,
int col );
306 if ( mResults->size() > 0 )
308 return mResults->at( 0 )->dataSize();
406 long mValidCells = 0;
407 long mTotalLosNodesCount = 0;
408 long mNumberOfLos = 0;
410 bool mInverseViewshed =
false;
412 double mMaxDistance = std::numeric_limits<double>::max();
413 double mMinAngle = std::numeric_limits<double>::quiet_NaN();
414 double mMaxAngle = std::numeric_limits<double>::quiet_NaN();
422 double mCellSize = 0;
450 bool mCurvatureCorrections =
false;
451 double mEarthDiameter = EARTH_DIAMETER;
452 double mRefractionCoefficient = REFRACTION_COEFFICIENT;
456 std::vector<LoSNode> prepareLoSWithPoint( OGRPoint point );
465 std::shared_ptr<ResultRasters> mResults = std::make_shared<ResultRasters>();
466 std::shared_ptr<ProjectedSquareCellRaster> mVisibilityRaster =
nullptr;
468 std::chrono::nanoseconds mTimeInit;
469 std::chrono::nanoseconds mTimeSort;
470 std::chrono::nanoseconds mTimeParse;
472 double mCellElevs[3];
473 double mAngleCenter, mAngleEnter, mAngleExit;
474 double mEventDistance;
477 double mOppositeAngleEnter, mOppositeAngleExit;
void setMaximalDistance(double distance)
Set the Maximal Distance limit value. Limits event list creation to cells within this distance limit....
Definition abstractviewshed.cpp:91
bool isInsideAngles(const double &eventEnterAngle, const double &eventExitAngle)
Checks if cell with these enter and exit angles falls inside the angle limit.
Definition abstractviewshed.cpp:127
void initEventList()
Create event list for line sweep algorithm from input raster.
Definition abstractviewshed.cpp:32
void sortEventList()
Sort event list for parsing.
Definition abstractviewshed.cpp:151
void setMaxThreads(int threads)
Set the maximal number of threads that can be used for calculation.
Definition abstractviewshed.cpp:327
void setMaxConcurentTasks(int maxTasks)
Set the number of maximum Concurent Taks that can be prepared in thread pool for processing.
Definition abstractviewshed.cpp:325
void parseEventList(std::function< void(int, int)> progressCallback=[](int, int) {})
Parse event list by individual events.
Definition abstractviewshed.cpp:160
void setAngles(double minAngle, double maxAngle)
Set horizontal angle limits for viewshed calculation. 0.
Definition abstractviewshed.cpp:93
void prepareMemoryRasters()
Initialized output rasters in memory.
Definition abstractviewshed.cpp:12
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.
Definition abstractviewshed.cpp:240
Abstract class that represents viewshed calculation from this class specific implementations ( Viewsh...
Definition abstractviewshed.h:43
CellEvent cellEvent(size_t i)
Extract individual cell event from cell events.
Definition abstractviewshed.h:333
long long meanSizeOfLoS()
Mean size of solved LoS in bytes.
Definition abstractviewshed.h:269
virtual void addEventsFromCell(int &row, int &column, const double &pixelValue, bool &solveCell)=0
Function that creates events for event list from given cell.
long long totalCountOfLoSNodes()
Overall number of solved LoSNodes in all evaluated LoS.
Definition abstractviewshed.h:248
virtual void submitToThreadpool(const CellEvent &e)=0
Submit LoS with this CellEvent to threadpool for solving.
std::string mTaskError
First error that occurred during calculation, empty if there was none.
Definition abstractviewshed.h:435
bool saveResults(std::string location, std::string fileNamePrefix="")
Save all result rasters into the folder, optionally using name prefix.
Definition abstractviewshed.cpp:261
std::shared_ptr< ProjectedSquareCellRaster > mInputDsm
Input raster with digital surface model.
Definition abstractviewshed.h:374
long numberOfValidCells()
Number of valid cells in raster - cells not containing no data.
Definition abstractviewshed.h:196
bool isValid()
Check if the viewshed is valid, meaning that the important point is valid.
Definition abstractviewshed.h:211
void setDefaultResultDataType(GDALDataType dataType)
Set the Default Result Data Type to use in output rasters.
Definition abstractviewshed.cpp:23
void calculateVisibilityMask()
Calculate visibility mask raster.
Definition abstractviewshed.cpp:405
double parseLastedSeconds()
Number of seconds the parsing of event list lasted.
Definition abstractviewshed.h:290
int numberOfResultRasters()
Number of output rasters. Equals number of input algorithms.
Definition abstractviewshed.h:318
void recordTaskError(const std::string &message)
Store error message from a calculation task, keeping only the first one recorded.
Definition abstractviewshed.h:441
LoSNode statusNodeFromPoint(OGRPoint point)
Create LoSNode from OGRPoint.
Definition abstractviewshed.cpp:300
double initLastedSeconds()
Number of seconds the creation of event list lasted.
Definition abstractviewshed.h:276
std::string errorMessage()
Message of the first error that occurred during calculation, empty string if there was none.
Definition abstractviewshed.h:230
void setVisibilityMask(std::shared_ptr< ProjectedSquareCellRaster > mask)
Set the Visibility Mask for viewshed calculation.
Definition abstractviewshed.h:241
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,...
long long totalSizeOfLoS()
Overall size of all solved LoS in bytes.
Definition abstractviewshed.h:262
long numberOfCellEvents()
Number of events in event list.
Definition abstractviewshed.h:203
virtual void calculateVisibilityRaster()=0
Calculate visibility mask of areas which are visible from point (visibility), or from which the point...
std::vector< LoSNode > mLosNodes
LoSNodes in currently solved LoS while parsing event list.
Definition abstractviewshed.h:362
OGRPoint point(int row, int col)
Create OGRPoint with coordinates of given row and column in the raster.
Definition abstractviewshed.cpp:290
GDALDataType mDataType
Data type of output rasters.
Definition abstractviewshed.h:399
int mDefaultBand
Default band to read from rasters.
Definition abstractviewshed.h:405
std::shared_ptr< Point > mPoint
Important point for visibility calculation. Either viewpoint (normal viewshed) or target point (inver...
Definition abstractviewshed.h:387
int mMaxNumberOfTasks
Maximal number of LoS to solve, that can be stored in threadpool.
Definition abstractviewshed.h:420
BS::thread_pool mThreadPool
Threadpool that takes care of preparing individual threads with LoS to be solved.
Definition abstractviewshed.h:463
long long sizeOfOutputRasters()
Size in bytes that all output raster takes.
Definition abstractviewshed.h:325
double sortLastedSeconds()
Number of seconds the sort of event list lasted.
Definition abstractviewshed.h:283
std::mutex mTaskErrorMutex
Guards access to mTaskError, which can be written from worker threads.
Definition abstractviewshed.h:429
long long sizeOfOutputRaster()
Size in bytes that one output raster takes.
Definition abstractviewshed.h:304
double processingLastedSeconds()
Number of seconds the calculation of viewshed indexes lasted.
Definition abstractviewshed.h:297
std::shared_ptr< SingleBandRaster > resultRaster(int index=0)
Extract individual result raster.
Definition abstractviewshed.cpp:259
std::shared_ptr< ProjectedSquareCellRaster > mVisibilityMask
Input raster with visibility calculation mask.
Definition abstractviewshed.h:380
std::shared_ptr< ViewshedAlgorithms > mVisibilityIndices
Visibility indexes to calculate while calculating this viewshed. As AbstractViewshedAlgorithm.
Definition abstractviewshed.h:393
bool hasError()
Check if an error occurred during calculation (e.g. in one of the worker threads).
Definition abstractviewshed.h:219
std::vector< CellEvent > mCellEvents
Event list. All cell events for the input raster.
Definition abstractviewshed.h:368
long long sizeOfEvents()
Size of cell event list in bytes.
Definition abstractviewshed.h:255
bool saveVisibilityRaster(std::string filePath)
Save visibility raster to file.
Definition abstractviewshed.cpp:388
Class representing cell events for Van Kreveld's plane sweep algorithm. Stores cell position (row and...
Definition cellevent.h:17
Representation of single cell that creates a point on LoS.
Definition losnode.h:19
Class that represents LoS for classic Viewshed calculation.
Definition los.h:25