通过设置全脸顶点和索引数据在R中绘制脸部网格的右半部分时遇到错误 [英] Error encountered while plotting right half of facial surface mesh in R by subsetting full face vertices and indices data

查看:53
本文介绍了通过设置全脸顶点和索引数据在R中绘制脸部网格的右半部分时遇到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在

如果没有别的,那就更简单了:

  library(rgl)open3d()shade3d(addNormals(subdivision3d(icosahedron3d(),2)),col ="pink")clipplanes3d(a = 1,b = 0,c = 0,d = 0) 

产生

I have vertices and indices data for human face here. I have a post one year ago on plotting 3D facial surface mesh based on these data. Now, I want to plot only the right half and mid-facial vertices while ignoring the left side vertices. Based on my earlier plot, I tried the following code:

library(tidyverse)
library(readxl)
library(rgl)

vb <- read_excel("...\\vb.xlsx", sheet = "Sheet1", col_names = F)
it <- read_excel("...\\it.xlsx", sheet = "Sheet1", col_names = F)

# Extract vertices for the right side
lm_right_ind <- which(vb[,1] < 0)
vb_mat_right <- t(vb[lm_right_ind, ])
vb_mat_right <- rbind(vb_mat_right, 1)
rownames(vb_mat_right) <- c("xpts", "ypts", "zpts", "")
vertices1_right <- c(vb_mat_right)

# Extract `it` whose rows do not contain vertices on the left side
# Left-side vertices have vb[,1] greater than 0
lm_left_ind <- which(vb[,1] > 0)

leftContain <- NULL

for (i in 1: dim(it)[1]) {
   if (T %in% (it[i,] %in% lm_left_ind)) {
          leftContain[i] <- i
    } else {leftContain[i] <- NA}
}

leftContain <- leftContain[!is.na(leftContain)]
# Remove indices that involve left-side vertices
it_rightMid <- it[-leftContain,]

it_mat_right <- t(as.matrix(it_rightMid))
rownames(it_mat_right) <- NULL

indices_right <- c(it_mat_right)

# Plot
try1_right <- tmesh3d(vertices = vertices1_right, indices = indices_right, homogeneous = TRUE, 
             material = NULL, normals = NULL, texcoords = NULL)

# Use addNormals to smooth the plot. See my Stackoverflow question:
# https://stackoverflow.com/questions/53918849/smooth-3d-trangular-mesh-in-r
try12_right <- addNormals(try1_right)

shade3d(try12_right, col="#add9ec", specular = "#202020", alpha = 0.8)

I got an error whing trying to obtain try12_right: Error in v[, it[3, i]] : subscript out of bounds.

I did exactly as what I did in my earlier plot but why something went wrong here? Thank you.

解决方案

Here's an example of using a clipping plane to leave off the left hand side of a mesh object:

library(rgl)
open3d()
root <- currentSubscene3d()
newSubscene3d("inherit", "inherit", "inherit", parent = root) # Clipping limited to this subscene
shade3d(addNormals(subdivision3d(icosahedron3d(), 2)), col = "pink")
clipplanes3d(a = 1, b = 0, c = 0, d = 0)
useSubscene3d(root)
decorate3d()

The fiddling with subscenes limits the clipping to just the shaded sphere, not everything else in the picture.

This produces this output:

If there's nothing else there, it's simpler:

library(rgl)
open3d()
shade3d(addNormals(subdivision3d(icosahedron3d(), 2)), col = "pink")
clipplanes3d(a = 1, b = 0, c = 0, d = 0)

which produces

这篇关于通过设置全脸顶点和索引数据在R中绘制脸部网格的右半部分时遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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