Difference between revisions of "VTK/Examples/Cxx/PolyData/DownsamplePointCloud"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/DownsamplePointCloud DownsamplePointCloud] on the new [https://lorensen.github.io/VTKExamples/site/ VTKE...")
 
Line 1: Line 1:
<div class="floatcenter">[[File:VTK_Examples_Baseline_PolyData_TestDownsamplePointCloud.png]]</div>
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/DownsamplePointCloud DownsamplePointCloud] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
This example downsamples a point cloud by specifying the minimum distance two points can be from each other. The filter will delete points so that this criterion is met.
 
 
 
==DownsamplePointCloud.cxx==
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkPointSource.h>
 
#include <vtkPolyData.h>
 
#include <vtkCleanPolyData.h>
 
#include <vtkPolyDataMapper.h>
 
#include <vtkActor.h>
 
#include <vtkRenderWindow.h>
 
#include <vtkRenderer.h>
 
#include <vtkRenderWindowInteractor.h>
 
 
 
int main(int, char *[])
 
{
 
  vtkSmartPointer<vtkPointSource> pointSource =
 
    vtkSmartPointer<vtkPointSource>::New();
 
  pointSource->SetNumberOfPoints(1000);
 
  pointSource->SetRadius(1.0);
 
  pointSource->Update();
 
 
 
  vtkSmartPointer<vtkCleanPolyData> cleanPolyData =
 
    vtkSmartPointer<vtkCleanPolyData>::New();
 
  cleanPolyData->SetInputConnection(pointSource->GetOutputPort());
 
  cleanPolyData->SetTolerance(0.1);
 
  cleanPolyData->Update();
 
 
 
  vtkSmartPointer<vtkPolyDataMapper> inputMapper =
 
    vtkSmartPointer<vtkPolyDataMapper>::New();
 
  inputMapper->SetInputConnection(pointSource->GetOutputPort());
 
  vtkSmartPointer<vtkActor> inputActor =
 
    vtkSmartPointer<vtkActor>::New();
 
  inputActor->SetMapper(inputMapper);
 
 
 
  vtkSmartPointer<vtkPolyDataMapper> cleanedMapper =
 
    vtkSmartPointer<vtkPolyDataMapper>::New();
 
  cleanedMapper->SetInputConnection(cleanPolyData->GetOutputPort());
 
  vtkSmartPointer<vtkActor> cleanedActor =
 
    vtkSmartPointer<vtkActor>::New();
 
  cleanedActor->SetMapper(cleanedMapper);
 
 
 
  // There will be one render window
 
  vtkSmartPointer<vtkRenderWindow> renderWindow =
 
    vtkSmartPointer<vtkRenderWindow>::New();
 
  renderWindow->SetSize(600, 300);
 
 
 
  // And one interactor
 
  vtkSmartPointer<vtkRenderWindowInteractor> interactor =
 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
 
  interactor->SetRenderWindow(renderWindow);
 
 
 
  // Define viewport ranges
 
  // (xmin, ymin, xmax, ymax)
 
  double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
 
  double rightViewport[4] = {0.5, 0.0, 1.0, 1.0};
 
 
 
  // Setup both renderers
 
  vtkSmartPointer<vtkRenderer> leftRenderer =
 
    vtkSmartPointer<vtkRenderer>::New();
 
  renderWindow->AddRenderer(leftRenderer);
 
  leftRenderer->SetViewport(leftViewport);
 
  leftRenderer->SetBackground(.6, .5, .4);
 
 
 
  vtkSmartPointer<vtkRenderer> rightRenderer =
 
    vtkSmartPointer<vtkRenderer>::New();
 
  renderWindow->AddRenderer(rightRenderer);
 
  rightRenderer->SetViewport(rightViewport);
 
  rightRenderer->SetBackground(.4, .5, .6);
 
 
 
  leftRenderer->AddActor(inputActor);
 
  rightRenderer->AddActor(cleanedActor);
 
 
 
  leftRenderer->ResetCamera();
 
  rightRenderer->ResetCamera();
 
 
 
  renderWindow->Render();
 
  interactor->Start();
 
 
 
  return EXIT_SUCCESS;
 
}
 
 
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 
 
 
[[Category:VTKAddImage]]
 

Latest revision as of 17:15, 9 September 2019

See DownsamplePointCloud on the new VTKExamples website.