基于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);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具