vtkRectilinearGrid理解为沿着坐标轴方向一系列规格的网格,但是网格间距可以不同。需要显式的提供各坐标轴的点数据。单元数据不用指定,会隐式生成。与前面提到的vtkStructuredGrid 类似,但是每个网格线都是直的。
1.给三个坐标分配点,故意使间距不一致
Create(vtkFloatArray, xArray);
Create(vtkFloatArray, yArray);
Create(vtkFloatArray, zArray);
for(int i = 0; i < 10; i++)
{
xArray->InsertNextValue(pow(i, 1.2));
yArray->InsertNextValue(pow(i, 1.5));
zArray->InsertNextValue(pow(i, 1.8));
}
2.创建网格
Create(vtkRectilinearGrid, grid);
grid->SetDimensions(10, 10, 10);
grid->SetXCoordinates(xArray);
grid->SetYCoordinates(yArray);
grid->SetZCoordinates(zArray);
维度是(10,10,10),也就是XYZ方向分别有10个点,9个间距。给每个维度分配点。
3.直接映射,不需要分配拓扑结构
Create(vtkDataSetMapper, mapper);
mapper->SetInputData(grid);
4.可以明显看到网格分配状况
5.完整代码
#include<vtkCamera.h>
#include<vtkProperty.h>
#include<vtkFloatArray.h>
#include<vtkDataSetMapper.h>
#include<vtkRectilinearGrid.h>
#include<vtkQuadraticHexahedron.h>
#include<vtkNew.h>
#include<vtkRenderer.h>
#include<vtkRenderWindow.h>
#include<vtkPolyDataMapper.h>
#include<vtkRenderWindowInteractor.h>
#define Create(type,name) vtkNew<type> name
#include<vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
int main()
{
Create(vtkFloatArray, xArray);
Create(vtkFloatArray, yArray);
Create(vtkFloatArray, zArray);
for(int i = 0; i < 10; i++)
{
xArray->InsertNextValue(pow(i, 1.2));
yArray->InsertNextValue(pow(i, 1.5));
zArray->InsertNextValue(pow(i, 1.8));
}
Create(vtkRectilinearGrid, grid);
grid->SetDimensions(10, 10, 10);
grid->SetXCoordinates(xArray);
grid->SetYCoordinates(yArray);
grid->SetZCoordinates(zArray);
Create(vtkDataSetMapper, mapper);
mapper->SetInputData(grid);
Create(vtkActor, actor);
actor->SetMapper(mapper);
actor->GetProperty()->SetEdgeVisibility(true);
actor->GetProperty()->SetRepresentationToSurface();
Create(vtkRenderer, render);
render->AddActor(actor);
render->GetActiveCamera()->SetParallelProjection(true);
render->ResetCamera();
Create(vtkRenderWindow, window);
window->AddRenderer(render);
Create(vtkRenderWindowInteractor, inter);
inter->SetRenderWindow(window);
inter->Start();
return 0;
}