VTK/Examples/SurfaceFromUnorganizedPoints
From KitwarePublic
< VTK | Examples(Redirected from Create a surface from Unorganized Points)
This example creates points on a sphere and then finds the surface through the points.
SurfaceFromUnorganizedPoints.cxx
#include <vtkSmartPointer.h> #include <vtkSurfaceReconstructionFilter.h> #include <vtkProgrammableSource.h> #include <vtkContourFilter.h> #include <vtkReverseSense.h> #include <vtkPolyDataMapper.h> #include <vtkProperty.h> #include <vtkPolyData.h> #include <vtkCamera.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkSphereSource.h> int main(int argc, char **argv) { vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); sphereSource->Update(); vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New(); polydata->SetPoints(sphereSource->GetOutput()->GetPoints()); // Construct the surface and create isosurface. vtkSmartPointer<vtkSurfaceReconstructionFilter> surf = vtkSmartPointer<vtkSurfaceReconstructionFilter>::New(); surf->SetInput(polydata); vtkSmartPointer<vtkContourFilter> cf = vtkSmartPointer<vtkContourFilter>::New(); cf->SetInputConnection(surf->GetOutputPort()); cf->SetValue(0, 0.0); // Sometimes the contouring algorithm can create a volume whose gradient // vector and ordering of polygon (using the right hand rule) are // inconsistent. vtkReverseSense cures this problem. vtkSmartPointer<vtkReverseSense> reverse = vtkSmartPointer<vtkReverseSense>::New(); reverse->SetInputConnection(cf->GetOutputPort()); reverse->ReverseCellsOn(); reverse->ReverseNormalsOn(); vtkSmartPointer<vtkPolyDataMapper> map = vtkSmartPointer<vtkPolyDataMapper>::New(); map->SetInputConnection(reverse->GetOutputPort()); map->ScalarVisibilityOff(); vtkSmartPointer<vtkActor> surfaceActor = vtkSmartPointer<vtkActor>::New(); surfaceActor->SetMapper(map); // Create the RenderWindow, Renderer and both Actors vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New(); renWin->AddRenderer(ren); vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New(); iren->SetRenderWindow(renWin); // Add the actors to the renderer, set the background and size ren->AddActor(surfaceActor); ren->SetBackground(1, 1, 1); iren->Initialize(); renWin->Render(); iren->Start(); return EXIT_SUCCESS; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(SurfaceFromUnorganizedPoints) FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE}) ADD_EXECUTABLE(main SurfaceFromUnorganizedPoints.cxx) TARGET_LINK_LIBRARIES(SurfaceFromUnorganizedPoints vtkHybrid)

