赞
踩
2020-06-10
数据对象被组织成一种结构并且被赋予相应的属性值时就形成数据集(Dataset)。VTK里数据集对应的类是vtkDataSet,该类从vtkDataObject直接派生。vtkDataSet由两个部分组成,即组织结构(Organizing Structure)以及与组织结构相关联的属性数据(Attribute Data)。
vtkDataSet的组织结构由拓扑结构(Topology)和几何结构(Geometry)两部分组成。拓扑结构描述了物体的构成形式,几何结构描述了物体的空间位置关系。换言之,点数据(Point Data)所定义的一系列坐标点构成了vtkDataSet(数据集)的几何结构;点数据的连接(点的连接先形成单元数据(Cell Data),由单元数据再形成拓扑)就形成了数据集的拓扑结构。比如,我们想要在屏幕上显示一个三角形,首先我们必须定义三角形三个点的坐标(即Point Data,记三个点为P1, P2和P3),然后将这三个点按照一定的顺序连接起来(P1-P2-P3,或者是P3-P2-P1的顺序),这三个点定义了数据集的几何结构,它们的连接就构成了数据集的拓扑结构。亦即,点数据(Point Data)定义数据集的几何结构,单元数据(Cell Data)定义数据集的拓扑结构,要形成完整的数据集,必须有几何和拓扑两种结构。属性数据是对拓扑结构和几何结构信息的补充,属性数据可以是某个空间点的温度值,也可以是某个单元的质量之类的。属性数据包括点属性和单元属性。可以为vtkPolyData的点数据和单元数据分别指定属性数据。
1.
这里我们只定义了几何结构,即只有点的坐标
#include <vtkSmartPointer.h> #include <vtkPoints.h> #include <vtkPolyData.h> #include <vtkPolyDataMapper.h> #include <vtkActor.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> int main(){ vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New(); pts->InsertNextPoint(0.0, 0.0, 0.0); pts->InsertNextPoint(1.0, 0.0, 0.0); pts->InsertNextPoint(1.0, 1.0, 0.0); pts->InsertNextPoint(0.0, 1.0, 0.0); pts->InsertNextPoint(2.0, 0.0, 0.0); vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New(); polyData->SetPoints(pts); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputData(polyData); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); vtkSmartPointer<vtkRenderer> render = vtkSmartPointer<vtkRenderer>::New(); render->AddActor(actor); render->SetBackground(0.0, 0.0, 0.0); vtkSmartPointer<vtkRenderWindow> rw = vtkSmartPointer<vtkRenderWindow>::New(); rw->AddRenderer(render); rw->SetSize(320, 240); vtkSmartPointer<vtkRenderWindowInteractor> rwi = vtkSmartPointer<vtkRenderWindowInteractor>::New(); rwi->SetRenderWindow(rw); rwi->Render(); rwi->Start(); return 0; }
结果
2
点数据(Point Data)定义数据集的几何结构,单元数据(Cell Data)定义数据集的拓扑结构
vtkCellArray类型的对象vertices就是用来指定数据集polydata的拓扑结构,
而polydata的几何结构则是由points来定义的。
#include <vtkSmartPointer.h> #include <vtkPoints.h> #include <vtkPolyData.h> #include <vtkPolyDataMapper.h> #include <vtkActor.h> #include <vtkProperty.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> int main(){ vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New(); pts->InsertNextPoint(0.0, 0.0, 0.0); pts->InsertNextPoint(1.0, 0.0, 0.0); pts->InsertNextPoint(1.0, 1.0, 0.0); pts->InsertNextPoint(0.0, 1.0, 0.0); pts->InsertNextPoint(2.0, 0.0, 0.0); vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New(); for (int i = 0; i < 5; i++) { vtkIdType pt[1] = { i }; vertices->InsertNextCell(1, pt); } vtkSmartPointer<vtkPolyData> polyData= vtkSmartPointer<vtkPolyData>::New(); polyData->SetPoints(pts); polyData->SetVerts(vertices); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputData(polyData); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); actor->GetProperty()->SetPointSize(5); vtkSmartPointer<vtkRenderer> render = vtkSmartPointer<vtkRenderer>::New(); render->AddActor(actor); render->SetBackground(0.0, 0.0, 0.0); vtkSmartPointer<vtkRenderWindow> rw = vtkSmartPointer<vtkRenderWindow>::New(); rw->AddRenderer(render); rw->SetSize(320, 240); vtkSmartPointer<vtkRenderWindowInteractor> rwi = vtkSmartPointer<vtkRenderWindowInteractor>::New(); rwi->SetRenderWindow(rw); rwi->Render(); rwi->Start(); return 0; }
结果
如果什么也没有显示可以用鼠标滚轮进行缩放一下
3
将零维的点拓扑结构改成一维的线拓扑结构
#include <vtkSmartPointer.h> #include <vtkPoints.h> #include <vtkLine.h> #include <vtkPolyData.h> #include <vtkPolyDataMapper.h> #include <vtkActor.h> #include <vtkProperty.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> int main(){ vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New(); pts->InsertNextPoint(1.0, 0.0, 0.0); pts->InsertNextPoint(0.0, 0.0, 1.0); pts->InsertNextPoint(0.0, 0.0, 0.0); vtkSmartPointer<vtkLine> line0 = vtkSmartPointer<vtkLine>::New(); line0->GetPointIds()->SetId(0, 0); line0->GetPointIds()->SetId(1, 1); vtkSmartPointer<vtkLine> line1 = vtkSmartPointer<vtkLine>::New(); line1->GetPointIds()->SetId(0, 0); line1->GetPointIds()->SetId(1, 2); vtkSmartPointer<vtkLine> line2 = vtkSmartPointer<vtkLine>::New(); line2->GetPointIds()->SetId(0, 1); line2->GetPointIds()->SetId(1, 2); vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); lines->InsertNextCell(line0); lines->InsertNextCell(line1); lines->InsertNextCell(line2); vtkSmartPointer<vtkPolyData> polyData= vtkSmartPointer<vtkPolyData>::New(); polyData->SetPoints(pts); polyData->SetLines(lines); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputData(polyData); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); vtkSmartPointer<vtkRenderer> render = vtkSmartPointer<vtkRenderer>::New(); render->AddActor(actor); render->SetBackground(0.0, 0.0, 0.0); vtkSmartPointer<vtkRenderWindow> rw = vtkSmartPointer<vtkRenderWindow>::New(); rw->AddRenderer(render); rw->SetSize(320, 240); vtkSmartPointer<vtkRenderWindowInteractor> rwi = vtkSmartPointer<vtkRenderWindowInteractor>::New(); rwi->SetRenderWindow(rw); rwi->Render(); rwi->Start(); return 0; }
结果
如果什么也没有显示可以用鼠标滚轮进行缩放一下
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。