用颜色绘制表面网格的指定区域 [英] Plot specified area of a surface mesh with color

查看:26
本文介绍了用颜色绘制表面网格的指定区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3D 面板表面网格的数据.数据可在

鼻子和上唇的表面积为绿色,其他区域为灰色.

我生成灰色3D面部表面网格的代码如下:

library(geomorph)图书馆(xlsx)图书馆(rgl)# 导入数据vb <- read.xlsx("E:\...\vb.xlsx", sheetIndex = 1, header = F)it <- read.xlsx("E:\...\it.xlsx", sheetIndex = 1, header = F)vb_mat <- t(as.matrix(vb))vb_mat <- rbind(vb_mat, 1)rownames(vb_mat) <- c("xpts", "ypts", "zpts", "")it_mat <- t(as.matrix(it))rownames(it_mat) <- NULL顶点 <- c(vb_mat)指数 <- c(it_mat)尝试 <- tmesh3d(顶点 = 顶点,索引 = 索引,同质 = TRUE,材料 = NULL,法线 = NULL,texcoords = NULL)try2 <- addNormals(try)shade3d(try2, col="darkgrey", specular = "#202020")

现在,我想绘制包含绿色编码为 1 的顶点的表面积和包含编码为 2 的粉色顶点的区域.我应该如何修改我的 R 代码?

谢谢.

解决方案

着色表面的棘手之处在于决定如何使用颜色.您可以按顶点、边或面着色.你想通过顶点来做.

只要您使用 rgl 0.100.2 或更新版本,这相对容易.为每个顶点指定一种颜色,并使用参数 meshColor = "vertices" 告诉 rgl 这就是你所做的.例如,

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

给出

此版本的 rgl 尚未在 CRAN 上发布,但可在 R-forgeGithub.

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.txt is a matrix of 7160*1 with elements of either 1 or 2. I want the surface area (not just vertices!) enclosed by vertices which are coded 1 to be plotted in a different color from areas covered by vertices coded 2.

For example, if vertices covering nose and upper lip are coded 1 and other facial areas are coded 2, then I wish to make a plot as below:

where surface area of nose and upper lip is green and other regions are gray.

My code to generate gray color 3D facial surface mesh is as follows:

library(geomorph)
library(xlsx)
library(rgl)

# Import data
vb <- read.xlsx("E:\...\vb.xlsx", sheetIndex = 1, header = F)
it <- read.xlsx("E:\...\it.xlsx", sheetIndex = 1, header = F)

vb_mat <- t(as.matrix(vb))
vb_mat <- rbind(vb_mat, 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)

try <- tmesh3d(vertices = vertices, indices = indices, homogeneous = TRUE, material = NULL, 
               normals = NULL, texcoords = NULL)

try2 <- addNormals(try)

shade3d(try2, col="darkgrey", specular = "#202020")

Now, I want to plot surface area containing vertices coded 1 with green color and area containing vertices coded 2 with pink color. How should I modify my R code?

Thank you.

解决方案

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.

这篇关于用颜色绘制表面网格的指定区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