@@ -245,6 +245,7 @@ bool ViewshedExecutor::writeLine(int nLine, std::vector<double> &vResult)
245245// / @return Processing limits of the line based on min/max distance.
246246LineLimits ViewshedExecutor::adjustHeight (int nYOffset,
247247 std::vector<double > &vThisLineVal,
248+ const std::vector<double > &vResult,
248249 std::vector<double > &vPitchMaskVal)
249250{
250251 LineLimits ll (0 , m_nX + 1 , m_nX + 1 , oCurExtent.xSize ());
@@ -298,6 +299,7 @@ LineLimits ViewshedExecutor::adjustHeight(int nYOffset,
298299 *pdfHeight -= m_dfHeightAdjFactor * dfR2 + m_dfZObserver;
299300 if (oOpts.pitchMasking ())
300301 calcPitchMask (*pdfHeight, std::sqrt (dfR2),
302+ vResult[m_nX + nXOffset],
301303 vPitchMaskVal[m_nX + nXOffset]);
302304 }
303305
@@ -322,6 +324,7 @@ LineLimits ViewshedExecutor::adjustHeight(int nYOffset,
322324 *pdfHeight -= m_dfHeightAdjFactor * dfR2 + m_dfZObserver;
323325 if (oOpts.pitchMasking ())
324326 calcPitchMask (*pdfHeight, std::sqrt (dfR2),
327+ vResult[m_nX + nXOffset],
325328 vPitchMaskVal[m_nX + nXOffset]);
326329 }
327330 }
@@ -339,25 +342,26 @@ LineLimits ViewshedExecutor::adjustHeight(int nYOffset,
339342 return ll;
340343}
341344
342- void ViewshedExecutor::calcPitchMask (double dfZ, double dfDist, double &maskVal)
345+ void ViewshedExecutor::calcPitchMask (double dfZ, double dfDist, double dfResult,
346+ double &maskVal)
343347{
344348 if (oOpts.lowPitchMasking ())
345349 {
346350 double dfZMask = dfDist * m_lowTanPitch;
347351 double adjustment = dfZMask - dfZ;
348352 if (adjustment > 0 )
349353 {
350- maskVal =
351- (oOpts. outputMode == OutputMode::Normal ? oOpts. outOfRangeVal
352- : adjustment);
354+ maskVal = (oOpts. outputMode == OutputMode::Normal
355+ ? std::numeric_limits< double >:: infinity ()
356+ : adjustment + dfResult );
353357 return ;
354358 }
355359 }
356360 if (oOpts.highPitchMasking ())
357361 {
358362 double dfZMask = dfDist * m_highTanPitch;
359363 if (dfZ > dfZMask)
360- maskVal = oOpts. outOfRangeVal ;
364+ maskVal = std::numeric_limits< double >:: infinity () ;
361365 }
362366}
363367
@@ -396,7 +400,8 @@ bool ViewshedExecutor::processFirstLine(std::vector<double> &vLastLineVal)
396400 if (oOpts.outputMode == OutputMode::DEM)
397401 vResult = vThisLineVal;
398402
399- LineLimits ll = adjustHeight (nYOffset, vThisLineVal, vPitchMaskVal);
403+ LineLimits ll =
404+ adjustHeight (nYOffset, vThisLineVal, vResult, vPitchMaskVal);
400405 if (oCurExtent.containsX (m_nX) && ll.leftMin != ll.rightMin )
401406 vResult[m_nX] = oOpts.outOfRangeVal ;
402407
@@ -430,10 +435,10 @@ void ViewshedExecutor::applyPitchMask(std::vector<double> &vResult,
430435 {
431436 if (std::isnan (vPitchMaskVal[i]))
432437 continue ;
433- if (vPitchMaskVal[i] == oOpts. outOfRangeVal )
438+ if (std::isinf ( vPitchMaskVal[i]) )
434439 vResult[i] = oOpts.outOfRangeVal ;
435440 else
436- vResult[i] + = vPitchMaskVal[i];
441+ vResult[i] = vPitchMaskVal[i];
437442 }
438443}
439444
@@ -880,7 +885,8 @@ bool ViewshedExecutor::processLine(int nLine, std::vector<double> &vLastLineVal)
880885 vResult = vThisLineVal;
881886
882887 // Adjust height of the read line.
883- LineLimits ll = adjustHeight (nYOffset, vThisLineVal, vPitchMaskVal);
888+ LineLimits ll =
889+ adjustHeight (nYOffset, vThisLineVal, vResult, vPitchMaskVal);
884890
885891 // Handle the initial position on the line.
886892 if (oCurExtent.containsX (m_nX))
0 commit comments