1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestLightingMapPass.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // This test ... TO DO
16 //
17 // The command line arguments are:
18 // -I        => run in interactive mode; unless this is used, the program will
19 //              not allow interaction and exit
20 
21 #include "vtkTestUtilities.h"
22 #include "vtkRegressionTestImage.h"
23 
24 #include "vtkActor.h"
25 #include "vtkCameraPass.h"
26 #include "vtkCellArray.h"
27 #include "vtkInformation.h"
28 #include "vtkLight.h"
29 #include "vtkOpenGLRenderer.h"
30 #include "vtkPLYReader.h"
31 #include "vtkPolyData.h"
32 #include "vtkPolyDataMapper.h"
33 #include "vtkProperty.h"
34 #include "vtkRenderPassCollection.h"
35 #include "vtkRenderWindow.h"
36 #include "vtkRenderWindowInteractor.h"
37 #include "vtkSequencePass.h"
38 #include "vtkSmartPointer.h"
39 #include "vtkTestUtilities.h"
40 #include "vtkLightingMapPass.h"
41 
42 
TestLightingMapNormalsPass(int argc,char * argv[])43 int TestLightingMapNormalsPass(int argc, char *argv[])
44 {
45   bool interactive = false;
46 
47   for (int i = 0; i < argc; ++i)
48   {
49     if (!strcmp(argv[i], "-I"))
50     {
51       interactive = true;
52     }
53   }
54 
55   // 0. Prep data
56   const char* fileName =
57     vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/dragon.ply");
58   vtkSmartPointer<vtkPLYReader> reader
59     = vtkSmartPointer<vtkPLYReader>::New();
60   reader->SetFileName(fileName);
61   reader->Update();
62 
63   delete [] fileName;
64 
65   vtkSmartPointer<vtkPolyDataMapper> mapper =
66     vtkSmartPointer<vtkPolyDataMapper>::New();
67   mapper->SetInputConnection(reader->GetOutputPort());
68 
69   vtkSmartPointer<vtkActor> actor =
70     vtkSmartPointer<vtkActor>::New();
71   actor->SetMapper(mapper);
72 
73   actor->GetProperty()->SetAmbientColor(0.2, 0.2, 1.0);
74   actor->GetProperty()->SetDiffuseColor(1.0, 0.65, 0.7);
75   actor->GetProperty()->SetSpecularColor(1.0, 1.0, 1.0);
76   actor->GetProperty()->SetSpecular(0.5);
77   actor->GetProperty()->SetDiffuse(0.7);
78   actor->GetProperty()->SetAmbient(0.5);
79   actor->GetProperty()->SetSpecularPower(20.0);
80   actor->GetProperty()->SetOpacity(1.0);
81   //actor->GetProperty()->SetRepresentationToWireframe();
82 
83   // 1. Set up renderer, window, & interactor
84   vtkSmartPointer<vtkRenderWindowInteractor> interactor =
85     vtkSmartPointer<vtkRenderWindowInteractor>::New();
86 
87   vtkSmartPointer<vtkRenderWindow> window =
88     vtkSmartPointer<vtkRenderWindow>::New();
89 
90   vtkSmartPointer<vtkRenderer> renderer =
91     vtkSmartPointer<vtkRenderer>::New();
92 
93   window->AddRenderer(renderer);
94   interactor->SetRenderWindow(window);
95 
96   vtkSmartPointer<vtkLight> light =
97     vtkSmartPointer<vtkLight>::New();
98   light->SetLightTypeToSceneLight();
99   light->SetPosition(0.0, 0.0, 1.0);
100   light->SetPositional(true);
101   light->SetFocalPoint(0.0, 0.0, 0.0);
102   light->SetIntensity(1.0);
103 
104   renderer->AddLight(light);
105 
106   renderer->AddActor(actor);
107 
108   // 2. Set up rendering passes
109   vtkSmartPointer<vtkLightingMapPass> lightingPass =
110     vtkSmartPointer<vtkLightingMapPass>::New();
111   lightingPass->SetRenderType(vtkLightingMapPass::NORMALS);
112 
113   vtkSmartPointer<vtkRenderPassCollection> passes =
114     vtkSmartPointer<vtkRenderPassCollection>::New();
115   passes->AddItem(lightingPass);
116 
117   vtkSmartPointer<vtkSequencePass> sequence =
118     vtkSmartPointer<vtkSequencePass>::New();
119   sequence->SetPasses(passes);
120 
121   vtkSmartPointer<vtkCameraPass> cameraPass =
122     vtkSmartPointer<vtkCameraPass>::New();
123   cameraPass->SetDelegatePass(sequence);
124 
125   vtkOpenGLRenderer *glRenderer =
126     vtkOpenGLRenderer::SafeDownCast(renderer);
127   glRenderer->SetPass(cameraPass);
128 
129   // 3. Render image and compare against baseline
130   window->Render();
131 
132   int retVal = vtkRegressionTestImage(window);
133   if (interactive || retVal == vtkRegressionTester::DO_INTERACTOR)
134   {
135     interactor->Start();
136   }
137   return !retVal;
138 }
139