三角链实例代码
#include <iostream>
#include <string>
#include <regex>
#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 <vtkAutoInit.h>
#include<vtkPNGReader.h>
#include<vtkTexture.h>
#include<vtkPlaneSource.h>
#include<vtkStringArray.h>
#include<vtkPoints.h>#include<vtkTecplotReader.h>
#include <iostream>
#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 <fstream>int main(int agrv, char * agrc) {vtkNew<vtkPoints> 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<vtkCellArray> 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<vtkPolyData> poly;poly->SetPoints(points);poly->SetStrips(strips);vtkNew<vtkPolyDataMapper> mapper;mapper->SetInputData(poly);vtkNew<vtkActor> actor; //演员actor->SetMapper(mapper); vtkNew<vtkRenderer> render; //设置舞台render->AddActor(actor); //演员上舞台render->SetBackground(0.0, 0.0, 0.0);//设置舞台背景vtkNew<vtkRenderWindow> renWin; //renWin->AddRenderer(render);//舞台搬进戏院renWin->SetSize(640, 480);//戏院大小renWin->Render(); //戏院渲染renWin->SetWindowName("vtkPipelineDemo");//戏院起名vtkNew<vtkRenderWindowInteractor> interactor; //与看客交互interactor->SetRenderWindow(renWin);interactor->Initialize();interactor->Start();}
单元数据分成两个写,如下,结果一样。
vtkNew<vtkCellArray> 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<vtkPolyData> poly;
运行结果:
按w键,查看线结构:
在线性结构里面,属于下图;f) Triangle strip(n triangles)