Skip to content

Commit 4bfb960

Browse files
committed
Save height-adjusted line for SD processing instead of raw line.
1 parent 257109a commit 4bfb960

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

alg/viewshed/viewshed_executor.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,10 @@ void ViewshedExecutor::setOutputNormal(Lines &lines, int pos, double dfZ)
234234
result += adjustment;
235235
}
236236
else
237-
result = (cur + oOpts.targetHeight < dfZ) ? oOpts.invisibleVal
238-
: oOpts.visibleVal;
237+
{
238+
double cellHeight = cur + oOpts.targetHeight;
239+
result = (cellHeight < dfZ) ? oOpts.invisibleVal : oOpts.visibleVal;
240+
}
239241
cur = std::max(cur, dfZ);
240242
}
241243

@@ -287,7 +289,6 @@ bool ViewshedExecutor::readLine(int nLine, Lines &lines)
287289

288290
if (sdMode())
289291
{
290-
lines.input = lines.cur;
291292
double nodata = m_sdBand.GetNoDataValue();
292293
CPLErr sdStatus = m_sdBand.RasterIO(
293294
GF_Read, oOutExtent.xStart, nLine, oOutExtent.xSize(), 1,
@@ -490,6 +491,11 @@ bool ViewshedExecutor::processFirstLine(Lines &lines)
490491
m_dfZObserver += lines.cur[m_nX];
491492

492493
LineLimits ll = adjustHeight(nYOffset, lines);
494+
495+
std::vector<double> savedInput;
496+
if (sdMode())
497+
savedInput = lines.cur;
498+
493499
if (oCurExtent.containsX(m_nX))
494500
{
495501
if (ll.leftMin != ll.rightMin)
@@ -517,7 +523,7 @@ bool ViewshedExecutor::processFirstLine(Lines &lines)
517523
lines.prev = lines.cur;
518524
if (sdMode())
519525
{
520-
lines.cur = std::move(lines.input);
526+
lines.cur = std::move(savedInput);
521527
process(true);
522528
lines.prevTmp = lines.cur;
523529
}
@@ -1013,6 +1019,10 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
10131019
// Adjust height of the read line.
10141020
LineLimits ll = adjustHeight(nYOffset, lines);
10151021

1022+
std::vector<double> savedLine;
1023+
if (sdMode())
1024+
savedLine = lines.cur;
1025+
10161026
auto process = [this, nYOffset, &ll, &lines](bool sdCalc)
10171027
{
10181028
CPLJobQueuePtr pQueue = m_pool.CreateJobQueue();
@@ -1043,7 +1053,7 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
10431053
{
10441054
lines.prev = std::move(lines.prevTmp);
10451055
lines.prevTmp = std::move(lines.cur);
1046-
lines.cur = std::move(lines.input);
1056+
lines.cur = std::move(savedLine);
10471057
// Handle initial position on the line.
10481058
if (!masked && oCurExtent.containsX(m_nX))
10491059
{

alg/viewshed/viewshed_executor.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,19 @@ struct Lines
3636
std::vector<double> result; //!< Result values for current line
3737
std::vector<double> prev; //!< Height values for previous line
3838
std::vector<double>
39-
pitchMask; //!< Height/indicator values for pitch masking.
40-
std::vector<double> input; //!< Copy of input data when in SD mode.
39+
pitchMask; //!< Height/indicator values for pitch masking.
4140
std::vector<double> prevTmp; //!< Saved prev values when in SD mode.
4241
std::vector<double> sd; //!< SD mask.
4342

4443
/// Constructor
45-
Lines() : cur(), result(), prev(), pitchMask(), input(), prevTmp(), sd()
44+
Lines() : cur(), result(), prev(), pitchMask(), prevTmp(), sd()
4645
{
4746
}
4847

4948
/// Constructor that initializes to line length
5049
/// \param lineLen Line length.
5150
explicit Lines(size_t lineLen)
52-
: cur(lineLen), result(lineLen), prev(), pitchMask(), input(),
53-
prevTmp(), sd()
51+
: cur(lineLen), result(lineLen), prev(), pitchMask(), prevTmp(), sd()
5452
{
5553
}
5654
};

0 commit comments

Comments
 (0)