在vtk
中,您最多可以將一個六角棱柱單元添加到帶有InsertNextCell (int type, vtkIdType npts, vtkIdType *ptIds)
的vtkUnstructuredGrid
。這很好,但我想包括一個七邊形和八角形棱鏡到vtkUnstructuredGrid
。細胞類型在VTK定義...如何創建vtk七棱柱(具有4個頂點和7個頂點的2個面)
只是爲了澄清一些疑問,我與c#
工作,但一個c++
或python
例子就足以將其翻譯爲c#
。
回到問題,我先複製並稍微修改了代碼in this example獲得體素(8分和單元格類型= 11)
vtkPoints points = vtkPoints.New();
points.InsertNextPoint(-1.0, -1.0, -1.0);
points.InsertNextPoint(1.0, -1.0, -1.0);
points.InsertNextPoint(1.0, 1.0, -1.0);
points.InsertNextPoint(-1.0, 1.0, -1.0);
points.InsertNextPoint(-1.0, -1.0, 1.0);
points.InsertNextPoint(1.0, -1.0, 1.0);
points.InsertNextPoint(1.0, 1.0, 1.0);
points.InsertNextPoint(-1.0, 1.0, 1.0);
vtkUnstructuredGrid unstructuredGrid1 = vtkUnstructuredGrid.New();
unstructuredGrid1.SetPoints(points);
int[] ptIds = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
IntPtr ptIdsPointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * 8);
Marshal.Copy(ptIds, 0, ptIdsPointer, 8);
unstructuredGrid1.InsertNextCell(11, 8, ptIdsPointer);
Marshal.FreeHGlobal(ptIdsPointer);
// Create a mapper and actor
vtkDataSetMapper mapper = vtkDataSetMapper.New();
mapper.SetInputConnection(unstructuredGrid1.GetProducerPort());
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetColor(1, 0, 0);
actor.GetProperty().SetPointSize(3);
actor.GetProperty().SetOpacity(1);
actor.GetProperty().SetLineWidth(2);
actor.GetProperty().EdgeVisibilityOn();
Renderer3D.AddActor(actor);
但因爲我想一個七面體,我努力適應使用VTK_POLYHEDRON
的想法,改變它告訴PF類型的細胞中添加行非結構網格
unstructuredGrid1.InsertNextCell(11, 8, ptIdsPointer);
至(42代表VTK_POLYHEDRON
,11個代表VTK_VOXEL
)和點= 14
unstructuredGrid1.InsertNextCell(42, 14, ptIdsPointer);
this example等。我triedsomething像C++,但我沒有得到任何結果
int numberOfVertices = 14;
int numberOfFaces = 9; //how to tell heptagonal prism has 2 faces with 7 vertices and 7 with 4 vertices?
int numberOfFaceVertices = 4;
vtkIdType heptagonPointsIds[14] =
{0, 1, 2, 3, 4, 5, 6
7, 8, 9, 10, 11, 12,13};
//points that only change in z
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(454.6, 678.534, 1.1009301757813); //id 0
points->InsertNextPoint(454.6, 678.545, 1.1500146484375);//id 1
points->InsertNextPoint(454.6, 678.556, 1.2255187988281);//id 2
points->InsertNextPoint(455.1, 678.556, 1.6478076171875);//id 3
points->InsertNextPoint(455.1, 678.534, 1.7926538085938);//id 4
points->InsertNextPoint(455.1, 678.545, 1.7166479492188);//id 5
points->InsertNextPoint(454.85, 678.534, 1.0092297363281);//id 6
points->InsertNextPoint(454.6, 678.534, 5.1009301757813);//id 7
points->InsertNextPoint(454.6, 678.545, 5.1500146484375);//id 8
points->InsertNextPoint(454.6, 678.556, 5.2255187988281);//id 9
points->InsertNextPoint(455.1, 678.556, 5.6478076171875);//id 10
points->InsertNextPoint(455.1, 678.534, 5.7926538085938);//id 11
points->InsertNextPoint(455.1, 678.545, 5.7166479492188);//id 12
points->InsertNextPoint(454.85, 678.534, 5.0092297363281);//id13
vtkIdType heptagonPrismFace[9][4] = {
{0, 1, 7, 8},
{1, 2, 8, 9},
{2, 3, 9, 10},
{3, 4, 10, 11},
{4, 5, 11, 12},
{5, 6, 12, 13},
{6, 1, 13, 8},
//last two faces how to tel they should be 0 1 2 3 4 5 6 and 7 8 9 10 11 12 13 ?
{0, 1, 2, 3},
{7, 8, 9, 10},
};
vtkSmartPointer<vtkCellArray> heptagonFaces=
vtkSmartPointer<vtkCellArray>::New();
for (int i = 0; i < numberOfFaces; i++)
{
heptagonFaces->InsertNextCell(numberOfFaceVertices, heptagonPrismFace[i]);
}
vtkSmartPointer<vtkUnstructuredGrid> uGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
uGrid->InsertNextCell(VTK_POLYHEDRON,
numberOfVertices, heptagonPointsIds,
numberOfFaces, heptagonFaces->GetPointer());
uGrid->SetPoints(points);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputConnection(uGrid->GetProducerPort());
//add actor to render and stuff...
你爲什麼不拿['vtkHexagonalPrism'(HTTP:// www.vtk.org/doc/nightly/html/classvtkHexagonalPrism.html)的代碼並相應地進行編輯?我推測所有棱鏡類都分享他們的大部分代碼,或者至少是它設計的方式。 –
@ivan_pozdeev你會碰巧知道在c#中使用它的方法嗎?我紅色'vtkHexagonalPrism'來源,但我不知道他們在哪裏定義vtkHexagonalPrism細胞類型 – cMinor
我相信你的體素圖片顯示你的頂點不是正確的順序。它應該是一個立方體,但是頂部和底部的表面似乎是通過體素的中間傾斜的。 – RootTwo