[R] Irregular 3d objects with rgl

Greg Snow Greg.Snow at imail.org
Sun Oct 16 00:55:02 CEST 2011


You could use the rgl package and plot a sprite at each of your points with the color based on the concentration:

plume$col <- cut(plume$conc, c(-1,0.01,0.02,0.3,0.7,1), 
	labels=c('blue','green','yellow','orange','red'))


plume2 <- plume
theta <- atan2(plume2$y-mean(plume2$y), plume2$x-mean(plume2$x))
slice <- pi/4 < theta & theta < 3*pi/4
plume2$y[slice] <- plume2$y[slice] + 3 

library(rgl)
open3d()
sprites3d( plume2$x, plume2$y, plume2$z, color=as.character(plume$col),
 lit=FALSE, radius=1)

It looks better with more points in each direction and a smaller radius on the sprites.


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of emorway
Sent: Friday, October 14, 2011 6:15 PM
To: r-help at r-project.org
Subject: [R] Irregular 3d objects with rgl

Hello, 

While exploring if rgl is along the lines of what I need, I checked out
demo("rgl") and didn't find quite what I'm looking for, and am therefore
seeking additional help/suggestions.    

The application is geared towards displaying a 3D rendering of a contaminant
plume in the subsurface with the following highlights:  Once the plume was
rendered as a 3D object, a pie-like wedge could be removed (or cut away)
exposing the higher concentrations within the plume as 'hotter' colors. 
About the closest example I could find is here: 

http://mclaneenv.com/graphicdownloads/plume.jpg 

Whereas this particular rendering shows a bullet-like object where 3/4 of
the object is removed, I would like to try and show something where 3/4 of
the object remains, and where the object has been cut away the colors would
show concentrations within the plume, just as in the example referenced
above.  It would seem most software capable of this type of thing is
proprietary (and perhaps for good reason if it is a difficult problem to
solve).     

I've put together a very simple 6x6x6 cube with non-zero values internal to
it representing the plume.  I wondering if an isosurface where "conc" = 0.01
can be rendered in 3D and then if a "bite" or wedge can be removed from the
3d object exposing the higher concentrations inside as discussed above?

x<-c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,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4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6)

conc<-c(0,0,0,0,0,0,0,0,0.1,0.1,0,0,0,0.1,1,1,0.1,0,0,0.1,0.5,1,0.1,0,0,0,0.2,0.2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.05,0.1,0,0,0,0.05,0.8,0.8,0.05,0,0,0.05,0.4,0.8,0.05,0,0,0,0.1,0.1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.05,0,0,0,0,0.6,0.6,0.02,0,0,0,0.2,0.5,0.02,0,0,0,0.05,0.05,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.05,0.2,0,0,0,0,0,0.05,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.02,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)

plume<-data.frame(cbind(x=x,y=y,z=z,conc=conc))

if it helps to view the concentrations in layer by layer tabular form:
Layer 1
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.10 0.10 0.00 0.00
0.00 0.10 1.00 0.50 0.20 0.00
0.00 0.10 1.00 1.00 0.20 0.00
0.00 0.00 0.10 0.10 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
Layer 2     
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.05 0.05 0.00 0.00
0.00 0.05 0.80 0.40 0.10 0.00
0.00 0.10 0.80 0.80 0.10 0.00
0.00 0.00 0.05 0.05 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
Layer 3     
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.60 0.20 0.05 0.00
0.00 0.05 0.60 0.50 0.05 0.00
0.00 0.00 0.02 0.02 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
Layer 4     
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.05 0.00 0.00 0.00
0.00 0.00 0.20 0.05 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
Layer 5     
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.02 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
Layer 6
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00




--
View this message in context: http://r.789695.n4.nabble.com/Irregular-3d-objects-with-rgl-tp3906573p3906573.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list