Commit ee2b08d0 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

ENH: First pass at the scatter plot matrix class.

Takes a vtkTable as input, sets up the charts and displays them. Still
more work to get everything lined up correctly, only showing scatter
plots in the bottom triangle and histograms in the diagonal.

Change-Id: Ieda692e9979a0fe129ebfad0a5e9f3b370356760
parent 2647c809
......@@ -64,6 +64,7 @@ SET(Kit_SRCS
vtkPlotParallelCoordinates.cxx
vtkPlotPoints.cxx
vtkScalarsToColorsItem.cxx
vtkScatterPlotMatrix.cxx
vtkTooltipItem.cxx
)
......
......@@ -35,6 +35,7 @@ IF(VTK_USE_RENDERING AND VTK_USE_VIEWS)
TestPlotMatrix.cxx
TestScalarsToColors.cxx
TestScatterPlot.cxx
TestScatterPlotMatrix.cxx
TestScientificPlot.cxx
TestStackedBarGraph.cxx
TestStackedPlot.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestLinePlot.cxx
Module: TestChartMatrix.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestScatterPlotMatrix.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 "vtkScatterPlotMatrix.h"
#include "vtkRenderWindow.h"
#include "vtkChart.h"
#include "vtkPlot.h"
#include "vtkTable.h"
#include "vtkFloatArray.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNew.h"
//----------------------------------------------------------------------------
int TestScatterPlotMatrix(int, char * [])
{
// Set up a 2D scene, add an XY chart to it
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
vtkNew<vtkScatterPlotMatrix> matrix;
view->GetScene()->AddItem(matrix.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> tangent;
tangent->SetName("Tangent");
table->AddColumn(tangent.GetPointer());
// Test charting with a few more points...
int numPoints = 42;
float inc = 7.5 / (numPoints-1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
table->SetValue(i, 0, i * inc);
table->SetValue(i, 1, cos(i * inc));
table->SetValue(i, 2, sin(i * inc));
table->SetValue(i, 3, sin(i * inc) + 0.5);
table->SetValue(i, 4, tan(i * inc));
}
matrix->SetInput(table.GetPointer());
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkScatterPlotMatrix.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 "vtkScatterPlotMatrix.h"
#include "vtkTable.h"
#include "vtkChart.h"
#include "vtkPlot.h"
#include "vtkAxis.h"
#include "vtkObjectFactory.h"
class vtkScatterPlotMatrix::PIMPL
{
public:
PIMPL() {}
~PIMPL() {}
};
vtkStandardNewMacro(vtkScatterPlotMatrix)
vtkScatterPlotMatrix::vtkScatterPlotMatrix()
{
}
vtkScatterPlotMatrix::~vtkScatterPlotMatrix()
{
}
void vtkScatterPlotMatrix::Update()
{
}
bool vtkScatterPlotMatrix::Paint(vtkContext2D *painter)
{
return Superclass::Paint(painter);
}
void vtkScatterPlotMatrix::SetInput(vtkTable *table)
{
if (this->Input != table)
{
// Set the input, then update the size of the scatter plot matrix, set their
// inputs and all the other stuff needed.
this->Input = table;
this->SetSize(vtkVector2i(this->Input->GetNumberOfColumns(),
this->Input->GetNumberOfColumns()));
// We want scatter plots on the lower-left triangle, then histograms along
// the diagonal and a big plot in the top-right. The basic layout is,
//
// 0 H +++
// 1 S H +++
// 2 S S H
// 3 S S S H
// 0 1 2 3
//
// Where the indices are those of the columns. The indices of the charts
// originate in the bottom-left.
for (int i = 0; i < this->Size.X(); ++i)
{
for (int j = 0; j < this->Size.Y(); ++j)
{
vtkVector2i pos(i, j);
if (this->Size.X() - j > 0)
{
vtkPlot *plot = this->GetChart(pos)->AddPlot(vtkChart::POINTS);
plot->SetInput(table, i, this->Size.X() - j - 1);
}
// Only show bottom axis label for bottom plots
if (j > 0)
{
vtkAxis *axis = this->GetChart(pos)->GetAxis(vtkAxis::BOTTOM);
axis->SetTitle("");
axis->SetLabelsVisible(false);
}
// Only show the left axis labels for left-most plots
if (i > 0)
{
vtkAxis *axis = this->GetChart(pos)->GetAxis(vtkAxis::LEFT);
axis->SetTitle("");
axis->SetLabelsVisible(false);
}
}
}
this->Modified();
}
}
void vtkScatterPlotMatrix::PrintSelf(ostream &os, vtkIndent indent)
{
Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkScatterPlotMatrix.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 vtkScatterPlotMatrix - container for a matrix of charts.
//
// .SECTION Description
// This class contains a matrix of charts. These charts will be of type
// vtkChartXY by default, but this can be overridden. The class will manage
// their layout and object lifetime.
#ifndef __vtkScatterPlotMatrix_h
#define __vtkScatterPlotMatrix_h
#include "vtkChartMatrix.h"
#include "vtkSmartPointer.h" // For ivars
class vtkTable;
class VTK_CHARTS_EXPORT vtkScatterPlotMatrix : public vtkChartMatrix
{
public:
vtkTypeMacro(vtkScatterPlotMatrix, vtkChartMatrix);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Creates a new object.
static vtkScatterPlotMatrix *New();
// Description:
// Perform any updates to the item that may be necessary before rendering.
virtual void Update();
// Description:
// Paint event for the chart matrix.
virtual bool Paint(vtkContext2D *painter);
// Description:
// Set the input table for the scatter plot matrix. This will cause all
// columns to be plotted against each other - a square scatter plot matrix.
virtual void SetInput(vtkTable *table);
protected:
vtkScatterPlotMatrix();
~vtkScatterPlotMatrix();
class PIMPL;
PIMPL *Private;
vtkSmartPointer<vtkTable> Input;
private:
vtkScatterPlotMatrix(const vtkScatterPlotMatrix &); // Not implemented.
void operator=(const vtkScatterPlotMatrix &); // Not implemented.
};
#endif //__vtkScatterPlotMatrix_h
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