1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestIntersectionPolyDataFilter3.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <vtkIntersectionPolyDataFilter.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkCubeSource.h>
#include <vtkLinearSubdivisionFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkTriangleFilter.h>
int TestIntersectionPolyDataFilter3(int, char *[])
{
vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
cubeSource->SetCenter(0.0, 0.0, 0.0);
cubeSource->SetXLength(1.0);
cubeSource->SetYLength(1.0);
cubeSource->SetZLength(1.0);
cubeSource->Update();
vtkSmartPointer<vtkTriangleFilter> cubetriangulator =
vtkSmartPointer<vtkTriangleFilter>::New();
cubetriangulator->SetInputConnection(cubeSource->GetOutputPort());
vtkSmartPointer<vtkLinearSubdivisionFilter> cubesubdivider =
vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
cubesubdivider->SetInputConnection(cubetriangulator->GetOutputPort());
cubesubdivider->SetNumberOfSubdivisions(3);
vtkSmartPointer<vtkPolyDataMapper> cubeMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cubeMapper->SetInputConnection( cubesubdivider->GetOutputPort() );
cubeMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> cubeActor =
vtkSmartPointer<vtkActor>::New();
cubeActor->SetMapper( cubeMapper );
cubeActor->GetProperty()->SetOpacity(.3);
cubeActor->GetProperty()->SetColor(1,0,0);
cubeActor->GetProperty()->SetInterpolationToFlat();
vtkSmartPointer<vtkConeSource> coneSource =
vtkSmartPointer<vtkConeSource>::New();
coneSource->SetCenter(0.0, 0.0, 0.0);
coneSource->SetRadius(0.5);
coneSource->SetHeight(2.0);
coneSource->SetResolution(10.0);
coneSource->SetDirection(1,0,0);
vtkSmartPointer<vtkTriangleFilter> conetriangulator =
vtkSmartPointer<vtkTriangleFilter>::New();
conetriangulator->SetInputConnection(coneSource->GetOutputPort());
vtkSmartPointer<vtkLinearSubdivisionFilter> conesubdivider =
vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
conesubdivider->SetInputConnection(conetriangulator->GetOutputPort());
conesubdivider->SetNumberOfSubdivisions(3);
vtkSmartPointer<vtkPolyDataMapper> coneMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
coneMapper->SetInputConnection( conesubdivider->GetOutputPort() );
coneMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> coneActor =
vtkSmartPointer<vtkActor>::New();
coneActor->SetMapper( coneMapper );
coneActor->GetProperty()->SetOpacity(.3);
coneActor->GetProperty()->SetColor(0,1,0);
coneActor->GetProperty()->SetInterpolationToFlat();
vtkSmartPointer<vtkIntersectionPolyDataFilter> intersectionPolyDataFilter =
vtkSmartPointer<vtkIntersectionPolyDataFilter>::New();
intersectionPolyDataFilter->SetInputConnection( 0, cubesubdivider->GetOutputPort() );
intersectionPolyDataFilter->SetInputConnection( 1, conesubdivider->GetOutputPort() );
intersectionPolyDataFilter->SetSplitFirstOutput(0);
intersectionPolyDataFilter->SetSplitSecondOutput(0);
intersectionPolyDataFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> intersectionMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
intersectionMapper->SetInputConnection( intersectionPolyDataFilter->GetOutputPort() );
intersectionMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> intersectionActor =
vtkSmartPointer<vtkActor>::New();
intersectionActor->SetMapper( intersectionMapper );
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddViewProp(cubeActor);
renderer->AddViewProp(coneActor);
renderer->AddViewProp(intersectionActor);
renderer->SetBackground(.1, .2, .3);
vtkSmartPointer<vtkRenderWindow> renderWindow
= vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer( renderer );
vtkSmartPointer<vtkRenderWindowInteractor> renWinInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renWinInteractor->SetRenderWindow( renderWindow );
intersectionPolyDataFilter->Print(std::cout);
renderWindow->Render();
renWinInteractor->Start();
return EXIT_SUCCESS;
}
|