R/kde.R
as.mesh3d.kde.Rd
Convert a 3D Kernel Density Estimate (package ks) into rgl mesh3d object
# S3 method for kde as.mesh3d(x, cont = 50, approx.cont = TRUE, method = c("tri", "ashape3d"), ashape.alpha = NULL, ...)
x | The kde object |
---|---|
cont | The contour level to use |
approx.cont | Whether to compute an approximate contour level. (Default
|
method | Which conversion method to use (see details) |
ashape.alpha | A length parameter (alpha) passed to
|
... | Additional rgl rendering parameters eventually passed to
|
An object of class mesh3d
There are two conversion methods. The default uses the output of the
misc3d::contour3d function. This looks nice but seems to me to have a lot
of redundant triangles. The alternative uses the alphashape3d
library which produces a simpler output. But you must provide a
length parameter ashape.alpha
which is passed to alphashape3d
# NOT RUN { # Assuming you have lh.voxels object from Alex lh.voxels.m3d=lapply(lh.voxels, function(x) as.mesh3d(attr(x, 'fhat'))) shade3d(lh.voxels.m3d[[1]], col='red', alpha=.3) # plot several at once mapply(shade3d, lh.voxels.m3d[c(1,4,10)], col=rainbow(3), alpha=.3) # alternatively making a smoother/simpler alphashape # note that the parameter am1=as.mesh3d(attr(lh.voxels[[1]], 'fhat'), method='alpha', alpha=10) lh.voxels.m3d2=lapply(, function(x) ) # }