Skip to content

Commit 26dca38

Browse files
committed
Checkpoint.
1 parent 9f6dfd6 commit 26dca38

File tree

3 files changed

+66
-16
lines changed

3 files changed

+66
-16
lines changed

alg/viewshed/viewshed_executor.cpp

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ double ViewshedExecutor::calcHeightAdjFactor()
219219
/// dfZ Minimum observable height at cell.
220220
void ViewshedExecutor::setOutput(double &dfResult, double &dfCellVal,
221221
double dfZ)
222+
{
223+
if (!m_sdCalc)
224+
setOutputNormal(dfResult, dfCellVal, dfZ);
225+
else
226+
setOutputSd(dfResult, dfCellVal, dfZ);
227+
}
228+
229+
void ViewshedExecutor::setOutputNormal(double &dfResult, double &dfCellVal,
230+
double dfZ)
222231
{
223232
if (oOpts.outputMode != OutputMode::Normal)
224233
{
@@ -232,6 +241,25 @@ void ViewshedExecutor::setOutput(double &dfResult, double &dfCellVal,
232241
dfCellVal = std::max(dfCellVal, dfZ);
233242
}
234243

244+
void ViewshedExecutor::setOutputSd(double &dfResult, double &dfCellVal,
245+
double dfZ)
246+
{
247+
assert(oOpts.outputMode == OutputMode::Normal);
248+
if (dfResult == oOpts.invisibleVal)
249+
{
250+
double cellHeight = dfCellVal + oOpts.targetHeight;
251+
if (cellHeight > dfZ)
252+
dfResult = oOpts.maybeVisibleVal;
253+
}
254+
//ABELL
255+
/**
256+
if (lines.sd[pixel] <= 1)
257+
dfCellVal = std::max(dfZ, dfCellVal);
258+
else
259+
dfCellVal = dfZ;
260+
**/
261+
}
262+
235263
/// Read a line of raster data.
236264
///
237265
/// @param nLine Line number to read.
@@ -464,21 +492,27 @@ bool ViewshedExecutor::processFirstLine(Lines &lines)
464492
lines.result[m_nX] = oOpts.visibleVal;
465493
}
466494

467-
//ABELL
468-
if (!oCurExtent.containsY(m_nY))
469-
processFirstLineTopOrBottom(ll, lines);
470-
else
495+
auto process = [this, &ll, &lines](bool sdCalc)
471496
{
472-
CPLJobQueuePtr pQueue = m_pool.CreateJobQueue();
473-
pQueue->SubmitJob([&]() { processFirstLineLeft(ll, lines); });
474-
pQueue->SubmitJob([&]() { processFirstLineRight(ll, lines); });
475-
pQueue->WaitCompletion();
476-
}
477-
//ABELL
497+
m_sdCalc = sdCalc;
498+
if (!oCurExtent.containsY(m_nY))
499+
processFirstLineTopOrBottom(ll, lines);
500+
else
501+
{
502+
CPLJobQueuePtr pQueue = m_pool.CreateJobQueue();
503+
pQueue->SubmitJob([&]() { processFirstLineLeft(ll, lines); });
504+
pQueue->SubmitJob([&]() { processFirstLineRight(ll, lines); });
505+
pQueue->WaitCompletion();
506+
}
507+
sdCalc = false;
508+
};
509+
510+
process(false);
478511
if (sdMode())
479512
{
513+
lines.cur = std::move(lines.input);
514+
process(true);
480515
}
481-
//ABELL
482516

483517
if (oOpts.pitchMasking())
484518
applyPitchMask(lines.result, lines.pitchMask);
@@ -947,11 +981,22 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
947981
maskInitial(lines.result, nLine);
948982
}
949983

950-
// process left half then right half of line
951-
CPLJobQueuePtr pQueue = m_pool.CreateJobQueue();
952-
pQueue->SubmitJob([&]() { processLineLeft(nYOffset, ll, lines); });
953-
pQueue->SubmitJob([&]() { processLineRight(nYOffset, ll, lines); });
954-
pQueue->WaitCompletion();
984+
auto process = [this, nYOffset, &ll, &lines](bool sdCalc)
985+
{
986+
m_sdCalc = sdCalc;
987+
CPLJobQueuePtr pQueue = m_pool.CreateJobQueue();
988+
pQueue->SubmitJob([&]() { processLineLeft(nYOffset, ll, lines); });
989+
pQueue->SubmitJob([&]() { processLineRight(nYOffset, ll, lines); });
990+
pQueue->WaitCompletion();
991+
m_sdCalc = false;
992+
};
993+
994+
process(false);
995+
if (sdMode())
996+
{
997+
lines.cur = std::move(lines.input);
998+
process(true);
999+
}
9551000

9561001
if (oOpts.pitchMasking())
9571002
applyPitchMask(lines.result, lines.pitchMask);

alg/viewshed/viewshed_executor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ class ViewshedExecutor
110110
double m_lowTanPitch{std::numeric_limits<double>::quiet_NaN()};
111111
double m_highTanPitch{std::numeric_limits<double>::quiet_NaN()};
112112
double (*oZcalc)(int, int, double, double, double){};
113+
bool m_sdCalc = false;
113114

114115
double calcHeightAdjFactor();
115116
void setOutput(double &dfResult, double &dfCellVal, double dfZ);
117+
void setOutputNormal(double &dfResult, double &dfCellVal, double dfZ);
118+
void setOutputSd(double &dfResult, double &dfCellVal, double dfZ);
116119
bool readLine(int nLine, Lines &lines);
117120
bool writeLine(int nLine, std::vector<double> &vResult);
118121
bool processLine(int nLine, Lines &lines);

alg/viewshed/viewshed_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ struct Options
6060
Point observer{0, 0, 0}; //!< x, y, and z of the observer
6161
double visibleVal{255}; //!< raster output value for visible pixels.
6262
double invisibleVal{0}; //!< raster output value for non-visible pixels.
63+
double maybeVisibleVal{
64+
2}; //!< raster output for potentially visible pixels.
6365
double outOfRangeVal{
6466
0}; //!< raster output value for pixels outside of max distance.
6567
double nodataVal{-1}; //!< raster output value for pixels with no data

0 commit comments

Comments
 (0)