smoothShape: Smoothing of the shape of a mesh

View source: R/smoothing.R

smoothShapeR Documentation

Smoothing of the shape of a mesh

Description

Smooths the overall shape of the mesh by using the mean curvature flow.

Usage

smoothShape(
  vertices,
  faces,
  mesh = NULL,
  time,
  iterations = 1,
  normals = FALSE
)

Arguments

vertices

a numeric matrix with three columns

faces

either an integer matrix (each row provides the vertex indices of the corresponding face) or a list of integer vectors, each one providing the vertex indices of the corresponding face

mesh

if not NULL, this argument takes precedence over vertices and faces, and must be either a list containing two fields vertices and faces as described above, otherwise a rgl mesh (i.e. a mesh3d object)

time

positive number, a time step that corresponds to the speed by which the surface is smoothed (the larger the faster); typical values lie between 1e-6 and 1

iterations

number of iterations, a positive integer

normals

Boolean, whether to compute the vertex normals of the output mesh

Value

A triangle mesh represented as the output of the Mesh function.

Examples

library(MeshesOperations)
library(rgl)

# parabola ####
x <- seq(-1, 1, length.out = 30)
parabola <- cylinder3d(cbind(x, x^2, 0), radius = 0.2, closed = -2)
vertices <- t(parabola$vb[-4L, ])
faces <- c(
  split(t(parabola$it), 1L:ncol(parabola$it)),
  split(t(parabola$ib), 1L:ncol(parabola$ib))
)
sparabola <- smoothShape(
  vertices, faces, time = 0.0005, iterations = 10
)
sparabola <- toRGL(sparabola)
open3d(windowRect = c(50, 50, 950, 500))
mfrow3d(1, 2)
view3d(0, 0, zoom = 0.9)
shade3d(parabola, color = "orange")
wire3d(parabola)
next3d()
view3d(0, 0)
shade3d(sparabola, color = "green")
wire3d(sparabola)

# Stanford bunny (light version)
vf <- readMeshFile(
  system.file("extdata", "bunny.off", package = "MeshesOperations")
)
mesh <- Mesh(
  vf[["vertices"]], vf[["faces"]], normals = TRUE
)
rglmesh <- toRGL(mesh)
smesh <- smoothShape(
  mesh = mesh,
  time = 0.00001, iterations = 1, normals = TRUE
)
srglmesh <- toRGL(smesh)
open3d(windowRect = c(50, 50, 900, 500))
mfrow3d(1, 2)
view3d(0, 0, zoom = 0.8)
shade3d(rglmesh, color = "purple")
next3d()
view3d(0, 0, zoom = 0.8)
shade3d(srglmesh, color = "violetred")

stla/MeshesOperations documentation built on Oct. 23, 2022, 8:23 a.m.