Skip to content

Commit 1892d9c

Browse files
committed
Add doc.
1 parent 0df8251 commit 1892d9c

File tree

3 files changed

+111
-12
lines changed

3 files changed

+111
-12
lines changed

alg/viewshed/util.cpp

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace viewshed
2020

2121
/// Normalize a masking angle. Change from clockwise with 0 north (up) to counterclockwise
2222
/// with 0 to the east (right) and change to radians.
23+
///
24+
// @param maskAngle Masking angle in degrees.
2325
double normalizeAngle(double maskAngle)
2426
{
2527
maskAngle = 90 - maskAngle;
@@ -30,7 +32,12 @@ double normalizeAngle(double maskAngle)
3032

3133
/// Compute the X intersect position on the line Y = y with a ray extending
3234
/// from (nX, nY) along `angle`.
33-
///ABELL doc args
35+
///
36+
/// @param angle Angle in radians, standard arrangement.
37+
/// @param nX X coordinate of ray endpoint.
38+
/// @param nY Y coordinte of ray endpoint.
39+
/// @param y Horizontal line where Y = y.
40+
/// @return X intersect or NaN
3441
double horizontalIntersect(double angle, int nX, int nY, int y)
3542
{
3643
double x = std::numeric_limits<double>::quiet_NaN();
@@ -54,6 +61,14 @@ double horizontalIntersect(double angle, int nX, int nY, int y)
5461
return x;
5562
}
5663

64+
/// Compute the X intersect position on the line Y = y with a ray extending
65+
/// from (nX, nY) along `angle`.
66+
///
67+
/// @param angle Angle in radians, standard arrangement.
68+
/// @param nX X coordinate of ray endpoint.
69+
/// @param nY Y coordinte of ray endpoint.
70+
/// @param y Horizontal line where Y = y.
71+
/// @return Rounded X intersection of the sentinel INVALID_ISECT
5772
int hIntersect(double angle, int nX, int nY, int y)
5873
{
5974
double x = horizontalIntersect(angle, nX, nY, y);
@@ -62,6 +77,14 @@ int hIntersect(double angle, int nX, int nY, int y)
6277
return static_cast<int>(std::round(x));
6378
}
6479

80+
/// Compute the X intersect on one of the horizontal edges of a window
81+
/// with a ray extending from (nX, nY) along `angle`, clamped the the extent of a window.
82+
///
83+
/// @param angle Angle in radians, standard arrangement.
84+
/// @param nX X coordinate of ray endpoint.
85+
/// @param nY Y coordinte of ray endpoint.
86+
/// @param win Window to intersect.
87+
/// @return X intersect, clamped to the window extent.
6588
int hIntersect(double angle, int nX, int nY, const Window &win)
6689
{
6790
if (ARE_REAL_EQUAL(angle, M_PI))
@@ -74,9 +97,14 @@ int hIntersect(double angle, int nX, int nY, const Window &win)
7497
return std::clamp(static_cast<int>(std::round(x)), win.xStart, win.xStop);
7598
}
7699

77-
/// Compute the Y intersect position on the line X = x with a ray extending
100+
/// Compute the X intersect position on the line Y = y with a ray extending
78101
/// from (nX, nY) along `angle`.
79-
///ABELL doc args
102+
///
103+
/// @param angle Angle in radians, standard arrangement.
104+
/// @param nX X coordinate of ray endpoint.
105+
/// @param nY Y coordinte of ray endpoint.
106+
/// @param y Vertical line where X = x.
107+
/// @return Y intersect or NaN
80108
double verticalIntersect(double angle, int nX, int nY, int x)
81109
{
82110
double y = std::numeric_limits<double>::quiet_NaN();
@@ -100,6 +128,14 @@ double verticalIntersect(double angle, int nX, int nY, int x)
100128
return y;
101129
}
102130

131+
/// Compute the X intersect position on the line Y = y with a ray extending
132+
/// from (nX, nY) along `angle`.
133+
///
134+
/// @param angle Angle in radians, standard arrangement.
135+
/// @param nX X coordinate of ray endpoint.
136+
/// @param nY Y coordinte of ray endpoint.
137+
/// @param y Horizontal line where X = x.
138+
/// @return Rounded Y intersection of the sentinel INVALID_ISECT
103139
int vIntersect(double angle, int nX, int nY, int x)
104140
{
105141
double y = verticalIntersect(angle, nX, nY, x);
@@ -108,6 +144,15 @@ int vIntersect(double angle, int nX, int nY, int x)
108144
return static_cast<int>(std::round(y));
109145
}
110146

147+
/// Compute the Y intersect on one of the vertical edges of a window
148+
/// with a ray extending from (nX, nY) along `angle`, clamped the the extent
149+
/// of the window.
150+
///
151+
/// @param angle Angle in radians, standard arrangement.
152+
/// @param nX X coordinate of ray endpoint.
153+
/// @param nY Y coordinte of ray endpoint.
154+
/// @param win Window to intersect.
155+
/// @return y intersect, clamped to the window extent.
111156
int vIntersect(double angle, int nX, int nY, const Window &win)
112157
{
113158
if (ARE_REAL_EQUAL(angle, M_PI / 2))
@@ -120,8 +165,12 @@ int vIntersect(double angle, int nX, int nY, const Window &win)
120165
return std::clamp(static_cast<int>(std::round(y)), win.yStart, win.yStop);
121166
}
122167

123-
// Determine if ray is in the slice between two rays starting at `start` and
124-
// going clockwise to `end` (inclusive). [start, end]
168+
/// Determine if ray is in the slice between two rays starting at `start` and
169+
/// going clockwise to `end` (inclusive). [start, end]
170+
/// @param start Start angle.
171+
/// @param end End angle.
172+
/// @param test Test angle.
173+
/// @return Whether `test` lies in the slice [start, end]
125174
bool rayBetween(double start, double end, double test)
126175
{
127176
// Our angles go counterclockwise, so swap start and end

alg/viewshed/viewshed.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,26 @@ bool getTransforms(GDALRasterBand &band, double *pFwdTransform,
217217
return true;
218218
}
219219

220+
/// Shrink the extent of a window to just cover the slice defined by rays from
221+
/// (nX, nY) and [startAngle, endAngle]
222+
///
223+
/// @param oOutExtent Window to modify
224+
/// @param nX X coordinate of ray endpoint.
225+
/// @param nY Y coordinate of ray endpoint.
226+
/// @param startAngle Start angle of slice (standard mathmatics notion, in radians)
227+
/// @param endAngle End angle of slice (standard mathmatics notion, in radians)
220228
void shrinkWindowForAngles(Window &oOutExtent, int nX, int nY,
221229
double startAngle, double endAngle)
222230
{
231+
/// NOTE: This probably doesn't work when the observer is outside the raster and
232+
/// needs to be enhanced for that case.
233+
223234
if (startAngle == endAngle)
224235
return;
225236

226237
Window win = oOutExtent;
227238

228239
// Set the X boundaries for the angles
229-
//ABELL - Verify for out-of-raster.
230240
int startAngleX = hIntersect(startAngle, nX, nY, win);
231241
int stopAngleX = hIntersect(endAngle, nX, nY, win);
232242

@@ -248,7 +258,6 @@ void shrinkWindowForAngles(Window &oOutExtent, int nX, int nY,
248258
}
249259

250260
// Set the Y boundaries for the angles
251-
//ABELL - Verify for out-of-raster.
252261
int startAngleY = vIntersect(startAngle, nX, nY, win);
253262
int stopAngleY = vIntersect(endAngle, nX, nY, win);
254263

alg/viewshed/viewshed_executor.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ namespace viewshed
2929
namespace
3030
{
3131

32-
bool valid(int x)
32+
/// Determines whether a value is a valid intersection coordinate.
33+
/// @param i Value to test.
34+
/// @return True if the value doesn't represent an invalid intersection.
35+
bool valid(int i)
3336
{
34-
return x != INVALID_ISECT;
37+
return i != INVALID_ISECT;
3538
}
3639

37-
bool invalid(int x)
40+
/// Determines whether a value is an invalid intersection coordinate.
41+
/// @param i Value to test.
42+
/// @return True if the value represents an invalid intersection.
43+
bool invalid(int i)
3844
{
39-
return !valid(x);
45+
return !valid(i);
4046
}
4147

4248
/// Calculate the height at nDistance units along a line through the origin given the height
@@ -454,6 +460,11 @@ void ViewshedExecutor::processFirstLineLeft(const LineLimits &ll,
454460
maskLineLeft(vResult, ll, m_nY);
455461
}
456462

463+
/// Mask cells based on angle intersection to the left of the observer.
464+
///
465+
/// @param vResult Result raaster line.
466+
/// @param nLine Line number.
467+
/// @return True when all cells have been masked.
457468
bool ViewshedExecutor::maskAngleLeft(std::vector<double> &vResult, int nLine)
458469
{
459470
auto clamp = [this](int x)
@@ -510,6 +521,11 @@ bool ViewshedExecutor::maskAngleLeft(std::vector<double> &vResult, int nLine)
510521
return false;
511522
}
512523

524+
/// Mask cells based on angle intersection to the right of the observer.
525+
///
526+
/// @param vResult Result raaster line.
527+
/// @param nLine Line number.
528+
/// @return True when all cells have been masked.
513529
bool ViewshedExecutor::maskAngleRight(std::vector<double> &vResult, int nLine)
514530
{
515531
int lineLength = static_cast<int>(vResult.size());
@@ -571,6 +587,11 @@ bool ViewshedExecutor::maskAngleRight(std::vector<double> &vResult, int nLine)
571587
return false;
572588
}
573589

590+
/// Perform angle and min/max masking to the left of the observer.
591+
///
592+
/// @param vResult Raster line to mask.
593+
/// @param ll Min/max line limits.
594+
/// @param nLine Line number.
574595
void ViewshedExecutor::maskLineLeft(std::vector<double> &vResult,
575596
const LineLimits &ll, int nLine)
576597
{
@@ -586,6 +607,11 @@ void ViewshedExecutor::maskLineLeft(std::vector<double> &vResult,
586607
oOpts.outOfRangeVal);
587608
}
588609

610+
/// Perform angle and min/max masking to the right of the observer.
611+
///
612+
/// @param vResult Raster line to mask.
613+
/// @param ll Min/max line limits.
614+
/// @param nLine Line number.
589615
void ViewshedExecutor::maskLineRight(std::vector<double> &vResult,
590616
const LineLimits &ll, int nLine)
591617
{
@@ -783,7 +809,9 @@ void ViewshedExecutor::processLineRight(int nYOffset, LineLimits &ll,
783809
maskLineRight(vResult, ll, nLine);
784810
}
785811

786-
// Apply angular mask to the initial X position. Assumes m_nX is in the raster.
812+
/// Apply angular mask to the initial X position. Assumes m_nX is in the raster.
813+
/// @param vResult Raster line on which to apply mask.
814+
/// @param nLine Line number.
787815
void ViewshedExecutor::maskInitial(std::vector<double> &vResult, int nLine)
788816
{
789817
if (!oOpts.angleMasking())
@@ -952,6 +980,12 @@ bool ViewshedExecutor::run()
952980
return true;
953981
}
954982

983+
/// Mask cells lower than the low pitch angle of intersection by setting the value
984+
/// to the intersection value.
985+
///
986+
/// @param dfZ Initial/modified cell height.
987+
/// @param nXOffset Cell X offset from observer.
988+
/// @param nYOffset Cell Y offset from observer.
955989
void ViewshedExecutor::maskLowPitch(double &dfZ, int nXOffset, int nYOffset)
956990
{
957991
if (std::isnan(m_lowTanPitch))
@@ -963,6 +997,13 @@ void ViewshedExecutor::maskLowPitch(double &dfZ, int nXOffset, int nYOffset)
963997
dfZ = dfZmask;
964998
}
965999

1000+
/// Mask cells higher than the high pitch angle of intersection by setting the value
1001+
/// to out-of-range.
1002+
///
1003+
/// @param dfResult Result value.
1004+
/// @param dfZ Cell height.
1005+
/// @param nXOffset Cell X offset from observer.
1006+
/// @param nYOffset Cell Y offset from observer.
9661007
void ViewshedExecutor::maskHighPitch(double &dfResult, double dfZ, int nXOffset,
9671008
int nYOffset)
9681009
{

0 commit comments

Comments
 (0)