as.mesh3d.kde: Convert a 3D Kernel Density Estimate (package ks) into rgl...

View source: R/kde.R

as.mesh3d.kdeR Documentation

Convert a 3D Kernel Density Estimate (package ks) into rgl mesh3d object

Description

Convert a 3D Kernel Density Estimate (package ks) into rgl mesh3d object

Usage

## S3 method for class 'kde'
as.mesh3d(
  x,
  cont = 50,
  approx.cont = TRUE,
  method = c("tri", "ashape3d"),
  ashape.alpha = NULL,
  ...
)

Arguments

x

The kde object

cont

The contour level to use

approx.cont

Whether to compute an approximate contour level. (Default FALSE).

method

Which conversion method to use (see details)

ashape.alpha

A length parameter (alpha) passed to alphashape3d::ashape3d (see details).

...

Additional rgl rendering parameters eventually passed to rgl::tmesh3d

Details

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

Value

An object of class mesh3d

See Also

plot.kde, as.mesh3d, as.mesh3d.ashape3d

Examples

## 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) )

## End(Not run)

alexanderbates/catnat documentation built on Sept. 5, 2023, 4:51 a.m.