Skip to content

Commit

Permalink
Version 0.4.0: rgl 3D plot integration
Browse files Browse the repository at this point in the history
Added `plot_3d`, a function to plot 3D surfaces with a hillshade/image applied as a surface map.
  • Loading branch information
tylermorganwall committed Jul 1, 2018
1 parent a9c4f5e commit aa61f1e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rayshader
Type: Package
Title: Raytraces Elevation Matrices to Produce Global Illumination Relief Maps
Version: 0.3.1
Title: Produce and Visualize Hillshaded Maps from Elevation Matrices with Raytracing and Local Illumination Models
Version: 0.4.0
Date: 2018-06-30
Author: Tyler Morgan-Wall
Maintainer: Tyler Morgan-Wall <[email protected]>
Expand All @@ -16,6 +16,9 @@ Imports: doParallel,
jpeg,
png,
akima,
magrittr
magrittr,
rgl
LinkingTo: Rcpp, progress
RoxygenNote: 6.0.1
URL: https://github.com/tylermorganwall/rayshader
BugReports: https://github.com/tylermorganwall/rayshader/issues
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(calculate_normal)
export(create_texture)
export(detect_water)
export(lamb_shade)
export(plot_3d)
export(plot_map)
export(ray_shade)
export(sphere_shade)
Expand All @@ -15,6 +16,7 @@ import(doParallel)
import(foreach)
import(parallel)
import(progress)
import(rgl)
importFrom(Rcpp,evalCpp)
importFrom(grDevices,col2rgb)
importFrom(grDevices,rainbow)
Expand Down
31 changes: 31 additions & 0 deletions R/plot_3d.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#'@title plot_3d
#'
#'@description Displays the shaded map in 3D with the `rgl` package.
#'
#'@param hillshade Hillshade/image to be added to 3D surface map.
#'@param heightmap A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.
#'@param zscale Default `1`. The ratio between the x and y spacing (which are assumed to be equal) and the z axis. For example, if the elevation levels are in units
#'of 1 meter and the grid values are separated by 10 meters, `zscale` would be 10.
#'@param theta Default 0. Rotation around z-axis.
#'@param phi Default `45`. Azimuth angle.
#'@param fov Field-of-view angle in degrees.
#'@param zoom Default `1`. Zoom factor.
#'@param background Default `grey10`. Color of the background.
#'@param windowsize Default `c(600,600)`. Width and height of the `rgl` device displaying the plot.
#'@param ... Additional arguments to pass to the `rgl::par3d` function.
#'@import rgl
#'@export
#'@examples
#'#Plotting a spherical texture map of the volcano dataset.
#'plot_3d(sphere_shade(volcano,texture="desert"),volcano, zscale=5)
plot_3d = function(hillshade, heightmap, zscale=1, theta=0, phi = 45, fov=60 , zoom = 1, background="grey10", windowsize= c(600,600), ...) {
if(is.null(heightmap)) {
stop("heightmap argument missing--need to input both hillshade and original elevation matrix")
}
tempmap = tempfile()
write_png(hillshade,tempmap)
rgl.surface(1:nrow(heightmap),1:ncol(heightmap),heightmap[,ncol(heightmap):1]/zscale,texture=paste0(tempmap,".png"),lit=FALSE)
rgl.bg(color=background)
rgl.viewpoint(zoom=zoom,phi=phi,theta=theta,fov=fov)
par3d("windowRect" = c(0,0,windowsize), ...)
}
2 changes: 1 addition & 1 deletion R/sphere_shade.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#'@return RGB array of hillshaded texture mappings.
#'@export
#'@examples
#'#TBD
#'plot_map(sphere_shade(volcano,texture="desert"))
sphere_shade = function(heightmap, sunangle=315, texture="imhof1", normalvectors = NULL, zscale=1, remove_edges = TRUE, progbar = TRUE) {
sunangle = sunangle/180*pi
if(is.null(normalvectors)) {
Expand Down
38 changes: 38 additions & 0 deletions man/plot_3d.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sphere_shade.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aa61f1e

Please sign in to comment.