Commit 7ef9d7a4 authored by Zack Galbreath's avatar Zack Galbreath

refactor vtkChartXYZ

It now follows the API of the 2D charts more closely.  vtkChartXYZ is
responsible for the axes, while the subclasses of vtkPlot3D handle
displaying the actual data.  As part of this effort, I've included
optional interactivity into vtkChartXYZ.  This eliminates the need for a
separate vtkInteractiveChartXYZ class.

This change also introduces new functionality.  vtkPlotSurface allows us
to visualize a table as a 3D surface plot.

I've updated vtkScatterPlotMatrix so that it correctly uses the new API
of vtkChartXYZ for animation.

All affected tests were updated as well.
Change-Id: Ic8406c99758a98851949c6153129f7704784e31a
parent f2327f6f
......@@ -16,12 +16,12 @@ set(Module_SRCS
vtkCompositeTransferFunctionItem.cxx
vtkContextPolygon.cxx
vtkControlPointsItem.cxx
vtkInteractiveChartXYZ.cxx
vtkLookupTableItem.cxx
vtkPiecewiseControlPointsItem.cxx
vtkPiecewiseFunctionItem.cxx
vtkPiecewisePointHandleItem.cxx
vtkPlot.cxx
vtkPlot3D.cxx
vtkPlotBar.cxx
vtkPlotGrid.cxx
vtkPlotHistogram2D.cxx
......@@ -29,7 +29,9 @@ set(Module_SRCS
vtkPlotParallelCoordinates.cxx # This adds a vtkInfovisCore dep for one class...
vtkPlotPie.cxx
vtkPlotPoints.cxx
vtkPlotPoints3D.cxx
vtkPlotStacked.cxx
vtkPlotSurface.cxx
vtkScalarsToColorsItem.cxx
vtkScatterPlotMatrix.cxx
)
......
......@@ -41,6 +41,7 @@
TestScientificPlot.cxx
TestStackedBarGraph.cxx
TestStackedPlot.cxx
TestSurfacePlot.cxx
)
# Set the tolerance higher for a few tests that need it
set(TestGLSLError 12)
......
......@@ -17,6 +17,7 @@
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkFloatArray.h"
#include "vtkPlotPoints3D.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
......@@ -51,10 +52,15 @@ int TestChartXYZ(int , char * [])
{
// Now the chart
vtkNew<vtkChartXYZ> chart;
chart->SetAutoRotate(true);
chart->SetFitToScene(false);
chart->SetDecorateAxes(false);
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
view->GetScene()->AddItem(chart.GetPointer());
vtkNew<vtkChartXYZ> chart2;
chart2->SetFitToScene(false);
chart->SetDecorateAxes(false);
view->GetScene()->AddItem(chart2.GetPointer());
chart->SetGeometry(vtkRectf(75.0, 20.0, 250, 260));
......@@ -85,14 +91,14 @@ int TestChartXYZ(int , char * [])
//chart->SetAroundX(true);
// Add the three dimensions we are interested in visualizing.
chart->SetInput(table.GetPointer(), "X Axis", "Sine", "Cosine");
chart->RecalculateBounds();
chart->RecalculateTransform();
vtkNew<vtkPlotPoints3D> plot;
plot->SetInputData(table.GetPointer(), "X Axis", "Sine", "Cosine");
chart->AddPlot(plot.GetPointer());
// We want a duplicate, that does not move.
chart2->SetInput(table.GetPointer(), "X Axis", "Sine", "Cosine");
chart2->RecalculateBounds();
chart2->RecalculateTransform();
vtkNew<vtkPlotPoints3D> plot2;
plot2->SetInputData(table.GetPointer(), "X Axis", "Sine", "Cosine");
chart2->AddPlot(plot2.GetPointer());
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
......
......@@ -13,12 +13,13 @@
=========================================================================*/
#include "vtkInteractiveChartXYZ.h"
#include "vtkChartXYZ.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkFloatArray.h"
#include "vtkNew.h"
#include "vtkPlotPoints3D.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
......@@ -30,7 +31,7 @@
int TestInteractiveChartXYZ(int , char * [])
{
// Now the chart
vtkNew<vtkInteractiveChartXYZ> chart;
vtkNew<vtkChartXYZ> chart;
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
view->GetScene()->AddItem(chart.GetPointer());
......@@ -65,9 +66,9 @@ int TestInteractiveChartXYZ(int , char * [])
}
// Add the dimensions we are interested in visualizing.
chart->SetInput(table.GetPointer(), "X Axis", "Sine", "Cosine", "Color");
chart->RecalculateBounds();
chart->RecalculateTransform();
vtkNew<vtkPlotPoints3D> plot;
plot->SetInputData(table.GetPointer(), "X Axis", "Sine", "Cosine", "Color");
chart->AddPlot(plot.GetPointer());
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
......
......@@ -74,6 +74,16 @@ int TestScatterPlotMatrix(int, char * [])
matrix->GetMainChart()->SetActionToButton(vtkChart::SELECT_POLYGON,
vtkContextMouseEvent::RIGHT_BUTTON);
// Test animation by releasing a right click on subchart (1,2)
vtkContextMouseEvent mouseEvent;
mouseEvent.SetInteractor(view->GetInteractor());
vtkVector2f pos;
mouseEvent.SetButton(vtkContextMouseEvent::RIGHT_BUTTON);
pos.Set(245, 301);
mouseEvent.SetPos(pos);
matrix->MouseButtonReleaseEvent(mouseEvent);
//Finally render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestSurfacePlot.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 "vtkChartXYZ.h"
#include "vtkContextMouseEvent.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkFloatArray.h"
#include "vtkNew.h"
#include "vtkPlotSurface.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTable.h"
#include "vtkRegressionTestImage.h"
#include "vtkUnsignedCharArray.h"
#include "vtkVector.h"
int TestSurfacePlot(int , char * [])
{
vtkNew<vtkChartXYZ> chart;
vtkNew<vtkPlotSurface> plot;
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
view->GetScene()->AddItem(chart.GetPointer());
chart->SetGeometry(vtkRectf(75.0, 20.0, 250, 260));
// Create a surface
vtkNew<vtkTable> table;
float numPoints = 70;
float inc = 9.424778 / (numPoints - 1);
for (float i = 0; i < numPoints; ++i)
{
vtkNew<vtkFloatArray> arr;
table->AddColumn(arr.GetPointer());
}
table->SetNumberOfRows(numPoints);
for (float i = 0; i < numPoints; ++i)
{
float x = i * inc;
for (float j = 0; j < numPoints; ++j)
{
float y = j * inc;
table->SetValue(i, j, sin(sqrt(x*x + y*y)));
}
}
// Set up the surface plot we wish to visualize and add it to the chart.
plot->SetXRange(0, 9.424778);
plot->SetYRange(0, 9.424778);
plot->SetInputData(table.GetPointer());
chart->AddPlot(plot.GetPointer());
view->GetRenderWindow()->SetMultiSamples(0);
view->GetInteractor()->Initialize();
view->GetRenderWindow()->Render();
// rotate
vtkContextMouseEvent mouseEvent;
mouseEvent.SetInteractor(view->GetInteractor());
vtkVector2i pos;
vtkVector2i lastPos;
mouseEvent.SetButton(vtkContextMouseEvent::LEFT_BUTTON);
lastPos.Set(100, 50);
mouseEvent.SetLastScreenPos(lastPos);
pos.Set(150, 100);
mouseEvent.SetScreenPos(pos);
vtkVector2d sP(pos.Cast<double>().GetData());
vtkVector2d lSP(lastPos.Cast<double>().GetData());
vtkVector2d screenPos(mouseEvent.GetScreenPos().Cast<double>().GetData());
vtkVector2d lastScreenPos(mouseEvent.GetLastScreenPos().Cast<double>().GetData());
chart->MouseMoveEvent(mouseEvent);
view->GetInteractor()->Start();
return EXIT_SUCCESS;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPlot3D.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 vtkPlot3D - Abstract class for 3D plots.
//
// .SECTION Description
// The base class for all plot types used in vtkChart derived charts.
//
// .SECTION See Also
// vtkPlot3DPoints vtkPlot3DLine vtkPlot3DBar vtkChart vtkChartXY
#ifndef __vtkPlot3D_h
#define __vtkPlot3D_h
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkContextItem.h"
#include "vtkNew.h" // Needed to hold vtkNew ivars
#include "vtkSmartPointer.h" // Needed to hold SP ivars
#include "vtkVector.h" // For Points ivar
#include <vector> // For ivars
using std::vector;
class vtkChartXYZ;
class vtkTable;
class vtkUnsignedCharArray;
class vtkPen;
class VTKCHARTSCORE_EXPORT vtkPlot3D : public vtkContextItem
{
public:
vtkTypeMacro(vtkPlot3D, vtkContextItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Set/get the vtkPen object that controls how this plot draws (out)lines.
void SetPen(vtkPen *pen);
vtkPen* GetPen();
// Description:
// Set the input to the plot.
virtual void SetInputData(vtkTable *input);
virtual void SetInputData(vtkTable *input, const vtkStdString &xName,
const vtkStdString &yName,
const vtkStdString &zName);
virtual void SetInputData(vtkTable *input, const vtkStdString &xName,
const vtkStdString &yName,
const vtkStdString &zName,
const vtkStdString &colorName);
virtual void SetInputData(vtkTable *input, vtkIdType xColumn,
vtkIdType yColumn, vtkIdType zColumn);
// Description:
// Get all the data points within this plot.
vector<vtkVector3f> GetPoints();
// Description:
// Get the data points from this plot that currently fall within the axes
// of the chart.
vector<vtkVector3f> GetPointsThatSurviveClipping();
// Description:
// Get/set the chart for this plot.
vtkGetObjectMacro(Chart, vtkChartXYZ);
virtual void SetChart(vtkChartXYZ* chart);
// Description:
// Get the label for the X axis.
std::string GetXAxisLabel();
// Description:
// Get the label for the Y axis.
std::string GetYAxisLabel();
// Description:
// Get the label for the Z axis.
std::string GetZAxisLabel();
// Description:
// Get the bounding cube surrounding the currently rendered data points.
vector<vtkVector3f> GetDataBounds() { return this->DataBounds; }
//BTX
protected:
vtkPlot3D();
~vtkPlot3D();
// Description:
// Determine what data points fall within the bounds of the chart axes.
virtual void UpdateClippedPoints();
// Description:
// Generate a bounding cube for our data.
virtual void ComputeDataBounds();
// Description:
// This object stores the vtkPen that controls how the plot is drawn.
vtkSmartPointer<vtkPen> Pen;
// Description:
// This array assigns a color to each datum in the plot.
vtkNew<vtkUnsignedCharArray> Colors;
// Description:
// This array assigns a color to each data point which is currently
// rendered within the axes.
vtkNew<vtkUnsignedCharArray> ClippedColors;
// Description:
// Number of components in our color vectors. This value is initialized
// to zero. It's typically set to 3 or 4 if the points are to be colored.
int NumberOfComponents;
// Description:
// The label for the X Axis.
std::string XAxisLabel;
// Description:
// The label for the Y Axis.
std::string YAxisLabel;
// Description:
// The label for the Z Axis.
std::string ZAxisLabel;
// Description:
// The data points read in during SetInputData().
vector<vtkVector3f> Points;
// Description:
// The subset of our data points that fall within the axes. These are
// the only data points that are rendered.
vector<vtkVector3f> PointsThatSurviveClipping;
// Description:
// When the points were last built.
vtkTimeStamp PointsBuildTime;
// Description:
// The chart containing this plot.
vtkChartXYZ* Chart;
// Description:
// A bounding cube surrounding the currently rendered data points.
vector<vtkVector3f> DataBounds;
private:
vtkPlot3D(const vtkPlot3D &); // Not implemented.
void operator=(const vtkPlot3D &); // Not implemented.
//ETX
};
#endif //__vtkPlot3D_h
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPlotPoints3D.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 "vtkChartXYZ.h"
#include "vtkContext2D.h"
#include "vtkContext3D.h"
#include "vtkObjectFactory.h"
#include "vtkNew.h"
#include "vtkPen.h"
#include "vtkPlotPoints3D.h"
#include "vtkUnsignedCharArray.h"
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotPoints3D)
//-----------------------------------------------------------------------------
vtkPlotPoints3D::vtkPlotPoints3D()
{
this->Pen->SetWidth(5);
this->Pen->SetColor(0, 0, 0, 255);
}
//-----------------------------------------------------------------------------
vtkPlotPoints3D::~vtkPlotPoints3D()
{
}
//-----------------------------------------------------------------------------
void vtkPlotPoints3D::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//-----------------------------------------------------------------------------
bool vtkPlotPoints3D::Paint(vtkContext2D *painter)
{
if (!this->Visible || this->Points.size() == 0)
return false;
// Get the 3D context.
vtkContext3D *context = painter->GetContext3D();
if (!context)
return false;
this->Update();
// Update the points that fall inside our axes
if (this->Chart->ShouldCheckClipping())
{
this->UpdateClippedPoints();
}
if (this->PointsThatSurviveClipping.size() > 0)
{
// Draw the points in 3d.
context->ApplyPen(this->Pen.GetPointer());
if (this->NumberOfComponents == 0)
{
context->DrawPoints(
this->PointsThatSurviveClipping[0].GetData(),
static_cast<int>(this->PointsThatSurviveClipping.size()));
}
else
{
context->DrawPoints(
this->PointsThatSurviveClipping[0].GetData(),
static_cast<int>(this->PointsThatSurviveClipping.size()),
this->ClippedColors->GetPointer(0), this->NumberOfComponents);
}
}
return true;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPlotPoints3D.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 vtkPlotPoints3D - 3D scatter plot.
//
// .SECTION Description
// 3D scatter plot.
//
#ifndef __vtkPlotPoints3D_h
#define __vtkPlotPoints3D_h
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkPlot3D.h"
class vtkContext2D;
class VTKCHARTSCORE_EXPORT vtkPlotPoints3D : public vtkPlot3D
{
public:
vtkTypeMacro(vtkPlotPoints3D, vtkPlot3D);
virtual void PrintSelf(ostream &os, vtkIndent indent);
static vtkPlotPoints3D * New();
// Description:
// Paint event for the XY plot, called whenever the chart needs to be drawn
virtual bool Paint(vtkContext2D *painter);
//BTX
protected:
vtkPlotPoints3D();
~vtkPlotPoints3D();
private:
vtkPlotPoints3D(const vtkPlotPoints3D &); // Not implemented.
void operator=(const vtkPlotPoints3D &); // Not implemented.
//ETX
};
#endif //__vtkPlotPoints3D_h
This diff is collapsed.
This diff is collapsed.
......@@ -31,6 +31,7 @@
#include "vtkObjectFactory.h"
#include "vtkBrush.h"
#include "vtkPlotPoints.h"
#include "vtkPlotPoints3D.h"
#include "vtkCommand.h"
#include "vtkTextProperty.h"
#include "vtkContextScene.h"
......@@ -622,13 +623,15 @@ void vtkScatterPlotMatrix::AdvanceAnimation()
this->Private->NextActivePlot = *this->Private->AnimationIter;
vtkChartXYZ *chart = this->Private->BigChart3D.GetPointer();
chart->SetVisible(false);
vtkRectf size = this->Private->BigChart->GetSize();
chart->SetGeometry(size);
chart->SetAutoRotate(true);
chart->SetDecorateAxes(false);
chart->SetFitToScene(false);
int yColumn = this->GetSize().GetY() - this->ActivePlot.GetY() - 1;
bool isX = false;
int zColumn = 0;
vtkRectf size = this->Private->BigChart->GetSize();
float zSize(size.GetWidth());
this->Private->FinalAngle = 90.0;
this->Private->IncAngle = this->Private->FinalAngle / this->NumberOfFrames;
......@@ -666,12 +669,20 @@ void vtkScatterPlotMatrix::AdvanceAnimation()
}
}
chart->SetAroundX(isX);
chart->SetGeometry(size);
vtkStdString names[3];
names[0] = this->VisibleColumns->GetValue(this->ActivePlot.GetX());
names[1] = this->VisibleColumns->GetValue(yColumn);
names[2] = this->VisibleColumns->GetValue(zColumn);
this->Private->BigChart3D->SetInput(this->Input.GetPointer(),
names[0], names[1], names[2]);
// Setup the 3D chart
this->Private->BigChart3D->ClearPlots();
vtkNew<vtkPlotPoints3D> scatterPlot3D;
scatterPlot3D->SetInputData(
this->Input.GetPointer(), names[0], names[1], names[2]);
this->Private->BigChart3D->AddPlot(scatterPlot3D.GetPointer());
// Set the z axis up so that it ends in the right orientation.
chart->GetAxis(2)->SetPoint2(0, zSize);
// Now set the ranges for the three axes.
......@@ -685,7 +696,7 @@ void vtkScatterPlotMatrix::AdvanceAnimation()
++this->Private->AnimationPhase;
return;
}
case 1: // Make BigChart inivisible, and BigChart3D visible.
case 1: // Make BigChart invisible, and BigChart3D visible.
this->Private->BigChart->SetVisible(false);
this->AddItem(this->Private->BigChart3D.GetPointer());
this->Private->BigChart3D->SetVisible(true);
......
......@@ -89,6 +89,13 @@ void vtkContext3D::DrawPoints(const float *points, int n,
this->Device->DrawPoints(points, n, colors, nc_comps);
}
void vtkContext3D::DrawSurface(const float *surface, int n,
const unsigned char *colors, int nc)
{
assert(this->Device);
this->Device->DrawSurface(surface, n, colors, nc);
}
void vtkContext3D::ApplyPen(vtkPen *pen)
{
assert(this->Device);
......
......@@ -79,6 +79,11 @@ public:
void DrawPoints(const float *points, int n,
unsigned char *colors, int nc_comps);
// Description:
// Draw triangles to generate the specified surface.
void DrawSurface(const float *surface, int n,
const unsigned char *colors, int nc);
// Description:
// Apply the supplied pen which controls the outlines of shapes, as well as
// lines, points and related primitives. This makes a deep copy of the vtkPen
......
......@@ -51,6 +51,11 @@ public:
virtual void DrawPoints(const float *verts, int n,
const unsigned char *colors = 0, int nc = 0) = 0;
// Description:
// Draw triangles to generate the specified surface.
virtual void DrawSurface(const float *surface, int n,
const unsigned char *colors, int nc) = 0;
// Description:
// Apply the supplied pen which controls the outlines of shapes, as well as
// lines, points and related primitives. This makes a deep copy of the vtkPen
......
......@@ -44,7 +44,13 @@ public:
// Description:
// Draw points at the vertex positions specified.
void DrawPoints(const float *verts, int n, const unsigned char *colors, int nc);
void DrawPoints(const float *verts, int n,
const unsigned char *colors, int nc);
// Description:
// Draw triangles to generate the specified surface.
void DrawSurface(const float *surface, int n,
const unsigned char *colors, int nc);
// Description:
// Apply the supplied pen which controls the outlines of shapes, as well as
......
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