Skip to content

Commit 4b02f43

Browse files
committed
Checkpoint.
1 parent 26dca38 commit 4b02f43

File tree

2 files changed

+56
-70
lines changed

2 files changed

+56
-70
lines changed

alg/viewshed/viewshed_executor.cpp

Lines changed: 51 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -217,47 +217,48 @@ double ViewshedExecutor::calcHeightAdjFactor()
217217
/// dfResult Reference to the result cell
218218
/// dfCellVal Reference to the current cell height. Replace with observable height.
219219
/// dfZ Minimum observable height at cell.
220-
void ViewshedExecutor::setOutput(double &dfResult, double &dfCellVal,
221-
double dfZ)
220+
void ViewshedExecutor::setOutput(Lines &lines, int pos, double dfZ)
222221
{
223222
if (!m_sdCalc)
224-
setOutputNormal(dfResult, dfCellVal, dfZ);
223+
setOutputNormal(lines, pos, dfZ);
225224
else
226-
setOutputSd(dfResult, dfCellVal, dfZ);
225+
setOutputSd(lines, pos, dfZ);
227226
}
228227

229-
void ViewshedExecutor::setOutputNormal(double &dfResult, double &dfCellVal,
230-
double dfZ)
228+
void ViewshedExecutor::setOutputNormal(Lines &lines, int pos, double dfZ)
231229
{
230+
double &cur = lines.cur[pos];
231+
double &result = lines.result[pos];
232+
232233
if (oOpts.outputMode != OutputMode::Normal)
233234
{
234-
double adjustment = dfZ - dfCellVal;
235+
double adjustment = dfZ - cur;
235236
if (adjustment > 0)
236-
dfResult += adjustment;
237+
result += adjustment;
237238
}
238239
else
239-
dfResult = (dfCellVal + oOpts.targetHeight < dfZ) ? oOpts.invisibleVal
240-
: oOpts.visibleVal;
241-
dfCellVal = std::max(dfCellVal, dfZ);
240+
result = (cur + oOpts.targetHeight < dfZ) ? oOpts.invisibleVal
241+
: oOpts.visibleVal;
242+
cur = std::max(cur, dfZ);
242243
}
243244

244-
void ViewshedExecutor::setOutputSd(double &dfResult, double &dfCellVal,
245-
double dfZ)
245+
void ViewshedExecutor::setOutputSd(Lines &lines, int pos, double dfZ)
246246
{
247+
double &cur = lines.cur[pos];
248+
double &result = lines.result[pos];
249+
double &sd = lines.sd[pos];
250+
247251
assert(oOpts.outputMode == OutputMode::Normal);
248-
if (dfResult == oOpts.invisibleVal)
252+
if (result == oOpts.invisibleVal)
249253
{
250-
double cellHeight = dfCellVal + oOpts.targetHeight;
254+
double cellHeight = cur + oOpts.targetHeight;
251255
if (cellHeight > dfZ)
252-
dfResult = oOpts.maybeVisibleVal;
256+
result = oOpts.maybeVisibleVal;
253257
}
254-
//ABELL
255-
/**
256-
if (lines.sd[pixel] <= 1)
257-
dfCellVal = std::max(dfZ, dfCellVal);
258+
if (sd <= 1)
259+
cur = std::max(dfZ, cur);
258260
else
259-
dfCellVal = dfZ;
260-
**/
261+
cur = dfZ;
261262
}
262263

