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 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestScalarBarCombinatorics.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 "vtkActor.h"
#include "vtkBandedPolyDataContourFilter.h"
#include "vtkCommand.h"
#include "vtkColorSeries.h"
#include "vtkDataArray.h"
#include "vtkInteractorEventRecorder.h"
#include "vtkLookupTable.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiBlockPLOT3DReader.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkScalarBarActor.h"
#include "vtkSmartPointer.h"
#include "vtkStructuredGridGeometryFilter.h"
#include "vtkStructuredGrid.h"
#include "vtkTestUtilities.h"
#include "vtkTextProperty.h"
#include "vtkTesting.h"
#include <stdlib.h> // for atof
struct vtkScalarBarTestCondition
{
const char* Title;
int Orientation;
int TextPosition;
int DrawAnnotations;
int DrawNanAnnotation;
int IndexedLookup;
int FixedAnnotationLeaderLineColor;
double Position[2];
double Position2[2];
int ProcessEvents;
int Enabled;
int VTitleSeparation;
} conditions[] = {
{"$T_1$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::PrecedeScalarBar, 1, 1, 1, 0, {0.000, 0.015}, {0.400, 0.135}, 1, 1, 0},
{"$T_2$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::PrecedeScalarBar, 1, 0, 1, 1, {0.000, 0.230}, {0.400, 0.146}, 1, 1, 0},
{"$T_3$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::SucceedScalarBar, 1, 1, 1, 1, {0.000, 0.850}, {0.630, 0.154}, 1, 1, 5},
{"$T_4$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::PrecedeScalarBar, 1, 1, 1, 0, {0.799, 0.032}, {0.061, 0.794}, 1, 1, 5},
{"$T_5$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::PrecedeScalarBar, 1, 0, 1, 1, {0.893, 0.036}, {0.052, 0.752}, 1, 1, 0},
{"$T_6$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::SucceedScalarBar, 1, 1, 1, 1, {0.792, 0.081}, {0.061, 0.617}, 1, 1, 0},
{"$T_7$", VTK_ORIENT_VERTICAL, vtkScalarBarActor::SucceedScalarBar, 1, 1, 0, 0, {0.646, 0.061}, {0.084, 0.714}, 1, 1, 0},
{"$T_8$", VTK_ORIENT_HORIZONTAL, vtkScalarBarActor::SucceedScalarBar, 0, 1, 0, 1, {0.076, 0.535}, {0.313, 0.225}, 1, 1, 0},
};
static vtkSmartPointer<vtkScalarBarActor> CreateScalarBar(
vtkScalarBarTestCondition& cond, vtkScalarsToColors* idxLut, vtkScalarsToColors* conLut, vtkRenderer* ren)
{
vtkNew<vtkScalarBarActor> sba;
sba->SetTitle(cond.Title);
sba->SetLookupTable(cond.IndexedLookup ? idxLut : conLut);
sba->SetOrientation(cond.Orientation);
sba->SetTextPosition(cond.TextPosition);
sba->SetDrawAnnotations(cond.DrawAnnotations);
sba->SetDrawNanAnnotation(cond.DrawNanAnnotation);
sba->SetFixedAnnotationLeaderLineColor(cond.FixedAnnotationLeaderLineColor);
sba->SetPosition(cond.Position[0], cond.Position[1]);
sba->SetPosition2(cond.Position2[0], cond.Position2[1]);
sba->SetVerticalTitleSeparation(cond.VTitleSeparation);
ren->AddActor(sba.GetPointer());
return sba.GetPointer();
}
int TestScalarBarCombinatorics(int argc, char* argv[])
{
vtkTesting* t = vtkTesting::New();
double threshold = 10.;
for (int cc = 1; cc < argc; ++cc)
{
if ((cc < argc - 1) && (argv[cc][0] == '-') && (argv[cc][1] == 'E'))
{
threshold = atof(argv[++cc]);
continue;
}
t->AddArgument(argv[cc]);
}
vtkNew<vtkRenderer> ren1;
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(ren1.GetPointer());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin.GetPointer());
vtkNew<vtkLookupTable> lutA;
vtkNew<vtkLookupTable> lutB;
// Create a grid of scalar bars
int numBars = static_cast<int>(sizeof(conditions) / sizeof(conditions[0]));
std::vector<vtkSmartPointer<vtkScalarBarActor> > actors;
actors.reserve(numBars);
for (int c = 0; c < numBars; ++c)
{
actors.push_back(CreateScalarBar(conditions[c], lutA.GetPointer(), lutB.GetPointer(), ren1.GetPointer()));
}
// Add the actors to the renderer, set the background and size
//
ren1->SetBackground(0.1, 0.2, 0.4);
renWin->SetSize(600, 300);
vtkNew<vtkColorSeries> pal;
pal->SetColorSchemeByName("Brewer Sequential Blue-Green (5)");
pal->BuildLookupTable(lutB.GetPointer());
lutB->IndexedLookupOff();
lutB->Build();
lutB->SetAnnotation(5.00, "Just Wow");
lutB->SetAnnotation(4.00, "Super-Special");
lutB->SetAnnotation(3.00, "Amazingly Special");
lutB->SetAnnotation(1.00, "Special");
lutB->SetAnnotation(0.00, "Special $\\cap$ This $= \\emptyset$");
lutB->SetRange(0., 4.); // Force "Just Wow" to be omitted from rendering.
lutB->Build();
// Now make a second set of annotations with an even number of entries (10).
// This tests another branch of the annotation label positioning code.
pal->SetColorSchemeByName("Brewer Diverging Purple-Orange (10)");
pal->BuildLookupTable(lutA.GetPointer());
lutA->SetAnnotation(5.00, "A");
lutA->SetAnnotation(4.00, "B");
lutA->SetAnnotation(3.00, "C");
lutA->SetAnnotation(2.00, "D");
lutA->SetAnnotation(1.00, ""); // Test empty label omission
lutA->SetAnnotation(0.00, "F");
lutA->SetAnnotation(6.00, "G");
lutA->SetAnnotation(7.00, "H");
lutA->SetAnnotation(8.00, "I");
lutA->SetAnnotation(9.00, ""); // Test empty label omission
// render the image
iren->Initialize();
renWin->Render();
t->SetRenderWindow(renWin.GetPointer());
int res = t->RegressionTest(threshold);
t->Delete();
iren->Start();
return res == vtkTesting::PASSED ? 0 : 1;
}
|