2017-11-25 105 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

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