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

问题描述

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



其中鼻子和上唇的表面积为



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

 库(geomorph)
库(xlsx)
库(rgl)

#导入数据
vb <-read.xlsx( E:\\。 ..\\it.xlsx,sheetIndex = 1,hea der = 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

顶点索引
try 法线= NULL,texcoords = NULL)

try2<-addNormals(try)

shade3d(try2,col = darkgrey,镜面=#202020)

现在,我想绘制包含顶点的表面积编码为1的绿色,顶点区域编码为2的粉红色。



谢谢。

解决方案

在着色表面上棘手的事情是决定如何使用颜色。您可以按顶点,按边缘或按面着色。您想通过顶点来实现。



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

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

给出





此版本的 rgl 尚未在CRAN上,但可以在和。


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.

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

09-17 14:48