connectedComponents: Connected components of a 3D mesh

View source: R/connectedComponents.R

connectedComponentsR Documentation

Connected components of a 3D mesh

Description

Computes the connected components of a 3D mesh; for each returned component, its faces are coherently oriented, its normals are computed if desired, and it is triangulated if desired.

Usage

connectedComponents(
  vertices,
  faces,
  mesh = NULL,
  triangulate = FALSE,
  clean = FALSE,
  normals = FALSE,
  numbersType = "double"
)

Arguments

vertices

a numeric matrix with three columns, or a bigq matrix with three columns if numbersType="gmp"

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 the fields vertices and faces (objects as described above), otherwise a rgl mesh (i.e. a mesh3d object)

triangulate

Boolean, whether to triangulate the faces

clean

Boolean, whether to clean the mesh (merging duplicated vertices, duplicated faces, removed isolated vertices)

normals

Boolean, whether to compute the normals

numbersType

the type of the numbers used in C++ for the computations; must be one of "double", "lazyExact" (a type provided by CGAL for exact computations), or "gmp" (exact computations with rational numbers); using exact computations can improve the detection of the exterior edges

Value

A list of meshes, the connected components, each one being represented as the output of the Mesh function.

Examples

library(MeshesOperations)
library(rgl)

# a tetrahedron with ill-oriented faces ####
vertices1 <- rbind(
  c(-1, -1, -1),
  c( 1,  1, -1),
  c( 1, -1,  1),
  c(-1,  1,  1)
)
faces1 <- rbind(
  c(1, 2, 3),
  c(3, 4, 2),
  c(4, 2, 1),
  c(4, 3, 1)
)
# same tetrahedron translated ####
vertices2 <- vertices1 + 3
# merge the two tetrahedra ####
vertices <- rbind(vertices1, vertices2)
faces <- rbind(faces1, faces1 + 4)

# now run the `connectedComponents` function ####
meshes <- connectedComponents(vertices, faces, normals = FALSE)
mesh1 <- meshes[[1]]; mesh2 <- meshes[[2]]
# plot
tmesh1 <- toRGL(mesh1)
tmesh2 <- toRGL(mesh2)
open3d(windowRect = c(50, 50, 562, 562))
shade3d(tmesh1, color = "green", back = "culled")
shade3d(tmesh2, color = "red", back = "culled")

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