Plot 3D map of elevation generated by an OCN via rgl rendering
draw_elev3Drgl_OCN.Rd
Function that plots the 3D elevation map generated by an OCN.
Usage
draw_elev3Drgl_OCN(OCN, coarseGrain = c(1, 1), chooseCM = FALSE,
addColorbar = FALSE, drawRiver = FALSE, thrADraw = 0.002 *
OCN$FD$nNodes* OCN$cellsize^2, riverColor = "#00CCFF",
min_lwd = 1, max_lwd = 8, ...)
Arguments
- OCN
A
river
object as produced bylandscape_OCN
.- coarseGrain
2x1 vector (only effective if
chooseCM = FALSE
). For aesthetic purposes, the elevation map can be coarse-grained into aOCN$dimX/coarseGrain[1]
-by-OCN$dimX/coarseGrain[2]
domain, where each cell's elevation is the average of elevations of the correspondingcoarseGrain[1]
-by-coarseGrain[2]
cells of the original elevation field.coarseGrain[1]
andcoarseGrain[2]
must be divisors ofOCN$dimX
andOCN$dimY
, respectively.coarseGrain = c(2,2)
is often sufficient to achieve a good graphical results for large (i.e. at least 100x100 nodes) OCNs.- chooseCM
Index of catchment to display (only effective if
OCN$nOutlet > 1
). It can be a logical, or a scalar within1:length(OCN$nOutlet)
. IfTRUE
, the catchment with largest area is displayed. Note that, if the size of the chosen catchment is too small (e.g.OCN$CM$A[chooseCM] < 5*OCN$cellsize^2
), an error might occur due to failure in triangulation.- addColorbar
If
TRUE
, add colorbar to the plot.- drawRiver
If
TRUE
, draw the OCN on top of the elevation field.- thrADraw
Threshold drainage area value used to display the network.
- riverColor
Color used to plot the river.
- min_lwd, max_lwd
Minimum and maximum values of line width used to display the OCN (actual line width is proportional to the square root of drainage area).
- ...
Further parameters passed to function
persp3d
. The default value foraspect
isc(OCN$dimX/sqrt(OCN$dimX*OCN$dimY, OCN$dimY/sqrt(OCN$dimX*OCN$dimY, 1))
.
Details
This function makes use of the rgl
rendering system. To export the figure in raster format, use rgl.snapshot
.
To export in vectorial format, use rgl.postscript
(but note that this might produce rendering issues, see rgl
for details).
The function will attempt at drawing a contour of the plotted entity (i.e. the lattice or a catchment, depending on chooseCM
) at null elevation, and drawing polygons connecting this contour with the lattice/catchment contour at the real elevation. If chooseCM != FALSE
, this might result in errors owing to failure of polygon3d
in triangulating the polygons.
Examples
if (FALSE) {
draw_elev3Drgl_OCN(landscape_OCN(OCN_20))
}
if (FALSE) {
# 1a) draw the 3D representation of a single catchment within an OCN
# generated with nOutlet = "All" and add draw the river on top of it
OCN <- landscape_OCN(OCN_400_Allout, displayUpdates = 2) # this takes some minutes
draw_elev3Drgl_OCN(OCN, chooseCM = 983, drawRiver = TRUE)
# 1b) draw the 3D representation of the largest catchment within the OCN
# (here polygon3d may fail at plotting the polygon at zero elevation)
draw_elev3Drgl_OCN(OCN, chooseCM = TRUE)
# 1c) draw the 3D representation of the whole OCN
# and enhance the aspect ratio of Z coordinates
# with respect to the default value (the final result will be ugly):
draw_elev3Drgl_OCN(OCN, aspect = c(1, 1, 0.2))
# 1d) same as above, but operate coarse graining for better aesthetics:
draw_elev3Drgl_OCN(OCN, coarseGrain = c(5,5), aspect = c(1, 1, 0.2))
# 2) draw the 3D representation of a single catchment of an OCN generated
# with periodicBoundaries = TRUE
# (note that the real shape of the catchment is drawn)
OCN <- landscape_OCN(OCN_300_4out_PB, displayUpdates = 2) # this takes some minutes
draw_elev3Drgl_OCN(OCN, chooseCM = TRUE)
}