Commit e25f4c18 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

Separate out custom tick labels, add more testing

This commit adds a new ivar for custom labels, and cleans up some of
logic around tick label generation. A new test was added that exercises
several of these new code paths and verifies correct functionality.

Change-Id: I3cdb8ac06d77af6ec4d9f2222d6f88d4eb1307ac
parent 0162904c
......@@ -10,6 +10,7 @@
# add tests that require data
set(MyTests ${MyTests}
TestAxes.cxx
TestBarGraph.cxx
TestBarGraphHorizontal.cxx
TestColorTransferFunction.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestBarGraph.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 "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkDoubleArray.h"
#include "vtkNew.h"
#include "vtkSmartPointer.h"
#include "vtkVector.h"
#include "vtkStringArray.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include <vector>
//----------------------------------------------------------------------------
int TestAxes(int , char * [])
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(500, 300);
// Set up our custom label arrays for the axes;
vtkNew<vtkDoubleArray> positions;
vtkNew<vtkStringArray> labels;
positions->InsertNextValue(0.0);
labels->InsertNextValue("0.0");
positions->InsertNextValue(42.0);
labels->InsertNextValue("The Answer");
positions->InsertNextValue(99.0);
labels->InsertNextValue("99");
// Let's create a few axes, and place them on the scene.
std::vector<vtkSmartPointer<vtkAxis> > axesVertical(4);
for (size_t i = 0; i < axesVertical.size(); ++i)
{
axesVertical[i] = vtkSmartPointer<vtkAxis>::New();
vtkAxis *axis = axesVertical[i].GetPointer();
axis->SetPoint1(vtkVector2f(i * 69 + 30, 10));
axis->SetPoint2(vtkVector2f(i * 69 + 30, 290));
axis->SetPosition(i % 2 ? vtkAxis::LEFT : vtkAxis::RIGHT);
axis->SetRange(-1, 50);
view->GetScene()->AddItem(axis);
}
// Exercise some of the API in the axis API.
axesVertical[0]->AutoScale();
axesVertical[1]->SetBehavior(vtkAxis::FIXED);
axesVertical[1]->AutoScale();
axesVertical[2]->SetNotation(vtkAxis::SCIENTIFIC_NOTATION);
axesVertical[2]->SetPosition(vtkAxis::LEFT);
axesVertical[2]->SetPrecision(0);
axesVertical[3]->SetTitle("Custom vertical labels");
axesVertical[3]->SetTickPositions(positions.GetPointer());
axesVertical[3]->SetTickLabels(labels.GetPointer());
axesVertical[3]->SetPoint1(vtkVector2f(3 * 69 + 80, 10));
axesVertical[3]->SetPoint2(vtkVector2f(3 * 69 + 80, 290));
axesVertical[3]->AutoScale();
for (size_t i = 0; i < axesVertical.size(); ++i)
{
axesVertical[i]->Update();
}
// Let's create a few axes, and place them on the scene.
std::vector<vtkSmartPointer<vtkAxis> > axesHorizontal(6);
for (size_t i = 0; i < axesHorizontal.size(); ++i)
{
axesHorizontal[i] = vtkSmartPointer<vtkAxis>::New();
vtkAxis *axis = axesHorizontal[i].GetPointer();
axis->SetPoint1(vtkVector2f(310, i * 50 + 30));
axis->SetPoint2(vtkVector2f(490, i * 50 + 30));
axis->SetPosition(i % 2 ? vtkAxis::TOP : vtkAxis::BOTTOM);
axis->SetRange(-1, 50);
view->GetScene()->AddItem(axis);
axis->Update();
}
// Now to test some of the API in the horizontal axes.
axesHorizontal[0]->AutoScale();
axesHorizontal[1]->SetRange(10, -5);
axesHorizontal[1]->AutoScale();
axesHorizontal[2]->SetRange(10, -5);
axesHorizontal[2]->SetBehavior(vtkAxis::FIXED);
axesHorizontal[2]->AutoScale();
axesHorizontal[2]->SetTitle("Test");
axesHorizontal[3]->SetTickLabelAlgorithm(vtkAxis::TICK_WILKINSON_EXTENDED);
axesHorizontal[3]->AutoScale();
axesHorizontal[4]->SetNumberOfTicks(5);
axesHorizontal[5]->SetTitle("Custom horizontal labels");
axesHorizontal[5]->SetTickPositions(positions.GetPointer());
axesHorizontal[5]->SetTickLabels(labels.GetPointer());
axesHorizontal[5]->SetPosition(vtkAxis::BOTTOM);
for (size_t i = 0; i < axesHorizontal.size(); ++i)
{
axesHorizontal[i]->Update();
}
// Finally render the scene and compare the image to a reference image, or
// start the main interactor loop if the test is interactive.
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
......@@ -15,7 +15,7 @@
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkNew.h"
#include "vtkChartXY.h"
#include "vtkPlot.h"
#include "vtkAxis.h"
......@@ -30,60 +30,61 @@
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
// 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};
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 TestStackedPlot(int , char * [])
{
// Set up a 2D scene, add an XY chart to it
VTK_CREATE(vtkContextView, view);
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
VTK_CREATE(vtkChartXY, chart);
view->GetScene()->AddItem(chart);
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart.GetPointer());
// Create a table with some points in it...
VTK_CREATE(vtkTable, table);
vtkNew<vtkTable> table;
VTK_CREATE(vtkStringArray, arrMonthLabel);
vtkNew<vtkStringArray> arrMonthLabel;
arrMonthLabel->SetNumberOfValues(12);
VTK_CREATE(vtkDoubleArray, arrXTickPositions);
vtkNew<vtkDoubleArray> arrXTickPositions;
arrXTickPositions->SetNumberOfValues(12);
VTK_CREATE(vtkIntArray, arrMonth);
vtkNew<vtkIntArray> arrMonth;
arrMonth->SetName("Month");
table->AddColumn(arrMonth);
table->AddColumn(arrMonth.GetPointer());
VTK_CREATE(vtkIntArray, arrBook);
vtkNew<vtkIntArray> arrBook;
arrBook->SetName("Books");
table->AddColumn(arrBook);
table->AddColumn(arrBook.GetPointer());
VTK_CREATE(vtkIntArray, arrNewPopularBook);
vtkNew<vtkIntArray> arrNewPopularBook;
arrNewPopularBook->SetName("New / Popular");
table->AddColumn(arrNewPopularBook);
table->AddColumn(arrNewPopularBook.GetPointer());
VTK_CREATE(vtkIntArray, arrPeriodical);
vtkNew<vtkIntArray> arrPeriodical;
arrPeriodical->SetName("Periodical");
table->AddColumn(arrPeriodical);
table->AddColumn(arrPeriodical.GetPointer());
VTK_CREATE(vtkIntArray, arrAudiobook);
vtkNew<vtkIntArray> arrAudiobook;
arrAudiobook->SetName("Audiobook");
table->AddColumn(arrAudiobook);
table->AddColumn(arrAudiobook.GetPointer());
VTK_CREATE(vtkIntArray, arrVideo);
vtkNew<vtkIntArray> arrVideo;
arrVideo->SetName("Video");
table->AddColumn(arrVideo);
table->AddColumn(arrVideo.GetPointer());
table->SetNumberOfRows(12);
for (int i = 0; i < 12; i++)
......@@ -99,9 +100,10 @@ int TestStackedPlot(int , char * [])
}
// Set the Month Labels
chart->GetAxis(1)->SetTickLabels(arrMonthLabel);
chart->GetAxis(1)->SetTickPositions(arrXTickPositions);
chart->GetAxis(1)->SetMaximum(11);
chart->GetAxis(1)->SetTickLabels(arrMonthLabel.GetPointer());
chart->GetAxis(1)->SetTickPositions(arrXTickPositions.GetPointer());
chart->GetAxis(1)->SetRange(0, 11);
chart->GetAxis(1)->SetBehavior(vtkAxis::FIXED);
// Add multiple line plots, setting the colors etc
vtkPlotStacked *stack = 0;
......@@ -109,16 +111,16 @@ int TestStackedPlot(int , char * [])
// Books
stack = vtkPlotStacked::SafeDownCast(chart->AddPlot(vtkChart::STACKED));
stack->SetUseIndexForXSeries(true);
stack->SetInputData(table);
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");
VTK_CREATE(vtkColorSeries,colorSeries);
vtkNew<vtkColorSeries> colorSeries;
colorSeries->SetColorScheme(vtkColorSeries::COOL);
stack->SetColorSeries(colorSeries);
stack->SetColorSeries(colorSeries.GetPointer());
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
......
......@@ -78,6 +78,7 @@ class TestStackedPlot(vtk.test.Testing.vtkTest):
chart.GetAxis(1).SetTickLabels(arrMonthLabels)
chart.GetAxis(1).SetTickPositions(arrMonthPositions)
chart.GetAxis(1).SetMaximum(11)
chart.GetAxis(1).SetBehavior(vtk.vtkAxis.FIXED)
# Create the stacked plot
stack = chart.AddPlot(3)
......
This diff is collapsed.
......@@ -91,7 +91,7 @@ public:
// Description:
// Set the number of tick marks for this axis. Default is -1, which leads to
// automatic calculation of nicely spaced tick marks.
vtkSetMacro(NumberOfTicks, int);
virtual void SetNumberOfTicks(int numberOfTicks);
// Description:
// Get the number of tick marks for this axis.
......@@ -206,16 +206,24 @@ public:
// Description:
// Enumeration of the axis behaviors.
enum {
AUTO = 0,
FIXED,
CUSTOM
AUTO = 0, //< Automatically scale the axis to view all data that is visible.
FIXED, //< Use a fixed axis range and make no attempt to rescale.
CUSTOM //< Deprecated, use the tick label settings instead.
};
// Description:
// Get/set the behavior of the axis (auto, fixed, custom). Default is 0 (auto).
// Get/set the behavior of the axis (auto or fixed). The default is 0 (auto).
vtkSetMacro(Behavior, int);
vtkGetMacro(Behavior, int);
// Description:
// Get/set the tick label generation for the axis. Defaults to false (the
// axis will generate appropriate labels). If set to true only the custom
// labels set will be used.
vtkSetMacro(CustomTickLabels, bool)
vtkGetMacro(CustomTickLabels, bool)
vtkBooleanMacro(CustomTickLabels, bool)
// Description:
// Get a pointer to the vtkPen object that controls the way this axis is drawn.
vtkGetObjectMacro(Pen, vtkPen);
......@@ -361,6 +369,10 @@ protected:
bool TitleAppended; // Track if the title is updated when the label formats
// are changed in the Extended Axis Labeling algorithm
// Description:
// Are we using custom tick labels, or should the axis generate them?
bool CustomTickLabels;
// Description:
// This object stores the vtkPen that controls how the axis is drawn.
vtkPen* Pen;
......@@ -409,6 +421,10 @@ protected:
private:
vtkAxis(const vtkAxis &); // Not implemented.
void operator=(const vtkAxis &); // Not implemented.
// Description:
// Return true if the value is in range, false otherwise.
bool InRange(double value);
//ETX
};
......
......@@ -100,7 +100,8 @@ int TestStackedPlotGL2PS(int , char * [])
// Set the Month Labels
chart->GetAxis(1)->SetTickLabels(arrMonthLabel.GetPointer());
chart->GetAxis(1)->SetTickPositions(arrXTickPositions.GetPointer());
chart->GetAxis(1)->SetMaximum(11);
chart->GetAxis(1)->SetRange(0, 11);
chart->GetAxis(1)->SetBehavior(vtkAxis::FIXED);
// Add multiple line plots, setting the colors etc
vtkPlotStacked *stack = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment