1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestScalarBarCombinatorics.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 "vtkActor.h"
17 #include "vtkBandedPolyDataContourFilter.h"
18 #include "vtkCommand.h"
19 #include "vtkColorSeries.h"
20 #include "vtkDataArray.h"
21 #include "vtkInteractorEventRecorder.h"
22 #include "vtkLookupTable.h"
23 #include "vtkMultiBlockDataSet.h"
24 #include "vtkMultiBlockPLOT3DReader.h"
25 #include "vtkNew.h"
26 #include "vtkPointData.h"
27 #include "vtkPolyDataMapper.h"
28 #include "vtkRenderer.h"
29 #include "vtkRenderWindow.h"
30 #include "vtkRenderWindowInteractor.h"
31 #include "vtkScalarBarActor.h"
32 #include "vtkSmartPointer.h"
33 #include "vtkStructuredGridGeometryFilter.h"
34 #include "vtkStructuredGrid.h"
35 #include "vtkTestUtilities.h"
36 #include "vtkTextProperty.h"
37 #include "vtkTesting.h"
38
39 #include <stdlib.h> // for atof
40
41 struct vtkScalarBarTestCondition
42 {
43 const char* Title;
44 int Orientation;
45 int TextPosition;
46 int DrawAnnotations;
47 int DrawNanAnnotation;
48 int IndexedLookup;
49 int FixedAnnotationLeaderLineColor;
50 double Position[2];
51 double Position2[2];
52 int ProcessEvents;
53 int Enabled;
54 int VTitleSeparation;
55 } conditions[] = {
56 {"$T_1$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::PrecedeScalarBar, 1, 1, 1, 0, {0.000, 0.015}, {0.400, 0.135}, 1, 1, 0},
57 {"$T_2$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::PrecedeScalarBar, 1, 0, 1, 1, {0.000, 0.230}, {0.400, 0.146}, 1, 1, 0},
58 {"$T_3$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::SucceedScalarBar, 1, 1, 1, 1, {0.000, 0.850}, {0.630, 0.154}, 1, 1, 5},
59 {"$T_4$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::PrecedeScalarBar, 1, 1, 1, 0, {0.799, 0.032}, {0.061, 0.794}, 1, 1, 5},
60 {"$T_5$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::PrecedeScalarBar, 1, 0, 1, 1, {0.893, 0.036}, {0.052, 0.752}, 1, 1, 0},
61 {"$T_6$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::SucceedScalarBar, 1, 1, 1, 1, {0.792, 0.081}, {0.061, 0.617}, 1, 1, 0},
62 {"$T_7$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::SucceedScalarBar, 1, 1, 0, 0, {0.646, 0.061}, {0.084, 0.714}, 1, 1, 0},
63 {"$T_8$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::SucceedScalarBar, 0, 1, 0, 1, {0.076, 0.535}, {0.313, 0.225}, 1, 1, 0},
64 };
65
CreateScalarBar(vtkScalarBarTestCondition & cond,vtkScalarsToColors * idxLut,vtkScalarsToColors * conLut,vtkRenderer * ren)66 static vtkSmartPointer<vtkScalarBarActor> CreateScalarBar(
67 vtkScalarBarTestCondition& cond, vtkScalarsToColors* idxLut, vtkScalarsToColors* conLut, vtkRenderer* ren)
68 {
69 vtkNew<vtkScalarBarActor> sba;
70 sba->SetTitle(cond.Title);
71 sba->SetLookupTable(cond.IndexedLookup ? idxLut : conLut);
72 sba->SetOrientation(cond.Orientation);
73 sba->SetTextPosition(cond.TextPosition);
74 sba->SetDrawAnnotations(cond.DrawAnnotations);
75 sba->SetDrawNanAnnotation(cond.DrawNanAnnotation);
76 sba->SetFixedAnnotationLeaderLineColor(cond.FixedAnnotationLeaderLineColor);
77 sba->SetPosition(cond.Position[0], cond.Position[1]);
78 sba->SetPosition2(cond.Position2[0], cond.Position2[1]);
79 sba->SetVerticalTitleSeparation(cond.VTitleSeparation);
80 ren->AddActor(sba.GetPointer());
81 return sba.GetPointer();
82 }
83
TestScalarBarCombinatorics(int argc,char * argv[])84 int TestScalarBarCombinatorics(int argc, char* argv[])
85 {
86 vtkTesting* t = vtkTesting::New();
87 double threshold = 10.;
88 for (int cc = 1; cc < argc; ++cc)
89 {
90 if (argv[cc][0] == '-' && argv[cc][1] == 'E' && cc < argc - 1)
91 {
92 threshold = atof(argv[++cc]);
93 continue;
94 }
95 t->AddArgument(argv[cc]);
96 }
97
98 vtkNew<vtkRenderer> ren1;
99 vtkNew<vtkRenderWindow> renWin;
100 renWin->AddRenderer(ren1.GetPointer());
101
102 vtkNew<vtkRenderWindowInteractor> iren;
103 iren->SetRenderWindow(renWin.GetPointer());
104
105 vtkNew<vtkLookupTable> lutA;
106 vtkNew<vtkLookupTable> lutB;
107 // Create a grid of scalar bars
108 int numBars = static_cast<int>(sizeof(conditions) / sizeof(conditions[0]));
109 std::vector<vtkSmartPointer<vtkScalarBarActor> > actors;
110 actors.reserve(numBars);
111 for (int c = 0; c < numBars; ++c)
112 {
113 actors.push_back(CreateScalarBar(conditions[c], lutA.GetPointer(), lutB.GetPointer(), ren1.GetPointer()));
114 }
115
116 // Add the actors to the renderer, set the background and size
117 //
118 ren1->SetBackground(0.1, 0.2, 0.4);
119 renWin->SetSize(600, 300);
120
121 vtkNew<vtkColorSeries> pal;
122 pal->SetColorSchemeByName("Brewer Sequential Blue-Green (5)");
123 pal->BuildLookupTable(lutB.GetPointer());
124 lutB->IndexedLookupOff();
125 lutB->Build();
126 lutB->SetAnnotation(5.00, "Just Wow");
127 lutB->SetAnnotation(4.00, "Super-Special");
128 lutB->SetAnnotation(3.00, "Amazingly Special");
129 lutB->SetAnnotation(1.00, "Special");
130 lutB->SetAnnotation(0.00, "Special $\\cap$ This $= \\emptyset$");
131 lutB->SetRange(0., 4.); // Force "Just Wow" to be omitted from rendering.
132 lutB->Build();
133
134 // Now make a second set of annotations with an even number of entries (10).
135 // This tests another branch of the annotation label positioning code.
136 pal->SetColorSchemeByName("Brewer Diverging Purple-Orange (10)");
137 pal->BuildLookupTable(lutA.GetPointer());
138 lutA->SetAnnotation(5.00, "A");
139 lutA->SetAnnotation(4.00, "B");
140 lutA->SetAnnotation(3.00, "C");
141 lutA->SetAnnotation(2.00, "D");
142 lutA->SetAnnotation(1.00, ""); // Test empty label omission
143 lutA->SetAnnotation(0.00, "F");
144 lutA->SetAnnotation(6.00, "G");
145 lutA->SetAnnotation(7.00, "H");
146 lutA->SetAnnotation(8.00, "I");
147 lutA->SetAnnotation(9.00, ""); // Test empty label omission
148
149 // render the image
150 iren->Initialize();
151 renWin->Render();
152 t->SetRenderWindow(renWin.GetPointer());
153 int res = t->RegressionTest(threshold);
154 t->Delete();
155
156 iren->Start();
157
158 return res == vtkTesting::PASSED ? 0 : 1;
159 }
160