1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestColorByCellDataStringArray.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
16 #include "vtkRegressionTestImage.h"
17 #include "vtkTestUtilities.h"
18
19 #include <vtkActor.h>
20 #include <vtkCellData.h>
21 #include <vtkDiscretizableColorTransferFunction.h>
22 #include <vtkNew.h>
23 #include <vtkPolyData.h>
24 #include <vtkPolyDataMapper.h>
25 #include <vtkRenderWindow.h>
26 #include <vtkRenderWindowInteractor.h>
27 #include <vtkRenderer.h>
28 #include <vtkSphereSource.h>
29 #include <vtkStdString.h>
30 #include <vtkStringArray.h>
31
32 #include "vtkOpenGLPolyDataMapper.h"
33
TestAppleBug(int argc,char * argv[])34 int TestAppleBug(int argc, char* argv[])
35 {
36 vtkNew<vtkSphereSource> sphere;
37 sphere->Update();
38
39 vtkNew<vtkPolyData> polydata;
40 polydata->ShallowCopy(sphere->GetOutput());
41
42 // Set up string array associated with cells
43 vtkNew<vtkStringArray> sArray;
44 sArray->SetName("color");
45 sArray->SetNumberOfComponents(1);
46 sArray->SetNumberOfTuples(polydata->GetNumberOfCells());
47
48 vtkVariant colors[5];
49 colors[0] = "red";
50 colors[1] = "blue";
51 colors[2] = "green";
52 colors[3] = "yellow";
53 colors[4] = "cyan";
54
55 // Round-robin assignment of color strings
56 for (int i = 0; i < polydata->GetNumberOfCells(); ++i)
57 {
58 sArray->SetValue(i, colors[i % 5].ToString());
59 }
60
61 vtkCellData* cd = polydata->GetCellData();
62 cd->AddArray(sArray);
63
64 // Set up transfer function
65 vtkNew<vtkDiscretizableColorTransferFunction> tfer;
66 tfer->IndexedLookupOn();
67 tfer->SetNumberOfIndexedColors(5);
68 tfer->SetIndexedColor(0, 1.0, 0.0, 0.0);
69 tfer->SetIndexedColor(1, 0.0, 0.0, 1.0);
70 tfer->SetIndexedColor(2, 0.0, 1.0, 0.0);
71 tfer->SetIndexedColor(3, 1.0, 1.0, 0.0);
72 tfer->SetIndexedColor(4, 0.0, 1.0, 1.0);
73
74 vtkStdString red("red");
75 tfer->SetAnnotation(red, red);
76 vtkStdString blue("blue");
77 tfer->SetAnnotation(blue, blue);
78 vtkStdString green("green");
79 tfer->SetAnnotation(green, green);
80 vtkStdString yellow("yellow");
81 tfer->SetAnnotation(yellow, yellow);
82 vtkStdString cyan("cyan");
83 tfer->SetAnnotation(cyan, cyan);
84
85 vtkNew<vtkOpenGLPolyDataMapper> mapper;
86 mapper->SetInputDataObject(polydata);
87 mapper->SetLookupTable(tfer);
88 mapper->ScalarVisibilityOn();
89 mapper->SetScalarModeToUseCellFieldData();
90 mapper->SelectColorArray("color");
91
92 vtkNew<vtkActor> actor;
93 actor->SetMapper(mapper);
94
95 vtkNew<vtkRenderer> renderer;
96 renderer->AddActor(actor);
97
98 vtkNew<vtkRenderWindow> renderWindow;
99 renderWindow->AddRenderer(renderer);
100
101 vtkNew<vtkRenderWindowInteractor> iren;
102 iren->SetRenderWindow(renderWindow);
103
104 renderWindow->Render();
105
106 int retVal = vtkRegressionTestImage(renderWindow);
107
108 cerr << renderWindow->ReportCapabilities();
109
110 // if it thinks it has the bug, try it
111 // without the code
112 if (mapper->GetHaveAppleBug())
113 {
114 mapper->ForceHaveAppleBugOff();
115 renderWindow->Render();
116 int offRetVal = vtkRegressionTestImage(renderWindow);
117 if (offRetVal == vtkRegressionTester::PASSED)
118 {
119 cerr << "FIX!!!! This system is using the AppleBug (rdar://20747550) code but does not need "
120 "it\n\n";
121 return !vtkRegressionTester::FAILED;
122 }
123 }
124 else
125 {
126 // if the test failed see if the apple bug would fix it
127 if (retVal == vtkRegressionTester::FAILED)
128 {
129 mapper->ForceHaveAppleBugOn();
130 renderWindow->Render();
131 retVal = vtkRegressionTestImage(renderWindow);
132 if (retVal == vtkRegressionTester::PASSED)
133 {
134 cerr
135 << "FIX!!! This system needs the AppleBug (rdar://20747550) code but doesn't have it\n\n";
136 return !vtkRegressionTester::FAILED;
137 }
138 }
139 }
140
141 if (retVal == vtkRegressionTester::DO_INTERACTOR)
142 {
143 iren->Start();
144 }
145
146 return !retVal;
147 }
148