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
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestStackedPlotGL2PS.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 "vtkAxis.h"
#include "vtkChartXY.h"
#include "vtkColor.h"
#include "vtkColorSeries.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkDoubleArray.h"
#include "vtkGL2PSExporter.h"
#include "vtkIntArray.h"
#include "vtkNew.h"
#include "vtkPlot.h"
#include "vtkPlotStacked.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkTestingInteractor.h"
// Monthly checkout data
static const char *month_labels[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static int book[] = {5675, 5902, 6388, 5990, 5575, 7393, 9878, 8082, 6417, 5946, 5526, 5166};
static int new_popular[] = {701, 687, 736, 696, 750, 814, 923, 860, 786, 735, 680, 741};
static int periodical[] = {184, 176, 166, 131, 171, 191, 231, 166, 197, 162, 152, 143};
static int audiobook[] = {903, 1038, 987, 1073, 1144, 1203, 1173, 1196, 1213, 1076, 926, 874};
static int video[] = {1524, 1565, 1627, 1445, 1179, 1816, 2293, 1811, 1588, 1561, 1542, 1563};
//----------------------------------------------------------------------------
int TestStackedPlotGL2PS(int , char * [])
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
view->GetRenderWindow()->SetSize(400, 300);
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart.GetPointer());
// Create a table with some points in it...
vtkNew<vtkTable> table;
vtkNew<vtkStringArray> arrMonthLabel;
arrMonthLabel->SetNumberOfValues(12);
vtkNew<vtkDoubleArray> arrXTickPositions;
arrXTickPositions->SetNumberOfValues(12);
vtkNew<vtkIntArray> arrMonth;
arrMonth->SetName("Month");
table->AddColumn(arrMonth.GetPointer());
vtkNew<vtkIntArray> arrBook;
arrBook->SetName("Books");
table->AddColumn(arrBook.GetPointer());
vtkNew<vtkIntArray> arrNewPopularBook;
arrNewPopularBook->SetName("New / Popular");
table->AddColumn(arrNewPopularBook.GetPointer());
vtkNew<vtkIntArray> arrPeriodical;
arrPeriodical->SetName("Periodical");
table->AddColumn(arrPeriodical.GetPointer());
vtkNew<vtkIntArray> arrAudiobook;
arrAudiobook->SetName("Audiobook");
table->AddColumn(arrAudiobook.GetPointer());
vtkNew<vtkIntArray> arrVideo;
arrVideo->SetName("Video");
table->AddColumn(arrVideo.GetPointer());
table->SetNumberOfRows(12);
for (int i = 0; i < 12; i++)
{
arrMonthLabel->SetValue(i,month_labels[i]);
arrXTickPositions->SetValue(i,i);
arrBook->SetValue(i,book[i]);
arrNewPopularBook->SetValue(i,new_popular[i]);
arrPeriodical->SetValue(i,periodical[i]);
arrAudiobook->SetValue(i,audiobook[i]);
arrVideo->SetValue(i,video[i]);
}
// Set the Month Labels
chart->GetAxis(1)->SetCustomTickPositions(arrXTickPositions.GetPointer(),
arrMonthLabel.GetPointer());
chart->GetAxis(1)->SetRange(0, 11);
chart->GetAxis(1)->SetBehavior(vtkAxis::FIXED);
// Add multiple line plots, setting the colors etc
vtkPlotStacked *stack = 0;
// Books
stack = vtkPlotStacked::SafeDownCast(chart->AddPlot(vtkChart::STACKED));
stack->SetUseIndexForXSeries(true);
stack->SetInputData(table.GetPointer());
stack->SetInputArray(1,"Books");
stack->SetInputArray(2,"New / Popular");
stack->SetInputArray(3,"Periodical");
stack->SetInputArray(4,"Audiobook");
stack->SetInputArray(5,"Video");
vtkNew<vtkColorSeries>colorSeries;
colorSeries->SetColorScheme(vtkColorSeries::COOL);
stack->SetColorSeries(colorSeries.GetPointer());
view->GetRenderWindow()->SetMultiSamples(0);
view->GetRenderWindow()->Render();
vtkNew<vtkGL2PSExporter> exp;
exp->SetRenderWindow(view->GetRenderWindow());
exp->SetFileFormatToPS();
exp->UsePainterSettings();
exp->CompressOff();
exp->DrawBackgroundOn();
std::string fileprefix = vtkTestingInteractor::TempDirectory +
std::string("/TestStackedPlotGL2PS");
exp->SetFilePrefix(fileprefix.c_str());
exp->Write();
//Finally render the scene and compare the image to a reference image
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
|