python vtk 三角化_VTK中二维Delaunay三角剖分

1 #include"vtkActor.h"2 #include"vtkCellArray.h"3 #include"vtkPoints.h"4 #include"vtkPolyData.h"5 #include"vtkPolyDataMapper.h"6 #include"vtkRenderWindow.h"7 #include"vtkRenderWindowInteractor.h"8 #include"vtkRenderer.h"9 #include"vtkTubeFilter.h"10 #include"vtkDelaunay2D.h"11 #include"vtkExtractEdges.h"12 #include"vtkInteractorStyleTrackballCamera.h"13 #include"vtkProperty.h"14 #include"vtkCamera.h"15 16 #pragmacomment( lib, "vtkGraphics" )17 #pragmacomment( lib, "vtkRendering" )18 #pragmacomment( lib, "vtkFiltering" )19 #pragmacomment( lib, "vtkCommon" )20 #pragmacomment( lib, "vtkWidgets")21 #pragmacomment( lib, "vtksys")22 #pragmacomment( lib, "vtkIO")23 #pragmacomment( lib, "vtkexpat")24 #pragmacomment( lib, "vtkjpeg")25 #pragmacomment( lib, "vtkpng")26 #pragmacomment( lib, "vtkzlib")27 #pragmacomment( lib, "vtktiff")28 #pragmacomment( lib, "OpenGL32")29 #pragmacomment( lib, "vtkImaging")30 #pragmacomment( lib, "vtkHybrid")31 32 #defineNUM_INPUT 1433 #defineNUM_CONSTRAIN1 1634 #defineNUM_CONSTRAIN2 335 #defineNUM_TOTAL (NUM_INPUT + NUM_CONSTRAIN1 + NUM_CONSTRAIN2)36 intmain(intargc,char*argv[] )37 {38 //Generate the input points and constrained edges/polygons.39 floatinput[NUM_TOTAL][3]={{0,100,0}, {0,50,0}, {0,0,0}, {50,0,0}, {100,0,0}, {150,0,0},40 {200,0,0}, {200,50,0}, {200,100,0}, {200,150,0}, {150,150,0},41 {100,150,0}, {50,150,0}, {0,150,0}, {154,29,0}, {167,29,0},42 {167,20,0}, {120,20,0}, {120,29,0}, {138,29,0}, {121,63,0},43 {74,63,0}, {58,29,0}, {78,29,0}, {78,20,0}, {38,20,0},44 {38,29,0}, {50,29,0}, {95,130,0}, {110,135,0}, {76,70,0},45 {120,70,0}, {99,121,0}};46 vtkPoints*points=vtkPoints::New();47 48 //添加所有点49 for(inti=0; iInsertPoint(i, input[i]);52 }53 //添加CELL54 vtkCellArray*polys=vtkCellArray::New();55 polys->InsertNextCell(NUM_INPUT);56 for(inti=0; iInsertCellPoint(i );//所有输入的点 组成一个CELL59 }60 polys->InsertNextCell(NUM_CONSTRAIN1);61 for(inti=0; iInsertCellPoint(i+NUM_INPUT);64 }65 polys->InsertNextCell(NUM_CONSTRAIN2);66 for(inti=0; iInsertCellPoint(i+NUM_INPUT+NUM_CONSTRAIN1);//约束269 }70 71 vtkPolyData*polyData=vtkPolyData::New();72 polyData->SetPoints(points);//添加点集73 polyData->SetPolys(polys);//添加面集74 75 vtkDelaunay2D*del=vtkDelaunay2D::New();76 del->SetInput(polyData);//对数据进行Delaunay剖分77 del->SetSource(polyData);78 79 vtkPolyDataMapper*mapMesh=vtkPolyDataMapper::New();80 mapMesh->SetInput(del->GetOutput());//映射到Mapper81 82 vtkActor*meshActor=vtkActor::New();83 meshActor->SetMapper(mapMesh);84 meshActor->GetProperty()->SetColor(0.4,1.0,0.4);85 meshActor->GetProperty()->SetOpacity(0.4);86 87 vtkExtractEdges*extract=vtkExtractEdges::New();//提取Delaunay三角网边界 可以从任何类型的数据中提取边界88 extract->SetInput(del->GetOutput());89 vtkTubeFilter*tubes=vtkTubeFilter::New();90 tubes->SetInput(extract->GetOutput());91 tubes->SetRadius(1.4);92 tubes->SetNumberOfSides(5);93 94 vtkPolyDataMapper*mapEdges=vtkPolyDataMapper::New();//映射95 mapEdges->SetInput(tubes->GetOutput());96 97 vtkActor*edgeActor=vtkActor::New();98 edgeActor->SetMapper(mapEdges);99 edgeActor->GetProperty()->SetColor(1,1,0);100 101 //Create the rendering window, renderer, and interactive renderer102 vtkRenderer*ren1=vtkRenderer::New();103 vtkRenderWindow*renWin=vtkRenderWindow::New();104 renWin->AddRenderer(ren1);105 106 //Add the actors to the renderer, set the background and size107 ren1->AddActor(meshActor);108 ren1->AddActor(edgeActor);109 ren1->SetBackground(0.0,0.0,0.2);110 ren1->GetActiveCamera()->Zoom(1.8);111 renWin->SetSize(500,400);112 113 vtkRenderWindowInteractor*iren=vtkRenderWindowInteractor::New();114 iren->SetRenderWindow(renWin);115 116 vtkInteractorStyleTrackballCamera*style=vtkInteractorStyleTrackballCamera::New();117 iren->SetInteractorStyle(style);118 iren->Initialize();119 iren->Start();120 121 //Free up any objects we created. All instances in VTK are deleted by122 //using the Delete() method.123 points->Delete();124 polys->Delete();125 polyData->Delete();126 del->Delete();127 mapMesh->Delete();128 meshActor->Delete();129 extract->Delete();130 tubes->Delete();131 mapEdges->Delete();132 edgeActor->Delete();133 ren1->Delete();134 renWin->Delete();135 iren->Delete();136 style->Delete();137 return0;138 }139 140

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值