# VTK-vtkStructuredGrid学习

vtkStructuredGrid是具有规则拓扑和不规则几何的数据集。可以理解为单元格顺序沿着坐标轴排列，但是每个单元格可以不一样。看了很多文字解释，感觉不清楚，直接用图解验证：

2.获取这些点信息，点顺序要严格按照图示

Create(vtkPoints, points);
points->InsertNextPoint(1.9475, 0.4465, 0);
points->InsertNextPoint(1.183, 1.4711, 0);
points->InsertNextPoint(0.018, 1.5855, 0);
points->InsertNextPoint(-1.2925, 1.1278, 0);

points->InsertNextPoint(2.7932, 1.0052, 0);
points->InsertNextPoint(2.0935, 2.0645, 0);
points->InsertNextPoint(-0.1276, 2.48, 0);
points->InsertNextPoint(-1.6423, 2.1293, 0);

points->InsertNextPoint(3.7595, 1.9673, 0);
points->InsertNextPoint(2.7703, 2.5821, 0);
points->InsertNextPoint(-0.0339, 3.2228, 0);
points->InsertNextPoint(-2.0392, 3.098, 0);

3.构造结构化网格

Create(vtkStructuredGrid, grid);
grid->SetDimensions(4, 3, 1);
grid->SetPoints(points);

维度理解为X/Y/Z方向的点数，如草图所示分别是4，3，1。此时只提供了12个点，只能构造一层，所以Z方向维度是1，不能是其他数据

4.将上面的网格显示出来

Create(vtkDataSetMapper, mapper);
mapper->SetInputData(grid);

Create(vtkActor, actor);
actor->SetMapper(mapper);
actor->GetProperty()->SetRepresentationToWireframe();

Create(vtkRenderer, render);

render->GetActiveCamera()->SetParallelProjection(true);

Create(vtkRenderWindow, window);

Create(vtkRenderWindowInteractor, inter);
inter->SetRenderWindow(window);

((vtkInteractorStyleSwitch *)inter->GetInteractorStyle())->SetCurrentStyleToTrackballCamera();

render->ResetCamera();

inter->Start();

5.点图、线图、面图如下，对应行的代码改一下出现不同效果图

actor->GetProperty()->SetRepresentationToPoints();
actor->GetProperty()->SetRepresentationToWireframe();
actor->GetProperty()->SetRepresentationToSurface();

6.点可以不在同一个平面，随机改变点Z数值

7.增加Z方向维度，点也要增加，点序保持一致

 Create(vtkPoints, points);
points->InsertNextPoint(1.9475, 0.4465, 0);
points->InsertNextPoint(1.183, 1.4711, 0.3);
points->InsertNextPoint(0.018, 1.5855, 0);
points->InsertNextPoint(-1.2925, 1.1278, -0.5);

points->InsertNextPoint(2.7932, 1.0052, 0);
points->InsertNextPoint(2.0935, 2.0645, 0);
points->InsertNextPoint(-0.1276, 2.48, 0);
points->InsertNextPoint(-1.6423, 2.1293, 0.5);

points->InsertNextPoint(3.7595, 1.9673, 0);
points->InsertNextPoint(2.7703, 2.5821, 0);
points->InsertNextPoint(-0.0339, 3.2228, 0);
points->InsertNextPoint(-2.0392, 3.098, 0);

points->InsertNextPoint(1.9475, 0.4465, 2);
points->InsertNextPoint(1.183, 1.4711, 2.3);
points->InsertNextPoint(0.018, 1.5855, 2);
points->InsertNextPoint(-1.2925, 1.1278, 1.5);

points->InsertNextPoint(2.7932, 1.0052, 2);
points->InsertNextPoint(2.0935, 2.0645, 2);
points->InsertNextPoint(-0.1276, 2.48, 2);
points->InsertNextPoint(-1.6423, 2.1293, 2.5);

points->InsertNextPoint(3.7595, 1.9673, 2);
points->InsertNextPoint(2.7703, 2.5821, 2);
points->InsertNextPoint(-0.0339, 3.2228, 2);
points->InsertNextPoint(-2.0392, 3.098, 2);

Create(vtkStructuredGrid, grid);
grid->SetDimensions(4, 3, 2);
grid->SetPoints(points);

• 12
点赞
• 1
收藏
觉得还不错? 一键收藏
• 0
评论
09-28 1128
06-24 1340
01-19 909
04-26 1881
05-22 2028
08-18 1941
04-25 5129

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。