python vtk 三角化_VTK实现Delaunay三角化

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PI 3.1415926 int main(int, char *[]) {         // Generate two circular polygons         vtkSmartPointer points =                 vtkSmartPointer::New();         vtkSmartPointer aCellArray =                 vtkSmartPointer::New();         aCellArray->InsertNextCell(36);         for (int theta = 0;theta<360;theta+=10)         {                 double x = 2*cos(theta*PI/180);                 double y = 2*sin(theta*PI/180);                 vtkIdType pointId = points->InsertNextPoint(x,y,0);                 aCellArray->InsertCellPoint(pointId);         }         aCellArray->InsertNextCell(36);         for (int theta = 350;theta>=0;theta-=10)         {                 double x = cos(theta*PI/180);                 double y = sin(theta*PI/180);                 vtkIdType pointId = points->InsertNextPoint(x,y,0);                 aCellArray->InsertCellPoint(pointId);         }         // Create a polydata to store the polys.         vtkSmartPointer polys =                 vtkSmartPointer::New();         polys->SetPoints(points);         polys->SetPolys(aCellArray);         // Triangulate the grid points         vtkSmartPointer triangulator =                 vtkSmartPointer::New(); #if VTK_MAJOR_VERSION <= 5         triangulator->SetInput(polys);         triangulator->SetSource(polys); #else         triangulator->SetInputData(polys);         triangulator->SetSourceData(polys); #endif         triangulator->Update();         // Visualize         vtkSmartPointer meshMapper =                 vtkSmartPointer::New();         meshMapper->SetInputConnection(triangulator->GetOutputPort());         vtkSmartPointer meshActor =                 vtkSmartPointer::New();         meshActor->SetMapper(meshMapper);         meshActor->GetProperty()->SetRepresentationToWireframe();         vtkSmartPointer edgeFilter =                 vtkSmartPointer::New(); #if VTK_MAJOR_VERSION <= 5         edgeFilter->SetInputConnection(polys->GetProducerPort()); #else         edgeFilter->SetInputData(polys); #endif         edgeFilter->Update();         vtkSmartPointer contourMapper =                 vtkSmartPointer::New();         contourMapper->SetInputConnection(edgeFilter->GetOutputPort());         vtkSmartPointer contourActor =                 vtkSmartPointer::New();         contourActor->SetMapper(contourMapper);         contourActor->GetProperty()->SetColor(1,0,0);         // Create a renderer, render window, and interactor         vtkSmartPointer renderer =                 vtkSmartPointer::New();         vtkSmartPointer renderWindow =                 vtkSmartPointer::New();         renderWindow->AddRenderer(renderer);         vtkSmartPointer renderWindowInteractor =                 vtkSmartPointer::New();         renderWindowInteractor->SetRenderWindow(renderWindow);         // Add the actor to the scene         renderer->AddActor(meshActor);         renderer->AddActor(contourActor);         renderer->SetBackground(.3, .6, .3); // Background color green         // Render and interact         renderWindow->Render();         renderWindowInteractor->Start();         return EXIT_SUCCESS; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值