[Stpp-commits] r20 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 30 16:33:19 CET 2008


Author: barryrowlingson
Date: 2008-10-30 16:33:19 +0100 (Thu, 30 Oct 2008)
New Revision: 20

Modified:
   pkg/R/stani.R
   pkg/man/stani.Rd
Log:
stani can now have polygons and raster backgrounds set

Modified: pkg/R/stani.R
===================================================================
--- pkg/R/stani.R	2008-10-29 16:05:24 UTC (rev 19)
+++ pkg/R/stani.R	2008-10-30 15:33:19 UTC (rev 20)
@@ -56,7 +56,7 @@
  return(panel)
 }
 
-stani <- function(xyt,tlim=range(xyt[,3],na.rm=TRUE),twid=diff(tlim)/20,persist=FALSE,states){
+stani <- function(xyt,tlim=range(xyt[,3],na.rm=TRUE),twid=diff(tlim)/20,persist=FALSE,states,bgpoly,bgframe=TRUE,bgimage,bgcol=gray(seq(0,1,len=12))){
   require(rgl)
   require(rpanel)
   if(missing(states)){
@@ -84,6 +84,26 @@
     
   .setPlot(xr[1],xr[2],yr[1],yr[2],tr[1],tr[2],maxRadius)
 
+  if(!missing(bgpoly)){
+    poly=rbind(bgpoly,bgpoly[1,])
+    poly=cbind(poly,min(tr))
+    lines3d(poly,size=2.0)
+    if(bgframe){
+      ci=chull(bgpoly)
+      nci=length(ci)
+      cpoints=bgpoly[ci,]
+      cpoints2 = cpoints[rep(1:nci,rep(2,nci)),]
+      cpoints2 = cbind(cpoints2,c(min(tr),max(tr)))
+      segments3d(cpoints2)
+      poly=cbind(poly[,1:2],max(tr))
+      lines3d(poly,size=2.0)
+    }
+  }
+
+  if(!missing(bgimage)){
+    .setBG(bgimage,min(tr),col=bgcol)
+  }
+  
   xyt=data.frame(xyt)
   xyt$id=NA
   ## initially all points will need redrawing:
@@ -126,4 +146,7 @@
 
 }
 
-  
+.setBG=function(xyz,zplane,col=heat.colors(12)){
+  cols = col[as.integer(cut(xyz$z,length(col)))]
+  surface3d(xyz$x,xyz$y,rep(zplane,prod(dim(xyz$z))),col=cols,lit=FALSE)
+}

Modified: pkg/man/stani.Rd
===================================================================
--- pkg/man/stani.Rd	2008-10-29 16:05:24 UTC (rev 19)
+++ pkg/man/stani.Rd	2008-10-30 15:33:19 UTC (rev 20)
@@ -13,6 +13,11 @@
   \item{twid}{The initial time window width}
   \item{persist}{Whether to display points before time window}
   \item{states}{How to display points - see Details}
+  \item{bgpoly}{A polygon to draw on the background plane}
+  \item{bgframe}{Whether to extend the bgpoly to the front plane}
+  \item{bgimage}{An list with x,y vectors and z matrix to display on the
+    background plane}
+  \item{bgcol}{A colour palette vector with which to draw the bgimage}
 }
 \details{
 This function requires the \code{rpanel} and \code{rgl} packages. It
@@ -44,6 +49,19 @@
 used in any of the state elements. This is to make sure the parameters
 are reset for each of the sets of points.
 
+The background polygon must be a simple 2-column vector of x and y
+coordinates. When used with bgframe=TRUE, the polygon is also drawn on
+the front plane, and the convex hull points are connected front to back
+in order to visualise the space-time prism that the data are contained
+in.
+
+A raster image can be displayed on the back plane by setting the bgimage
+parameter. This must be a list with x, y and z components as needed by
+the image function. Note that x and y define the center of cells and so
+must be the same length as the dimensions of z - the image function can
+accept x and y values that are one longer than the dimensions of z to
+define the edges, but bgimage does not allow that.
+
 }
 \value{
 A list of the slider parameters when the dialog is quitted.



More information about the Stpp-commits mailing list