2017-11-25 101 views
0

正如你在标题看到的,我想在VTK均匀分布球(蟒蛇)我想在VTK(蟒蛇)均匀分布的球体

首先,我看到这个链接“Evenly distributing n points on a sphere”,这是一方法来创建均匀分布的球体。通过这个链接,我得到了均匀分布球体的x,y,z坐标。其次,这不是我必须解决的问题。问题是,即使我有X,Y,分布均匀球体的Z坐标,我不能在VTK(蟒蛇)做出POLYDATA ..

import numpy as np 
import mpl_toolkits.mplot3d 
import matplotlib.pyplot as plt 
import vtk 
from scipy.spatial import Delaunay 

num_pts = 1000 
indices = np.arange(0, num_pts, dtype=float) + 0.5 

phi = np.arccos(1 - 2*indices/num_pts) 
theta = np.pi * (1 + 5**0.5) * indices 

x, y, z = np.cos(theta) * np.sin(phi), np.sin(theta) * np.sin(phi), np.cos(phi); 

# x,y,z is coordination of evenly distributed shpere 
# I will try to make poly data use this x,y,z 

points = vtk.vtkPoints() 


for i in range(len(x)): 
    array_point = np.array([x[i], y[i], z[i]]) 
    points.InsertNextPoint(x[i],y[i],z[i]) 


# tri = Delaunay(points) (Do I have to use this function??) 

poly = vtk.vtkPolyData() 
poly.SetPoints(points) 

mapper = vtk.vtkPolyDataMapper() 
mapper.SetInputData(poly) 

actor = vtk.vtkActor() 
actor.SetMapper(mapper) 

ren = vtk.vtkRenderer() 
ren.AddActor(actor) 
renWin = vtk.vtkRenderWindow() 
renWin.AddRenderer(ren) 

iren = vtk.vtkRenderWindowInteractor() 
iren.SetRenderWindow(renWin) 

renWin.Render() 
iren.Start() 

的代码不会引发任何错误,但POLYDATA没有出现在我的VTK窗口,, 我该怎么做才能解决这个问题?

-Tae Young。

+0

你能否提供至少一点点写入PolyData的代码?这是你的任务,如果你告诉我们你卡在哪里,我们可以帮助你。但期待我们提供完整的解决方案是不公平的。 –

+0

对不起,这是我第一次问问题,我编辑我的问题包括更多的细节,, –

回答

3

好的工作。现在,您已将点添加到球形polydata中,我们需要从点中生成曲面。我们使用vtkDelaunay3D过滤器来执行此操作。它将生成四面体的3D网格。因此,要获得实际的球面,我们必须使用vtkDataSetSurfaceFilter来提取曲面。这些工作如下:

import numpy as np 
import vtk 

num_pts = 1000 
indices = np.arange(0, num_pts, dtype=float) + 0.5 

phi = np.arccos(1 - 2*indices/num_pts) 
theta = np.pi * (1 + 5**0.5) * indices 

x, y, z = np.cos(theta) * np.sin(phi), np.sin(theta) * np.sin(phi), np.cos(phi); 

# x,y,z is coordination of evenly distributed shpere 
# I will try to make poly data use this x,y,z 

points = vtk.vtkPoints() 


for i in range(len(x)): 
    array_point = np.array([x[i], y[i], z[i]]) 
    points.InsertNextPoint(x[i],y[i],z[i]) 

poly = vtk.vtkPolyData() 
poly.SetPoints(points) 

# To create surface of a sphere we need to use Delaunay triangulation 
d3D = vtk.vtkDelaunay3D() 
d3D.SetInputData(poly) # This generates a 3D mesh 

# We need to extract the surface from the 3D mesh 
dss = vtk.vtkDataSetSurfaceFilter() 
dss.SetInputConnection(d3D.GetOutputPort()) 
dss.Update() 

# Now we have our final polydata 
spherePoly = dss.GetOutput() 

mapper = vtk.vtkPolyDataMapper() 
mapper.SetInputData(spherePoly) 

actor = vtk.vtkActor() 
actor.SetMapper(mapper) 

ren = vtk.vtkRenderer() 
ren.AddActor(actor) 
renWin = vtk.vtkRenderWindow() 
renWin.AddRenderer(ren) 

iren = vtk.vtkRenderWindowInteractor() 
iren.SetRenderWindow(renWin) 

renWin.Render() 
iren.Start() 
+0

谢谢!!!!!!那正是我想要的!!!!!! –