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

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to: navigation, search
(Replaced content with "= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColorDisconnectedRegions ColorDisconnectedRegions] on the new [https://lorensen.github.io/VTKExamples/si...")
 
Line 1: Line 1:
<div class="floatright">[[File:VTK_Examples_Baseline_PolyData_TestColorDisconnectedRegions.png]]</div>
+
= '''See [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColorDisconnectedRegions ColorDisconnectedRegions] on the new [https://lorensen.github.io/VTKExamples/site/ VTKExamples website].''' =
==ColorDisconnectedRegions.cxx==
 
<source lang="cpp">
 
#include <vtkSmartPointer.h>
 
#include <vtkPointData.h>
 
#include <vtkSphereSource.h>
 
#include <vtkPolyDataConnectivityFilter.h>
 
#include <vtkPolyDataMapper.h>
 
#include <vtkActor.h>
 
#include <vtkProperty.h>
 
#include <vtkRenderer.h>
 
#include <vtkRenderWindow.h>
 
#include <vtkRenderWindowInteractor.h>
 
#include <vtkAppendPolyData.h>
 
 
 
int main(int, char*[])
 
{
 
  // Create some spheres
 
  vtkSmartPointer<vtkSphereSource> sphereSource1 =
 
    vtkSmartPointer<vtkSphereSource>::New();
 
  sphereSource1->Update();
 
 
 
  vtkSmartPointer<vtkSphereSource> sphereSource2 =
 
    vtkSmartPointer<vtkSphereSource>::New();
 
  sphereSource2->SetCenter(5,0,0);
 
  sphereSource2->Update();
 
 
 
  vtkSmartPointer<vtkSphereSource> sphereSource3 =
 
    vtkSmartPointer<vtkSphereSource>::New();
 
  sphereSource3->SetCenter(10,0,0);
 
  sphereSource3->Update();
 
 
 
  vtkSmartPointer<vtkAppendPolyData> appendFilter =
 
    vtkSmartPointer<vtkAppendPolyData>::New();
 
  appendFilter->AddInputConnection(sphereSource1->GetOutputPort());
 
  appendFilter->AddInputConnection(sphereSource2->GetOutputPort());
 
  appendFilter->AddInputConnection(sphereSource3->GetOutputPort());
 
  appendFilter->Update();
 
 
 
  vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
 
    vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
 
  connectivityFilter->SetInputConnection(appendFilter->GetOutputPort());
 
  connectivityFilter->SetExtractionModeToAllRegions();
 
  connectivityFilter->ColorRegionsOn();
 
  connectivityFilter->Update();
 
 
 
  // Visualize
 
  vtkSmartPointer<vtkPolyDataMapper> mapper =
 
    vtkSmartPointer<vtkPolyDataMapper>::New();
 
  mapper->SetInputConnection(connectivityFilter->GetOutputPort());
 
  mapper->SetScalarRange(connectivityFilter->GetOutput()->GetPointData()->GetArray("RegionId")->GetRange());
 
  mapper->Update();
 
 
 
  vtkSmartPointer<vtkActor> actor =
 
    vtkSmartPointer<vtkActor>::New();
 
  actor->SetMapper(mapper);
 
 
 
  vtkSmartPointer<vtkRenderer> renderer =
 
    vtkSmartPointer<vtkRenderer>::New();
 
  renderer->AddActor(actor);
 
 
 
  vtkSmartPointer<vtkRenderWindow> renderWindow =
 
    vtkSmartPointer<vtkRenderWindow>::New();
 
  renderWindow->AddRenderer(renderer);
 
 
 
  vtkSmartPointer<vtkRenderWindowInteractor> interactor =
 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
 
  interactor->SetRenderWindow(renderWindow);
 
  interactor->Initialize();
 
  interactor->Start();
 
 
 
  return EXIT_SUCCESS;
 
}
 
</source>
 
 
 
{{VTKCMakeLists|{{SUBPAGENAME}}}}
 

Latest revision as of 15:32, 9 September 2019

See ColorDisconnectedRegions on the new VTKExamples website.