基于vtk非结构网格的eclipse网格模型显示
基于vtk中的 vtkHexahedron网格,绘制空间上8个顶点组成的网格的三维模型,最整个模型需要绘制每个vtkHexhedron网格,组成整体模型,是vtkUnstructuredGrid的显示方法。这里只放了规则模型的框架图和颜色,可以用于显示eclipse grid格式的油藏地质三维模型。
public static void DrawCoordXYZGrid(Point3D[,,] coordXYZGrid, ref RenderWindowControl myRenderWindowControl)
{
int node_ni = coordXYZGrid.GetLength(0);
int node_nj = coordXYZGrid.GetLength(1);
int node_nk = coordXYZGrid.GetLength(2);
vtkPoints points = vtkPoints.New();
vtkFloatArray scalars = vtkFloatArray.New();
points.SetNumberOfPoints(node_ni * node_nj * node_nk);
int seq = 0;
for (int k = 0; k < node_nk; k++)
for (int j = 0; j < node_nj; j++)
for (int i = 0; i < node_ni; i++)
{
points.InsertPoint(seq, coordXYZGrid[i, j, k].X, coordXYZGrid[i, j, k].Y, coordXYZGrid[i, j, k].Z);
scalars.InsertTuple1(seq, k);
//Console.WriteLine(“{0} {1} {2}”, coordXYZGrid[i, j, k].x, coordXYZGrid[i, j, k].y, coordXYZGrid[i, j, k].z);
seq += 1;
}
vtkHexahedron hexahedron;
vtkUnstructuredGrid coordXYZUG = vtkUnstructuredGrid.New();
coordXYZUG.Allocate(1, 1);
coordXYZUG.SetPoints(points);
coordXYZUG.GetPointData().SetScalars(scalars);
seq = 0;
for (int k = 0; k < node_nk -1; k++)
for (int j = 0; j < node_nj - 1; j++)
for (int i = 0; i < node_ni - 1; i++)
{
seq = k * node_nj * node_ni + j * node_ni + i;
hexahedron = vtkHexahedron.New();
hexahedron.GetPointIds().SetId(0, seq);
hexahedron.GetPointIds().SetId(1, seq + 1);
hexahedron.GetPointIds().SetId(2, seq + node_ni + 1);
hexahedron.GetPointIds().SetId(3, seq + node_ni);
hexahedron.GetPointIds().SetId(4, seq + node_nj * node_ni);
hexahedron.GetPointIds().SetId(5, seq + node_nj * node_ni + 1);
hexahedron.GetPointIds().SetId(6, seq + node_nj * node_ni + node_ni + 1);
hexahedron.GetPointIds().SetId(7, seq + node_nj * node_ni + node_ni);
coordXYZUG.InsertNextCell(hexahedron.GetCellType(), hexahedron.GetPointIds());
}
vtkDataSetMapper aHexahedronMapper = vtkDataSetMapper.New();
aHexahedronMapper.SetInputData(coordXYZUG);
aHexahedronMapper.SetScalarRange(0, node_nk);
vtkActor aHexahedronActor = vtkActor.New();
aHexahedronActor.SetMapper(aHexahedronMapper);
aHexahedronActor.GetProperty().SetDiffuseColor(1, 1, 0);
vtkRenderer render = vtkRenderer.New();
vtkRenderWindow renWin = myRenderWindowControl.RenderWindow;
renWin.AddRenderer(render);
render.SetBackground(0, 0, 1);
render.AddActor(aHexahedronActor);
}