VTK/Examples/Cxx/PolyData/ConvexHull ShrinkWrap
From KitwarePublic
This example creates a point cloud, and a sphere larger than the point cloud which fully contains the cloud. It then "shrink wraps" the sphere onto the points. This produces approximately a convex hull.
ConvexHullShrinkWrap.cxx
#include <vtkSmartPointer.h> #include <vtkPolyData.h> #include <vtkSphereSource.h> #include <vtkPointSource.h> #include <vtkSmoothPolyDataFilter.h> #include <vtkXMLPolyDataWriter.h> int main(int, char *[]) { vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); sphereSource->SetRadius(10); sphereSource->SetPhiResolution(50); sphereSource->SetThetaResolution(50); sphereSource->Update(); vtkSmartPointer<vtkPointSource> pointSource = vtkSmartPointer<vtkPointSource>::New(); pointSource->SetNumberOfPoints(40); pointSource->SetRadius(2); pointSource->Update(); { vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetFileName("input.vtp"); writer->SetInputConnection(sphereSource->GetOutputPort()); writer->Write(); } { vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetFileName("points.vtp"); writer->SetInputConnection(pointSource->GetOutputPort()); writer->Write(); } vtkSmartPointer<vtkSmoothPolyDataFilter> smoothFilter = vtkSmartPointer<vtkSmoothPolyDataFilter>::New(); smoothFilter->SetInputConnection(0, sphereSource->GetOutputPort()); smoothFilter->SetInputConnection(1, pointSource->GetOutputPort()); smoothFilter->Update(); vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetFileName("output.vtp"); writer->SetInputConnection(smoothFilter->GetOutputPort()); writer->Write(); return EXIT_SUCCESS; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.8) PROJECT(ConvexHullShrinkWrap) find_package(VTK REQUIRED) include(${VTK_USE_FILE}) if (APPLE) add_executable(ConvexHullShrinkWrap MACOSX_BUNDLE ConvexHullShrinkWrap.cxx) else() add_executable(ConvexHullShrinkWrap ConvexHullShrinkWrap.cxx) endif() if(VTK_LIBRARIES) target_link_libraries(ConvexHullShrinkWrap ${VTK_LIBRARIES}) else() target_link_libraries(ConvexHullShrinkWrap vtkHybrid ) endif()
I'm not sure the current code does what it claims to!?