Commit 90051aa9 authored by Keith Fieldhouse's avatar Keith Fieldhouse
Browse files

Update Stacked Plot API

The Stacked Plot API has been updated to be consistent
with the Stacked Bar Graph API.  In particular, a stacked
plot is self contained, each data series is added to the plot
with SetInputArray.
parent fc03641d
......@@ -20,6 +20,8 @@
#include "vtkPlot.h"
#include "vtkAxis.h"
#include "vtkPlotStacked.h"
#include "vtkColor.h"
#include "vtkColorSeries.h"
#include "vtkTable.h"
#include "vtkIntArray.h"
#include "vtkDoubleArray.h"
......@@ -28,6 +30,9 @@
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRegressionTestImage.h"
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
......@@ -90,12 +95,11 @@ int TestStackedPlot( int argc, char * argv [] )
arrMonthLabel->SetValue(i,month_labels[i]);
arrXTickPositions->SetValue(i,i);
table->SetValue(i,0,i);
table->SetValue(i,1,book[i]);
table->SetValue(i,2,new_popular[i]);
table->SetValue(i,3,periodical[i]);
table->SetValue(i,4,audiobook[i]);
table->SetValue(i,5,video[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
......@@ -104,33 +108,28 @@ int TestStackedPlot( int argc, char * argv [] )
chart->GetAxis(1)->SetMaximum(11);
// Add multiple line plots, setting the colors etc
vtkPlot *stack = 0;
vtkPlotStacked *stack = 0;
// Books
stack = chart->AddPlot(vtkChart::STACKED);
stack->SetInput(table, 0, 1);
stack->SetColor(120, 120, 254, 255);
stack = vtkPlotStacked::SafeDownCast(chart->AddPlot(vtkChart::STACKED));
stack->SetUseIndexForXSeries(true);
stack->SetInput(table);
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);
colorSeries->ClearColors();
colorSeries->AddColor(vtkColor3ub(120,120,254));
colorSeries->AddColor(vtkColor3ub(254,118,118));
colorSeries->AddColor(vtkColor3ub(170,170,254));
colorSeries->AddColor(vtkColor3ub(91,91,254));
colorSeries->AddColor(vtkColor3ub(253,158,158));
stack->SetColorSeries(colorSeries);
// New / Popular
stack = chart->AddPlot(vtkChart::STACKED);
stack->SetInput(table, 0, 2);
stack->SetColor(254, 118, 118, 255);
// Periodical
stack = chart->AddPlot(vtkChart::STACKED);
stack->SetInput(table, 0, 3);
stack->SetColor(170, 170, 254, 255);
// Audiobook
stack = chart->AddPlot(vtkChart::STACKED);
stack->SetInput(table, 0, 4);
stack->SetColor(91, 91, 254, 255);
// Video
stack = chart->AddPlot(vtkChart::STACKED);
stack->SetInput(table, 0, 5);
stack->SetColor(253, 158, 158, 255);
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
......
......@@ -70,8 +70,6 @@ public:
this->PlotCorners.resize(4);
this->PlotTransforms.resize(4);
this->PlotTransforms[0] = vtkSmartPointer<vtkTransform2D>::New();
this->StackedPlotAccumulator = vtkSmartPointer<vtkDataArray>();
this->StackParticipantsChanged.Modified();
}
vtkstd::vector<vtkPlot *> plots; // Charts can contain multiple plots of data
......@@ -79,8 +77,6 @@ public:
vtkstd::vector< vtkSmartPointer<vtkTransform2D> > PlotTransforms; // Transforms
vtkstd::vector<vtkAxis *> axes; // Charts can contain multiple axes
vtkSmartPointer<vtkColorSeries> Colors; // Colors in the chart
vtkSmartPointer<vtkDataArray> StackedPlotAccumulator;
vtkTimeStamp StackParticipantsChanged; // Plot added or plot visibility changed
};
//-----------------------------------------------------------------------------
......@@ -150,10 +146,6 @@ vtkChartXY::~vtkChartXY()
//-----------------------------------------------------------------------------
void vtkChartXY::Update()
{
// The Stack accumulator should be re-initialized at the start of every
// update cycle.
this->ChartPrivate->StackedPlotAccumulator = NULL;
// Perform any necessary updates that are not graphical
// Update the plots if necessary
for (size_t i = 0; i < this->ChartPrivate->plots.size(); ++i)
......@@ -226,8 +218,8 @@ bool vtkChartXY::Paint(vtkContext2D *painter)
recalculateTransform = true;
}
if (this->ChartPrivate->plots[0]->GetData()->GetInput()->GetMTime() > this->MTime ||
this->ChartPrivate->StackParticipantsChanged > this->MTime)
if (this->ChartPrivate->plots[0]->GetData()->GetInput()->GetMTime() > this->MTime)
{
this->RecalculateBounds();
}
......@@ -874,66 +866,6 @@ void vtkChartXY::SetScene(vtkContextScene *scene)
this->vtkContextItem::SetScene(scene);
this->Tooltip->SetScene(scene);
}
//-----------------------------------------------------------------------------
namespace {
template <class A>
void InitializeAccumulator(A *a, int n)
{
for (int i = 0; i < n; ++i)
{
a[i] = 0;
}
}
}
//-----------------------------------------------------------------------------
vtkDataArray *vtkChartXY::GetStackedPlotAccumulator(int dataType, int n)
{
if (!this->ChartPrivate->StackedPlotAccumulator)
{
this->ChartPrivate->StackedPlotAccumulator.TakeReference(vtkDataArray::SafeDownCast(vtkDataArray::CreateArray(dataType)));
if (!this->ChartPrivate->StackedPlotAccumulator)
{
return NULL;
}
this->ChartPrivate->StackedPlotAccumulator->SetNumberOfTuples(n);
switch (dataType)
{
vtkTemplateMacro(
InitializeAccumulator(static_cast<VTK_TT*>(this->ChartPrivate->StackedPlotAccumulator->GetVoidPointer(0)),n));
}
return this->ChartPrivate->StackedPlotAccumulator;
}
else
{
if (this->ChartPrivate->StackedPlotAccumulator->GetDataType() != dataType)
{
vtkErrorMacro("DataType of Accumulator " << this->ChartPrivate->StackedPlotAccumulator->GetDataType() <<
"does not match request " << dataType);
return NULL;
}
if (this->ChartPrivate->StackedPlotAccumulator->GetNumberOfTuples() != n)
{
vtkErrorMacro("Number of tuples in Accumulator " << this->ChartPrivate->StackedPlotAccumulator->GetNumberOfTuples() <<
"does not match request " << n);
return NULL;
}
return this->ChartPrivate->StackedPlotAccumulator;
}
}
//-----------------------------------------------------------------------------
vtkTimeStamp vtkChartXY::GetStackParticipantsChanged()
{
return this->ChartPrivate->StackParticipantsChanged;
}
//-----------------------------------------------------------------------------
void vtkChartXY::SetStackPartipantsChanged()
{
this->ChartPrivate->StackParticipantsChanged.Modified();
}
//-----------------------------------------------------------------------------
bool vtkChartXY::Hit(const vtkContextMouseEvent &mouse)
......
......@@ -146,18 +146,6 @@ public:
// Set the vtkContextScene for the item, always set for an item in a scene.
virtual void SetScene(vtkContextScene *scene);
// Description:
// Return the Stacked plot accumulator so that each vtkPlotStacked can
// use it to determine its base and contribute to the position of the next
// stacked plot.
vtkDataArray *GetStackedPlotAccumulator(int dataType, int n);
// Description:
// Timestamp identifying the last time the participants in a stacked plot
// have changed (either by being added or having their visibility change)
vtkTimeStamp GetStackParticipantsChanged();
void SetStackPartipantsChanged();
//BTX
protected:
vtkChartXY();
......
......@@ -259,7 +259,7 @@ class vtkPlotBarPrivate {
this->Segments.begin();
it != this->Segments.end(); ++it)
{
if (useColorSeries)
if (useColorSeries && colorSeries)
brush->SetColor(colorSeries->GetColorRepeating(colorInSeries++).GetData());
(*it)->Paint(painter,pen,brush,width,offset);
}
......
......@@ -124,7 +124,6 @@ protected:
// The point cache is marked dirty until it has been initialized.
vtkTimeStamp BuildTime;
// Description:
// The color series to use if this becomes a stacked bar
vtkSmartPointer<vtkColorSeries> ColorSeries;
......
This diff is collapsed.
......@@ -30,6 +30,9 @@ class vtkTable;
class vtkPoints2D;
class vtkStdString;
class vtkImageData;
class vtkColorSeries;
class vtkPlotStackedPrivate;
class VTK_CHARTS_EXPORT vtkPlotStacked : public vtkPlot
{
......@@ -69,6 +72,22 @@ public:
// Get the bounds for this mapper as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
virtual void GetBounds(double bounds[4]);
// Description:
// When used to set additional arrays, stacked bars are created.
virtual void SetInputArray(int index, const char *name);
// Description:
// Set the color series to use if this becomes a stacked bar plot.
void SetColorSeries(vtkColorSeries *colorSeries);
// Description:
// Get the color series used if when this is a stacked bar plot.
vtkColorSeries *GetColorSeries();
// Description
// Get the plot labels.
virtual vtkStringArray *GetLabels();
//BTX
// Description:
......@@ -87,11 +106,6 @@ public:
// Set the parent, required to accumlate base points when positioning is implicit
virtual void SetParent(vtkChartXY *parent);
// Description:
// Make this plot visible or invisible
virtual void SetVisible(bool visible);
//BTX
protected:
vtkPlotStacked();
......@@ -111,28 +125,6 @@ protected:
// called by UpdateTableCache once the data has been updated in Points.
void CalculateLogSeries();
// Description:
// Find all of the "bad points" in the series. This is mainly used to cache
// bad points for performance reasons, but could also be used plot the bad
// points in the future.
void FindBadPoints();
// Description:
// Calculate the bounds of the plot, ignoring the bad points.
void CalculateBounds(vtkPoints2D *points, vtkIdTypeArray *badPoints, double bounds[4]);
// Description:
// Store a well packed set of XY coordinates for the base of this series
vtkPoints2D *BasePoints;
// Description:
// Store a well packed set of XY coordinates for the extent of this series
vtkPoints2D *ExtentPoints;
// Description:
// Sorted points, used when searching for the nearest point.
class VectorPIMPL;
VectorPIMPL* Sorted;
// Description:
// An array containing the indices of all the "bad base points", meaning any x, y
// pair that has an infinity, -infinity or not a number value.
......@@ -153,10 +145,16 @@ protected:
// The parent Chart of this Plot
vtkChartXY *Parent;
// Description:
// The color series to use for each series.
vtkSmartPointer<vtkColorSeries> ColorSeries;
private:
vtkPlotStacked(const vtkPlotStacked &); // Not implemented.
void operator=(const vtkPlotStacked &); // Not implemented.
vtkPlotStackedPrivate *Private;
//ETX
};
......
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