#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; }
python vtk 三角化_VTK实现Delaunay三角化
最新推荐文章于 2024-04-28 10:30:53 发布