VTK/Examples/Cxx/Filtering/Delaunay2D

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Revision as of 08:44, 24 October 2009 by Daviddoria (talk | contribs) (New page: ==Delaunay.cxx== <source lang="cpp"> #include <vtkCellArray.h> #include <vtkPoints.h> #include <vtkTriangle.h> #include <vtkPolyData.h> #include <vtkPointData.h> #include <vtkLine.h> #incl...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Delaunay.cxx

#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkTriangle.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkLine.h>
#include <vtkCellLocator.h>

#include <vtkSmartPointer.h>
#include <vtkDelaunay2D.h>
#include <vtkXMLPolyDataWriter.h>

int main ( int argc, char *argv[] )
{
	//Create a random set of heighs on a grid. This is often called a "terrain map"
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();

	unsigned int GridSize = 10;
	for ( unsigned int x = 0; x < GridSize; x++ )
	{
		for ( unsigned int y = 0; y < GridSize; y++ )
		{
			points->InsertNextPoint ( x, y, drand48() );
		}
	}

	//add the grid points to a polydata object
	vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
	polydata->SetPoints ( points );

	//triangulate the grid points
	vtkSmartPointer<vtkDelaunay2D> delaunay = vtkSmartPointer<vtkDelaunay2D>::New();
	delaunay->SetInput ( polydata );
	delaunay->Update();

	vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
	writer->SetFileName ( "Delaunay.vtp" );
	writer->SetInput ( delaunay->GetOutput() );
	writer->Write();

	return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(Delaunay)

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(Delaunay Delaunay.cxx)
TARGET_LINK_LIBRARIES(Delaunay vtkHybrid)