From KitwarePublic
< VTK‎ | Examples
Jump to navigationJump to search

Create a solid mesh from unorganized points Delaunay3D with Alpha)

This example creates a tetrahedral mesh from unorganized points. The example uses the vtkDelaunay3D filter with a non-zero Alpha. Only tetrahedra, triangles, edges and vertices that lie within the alpha radius are output. The resulting mesh is an unstructured grid that contains tetrahedra, triangles, edges and vertices. The example takes the points from a XML PolyData file (.vtp) and produces an XML Unstructured Grid file (.vtu).

Once you generate the file, you can view the results with Paraview.

Also, look at the contents of the file with DumpXMLFile.

Contrast the results from this example and Create a solid mesh from unorganized points (Delaunay3D).

Click here to download a sample input file


#include <vtkSmartPointer.h>
#include <vtkCleanPolyData.h>
#include <vtkDelaunay3D.h>
#include <vtkXMLDataSetWriter.h>
#include <vtkXMLPolyDataReader.h>

int main ( int argc, char *argv[] )
  if (argc != 4)
    cout << "Usage: " << argv[0]
         << " Alpha InputPolyDataFile(.vtp) OutputDataSetFile(.vtu)" << endl;
    return EXIT_FAILURE;

  //Read a file
  vtkSmartPointer<vtkXMLPolyDataReader> reader =
  reader->SetFileName (argv[2]);

  // Clean the polydata. This will remove duplicate points that may be
  // present in the input data.
  vtkSmartPointer<vtkCleanPolyData> cleaner =
  cleaner->SetInputConnection (reader->GetOutputPort());

  // Generate a mesh from the input points. If Alpha is non-zero, then
  // tetrahedra, triangles, edges and vertices that lie within the
  // alpha radius are output.
  vtkSmartPointer<vtkDelaunay3D> delaunay3D =
  delaunay3D->SetInputConnection (cleaner->GetOutputPort());

  // Output the mesh
  vtkSmartPointer<vtkXMLDataSetWriter> writer =
  writer->SetFileName ( argv[3] );
  writer->SetInputConnection ( delaunay3D->GetOutputPort() );

  return EXIT_SUCCESS;

Please try the new VTKExamples website.


cmake_minimum_required(VERSION 2.8)


find_package(VTK REQUIRED)

add_executable(Delaunay3DAlpha MACOSX_BUNDLE Delaunay3DAlpha.cxx)

  target_link_libraries(Delaunay3DAlpha ${VTK_LIBRARIES})
  target_link_libraries(Delaunay3DAlpha vtkHybrid vtkWidgets)

Download and Build Delaunay3DAlpha

Click here to download Delaunay3DAlpha. and its CMakeLists.txt file.

Once the tarball Delaunay3DAlpha.tar has been downloaded and extracted,

cd Delaunay3DAlpha/build 
  • If VTK is installed:
cmake ..
  • If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:


and run it:


WINDOWS USERS PLEASE NOTE: Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.