| Title: | 3D Surface Meshes Based on 'CGAL' |
|---|---|
| Description: | Processing of 3D surface meshes based on the 'C++' library 'CGAL' (Computational Geometry Algorithms Library, <https://www.cgal.org/>). Reads and writes common file formats for meshes and polygon soups. Supports mesh repair, remeshing, subdivision, Boolean operations on bounded volumes, outlier removal, surface reconstruction, (optimal) bounding box, bounding sphere, bounding ellipsoid, convex hull, vertex normals, surface distance metrics (such as Hausdorff), volume-overlap similarity measures JSC (Jaccard Similarity Coefficient) and DSC (Dice Similarity Coefficient). Adapts code from packages 'Boov' and 'cgalMeshes' developed by Stephane Laurent. |
| Authors: | Daniel Wollschlaeger [aut, cre], Stephane Laurent [aut], The CGAL Project [cph] |
| Maintainer: | Daniel Wollschlaeger <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.2 |
| Built: | 2026-11-18 00:22:06 UTC |
| Source: | https://github.com/cran/SurfaceMesh |
Add normal vectors to a given 3D surface mesh. Currently, only vertex normals are supported.
addVertexNormals(x)addVertexNormals(x)
x |
A |
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataToroHelix, normals=FALSE) mesh mesh_vn <- addVertexNormals(mesh) mesh_vn mfrow3d(1, 2) view3d(0, 30, zoom=0.8) shade3d(toRGL(mesh), col="gray") next3d() view3d(0, 30, zoom=0.8) shade3d(toRGL(mesh_vn), col="gray")library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataToroHelix, normals=FALSE) mesh mesh_vn <- addVertexNormals(mesh) mesh_vn mfrow3d(1, 2) view3d(0, 30, zoom=0.8) shade3d(toRGL(mesh), col="gray") next3d() view3d(0, 30, zoom=0.8) shade3d(toRGL(mesh_vn), col="gray")
Reconstruction of a 3D surface mesh from a cloud of 3D points by alpha wrapping.
alphaWrap(x, alphaRel, offsetRel, normals = FALSE)alphaWrap(x, alphaRel, offsetRel, normals = FALSE)
x |
A |
alphaRel |
Relative alpha parameter. The actual alpha parameter (see details) is defined as the length of the diagonal of the bounding box of the point cloud divided by the relative alpha parameter. Increase for a more detailed mesh. |
offsetRel |
Relative offset. The actual offset parameter (see details) is defined as the length of the diagonal of the bounding box of the point cloud divided by the relative offset parameter. Increase for output that is closer to input mesh. |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Alpha_wrap_3/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See also reconstructAFS,
reconstructSSS,
reconstructPoisson for other surface reconstruction
methods.
library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_aw <- alphaWrap(mesh, alphaRel =10, offsetRel=300) mesh_aw_rgl <- toRGL(mesh_aw) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_aw_rgl, col="gray")library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_aw <- alphaWrap(mesh, alphaRel =10, offsetRel=300) mesh_aw_rgl <- toRGL(mesh_aw) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_aw_rgl, col="gray")
Compute the difference between two 3D surface meshes
(mesh1 - mesh2).
boolDifference( mesh1, mesh2, repairSoup = TRUE, normals = FALSE, verbose = FALSE )boolDifference( mesh1, mesh2, repairSoup = TRUE, normals = FALSE, verbose = FALSE )
mesh1 |
A mesh, either given as a |
mesh2 |
A mesh, either given as a |
repairSoup |
Boolean. Clean the input meshes (merging duplicated
vertices, duplicated faces, removing isolated vertices)? Set to
|
normals |
Boolean. Return vertex normals of the output mesh? |
verbose |
Boolean. Print out messages about mesh processing? |
See https://doc.cgal.org/latest/PMP_Boolean_operations/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See also boolIntersection and
boolUnion for other Boolean mesh operations.
library(SurfaceMesh) library(rgl) # mesh one: a cube mesh1_rgl <- cube3d() # (from the rgl package) # mesh two: another cube mesh2_rgl <- translate3d(cube3d(), 1, 1, 0) # compute the difference mesh_d <- boolDifference(mesh1_rgl, mesh2_rgl) # plot mesh_d_rgl <- toRGL(mesh_d) open3d(windowRect=c(50, 50, 562, 562)) shade3d(mesh1_rgl, color="yellow", alpha=0.2) shade3d(mesh2_rgl, color="cyan", alpha=0.2) shade3d(mesh_d_rgl, color="red") plotEdges(mesh_d[["vertices"]], edges =mesh_d[["edgesExterior"]], edgesAsTubes =TRUE, verticesAsSpheres=TRUE)library(SurfaceMesh) library(rgl) # mesh one: a cube mesh1_rgl <- cube3d() # (from the rgl package) # mesh two: another cube mesh2_rgl <- translate3d(cube3d(), 1, 1, 0) # compute the difference mesh_d <- boolDifference(mesh1_rgl, mesh2_rgl) # plot mesh_d_rgl <- toRGL(mesh_d) open3d(windowRect=c(50, 50, 562, 562)) shade3d(mesh1_rgl, color="yellow", alpha=0.2) shade3d(mesh2_rgl, color="cyan", alpha=0.2) shade3d(mesh_d_rgl, color="red") plotEdges(mesh_d[["vertices"]], edges =mesh_d[["edgesExterior"]], edgesAsTubes =TRUE, verticesAsSpheres=TRUE)
Compute the intersection of the given 3D surface meshes.
boolIntersection(x, repairSoup = TRUE, normals = FALSE, verbose = FALSE)boolIntersection(x, repairSoup = TRUE, normals = FALSE, verbose = FALSE)
x |
A list of meshes, each being either a |
repairSoup |
Boolean. Clean the meshes (merging
duplicated vertices, duplicated faces, removing isolated vertices)?
Set to |
normals |
Boolean. Return vertex normals of the output mesh? |
verbose |
Boolean. Print out messages about mesh processing? |
See https://doc.cgal.org/latest/PMP_Boolean_operations/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See also boolUnion and
boolDifference for other Boolean mesh operations.
library(SurfaceMesh) library(rgl) # mesh one: truncated icosahedron; we triangulate it mesh1 <- makeMesh(dataTruncIcosahedron, triangulate=TRUE, normals = FALSE) # mesh two: a cube mesh2_rgl <- translate3d(cube3d(), 2, 0, 0) mesh2 <- makeMesh(mesh2_rgl, triangulate=TRUE, normals =FALSE) # compute the intersection mesh_i <- boolIntersection(list(mesh1, mesh2)) # plot mesh1_rgl <- toRGL(mesh1) mesh_i_rgl <- toRGL(mesh_i) open3d(windowRect=c(50, 50, 562, 562)) shade3d(mesh1_rgl, color="yellow", alpha=0.2) shade3d(mesh2_rgl, color="cyan", alpha=0.2) shade3d(mesh_i_rgl, color="red") plotEdges(mesh_i[["vertices"]], edges =mesh_i[["edgesExterior"]], edgesAsTubes =FALSE, lwd =3, verticesAsSpheres=FALSE)library(SurfaceMesh) library(rgl) # mesh one: truncated icosahedron; we triangulate it mesh1 <- makeMesh(dataTruncIcosahedron, triangulate=TRUE, normals = FALSE) # mesh two: a cube mesh2_rgl <- translate3d(cube3d(), 2, 0, 0) mesh2 <- makeMesh(mesh2_rgl, triangulate=TRUE, normals =FALSE) # compute the intersection mesh_i <- boolIntersection(list(mesh1, mesh2)) # plot mesh1_rgl <- toRGL(mesh1) mesh_i_rgl <- toRGL(mesh_i) open3d(windowRect=c(50, 50, 562, 562)) shade3d(mesh1_rgl, color="yellow", alpha=0.2) shade3d(mesh2_rgl, color="cyan", alpha=0.2) shade3d(mesh_i_rgl, color="red") plotEdges(mesh_i[["vertices"]], edges =mesh_i[["edgesExterior"]], edgesAsTubes =FALSE, lwd =3, verticesAsSpheres=FALSE)
Compute the union of the given meshes.
boolUnion(x, repairSoup = TRUE, normals = FALSE, verbose = FALSE)boolUnion(x, repairSoup = TRUE, normals = FALSE, verbose = FALSE)
x |
A list of meshes, each being either a |
repairSoup |
Boolean. Clean the input meshes (merging duplicated
vertices, duplicated faces, removing isolated vertices)? Set to
|
normals |
Boolean. Return vertex normals of the output mesh? |
verbose |
Boolean. Print out messages about mesh processing? |
See https://doc.cgal.org/latest/PMP_Boolean_operations/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See also boolIntersection and
boolDifference for other Boolean mesh operations.
library(SurfaceMesh) library(rgl) # mesh one: a cube mesh1_rgl <- cube3d() # (from the rgl package) # mesh two: another cube mesh2_rgl <- translate3d(cube3d(), 1, 1, 1) # compute the union mesh_u <- boolUnion(list(mesh1_rgl, mesh2_rgl)) # plot mesh_u_rgl <- toRGL(mesh_u) open3d(windowRect=c(50, 50, 562, 562)) shade3d(mesh_u_rgl, color="red") plotEdges(mesh_u[["vertices"]], edges =mesh_u[["edgesExterior"]], edgesAsTubes =TRUE, verticesAsSpheres=TRUE)library(SurfaceMesh) library(rgl) # mesh one: a cube mesh1_rgl <- cube3d() # (from the rgl package) # mesh two: another cube mesh2_rgl <- translate3d(cube3d(), 1, 1, 1) # compute the union mesh_u <- boolUnion(list(mesh1_rgl, mesh2_rgl)) # plot mesh_u_rgl <- toRGL(mesh_u) open3d(windowRect=c(50, 50, 562, 562)) shade3d(mesh_u_rgl, color="red") plotEdges(mesh_u[["vertices"]], edges =mesh_u[["edgesExterior"]], edgesAsTubes =TRUE, verticesAsSpheres=TRUE)
An object of class mesh3d from package
rgl representing a Dupin cyclide.
dataCyclidedataCyclide
A list with components vb, it.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "Cyclide.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(0, -35, zoom=0.8) shade3d(dataCyclide, color="orangered")## The following files were used to generate this mesh. system.file("data-raw", "Cyclide.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(0, -35, zoom=0.8) shade3d(dataCyclide, color="orangered")
An object of class mesh3d from package
rgl representing an Entzensberger star.
dataEntzenStardataEntzenStar
A list with components vb, it.
## The following files were used to generate this mesh. system.file("data-raw", "EntzenStar.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-55, -20, zoom=0.8) shade3d(dataEntzenStar, color="steelblue2")## The following files were used to generate this mesh. system.file("data-raw", "EntzenStar.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-55, -20, zoom=0.8) shade3d(dataEntzenStar, color="steelblue2")
An object of class CGALmesh representing a human heart
based on a CT scan.
dataHeart1dataHeart1
A CGALmesh object.
library(SurfaceMesh) library(rgl) view3d(-5, -90, zoom=0.8) shade3d(toRGL(dataHeart1), color="tomato")library(SurfaceMesh) library(rgl) view3d(-5, -90, zoom=0.8) shade3d(toRGL(dataHeart1), color="tomato")
An object of class CGALmesh representing a human heart
based on a CT scan.
dataHeart2dataHeart2
A CGALmesh object.
library(SurfaceMesh) library(rgl) view3d(-5, -90, zoom=0.8) shade3d(toRGL(dataHeart2), color="gray")library(SurfaceMesh) library(rgl) view3d(-5, -90, zoom=0.8) shade3d(toRGL(dataHeart2), color="gray")
A CGALmesh object, i.e., the output of
makeMesh representing a Hopf torus.
dataHopfTorusdataHopfTorus
A CGALmesh object.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "HopfTorus.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(35, -20, zoom=0.8) shade3d(toRGL(dataHopfTorus), color="darkred")## The following files were used to generate this mesh. system.file("data-raw", "HopfTorus.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(35, -20, zoom=0.8) shade3d(toRGL(dataHopfTorus), color="darkred")
An object of class mesh3d from package
rgl representing an ICN5D eight, a shape presented by user
ICN5D on the Higher Space Forum.
dataICN5DeightdataICN5Deight
A list with components vb, it, and normals.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "ICN5Deight.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(35, -20, zoom=0.8) shade3d(dataICN5Deight, color="violetred")## The following files were used to generate this mesh. system.file("data-raw", "ICN5Deight.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(35, -20, zoom=0.8) shade3d(dataICN5Deight, color="violetred")
A CGALmesh object, i.e., the output of
makeMesh representing an oloid.
dataOloiddataOloid
A CGALmesh object.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "Oloid.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(20, 15, zoom=0.8) shade3d(toRGL(dataOloid), color="darkviolet")## The following files were used to generate this mesh. system.file("data-raw", "Oloid.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(20, 15, zoom=0.8) shade3d(toRGL(dataOloid), color="darkviolet")
An object of class mesh3d from package
rgl representing an Ortho Circle.
dataOrthoCircledataOrthoCircle
A list with components vb, it, and normals.
https://paulbourke.net/geometry/orthocircle/
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "OrthoCircle.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-15, -10, zoom=0.8) shade3d(dataOrthoCircle, color="darkolivegreen4")## The following files were used to generate this mesh. system.file("data-raw", "OrthoCircle.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-15, -10, zoom=0.8) shade3d(dataOrthoCircle, color="darkolivegreen4")
A list representing a pentagrammic prism, giving the vertices and the faces; it has 20 vertices, 10 triangular faces, 10 rectangular faces and two pentagonal faces.
dataPentaPrismdataPentaPrism
A list with components vertices, faces.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "PentaPrism.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) mPentaPrism <- makeMesh(dataPentaPrism, triangulate=TRUE) view3d(-15, -15, zoom=0.8) shade3d(toRGL(mPentaPrism), color="forestgreen")## The following files were used to generate this mesh. system.file("data-raw", "PentaPrism.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) mPentaPrism <- makeMesh(dataPentaPrism, triangulate=TRUE) view3d(-15, -15, zoom=0.8) shade3d(toRGL(mPentaPrism), color="forestgreen")
An object of class mesh3d from package
rgl representing a septuaginta, i.e. a polyhedron with 72
faces like a sphere based on the drawing by Leonardo da Vinci.
dataSeptuagintadataSeptuaginta
A list with components vb, it, and ib.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "Septuaginta.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-10, -20, zoom=0.8) shade3d(dataSeptuaginta, color="orangered")## The following files were used to generate this mesh. system.file("data-raw", "Septuaginta.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-10, -20, zoom=0.8) shade3d(dataSeptuaginta, color="orangered")
An object of class mesh3d from package
rgl, representing a solid Mobius Strip.
dataSolidMobiusStripdataSolidMobiusStrip
A list with components vb, it, and normals.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "SolidMobiusStrip.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-10, -20, zoom=0.8) shade3d(dataSolidMobiusStrip, color="darkred")## The following files were used to generate this mesh. system.file("data-raw", "SolidMobiusStrip.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-10, -20, zoom=0.8) shade3d(dataSolidMobiusStrip, color="darkred")
An object of class mesh3d from package
rgl representing a sphere
dataSpheredataSphere
A list with components vb, it, and normals.
## The following files were used to generate this mesh. system.file("data-raw", "Sphere.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(15, -20, zoom=0.8) shade3d(dataSphere, color="darkgoldenrod")## The following files were used to generate this mesh. system.file("data-raw", "Sphere.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(15, -20, zoom=0.8) shade3d(dataSphere, color="darkgoldenrod")
An object of class mesh3d from package
rgl representing a Spider Cage.
dataSpiderCagedataSpiderCage
A list with components vb, it, and normals.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "SpiderCage.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-25, -45, zoom=0.8) shade3d(dataSpiderCage, color="mediumseagreen")## The following files were used to generate this mesh. system.file("data-raw", "SpiderCage.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-25, -45, zoom=0.8) shade3d(dataSpiderCage, color="mediumseagreen")
An object of class mesh3d from package
rgl representing a toroidal helix.
dataToroHelixdataToroHelix
A list with components vb, it.
## The following files were used to generate this mesh. system.file("data-raw", "ToroHelix.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(15, -20, zoom=0.8) shade3d(dataToroHelix, color="violetred")## The following files were used to generate this mesh. system.file("data-raw", "ToroHelix.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(15, -20, zoom=0.8) shade3d(dataToroHelix, color="violetred")
An object of class mesh3d from package
rgl representing a torus.
dataTorusdataTorus
A list with components vb, it.
## The following files were used to generate this mesh. system.file("data-raw", "Torus.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(15, -20, zoom=0.8) shade3d(dataTorus, color="green")## The following files were used to generate this mesh. system.file("data-raw", "Torus.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(15, -20, zoom=0.8) shade3d(dataTorus, color="green")
A list giving the vertices and the faces of a truncated icosahedron. There are some hexagonal faces and some pentagonal faces.
dataTruncIcosahedrondataTruncIcosahedron
A list with two components: vertices and faces.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "TruncIcosahedron.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) mTruncIcosahedron <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) view3d(-15, -10, zoom=0.8) shade3d(toRGL(mTruncIcosahedron), color="wheat2")## The following files were used to generate this mesh. system.file("data-raw", "TruncIcosahedron.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) mTruncIcosahedron <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) view3d(-15, -10, zoom=0.8) shade3d(toRGL(mTruncIcosahedron), color="wheat2")
An object of class mesh3d from package
rgl representing a tubular knot.
dataTubularKnotdataTubularKnot
A list with components vb, it.
Originally developed by Stephane Laurent.
## The following files were used to generate this mesh. system.file("data-raw", "TubularKnot.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-15, -15, zoom=0.8) shade3d(dataTubularKnot, color="royalblue3")## The following files were used to generate this mesh. system.file("data-raw", "TubularKnot.R", package="SurfaceMesh") system.file("data-raw", "00_GenerateMeshes.R", package="SurfaceMesh") library(SurfaceMesh) library(rgl) view3d(-15, -15, zoom=0.8) shade3d(dataTubularKnot, color="royalblue3")
Does given 3D surface mesh bound a volume?
doesBoundVolume(x)doesBoundVolume(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See orientToBoundVolume for orienting the mesh to
bound a volume, and getVolume for the volume bounded by
the mesh.
library(SurfaceMesh) vertices <- rbind( c(0, 0, 0), c(2, 2, 0), c(2, 0, 2), c(0, 2, 2), c(3, 3, 3), c(5, 5, 3), c(5, 3, 5), c(3, 5, 5)) faces <- rbind( c(3, 2, 1), c(3, 4, 2), c(1, 2, 4), c(4, 3, 1), c(5, 6, 7), c(6, 8, 7), c(8, 6, 5), c(5, 7, 8)) mesh <- makeMesh(vertices, faces=faces) doesBoundVolume(mesh) # FALSE getVolume(mesh) # NA mesh_bv <- orientToBoundVolume(mesh) doesBoundVolume(mesh_bv) # TRUE getVolume(mesh_bv)library(SurfaceMesh) vertices <- rbind( c(0, 0, 0), c(2, 2, 0), c(2, 0, 2), c(0, 2, 2), c(3, 3, 3), c(5, 5, 3), c(5, 3, 5), c(3, 5, 5)) faces <- rbind( c(3, 2, 1), c(3, 4, 2), c(1, 2, 4), c(4, 3, 1), c(5, 6, 7), c(6, 8, 7), c(8, 6, 5), c(5, 7, 8)) mesh <- makeMesh(vertices, faces=faces) doesBoundVolume(mesh) # FALSE getVolume(mesh) # NA mesh_bv <- orientToBoundVolume(mesh) doesBoundVolume(mesh_bv) # TRUE getVolume(mesh_bv)
Does the given 3D surface mesh self intersect?
doesSelfIntersect(x)doesSelfIntersect(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See removeSelfIntersections for removing
self-intersections.
library(SurfaceMesh) verts1 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), 0.3) }, numeric(3L)) verts2 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), -0.3) }, numeric(3L)) vertices <- t(cbind(verts1, verts2)) pentagramms <- rbind(1L:5L, 6L:10L) rectangles <- rbind( c(1L, 2L, 7L, 6L), c(2L, 3L, 8L, 7L), c(3L, 4L, 9L, 8L), c(4L, 5L, 10L, 9L), c(5L, 1L, 6L, 10L)) faces <- list( pentagramms[1L, ], pentagramms[2L, ], rectangles[1L, ], rectangles[2L, ], rectangles[3L, ], rectangles[4L, ], rectangles[5L, ]) mesh <- makeMesh(vertices, faces) doesSelfIntersect(mesh)library(SurfaceMesh) verts1 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), 0.3) }, numeric(3L)) verts2 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), -0.3) }, numeric(3L)) vertices <- t(cbind(verts1, verts2)) pentagramms <- rbind(1L:5L, 6L:10L) rectangles <- rbind( c(1L, 2L, 7L, 6L), c(2L, 3L, 8L, 7L), c(3L, 4L, 9L, 8L), c(4L, 5L, 10L, 9L), c(5L, 1L, 6L, 10L)) faces <- list( pentagramms[1L, ], pentagramms[2L, ], rectangles[1L, ], rectangles[2L, ], rectangles[3L, ], rectangles[4L, ], rectangles[5L, ]) mesh <- makeMesh(vertices, faces) doesSelfIntersect(mesh)
Try to fill boundary holes in a 3D surface mesh.
fillBoundaryHoles( x, fairHole = TRUE, maxNumHoles = 10L, normals = FALSE, verbose = FALSE )fillBoundaryHoles( x, fairHole = TRUE, maxNumHoles = 10L, normals = FALSE, verbose = FALSE )
x |
A |
fairHole |
Boolean. Use CGAL |
maxNumHoles |
|
normals |
Boolean. Return vertex normals? |
verbose |
Boolean. Print out messages about mesh processing? |
See https://www.cgal.org/2025/06/13/autorefine-and-snap/ and https://doc.cgal.org/latest/PMP_Mesh_repair/ for details. If faces are not already triangle, the mesh is first triangulated.
CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See removeSelfIntersections for removing
self-intersections.
library(SurfaceMesh) library(rgl) f_mesh <- system.file("extdata", "dataCornerHole.off", package="SurfaceMesh") mesh <- makeMesh(f_mesh, triangulate=TRUE, verbose=TRUE) mesh_rgl <- toRGL(mesh) mesh_fill <- fillBoundaryHoles(mesh, verbose=TRUE) mesh_fill_rgl <- toRGL(mesh_fill) mfrow3d(1, 2) view3d(70, 25, zoom=0.8) shade3d(mesh_rgl, col="gray") next3d() view3d(70, 25, zoom=0.8) shade3d(mesh_fill_rgl, col="gray")library(SurfaceMesh) library(rgl) f_mesh <- system.file("extdata", "dataCornerHole.off", package="SurfaceMesh") mesh <- makeMesh(f_mesh, triangulate=TRUE, verbose=TRUE) mesh_rgl <- toRGL(mesh) mesh_fill <- fillBoundaryHoles(mesh, verbose=TRUE) mesh_fill_rgl <- toRGL(mesh_fill) mfrow3d(1, 2) view3d(70, 25, zoom=0.8) shade3d(mesh_rgl, col="gray") next3d() view3d(70, 25, zoom=0.8) shade3d(mesh_fill_rgl, col="gray")
Get the surface area of a given 3D surface mesh.
getArea(x)getArea(x)
x |
A |
numeric. The mesh area.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See getVolume for the volume bounded by the mesh.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) getArea(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) getArea(mesh)
Computes the average spacing of all input points to their
nNeighbors nearest neighbor points. This provides an order of a
point set density, useful in a surface reconstruction pipeline.
getAverageSpacing(x, nNeighbors = 6L)getAverageSpacing(x, nNeighbors = 6L)
x |
A |
nNeighbors |
|
See https://doc.cgal.org/latest/Point_set_processing_3/ for details.
The average spacing.
removeOutliers,
reconstructPoisson,
reconstructSSS,
alphaWrap
library(SurfaceMesh) library(rgl) pts <- matrix(rnorm(120L), ncol=3) getAverageSpacing(pts, nNeighbors=6L)library(SurfaceMesh) library(rgl) pts <- matrix(rnorm(120L), ncol=3) getAverageSpacing(pts, nNeighbors=6L)
Get the axis-parallel or optimal (oriented) bounding box of a 3D surface mesh.
getBoundingBox( x, oriented = FALSE, out = c("CGALmesh", "rgl", "Points"), triangulate = FALSE, normals = FALSE )getBoundingBox( x, oriented = FALSE, out = c("CGALmesh", "rgl", "Points"), triangulate = FALSE, normals = FALSE )
x |
A |
oriented |
Boolean. Get the optimal (oriented) bounding box? |
out |
|
triangulate |
Boolean. Triangulate the faces of the bounding box? |
normals |
Boolean. Return vertex normals? |
A CGALmesh object, a mesh3d object,
or a matrix with the corner points as rows.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See getConvexHull for the convex hull,
getBoundingSphere for the bounding sphere,
getBoundingEll for the bounding ellipse.
library(SurfaceMesh) library(rgl) mesh1 <- makeMesh(dataTubularKnot) mesh1_rgl <- toRGL(mesh1) bb1_rgl <- getBoundingBox(mesh1[["vertices"]], out="rgl") open3d(windowRect=50 + c(0, 0, 400, 400)) view3d(0, 30, zoom=0.9) shade3d(mesh1_rgl, color="seashell") wire3d(bb1_rgl) mesh2 <- dataHeart1 mesh2_rgl <- toRGL(mesh2) bb2_rgl <- getBoundingBox(mesh2[["vertices"]], oriented=TRUE, out="rgl") open3d(windowRect=50 + c(0, 0, 400, 400)) shade3d(mesh2_rgl, color="seashell") wire3d(bb2_rgl)library(SurfaceMesh) library(rgl) mesh1 <- makeMesh(dataTubularKnot) mesh1_rgl <- toRGL(mesh1) bb1_rgl <- getBoundingBox(mesh1[["vertices"]], out="rgl") open3d(windowRect=50 + c(0, 0, 400, 400)) view3d(0, 30, zoom=0.9) shade3d(mesh1_rgl, color="seashell") wire3d(bb1_rgl) mesh2 <- dataHeart1 mesh2_rgl <- toRGL(mesh2) bb2_rgl <- getBoundingBox(mesh2[["vertices"]], oriented=TRUE, out="rgl") open3d(windowRect=50 + c(0, 0, 400, 400)) shade3d(mesh2_rgl, color="seashell") wire3d(bb2_rgl)
Get the approximate bounding ellipsoid of a given set of 3D points.
getBoundingEll( x, out = c("CGALmesh", "rgl", "CtrRadDir"), nIter = 3L, eps = 0.01, normals = FALSE )getBoundingEll( x, out = c("CGALmesh", "rgl", "CtrRadDir"), nIter = 3L, eps = 0.01, normals = FALSE )
x |
A |
out |
|
nIter |
|
eps |
|
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Bounding_volumes/ for details.
A list with components "center", "lengths",
and "directions";
a CGALmesh object; or a mesh3d object -
depending on argument out.
See getBoundingBox for the bounding box,
getBoundingSphere for the bounding sphere,
getConvexHull for the convex hull.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataHeart1) mesh_rgl <- toRGL(mesh) bell_rgl <- getBoundingEll(mesh, out="rgl", eps=0.01) shade3d(mesh_rgl, color="lightgreen") wire3d(bell_rgl)library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataHeart1) mesh_rgl <- toRGL(mesh) bell_rgl <- getBoundingEll(mesh, out="rgl", eps=0.01) shade3d(mesh_rgl, color="lightgreen") wire3d(bell_rgl)
Get the bounding sphere of a given set of 3D points.
getBoundingSphere( x, out = c("CGALmesh", "rgl", "CtrRad"), nIter = 3L, normals = FALSE )getBoundingSphere( x, out = c("CGALmesh", "rgl", "CtrRad"), nIter = 3L, normals = FALSE )
x |
A |
out |
|
nIter |
|
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Bounding_volumes/ for details.
A list with components "center" and "radius",
a CGALmesh object; or a mesh3d object -
depending on argument out.
See getBoundingBox for the bounding box,
getBoundingEll for the bounding ellipse,
getConvexHull for the convex hull.
library(SurfaceMesh) library(rgl) bs_rgl <- getBoundingSphere(dataToroHelix, out="rgl") shade3d(dataToroHelix, color="plum2") wire3d(bs_rgl)library(SurfaceMesh) library(rgl) bs_rgl <- getBoundingSphere(dataToroHelix, out="rgl") shade3d(dataToroHelix, color="plum2") wire3d(bs_rgl)
Get the centroid (center of mass) of a given 3D surface mesh.
getCentroid(x)getCentroid(x)
x |
A |
numeric. 3-vector with the coordinates of the mesh centroid.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) getCentroid(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) getCentroid(mesh)
Get the convex hull of a given set of 3D points using the quickhull algorithm.
getConvexHull(x, normals = FALSE)getConvexHull(x, normals = FALSE)
x |
|
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Convex_hull_3/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See getBoundingBox for the bounding box,
getBoundingSphere for the bounding sphere,
getBoundingEll for the bounding ellipse.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataHopfTorus) mesh_rgl <- toRGL(mesh) hull <- getConvexHull(mesh[["vertices"]]) hull_rgl <- toRGL(hull) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(hull_rgl)library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataHopfTorus) mesh_rgl <- toRGL(mesh) hull <- getConvexHull(mesh[["vertices"]]) hull_rgl <- toRGL(hull) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(hull_rgl)
Calculates the Euclidean distance between the two respective centers of mass of two 3D surface meshes.
getDCOM(mesh1, mesh2)getDCOM(mesh1, mesh2)
mesh1 |
A |
mesh2 |
A |
The Euclidean distance between the two respective centers of mass.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See getCentroid for calculating the center of mass.
library(SurfaceMesh) getDCOM(dataHeart1, dataHeart2)library(SurfaceMesh) getDCOM(dataHeart1, dataHeart2)
Calculate the Euclidean distance of a set of points to a given 3D surface mesh.
getDistance(x, points)getDistance(x, points)
x |
A |
points |
|
numeric vector: The distance of each point in points
to the mesh x.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) points <- matrix(2*runif(3*4), ncol=3) getDistance(mesh, points)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) points <- matrix(2*runif(3*4), ncol=3) getDistance(mesh, points)
Hausdorff distance between two 3D surface meshes. The approximate distance, the distance estimate with a given error bound, or the quantile Hausdorff distance, e.g., HD95.
getHausdorff(mesh1, mesh2, symmetric = TRUE, errBound, p, ...)getHausdorff(mesh1, mesh2, symmetric = TRUE, errBound, p, ...)
mesh1 |
A |
mesh2 |
A |
symmetric |
Boolean. Report the symmetric Hausdorff distance? |
errBound |
A positive number. If provided, upper bound on the
error of the Hausdorff distance estimate. If missing, and |
p |
A number in |
... |
Options for random sampling passed to
|
The quantile Hausdorff distance approximates the Hausdorff distance using a quantile (often the 95th percentile, i.e. "HD95") of the distances from a random sample of points on one mesh to the other mesh, instead of their maximum. This is less sensitive to small, isolated outlying regions than the full Hausdorff distance.
See https://metrics-reloaded.dkfz.de/metric-library/hd and https://metrics-reloaded.dkfz.de/metric-library/xhd for more information on the (quantile) Hausdorff distance. See https://doc.cgal.org/latest/Polygon_mesh_processing/index.html#PMPDistance for implementation details.
A number. For the apprixmate and quantile distance, the algorithm uses random sampling, and thus the result can vary.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See getSurfaceDist for other surface distance metrics, and
getJSCDSC for volume-overlap based mesh similarity metrics (JSC, DSC).
library(SurfaceMesh) ## approximate symmetric Hausdorff distance getHausdorff(dataHeart1, dataHeart2, symmetric=TRUE) ## estimate with error bound getHausdorff(dataHeart1, dataHeart2, symmetric=TRUE, errBound=0.01) ## quantile Hausdorff distance getHausdorff(dataHeart1, dataHeart2, symmetric=TRUE, p=0.95)library(SurfaceMesh) ## approximate symmetric Hausdorff distance getHausdorff(dataHeart1, dataHeart2, symmetric=TRUE) ## estimate with error bound getHausdorff(dataHeart1, dataHeart2, symmetric=TRUE, errBound=0.01) ## quantile Hausdorff distance getHausdorff(dataHeart1, dataHeart2, symmetric=TRUE, p=0.95)
Compute the Jaccard Similarity Coefficient (JSC, also known as Intersection over Union, IoU) and the Dice Similarity Coefficient (DSC) for the respective volumes defined by two 3D surface meshes.
getJSCDSC(mesh1, mesh2, repairSoup = TRUE, verbose = FALSE)getJSCDSC(mesh1, mesh2, repairSoup = TRUE, verbose = FALSE)
mesh1 |
Either a |
mesh2 |
Either a |
repairSoup |
Boolean. Clean the input meshes (merging duplicated
vertices, duplicated faces, removing isolated vertices)? Set to
|
verbose |
Boolean. Print out messages about mesh processing? |
See https://metrics-reloaded.dkfz.de/metric-library/dsc and https://metrics-reloaded.dkfz.de/metric-library/intersection_over_union for details.
A list with five components: "Vol1", "Vol2",
"VolI", "VolU", "JSC" (IoU) and "DSC".
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See also boolUnion,
boolIntersection, and
boolDifference for Boolean mesh operations.
library(SurfaceMesh) library(rgl) mesh1_rgl <- cube3d() # (from the rgl package) mesh2_rgl <- translate3d(cube3d(), 1, 1, 1) getJSCDSC(mesh1_rgl, mesh2_rgl)library(SurfaceMesh) library(rgl) mesh1_rgl <- cube3d() # (from the rgl package) mesh2_rgl <- translate3d(cube3d(), 1, 1, 1) getJSCDSC(mesh1_rgl, mesh2_rgl)
Returns a function which estimates normals for a 3D point cloud.
getNormalsFun(x, method = c("PCA", "Jet"))getNormalsFun(x, method = c("PCA", "Jet"))
x |
|
method |
One of |
See https://doc.cgal.org/latest/Point_set_processing_3/ for details.
The getNormalsFun function is intended to be used in the
reconstructPoisson function. If you want to use it for
another purpose, be careful because the function it returns does not
check the matrix it takes as argument.
A function which takes one argument: a numeric matrix with three columns, each row represents a point, and the function returns a matrix of the same size as the input matrix, with each row giving one unit normal per point.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) fun <- getNormalsFun(6) mesh_psr <- reconstructPoisson(mesh[["vertices"]], normalsFun=fun, smAngle=10, smRadius=1.5, smDistance=0.3) mesh_psr_rgl <- toRGL(mesh_psr) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_psr_rgl)library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) fun <- getNormalsFun(6) mesh_psr <- reconstructPoisson(mesh[["vertices"]], normalsFun=fun, smAngle=10, smRadius=1.5, smDistance=0.3) mesh_psr_rgl <- toRGL(mesh_psr) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_psr_rgl)
Quantile Hausdorff distance (HD), average symmetric surface distance (ASSD), and root mean squared error (RMSE) for the surface distance between two 3D surface meshes.
getSurfaceDist( mesh1, mesh2, returnDists = FALSE, symmetric = TRUE, p = 0.95, method = c("random", "grid", "mc"), sampleVerts = TRUE, sampleEdges = TRUE, sampleFaces = TRUE, gridSpacing = NULL, ptsOnEdges = NULL, ptsOnFaces = NULL, ptsPerDist = NULL, ptsPerEdge = NULL, ptsPerArea = NULL, ptsPerFace = NULL )getSurfaceDist( mesh1, mesh2, returnDists = FALSE, symmetric = TRUE, p = 0.95, method = c("random", "grid", "mc"), sampleVerts = TRUE, sampleEdges = TRUE, sampleFaces = TRUE, gridSpacing = NULL, ptsOnEdges = NULL, ptsOnFaces = NULL, ptsPerDist = NULL, ptsPerEdge = NULL, ptsPerArea = NULL, ptsPerFace = NULL )
mesh1 |
A |
mesh2 |
A |
returnDists |
Boolean. Return the sampled distances from mesh 1 to 2, and from 2 to 1? |
symmetric |
Boolean. Report the symmetric quantile Hausdorff distance? |
p |
A number in |
method |
|
sampleVerts |
Boolean. Do sample vertices? |
sampleEdges |
Boolean. Do sample edges? |
sampleFaces |
Boolean. Do sample faces? |
gridSpacing |
|
ptsOnEdges |
|
ptsOnFaces |
|
ptsPerDist |
|
ptsPerEdge |
|
ptsPerArea |
|
ptsPerFace |
|
See getHausdorff for details on the quantile
Hausdorff distance, https://metrics-reloaded.dkfz.de/metric-library/assd for ASSD.
Inspired by http://vcglib.net/metro.html.
For details on sampling options, see
https://doc.cgal.org/latest/Polygon_mesh_processing/group__PMP__distance__grp.html.
A list with components "HDq" (quantile Hausdorff distance),
"ASSD" (average symmetric surface distance),
"RMSE" (root mean squared error).
For returnDists=TRUE also "dists12" and "dists21".
The algorithm uses random sampling, so the result can vary.
See getHausdorff for the (approximate) Hausdorff distance, and
getJSCDSC for volume-overlap based mesh similarity metrics (JSC, DSC).
library(SurfaceMesh) getSurfaceDist(dataHeart1, dataHeart2, p=0.95, ptsOnFaces=1000L)library(SurfaceMesh) getSurfaceDist(dataHeart1, dataHeart2, p=0.95, ptsOnFaces=1000L)
Get the vertex normals of a 3D surface mesh.
getVertexNormals(x)getVertexNormals(x)
x |
A |
Note that this function is not really necessary as the vertex
normals are simply stored in component "normals" of the
CGALmesh object on the R side.
However, importing vertex normals to the C++ / CGAL side, and then
exporting them to the R side is a test case for working with CGAL
property maps that may be useful in the future.
The numeric matrix of normals attached to the vertices of the mesh.
NULL if there are no vertex normals.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) mesh <- makeMeshValid(dataSphere, normals=TRUE) vn <- getVertexNormals(mesh) head(vn)library(SurfaceMesh) mesh <- makeMeshValid(dataSphere, normals=TRUE) vn <- getVertexNormals(mesh) head(vn)
Get the volume bounded by a closed 3D surface mesh.
getVolume(x)getVolume(x)
x |
A |
numeric. The mesh volume - if mesh bounds a volume.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See getArea for the mesh area.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) getVolume(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) getVolume(mesh)
Check whether the given 3D surface mesh has garbage, i.e., there is a mismatch between faces and vertices.
hasGarbage(x)hasGarbage(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See isValid for checking if the mesh is valid.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism) hasGarbage(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism) hasGarbage(mesh)
Check whether the given 3D surface mesh is closed (watertight).
isClosed(x)isClosed(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See fillBoundaryHoles for a function to fill holes.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) isClosed(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) isClosed(mesh)
Check whether the given 3D surface mesh has a positive (outward) orientation.
isOutwardOriented(x)isOutwardOriented(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
reverseFaceOrientations,
orientToBoundVolume.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) isOutwardOriented(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) isOutwardOriented(mesh)
Check whether the given 3D surface mesh is a quad mesh.
isQuad(x)isQuad(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See isTriangle to check whether mesh is a triangle mesh.
library(SurfaceMesh) f_mesh <- system.file("extdata", "dataCorner.off", package="SurfaceMesh") mesh <- makeMesh(f_mesh) isQuad(mesh)library(SurfaceMesh) f_mesh <- system.file("extdata", "dataCorner.off", package="SurfaceMesh") mesh <- makeMesh(f_mesh) isQuad(mesh)
Check whether the given 3D surface mesh is a triangle mesh.
isTriangle(x)isTriangle(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See isQuad to check whether mesh is a quad mesh.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=FALSE) isTriangle(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=FALSE) isTriangle(mesh)
Check whether the given mesh is a valid 3D surface mesh.
isValid(x)isValid(x)
x |
A |
TRUE or FALSE.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See hasGarbage to check whether mesh has garbage.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism) isValid(mesh)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism) isValid(mesh)
Make a 3D surface mesh from an input file,
from an existing rgl mesh3d object,
or from given vertices and faces. The mesh is optionally cleaned:
duplicated vertices or faces are merged, and isolated vertices are removed.
The returned faces are coherently oriented, normals are computed if requested, and
triangulation is performed if requested.
makeMesh( x, faces, triangulate = FALSE, repairSoup = TRUE, removeIntersections = FALSE, removeMethod = c("auto", "auto_snap"), fillHoles = FALSE, fairHole = FALSE, maxNumHoles = 5L, normals = FALSE, verbose = FALSE )makeMesh( x, faces, triangulate = FALSE, repairSoup = TRUE, removeIntersections = FALSE, removeMethod = c("auto", "auto_snap"), fillHoles = FALSE, fairHole = FALSE, maxNumHoles = 5L, normals = FALSE, verbose = FALSE )
x |
One of three options: 1) A numeric matrix with 3 columns providing the
coordinates of the vertices of the mesh. 2) Either a list containing the components
|
faces |
When |
triangulate |
Boolean. Triangulate the faces? Ignored if faces are already triangle. |
repairSoup |
Boolean. Clean the mesh (merging duplicated vertices and duplicated faces, removing isolated vertices)? |
removeIntersections |
Boolean. Try to remove self-intersections? |
removeMethod |
|
fillHoles |
Boolean. Try to fill boundary holes? |
fairHole |
Boolean. Use CGAL |
maxNumHoles |
|
normals |
Boolean. Compute vertex normals? |
verbose |
Boolean. Print out messages about mesh processing? |
CAVE: Y-axis direction is front-back in rgl (OpenGL)
convention but down-up in CGAL convention. This is ignored here when
importing a mesh3d object.
A list of class CGALmesh giving the vertices, the edges, the faces
of the mesh, the exterior edges, the exterior vertices, and optionally the
vertex normals.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See plotEdges for details about the edges
returned by this function.
See makeMeshValid for a similar function that assumes
that the input defines a valid mesh, and does not perform mesh repair to gain
some speed.
See toRGL for conversion to class
mesh3d from package rgl.
library(SurfaceMesh) library(rgl) ## make mesh based on file f_mesh <- system.file("extdata", "dataHeart3.ply", package="SurfaceMesh") mesh1 <- makeMesh(f_mesh, verbose=TRUE) mesh1_rgl <- toRGL(mesh1) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh1_rgl) ## make mesh from vertices and faces ## tetrahedron with ill-oriented faces vertices <- rbind( c(-1, -1, -1), c(1, 1, -1), c(1, -1, 1), c(-1, 1, 1)) faces <- rbind( c(1, 2, 3), c(3, 4, 2), c(4, 2, 1), c(4, 3, 1)) mesh2 <- makeMesh(vertices, faces, verbose=TRUE) mesh2_rgl <- toRGL(mesh2) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh2_rgl) ## illustration of the `triangulate` option ## the faces of the truncated icosahedron are hexagonal or pentagonal: dataTruncIcosahedron[["faces"]] # so we triangulate them: mesh3 <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) mesh3_rgl <- toRGL(mesh3) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh3_rgl)library(SurfaceMesh) library(rgl) ## make mesh based on file f_mesh <- system.file("extdata", "dataHeart3.ply", package="SurfaceMesh") mesh1 <- makeMesh(f_mesh, verbose=TRUE) mesh1_rgl <- toRGL(mesh1) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh1_rgl) ## make mesh from vertices and faces ## tetrahedron with ill-oriented faces vertices <- rbind( c(-1, -1, -1), c(1, 1, -1), c(1, -1, 1), c(-1, 1, 1)) faces <- rbind( c(1, 2, 3), c(3, 4, 2), c(4, 2, 1), c(4, 3, 1)) mesh2 <- makeMesh(vertices, faces, verbose=TRUE) mesh2_rgl <- toRGL(mesh2) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh2_rgl) ## illustration of the `triangulate` option ## the faces of the truncated icosahedron are hexagonal or pentagonal: dataTruncIcosahedron[["faces"]] # so we triangulate them: mesh3 <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) mesh3_rgl <- toRGL(mesh3) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh3_rgl)
Make a 3D surface mesh from an input file,
from an existing rgl mesh3d object, or
from given vertices and faces - assuming that the input defines a valid mesh.
Omitted validity checks save some processing time.
The returned faces are coherently oriented (if possible),
normals are computed if requested, triangulation is performed if requested.
makeMeshValid( x, faces, soup = FALSE, triangulate = FALSE, normals = FALSE, verbose = FALSE )makeMeshValid( x, faces, soup = FALSE, triangulate = FALSE, normals = FALSE, verbose = FALSE )
x |
One of three options: 1) A numeric matrix with three columns providing the
coordinates of the vertices of the mesh. 2) Either a list containing the components
|
faces |
When |
soup |
Boolean. Assume a polygon soup? If |
triangulate |
Boolean. Triangulate the faces? Ignored if faces are already triangle. |
normals |
Boolean. Compute vertex normals? |
verbose |
Boolean. Print out messages about mesh processing? |
CAVE: Y-axis direction is front-back in rgl (OpenGL)
convention but down-up in CGAL convention. This is ignored here when
importing a mesh3d object.
A list of class CGALmesh giving the vertices, the edges, the faces
of the mesh, the exterior edges, the exterior vertices, and optionally the normals.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See plotEdges for details about the edges
returned by this function.
See makeMesh for a similar function that does not assume
that the input defines a valid mesh, and may perform mesh repair.
See toRGL for conversion to class
mesh3d from package rgl.
library(SurfaceMesh) library(rgl) ## mesh from file f_mesh <- system.file("extdata", "dataCorner.off", package="SurfaceMesh") mesh1 <- makeMeshValid(f_mesh, soup=TRUE, triangulate=TRUE) mesh1_rgl <- toRGL(mesh1) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh1_rgl) ## mesh from vertices, faces head(dataPentaPrism[["vertices"]]) head(dataPentaPrism[["faces"]]) mesh2 <- makeMeshValid(dataPentaPrism, soup=TRUE, triangulate=TRUE) mesh2_rgl <- toRGL(mesh2) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh2_rgl)library(SurfaceMesh) library(rgl) ## mesh from file f_mesh <- system.file("extdata", "dataCorner.off", package="SurfaceMesh") mesh1 <- makeMeshValid(f_mesh, soup=TRUE, triangulate=TRUE) mesh1_rgl <- toRGL(mesh1) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh1_rgl) ## mesh from vertices, faces head(dataPentaPrism[["vertices"]]) head(dataPentaPrism[["faces"]]) mesh2 <- makeMeshValid(dataPentaPrism, soup=TRUE, triangulate=TRUE) mesh2_rgl <- toRGL(mesh2) open3d(windowRect=c(50, 50, 562, 562)) wire3d(mesh2_rgl)
Generate a triangle surface smesh of a 3D ellipsoid.
meshEllipsoid( ctr = c(0, 0, 0), r = c(1, 1, 1), dirs = diag(nrow = 3L), euler, nIter = 3L )meshEllipsoid( ctr = c(0, 0, 0), r = c(1, 1, 1), dirs = diag(nrow = 3L), euler, nIter = 3L )
ctr |
|
r |
|
dirs |
|
euler |
|
nIter |
|
A mesh3d object.
library(SurfaceMesh) library(rgl) mesh_rgl <- meshEllipsoid(c(0, 0, 0), r=c(1, 0.5, 0.25)) wire3d(mesh_rgl)library(SurfaceMesh) library(rgl) mesh_rgl <- meshEllipsoid(c(0, 0, 0), r=c(1, 0.5, 0.25)) wire3d(mesh_rgl)
Generate a surface mesh of an iso-oriented cuboid, i.e. with edges parallel to the axes.
meshIsoCuboid(lo, up)meshIsoCuboid(lo, up)
lo |
|
up |
|
CAVE: Y-axis direction is assumed to be front-back, corresponding to rgl (OpenGL) convention.
A rgl mesh, i.e. a mesh3d object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) lo <- c(-4, -2, -1) up <- c( 4, 2, 1) cuboid_rgl <- meshIsoCuboid(lo, up) wire3d(cuboid_rgl)library(SurfaceMesh) library(rgl) lo <- c(-4, -2, -1) up <- c( 4, 2, 1) cuboid_rgl <- meshIsoCuboid(lo, up) wire3d(cuboid_rgl)
Generate a triangle surface mesh of a 3D sphere.
meshSphere(ctr = c(0, 0, 0), r = 1, nIter = 3L)meshSphere(ctr = c(0, 0, 0), r = 1, nIter = 3L)
ctr |
|
r |
|
nIter |
|
A mesh3d object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) mesh_rgl <- meshSphere(c(0, 0, 0), r=2) wire3d(mesh_rgl)library(SurfaceMesh) library(rgl) mesh_rgl <- meshSphere(c(0, 0, 0), r=2) wire3d(mesh_rgl)
Orient a given 3D surface mesh to bound a volume.
orientToBoundVolume(x, normals = FALSE)orientToBoundVolume(x, normals = FALSE)
x |
A |
normals |
Boolean. Return vertex normals? |
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
doesBoundVolume to check whether mesh
bounds a volume and getVolume to get the
volume bounded by the mesh.
library(SurfaceMesh) ## Two tetraeders ## one with positive orientation ## one with negative orientation vertices <- rbind( c(0, 0, 0), c(2, 2, 0), c(2, 0, 2), c(0, 2, 2), c(3, 3, 3), c(5, 5, 3), c(5, 3, 5), c(3, 5, 5)) faces <- rbind( c(3, 2, 1), c(3, 4, 2), c(1, 2, 4), c(4, 3, 1), c(5, 6, 7), c(6, 8, 7), c(8, 6, 5), c(5, 7, 8)) mesh <- makeMesh(vertices, faces=faces) doesBoundVolume(mesh) # FALSE getVolume(mesh) # NA mesh_bv <- orientToBoundVolume(mesh) doesBoundVolume(mesh_bv) # TRUE getVolume(mesh_bv)library(SurfaceMesh) ## Two tetraeders ## one with positive orientation ## one with negative orientation vertices <- rbind( c(0, 0, 0), c(2, 2, 0), c(2, 0, 2), c(0, 2, 2), c(3, 3, 3), c(5, 5, 3), c(5, 3, 5), c(3, 5, 5)) faces <- rbind( c(3, 2, 1), c(3, 4, 2), c(1, 2, 4), c(4, 3, 1), c(5, 6, 7), c(6, 8, 7), c(8, 6, 5), c(5, 7, 8)) mesh <- makeMesh(vertices, faces=faces) doesBoundVolume(mesh) # FALSE getVolume(mesh) # NA mesh_bv <- orientToBoundVolume(mesh) doesBoundVolume(mesh_bv) # TRUE getVolume(mesh_bv)
Plot the given edges with functions from package rgl.
plotEdges( x, edges, color = "black", lwd = 2, edgesAsTubes = TRUE, tubesRadius = 0.03, verticesAsSpheres = TRUE, only, spheresRadius = 0.05, spheresColor = color )plotEdges( x, edges, color = "black", lwd = 2, edgesAsTubes = TRUE, tubesRadius = 0.03, verticesAsSpheres = TRUE, only, spheresRadius = 0.05, spheresColor = color )
x |
A matrix with 3 columns giving the coordinates of the vertices. |
edges |
|
color |
|
lwd |
Positive number. Line width. Ignored if |
edgesAsTubes |
Boolean. Draw edges as tubes? |
tubesRadius |
Positive number. Radius of the tubes when |
verticesAsSpheres |
Boolean. Draw vertices as spheres? |
only |
|
spheresRadius |
The radius of the spheres when
|
spheresColor |
|
No value.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) # triangulate and plot the pentagrammic prism mesh mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) mesh_rgl <- toRGL(mesh) open3d(windowRect=c(50, 50, 562, 562), zoom=0.9) shade3d(mesh_rgl, color="navy") plotEdges(mesh[["vertices"]], mesh[["edgesExterior"]], color ="gold", tubesRadius =0.02, spheresRadius=0.02)library(SurfaceMesh) library(rgl) # triangulate and plot the pentagrammic prism mesh mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) mesh_rgl <- toRGL(mesh) open3d(windowRect=c(50, 50, 562, 562), zoom=0.9) shade3d(mesh_rgl, color="navy") plotEdges(mesh[["vertices"]], mesh[["edgesExterior"]], color ="gold", tubesRadius =0.02, spheresRadius=0.02)
Read mesh vertices and faces from a file.
readMesh(x, method = c("soup", "mesh"), normals = FALSE, verbose = FALSE)readMesh(x, method = c("soup", "mesh"), normals = FALSE, verbose = FALSE)
x |
Path to the mesh file. Supported formats are |
method |
Either |
normals |
Boolean. Return vertex normals for |
verbose |
Boolean. Print out messages about mesh processing? |
For method="soup": A list with two components: vertices,
a numeric matrix with three columns, and faces, either a list of
integer vectors or, in the case if all faces have the same number of sides,
an integer matrix.
For method="mesh": A list of class CGALmesh giving the vertices,
the edges, the faces of the mesh, the exterior edges, the exterior vertices and
optionally the normals.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See makeMesh and makeMeshValid
for creating a CGALmesh object.
library(SurfaceMesh) library(rgl) f_ply <- system.file("extdata", "dataHeart3.ply", package="SurfaceMesh") mesh_vf <- readMesh(f_ply, method="soup") mesh <- makeMesh(mesh_vf, normals=TRUE) mesh_rgl <- toRGL(mesh) open3d(windowRect=c(50, 50, 562, 562)) view3d(0, 0, zoom=0.8) shade3d(mesh_rgl, color="palevioletred")library(SurfaceMesh) library(rgl) f_ply <- system.file("extdata", "dataHeart3.ply", package="SurfaceMesh") mesh_vf <- readMesh(f_ply, method="soup") mesh <- makeMesh(mesh_vf, normals=TRUE) mesh_rgl <- toRGL(mesh) open3d(windowRect=c(50, 50, 562, 562)) view3d(0, 0, zoom=0.8) shade3d(mesh_rgl, color="palevioletred")
Advancing front surface reconstruction of a 3D surface mesh from a cloud of 3D points.
reconstructAFS(x, nNeighbors, repairSoup = TRUE, normals = FALSE)reconstructAFS(x, nNeighbors, repairSoup = TRUE, normals = FALSE)
x |
A |
nNeighbors |
Optional integer >= 2. If specified, the point cloud is smoothed before the reconstruction, using this integer as the number of neighbors for the smoothing. Note that this smoothing preprocessing relocates the points and then should not be used if the points have been sampled without noise on the surface. |
repairSoup |
Boolean. Clean the mesh (merging duplicated vertices, duplicated faces, removing isolated vertices)? |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Advancing_front_surface_reconstruction/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
removeOutliers,
reconstructSSS,
reconstructPoisson, alphaWrap
library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_afs <- reconstructAFS(mesh[["vertices"]], nNeighbors=30L) mesh_afs_rgl <- toRGL(mesh_afs) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_afs_rgl, col="gray")library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_afs <- reconstructAFS(mesh[["vertices"]], nNeighbors=30L) mesh_afs_rgl <- toRGL(mesh_afs) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_afs_rgl, col="gray")
Poisson reconstruction of a 3D surface mesh from a cloud of 3D points.
reconstructPoisson( x, normalsFun = getNormalsFun(6L), spacing, smAngle = 20, smRadius = 30, smDistance = 0.375, normals = FALSE )reconstructPoisson( x, normalsFun = getNormalsFun(6L), spacing, smAngle = 20, smRadius = 30, smDistance = 0.375, normals = FALSE )
x |
A |
normalsFun |
A function that accepts a matrix with 3D points and uses it to
return a matrix with normals. Such a function is returned by
|
spacing |
Optional size parameter. Smaller values increase the precision of the output mesh at the cost of higher computation time. If missing, an average spacing is chosen as a reasonable default value. |
smAngle |
Bound for the minimum facet angle in degrees. |
smRadius |
Relative bound for the radius of the surface Delaunay balls. |
smDistance |
Relative bound for the center-center distances. |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Poisson_surface_reconstruction_3/ for details. Performs well if the aim is to approximate a noisy point cloud with a smooth surface. Not appropriate if the surface is expected to interpolate the input points.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
removeOutliers,
reconstructAFS,
reconstructSSS,
alphaWrap
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataSeptuaginta) mesh_rgl <- toRGL(mesh) mesh_psr <- reconstructPoisson(mesh[["vertices"]], normalsFun=getNormalsFun(6L), smAngle=20, smRadius=1, smDistance=20) mesh_psr_rgl <- toRGL(mesh_psr) mfrow3d(1, 2) shade3d(mesh_rgl, col="gray") next3d() shade3d(mesh_psr_rgl, col="gray")library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataSeptuaginta) mesh_rgl <- toRGL(mesh) mesh_psr <- reconstructPoisson(mesh[["vertices"]], normalsFun=getNormalsFun(6L), smAngle=20, smRadius=1, smDistance=20) mesh_psr_rgl <- toRGL(mesh_psr) mfrow3d(1, 2) shade3d(mesh_rgl, col="gray") next3d() shade3d(mesh_psr_rgl, col="gray")
Scale-space surface reconstruction of a 3D surface mesh from a cloud of 3D points.
reconstructSSS( x, nScaleIter = 1L, nNeighbors = 12L, nSamples = 300L, separateShells = FALSE, forceManifold = TRUE, borderAngle = 45, repairSoup = TRUE, normals = FALSE )reconstructSSS( x, nScaleIter = 1L, nNeighbors = 12L, nSamples = 300L, separateShells = FALSE, forceManifold = TRUE, borderAngle = 45, repairSoup = TRUE, normals = FALSE )
x |
A |
nScaleIter |
Positive integer. Number of iterations used to increase the scale. |
nNeighbors |
Positive integer. Number of neighbors used to smooth the point cloud. |
nSamples |
Positive integer. Number of samples used to smooth the point cloud. |
separateShells |
Boolean. Separate the shells? |
forceManifold |
Boolean. Force a manifold output mesh? |
borderAngle |
Bound on the angle in degrees used to detect border edges. |
repairSoup |
Boolean. Clean the mesh (merging duplicated vertices, duplicated faces, removing isolated vertices)? |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Scale_space_reconstruction_3/ for details. A good choice if the input point cloud is noisy but the user still wants the surface to pass exactly through the points.
A CGALmesh object or a mesh3d object from package rgl.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
removeOutliers,
reconstructAFS,
reconstructPoisson, alphaWrap
library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_sss <- reconstructSSS(mesh[["vertices"]], nScaleIter =2L, nNeighbors =12L, forceManifold=TRUE) mesh_sss_rgl <- toRGL(mesh_sss) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_sss_rgl, col="gray")library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_sss <- reconstructSSS(mesh[["vertices"]], nScaleIter =2L, nNeighbors =12L, forceManifold=TRUE) mesh_sss_rgl <- toRGL(mesh_sss) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_sss_rgl, col="gray")
Approximated centroidal Voronoi diagram remeshing (ACVD) uses clustering on polygonal meshes as to approximate a centroidal Voronoi diagram construction. Includes triangulation if mesh is not already triangle.
remeshACVD( x, method = c("uniform_iso", "uniform_iso_qem", "uniform_qem", "adapt_iso"), nVerts = 500L, vertCountRatio = 0.1, gradationFactor = 2, normals = FALSE )remeshACVD( x, method = c("uniform_iso", "uniform_iso_qem", "uniform_qem", "adapt_iso"), nVerts = 500L, vertCountRatio = 0.1, gradationFactor = 2, normals = FALSE )
x |
A |
method |
|
nVerts |
Positive |
vertCountRatio |
Positive number. Ratio used when input mesh does not
have enough vertices compared to |
gradationFactor |
Positive number. For |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/PMP_Remeshing/ for details.
A CGALmesh object.
See remeshDelaunay,
remeshIsotropic,
remeshSimplify,
remeshSmoothShape,
remeshSmoothAngle,
remeshSmoothTangentRelax
for other remeshing operations.
library(SurfaceMesh) library(rgl) mesh <- makeMeshValid(dataOloid) mesh_rgl <- toRGL(mesh) mesh_d <- remeshACVD(mesh, method="uniform_iso_qem", nVerts=100L) mesh_d_rgl <- toRGL(mesh_d) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) view3d(0, 30, zoom=0.8) wire3d(mesh_rgl) next3d() view3d(0, 30, zoom=0.8) wire3d(mesh_d_rgl)library(SurfaceMesh) library(rgl) mesh <- makeMeshValid(dataOloid) mesh_rgl <- toRGL(mesh) mesh_d <- remeshACVD(mesh, method="uniform_iso_qem", nVerts=100L) mesh_d_rgl <- toRGL(mesh_d) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) view3d(0, 30, zoom=0.8) wire3d(mesh_rgl) next3d() view3d(0, 30, zoom=0.8) wire3d(mesh_d_rgl)
Remeshing algorithm based on Delaunay refinement of a restricted Delaunay triangulation. Includes triangulation if mesh is not already triangle.
remeshDelaunay( x, edgeSize, facetAngle = 0, facetDist = 0.5, protectConstraints = TRUE, dihedralAngle = 60, normals = FALSE )remeshDelaunay( x, edgeSize, facetAngle = 0, facetDist = 0.5, protectConstraints = TRUE, dihedralAngle = 60, normals = FALSE )
x |
A |
edgeSize |
Positive number: Upper bound for the lengths of curve
edges. Has to be set to a positive value when |
facetAngle |
Positive number: Lower bound for the angles (in degrees) of the surface mesh facets. |
facetDist |
Positive number. Upper bound for the distance between the facet circumcenter and the center of its surface Delaunay ball. |
protectConstraints |
Boolean. Protect sharp edges.
See |
dihedralAngle |
Positive number. Constrain edges with a dihedral angle over given value to protect sharp edges. |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/PMP_Remeshing/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See remeshACVD,
remeshIsotropic,
remeshSimplify,
remeshSmoothShape,
remeshSmoothAngle,
remeshSmoothTangentRelax
for other remeshing operations.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_d <- remeshDelaunay(mesh, edgeSize=0.2, facetDist=0.2, protectConstraints=TRUE) mesh_d_rgl <- toRGL(mesh_d) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) view3d(0, 30, zoom=0.8) wire3d(mesh_rgl) next3d() view3d(0, 30, zoom=0.8) wire3d(mesh_d_rgl)library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_d <- remeshDelaunay(mesh, edgeSize=0.2, facetDist=0.2, protectConstraints=TRUE) mesh_d_rgl <- toRGL(mesh_d) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) view3d(0, 30, zoom=0.8) wire3d(mesh_rgl) next3d() view3d(0, 30, zoom=0.8) wire3d(mesh_d_rgl)
Isotropic remeshing of a triangular 3D surface mesh.
remeshIsotropic( x, method = c("uniform", "adaptive"), tol = 0.001, edgeMin = 0.001, edgeMax, targetEdgeLen, nIter = 1L, nRelaxSteps = 1L, protectConstraints = TRUE, dihedralAngle = 60, normals = FALSE )remeshIsotropic( x, method = c("uniform", "adaptive"), tol = 0.001, edgeMin = 0.001, edgeMax, targetEdgeLen, nIter = 1L, nRelaxSteps = 1L, protectConstraints = TRUE, dihedralAngle = 60, normals = FALSE )
x |
A |
method |
|
tol |
Positive number for |
edgeMin |
Positive number for |
edgeMax |
Positive number for |
targetEdgeLen |
Positive number for |
nIter |
Positive |
nRelaxSteps |
Positive |
protectConstraints |
Boolean. Protect constraints? See details. |
dihedralAngle |
Positive number. Constrain edges with a dihedral angle over given value to protect sharp edges. |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/PMP_Remeshing/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See remeshACVD,
remeshDelaunay,
remeshSimplify,
remeshSmoothShape,
remeshSmoothAngle,
remeshSmoothTangentRelax
for other remeshing operations.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_rem <- remeshIsotropic(mesh, targetEdgeLen=0.7) mesh_rem_rgl <- toRGL(mesh_rem) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_rem_rgl)library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_rem <- remeshIsotropic(mesh, targetEdgeLen=0.7) mesh_rem_rgl <- toRGL(mesh_rem) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_rem_rgl)
Simplification of a triangular 3D surface mesh.
remeshSimplify( x, repairSoup = TRUE, repairMesh = TRUE, method = c("LT-R", "LT-C", "LT-BNCF", "GH"), stopUeRatio = 0.1, stopUeCount, policyGH = c("CP", "CT", "PP", "PT", "PL"), normals = FALSE, verbose = FALSE )remeshSimplify( x, repairSoup = TRUE, repairMesh = TRUE, method = c("LT-R", "LT-C", "LT-BNCF", "GH"), stopUeRatio = 0.1, stopUeCount, policyGH = c("CP", "CT", "PP", "PT", "PL"), normals = FALSE, verbose = FALSE )
x |
A |
repairSoup |
Boolean. Clean the input mesh (merging duplicated vertices and duplicated faces, removing isolated vertices)? |
repairMesh |
Boolean. Try to remove self-intersections from output mesh? |
method |
|
stopUeRatio |
Positive number. Stop predicate. For |
stopUeCount |
|
policyGH |
|
normals |
Boolean. Return vertex normals? |
verbose |
Boolean. Print out messages about mesh processing? |
See https://doc.cgal.org/latest/Surface_mesh_simplification/ for details.
A CGALmesh object.
See remeshACVD,
remeshDelaunay,
remeshIsotropic,
remeshSmoothShape,
remeshSmoothAngle,
remeshSmoothTangentRelax
for other remeshing operations.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataHopfTorus, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_s <- remeshSimplify(mesh, method="LT-R", stopUeRatio=0.1) mesh_s_rgl <- toRGL(mesh_s) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_s_rgl)library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataHopfTorus, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_s <- remeshSimplify(mesh, method="LT-R", stopUeRatio=0.1) mesh_s_rgl <- toRGL(mesh_s) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_s_rgl)
Smoothes a 3D surface mesh by angle optimization. Includes triangulation if mesh is not already triangle.
remeshSmoothAngle( x, dihedralAngle = 60, nIter = 1L, useSafeConstr = FALSE, doProject = TRUE, normals = FALSE )remeshSmoothAngle( x, dihedralAngle = 60, nIter = 1L, useSafeConstr = FALSE, doProject = TRUE, normals = FALSE )
x |
A |
dihedralAngle |
Positive number. Constrain edges with a dihedral angle over given value to preserve sharp edges. |
nIter |
Positive |
useSafeConstr |
Boolean. Use safety constraints for moving vertices? |
doProject |
Boolean. Project points onto initial surface after each iteration? |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/PMP_Remeshing/ for details.
Note that CGAL angle_and_area_smoothing() supports smoothing by area
optimization as well. However, this feature requires the external
Ceres library (https://github.com/ceres-solver/ceres-solver) and thus is currently
not enabled here.
A CGALmesh object.
See remeshACVD,
remeshDelaunay,
remeshIsotropic,
remeshSimplify,
remeshSmoothShape,
remeshSmoothTangentRelax
for other remeshing operations.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataSeptuaginta, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_s <- remeshSmoothAngle(mesh, nIter=5L) mesh_s_rgl <- toRGL(mesh_s) mfrow3d(1, 2) view3d(45, -45, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(45, -45, zoom=0.7) shade3d(mesh_s_rgl, col="gray")library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataSeptuaginta, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_s <- remeshSmoothAngle(mesh, nIter=5L) mesh_s_rgl <- toRGL(mesh_s) mfrow3d(1, 2) view3d(45, -45, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(45, -45, zoom=0.7) shade3d(mesh_s_rgl, col="gray")
Smooths the overall shape of a 3D surface mesh by using the mean curvature flow. Includes triangulation if mesh is not already triangle.
remeshSmoothShape(x, faces, nIter = 1L, time = 0.001, normals = FALSE)remeshSmoothShape(x, faces, nIter = 1L, time = 0.001, normals = FALSE)
x |
A |
faces |
Indices of the faces to be smoothed. If missing, the whole mesh is smoothed. |
nIter |
Positive |
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 |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/PMP_Remeshing/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See remeshACVD,
remeshDelaunay,
remeshIsotropic,
remeshSimplify,
remeshSmoothAngle,
remeshSmoothTangentRelax
for other remeshing operations.
library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_s <- remeshSmoothShape(mesh, nIter=5L, time=1) mesh_s_rgl <- toRGL(mesh_s) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_s_rgl, col="gray")library(SurfaceMesh) library(rgl) mesh <- dataHeart1 mesh_rgl <- toRGL(mesh) mesh_s <- remeshSmoothShape(mesh, nIter=5L, time=1) mesh_s_rgl <- toRGL(mesh_s) mfrow3d(1, 2) view3d(0, -90, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(0, -90, zoom=0.7) shade3d(mesh_s_rgl, col="gray")
Iterative area-based smoothing of a 3D surface mesh by tangential relaxation. Includes triangulation if mesh is not already triangle.
remeshSmoothTangentRelax(x, nIter = 1L, relaxConstr = FALSE, normals = FALSE)remeshSmoothTangentRelax(x, nIter = 1L, relaxConstr = FALSE, normals = FALSE)
x |
A |
nIter |
Positive |
relaxConstr |
Boolean. If |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/PMP_Remeshing/ for details.
A CGALmesh object.
See remeshACVD,
remeshDelaunay,
remeshIsotropic,
remeshSimplify,
remeshSmoothShape,
remeshSmoothAngle
for other remeshing operations.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataSeptuaginta, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_s <- remeshSmoothTangentRelax(mesh, nIter=5L) mesh_s_rgl <- toRGL(mesh_s) mfrow3d(1, 2) view3d(45, -45, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(45, -45, zoom=0.7) shade3d(mesh_s_rgl, col="gray")library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataSeptuaginta, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_s <- remeshSmoothTangentRelax(mesh, nIter=5L) mesh_s_rgl <- toRGL(mesh_s) mfrow3d(1, 2) view3d(45, -45, zoom=0.7) shade3d(mesh_rgl, col="gray") next3d() view3d(45, -45, zoom=0.7) shade3d(mesh_s_rgl, col="gray")
Remove outliers from 3D point cloud based on their distance to neighboring points.
removeOutliers(x, nNeighbors = 6L, threshPerc, threshDst)removeOutliers(x, nNeighbors = 6L, threshPerc, threshDst)
x |
A |
nNeighbors |
|
threshPerc |
|
threshDst |
|
See https://doc.cgal.org/latest/Point_set_processing_3/ for details.
A numeric matrix of points with outliers removed.
reconstructAFS,
reconstructPoisson,
reconstructSSS,
alphaWrap
library(SurfaceMesh) library(rgl) ptsBefore <- matrix(rnorm(120L, mean=0, sd=1), ncol=3L) (avgSpacing <- getAverageSpacing(ptsBefore, nNeighbors=6L)) ## contaminate idx <- sample(seq_len(nrow(ptsBefore)), 4L, replace=FALSE) ptsBefore[idx, ] <- matrix(rnorm(12L, mean=10, sd=1), ncol=3L) ptsAfter <- removeOutliers(ptsBefore, nNeighbors=6L) dim(ptsBefore) dim(ptsAfter)library(SurfaceMesh) library(rgl) ptsBefore <- matrix(rnorm(120L, mean=0, sd=1), ncol=3L) (avgSpacing <- getAverageSpacing(ptsBefore, nNeighbors=6L)) ## contaminate idx <- sample(seq_len(nrow(ptsBefore)), 4L, replace=FALSE) ptsBefore[idx, ] <- matrix(rnorm(12L, mean=10, sd=1), ncol=3L) ptsAfter <- removeOutliers(ptsBefore, nNeighbors=6L) dim(ptsBefore) dim(ptsAfter)
Try to remove self intersections of a 3D surface mesh.
removeSelfIntersections( x, method = c("auto", "auto_snap"), normals = FALSE, verbose = FALSE )removeSelfIntersections( x, method = c("auto", "auto_snap"), normals = FALSE, verbose = FALSE )
x |
A |
method |
|
normals |
Boolean. Return vertex normals? |
verbose |
Boolean. Print out messages about mesh processing? |
See https://www.cgal.org/2025/06/13/autorefine-and-snap/ and https://doc.cgal.org/latest/PMP_Mesh_repair/ for details. If faces are not triangle, the mesh is triangulated. Not guaranteed to work for every input mesh.
CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
See fillBoundaryHoles for filling
boundary holes.
library(SurfaceMesh) verts1 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), 0.3) }, numeric(3L)) verts2 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), -0.3) }, numeric(3L)) vertices <- t(cbind(verts1, verts2)) pentagramms <- rbind(1L:5L, 6L:10L) rectangles <- rbind( c(1L, 2L, 7L, 6L), c(2L, 3L, 8L, 7L), c(3L, 4L, 9L, 8L), c(4L, 5L, 10L, 9L), c(5L, 1L, 6L, 10L)) faces <- list( pentagramms[1L, ], pentagramms[2L, ], rectangles[1L, ], rectangles[2L, ], rectangles[3L, ], rectangles[4L, ], rectangles[5L, ]) mesh <- makeMesh(vertices, faces) doesSelfIntersect(mesh) mesh_nsi <- removeSelfIntersections(mesh) getVolume(mesh_nsi)library(SurfaceMesh) verts1 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), 0.3) }, numeric(3L)) verts2 <- vapply(c(0, 2, 4, 1, 3), function(i) { c(cos(2*i*pi/5), sin(2*i*pi/5), -0.3) }, numeric(3L)) vertices <- t(cbind(verts1, verts2)) pentagramms <- rbind(1L:5L, 6L:10L) rectangles <- rbind( c(1L, 2L, 7L, 6L), c(2L, 3L, 8L, 7L), c(3L, 4L, 9L, 8L), c(4L, 5L, 10L, 9L), c(5L, 1L, 6L, 10L)) faces <- list( pentagramms[1L, ], pentagramms[2L, ], rectangles[1L, ], rectangles[2L, ], rectangles[3L, ], rectangles[4L, ], rectangles[5L, ]) mesh <- makeMesh(vertices, faces) doesSelfIntersect(mesh) mesh_nsi <- removeSelfIntersections(mesh) getVolume(mesh_nsi)
For the faces of a 3D surface mesh, reverses the order of the vertices along the face boundary.
reverseFaceOrientations(x, faces, normals = FALSE)reverseFaceOrientations(x, faces, normals = FALSE)
x |
A |
faces |
Indices of the faces to select for reversing orientation. If missing, the orientation of all faces is reversed. Cave: The resulting mesh may be invalid if faces have inconsistent orientation. |
normals |
Boolean. Return vertex normals? |
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
isOutwardOriented,
doesBoundVolume,
orientToBoundVolume.
library(SurfaceMesh) mesh <- makeMeshValid(dataTorus) doesBoundVolume(mesh) getVolume(mesh) # positive mesh_rfo <- reverseFaceOrientations(mesh) doesBoundVolume(mesh_rfo) getVolume(mesh_rfo) # negative ## invalid mesh from inconsistent face orientations mesh_invalid <- reverseFaceOrientations(mesh, faces=501:1000)library(SurfaceMesh) mesh <- makeMeshValid(dataTorus) doesBoundVolume(mesh) getVolume(mesh) # positive mesh_rfo <- reverseFaceOrientations(mesh) doesBoundVolume(mesh_rfo) getVolume(mesh_rfo) # negative ## invalid mesh from inconsistent face orientations mesh_invalid <- reverseFaceOrientations(mesh, faces=501:1000)
Random sampling of vertices on a given 3D triangle surface mesh.
samplePoints( x, method = c("random", "grid", "mc"), sampleVerts = TRUE, sampleEdges = TRUE, sampleFaces = TRUE, gridSpacing = NULL, ptsOnEdges = NULL, ptsOnFaces = NULL, ptsPerDist = NULL, ptsPerEdge = NULL, ptsPerArea = NULL, ptsPerFace = NULL )samplePoints( x, method = c("random", "grid", "mc"), sampleVerts = TRUE, sampleEdges = TRUE, sampleFaces = TRUE, gridSpacing = NULL, ptsOnEdges = NULL, ptsOnFaces = NULL, ptsPerDist = NULL, ptsPerEdge = NULL, ptsPerArea = NULL, ptsPerFace = NULL )
x |
A |
method |
|
sampleVerts |
Boolean. Do sample vertices? |
sampleEdges |
Boolean. Do sample edges? |
sampleFaces |
Boolean. Do sample faces? |
gridSpacing |
|
ptsOnEdges |
|
ptsOnFaces |
|
ptsPerDist |
|
ptsPerEdge |
|
ptsPerArea |
|
ptsPerFace |
|
For details on sampling options, see https://doc.cgal.org/latest/Polygon_mesh_processing/group__PMP__distance__grp.html.
A n x 3 numeric matrix containing the sampled vertices.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) samplePoints(mesh, ptsOnFaces=2L)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) samplePoints(mesh, ptsOnFaces=2L)
Assign given per-vertex normal vectors to a 3D surface mesh.
setVertexNormals(x, normals, tol = 1e-08)setVertexNormals(x, normals, tol = 1e-08)
x |
A |
normals |
A numeric matrix providing unit normal vectors with three columns and as many rows as the number of vertices. |
tol |
|
Note: This function is currently not doing anything except adding
a list component normals to the CGALmesh object after
setting the property map on the C++ / CGAL side, and then exporting it
back to R. This is a test case for working with CGAL property maps that
may be useful in the future.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE, normals=FALSE) ## random unit normal vectors nVerts <- nrow(mesh[["vertices"]]) nrmls0 <- matrix(runif(nVerts*3), ncol=3) lens <- sqrt(rowSums(nrmls0^2)) nrmls <- diag(1/lens) %*% nrmls0 mesh_vn <- setVertexNormals(mesh, nrmls) head(mesh_vn[["normals"]]) head(nrmls)library(SurfaceMesh) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE, normals=FALSE) ## random unit normal vectors nVerts <- nrow(mesh[["vertices"]]) nrmls0 <- matrix(runif(nVerts*3), ncol=3) lens <- sqrt(rowSums(nrmls0^2)) nrmls <- diag(1/lens) %*% nrmls0 mesh_vn <- setVertexNormals(mesh, nrmls) head(mesh_vn[["normals"]]) head(nrmls)
Performs the Catmull-Clark, Doo-Sabin, Loop, and Sqrt3 subdivision and deformation of a 3D surface mesh. Includes triangulation if mesh is not already triangle.
subdivide( x, method = c("CC", "DS", "Loop", "Sqrt3"), nIter = 1L, triangulate = TRUE, normals = FALSE )subdivide( x, method = c("CC", "DS", "Loop", "Sqrt3"), nIter = 1L, triangulate = TRUE, normals = FALSE )
x |
A |
method |
|
nIter |
Positive |
triangulate |
Boolean. For |
normals |
Boolean. Return vertex normals? |
See https://doc.cgal.org/latest/Subdivision_method_3/ for details.
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_cc <- subdivide(mesh, method="CC", nIter=2L) mesh_ds <- subdivide(mesh, method="DS", nIter=2L) mesh_cc_rgl <- toRGL(mesh_cc) mesh_ds_rgl <- toRGL(mesh_ds) open3d(windowRect=50 + c(0, 0, 1200, 400)) mfrow3d(1, 3) wire3d(mesh_rgl) next3d() wire3d(mesh_cc_rgl) next3d() wire3d(mesh_ds_rgl)library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataPentaPrism, triangulate=TRUE) mesh_rgl <- toRGL(mesh) mesh_cc <- subdivide(mesh, method="CC", nIter=2L) mesh_ds <- subdivide(mesh, method="DS", nIter=2L) mesh_cc_rgl <- toRGL(mesh_cc) mesh_ds_rgl <- toRGL(mesh_ds) open3d(windowRect=50 + c(0, 0, 1200, 400)) mfrow3d(1, 3) wire3d(mesh_rgl) next3d() wire3d(mesh_cc_rgl) next3d() wire3d(mesh_ds_rgl)
Converts a CGALmesh object (the output of the makeMesh
function) to a mesh3d object from package rgl.
toRGL(x, ...)toRGL(x, ...)
x |
A |
... |
Arguments passed to |
CAVE: Y-axis direction is front-back in rgl (OpenGL) convention but down-up in CGAL convention. This is ignored here.
A mesh3d object from package rgl.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) mesh_rgl <- toRGL(mesh, segments=t(mesh[["edges"]])) open3d(windowRect=c(50, 50, 562, 562), zoom=0.9) wire3d(mesh_rgl, color="darkred")library(SurfaceMesh) library(rgl) mesh <- makeMesh(dataTruncIcosahedron, triangulate=TRUE) mesh_rgl <- toRGL(mesh, segments=t(mesh[["edges"]])) open3d(windowRect=c(50, 50, 562, 562), zoom=0.9) wire3d(mesh_rgl, color="darkred")
Triangulate a given 3D surface mesh.
triangulateMesh(x, normals = FALSE)triangulateMesh(x, normals = FALSE)
x |
A |
normals |
Boolean. Return vertex normals? |
A CGALmesh object.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.
library(SurfaceMesh) library(rgl) ## quad mesh f_mesh <- system.file("extdata", "dataCorner.off", package="SurfaceMesh") mesh <- makeMesh(f_mesh) mesh_rgl <- toRGL(mesh) isTriangle(mesh) mesh_tri <- triangulateMesh(mesh) mesh_tri_rgl <- toRGL(mesh_tri) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_tri_rgl)library(SurfaceMesh) library(rgl) ## quad mesh f_mesh <- system.file("extdata", "dataCorner.off", package="SurfaceMesh") mesh <- makeMesh(f_mesh) mesh_rgl <- toRGL(mesh) isTriangle(mesh) mesh_tri <- triangulateMesh(mesh) mesh_tri_rgl <- toRGL(mesh_tri) open3d(windowRect=50 + c(0, 0, 800, 400)) mfrow3d(1, 2) wire3d(mesh_rgl) next3d() wire3d(mesh_tri_rgl)
Export a 3D surface mesh to a file.
writeMesh( x, filename, normals = FALSE, precision = 17L, binary = FALSE, verbose = FALSE )writeMesh( x, filename, normals = FALSE, precision = 17L, binary = FALSE, verbose = FALSE )
x |
A mesh given as |
filename |
Name of the output file. Supported file formats are
|
normals |
Boolean. For |
precision |
Positive |
binary |
Boolean. For file types |
verbose |
Boolean. Print out messages about mesh processing? |
No value. Just generates the file.
Originally developed by Stephane Laurent, adapted by Daniel Wollschlaeger.