Commit efb0b575 authored by Matt McCormick's avatar Matt McCormick

Add vtkPlotLine3D class.

Implementation based off vtkPlotLine.

Change-Id: I4a00a3df68df351cd11c127e44135bff7e3eb7ec
parent 8517623a
...@@ -26,6 +26,7 @@ set(Module_SRCS ...@@ -26,6 +26,7 @@ set(Module_SRCS
vtkPlotGrid.cxx vtkPlotGrid.cxx
vtkPlotHistogram2D.cxx vtkPlotHistogram2D.cxx
vtkPlotLine.cxx vtkPlotLine.cxx
vtkPlotLine3D.cxx
vtkPlotParallelCoordinates.cxx # This adds a vtkInfovisCore dep for one class... vtkPlotParallelCoordinates.cxx # This adds a vtkInfovisCore dep for one class...
vtkPlotPie.cxx vtkPlotPie.cxx
vtkPlotPoints.cxx vtkPlotPoints.cxx
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
TestInteractiveChartXYZ.cxx TestInteractiveChartXYZ.cxx
TestLegendHiddenPlots.cxx TestLegendHiddenPlots.cxx
TestLinePlot.cxx TestLinePlot.cxx
TestLinePlot3D.cxx
TestLinePlotAxisFonts.cxx TestLinePlotAxisFonts.cxx
TestLinePlot2.cxx TestLinePlot2.cxx
TestLinePlotInteraction.cxx TestLinePlotInteraction.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestLinePlot.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 "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkChartXYZ.h"
#include "vtkPen.h"
#include "vtkPlotLine3D.h"
#include "vtkTable.h"
#include "vtkFloatArray.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNew.h"
// Plot the solution to the Lorenz attractor.
// http://en.wikipedia.org/wiki/Lorenz_system
namespace
{
void lorenz(const float * varX, float * varXDerivative)
{
const float sigma = 10.f;
const float rho = 28.f;
const float beta = 2.66666666666f;
varXDerivative[0] = sigma * (varX[1] - varX[0]);
varXDerivative[1] = varX[0] * (rho - varX[2]) - varX[1];
varXDerivative[2] = varX[0] * varX[1] - beta * varX[2];
}
} // end anonymous namespace
//----------------------------------------------------------------------------
int TestLinePlot3D( int, char * [] )
{
// Create the data.
vtkNew<vtkTable> varXSolution;
vtkNew<vtkFloatArray> arrX0;
arrX0->SetName("X Axis");
varXSolution->AddColumn(arrX0.GetPointer());
vtkNew<vtkFloatArray> arrX1;
arrX1->SetName("Y Axis");
varXSolution->AddColumn(arrX1.GetPointer());
vtkNew<vtkFloatArray> arrX2;
arrX2->SetName("Z Axis");
varXSolution->AddColumn(arrX2.GetPointer());
const unsigned int numberOfTimePoints = 10000;
varXSolution->SetNumberOfRows(numberOfTimePoints);
float varX[3];
varX[0] = 0.0f;
varX[1] = 1.0f;
varX[2] = 1.05f;
float varXDerivative[3];
const float deltaT = 0.01f;
for (unsigned int ii = 0; ii < numberOfTimePoints; ++ii)
{
varXSolution->SetValue(ii, 0, varX[0]);
varXSolution->SetValue(ii, 1, varX[1]);
varXSolution->SetValue(ii, 2, varX[2]);
lorenz(varX, varXDerivative);
varX[0] += varXDerivative[0] * deltaT;
varX[1] += varXDerivative[1] * deltaT;
varX[2] += varXDerivative[2] * deltaT;
}
// Set up a 3D scene and add an XYZ chart to it.
vtkNew<vtkContextView> view;
view->GetRenderWindow()->SetSize(400, 300);
vtkNew<vtkChartXYZ> chart;
chart->SetGeometry(vtkRectf(75.0, 20.0, 250, 260));
view->GetScene()->AddItem(chart.GetPointer());
// Add a line plot.
vtkNew<vtkPlotLine3D> plot;
plot->SetInputData(varXSolution.GetPointer());
vtkPen * pen = plot->GetPen();
pen->SetColorF(0.1, 0.2, 0.8, 0.5);
chart->AddPlot(plot.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: vtkPlotLine.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 "vtkPlotLine3D.h"
#include "vtkPen.h"
#include "vtkContext2D.h"
#include "vtkContext3D.h"
#include "vtkObjectFactory.h"
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotLine3D);
//-----------------------------------------------------------------------------
vtkPlotLine3D::vtkPlotLine3D()
{
}
//-----------------------------------------------------------------------------
vtkPlotLine3D::~vtkPlotLine3D()
{
}
//-----------------------------------------------------------------------------
bool vtkPlotLine3D::Paint(vtkContext2D *painter)
{
// This is where everything should be drawn, or dispatched to other methods.
vtkDebugMacro(<< "Paint event called in vtkPlotLine3D.");
if (!this->Visible || this->Points.size() == 0)
{
return false;
}
// Get the 3D context.
vtkContext3D *context = painter->GetContext3D();
if(context == false)
{
return false;
}
// Draw the line between the points
context->ApplyPen(this->Pen);
context->DrawPoly(this->Points[0].GetData(), static_cast< int >(this->Points.size()));
return this->vtkPlotPoints3D::Paint(painter);
}
//-----------------------------------------------------------------------------
void vtkPlotLine3D::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPlotLine3D.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 vtkPlotLine3D - Class for drawing an XYZ line plot given three columns from
// a vtkTable.
//
// .SECTION Description
// This class draws points with a line between them given three column from a
// vtkTable in a vtkChartXYZ.
//
// .SECTION See Also
// vtkPlotPoints3D
// vtkPlotLine
//
#ifndef __vtkPlotLine3D_h
#define __vtkPlotLine3D_h
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkPlotPoints3D.h"
class VTKCHARTSCORE_EXPORT vtkPlotLine3D : public vtkPlotPoints3D
{
public:
vtkTypeMacro(vtkPlotLine3D, vtkPlotPoints3D);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Creates a 3D Chart object.
static vtkPlotLine3D *New();
// Description:
// Paint event for the XYZ plot, called whenever the chart needs to be drawn.
virtual bool Paint(vtkContext2D *painter);
//BTX
protected:
vtkPlotLine3D();
~vtkPlotLine3D();
private:
vtkPlotLine3D(const vtkPlotLine3D &); // Not implemented.
void operator=(const vtkPlotLine3D &); // Not implemented.
//ETX
};
#endif //__vtkPlotLine3D_h
...@@ -47,13 +47,17 @@ void vtkPlotPoints3D::PrintSelf(ostream &os, vtkIndent indent) ...@@ -47,13 +47,17 @@ void vtkPlotPoints3D::PrintSelf(ostream &os, vtkIndent indent)
bool vtkPlotPoints3D::Paint(vtkContext2D *painter) bool vtkPlotPoints3D::Paint(vtkContext2D *painter)
{ {
if (!this->Visible || this->Points.size() == 0) if (!this->Visible || this->Points.size() == 0)
{
return false; return false;
}
// Get the 3D context. // Get the 3D context.
vtkContext3D *context = painter->GetContext3D(); vtkContext3D *context = painter->GetContext3D();
if (!context) if (!context)
{
return false; return false;
}
this->Update(); this->Update();
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
// .SECTION Description // .SECTION Description
// 3D scatter plot. // 3D scatter plot.
// //
// .SECTION See Also
// vtkPlotLine3D
// vtkPlotPoints
//
#ifndef __vtkPlotPoints3D_h #ifndef __vtkPlotPoints3D_h
#define __vtkPlotPoints3D_h #define __vtkPlotPoints3D_h
...@@ -46,8 +50,8 @@ protected: ...@@ -46,8 +50,8 @@ protected:
private: private:
vtkPlotPoints3D(const vtkPlotPoints3D &); // Not implemented. vtkPlotPoints3D(const vtkPlotPoints3D &); // Not implemented.
void operator=(const vtkPlotPoints3D &); // Not implemented. void operator=(const vtkPlotPoints3D &); // Not implemented.
//ETX //ETX
}; };
#endif //__vtkPlotPoints3D_h #endif //__vtkPlotPoints3D_h
...@@ -70,6 +70,12 @@ void vtkContext3D::DrawLine(const vtkVector3f &start, const vtkVector3f &end) ...@@ -70,6 +70,12 @@ void vtkContext3D::DrawLine(const vtkVector3f &start, const vtkVector3f &end)
this->Device->DrawPoly(line[0].GetData(), 2); this->Device->DrawPoly(line[0].GetData(), 2);
} }
void vtkContext3D::DrawPoly(const float *points, int n)
{
assert(this->Device);
this->Device->DrawPoly(points, n);
}
void vtkContext3D::DrawPoint(const vtkVector3f &point) void vtkContext3D::DrawPoint(const vtkVector3f &point)
{ {
assert(this->Device); assert(this->Device);
......
...@@ -64,6 +64,10 @@ public: ...@@ -64,6 +64,10 @@ public:
// Draw a line between the specified points. // Draw a line between the specified points.
void DrawLine(const vtkVector3f &start, const vtkVector3f &end); void DrawLine(const vtkVector3f &start, const vtkVector3f &end);
// Description:
// Draw a poly line between the specified points.
void DrawPoly(const float *points, int n);
// Description: // Description:
// Draw a point at the point in 3D space. // Draw a point at the point in 3D space.
void DrawPoint(const vtkVector3f &point); void DrawPoint(const vtkVector3f &point);
......
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