2017-11-25 7 views
0

あなたがタイトルに見ることができるように、私はVTKで均等に分散球(のpython)を作りたい私はVTKで均等に分散球(のpython)を作りたい

まず、私は、このリンクである「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ありません この問題を解決するにはどうすればよいですか?

-テーヤング。

+0

PolyDataを書き込むコードを少なくとも提供できますか?それはあなたの任務です。あなたがどこにいるか教えてくれれば、私たちはあなたを助けることができます。しかし、私たちの完全な解決策を期待するのは公正ではありません。 –

+0

申し訳ありませんが、質問をする私の初めての質問です、私の質問を編集する詳細を含めると、 –

答えて

3

良い仕事。球のポリデータにポイントを追加したので、ポイントからサーフェスを生成する必要があります。これは、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

ありがとう!!!!!!それはまさに私が欲しかったものです!!!!!! –

関連する問題