#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkLight.h>
#include <vtkCamera.h>
#include <vtkPolyDataWriter.h>
int main()
{
//vtk几何结构与拓扑结构-三个点的显示
double X[3] = { 1,0,0 };
double Y[3] = { 0,0,1 };
double Z[3] = { 0,0,0 };
//创建点数据以及在每个点坐标上加入顶点vertex类型单元
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
for (int i=0;i<3;i++)
{
vtkIdType pid[1];//int
pid[0] = points->InsertNextPoint(X[i], Y[i], Z[i]);
vertices->InsertNextCell(1, pid);//每个坐标点上创建一个顶点,顶点是单元cell的一种类型
}
//创建vtkPolyData
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);//指定数据集的几何结构
polydata->SetVerts(vertices);//指定数据集的拓扑结构
//写文件vtk
vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
writer->SetFileName("e:\\TriangleVerts.vtk");
writer->SetInputData(polydata);
writer->Write();
return 0;
}
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(Chap03)
FIND_PACKAGE(VTK REQUIRED)
include(${VTK_USE_FILE})
ADD_EXECUTABLE(point point.cpp)
TARGET_LINK_LIBRARIES(point ${VTK_LIBRARIES})
ADD_EXECUTABLE(TriangleVertices TriangleVertices.cpp)
TARGET_LINK_LIBRARIES(TriangleVertices ${VTK_LIBRARIES})
![](https://i-blog.csdnimg.cn/blog_migrate/b191af8c65d39a3011724c2fbfcba277.png)