2016-04-18 4 views
0

私はpolyplotlibを使ってPythonスクリプトを書いてポリキューブを、ポリキューブの対称性を明らかにする面または軸とともにビジュアル化して回転させました。以下のイラストからわかるように、ある点までは成功しました。そこには、6つの立方体からなる77の3Dポリキューブがあります。私のスクリプトはmatplotlibを使用しています。matplotlibを使うと、ポリキューブを回転させて任意の角度で見ることができます。ほとんどのポリキューブには大きな問題があります。これは、下の2番目の画像に示されています。私がポリキューブの回転を開始した少し後、matplotlibは、他のプレーンの後ろに部分的にあるプレーンを示します。したがって、部分的には見えず、描画されないか、部分的に描画されません。六面体で構成を視覚化

私はフォーラムやGoogleで多くの検索を行っていますが、役に立たないものです。 matplotlibの代わりにmayaviを使うべきであることを示唆するヒットがあった。だから私はマヤビについて広範に研究しました。私は文字通り数週間、どうやってマヤビを作るのか考え出すのに過ごしました。最初にdocs.enthoughtのヒットは有望に見えましたが、目的には明らかにマヤビが適していて、オブジェクトの視覚化には優れていますが、わかりやすいドキュメントは見つかりません。私はvtkまたはtvtkで実際のプログラマーガイドを使用することができます。多くのドキュメントがありますが、主にプログラマーではなくデザイナー向けです。利用できない場合(?)、六面体または不規則格子のスクリプトの例もあります。これは、canopy(1.6.2)のPython実装で機能します。

答えて

0

Iこの例では、配列要素の配列座標点からジオメトリを作成することができる機能に変換することができVTKドキュメント(http://www.vtk.org/gitweb?p=VTK.git;a=blob_plain;f=Examples/DataManipulation/Python/BuildUGrid.py

の例を変更しました。

私はVTKのための任意のガイドを使用していないが、私は通常、ここで見つけるのpythonの例を参照してください。http://www.vtk.org/Wiki/VTK/Examples/Python

import vtk 

# Initialize the vtkPoints variable and set the number of points 
points = vtk.vtkPoints() 
points.SetNumberOfPoints(8) 

# Add points to the variable, with the point number first, then the x, y, z coordinates. 
# For demonstration purposes, I started numbering the ponts at 10 (normally they would start at 0). 
points.InsertPoint(0, 0, 0, 0) 
points.InsertPoint(1, 1, 0, 0) 
points.InsertPoint(2, 1, 1, 0) 
points.InsertPoint(3, 0, 1, 0) 
points.InsertPoint(4, 0, 0, 1) 
points.InsertPoint(5, 1, 0, 1) 
points.InsertPoint(6, 1, 1, 1) 
points.InsertPoint(7, 0, 1, 1) 

points.InsertPoint(8, 0, 0, 1.1) 
points.InsertPoint(9, 1, 0, 1.1) 
points.InsertPoint(10, 1, 1, 1.1) 
points.InsertPoint(11, 0, 1, 1.1) 
points.InsertPoint(12, 0, 0, 2) 
points.InsertPoint(13, 1, 0, 2) 
points.InsertPoint(14, 1, 1, 2) 
points.InsertPoint(15, 0, 1, 2.5) 

# Define the hexahedron, then set the point Ids of the hexahedron cell/element. 
# From the documentation: points (0,1,2,3) is the base of the hexahedron which, using the right hand rule, forms a 
# quadrilaterial whose normal points in the direction of the opposite face (4,5,6,7) 
aHexahedron1 = vtk.vtkHexahedron() 
aHexahedron1.GetPointIds().SetId(0, 0) # Cell point 0 corresponds to point 0 which was defined above 
aHexahedron1.GetPointIds().SetId(1, 1) 
aHexahedron1.GetPointIds().SetId(2, 2) 
aHexahedron1.GetPointIds().SetId(3, 3) 
aHexahedron1.GetPointIds().SetId(4, 4) 
aHexahedron1.GetPointIds().SetId(5, 5) 
aHexahedron1.GetPointIds().SetId(6, 6) 
aHexahedron1.GetPointIds().SetId(7, 7) 

# Define a second hexahedron 
aHexahedron2 = vtk.vtkHexahedron() 
aHexahedron2.GetPointIds().SetId(0, 8) # Cell point 0 corresponds to point 8 which was defined above 
aHexahedron2.GetPointIds().SetId(1, 9) 
aHexahedron2.GetPointIds().SetId(2, 10) 
aHexahedron2.GetPointIds().SetId(3, 11) 
aHexahedron2.GetPointIds().SetId(4, 12) 
aHexahedron2.GetPointIds().SetId(5, 13) 
aHexahedron2.GetPointIds().SetId(6, 14) 
aHexahedron2.GetPointIds().SetId(7, 15) 

# Define an unstructured grid. 
aHexahedronGrid = vtk.vtkUnstructuredGrid() 

# Add the hexahedron to the unstructured grid 
# Note: this operation defines the point ids, and not the actual point coordinates 
aHexahedronGrid.InsertNextCell(aHexahedron1.GetCellType(), aHexahedron1.GetPointIds()) 
aHexahedronGrid.InsertNextCell(aHexahedron2.GetCellType(), aHexahedron2.GetPointIds()) 

# Set the points which includes the coordinates. The point ids defined in the line above correspond to the point ids 
# that were defined earlier (i.e. points.InsertPoint(10, 0, 0, 0)) 
aHexahedronGrid.SetPoints(points) 

# Now we have defined one hexahedron, and added it an unstructured grid. 
# We could create more hexahedrons, and add them to the same unstructured grid. 

# To view the unstructured grid, we need to define a mapper and set the unstructured grid as the input 
aHexahedronMapper = vtk.vtkDataSetMapper() 
aHexahedronMapper.SetInputData(aHexahedronGrid) 

# Define an actor, and set the mapper as the input 
aHexahedronActor = vtk.vtkActor() 
aHexahedronActor.SetMapper(aHexahedronMapper) 

# Create the usual rendering stuff. 
ren = vtk.vtkRenderer() 
renWin = vtk.vtkRenderWindow() 
renWin.AddRenderer(ren) 
iren = vtk.vtkRenderWindowInteractor() 
iren.SetRenderWindow(renWin) 
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) # Change the rotation type from the default to 'trackball' 
ren.SetBackground(.1, .2, .4) 

# Add the actor to the renderer to actually view the geometry 
ren.AddActor(aHexahedronActor) 

# Render the scene and start interaction. 
iren.Initialize() 
renWin.Render() 
iren.Start() 
+0

私は、スクリプトを試してみましたが、私がそれを望んだとおりに働いています。もちろん、私は自分の特定のポリキューブを絵に描く方法を見つけなければならないでしょうが、それはまったく問題ではありません。例の2つの立方体は素晴らしい回転しています。 – Hein502

+0

私はshoe02に感謝します:shoe02ありがとう! – Hein502

+0

問題なく、うまくいきました! – shoe02