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 121
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestRotationalExtrusionFilter.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.
=========================================================================*/
// .SECTION Thanks
// This test was written by Philippe Pebay, Kitware SAS 2011
#include "vtkCamera.h"
#include "vtkLineSource.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRotationalExtrusionFilter.h"
#include "vtkTestUtilities.h"
//----------------------------------------------------------------------------
int TestRotationalExtrusion( int argc, char * argv [] )
{
// Create a line source
vtkNew<vtkLineSource> line;
line->SetPoint1( 0., 1., 0. );
line->SetPoint2( 0., 1., 2. );
line->SetResolution( 10 );
// Create mapper for line segment
vtkNew<vtkPolyDataMapper> lineMapper;
lineMapper->SetInputConnection( line->GetOutputPort() );
// Create actor for line segment
vtkNew<vtkActor> lineActor;
lineActor->SetMapper( lineMapper.GetPointer() );
lineActor->GetProperty()->SetLineWidth( 5 );
lineActor->GetProperty()->SetColor( 0., .749, 1. ); // deep sky blue
// Create 3/4 of a cylinder by rotational extrusion
vtkNew<vtkRotationalExtrusionFilter> lineSweeper;
lineSweeper->SetResolution( 20 );
lineSweeper->SetInputConnection( line->GetOutputPort() );
lineSweeper->SetAngle( 270 );
// Create normals for smooth rendering
vtkNew<vtkPolyDataNormals> normals;
normals->SetInputConnection( lineSweeper->GetOutputPort() );
// Create mapper for surface representation
vtkNew<vtkPolyDataMapper> cylMapper;
cylMapper->SetInputConnection( normals->GetOutputPort() );
cylMapper->SetResolveCoincidentTopologyToPolygonOffset();
// Create mapper for wireframe representation
vtkNew<vtkPolyDataMapper> cylMapperW;
cylMapperW->SetInputConnection( lineSweeper->GetOutputPort() );
cylMapperW->SetResolveCoincidentTopologyToPolygonOffset();
// Create actor for surface representation
vtkNew<vtkActor> cylActor;
cylActor->SetMapper( cylMapper.GetPointer() );
cylActor->GetProperty()->SetRepresentationToSurface();
cylActor->GetProperty()->SetInterpolationToGouraud();
cylActor->GetProperty()->SetColor( 1., .3882, .2784 ); // tomato
// Create actor for wireframe representation
vtkNew<vtkActor> cylActorW;
cylActorW->SetMapper( cylMapperW.GetPointer() );
cylActorW->GetProperty()->SetRepresentationToWireframe();
cylActorW->GetProperty()->SetColor( 0., 0., 0.);
cylActorW->GetProperty()->SetAmbient( 1. );
cylActorW->GetProperty()->SetDiffuse( 0. );
cylActorW->GetProperty()->SetSpecular( 0. );
// Create a renderer, add actors to it
vtkNew<vtkRenderer> ren1;
ren1->AddActor( lineActor.GetPointer() );
ren1->AddActor( cylActor.GetPointer() );
ren1->AddActor( cylActorW.GetPointer() );
ren1->SetBackground( 1., 1., 1. );
// Create a renderWindow
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer( ren1.GetPointer() );
renWin->SetSize( 300, 300 );
renWin->SetMultiSamples( 0 );
// Create a good view angle
vtkNew<vtkCamera> camera;
camera->SetClippingRange( 0.576398, 28.8199 );
camera->SetFocalPoint( 0.0463079, -0.0356571, 1.01993 );
camera->SetPosition( -2.47044, 2.39516, -3.56066 );
camera->SetViewUp( 0.607296, -0.513537, -0.606195 );
ren1->SetActiveCamera( camera.GetPointer() );
// Create interactor
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow( renWin.GetPointer() );
// Render and test
renWin->Render();
int retVal = vtkRegressionTestImage( renWin.GetPointer() );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
|