263264
/// Read a line of raster data.
@@ -548,14 +549,12 @@ void ViewshedExecutor::applyPitchMask(std::vector<double> &vResult,
548549
void ViewshedExecutor::processFirstLineTopOrBottom(const LineLimits &ll,
549550
Lines &lines)
550551
{
551-
double *pResult = lines.result.data() + ll.left;
552-
double *pThis = lines.cur.data() + ll.left;
553-
for (int iPixel = ll.left; iPixel < ll.right; ++iPixel, ++pResult, pThis++)
552+
for (int iPixel = ll.left; iPixel < ll.right; ++iPixel)
554553
{
555554
if (oOpts.outputMode == OutputMode::Normal)
556-
*pResult = oOpts.visibleVal;
555+
lines.result[iPixel] = oOpts.visibleVal;
557556
else
558-
setOutput(*pResult, *pThis, *pThis);
557+
setOutput(lines, iPixel, lines.cur[iPixel]);
559558
}
560559

561560
std::fill(lines.result.begin(), lines.result.begin() + ll.left,
@@ -582,26 +581,23 @@ void ViewshedExecutor::processFirstLineLeft(const LineLimits &ll, Lines &lines)
582581

583582
iStart = oCurExtent.clampX(iStart);
584583

585-
double *pThis = lines.cur.data() + iStart;
586-
587584
// If the start cell is next to the observer, just mark it visible.
588585
if (iStart + 1 == m_nX || iStart + 1 == oCurExtent.xStop)
589586
{
590-
double dfZ = *pThis;
587+
double dfZ = lines.cur[iStart];
591588
if (oOpts.outputMode == OutputMode::Normal)
592589
lines.result[iStart] = oOpts.visibleVal;
593590
else
594-
setOutput(lines.result[iStart], *pThis, dfZ);
591+
setOutput(lines, iStart, dfZ);
595592
iStart--;
596-
pThis--;
597593
}
598594

599595
// Go from the observer to the left, calculating Z as we go.
600-
for (int iPixel = iStart; iPixel > iEnd; iPixel--, pThis--)
596+
for (int iPixel = iStart; iPixel > iEnd; iPixel--)
601597
{
602598
int nXOffset = std::abs(iPixel - m_nX);
603-
double dfZ = CalcHeightLine(nXOffset, *(pThis + 1));
604-
setOutput(lines.result[iPixel], *pThis, dfZ);
599+
double dfZ = CalcHeightLine(nXOffset, lines.cur[iPixel + 1]);
600+
setOutput(lines, iPixel, dfZ);
605601
}
606602

607603
maskLineLeft(lines.result, ll, m_nY);
@@ -797,26 +793,23 @@ void ViewshedExecutor::processFirstLineRight(const LineLimits &ll, Lines &lines)
797793

798794
iStart = oCurExtent.clampX(iStart);
799795

800-
double *pThis = lines.cur.data() + iStart;
801-
802796
// If the start cell is next to the observer, just mark it visible.
803797
if (iStart - 1 == m_nX || iStart == oCurExtent.xStart)
804798
{
805-
double dfZ = *pThis;
799+
double dfZ = lines.cur[iStart];
806800
if (oOpts.outputMode == OutputMode::Normal)
807801
lines.result[iStart] = oOpts.visibleVal;
808802
else
809-
setOutput(lines.result[iStart], *pThis, dfZ);
803+
setOutput(lines, iStart, dfZ);
810804
iStart++;
811-
pThis++;
812805
}
813806

814807
// Go from the observer to the right, calculating Z as we go.
815-
for (int iPixel = iStart; iPixel < iEnd; iPixel++, pThis++)
808+
for (int iPixel = iStart; iPixel < iEnd; iPixel++)
816809
{
817810
int nXOffset = std::abs(iPixel - m_nX);
818-
double dfZ = CalcHeightLine(nXOffset, *(pThis - 1));
819-
setOutput(lines.result[iPixel], *pThis, dfZ);
811+
double dfZ = CalcHeightLine(nXOffset, lines.cur[iPixel - 1]);
812+
setOutput(lines, iPixel, dfZ);
820813
}
821814

822815
maskLineRight(lines.result, ll, m_nY);
@@ -842,36 +835,31 @@ void ViewshedExecutor::processLineLeft(int nYOffset, LineLimits &ll,
842835
}
843836
iStart = oCurExtent.clampX(iStart);
844837

845-
double *pThis = lines.cur.data() + iStart;
846-
double *pLast = lines.prev.data() + iStart;
847-
848838
// If the observer is to the right of the raster, mark the first cell to the left as
849839
// visible. This may mark an out-of-range cell with a value, but this will be fixed
850840
// with the out of range assignment at the end.
851-
852841
if (iStart == oCurExtent.xStop - 1)
853842
{
854843
if (oOpts.outputMode == OutputMode::Normal)
855844
lines.result[iStart] = oOpts.visibleVal;
856845
else
857-
setOutput(lines.result[iStart], *pThis, *pThis);
846+
setOutput(lines, iStart, lines.cur[iStart]);
858847
iStart--;
859-
pThis--;
860-
pLast--;
861848
}
862849

863850
// Go from the observer to the left, calculating Z as we go.
864851
nYOffset = std::abs(nYOffset);
865-
for (int iPixel = iStart; iPixel > iEnd; iPixel--, pThis--, pLast--)
852+
for (int iPixel = iStart; iPixel > iEnd; iPixel--)
866853
{
867854
int nXOffset = std::abs(iPixel - m_nX);
868855
double dfZ;
869856
if (nXOffset == nYOffset)
870-
dfZ = CalcHeightLine(nYOffset, *pThis, *(pLast + 1));
857+
dfZ = CalcHeightLine(nYOffset, lines.cur[iPixel],
858+
lines.prev[iPixel + 1]);
871859
else
872-
dfZ =
873-
oZcalc(nXOffset, nYOffset, *(pThis + 1), *pLast, *(pLast + 1));
874-
setOutput(lines.result[iPixel], *pThis, dfZ);
860+
dfZ = oZcalc(nXOffset, nYOffset, lines.cur[iPixel + 1],
861+
lines.prev[iPixel], lines.prev[iPixel + 1]);
862+
setOutput(lines, iPixel, dfZ);
875863
}
876864

877865
maskLineLeft(lines.result, ll, nLine);
@@ -897,9 +885,6 @@ void ViewshedExecutor::processLineRight(int nYOffset, LineLimits &ll,
897885
}
898886
iStart = oCurExtent.clampX(iStart);
899887

900-
double *pThis = lines.cur.data() + iStart;
901-
double *pLast = lines.prev.data() + iStart;
902-
903888
// If the observer is to the left of the raster, mark the first cell to the right as
904889
// visible. This may mark an out-of-range cell with a value, but this will be fixed
905890
// with the out of range assignment at the end.
@@ -908,24 +893,23 @@ void ViewshedExecutor::processLineRight(int nYOffset, LineLimits &ll,
908893
if (oOpts.outputMode == OutputMode::Normal)
909894
lines.result[iStart] = oOpts.visibleVal;
910895
else
911-
setOutput(lines.result[0], *pThis, *pThis);
896+
setOutput(lines, 0, lines.cur[0]);
912897
iStart++;
913-
pThis++;
914-
pLast++;
915898
}
916899

917900
// Go from the observer to the right, calculating Z as we go.
918901
nYOffset = std::abs(nYOffset);
919-
for (int iPixel = iStart; iPixel < iEnd; iPixel++, pThis++, pLast++)
902+
for (int iPixel = iStart; iPixel < iEnd; iPixel++)
920903
{
921904
int nXOffset = std::abs(iPixel - m_nX);
922905
double dfZ;
923906
if (nXOffset == nYOffset)
924-
dfZ = CalcHeightLine(nYOffset, *pThis, *(pLast - 1));
907+
dfZ = CalcHeightLine(nYOffset, lines.cur[iPixel],
908+
lines.prev[iPixel - 1]);
925909
else
926-
dfZ =
927-
oZcalc(nXOffset, nYOffset, *(pThis - 1), *pLast, *(pLast - 1));
928-
setOutput(lines.result[iPixel], *pThis, dfZ);
910+
dfZ = oZcalc(nXOffset, nYOffset, lines.cur[iPixel - 1],
911+
lines.prev[iPixel], lines.prev[iPixel - 1]);
912+
setOutput(lines, iPixel, dfZ);
929913
}
930914

931915
maskLineRight(lines.result, ll, nLine);
@@ -973,7 +957,7 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
973957
{
974958
double dfZ = CalcHeightLine(std::abs(nYOffset), lines.cur[m_nX],
975959
lines.prev[m_nX]);
976-
setOutput(lines.result[m_nX], lines.cur[m_nX], dfZ);
960+
setOutput(lines, m_nX, dfZ);
977961
}
978962
else
979963
lines.result[m_nX] = oOpts.outOfRangeVal;

alg/viewshed/viewshed_executor.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ class ViewshedExecutor
113113
bool m_sdCalc = false;
114114

115115
double calcHeightAdjFactor();
116-
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);
116+
117+
void setOutput(Lines &lines, int pos, double dfZ);
118+
void setOutputNormal(Lines &lines, int pos, double dfZ);
119+
void setOutputSd(Lines &lines, int pos, double dfZ);
120+
119121
bool readLine(int nLine, Lines &lines);
120122
bool writeLine(int nLine, std::vector<double> &vResult);
121123
bool processLine(int nLine, Lines &lines);

0 commit comments

Comments
 (0)