TestPolarAxes.cxx 3.89 KB
Newer Older
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestPolarAxes.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 Pbay, Kitware SAS 2011

#include "vtkBYUReader.h"
#include "vtkCamera.h"
#include "vtkPolarAxesActor.h"
#include "vtkLight.h"
#include "vtkLODActor.h"
#include "vtkNew.h"
#include "vtkOutlineFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"
Philippe Pébay's avatar
Philippe Pébay committed
34
#include "vtkTextProperty.h"
35
36
37
38

//----------------------------------------------------------------------------
int TestPolarAxes( int argc, char * argv [] )
{
39
40
41
  vtkNew<vtkBYUReader> reader;
  char* fname = vtkTestUtilities::ExpandDataFileName( argc, argv, "Data/teapot.g" );
  reader->SetGeometryFileName( fname );
42
43
44
  delete [] fname;

  vtkNew<vtkPolyDataNormals> normals;
45
  normals->SetInputConnection( reader->GetOutputPort() );
46

47
48
  vtkNew<vtkPolyDataMapper> readerMapper;
  readerMapper->SetInputConnection( normals->GetOutputPort() );
49

50
51
  vtkNew<vtkLODActor> readerActor;
  readerActor->SetMapper( readerMapper.GetPointer() );
Philippe Pébay's avatar
Philippe Pébay committed
52
  readerActor->GetProperty()->SetDiffuseColor( .5, .8, .3 );
53
54

  vtkNew<vtkOutlineFilter> outline;
55
  outline->SetInputConnection(normals->GetOutputPort() );
56
57

  vtkNew<vtkPolyDataMapper> mapOutline;
58
  mapOutline->SetInputConnection(outline->GetOutputPort() );
59
60

  vtkNew<vtkActor> outlineActor;
61
62
  outlineActor->SetMapper( mapOutline.GetPointer() );
  outlineActor->GetProperty()->SetColor( 0.0, 0.0, 0.0 );
63
64

  vtkNew<vtkCamera> camera;
65
66
  camera->SetClippingRange( 1.0, 100.0 );
  camera->SetFocalPoint( 0.9, 1.0, 0.0 );
Philippe Pébay's avatar
Philippe Pébay committed
67
  camera->SetPosition( 2., 6., 13. );
68
69

  vtkNew<vtkLight> light;
70
  light->SetFocalPoint( 0.21406, 1.5, 0.0 );
71
  light->SetPosition( 7., 7., 4. );
72

73
74
75
  vtkNew<vtkRenderer> renderer;
  renderer->SetActiveCamera( camera.GetPointer() );
  renderer->AddLight( light.GetPointer() );
76

77
  // Update normals in order to get correct bounds for polar axes
78
  normals->Update();
Philippe Pébay's avatar
Philippe Pébay committed
79
  
80
  vtkNew<vtkPolarAxesActor> polaxes;
81
  polaxes->SetBounds( normals->GetOutput()->GetBounds() );
82
  polaxes->SetPole( .5, 1., 3. );
Philippe Pébay's avatar
Philippe Pébay committed
83
  polaxes->SetAutoScaleRadius( false );
84
  polaxes->SetMaximumRadius( 3. );
85
86
  polaxes->SetMaximumAngle( 210. );
  polaxes->SetNumberOfRadialAxes( 8 );
87
  polaxes->SetCamera( renderer->GetActiveCamera() );
88
  polaxes->SetRadialLabelFormat( "%6.1f" );
89
90
91
92
93
  polaxes->GetRadialAxesProperty()->SetColor( .0, .0, 1. );
  polaxes->GetPolarArcsProperty()->SetColor( 1., .0, 0. );
  polaxes->GetPolarAxisTitleTextProperty()->SetColor( 1., 0., 0. );
  polaxes->GetPolarAxisLabelTextProperty()->SetColor( 1., 0., 0. );
  polaxes->SetScreenSize( 11.0 );
94

95
96
97
98
99
100
101
102
103
  vtkNew<vtkRenderWindow> renWin;
  renWin->SetMultiSamples( 0 );
  renWin->AddRenderer( renderer.GetPointer() );
  renWin->SetWindowName( "VTK - Polar Axes custom range" );
  renWin->SetSize( 600, 600 );

  vtkNew<vtkRenderWindowInteractor> iren;
  iren->SetRenderWindow( renWin.GetPointer() );

104
  renderer->SetBackground( .8, .8, .8 );
105
106
107
  renderer->AddViewProp( readerActor.GetPointer() );
  renderer->AddViewProp( outlineActor.GetPointer() );
  renderer->AddViewProp( polaxes.GetPointer() );
108
109
110
111
112
113
114
115
116
117
  renWin->Render();

  int retVal = vtkRegressionTestImage( renWin.GetPointer() );
  if ( retVal == vtkRegressionTester::DO_INTERACTOR)
    {
    iren->Start();
    }

  return !retVal;
}