当前位置:   article > 正文

VTK-vtkStructuredGrid学习

vtkstructuredgrid

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

1.使用CAD随意绘制个网格草图

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

  1. Create(vtkPoints, points);
  2. points->InsertNextPoint(1.9475, 0.4465, 0);
  3. points->InsertNextPoint(1.183, 1.4711, 0);
  4. points->InsertNextPoint(0.018, 1.5855, 0);
  5. points->InsertNextPoint(-1.2925, 1.1278, 0);
  6. points->InsertNextPoint(2.7932, 1.0052, 0);
  7. points->InsertNextPoint(2.0935, 2.0645, 0);
  8. points->InsertNextPoint(-0.1276, 2.48, 0);
  9. points->InsertNextPoint(-1.6423, 2.1293, 0);
  10. points->InsertNextPoint(3.7595, 1.9673, 0);
  11. points->InsertNextPoint(2.7703, 2.5821, 0);
  12. points->InsertNextPoint(-0.0339, 3.2228, 0);
  13. points->InsertNextPoint(-2.0392, 3.098, 0);

3.构造结构化网格

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

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

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

  1. Create(vtkDataSetMapper, mapper);
  2. mapper->SetInputData(grid);
  3. Create(vtkActor, actor);
  4. actor->SetMapper(mapper);
  5. actor->GetProperty()->SetRepresentationToWireframe();
  6. Create(vtkRenderer, render);
  7. render->AddActor(actor);
  8. render->GetActiveCamera()->SetParallelProjection(true);
  9. Create(vtkRenderWindow, window);
  10. window->AddRenderer(render);
  11. Create(vtkRenderWindowInteractor, inter);
  12. inter->SetRenderWindow(window);
  13. ((vtkInteractorStyleSwitch *)inter->GetInteractorStyle())->SetCurrentStyleToTrackballCamera();
  14. render->ResetCamera();
  15. inter->Start();

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

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

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

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

  1. Create(vtkPoints, points);
  2. points->InsertNextPoint(1.9475, 0.4465, 0);
  3. points->InsertNextPoint(1.183, 1.4711, 0.3);
  4. points->InsertNextPoint(0.018, 1.5855, 0);
  5. points->InsertNextPoint(-1.2925, 1.1278, -0.5);
  6. points->InsertNextPoint(2.7932, 1.0052, 0);
  7. points->InsertNextPoint(2.0935, 2.0645, 0);
  8. points->InsertNextPoint(-0.1276, 2.48, 0);
  9. points->InsertNextPoint(-1.6423, 2.1293, 0.5);
  10. points->InsertNextPoint(3.7595, 1.9673, 0);
  11. points->InsertNextPoint(2.7703, 2.5821, 0);
  12. points->InsertNextPoint(-0.0339, 3.2228, 0);
  13. points->InsertNextPoint(-2.0392, 3.098, 0);
  14. points->InsertNextPoint(1.9475, 0.4465, 2);
  15. points->InsertNextPoint(1.183, 1.4711, 2.3);
  16. points->InsertNextPoint(0.018, 1.5855, 2);
  17. points->InsertNextPoint(-1.2925, 1.1278, 1.5);
  18. points->InsertNextPoint(2.7932, 1.0052, 2);
  19. points->InsertNextPoint(2.0935, 2.0645, 2);
  20. points->InsertNextPoint(-0.1276, 2.48, 2);
  21. points->InsertNextPoint(-1.6423, 2.1293, 2.5);
  22. points->InsertNextPoint(3.7595, 1.9673, 2);
  23. points->InsertNextPoint(2.7703, 2.5821, 2);
  24. points->InsertNextPoint(-0.0339, 3.2228, 2);
  25. points->InsertNextPoint(-2.0392, 3.098, 2);
  26. Create(vtkStructuredGrid, grid);
  27. grid->SetDimensions(4, 3, 2);
  28. grid->SetPoints(points);

直接赋值第一层的12个点,改一下Z值。一定要同步修改Z方向维度为2.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/994771
推荐阅读
相关标签
  

闽ICP备14008679号