三维曲面图与XYZ坐标 [英] 3d surface plot with xyz coordinates
问题描述
我希望有经验的人可以从XYZ数据怎么一prepares形状文件帮助。一个ppared良好$ P $的数据集的一个很好的例子可以看到的此处彗星Churyumov-Gerasimenko,虽然在创建的形状文件。
I am hoping someone with experience can help in how one prepares the shape files from xyz data. A great example of a well-prepared dataset can be seen here for the comet Churyumov–Gerasimenko, although the preceding steps in creating the shape file are not provided.
我想更好地了解如何在表面上施加一组给定的XYZ坐标。使用直角坐标系是使用R包RGL直线前进,但形状的包装似乎周围的难度。我发现第r包几何
,它提供了一个接口 QHULL 功能。我试图用这个来计算德劳内三角面,我就可以绘制在 RGL
。我无法找出一些与功能 delaunayn
关联到可能的控制,这些方面的计算的最大距离的选项。我希望有人在这里可能有一些想法从XYZ数据改善面层施工。
I'm trying to better understand how to apply a surface to a given set of XYZ coordinates. Using Cartesian coordinates is straight forward with the R package "rgl", however shapes that wrap around seem more difficult. I found the R package geometry
, which provides an interface to QHULL functions. I tried using this to calculate Delaunay triangulated facets, which I can then plot in rgl
. I'm unable to figure out some of the options associated with the function delaunayn
to possibly control the maximum distances that these facets are calculated. I am hoping that someone here might have some ideas on improving the surface construction from xyz data.
library(onion)
library(rgl)
library(geometry)
data(bunny)
#XYZ point plot
open3d()
points3d(bunny, col=8, size=0.1)
#rgl.snapshot("3d_bunny_points.png")
#Facets following Delaunay triangulation
tc.bunny <- delaunayn(bunny)
open3d()
tetramesh(tc.bunny, bunny, alpha=0.25, col=8)
#rgl.snapshot("3d_bunny_facets.png")
这个答案使我相信,有可能是使用R执行Qhull的问题。另外,我现在已经尝试了各种设置(如 delaunayn(兔子,选项=Qt的)
)收效甚微。 Qhull选项进行了概述
This answer makes me believe that there might be a problem with the R implementation of Qhull. Also, I have now tried various settings (e.g. delaunayn(bunny, options="Qt")
) with little effect. Qhull options are outlined here
下面是一个球体的附加(简单)的例子。即使在这里,面的计算并不总能找到最邻近的顶点(如果你旋转的球,你会看到一些方面通过内部渡)。
Here is an additional (simpler) example of a sphere. Even here, the calculation of facets does not always find the closest neighboring vertices (if you rotate the ball you will see some facets crossing through the interior).
library(rgl)
library(geometry)
set.seed(1)
n <- 10
rho <- 1
theta <- seq(0, 2*pi,, n) # azimuthal coordinate running from 0 to 2*pi
phi <- seq(0, pi,, n) # polar coordinate running from 0 to pi (colatitude)
grd <- expand.grid(theta=theta, phi=phi)
x <- rho * cos(grd$theta) * sin(grd$phi)
y <- rho * sin(grd$theta) * sin(grd$phi)
z <- rho * cos(grd$phi)
set.seed(1)
xyz <- cbind(x,y,z)
tbr = t(surf.tri(xyz, delaunayn(xyz)))
open3d()
rgl.triangles(xyz[tbr,1], xyz[tbr,2], xyz[tbr,3], col = 5, alpha=0.5)
rgl.snapshot("ball.png")
推荐答案
下面是一个使用核密度估计,并从 misc3d的
。我研究了一下,直到我发现了 contour3d
函数的方法水平
的体面工作的值。这不是完美的precise,但您可能能够调整的事情,以获得更好,更精确的表面。如果你有超过8GB的内存,那么你也许可以增加 N
超出了我在这里做。
Here is an approach using kernel density estimation and the contour3d
function from misc3d
. I played around until I found a value for levels
that worked decently. It's not perfectly precise, but you may be able to tweak things to get a better, more accurate surface. If you have more than 8GB of memory, then you may be able to increase n
beyond what I did here.
library(rgl)
library(misc3d)
library(onion); data(bunny)
# the larger the n, the longer it takes, the more RAM you need
bunny.dens <- kde3d(bunny[,1],bunny[,2],bunny[,3], n=150,
lims=c(-.1,.2,-.1,.2,-.1,.2)) # I chose lim values manually
contour3d(bunny.dens$d, level = 600,
color = "pink", color2 = "green", smooth=500)
rgl.viewpoint(zoom=.75)
在右侧的图片是从底部,只是为了说明另一种观点。
The image on the right is from the bottom, just to show another view.
您可以使用一个较大的值 N
在 kde3d
,但它会需要更长的时间,并且可能耗尽的RAM,如果数组变得太大。您也可以尝试不同的带宽(默认这里使用)。我从计算和显示等值面在研发这种方法 - 丰和放大器;蒂尔尼2008 。
You can use a larger value for n
in kde3d
but it will take longer, and you may run out of RAM if the array becomes too large. You could also try a different bandwidth (default used here). I took this approach from Computing and Displaying Isosurfaces in R - Feng & Tierney 2008.
使用 Rvcg
包非常相似等值面的方法:
Very similar isosurface approach using the Rvcg
package:
library(Rvcg)
library(rgl)
library(misc3d)
library(onion); data(bunny)
bunny.dens <- kde3d(bunny[,1],bunny[,2],bunny[,3], n=150,
lims=c(-.1,.2,-.1,.2,-.1,.2)) # I chose lim values manually
bunny.mesh <- vcgIsosurface(bunny.dens$d, threshold=600)
shade3d(vcgSmooth(bunny.mesh,"HC",iteration=3),col="pink") # do a little smoothing
因为它是一个密度估计为基础的方法,我们可以得到一点更好地利用它通过增加兔子的密度。我还用 N = 400
在这里。成本是计算时间显著增加,但由此产生的表面是的野兔的更好:
Since it's a density estimation based approach, we can get a little more out of it by increasing the density of the bunny. I also use n=400
here. The cost is a significant increase in computation time, but the resulting surface is a hare better:
bunny.dens <- kde3d(rep(bunny[,1], 10), # increase density.
rep(bunny[,2], 10),
rep(bunny[,3], 10), n=400,
lims=c(-.1,.2,-.1,.2,-.1,.2))
bunny.mesh <- vcgIsosurface(bunny.dens$d, threshold=600)
shade3d(vcgSmooth(bunny.mesh,"HC",iteration=1), col="pink")
更优质,更高效的曲面重构方法存在(如电源外壳,泊松曲面重建,球支点算法),但我不知道有任何R中得到落实,但。
Better, more efficient surface reconstruction methods exist (e.g. power crust, Poisson surface reconstruction, ball-pivot algorithm), but I don't know that any have been implemented in R, yet.
下面是一个有关堆栈溢出后与一些伟大的信息和链接,检查出(包括链接到code):<一href="http://stackoverflow.com/questions/838761/robust-algorithm-for-surface-reconstruction-from-3d-point-cloud">robust算法从三维点云表面重建?。
Here's a relevant Stack Overflow post with some great information and links to check out (including links to code): robust algorithm for surface reconstruction from 3D point cloud?.
这篇关于三维曲面图与XYZ坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!