VTK系列58_VTK三角剖分(表面重建)
原创
©著作权归作者所有:来自51CTO博客作者亦我飞也的原创作品,请联系作者获取转载授权,否则将追究法律责任
实例58:三角剖分(表面重建)
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <vtkSmartPointer.h>
#include <vtkProperty.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkDelaunay2D.h>
#include <vtkMath.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkVertexGlyphFilter.h>
int main(int, char *[])
{
unsigned int gridSize = 10;
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
for(unsigned int x = 0; x < gridSize; x++)
{
for(unsigned int y = 0; y < gridSize; y++)
{
points->InsertNextPoint(x, y, vtkMath::Random(0.0, 3.0));
}
}
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
vtkSmartPointer<vtkDelaunay2D> delaunay =
vtkSmartPointer<vtkDelaunay2D>::New();
delaunay->SetInputData(polydata);
delaunay->Update();
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputData(polydata);
glyphFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> pointsMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
pointsMapper->SetInputData(glyphFilter->GetOutput());
vtkSmartPointer<vtkActor> pointsActor =
vtkSmartPointer<vtkActor>::New();
pointsActor->SetMapper(pointsMapper);
pointsActor->GetProperty()->SetPointSize(3);
pointsActor->GetProperty()->SetColor(1,0,0);
vtkSmartPointer<vtkPolyDataMapper> triangulatedMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
triangulatedMapper->SetInputData(delaunay->GetOutput());
vtkSmartPointer<vtkActor> triangulatedActor =
vtkSmartPointer<vtkActor>::New();
triangulatedActor->SetMapper(triangulatedMapper);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(pointsActor);
renderer->AddActor(triangulatedActor);
renderer->SetBackground(1.0, 1.0, 1.0);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindow->SetSize(640, 320);
renderWindow->Render();
renderWindow->SetWindowName("PolyDataDelaunay2D");
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
VTK系列目录: