VTK 数据类型:vtkUnstructuredGrid

VTK 数据类型:vtkUnstructuredGrid

非结构化点是在空间中离散随意分布的点,没有拓扑结构,几何机构也是完全没有规则的。非结构化点由顶点和多点的单元组成;非结构化点是一种简单但很重要的数据集类型,在部分可视化工作中会使用它来表示无结构的数据。

非结构化网格数据,是最常见的数据集类型,它的拓扑结构和几何结构都是非结构化的,所有单元类型都可以任意组合,所有单元的拓扑结构从零维延伸至三维。

在VTK中,任一类型的数据集都可用非结构化网格来表达,但其储存需要大量的空间,计算时需要消耗大量的资源,除非迫不得已,一般较少使用此种类型的数据集。

非结构化网格主要用于有限元分析、计算几何和几何建模这类领域。

VTK 中数据类型的继承关系

在这里插入图片描述

常用的几何类型

VTKCellType 是一个 enum,其中列举了常用的几何类型:

类型含义
VTK_EMPTY_CELL空单元
VTK_VERTEX顶点,由一个点定义,是零维度基本类型。
VTK_POLY_VERTEX多顶点,由多个顶点组合而成,是零维度的组合单元。
VTK_LINE直线,由两个点定义,方向是从第一个点指向第二个点。
VTK_POLY_LINE折线,由一个或多个线段组合而成。由n+1个有序的点连接定义的。n表示折线的线段条数,每两个点定义一条线段。
VTK_TRIANGLE三角形,由三个点按逆时针的方向连接定义,点的连接方向和表面法向量按照右手法则。
VTK_TRIANGLE_STRIP三角形条带,由一个或多个三角形组合而成。由n+2个有序的点连接,n表示三角形条带里三角形的个数,定义三角形条带的点不需要共面。
VTK_POLYGON多边形,是由共面的三个或三个以上的点按逆时针方向的顺序连接定义的。多边形表面法向量的方向通过右手法则确定。
VTK_PIXEL是由共面的四个点按一定的顺序连接定义的。与VTK_QUAD的区别在拓扑结构上,VTK_PIXEL 要求相邻的两条边必须垂直,而且相对两条边要与坐标轴平行。定义VTK_PIXEL 四个点的顺序与四边形不同,VTK_PIXEL 顶点的计数先沿着X轴方向,然后是Y轴,最后是Z轴方向。
VTK_QUAD四边形,由共面的四个点按逆时针的方向连接定义的。四边形要求是非自交的凸多边形。利用右手法则可以得到该四边形的表面法向量。
VTK_TETRA四面体,包含六条边和四个面,是由不共面的四个点两两连接定义的。
VTK_VOXEL正方体,与六面体的拓扑一样,几何上要求相邻的两个面必须垂直,VOXEL是VTK_HEXAHEDRON 的特殊形式。
VTK_HEXAHEDRON六面体,包含六个四边形面、12条边和8个顶点,六面体要求是凸多边形。
VTK_WEDGE楔形,三棱柱,由三个四边形面、两个三角形面、9条边和6个顶点构成。要求面和边不能与其他的相交,且楔形必须是凸多边形。
VTK_PYRAMID角椎体,金字塔形状。由一个四边形面、四个三角形面、8条边和五个顶点构成。定义四边形的四个点要求共面,且四个点构成的四边形必须是凸四边形,第五个点不在其他四个点定义的平面上。
VTK_PENTAGONAL_PRISM五棱柱,由五个四边形面、两个五边形面、15条边和10个顶点构成。五棱柱的面和边不能与其他的相交,且五棱柱必须是凸五边形。
VTK_HEXAGONAL_PRISM六角柱,由六个四边形面、两个六边形面、18条边和12个顶点构成。六角柱的面和边不能与其他的相交,且六角柱必须是凸六边形。

实例:vtkHexahedron 和 vtkTetra

