赞
踩
vtkStructuredGrid是具有规则拓扑和不规则几何的数据集。可以理解为单元格顺序沿着坐标轴排列,但是每个单元格可以不一样。看了很多文字解释,感觉不清楚,直接用图解验证:
1.使用CAD随意绘制个网格草图
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->AddActor(actor);
-
- render->GetActiveCamera()->SetParallelProjection(true);
-
- Create(vtkRenderWindow, window);
- window->AddRenderer(render);
-
- 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个点,改一下Z值。一定要同步修改Z方向维度为2.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。