View source: R/connectedComponents.R
connectedComponents | R Documentation |
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.
connectedComponents( vertices, faces, mesh = NULL, triangulate = FALSE, clean = FALSE, normals = FALSE, numbersType = "double" )
vertices |
a numeric matrix with three columns, or a |
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 |
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 |
A list of meshes, the connected components, each one being
represented as the output of the Mesh
function.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.