TestDeeringStereo.cxx 3.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*=========================================================================

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

=========================================================================*/

16
17
// This test draws a sphere in anaglyphic stereo (red-blue) mode using deering
// frustum.
18
19
20

#include "vtkActor.h"
#include "vtkCamera.h"
21
#include "vtkMatrix4x4.h"
22
23
24
25
26
27
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
28
#include "vtkConeSource.h"
29
30
31
32
33
34
#include "vtkSphereSource.h"

#include "vtkSmartPointer.h"
#define VTK_CREATE(type, var) \
  vtkSmartPointer<type> var = vtkSmartPointer<type>::New()

35
int TestDeeringStereo(int argc, char *argv[])
36
{
37
38
39
40
  double bottomLeft[3]  = {-1.0, -1.0, -1.0};
  double bottomRight[3] = { 1.0, -1.0, -1.0};
  double topRight[3]    = { 1.0,  1.0, -1.0};

41
  VTK_CREATE(vtkSphereSource, sphere1);
42
  sphere1->SetCenter(0.5, 0.0, -4.0);
43
44
  sphere1->SetThetaResolution(100);
  sphere1->SetPhiResolution(100.0);
45

46
47
  VTK_CREATE(vtkPolyDataMapper, mapper1);
  mapper1->SetInputConnection(sphere1->GetOutputPort());
48

49
50
  VTK_CREATE(vtkActor, actor1);
  actor1->SetMapper(mapper1);
51
  actor1->GetProperty()->SetAmbient(0.1);
52
53
54

  VTK_CREATE(vtkConeSource, cone1);
  cone1->SetCenter(0.0, 0.0, -10.0);
55
  cone1->SetResolution(100.0);
56
57
58
59
60
61

  VTK_CREATE(vtkPolyDataMapper, mapper2);
  mapper2->SetInputConnection(cone1->GetOutputPort());

  VTK_CREATE(vtkActor, actor2);
  actor2->SetMapper(mapper2);
62
  actor2->GetProperty()->SetAmbient(0.1);
63
64

  VTK_CREATE(vtkRenderer, renderer);
65
66
  renderer->AddActor(actor1);
  renderer->AddActor(actor2);
67
  renderer->SetAmbient(1.0, 1.0, 1.0);
68

69
70
71
72
73
  VTK_CREATE(vtkMatrix4x4, eyeMatrix);
  eyeMatrix->SetElement(0, 3, 0.0);
  eyeMatrix->SetElement(1, 3, 0.0);
  eyeMatrix->SetElement(2, 3, 10.0);

74
  vtkCamera *camera = renderer->GetActiveCamera();
75
76
77
  camera->SetScreenBottomLeft(bottomLeft);
  camera->SetScreenBottomRight(bottomRight);
  camera->SetScreenTopRight(topRight);
78
  camera->SetUseDeeringFrustum(1);
79
80
  camera->SetEyeTransformMatrix(eyeMatrix);
  camera->SetEyeSeparation(0.05);
81
82
83

  VTK_CREATE(vtkRenderWindow, renwin);
  renwin->AddRenderer(renderer);
84
  renwin->SetSize(400, 400);
85
86
  renwin->SetStereoRender(1);
  renwin->SetStereoCapableWindow(1);
87
  renwin->SetStereoTypeToRedBlue();
88

89
90
  renderer->Render();

91
92
93
94
95
96
  int retVal = vtkRegressionTestImage(renwin);
  if (retVal == vtkRegressionTester::DO_INTERACTOR)
    {
    VTK_CREATE(vtkRenderWindowInteractor, iren);
    iren->SetRenderWindow(renwin);
    iren->Initialize();
97

98
99
100
101
102
103
    iren->Start();
    retVal = vtkRegressionTester::PASSED;
    }

  return (retVal == vtkRegressionTester::PASSED) ? 0 : 1;
}