非结构化数据的构建只需要 3 步:第一步是设置 vtkPoints 的点数,并插入点;第二步是设置几何类型类,如 vtkTetra,按顺序插入 vtkPoints 类的点。最后在 vtkUnstructuredGrid 类中设置好点和几何类型类即可。

#include "VTKUnstructuredGrid.h"

#include <vtkHexahedron.h>
#include <vtkTetra.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetMapper.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>

VTKUnstructuredGrid::VTKUnstructuredGrid(QWidget* parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);

	_pVTKWidget = new QVTKOpenGLNativeWidget();
	this->setCentralWidget(_pVTKWidget);

	vtkNew<vtkRenderer> renderer;
	this->_pVTKWidget->renderWindow()->AddRenderer(renderer);
	this->_pVTKWidget->renderWindow()->Render();

	vtkNew<vtkPoints> hexahedronPoints;
	hexahedronPoints->SetNumberOfPoints(8);
	hexahedronPoints->InsertPoint(0, 0, 0, 0);
	hexahedronPoints->InsertPoint(1, 1, 0, 0);
	hexahedronPoints->InsertPoint(2, 1, 1, 0);
	hexahedronPoints->InsertPoint(3, 0, 1, 0);
	hexahedronPoints->InsertPoint(4, 0, 0, 1);
	hexahedronPoints->InsertPoint(5, 1, 0, 1);
	hexahedronPoints->InsertPoint(6, 1, 1, 1);
	hexahedronPoints->InsertPoint(7, 0, 1, 1);
	vtkNew<vtkHexahedron> hexahedron;
	hexahedron->GetPointIds()->SetId(0, 0);
	hexahedron->GetPointIds()->SetId(1, 1);
	hexahedron->GetPointIds()->SetId(2, 2);
	hexahedron->GetPointIds()->SetId(3, 3);
	hexahedron->GetPointIds()->SetId(4, 4);
	hexahedron->GetPointIds()->SetId(5, 5);
	hexahedron->GetPointIds()->SetId(6, 6);
	hexahedron->GetPointIds()->SetId(7, 7);
	vtkNew<vtkUnstructuredGrid> hexahedronGrid;
	hexahedronGrid->SetPoints(hexahedronPoints);
	hexahedronGrid->InsertNextCell(hexahedron->GetCellType(), hexahedron->GetPointIds());

	vtkNew<vtkPoints> tetraPoints;
	tetraPoints->SetNumberOfPoints(4);
	tetraPoints->InsertPoint(0, 0, 0, 0);
	tetraPoints->InsertPoint(1, 1, 0, 0);
	tetraPoints->InsertPoint(2, 0.5, 1, 0);
	tetraPoints->InsertPoint(3, 0.5, 0.5, 1);
	vtkNew<vtkTetra> tetra;
	tetra->GetPointIds()->SetId(0, 0);
	tetra->GetPointIds()->SetId(1, 1);
	tetra->GetPointIds()->SetId(2, 2);
	tetra->GetPointIds()->SetId(3, 3);
	vtkNew<vtkUnstructuredGrid> tetraGrid;
	tetraGrid->SetPoints(tetraPoints);
	tetraGrid->InsertNextCell(tetra->GetCellType(), tetra->GetPointIds());

	vtkNew<vtkDataSetMapper> hexahedronMapper;
	hexahedronMapper->SetInputData(hexahedronGrid);
	vtkNew<vtkDataSetMapper> tetraMapper;
	tetraMapper->SetInputData(tetraGrid);

	vtkNew<vtkActor> hexahedronActor;
	hexahedronActor->SetMapper(hexahedronMapper);
	vtkNew<vtkActor> tetraActor;
	tetraActor->SetMapper(tetraMapper);
	tetraActor->SetPosition(2, 0, 0);

	renderer->AddActor(hexahedronActor);
	renderer->AddActor(tetraActor);
}

VTKUnstructuredGrid::~VTKUnstructuredGrid()
{}

本程序构建了一个六面体和四面体。

运行结果:

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UestcXiye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值