@@ -212,19 +212,6 @@ double ViewshedExecutor::calcHeightAdjFactor()
212212 return 0 ;
213213}
214214
215- // / Set the output Z value depending on the observable height and computation mode.
216- // /
217- // / dfResult Reference to the result cell
218- // / dfCellVal Reference to the current cell height. Replace with observable height.
219- // / dfZ Minimum observable height at cell.
220- void ViewshedExecutor::setOutput (Lines &lines, int pos, double dfZ)
221- {
222- if (!m_sdCalc)
223- setOutputNormal (lines, pos, dfZ);
224- else
225- setOutputSd (lines, pos, dfZ);
226- }
227-
228215// / Set the output Z value depending on the observable height and computation mode
229216// / in normal mode.
230217// /
@@ -506,28 +493,28 @@ bool ViewshedExecutor::processFirstLine(Lines &lines)
506493 lines.result [m_nX] = oOpts.visibleVal ;
507494 }
508495
509- auto process = [this , &ll, &lines]()
496+ auto process = [this , &ll, &lines](bool sdCalc )
510497 {
511498 if (!oCurExtent.containsY (m_nY))
512499 processFirstLineTopOrBottom (ll, lines);
513500 else
514501 {
515502 CPLJobQueuePtr pQueue = m_pool.CreateJobQueue ();
516- pQueue->SubmitJob ([&]() { processFirstLineLeft (ll, lines); });
517- pQueue->SubmitJob ([&]() { processFirstLineRight (ll, lines); });
503+ pQueue->SubmitJob ([&]()
504+ { processFirstLineLeft (ll, lines, sdCalc); });
505+ pQueue->SubmitJob ([&]()
506+ { processFirstLineRight (ll, lines, sdCalc); });
518507 pQueue->WaitCompletion ();
519508 }
520509 };
521510
522- process ();
511+ process (false );
523512 lines.prev = lines.cur ;
524513 if (sdMode ())
525514 {
526- m_sdCalc = true ;
527515 lines.cur = std::move (lines.input );
528- process ();
516+ process (true );
529517 lines.prevTmp = lines.cur ;
530- m_sdCalc = false ;
531518 }
532519
533520 if (oOpts.pitchMasking ())
@@ -569,7 +556,7 @@ void ViewshedExecutor::processFirstLineTopOrBottom(const LineLimits &ll,
569556 if (oOpts.outputMode == OutputMode::Normal)
570557 lines.result [iPixel] = oOpts.visibleVal ;
571558 else
572- setOutput (lines, iPixel, lines.cur [iPixel]);
559+ setOutputNormal (lines, iPixel, lines.cur [iPixel]);
573560 }
574561
575562 std::fill (lines.result .begin (), lines.result .begin () + ll.left ,
@@ -580,9 +567,11 @@ void ViewshedExecutor::processFirstLineTopOrBottom(const LineLimits &ll,
580567
581568// / Process the part of the first line to the left of the observer.
582569// /
583- // / @param ll Line limits for masking.
584- // / @param lines Raster lines to process.
585- void ViewshedExecutor::processFirstLineLeft (const LineLimits &ll, Lines &lines)
570+ // / @param ll Line limits for masking.
571+ // / @param sdCalc True when doing SD calculation.
572+ // / @param lines Raster lines to process.
573+ void ViewshedExecutor::processFirstLineLeft (const LineLimits &ll, Lines &lines,
574+ bool sdCalc)
586575{
587576 int iEnd = ll.left - 1 ;
588577 int iStart = m_nX - 1 ; // One left of the observer.
@@ -603,12 +592,13 @@ void ViewshedExecutor::processFirstLineLeft(const LineLimits &ll, Lines &lines)
603592 if (oOpts.outputMode == OutputMode::Normal)
604593 {
605594 lines.result [iStart] = oOpts.visibleVal ;
606- if (m_sdCalc )
595+ if (sdCalc )
607596 if (lines.sd [iStart] > 1 )
608- lines.cur [iStart] = m_dfZObserver;
597+ lines.cur [iStart] =
598+ m_dfZObserver; // Should this be a minimum value?
609599 }
610600 else
611- setOutput (lines, iStart, dfZ);
601+ setOutputNormal (lines, iStart, dfZ);
612602 iStart--;
613603 }
614604
@@ -617,7 +607,10 @@ void ViewshedExecutor::processFirstLineLeft(const LineLimits &ll, Lines &lines)
617607 {
618608 int nXOffset = std::abs (iPixel - m_nX);
619609 double dfZ = CalcHeightLine (nXOffset, lines.cur [iPixel + 1 ]);
620- setOutput (lines, iPixel, dfZ);
610+ if (!sdCalc)
611+ setOutputNormal (lines, iPixel, dfZ);
612+ else
613+ setOutputSd (lines, iPixel, dfZ);
621614 }
622615
623616 maskLineLeft (lines.result , ll, m_nY);
@@ -798,8 +791,10 @@ void ViewshedExecutor::maskLineRight(std::vector<double> &vResult,
798791// / Process the part of the first line to the right of the observer.
799792// /
800793// / @param ll Line limits
794+ // / @param sdCalc True when doing SD calcuation.
801795// / @param lines Raster lines to process.
802- void ViewshedExecutor::processFirstLineRight (const LineLimits &ll, Lines &lines)
796+ void ViewshedExecutor::processFirstLineRight (const LineLimits &ll, Lines &lines,
797+ bool sdCalc)
803798{
804799 int iStart = m_nX + 1 ;
805800 int iEnd = ll.right ;
@@ -820,12 +815,13 @@ void ViewshedExecutor::processFirstLineRight(const LineLimits &ll, Lines &lines)
820815 if (oOpts.outputMode == OutputMode::Normal)
821816 {
822817 lines.result [iStart] = oOpts.visibleVal ;
823- if (m_sdCalc )
818+ if (sdCalc )
824819 if (lines.sd [iStart] > 1 )
825- lines.cur [iStart] = m_dfZObserver;
820+ lines.cur [iStart] =
821+ m_dfZObserver; // Use some minimum value instead?
826822 }
827823 else
828- setOutput (lines, iStart, dfZ);
824+ setOutputNormal (lines, iStart, dfZ);
829825 iStart++;
830826 }
831827
@@ -834,7 +830,10 @@ void ViewshedExecutor::processFirstLineRight(const LineLimits &ll, Lines &lines)
834830 {
835831 int nXOffset = std::abs (iPixel - m_nX);
836832 double dfZ = CalcHeightLine (nXOffset, lines.cur [iPixel - 1 ]);
837- setOutput (lines, iPixel, dfZ);
833+ if (!sdCalc)
834+ setOutputNormal (lines, iPixel, dfZ);
835+ else
836+ setOutputSd (lines, iPixel, dfZ);
838837 }
839838
840839 maskLineRight (lines.result , ll, m_nY);
@@ -845,8 +844,9 @@ void ViewshedExecutor::processFirstLineRight(const LineLimits &ll, Lines &lines)
845844// / @param nYOffset Offset of the line being processed from the observer
846845// / @param ll Line limits
847846// / @param lines Raster lines to process.
847+ // / @param sdCalc SD calculation indicator.
848848void ViewshedExecutor::processLineLeft (int nYOffset, LineLimits &ll,
849- Lines &lines)
849+ Lines &lines, bool sdCalc )
850850{
851851 int iStart = m_nX - 1 ;
852852 int iEnd = ll.left - 1 ;
@@ -868,7 +868,7 @@ void ViewshedExecutor::processLineLeft(int nYOffset, LineLimits &ll,
868868 if (oOpts.outputMode == OutputMode::Normal)
869869 lines.result [iStart] = oOpts.visibleVal ;
870870 else
871- setOutput (lines, iStart, lines.cur [iStart]);
871+ setOutputNormal (lines, iStart, lines.cur [iStart]);
872872 iStart--;
873873 }
874874
@@ -884,7 +884,10 @@ void ViewshedExecutor::processLineLeft(int nYOffset, LineLimits &ll,
884884 else
885885 dfZ = oZcalc (nXOffset, nYOffset, lines.cur [iPixel + 1 ],
886886 lines.prev [iPixel], lines.prev [iPixel + 1 ]);
887- setOutput (lines, iPixel, dfZ);
887+ if (!sdCalc)
888+ setOutputNormal (lines, iPixel, dfZ);
889+ else
890+ setOutputSd (lines, iPixel, dfZ);
888891 }
889892
890893 maskLineLeft (lines.result , ll, nLine);
@@ -895,8 +898,9 @@ void ViewshedExecutor::processLineLeft(int nYOffset, LineLimits &ll,
895898// / @param nYOffset Offset of the line being processed from the observer
896899// / @param ll Line limits
897900// / @param lines Raster lines to process.
901+ // / @param sdCalc SD calculation indicator.
898902void ViewshedExecutor::processLineRight (int nYOffset, LineLimits &ll,
899- Lines &lines)
903+ Lines &lines, bool sdCalc )
900904{
901905 int iStart = m_nX + 1 ;
902906 int iEnd = ll.right ;
@@ -918,7 +922,7 @@ void ViewshedExecutor::processLineRight(int nYOffset, LineLimits &ll,
918922 if (oOpts.outputMode == OutputMode::Normal)
919923 lines.result [iStart] = oOpts.visibleVal ;
920924 else
921- setOutput (lines, 0 , lines.cur [0 ]);
925+ setOutputNormal (lines, 0 , lines.cur [0 ]);
922926 iStart++;
923927 }
924928
@@ -930,7 +934,7 @@ void ViewshedExecutor::processLineRight(int nYOffset, LineLimits &ll,
930934 double dfZ;
931935 if (nXOffset == nYOffset)
932936 {
933- if (m_sdCalc && nXOffset == 1 )
937+ if (sdCalc && nXOffset == 1 )
934938 {
935939 lines.result [iPixel] = oOpts.visibleVal ;
936940 if (lines.sd [iPixel] > 1 )
@@ -943,7 +947,10 @@ void ViewshedExecutor::processLineRight(int nYOffset, LineLimits &ll,
943947 else
944948 dfZ = oZcalc (nXOffset, nYOffset, lines.cur [iPixel - 1 ],
945949 lines.prev [iPixel], lines.prev [iPixel - 1 ]);
946- setOutput (lines, iPixel, dfZ);
950+ if (!sdCalc)
951+ setOutputNormal (lines, iPixel, dfZ);
952+ else
953+ setOutputSd (lines, iPixel, dfZ);
947954 }
948955
949956 maskLineRight (lines.result , ll, nLine);
@@ -1001,11 +1008,13 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
10011008 // Adjust height of the read line.
10021009 LineLimits ll = adjustHeight (nYOffset, lines);
10031010
1004- auto process = [this , nYOffset, &ll, &lines]()
1011+ auto process = [this , nYOffset, &ll, &lines](bool sdCalc )
10051012 {
10061013 CPLJobQueuePtr pQueue = m_pool.CreateJobQueue ();
1007- pQueue->SubmitJob ([&]() { processLineLeft (nYOffset, ll, lines); });
1008- pQueue->SubmitJob ([&]() { processLineRight (nYOffset, ll, lines); });
1014+ pQueue->SubmitJob ([&]()
1015+ { processLineLeft (nYOffset, ll, lines, sdCalc); });
1016+ pQueue->SubmitJob ([&]()
1017+ { processLineRight (nYOffset, ll, lines, sdCalc); });
10091018 pQueue->WaitCompletion ();
10101019 };
10111020
@@ -1018,17 +1027,15 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
10181027 {
10191028 double dfZ = CalcHeightLine (std::abs (nYOffset), lines.cur [m_nX],
10201029 lines.prev [m_nX]);
1021- setOutput (lines, m_nX, dfZ);
1030+ setOutputNormal (lines, m_nX, dfZ);
10221031 }
10231032 }
10241033
1025- process ();
1034+ process (false );
10261035
10271036 // Process SD mode
10281037 if (sdMode ())
10291038 {
1030- m_sdCalc = true ;
1031-
10321039 lines.prev = std::move (lines.prevTmp );
10331040 lines.prevTmp = std::move (lines.cur );
10341041 lines.cur = std::move (lines.input );
@@ -1046,13 +1053,12 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
10461053
10471054 double dfZ = CalcHeightLine (std::abs (nYOffset), lines.cur [m_nX],
10481055 lines.prev [m_nX]);
1049- setOutput (lines, m_nX, dfZ);
1056+ setOutputSd (lines, m_nX, dfZ);
10501057 }
10511058 }
1052- process ();
1059+ process (true );
10531060 lines.prev = std::move (lines.prevTmp );
10541061 lines.prevTmp = lines.cur ;
1055- m_sdCalc = false ;
10561062 }
10571063 else
10581064 lines.prev = lines.cur ;
0 commit comments