MeshesDifference: Meshes difference

View source: R/meshes.R

MeshesDifferenceR Documentation

Meshes difference

Description

Computes the difference between two meshes.

Usage

MeshesDifference(
  mesh1,
  mesh2,
  clean = FALSE,
  normals = FALSE,
  numbersType = "double"
)

Arguments

mesh1, mesh2

two triangular meshes, each given as a list with (at least) two fields: vertices and faces; the 'vertices' matrix must have the bigq class if numberTypes="gmp", otherwise it must be numeric

clean

Boolean, whether to clean the input mesh (merging duplicated vertices, duplicated faces, removed isolated vertices) as well as the output mesh

normals

Boolean, whether to return the per-vertex normals of the output mesh

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); of course using exact computations is slower but more accurate

Value

A triangular mesh given as a list with fields vertices, faces, edges, exteriorEdges, gmpvertices if numberTypes="gmp", and normals if normals=TRUE.

Examples

library(RCGAL)
library(rgl)

# mesh one: a cube; one has to triangulate it
cube1 <- cube3d() # (from the rgl package)
vertices <- t(cube1$vb[-4L, ])
faces <- t(cube1$ib)
mesh1 <- Mesh(vertices, faces, triangulate = TRUE, normals = FALSE)

# mesh two: another cube; one also has to triangulate it
cube2 <- translate3d( # (from the rgl package)
  cube3d(), 1, 1, 0
)
vertices <- t(cube2$vb[-4L, ])
faces <- t(cube2$ib)
mesh2 <- Mesh(vertices, faces, triangulate = TRUE, normals = FALSE)

# compute the difference
differ <- MeshesDifference(mesh1, mesh2)

# plot
rgldiffer <- tmesh3d(
  vertices = t(differ[["vertices"]]),
  indices = t(differ[["faces"]]),
  homogeneous = FALSE
)
open3d(windowRect = c(50, 50, 562, 562))
shade3d(cube1, color = "yellow", alpha = 0.2)
shade3d(cube2, color = "cyan", alpha = 0.2)
shade3d(rgldiffer, color = "red")
plotEdges(
  vertices = differ[["vertices"]], edges = differ[["exteriorEdges"]],
  edgesAsTubes = TRUE, verticesAsSpheres = TRUE
)

stla/RCGAL documentation built on June 15, 2022, 6:45 a.m.