File: TestAppleBug.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg1-12
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,776 kB
  • sloc: cpp: 1,539,582; ansic: 106,521; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 122; objc: 83
file content (145 lines) | stat: -rw-r--r-- 4,206 bytes parent folder | download | duplicates (3)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
/*=========================================================================

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

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

#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"

#include <vtkActor.h>
#include <vtkCellData.h>
#include <vtkDiscretizableColorTransferFunction.h>
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSphereSource.h>
#include <vtkStdString.h>
#include <vtkStringArray.h>

#include "vtkOpenGLPolyDataMapper.h"

int TestAppleBug(int argc, char* argv[])
{
  vtkNew<vtkSphereSource> sphere;
  sphere->Update();

  vtkNew<vtkPolyData> polydata;
  polydata->ShallowCopy(sphere->GetOutput());

  // Set up string array associated with cells
  vtkNew<vtkStringArray> sArray;
  sArray->SetName("color");
  sArray->SetNumberOfComponents(1);
  sArray->SetNumberOfTuples(polydata->GetNumberOfCells());

  vtkVariant colors[5];
  colors[0] = "red";
  colors[1] = "blue";
  colors[2] = "green";
  colors[3] = "yellow";
  colors[4] = "cyan";

  // Round-robin assignment of color strings
  for (int i = 0; i < polydata->GetNumberOfCells(); ++i)
  {
    sArray->SetValue(i, colors[i % 5].ToString());
  }

  vtkCellData* cd = polydata->GetCellData();
  cd->AddArray(sArray.Get());

  // Set up transfer function
  vtkNew<vtkDiscretizableColorTransferFunction> tfer;
  tfer->IndexedLookupOn();
  tfer->SetNumberOfIndexedColors(5);
  tfer->SetIndexedColor(0, 1.0, 0.0, 0.0);
  tfer->SetIndexedColor(1, 0.0, 0.0, 1.0);
  tfer->SetIndexedColor(2, 0.0, 1.0, 0.0);
  tfer->SetIndexedColor(3, 1.0, 1.0, 0.0);
  tfer->SetIndexedColor(4, 0.0, 1.0, 1.0);

  vtkStdString red("red");
  tfer->SetAnnotation(red, red);
  vtkStdString blue("blue");
  tfer->SetAnnotation(blue, blue);
  vtkStdString green("green");
  tfer->SetAnnotation(green, green);
  vtkStdString yellow("yellow");
  tfer->SetAnnotation(yellow, yellow);
  vtkStdString cyan("cyan");
  tfer->SetAnnotation(cyan, cyan);

  vtkNew<vtkOpenGLPolyDataMapper> mapper;
  mapper->SetInputDataObject(polydata.Get());
  mapper->SetLookupTable(tfer.Get());
  mapper->ScalarVisibilityOn();
  mapper->SetScalarModeToUseCellFieldData();
  mapper->SelectColorArray("color");

  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper.Get());

  vtkNew<vtkRenderer> renderer;
  renderer->AddActor(actor.Get());

  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->AddRenderer(renderer.Get());

  vtkNew<vtkRenderWindowInteractor> iren;
  iren->SetRenderWindow(renderWindow.Get());

  renderWindow->Render();

  int retVal = vtkRegressionTestImage(renderWindow.Get());

  cerr << renderWindow->ReportCapabilities();

  // if it thinks it has the bug, try it
  // without the code
  if (mapper->GetHaveAppleBug())
  {
    mapper->ForceHaveAppleBugOff();
    renderWindow->Render();
    int offRetVal = vtkRegressionTestImage(renderWindow.Get());
    if (offRetVal == vtkRegressionTester::PASSED)
    {
      cerr << "FIX!!!! This system is using the AppleBug (rdar://20747550) code but does not need it\n\n";
      return !vtkRegressionTester::FAILED;
    }
  }
  else
  {
    // if the test failed see if the apple bug would fix it
    if (retVal == vtkRegressionTester::FAILED)
    {
      mapper->ForceHaveAppleBugOn();
      renderWindow->Render();
      retVal = vtkRegressionTestImage(renderWindow.Get());
      if (retVal == vtkRegressionTester::PASSED)
      {
        cerr << "FIX!!! This system needs the AppleBug (rdar://20747550) code but doesn't have it\n\n";
        return !vtkRegressionTester::FAILED;
      }
    }
  }

  if (retVal == vtkRegressionTester::DO_INTERACTOR)
  {
    iren->Start();
  }

  return !retVal;
}