1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestGaussianBlurPass.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 "vtkElevationFilter.h"
28 #include "vtkInformation.h"
29 #include "vtkOpenGLRenderer.h"
30 #include "vtkPLYReader.h"
31 #include "vtkPointData.h"
32 #include "vtkPointDataToCellData.h"
33 #include "vtkPolyData.h"
34 #include "vtkPolyDataMapper.h"
35 #include "vtkRenderPassCollection.h"
36 #include "vtkRenderWindow.h"
37 #include "vtkRenderWindowInteractor.h"
38 #include "vtkSequencePass.h"
39 #include "vtkSmartPointer.h"
40 #include "vtkTestUtilities.h"
41 #include "vtkValuePass.h"
42 
43 
TestValuePass(int argc,char * argv[])44 int TestValuePass(int argc, char *argv[])
45 {
46   bool interactive = false;
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   cerr << reader->GetOutput()->GetBounds()[0] << ", "
66        << reader->GetOutput()->GetBounds()[1] << endl;
67 
68   vtkSmartPointer<vtkElevationFilter> elevation =
69     vtkSmartPointer<vtkElevationFilter>::New();
70   elevation->SetInputConnection(reader->GetOutputPort());
71   elevation->SetLowPoint(-0.11, 0.0, 0.0);
72   elevation->SetHighPoint(0.1, 0.0, 0.0);
73   elevation->Update();
74 
75   vtkPolyData *polyData = vtkPolyData::SafeDownCast(elevation->GetOutput());
76   vtkIntArray *array = vtkIntArray::New();
77   array->SetName("TestArray");
78   array->SetNumberOfComponents(1);
79   for (int i = 0; i < polyData->GetNumberOfPoints(); ++i)
80   {
81     array->InsertNextValue(i);
82   }
83   polyData->GetPointData()->AddArray(array);
84   array->Delete();
85 
86   vtkSmartPointer<vtkPointDataToCellData> pointsToCells =
87     vtkSmartPointer<vtkPointDataToCellData>::New();
88   pointsToCells->SetInputData(polyData);
89 
90   vtkSmartPointer<vtkPolyDataMapper> mapper =
91     vtkSmartPointer<vtkPolyDataMapper>::New();
92   mapper->SetInputConnection(pointsToCells->GetOutputPort());
93   mapper->ScalarVisibilityOn();
94 
95   vtkSmartPointer<vtkActor> actor =
96     vtkSmartPointer<vtkActor>::New();
97   actor->SetMapper(mapper);
98 
99   // 1. Set up renderer, window, & interactor
100   vtkSmartPointer<vtkRenderWindowInteractor> interactor =
101     vtkSmartPointer<vtkRenderWindowInteractor>::New();
102 
103   vtkSmartPointer<vtkRenderWindow> window =
104     vtkSmartPointer<vtkRenderWindow>::New();
105 
106   vtkSmartPointer<vtkRenderer> renderer =
107     vtkSmartPointer<vtkRenderer>::New();
108 
109   window->AddRenderer(renderer);
110   interactor->SetRenderWindow(window);
111 
112   renderer->AddActor(actor);
113 
114   // 2. Set up rendering passes
115   vtkSmartPointer<vtkValuePass> valuePass =
116     vtkSmartPointer<vtkValuePass>::New();
117   valuePass->SetInputArrayToProcess(VTK_SCALAR_MODE_USE_CELL_FIELD_DATA, 0);
118   valuePass->SetInputComponentToProcess(0);
119   valuePass->SetScalarRange(-0.11, 0.1);
120 
121   vtkSmartPointer<vtkRenderPassCollection> passes =
122     vtkSmartPointer<vtkRenderPassCollection>::New();
123   passes->AddItem(valuePass);
124 
125   vtkSmartPointer<vtkSequencePass> sequence =
126     vtkSmartPointer<vtkSequencePass>::New();
127   sequence->SetPasses(passes);
128 
129   vtkSmartPointer<vtkCameraPass> cameraPass =
130     vtkSmartPointer<vtkCameraPass>::New();
131   cameraPass->SetDelegatePass(sequence);
132 
133   vtkOpenGLRenderer *glRenderer =
134     vtkOpenGLRenderer::SafeDownCast(renderer);
135   glRenderer->SetPass(cameraPass);
136 
137   // 3. Render image and compare against baseline
138   for (int i = 0; i < 3; ++i)
139   {
140     if (i % 2 == 0)
141     {
142       glRenderer->SetPass(nullptr);
143     }
144     else
145     {
146       glRenderer->SetPass(cameraPass);
147     }
148     window->Render();
149   }
150 
151   if (interactive)
152   {
153     interactor->Start();
154   }
155 
156   return 0;
157 }
158