2016-04-06 5 views
2

誰かが 'ashape3d'クラスオブジェクトを 'mesh3d'クラスに変換する手助けができますか?ashape3dクラスをmesh3dに変換する

ashape3dでは、三角形の四面体の面が異なるフィールドに格納されます。私は同時に、三角形&四面体からmesh3dオブジェクトを作成することができる機能がないと思うと、私は次の(擬似コード)を試してみました:

model <- ashape3d(rtorus(1000, 0.5, 2),alpha=0.25) 

vert <- model$x[model$vert[,2]==1,] 
vert <- cbind(vert,rep(1,nrow(vert))) 
tria <- model$triang[model$triang[,4]==1,1:3] 
tetr <- model$tetra[model$tetra[,6]==1,1:4] 

m3dTria <- tmesh3d(vertices=vert , indices=tria) 
m3dTetr <- qmesh3d(vertices=vert , indices=tetr) 
m3d  <- mergeMeshes(m3dTria,m3dTetr) 

plot.ashape3d(model) # works fine 
plot3d(m3d)   # Error in x$vb[1, x$it] : subscript out of bounds 

誰もがより良い方法がありますか?

+0

上記のデータでそれを試してみることができます。 –

+0

いくつかのサンプルデータを含むように質問を更新しました。残念ながら、plot3d(m3d)を使用するとエラーになります。だから、おそらく私はまず何かを間違ってやっています。 –

+0

これは再現可能な例のアイデアです。それは本当に難しいと思うはずです。 :) –

答えて

2

私はこれを最近行う必要があり、この未解決の問題を発見しました。何が起こっているのかを調べる最も簡単な方法は、plot.ashape3dを見て、ashape3dのドキュメントを読むことです。 plot.ashape3dは三角形のみをプロットします。

rglパッケージには、汎用のas.mesh3d機能があります。これは、その汎用関数のメソッドを定義します。

as.mesh3d.ashape3d <- function(x, ...) { 
    if (length(x$alpha) > 1) 
    stop("I don't know how to handle ashape3d objects with >1 alpha value") 
    iAlpha = 1 

    # from help for ashape3d 
    # for each alpha, a value (0, 1, 2 or 3) indicating, respectively, that the 
    # triangle is not in the alpha-shape or it is interior, regular or singular 
    # (columns 9 to last) 

    # Pick the rows for which the triangle is regular or singular 
    selrows = x$triang[, 8 + iAlpha] >= 2 
    tr <- x$triang[selrows, c("tr1", "tr2", "tr3")] 

    rgl::tmesh3d(
    vertices = t(x$x), 
    indices = t(tr), 
    homogeneous = FALSE 
) 
} 

あなたは、再現性の例を提供してください

model <- ashape3d(rtorus(1000, 0.5, 2),alpha=0.25) 
plot(model, edges=F, vertices=F) 

library(rgl) 
model2=as.mesh3d(model) 
open3d() 
shade3d(model2, col='red') 
関連する問題