Learn R Programming

RRmorph (version 0.0.1)

interpolMesh: Interpolate values on a 3d mesh

Description

The function takes a reconstructed mesh3d object (sur) with some related values (to either triangles or vertices of the mesh) and transfers such values to the real mesh (refsur) from which sur was derived.

Usage

interpolMesh(sur,values,refsur,refmat,element=c("triangles","vertices"),k=4)

Value

The vector of values related to each vertex of refsur.

Arguments

sur

a reconstructed mesh3d object with vertices matching to refmat.

values

the vector of values related to sur to be interpolated. values can be related to either triangles or vertices (see element).

refsur

the reference mesh (mesh3d object) to interpolate the values on.

refmat

the landmark set related to refsur.

element

one of "triangles" or "vertices", depending on which of them values is related to.

k

the number of nearest neighbor vertices used for interpolation (see details).

Author

Marina Melchionna, Silvia Castiglione

Details

The function starts by locating a set of points (NNps) on refsur, each being the single nearest neighbor for each vertex of sur (or barycenter if element="triangles"). Then, interpolation is performed by identifying the k points among NNps being the closest to each vertex of refsur and computing the mean of their values weighted by their distance.

Examples

Run this code
  # \donttest{
  da<-"https://github.com/pasraia/RRmorph_example_data/raw/refs/heads/main/RRmorphdata.rda"
  download.file(url=da,destfile = paste0(tempdir(),"/RRmorphdata.rda"))
  load(paste0(tempdir(),"/RRmorphdata.rda"))

  require(rgl)
  require(Morpho)
  require(Rvcg)

  pca<-procSym(endo.set)
  ldm<-endo.set[,,"Homo_sapiens"]
  sur<-endo.sur[["Homo_sapiens"]]

  rec<- vcgBallPivoting(pca$mshape, radius = 0)
  rec$vb[1:3,]<-t(ldm)
  val1<-rnorm(ncol(rec$vb))

  # Interpolate values associated to vertices
  val1<-rnorm(ncol(rec$vb))
  interp1<-interpolMesh(sur = rec,refsur = sur,refmat = ldm,
                        values = val1,element ="vertices",k = 4)

  colmesh1<-col2mesh(mesh = sur,values = interp1,pal = heat.colors(5))
  open3d()
  shade3d(colmesh1,specular="black")


  # Interpolate values associated to triangles
  val2<-rnorm(ncol(rec$it))
  interp2<-interpolMesh(sur = rec,refsur = sur,refmat = ldm,
                        values = val2,element ="triangles",k = 4)

  colmesh2<-col2mesh(mesh = sur,values = interp2,pal = heat.colors(5))
  open3d()
  shade3d(colmesh2,specular="black")
  # }

Run the code above in your browser using DataLab