Commit 39efc956 authored by Joachim Pouderoux's avatar Joachim Pouderoux

Enhance bag plot API to allow specify line and points properties.

A new vtkPen is added to draw bag boundary lines, while the
default plot Pen is used to draw bag plot points.

This also patch the forced color values for Box plot pen.
Box plot pen is used to draw the box plot lines.

Change-Id: I566779743da52226916649879973699052366f28
parent e83fc65f
......@@ -33,12 +33,21 @@
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotBag);
vtkSetObjectImplementationMacro(vtkPlotBag, LinePen, vtkPen);
//-----------------------------------------------------------------------------
vtkPlotBag::vtkPlotBag()
{
this->MedianPoints = vtkPoints2D::New();
this->Q3Points = vtkPoints2D::New();
this->TooltipDefaultLabelFormat = "%l (%x, %y): %z";
this->Brush->SetColor(255, 0, 0);
this->Brush->SetOpacity(255);
this->Pen->SetColor(0, 0, 0);
this->Pen->SetWidth(5.f);
this->LinePen = vtkPen::New();
this->LinePen->SetColor(0, 0, 0);
this->LinePen->SetWidth(1.f);
}
//-----------------------------------------------------------------------------
......@@ -54,6 +63,11 @@ vtkPlotBag::~vtkPlotBag()
this->Q3Points->Delete();
this->Q3Points = 0;
}
if (this->LinePen)
{
this->LinePen->Delete();
this->LinePen = 0;
}
}
//-----------------------------------------------------------------------------
......@@ -224,16 +238,13 @@ bool vtkPlotBag::Paint(vtkContext2D *painter)
return false;
}
unsigned char pcolor[4];
this->Pen->GetColor(pcolor);
unsigned char bcolor[4];
this->Brush->GetColor(bcolor);
// Draw the 2 bags
this->Pen->SetColor(0, 0, 0);
this->Brush->SetOpacity(255);
this->Brush->SetColor(pcolor[0] / 2, pcolor[1] / 2, pcolor[2] / 2);
painter->ApplyPen(this->Pen);
this->Brush->SetColor(bcolor[0] / 2, bcolor[1] / 2, bcolor[2] / 2);
painter->ApplyPen(this->LinePen);
painter->ApplyBrush(this->Brush);
if (this->Q3Points->GetNumberOfPoints() > 2)
{
......@@ -244,9 +255,8 @@ bool vtkPlotBag::Paint(vtkContext2D *painter)
painter->DrawLine(this->Q3Points);
}
this->Brush->SetColor(pcolor);
this->Brush->SetColor(bcolor);
this->Brush->SetOpacity(128);
painter->ApplyPen(this->Pen);
painter->ApplyBrush(this->Brush);
if (this->MedianPoints->GetNumberOfPoints() > 2)
......@@ -258,8 +268,7 @@ bool vtkPlotBag::Paint(vtkContext2D *painter)
painter->DrawLine(this->MedianPoints);
}
this->Brush->SetColor(bcolor);
this->Pen->SetColor(pcolor);
painter->ApplyPen(this->Pen);
// Let PlotPoints draw the points as usual
return this->Superclass::Paint(painter);
......@@ -268,23 +277,21 @@ bool vtkPlotBag::Paint(vtkContext2D *painter)
//-----------------------------------------------------------------------------
bool vtkPlotBag::PaintLegend(vtkContext2D *painter, const vtkRectf& rect, int)
{
vtkNew<vtkPen> blackPen;
blackPen->SetWidth(1.0);
blackPen->SetColor(0, 0, 0, 255);
painter->ApplyPen(blackPen.GetPointer());
unsigned char pcolor[4];
this->Pen->GetColor(pcolor);
painter->ApplyPen(this->LinePen);
unsigned char bcolor[4];
this->Brush->GetColor(bcolor);
unsigned char opacity = this->Brush->GetOpacity();
this->Brush->SetColor(pcolor[0] / 2, pcolor[1] / 2, pcolor[2] / 2);
this->Brush->SetOpacity(255);
this->Brush->SetColor(bcolor[0] / 2, bcolor[1] / 2, bcolor[2] / 2);
painter->ApplyBrush(this->Brush);
painter->DrawRect(rect[0], rect[1], rect[2]/2, rect[3]);
painter->DrawRect(rect[0], rect[1], rect[2], rect[3]);
this->Brush->SetColor(pcolor);
this->Brush->SetOpacity(255);
this->Brush->SetColor(bcolor);
this->Brush->SetOpacity(128);
painter->ApplyBrush(this->Brush);
painter->DrawRect(rect[0] + rect[2] / 2.f, rect[1], rect[2]/2, rect[3]);
this->Brush->SetOpacity(opacity);
return true;
}
......@@ -306,7 +313,10 @@ vtkStringArray* vtkPlotBag::GetLabels()
this->AutoLabels = vtkSmartPointer<vtkStringArray>::New();
vtkDataArray *density = vtkDataArray::SafeDownCast(
this->Data->GetInputAbstractArrayToProcess(2, this->GetInput()));
this->AutoLabels->InsertNextValue(density->GetName());
if (density)
{
this->AutoLabels->InsertNextValue(density->GetName());
}
return this->AutoLabels;
}
return NULL;
......
......@@ -33,6 +33,8 @@
#include "vtkChartsCoreModule.h" // For export macro
#include "vtkPlotPoints.h"
class vtkPen;
class VTKCHARTSCORE_EXPORT vtkPlotBag : public vtkPlotPoints
{
public:
......@@ -90,6 +92,19 @@ public:
vtkIdType yColumn,
vtkIdType densityColumn);
// Description:
// Set/get the vtkPen object that controls how this plot draws boundary lines.
void SetLinePen(vtkPen* pen);
vtkGetObjectMacro(LinePen, vtkPen);
// Description:
// Set/get the vtkPen object that controls how this plot draws points.
// Those are just helpers functions:
// this pen is actually the default Plot pen.
void SetPointPen(vtkPen* pen) { this->SetPen(pen); }
vtkPen* GetPointPen() { return this->GetPen(); }
protected:
vtkPlotBag();
~vtkPlotBag();
......@@ -98,6 +113,7 @@ protected:
vtkPoints2D* MedianPoints;
vtkPoints2D* Q3Points;
vtkPen* LinePen;
private:
vtkPlotBag(const vtkPlotBag &); // Not implemented.
......
......@@ -58,7 +58,7 @@ vtkStandardNewMacro(vtkPlotBox)
vtkPlotBox::vtkPlotBox()
{
this->Storage = new vtkPlotBox::Private();
this->Pen->SetColor(255, 0, 0, 25);
this->Pen->SetColor(0, 0, 0);
this->BoxWidth = 20.;
this->LookupTable = 0;
this->TooltipDefaultLabelFormat = "%y";
......@@ -158,11 +158,6 @@ void vtkPlotBox::DrawBoxPlot(int i, unsigned char *rgba, double x,
vtkNew<vtkBrush> brush;
brush->SetColor(rgba);
vtkNew<vtkPen> blackPen;
blackPen->SetWidth(this->Pen->GetWidth());
blackPen->SetColor(0, 0, 0, 128);
blackPen->SetOpacity(255);
painter->ApplyPen(blackPen.GetPointer());
painter->ApplyBrush(brush.GetPointer());
// Helper variables for x position
......
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