1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestIntersectionPolyDataFilter.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13 =========================================================================*/
14
15 #include <vtkIntersectionPolyDataFilter.h>
16
17 #include <vtkActor.h>
18 #include <vtkPolyDataMapper.h>
19 #include <vtkProperty.h>
20 #include <vtkRenderWindow.h>
21 #include <vtkRenderWindowInteractor.h>
22 #include <vtkRenderer.h>
23 #include <vtkSmartPointer.h>
24 #include <vtkSphereSource.h>
25
TestIntersectionPolyDataFilter(int,char * [])26 int TestIntersectionPolyDataFilter(int, char*[])
27 {
28 vtkSmartPointer<vtkSphereSource> sphereSource1 = vtkSmartPointer<vtkSphereSource>::New();
29 sphereSource1->SetCenter(0.0, 0.0, 0.0);
30 sphereSource1->SetRadius(2.0);
31 sphereSource1->SetPhiResolution(11);
32 sphereSource1->SetThetaResolution(21);
33 sphereSource1->Update();
34 vtkSmartPointer<vtkPolyDataMapper> sphere1Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
35 sphere1Mapper->SetInputConnection(sphereSource1->GetOutputPort());
36 sphere1Mapper->ScalarVisibilityOff();
37 vtkSmartPointer<vtkActor> sphere1Actor = vtkSmartPointer<vtkActor>::New();
38 sphere1Actor->SetMapper(sphere1Mapper);
39 sphere1Actor->GetProperty()->SetOpacity(.3);
40 sphere1Actor->GetProperty()->SetColor(1, 0, 0);
41 sphere1Actor->GetProperty()->SetInterpolationToFlat();
42
43 vtkSmartPointer<vtkSphereSource> sphereSource2 = vtkSmartPointer<vtkSphereSource>::New();
44 sphereSource2->SetCenter(1.0, 0.0, 0.0);
45 sphereSource2->SetRadius(2.0);
46 vtkSmartPointer<vtkPolyDataMapper> sphere2Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
47 sphere2Mapper->SetInputConnection(sphereSource2->GetOutputPort());
48 sphere2Mapper->ScalarVisibilityOff();
49 vtkSmartPointer<vtkActor> sphere2Actor = vtkSmartPointer<vtkActor>::New();
50 sphere2Actor->SetMapper(sphere2Mapper);
51 sphere2Actor->GetProperty()->SetOpacity(.3);
52 sphere2Actor->GetProperty()->SetColor(0, 1, 0);
53 sphere2Actor->GetProperty()->SetInterpolationToFlat();
54
55 vtkSmartPointer<vtkIntersectionPolyDataFilter> intersectionPolyDataFilter =
56 vtkSmartPointer<vtkIntersectionPolyDataFilter>::New();
57 intersectionPolyDataFilter->SetInputConnection(0, sphereSource1->GetOutputPort());
58 intersectionPolyDataFilter->SetInputConnection(1, sphereSource2->GetOutputPort());
59 intersectionPolyDataFilter->Update();
60
61 vtkSmartPointer<vtkPolyDataMapper> intersectionMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
62 intersectionMapper->SetInputConnection(intersectionPolyDataFilter->GetOutputPort());
63 intersectionMapper->ScalarVisibilityOff();
64
65 vtkSmartPointer<vtkActor> intersectionActor = vtkSmartPointer<vtkActor>::New();
66 intersectionActor->SetMapper(intersectionMapper);
67
68 vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
69 renderer->AddViewProp(sphere1Actor);
70 renderer->AddViewProp(sphere2Actor);
71 renderer->AddViewProp(intersectionActor);
72 renderer->SetBackground(.1, .2, .3);
73
74 vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
75 renderWindow->AddRenderer(renderer);
76
77 vtkSmartPointer<vtkRenderWindowInteractor> renWinInteractor =
78 vtkSmartPointer<vtkRenderWindowInteractor>::New();
79 renWinInteractor->SetRenderWindow(renderWindow);
80
81 intersectionPolyDataFilter->Print(std::cout);
82
83 renderWindow->Render();
84 renWinInteractor->Start();
85
86 return EXIT_SUCCESS;
87 }
88