基于vtk结构化网格的eclipse三维地质模型
上述基于vtkHexahedron网格的三维模型显示需要显式地定义每个vtkHexahedron网格,然后建立vtkUnstructuredGrid,属于非结构化网格,计算量大。这个实例采用了vtkStructuredGrid的格式,不用显式地定义每个网格,只需要定义每个节点的空间坐标就行,计算量小,显示速度快,同时还以vtkAxesActor方式添加了XYZ方向的坐标轴。采用java的具体代码如下,其中coordXYZGrid是eclipse网格种每个节点的空间坐标,values是每个网格的属性值。
private void DrawstructuredGrid(Point3D[][][] coordXYZGrid, double[][][] values, double valueMin, double valueMax)
{
int node_nk = coordXYZGrid.length;
int node_nj = coordXYZGrid[0].length;
int node_ni = coordXYZGrid[0][0].length;
System.out.println("nk="+node_nk+" nj="+node_nj+" ni="+node_ni);
//create the points and array
vtkPoints points = new vtkPoints();
vtkDoubleArray scalars = new vtkDoubleArray();
//points.SetNumberOfPoints(node_ni * node_nj * node_nk);
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[k][j][i].X, coordXYZGrid[k][j][i].Y, coordXYZGrid[k][j][i].Z);
points.InsertNextPoint(coordXYZGrid[k][j][i].X, coordXYZGrid[k][j][i].Y, coordXYZGrid[k][j][i].Z);
//scalars.InsertTuple1(seq, k);
scalars.InsertNextTuple1(values[k][j][i]);
//Console.WriteLine(“{0} {1} {2}”, coordXYZGrid[i, j, k].x, coordXYZGrid[i, j, k].y, coordXYZGrid[i, j, k].z);
//seq += 1;
}
}
}
//create the structured grid
vtkStructuredGrid grid = new vtkStructuredGrid();
grid.SetDimensions(node_ni, node_nj, node_nk); //ni nj nk
grid.SetPoints(points);
grid.GetCellData().SetScalars(scalars);
//create a mapper
vtkDataSetMapper mapper = new vtkDataSetMapper();
mapper.SetInputData(grid);
mapper.SetScalarRange(valueMin,valueMax);
//create the actor
vtkActor actor = new vtkActor();
actor.SetMapper(mapper);
actor.GetProperty().SetDiffuseColor(1, 1, 0);
vtkRenderer render = new vtkRenderer();
vtkRenderWindow renWin = new vtkRenderWindow();
//设置交互样式
vtkRenderWindowInteractor renwinIn = new vtkRenderWindowInteractor();
renwinIn.SetRenderWindow(renWin);
renWin.AddRenderer(render);
render.SetBackground(0, 0, 0); //blue(0,0,1),red(1,0,0)
render.AddActor(actor);
//设置坐标轴
vtkAxesActor axesActor = new vtkAxesActor();
vtkOrientationMarkerWidget widget = new vtkOrientationMarkerWidget();
widget.SetOutlineColor(0.1, 0.1, 0.1);
widget.SetOrientationMarker(axesActor);
widget.SetInteractor(renwinIn);
widget.SetEnabled(1);
widget.InteractiveOn();
//可视化输出
render.ResetCamera();
renWin.Render();
renwinIn.Start();
}
具体显示结果如下