Commit 6c877c2f authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Adding area plot (vtkPlotArea).

Adding a new plot to plot a region named, vtkPlotArea. This can be used
to plot a region enclosed between two series.

Also added a new test, TestAreaPlot, to test this new plot.
parent 1093ae99
......@@ -24,6 +24,7 @@ set(Module_SRCS
vtkPiecewisePointHandleItem.cxx
vtkPlot.cxx
vtkPlot3D.cxx
vtkPlotArea.cxx
vtkPlotBag.cxx
vtkPlotBar.cxx
vtkPlotBox.cxx
......
......@@ -40,6 +40,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestContextScene.cxx,NO_DATA,NO_VALID
TestControlPointsItem.cxx,NO_DATA,NO_VALID
TestControlPointsItemEvents.cxx,NO_DATA,NO_VALID
TestAreaPlot.cxx
TestAxes.cxx
TestBagPlot.cxx
TestBarGraph.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestAreaPlot.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 "vtkBrush.h"
#include "vtkCharArray.h"
#include "vtkChartXY.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkFloatArray.h"
#include "vtkNew.h"
#include "vtkPlotArea.h"
#include "vtkPlot.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTable.h"
#include <algorithm>
//----------------------------------------------------------------------------
int TestAreaPlot( int, char * [] )
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
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<vtkFloatArray> arrX;
arrX->SetName("X Axis");
table->AddColumn(arrX.GetPointer());
vtkNew<vtkFloatArray> arrC;
arrC->SetName("Cosine");
table->AddColumn(arrC.GetPointer());
vtkNew<vtkFloatArray> arrS;
arrS->SetName("Sine");
table->AddColumn(arrS.GetPointer());
vtkNew<vtkFloatArray> arrS2;
arrS2->SetName("Sine2");
table->AddColumn(arrS2.GetPointer());
vtkNew<vtkFloatArray> arrS3;
arrS3->SetName("Sine3");
table->AddColumn(arrS3.GetPointer());
vtkNew<vtkFloatArray> arr1;
arr1->SetName("One");
table->AddColumn(arr1.GetPointer());
vtkNew<vtkCharArray> validMask;
validMask->SetName("ValidMask");
table->AddColumn(validMask.GetPointer());
// Test charting with a few more points...
int numPoints = 69;
float inc = 7.5 / (numPoints-1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
table->SetValue(i, 0, i * inc + 0.01);
table->SetValue(i, 1, cos(i * inc) + 0.01);
table->SetValue(i, 2, sin(i * inc) + 0.01);
table->SetValue(i, 3, sin(i * inc) + 0.5);
table->SetValue(i, 4, sin(i * inc) * sin(i * inc) + 0.01);
table->SetValue(i, 5, 1.0);
validMask->SetValue(i, (i > 30 && i < 40) ? 0 : 1);
}
// Add multiple line plots, setting the colors etc
vtkPlotArea* area = vtkPlotArea::SafeDownCast(chart->AddPlot(vtkChart::AREA));
area->SetInputData(table.GetPointer());
area->SetInputArray(0, "X Axis");
area->SetInputArray(1, "Sine");
area->SetInputArray(2, "Sine2");
area->SetValidPointMaskName("ValidMask");
area->GetBrush()->SetColorF(0.5, 0.5, 0.5, 0.5);
chart->GetAxis(vtkAxis::LEFT)->SetLogScale(true);
// Render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
......@@ -53,7 +53,8 @@ public:
BAR,
STACKED,
BAG,
FUNCTIONALBAG};
FUNCTIONALBAG,
AREA};
// Description:
// Enum of valid chart action types.
......
......@@ -32,6 +32,7 @@
#include "vtkVector.h"
#include "vtkVectorOperators.h"
#include "vtkPlotArea.h"
#include "vtkPlotBar.h"
#include "vtkPlotBag.h"
#include "vtkPlotFunctionalBag.h"
......@@ -389,6 +390,7 @@ bool vtkChartXY::Paint(vtkContext2D *painter)
}
this->UpdateLayout(painter);
// Recalculate the plot transform, min and max values if necessary
if (!this->PlotTransformValid)
{
......@@ -400,6 +402,14 @@ bool vtkChartXY::Paint(vtkContext2D *painter)
this->RecalculatePlotTransforms();
}
// Now that plot transforms, including whether to use log scaling and the
// shift-scale factors, have been updated, we give the vtkPlot instances an
// opportunity to update caches.
for (size_t i = 0; i < this->ChartPrivate->plots.size(); ++i)
{
this->ChartPrivate->plots[i]->UpdateCache();
}
// Update the clipping if necessary
this->ChartPrivate->Clip->SetClip(this->Point1[0], this->Point1[1],
this->Point2[0]-this->Point1[0],
......@@ -1150,6 +1160,14 @@ vtkPlot * vtkChartXY::AddPlot(int type)
plot = bag;
break;
}
case AREA:
{
vtkPlotArea* area = vtkPlotArea::New();
area->SetParent(this);
area->GetBrush()->SetColor(color.GetData());
plot = area;
break;
}
default:
plot = NULL;
......
......@@ -281,6 +281,13 @@ public:
return this->GetBounds(bounds);
}
// Description:
// Subclasses that build data caches to speed up painting should override this
// method to update such caches. This is called on each Paint, hence
// subclasses must add checks to avoid rebuilding of cache, unless necessary.
// Default implementation is empty.
virtual void UpdateCache() {}
//BTX
// Description:
// A General setter/getter that should be overridden. It can silently drop
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPlotArea.h
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.
=========================================================================*/
// .NAME vtkPlotArea - draws an area plot.
// .SECTION Description
// vtkPlotArea is used to render an area plot. An area plot (sometimes called a
// range plot) renders a filled region between the selected ymin and ymax
// arrays.
// To specify the x array and ymin/ymax arrays, use the SetInputArray method
// with array index as 0, 1, or 2, respectively.
#ifndef vtkPlotArea_h
#define vtkPlotArea_h
#include "vtkPlot.h"
class VTKCHARTSCORE_EXPORT vtkPlotArea : public vtkPlot
{
public:
static vtkPlotArea* New();
vtkTypeMacro(vtkPlotArea, vtkPlot);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Convenience method to set the input arrays. vtkPlotArea supports the
// following indices:
// \li 0: x-axis,
// \li 1: y-axis,
// \li 2: y-axis.
using Superclass::SetInputArray;
// Description:
// Overridden to set the brush color.
virtual void SetColor(unsigned char r, unsigned char g, unsigned char b,
unsigned char a);
virtual void SetColor(double r, double g, double b);
// Description:
// Get/set the valid point mask array name.
vtkGetMacro(ValidPointMaskName, vtkStdString)
vtkSetMacro(ValidPointMaskName, vtkStdString)
// Description:
// Perform any updates to the item that may be necessary before rendering.
virtual void Update();
// Description:
// Get the bounds for this plot as (Xmin, Xmax, Ymin, Ymax).
virtual void GetBounds(double bounds[4]);
// Description:
// Subclasses that build data caches to speed up painting should override this
// method to update such caches. This is called on each Paint, hence
// subclasses must add checks to avoid rebuilding of cache, unless necessary.
virtual void UpdateCache();
// Description:
// Paint event for the XY plot, called whenever the chart needs to be drawn
virtual bool Paint(vtkContext2D *painter);
// Description:
// Paint legend event for the plot, called whenever the legend needs the
// plot items symbol/mark/line drawn. A rect is supplied with the lower left
// corner of the rect (elements 0 and 1) and with width x height (elements 2
// and 3). The plot can choose how to fill the space supplied. The index is used
// by Plots that return more than one label.
virtual bool PaintLegend(vtkContext2D *painter, const vtkRectf& rect,
int legendIndex);
//BTX
// Description:
// Function to query a plot for the nearest point to the specified coordinate.
// Returns the index of the data series with which the point is associated, or
// -1 if no point was found.
virtual vtkIdType GetNearestPoint(const vtkVector2f& point,
const vtkVector2f& tolerance,
vtkVector2f* location);
// Description:
// Generate and return the tooltip label string for this plot
// The segmentIndex parameter is ignored, except for vtkPlotBar
virtual vtkStdString GetTooltipLabel(const vtkVector2d &plotPos,
vtkIdType seriesIndex,
vtkIdType segmentIndex);
protected:
vtkPlotArea();
~vtkPlotArea();
// Description:
// Name of the valid point mask array.
vtkStdString ValidPointMaskName;
private:
vtkPlotArea(const vtkPlotArea&); // Not implemented.
void operator=(const vtkPlotArea&); // Not implemented.
class vtkTableCache;
vtkTableCache* TableCache;
vtkTimeStamp UpdateTime;
//ETX
};
#endif
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