1

タイトルの通り、vtk(python)で均等に分散した球体を作りたい

最初に、均等に分散された球を作成する方法であるこのリンク「球上に n 点を均等に分散する」を見ました。そのリンクを介して、均等に分散された球の x、y、z 座標を取得しました。

第二に、それは実際には私が解決しなければならない問題ではありません。問題は、均等に分散された球の x、y、z 座標を持っているにもかかわらず、vtk(python) で 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()

コードはエラーをスローしませんが、vtk ウィンドウに polydata が表示されませんでした。この問題を解決するにはどうすればよいですか?

-テヨン。

4

2 に答える 2

4

よくできました。ポイントを球ポリデータに追加したので、ポイントからサーフェスを生成する必要があります。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()
于 2017-11-26T15:20:07.520 に答える