Commit debdfab0 authored by Marcus Hanwell's avatar Marcus Hanwell
Browse files

ENH: Plots now contain a vtkPen.

The plots now contain a vtkPen, this means that the pen can be
manipulated in order to change the color, width, line style etc.
parent 6ac34bab
......@@ -15,6 +15,7 @@
#include "vtkPlot.h"
#include "vtkPen.h"
#include "vtkTable.h"
#include "vtkDataObject.h"
#include "vtkIdTypeArray.h"
......@@ -23,17 +24,14 @@
#include "vtkStdString.h"
vtkCxxRevisionMacro(vtkPlot, "1.6");
vtkCxxRevisionMacro(vtkPlot, "1.7");
vtkCxxSetObjectMacro(vtkPlot, Selection, vtkIdTypeArray);
//-----------------------------------------------------------------------------
vtkPlot::vtkPlot()
{
this->Color[0] = 0;
this->Color[1] = 0;
this->Color[2] = 0;
this->Color[3] = 255;
this->Width = 2.0;
this->Pen = vtkPen::New();
this->Pen->SetWidth(2.0);
this->Label = NULL;
this->UseIndexForXSeries = false;
this->Data = vtkContextMapper2D::New();
......@@ -43,6 +41,11 @@ vtkPlot::vtkPlot()
//-----------------------------------------------------------------------------
vtkPlot::~vtkPlot()
{
if (this->Pen)
{
this->Pen->Delete();
this->Pen = NULL;
}
if (this->Data)
{
this->Data->Delete();
......@@ -55,27 +58,32 @@ vtkPlot::~vtkPlot()
void vtkPlot::SetColor(unsigned char r, unsigned char g, unsigned char b,
unsigned char a)
{
this->Color[0] = r;
this->Color[1] = g;
this->Color[2] = b;
this->Color[3] = a;
this->Pen->SetColor(r, g, b, a);
}
//-----------------------------------------------------------------------------
void vtkPlot::SetColor(double r, double g, double b)
{
this->Color[0] = static_cast<unsigned char>(r*255.0);
this->Color[1] = static_cast<unsigned char>(g*255.0);
this->Color[2] = static_cast<unsigned char>(b*255.0);
this->Pen->SetColorF(r, g, b);
}
//-----------------------------------------------------------------------------
void vtkPlot::SetWidth(float width)
{
this->Pen->SetWidth(width);
}
//-----------------------------------------------------------------------------
float vtkPlot::GetWidth()
{
return this->Pen->GetWidth();
}
//-----------------------------------------------------------------------------
void vtkPlot::GetColor(double rgb[3])
{
for (int i = 0; i < 3; ++i)
{
rgb[i] = double(this->Color[0]) / 255.0;
}
this->Pen->GetColorF(rgb);
}
//-----------------------------------------------------------------------------
......@@ -125,8 +133,4 @@ void vtkPlot::SetInputArray(int index, const char *name)
void vtkPlot::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
// Print out our color and width
os << indent << "Color: " << this->Color[0] << ", " << this->Color[1]
<< ", " << this->Color[2] << ", " << this->Color[3] << endl;
os << indent << "Width: " << this->Width << endl;
}
......@@ -27,6 +27,7 @@ class vtkVariant;
class vtkTable;
class vtkIdTypeArray;
class vtkContextMapper2D;
class vtkPen;
class VTK_CHARTS_EXPORT vtkPlot : public vtkContextItem
{
......@@ -43,11 +44,16 @@ public:
// Description:
// Set the width of the line.
vtkSetMacro(Width, float);
void SetWidth(float width);
// Description:
// Get the width of the line.
vtkGetMacro(Width, float);
float GetWidth();
// Description:
// Get a pointer to the vtkPen object that controls the was this plot draws
// lines.
vtkGetObjectMacro(Pen, vtkPen);
// Description:
// Set the plot label.
......@@ -99,11 +105,9 @@ protected:
vtkPlot();
~vtkPlot();
unsigned char Color[4];
// Description:
// Width in pixels of the plotted line.
float Width;
// This object stores the vtkPen that controls how the plot is drawn.
vtkPen* Pen;
// Description:
// Plot label, used by legend.
......
......@@ -29,7 +29,7 @@
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkPlotLine, "1.7");
vtkCxxRevisionMacro(vtkPlotLine, "1.8");
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotLine);
......@@ -83,8 +83,8 @@ bool vtkPlotLine::Paint(vtkContext2D *painter)
vtkDebugMacro(<<"Selection set " << this->Selection->GetNumberOfTuples());
for (int i = 0; i < this->Selection->GetNumberOfTuples(); ++i)
{
painter->GetPen()->SetWidth(this->Width*15.0);
painter->GetPen()->SetColor(0, 0, 255, 255);
painter->GetPen()->SetWidth(this->Pen->GetWidth()*15.0);
painter->GetPen()->SetColor(this->Pen->GetColor());
vtkIdType id = 0;
this->Selection->GetTupleValue(i, &id);
if (id < this->Points->GetNumberOfPoints())
......@@ -102,10 +102,12 @@ bool vtkPlotLine::Paint(vtkContext2D *painter)
// Now to plot the points
if (this->Points)
{
painter->GetPen()->SetColor(this->Color);
painter->GetPen()->SetOpacity(this->Color[3]);
painter->GetPen()->SetWidth(this->Width);
painter->GetPen()->SetColor(this->Pen->GetColor());
painter->GetPen()->SetOpacity(this->Pen->GetOpacity());
painter->GetPen()->SetWidth(this->Pen->GetWidth());
painter->GetPen()->SetLineType(this->Pen->GetLineType());
painter->DrawPoly(this->Points);
painter->GetPen()->SetLineType(vtkPen::SOLID_LINE);
}
return true;
......
......@@ -30,7 +30,7 @@
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkPlotPoints, "1.2");
vtkCxxRevisionMacro(vtkPlotPoints, "1.3");
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotPoints);
......@@ -74,7 +74,7 @@ bool vtkPlotPoints::Paint(vtkContext2D *painter)
vtkDebugMacro(<<"Selection set " << this->Selection->GetNumberOfTuples());
for (int i = 0; i < this->Selection->GetNumberOfTuples(); ++i)
{
painter->GetPen()->SetWidth(this->Width*15.0);
painter->GetPen()->SetWidth(this->Pen->GetWidth()*15.0);
painter->GetPen()->SetColor(0, 0, 255, 255);
vtkIdType id = 0;
this->Selection->GetTupleValue(i, &id);
......@@ -93,9 +93,9 @@ bool vtkPlotPoints::Paint(vtkContext2D *painter)
// Now to plot the points
if (this->Points)
{
painter->GetPen()->SetColor(this->Color);
painter->GetPen()->SetOpacity(this->Color[3]);
painter->GetPen()->SetWidth(this->Width);
painter->GetPen()->SetColor(this->Pen->GetColor());
painter->GetPen()->SetOpacity(this->Pen->GetOpacity());
painter->GetPen()->SetWidth(this->Pen->GetWidth());
painter->DrawPoints(this->Points);
}
......
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