contour3d               package:misc3d               R Documentation

_D_r_a_w _a_n _I_s_o_s_u_r_f_a_c_e, _a _T_h_r_e_e _D_i_m_e_n_s_i_o_n _C_o_n_t_o_u_r _P_l_o_t

_D_e_s_c_r_i_p_t_i_o_n:

     Uses rgl to render an isosurface computed by the marching cubes
     algorithm.

_U_s_a_g_e:

        contour3d(f, level, x, y, z, add=FALSE,...)

_A_r_g_u_m_e_n_t_s:

       f: a function of 3 arguments or a three dimensional array.

   level: numeric scalar. The value according to which to draw the
          isosurface.

   x,y,z: locations of grid planes at which values in 'f' are measured
          or 'f' is evaluated. Can be omitted if 'f' is an array.

     add: logical; if 'TRUE', add to current 'rgl' graph.

     ...: material and texture properties. See 'rgl.material' for
          details.

_D_e_t_a_i_l_s:

     Uses the marching-cubes algorithm, with adjustments for dealing
     with face and internal ambiguities, to draw the isosurface. See
     references for the details.

_R_e_f_e_r_e_n_c_e_s:

     Chernyaev E. (1995)   Marching Cubes 33: Construction of
     Topologically Correct Isosurfaces   _Technical Report CN/95-17,
     CERN_

     Daniel Adler, Oleg Nenadic and Walter Zucchini (2003) RGL: A
     R-library for 3D visualization with OpenGL

     Lorensen W. and Cline H. (1987)   Marching Cubes: A High
     Resolution 3D Surface Reconstruction Algorithm   _Computer
     Graphics_ *vol. 21, no. 4*, 163-169

     Nielson G. and Hamann B. (1992) The Asymptotic Decider: Resolving
     the Ambiguity in Marching Cubes   _Proc. IEEE Visualization_ 
     *92*, 83-91

_S_e_e _A_l_s_o:

     'rgl.triangles', 'rgl.material', 'rgl.surface'.

_E_x_a_m_p_l_e_s:

       #Example 1: Draw a ball
       f <- function(x, y, z)x^2+y^2+z^2
       x <- seq(-2,2,len=20)
       contour3d(f,4,x,x,x)

       #Example 2: Nested contours of mixture of three tri-variate normal densities
       nmix3 <- function(x, y, z, m, s) {
           0.4 * dnorm(x, m, s) * dnorm(y, m, s) * dnorm(z, m, s) +
           0.3 * dnorm(x, -m, s) * dnorm(y, -m, s) * dnorm(z, -m, s) +
           0.3 * dnorm(x, m, s) * dnorm(y, -1.5 * m, s) * dnorm(z, m, s)
       }
       f <- function(x,y,z) nmix3(x,y,z,.5,.5)
       g <- function(n = 40, k = 5, alo = 0.1, ahi = 0.5, cmap = heat.colors) {
           th <- seq(0.05, 0.2, len = k)
           col <- rev(cmap(length(th)))
           al <- seq(alo, ahi, len = length(th))
           x <- seq(-2, 2, len=n)
           for (i in seq(along = th)) {
                contour3d(f,th[i],x,x,x,color=col[i],alpha=al[i],
                          add = (i != 1))
           }
           rgl.bg(col="white")
       }
       g(40,5)

     ## Not run: 
       #Example 3: Nested contours for FMRI data.
       library(AnalyzeFMRI)
       a<-f.read.analyze.volume(system.file("example.img", package="AnalyzeFMRI"))
       contour3d(aperm(a[,,,1],c(1,3,2)),1:64,1.5*(1:21),1:64,lev=3000,alpha=0.5)
       contour3d(aperm(a[,,,1],c(1,3,2)),1:64,1.5*(1:21),1:64,lev=8000,
                 col="red",add=TRUE, alpha=0.5)
       contour3d(aperm(a[,,,1],c(1,3,2)),1:64,1.5*(1:21),1:64,lev=10000,
                 col="green",add=TRUE)
       
     ## End(Not run)

