VTK-vtkStructuredGrid学习

        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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值