Commit d787cec5 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell Committed by Kitware Robot
Browse files

Merge topic 'charts-2dhistogram'

d56ab4eb ENH: Enabled 2D histogram test.
c3415541 ENH: Inherit from vtkChartXY for 2D histogram charts.
6e4bb50c ENH: Inherit from vtkPlot for vtk2DHistogramItem.
efd8bfe4 ENH: Made UpdateLayout virtual.
parents d028eb14 d56ab4eb
......@@ -13,7 +13,7 @@ IF (VTK_USE_RENDERING AND VTK_USE_VIEWS)
# add tests that require data
SET(MyTests ${MyTests}
#TestContextUnicode.cxx # Disabled until Freetype unicode works
#Test2DHistogram.cxx
Test2DHistogram.cxx
TestBarGraph.cxx
TestContext.cxx
TestContextImage.cxx
......
......@@ -68,6 +68,9 @@ int Test2DHistogram( int, char * [] )
transferFunction->Build();
chart->SetTransferFunction(transferFunction);
chart->SetAutoSize(false);
chart->SetSize(vtkRectf(0.0, 0.0, size - 40, size));
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
......
......@@ -70,7 +70,7 @@ void vtk2DHistogramItem::SetInput(vtkImageData *data, vtkIdType)
}
//-----------------------------------------------------------------------------
vtkImageData * vtk2DHistogramItem::GetInput()
vtkImageData * vtk2DHistogramItem::GetInputImageData()
{
return this->Input;
}
......
......@@ -21,17 +21,17 @@
#ifndef __vtk2DHistogramItem_h
#define __vtk2DHistogramItem_h
#include "vtkContextItem.h"
#include "vtkPlot.h"
#include "vtkSmartPointer.h" // Needed for SP ivars
#include "vtkVector.h" // Needed for vtkRectf
class vtkImageData;
class vtkScalarsToColors;
class VTK_CHARTS_EXPORT vtk2DHistogramItem : public vtkContextItem
class VTK_CHARTS_EXPORT vtk2DHistogramItem : public vtkPlot
{
public:
vtkTypeMacro(vtk2DHistogramItem, vtkContextItem);
vtkTypeMacro(vtk2DHistogramItem, vtkPlot);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
......@@ -56,7 +56,7 @@ public:
// Description:
// Get the input table used by the plot.
vtkImageData * GetInput();
vtkImageData * GetInputImageData();
// Description:
// Set the color transfer funtion that will be used to generate the 2D
......
......@@ -24,33 +24,8 @@
#include "vtkAxis.h"
#include "vtk2DHistogramItem.h"
#include "vtkColorLegend.h"
#include "vtkContextTransform.h"
#include "vtkSmartPointer.h"
#include "vtkTransform2D.h"
#include "vtkObjectFactory.h"
#include "vtkCommand.h"
#include <vector>
// Minimal storage class for STL containers etc.
class vtkChart2DHistogram::Private
{
public:
Private()
{
this->Transform = vtkSmartPointer<vtkContextTransform>::New();
}
~Private()
{
for(std::vector<vtkAxis *>::iterator it = this->Axes.begin();
it != this->Axes.end(); ++it)
{
(*it)->Delete();
}
}
vtkSmartPointer<vtkContextTransform> Transform;
std::vector<vtkAxis *> Axes;
};
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkChart2DHistogram);
......@@ -58,20 +33,9 @@ vtkStandardNewMacro(vtkChart2DHistogram);
//-----------------------------------------------------------------------------
vtkChart2DHistogram::vtkChart2DHistogram()
{
this->Storage = new vtkChart2DHistogram::Private;
// Now for the 2D histogram
this->AddItem(this->Storage->Transform);
this->Histogram = vtkSmartPointer<vtk2DHistogramItem>::New();
this->Storage->Transform->AddItem(this->Histogram);
// Setup the axes
for (int i = 0; i < 2; ++i)
{
this->Storage->Axes.push_back(vtkAxis::New());
this->AddItem(this->Storage->Axes.back());
this->Storage->Axes[i]->SetPosition(i);
}
this->AddPlot(this->Histogram);
this->Legend = vtkSmartPointer<vtkColorLegend>::New();
this->AddItem(this->Legend);
......@@ -80,46 +44,14 @@ vtkChart2DHistogram::vtkChart2DHistogram()
//-----------------------------------------------------------------------------
vtkChart2DHistogram::~vtkChart2DHistogram()
{
delete this->Storage;
}
//-----------------------------------------------------------------------------
void vtkChart2DHistogram::Update()
{
for(std::vector<vtkAxis *>::iterator it = this->Storage->Axes.begin();
it != this->Storage->Axes.end(); ++it)
{
(*it)->Update();
}
this->Histogram->Update();
this->Legend->Update();
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::Paint(vtkContext2D *painter)
{
int geometry[] = { this->GetScene()->GetSceneWidth(),
this->GetScene()->GetSceneHeight() };
if (geometry[0] == 0 || geometry[1] == 0 || !this->Visible)
{
// The geometry of the chart must be valid before anything can be drawn
return false;
}
this->Update();
if (geometry[0] != this->Geometry[0] || geometry[1] != this->Geometry[1] ||
this->MTime > this->Storage->Axes[0]->GetMTime())
{
// Take up the entire window right now, this could be made configurable
this->SetGeometry(geometry);
}
this->UpdateGeometry();
this->PaintChildren(painter);
return true;
this->vtkChartXY::Update();
}
void vtkChart2DHistogram::SetInput(vtkImageData *data, vtkIdType z)
......@@ -134,69 +66,13 @@ void vtkChart2DHistogram::SetTransferFunction(vtkScalarsToColors *function)
}
//-----------------------------------------------------------------------------
vtkPlot* vtkChart2DHistogram::GetPlot(vtkIdType)
{
return NULL;
}
//-----------------------------------------------------------------------------
vtkIdType vtkChart2DHistogram::GetNumberOfPlots()
{
return 1;
}
//-----------------------------------------------------------------------------
vtkAxis* vtkChart2DHistogram::GetAxis(int index)
bool vtkChart2DHistogram::UpdateLayout(vtkContext2D *painter)
{
if (index < this->GetNumberOfAxes())
{
return this->Storage->Axes[index];
}
else
{
return NULL;
}
}
//-----------------------------------------------------------------------------
vtkIdType vtkChart2DHistogram::GetNumberOfAxes()
{
return this->Storage->Axes.size();
}
//-----------------------------------------------------------------------------
void vtkChart2DHistogram::UpdateGeometry()
{
this->SetBorders(20, 20, 60, 20);
double bounds[4];
this->Histogram->GetBounds(bounds);
vtkAxis *axis = this->Storage->Axes[vtkAxis::LEFT];
axis->SetRange(bounds[2], bounds[3]);
axis->SetPoint1(this->Point1[0], this->Point1[1]);
axis->SetPoint2(this->Point1[0], this->Point2[1]);
axis->AutoScale();
axis->Update();
axis = this->Storage->Axes[vtkAxis::BOTTOM];
axis->SetRange(bounds[0], bounds[1]);
axis->SetPoint1(this->Point1[0], this->Point1[1]);
axis->SetPoint2(this->Point2[0], this->Point1[1]);
axis->AutoScale();
axis->Update();
this->vtkChartXY::UpdateLayout(painter);
this->Legend->SetPosition(vtkRectf(this->Point2[0], this->Point1[1],
10, this->Point2[1] - this->Point1[1]));
this->CalculatePlotTransform(this->Storage->Axes[vtkAxis::BOTTOM],
this->Storage->Axes[vtkAxis::LEFT],
this->Storage->Transform->GetTransform());
}
//-----------------------------------------------------------------------------
void vtkChart2DHistogram::RecalculateBounds()
{
return;
this->Legend->Update();
return true;
}
//-----------------------------------------------------------------------------
......@@ -215,42 +91,6 @@ bool vtkChart2DHistogram::Hit(const vtkContextMouseEvent &mouse)
}
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::MouseEnterEvent(const vtkContextMouseEvent &)
{
return true;
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::MouseMoveEvent(const vtkContextMouseEvent &)
{
return true;
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::MouseLeaveEvent(const vtkContextMouseEvent &)
{
return true;
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::MouseButtonPressEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::MouseButtonReleaseEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkChart2DHistogram::MouseWheelEvent(const vtkContextMouseEvent &, int)
{
return true;
}
//-----------------------------------------------------------------------------
void vtkChart2DHistogram::PrintSelf(ostream &os, vtkIndent indent)
{
......
......@@ -21,7 +21,7 @@
#ifndef __vtkChart2DHistogram_h
#define __vtkChart2DHistogram_h
#include "vtkChart.h"
#include "vtkChartXY.h"
#include "vtkSmartPointer.h" // For SP ivars
class vtkColorLegend;
......@@ -29,10 +29,10 @@ class vtk2DHistogramItem;
class vtkImageData;
class vtkScalarsToColors;
class VTK_CHARTS_EXPORT vtkChart2DHistogram : public vtkChart
class VTK_CHARTS_EXPORT vtkChart2DHistogram : public vtkChartXY
{
public:
vtkTypeMacro(vtkChart2DHistogram, vtkChart);
vtkTypeMacro(vtkChart2DHistogram, vtkChartXY);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
......@@ -45,62 +45,13 @@ public:
// Paint function is invoked.
virtual void Update();
// Description:
// Paint event for the chart, called whenever the chart needs to be drawn
virtual bool Paint(vtkContext2D *painter);
virtual void SetInput(vtkImageData *data, vtkIdType z = 0);
virtual void SetTransferFunction(vtkScalarsToColors *function);
// Description:
// Get the plot at the specified index, returns null if the index is invalid.
virtual vtkPlot* GetPlot(vtkIdType index);
// Description:
// Get the number of plots the chart contains.
virtual vtkIdType GetNumberOfPlots();
// Description:
// Get the axis specified by axisIndex.
virtual vtkAxis* GetAxis(int axisIndex);
// Description:
// Get the number of axes in the current chart.
virtual vtkIdType GetNumberOfAxes();
// Description:
// Request that the chart recalculates the range of its axes. Especially
// useful in applications after the parameters of plots have been modified.
virtual void RecalculateBounds();
// Description:
// Return true if the supplied x, y coordinate is inside the item.
virtual bool Hit(const vtkContextMouseEvent &mouse);
// Description:
// Mouse enter event.
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse move event.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse leave event.
virtual bool MouseLeaveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button down event
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button release event.
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse wheel event, positive delta indicates forward movement of the wheel.
virtual bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta);
protected:
vtkChart2DHistogram();
~vtkChart2DHistogram();
......@@ -115,7 +66,7 @@ protected:
class Private;
Private* Storage;
void UpdateGeometry();
virtual bool UpdateLayout(vtkContext2D *painter);
private:
vtkChart2DHistogram(const vtkChart2DHistogram &); // Not implemented.
......
......@@ -827,7 +827,10 @@ vtkIdType vtkChartXY::AddPlot(vtkPlot * plot)
// Ensure that the bounds are recalculated
this->PlotTransformValid = false;
// Mark the scene as dirty
this->Scene->SetDirty(true);
if (this->Scene)
{
this->Scene->SetDirty(true);
}
return plotIndex;
}
......
......@@ -187,7 +187,7 @@ protected:
// Update the layout of the chart, this may require the vtkContext2D in order
// to get font metrics etc. Initially this was added to resize the charts
// according in response to the size of the axes.
bool UpdateLayout(vtkContext2D* painter);
virtual bool UpdateLayout(vtkContext2D* painter);
// Description:
// The grid for the chart.
......
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