as.mesh3d.ashape3d {rgl} | R Documentation

## Convert alpha-shape surface of a cloud of points to mesh3d object.

### Description

The `alphashape3d::ashape3d` function computes the 3D α-shape of a cloud of points. This is an approximation to the visual outline of the cloud. It may include isolated points, line segments, and triangular faces: this function converts the triangular faces to an rgl `tmesh3d` object.

### Usage

    ## S3 method for class 'ashape3d'
    as.mesh3d(x,
                       alpha = x$alpha[1],
                       col = "gray",
                       smooth = FALSE, normals = NULL,
                       texcoords = NULL, ...)

### Arguments

`x` | An object of class `"ashape3d"`.
`alpha` | Which `alpha` value stored in `x` should be converted?
`col` | The surface colour.
`smooth` | Whether to attempt to add normals to make the surface look smooth. See the Details below.
`normals, texcoords` | Normals and texture coordinates at each vertex can be specified.
`...` | Additional arguments to pass to use as `material3d` properties on the resulting mesh.

### Details

Edelsbrunner and Mucke's (1994) α-shape algorithm is intended to compute a surface of a general cloud of points. Unlike the convex hull, the cloud may have voids, isolated points, and other oddities. This function is designed to work in the case where the surface is made up of simple polygons.

If `smooth = TRUE`, this method attempts to orient all of the triangles in the surface consistently and add normals at each vertex by averaging the triangle normals. However, for some point clouds, the α-shape will contain sheets of polygons with a few solid polyhedra embedded. This does not allow a consistent definition of "inside" and outside. If this is detected, a warning is issued and the resulting mesh will likely contain boundaries where the assumed orientation of triangles changes, resulting in ugly dark lines through the shape. Larger values of `alpha` in the call to `alphashape3d::ashape3d` may help.

Methods for `plot3d` and `persp3d` are also defined: they call the `as.mesh3d` method and then plot the result.

### Value

A `"mesh3d"` object, suitable for plotting.

### Author(s)

Duncan Murdoch

### References

Edelsbrunner, H., Mucke, E. P. (1994). Three-Dimensional Alpha Shapes. ACM Transactions on Graphics, 13(1), pp.43-72.

Lafarge, T. and Pateiro-Lopez, B. (2017). alphashape3d: Implementation of the 3D Alpha-Shape for the Reconstruction of 3D Sets from a Point Cloud. R package version 1.3.

### Examples

    if (requireNamespace("alphashape3d", quietly = TRUE)) {
      set.seed(123)
      xyz <- rbind(cbind(runif(1000), runif(1000), runif(1000)),
                   cbind(runif(125, 1, 1.5),
                         runif(125, 0.25, 0.75),
                         runif(125, 0.25, 0.75)))
      ash <- suppressMessages(alphashape3d::ashape3d(xyz, alpha = 0.2))
      m <- as.mesh3d(ash, smooth = TRUE)
      open3d()
      mfrow3d(1, 2, sharedMouse = TRUE)
      plot3d(xyz, size = 1)
      plot3d(m, col = "red", alpha = 0.5)
      points3d(xyz, size = 1)
    }

[Package rgl version 0.100.19 Index]