Re: [R] Plotting a cloud/fog of variable density in rgl

2010-11-28 Thread JiHO
Thanks for both the replies.

 I think you can come closest to what you want within rgl by using
 sprites rather than rendering transparent spheres. See
 examples(sprites3d).

Sprites helps a lot indeed. With enough transparency I am close to what I want.

 If you only have 2 things with simple properties, namely point emitters
 as your organisms and a uniform concsntration of transparent scatters ( the
 fog) you can probably derive geometrical optics expressions for the ray trace
 results and just integrate those over your source distribution. This should
 be reasonably easy in R. I haven't been to siggraph since 1983 so can't help
 much but you can probably find analyitcal solutions for fog on google
 and just sum up your source distribution. I guess you could even do some
 wave optics etc as presumably the fog could be done as a function
 of wavelength just as easily. In any case, if you only have two basic things
 with simple disto should be reasonably easy to do in R with your own code.

I am afraid this is a bit too advanced for me. I know next to nothing
regarding digital 3D imaging and, even if I could compute this, I am
not sure how I would plot the result. My goal is really to add this to
my R-plotting arsenal and use it in routine, not to develop something
very specific for this particular application. But thank you for
taking the time to reply, maybe I'll come back to this when I know
more.

JiHO
---
http://maururu.net

__
R-help@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.


[R] Plotting a cloud/fog of variable density in rgl

2010-11-22 Thread JiHO
Hi everyone,

I want to plot a 3D interpolation of the concentration of aquatic
organisms. My goal would be to have the result represented as clouds
with a density proportional to the abundance of organisms, so that I
could fly (well, swim actually ;) ) through the scene and see the
patches here and there. Basically, I want to do something like this:
http://www.youtube.com/watch?v=27mo_Y-aU-c
but simpler and with only clouds.

I though about doing it this way:
1- interpolate to a fine grid
2- plot points at each grid intersection of transparency inversely
proportional to abundance
3- blur/fog a bit each point to create the general impression of a cloud

So far I am stuck on 3 but maybe there is a better overall solution.
Here is some code that reads the result of the interpolation on a
coarse grid and plots it:

# read a set of gridded data points in 3D
d = read.table(http://dl.dropbox.com/u/1047321/R/test3Ddata.txt;, 
header=T)

# plot
library(rgl)
spheres3d(d$x, d$y, d$z, alpha=alpha, radius=0.05)

And here is a version that actually performs the interpolation a
random set of points in 3D through kriging in case you want to try
with increase precision.

# create a set of random data points in 3D
n = 50
data3D = data.frame(x = runif(n), y = runif(n), z = runif(n), v = 
rnorm(n))

# do 3d interpolation via kriging
library(gstat)
coordinates(data3D) = ~x+y+z
range1D = seq(from = 0, to = 1, length = 10)
grid3D = expand.grid(x = range1D, y = range1D, z = range1D)
gridded(grid3D) = ~x+y+z
res3D = krige(formula = v ~ 1, data3D, grid3D, model = vgm(1, Exp, 
.2))

# convert the result to a data.frame
d = as.data.frame(res3D)

# compute transparency (proportional to the interpolated value)
maxD = max(d$var1.pred)
minD = min(d$var1.pred)
alpha = (d$var1.pred - minD)/(maxD - minD)
# reduce maximum alpha (all points are semi-transparent)
alpha = alpha/5

# plot
library(rgl)
spheres3d(d$x, d$y, d$z, alpha=alpha, radius=0.05)


I saw the fog effect but it seems to add a fog in the scene to
increase depth. What I want is my scene to actually look like a fog.

Thanks in advance for any help. Sincerely,

JiHO
---
http://maururu.net

__
R-help@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.


Re: [R] Plotting a cloud/fog of variable density in rgl

2010-11-22 Thread Duncan Murdoch

On 22/11/2010 12:51 PM, JiHO wrote:

Hi everyone,

I want to plot a 3D interpolation of the concentration of aquatic
organisms. My goal would be to have the result represented as clouds
with a density proportional to the abundance of organisms, so that I
could fly (well, swim actually ;) ) through the scene and see the
patches here and there. Basically, I want to do something like this:
http://www.youtube.com/watch?v=27mo_Y-aU-c
but simpler and with only clouds.


