diff --git a/DESCRIPTION b/DESCRIPTION index 8ce1693e..1feabda5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 @@ -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 diff --git a/NAMESPACE b/NAMESPACE index 8dbcb31e..8f0ad5a6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -15,6 +16,7 @@ import(doParallel) import(foreach) import(parallel) import(progress) +import(rgl) importFrom(Rcpp,evalCpp) importFrom(grDevices,col2rgb) importFrom(grDevices,rainbow) diff --git a/R/plot_3d.R b/R/plot_3d.R new file mode 100644 index 00000000..d2ed69d7 --- /dev/null +++ b/R/plot_3d.R @@ -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), ...) +} \ No newline at end of file diff --git a/R/sphere_shade.R b/R/sphere_shade.R index 951f43a8..a2a89904 100644 --- a/R/sphere_shade.R +++ b/R/sphere_shade.R @@ -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)) { diff --git a/man/plot_3d.Rd b/man/plot_3d.Rd new file mode 100644 index 00000000..953b7fa0 --- /dev/null +++ b/man/plot_3d.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot_3d.R +\name{plot_3d} +\alias{plot_3d} +\title{plot_3d} +\usage{ +plot_3d(hillshade, heightmap, zscale = 1, theta = 0, phi = 45, fov = 60, + zoom = 1, background = "grey10", windowsize = c(600, 600), ...) +} +\arguments{ +\item{hillshade}{Hillshade/image to be added to 3D surface map.} + +\item{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.} + +\item{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.} + +\item{theta}{Default 0. Rotation around z-axis.} + +\item{phi}{Default `45`. Azimuth angle.} + +\item{fov}{Field-of-view angle in degrees.} + +\item{zoom}{Default `1`. Zoom factor.} + +\item{background}{Default `grey10`. Color of the background.} + +\item{windowsize}{Default `c(600,600)`. Width and height of the `rgl` device displaying the plot.} + +\item{...}{Additional arguments to pass to the `rgl::par3d` function.} +} +\description{ +Displays the shaded map in 3D with the `rgl` package. +} +\examples{ +#Plotting a spherical texture map of the volcano dataset. +plot_3d(sphere_shade(volcano,texture="desert"),volcano, zscale=5) +} diff --git a/man/sphere_shade.Rd b/man/sphere_shade.Rd index f43f2729..be6421d6 100644 --- a/man/sphere_shade.Rd +++ b/man/sphere_shade.Rd @@ -32,5 +32,5 @@ product between light direction and the surface normal vector at that point. Eac intensity is proportional to the cosine of the normal ve } \examples{ -#TBD +plot_map(sphere_shade(volcano,texture="desert")) }