Plot specified area of a surface mesh with color

前端 未结 2 1530
说谎
说谎 2021-01-27 10:46

I have data for 3D facia surface mesh. Data are available here, where vb.xlsx contains coordinates for 7160 3D vertices and it.xlsx contains face information. The color coding.t

相关标签:
2条回答
  • 2021-01-27 11:00

    Is it the expected result?

    library(rgl)
    library(readxl)
    # Import data
    vb <- read_xlsx("vb.xlsx", sheet = 1, col_names = FALSE)
    it <- read_xlsx("it.xlsx", sheet = 1, col_names = FALSE)
    colorCoding <- read.table("Color coding.txt")$V1
    colors <- c("darkgrey","midnightblue")[colorCoding]
    
    vb_mat <- rbind(t(as.matrix(vb)), 1)
    rownames(vb_mat) <- c("xpts", "ypts", "zpts", "")
    it_mat <- t(as.matrix(it))
    rownames(it_mat) <- NULL
    vertices <- c(vb_mat)
    indices <- c(it_mat)
    
    mesh <- addNormals(
      tmesh3d(vertices = vertices, indices = indices, homogeneous = TRUE,
              material = list(color=colors)))
    shade3d(mesh, specular = "#202020")
    

    0 讨论(0)
  • 2021-01-27 11:11

    The tricky thing in colouring surfaces is deciding how to use the colours. You can colour by vertex, by edge, or by face. You want to do it by vertex.

    As long as you are using rgl version 0.100.2 or newer, this is relatively easy. Specify the colours one per vertex, and use argument meshColor = "vertices" to tell rgl that's what you did. For example,

    shade3d(try2, col=c("green", "pink")[col], meshColor = "vertices", specular = "#202020")
    

    which gives

    This version of rgl isn't on CRAN yet, but it's available on R-forge and Github.

    0 讨论(0)
提交回复
热议问题