vtk- 数据类型(一) 三角链实例代码

 三角链实例代码

#include 
#include 
#include 
#include "tuex.h"
#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include 
#include
#include
#include
#include
#include

#include
#include 
#include "vtkLine.h"
#include "vtkTriangle.h"
#include "vtkPolyLine.h"

//VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType)
using namespace std;
#include 
 

int main(int agrv, char * agrc) {

	vtkNew points;

	points->InsertPoint(0, 0.0, 0.0, 0.0);
	points->InsertPoint(1, 0.0, 1.0, 0.0);
	points->InsertPoint(2, 1.0, 0.0, 0.0);
	points->InsertPoint(3, 1.0, 1.0, 0.0);
	points->InsertPoint(4, 2.0, 0.0, 0.0);
	points->InsertPoint(5, 2.0, 1.0, 0.0);
	points->InsertPoint(6, 3.0, 0.0, 0.0);
	points->InsertPoint(7, 3.0, 1.0, 0.0);
	 
	vtkNew strips;

	strips->InsertNextCell(8);
	strips->InsertCellPoint(0);
	strips->InsertCellPoint(1);
	strips->InsertCellPoint(2);
	strips->InsertCellPoint(3);
	strips->InsertCellPoint(4);
	strips->InsertCellPoint(5);
	strips->InsertCellPoint(6);
	strips->InsertCellPoint(7);
 
	vtkNew poly;

	poly->SetPoints(points);
	poly->SetStrips(strips);

	vtkNew mapper;
	mapper->SetInputData(poly);

	vtkNew actor; //演员
	actor->SetMapper(mapper); 

	vtkNew render; //设置舞台
	render->AddActor(actor);  //演员上舞台
	render->SetBackground(0.0, 0.0, 0.0);//设置舞台背景

	vtkNew renWin; //
	renWin->AddRenderer(render);//舞台搬进戏院
	renWin->SetSize(640, 480);//戏院大小
	renWin->Render(); //戏院渲染
	renWin->SetWindowName("vtkPipelineDemo");//戏院起名

	vtkNew interactor; //与看客交互
	interactor->SetRenderWindow(renWin);
	interactor->Initialize();
	interactor->Start();
 
}

单元数据分成两个写,如下,结果一样。 

	vtkNew strips;

	strips->InsertNextCell(5);
	strips->InsertCellPoint(0);
	strips->InsertCellPoint(1);
	strips->InsertCellPoint(2);
	strips->InsertCellPoint(3);
	strips->InsertCellPoint(4);
	strips->InsertNextCell(5);
	strips->InsertCellPoint(3);
	strips->InsertCellPoint(4);
	strips->InsertCellPoint(5);
	strips->InsertCellPoint(6);
	strips->InsertCellPoint(7);
	vtkNew poly;

运行结果:

vtk- 数据类型(一) 三角链实例代码_第1张图片

按w键,查看线结构:

vtk- 数据类型(一) 三角链实例代码_第2张图片

 在线性结构里面,属于下图;f) Triangle strip(n triangles)

vtk- 数据类型(一) 三角链实例代码_第3张图片

你可能感兴趣的:(VTK,&,ITK,图像处理,计算机图形学)