File: TestPOVExporter.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (132 lines) | stat: -rw-r--r-- 4,373 bytes parent folder | download | duplicates (9)
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
122
123
124
125
126
127
128
129
130
131
132
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestPOVExporter.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.

=========================================================================*/
// .NAME TestPOVExpoter - Tests vtkPOVExporter.
// .SECTION Description
// Creates a scene and uses POVExporter to generate a pov file. Test passes
// if the file exists and has non zero length.

#include "vtkSphereSource.h"
#include "vtkConeSource.h"
#include "vtkGlyph3D.h"
#include "vtkPolyDataMapper.h"
#include "vtkLODActor.h"
#include "vtkTextMapper.h"
#include "vtkProperty.h"
#include "vtkActor2D.h"
#include "vtkCellPicker.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTextProperty.h"
#include "vtkCamera.h"
#include "vtkPOVExporter.h"
#include "vtksys/SystemTools.hxx"

int TestPOVExporter(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
  int err = 0;
  int exists = 0;
  unsigned long length = 0;

  // create a sphere source, mapper, and actor
  vtkSphereSource *sphere = vtkSphereSource::New();
  vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
  sphereMapper->SetInputConnection(sphere->GetOutputPort());
  sphereMapper->GlobalImmediateModeRenderingOn();
  vtkActor *sphereActor = vtkLODActor::New();
  sphereActor->SetMapper(sphereMapper);
  sphereActor->GetProperty()->SetDiffuseColor(0.8900, 0.8100, 0.3400);
  sphereActor->GetProperty()->SetSpecular(0.4);
  sphereActor->GetProperty()->SetSpecularPower(20);

  // create the spikes by glyphing the sphere with a cone.  Create the
  // mapper and actor for the glyphs.
  vtkConeSource *cone = vtkConeSource::New();
  cone->SetResolution(20);
  vtkGlyph3D *glyph = vtkGlyph3D::New();
  glyph->SetInputConnection(sphere->GetOutputPort());
  glyph->SetSourceConnection(cone->GetOutputPort());
  glyph->SetVectorModeToUseNormal();
  glyph->SetScaleModeToScaleByVector();
  glyph->SetScaleFactor(0.25);
  vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();
  spikeMapper->SetInputConnection(glyph->GetOutputPort());
  vtkLODActor *spikeActor = vtkLODActor::New();
  spikeActor->SetMapper(spikeMapper);
  spikeActor->GetProperty()->SetDiffuseColor(1.0000, 0.3882, 0.2784);
  spikeActor->GetProperty()->SetSpecular(0.4);
  spikeActor->GetProperty()->SetSpecularPower(20);

  // Create the Renderer, RenderWindow, etc. and set the Picker.
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren);

  ren->AddActor(sphereActor);
  ren->AddActor(spikeActor);
  ren->SetBackground(0.1, 0.2, 0.4);
  renWin->SetSize(300,300);

  ren->ResetCamera();
  vtkCamera *cam1 = ren->GetActiveCamera();
  cam1->Zoom(1.4);

  renWin->Render();

  // Instead of letting renderer to render the scene, we use
  // an exportor to save it to a file.
  vtkPOVExporter *povexp = vtkPOVExporter::New();
  povexp->SetRenderWindow(renWin);
  povexp->SetFileName("TestPOVExporter.pov");
  cout << "Writing file TestPOVExporter.pov..." << endl;

  povexp->Write();
  cout << "Done writing file TestPOVExporter.pov..." << endl;

  povexp->Delete();

  exists =
    static_cast<int>(vtksys::SystemTools::FileExists("TestPOVExporter.pov"));
  length = vtksys::SystemTools::FileLength("TestPOVExporter.pov");
  cout << "TestPOVExporter.pov file exists: " << exists << endl;
  cout << "TestPOVExporter.pov file length: " << length << endl;
  if (!exists)
    {
    err = 1;
    cerr << "ERROR: 1 - Test failing because TestPOVExporter.pov file doesn't exist..." << endl;
    }
  else
    {
    vtksys::SystemTools::RemoveFile("TestPOVExporter.pov");
    }

  if (0==length)
    {
    err = 2;
    cerr << "ERROR: 2 - Test failing because TestPOVExporter.pov file has zero length..." << endl;
    }

  renWin->Delete();
  ren->Delete();
  spikeActor->Delete();
  spikeMapper->Delete();
  glyph->Delete();
  cone->Delete();
  sphereActor->Delete();
  sphereMapper->Delete();
  sphere->Delete();

  return err;
}