rgl doesn't make everything in OpenGL available.  I'm not sure exactly 
how those clouds were done, but it wouldn't really be easy to do them in 
rgl.


I think you can come closest to what you want within rgl by using 
sprites rather than rendering transparent spheres.  See 
examples(sprites3d).


Duncan Murdoch


I though about doing it this way:
1- interpolate to a fine grid
2- plot points at each grid intersection of transparency inversely
proportional to abundance
3- blur/fog a bit each point to create the general impression of a cloud

So far I am stuck on 3 but maybe there is a better overall solution.
Here is some code that reads the result of the interpolation on a
coarse grid and plots it:

# read a set of gridded data points in 3D
d = read.table(http://dl.dropbox.com/u/1047321/R/test3Ddata.txt;, 
header=T)

# plot
library(rgl)
spheres3d(d$x, d$y, d$z, alpha=alpha, radius=0.05)

And here is a version that actually performs the interpolation a
random set of points in 3D through kriging in case you want to try
with increase precision.

# create a set of random data points in 3D
n = 50
data3D = data.frame(x = runif(n), y = runif(n), z = runif(n), v = 
rnorm(n))

# do 3d interpolation via kriging
library(gstat)
coordinates(data3D) = ~x+y+z
range1D = seq(from = 0, to = 1, length = 10)
grid3D = expand.grid(x = range1D, y = range1D, z = range1D)
gridded(grid3D) = ~x+y+z
res3D = krige(formula = v ~ 1, data3D, grid3D, model = vgm(1, Exp, 
.2))

# convert the result to a data.frame
d = as.data.frame(res3D)

# compute transparency (proportional to the interpolated value)
maxD = max(d$var1.pred)
minD = min(d$var1.pred)
alpha = (d$var1.pred - minD)/(maxD - minD)
# reduce maximum alpha (all points are semi-transparent)
alpha = alpha/5

# plot
library(rgl)
spheres3d(d$x, d$y, d$z, alpha=alpha, radius=0.05)


I saw the fog effect but it seems to add a fog in the scene to
increase depth. What I want is my scene to actually look like a fog.

Thanks in advance for any help. Sincerely,

JiHO
---
http://maururu.net

__
R-help@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.


__
R-help@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.


Re: [R] Plotting a cloud/fog of variable density in rgl

2010-11-22 Thread Mike Marchywka







 Date: Mon, 22 Nov 2010 13:55:13 -0500
 From: murdoch.dun...@gmail.com
 To: jo.li...@gmail.com
 CC: r-h...@stat.math.ethz.ch
 Subject: Re: [R] Plotting a cloud/fog of variable density in rgl

 On 22/11/2010 12:51 PM, JiHO wrote:
  Hi everyone,
 
  I want to plot a 3D interpolation of the concentration of aquatic
  organisms. My goal would be to have the result represented as clouds
  with a density proportional to the abundance of organisms, so that I
  could fly (well, swim actually ;) ) through the scene and see the
  patches here and there. Basically, I want to do something like this:
  http://www.youtube.com/watch?v=27mo_Y-aU-c
  but simpler and with only clouds.

 rgl doesn't make everything in OpenGL available. I'm not sure exactly
 how those clouds were done, but it wouldn't really be easy to do them in
 rgl.

 I think you can come closest to what you want within rgl by using
 sprites rather than rendering transparent spheres. See
 examples(sprites3d).

If you only have 2 things with simple properties, namely point emitters 
as your organisms and a uniform concsntration of transparent scatters ( the
fog) you can probably derive geometrical optics expressions for the ray trace
results and just integrate those over your source distribution. This should
be reasonably easy in R. I haven't been to siggraph since 1983 so can't help
much but you can probably find analyitcal solutions for fog on google
and just sum up your source distribution. I guess you could even do some 
wave optics etc as presumably the fog could be done as a function
of wavelength just as easily. In any case, if you only have two basic things
with simple disto should be reasonably easy to do in R with your own code.

  
__
R-help@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.