Commit 03d199c2 authored by Kyle Lutz's avatar Kyle Lutz Committed by Dave DeMarle
Browse files

Skip rendering of invalid points in PlotLine/PlotPoints

This adds code to skip the rendering of bad points in vtkPlotLine
and vtkPlotPoints. Also allows adding additional bad points with
a mask array.

This is used by the plot-over-line filter in ParaView to skip
rendering of points which are not a part of the data set.

Change-Id: I70b5caadeb21a8080b34b6ca9b24dfcd4b0f19f6
parent 3074f6e1
......@@ -18,6 +18,8 @@
#include "vtkContext2D.h"
#include "vtkPen.h"
#include "vtkRect.h"
#include "vtkPoints2D.h"
#include "vtkIdTypeArray.h"
#include "vtkObjectFactory.h"
......@@ -48,7 +50,32 @@ bool vtkPlotLine::Paint(vtkContext2D *painter)
// Draw the line between the points
painter->ApplyPen(this->Pen);
painter->DrawPoly(this->Points);
if (this->BadPoints && this->BadPoints->GetNumberOfTuples() > 0)
{
// draw lines skipping bad points
float *points = static_cast<float *>(this->Points->GetVoidPointer(0));
vtkIdType lastGood = 0;
for (vtkIdType i = 0; i < this->BadPoints->GetNumberOfTuples(); i++)
{
vtkIdType id = this->BadPoints->GetValue(i);
// render from last good point to one before this bad point
if (id - lastGood > 2)
{
painter->DrawPoly(points + 2 * (lastGood + 1), id - lastGood - 1);
}
lastGood = id;
}
}
else
{
// draw lines between all points
painter->DrawPoly(this->Points);
}
return this->vtkPlotPoints::Paint(painter);
}
......
......@@ -28,6 +28,7 @@
#include "vtkImageData.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkCharArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkLookupTable.h"
......@@ -67,6 +68,7 @@ vtkPlotPoints::vtkPlotPoints()
this->Points = NULL;
this->Sorted = NULL;
this->BadPoints = NULL;
this->ValidPointMask = NULL;
this->MarkerStyle = vtkPlotPoints::CIRCLE;
this->MarkerSize = -1.0;
this->LogX = false;
......@@ -113,6 +115,18 @@ void vtkPlotPoints::Update()
}
// Check if we have an input
vtkTable *table = this->Data->GetInput();
if (table && !this->ValidPointMaskName.empty() &&
table->GetColumnByName(this->ValidPointMaskName))
{
this->ValidPointMask = vtkCharArray::SafeDownCast(
table->GetColumnByName(this->ValidPointMaskName));
}
else
{
this->ValidPointMask = 0;
}
if (!table)
{
vtkDebugMacro(<< "Update event called with no input table set.");
......@@ -165,14 +179,43 @@ bool vtkPlotPoints::Paint(vtkContext2D *painter)
painter->ApplyPen(this->Pen);
painter->ApplyBrush(this->Brush);
painter->GetPen()->SetWidth(width);
float *points = static_cast<float *>(this->Points->GetVoidPointer(0));
unsigned char *colors = 0;
int nColorComponents = 0;
if (this->ScalarVisibility && this->Colors)
{
painter->DrawMarkers(this->MarkerStyle, false,
this->Points, this->Colors);
colors = this->Colors->GetPointer(0);
nColorComponents = static_cast<int>(this->Colors->GetNumberOfComponents());
}
if (this->BadPoints && this->BadPoints->GetNumberOfTuples() > 0)
{
vtkIdType lastGood = 0;
for (vtkIdType i = 0; i < this->BadPoints->GetNumberOfTuples(); i++)
{
vtkIdType id = this->BadPoints->GetValue(i);
// render from last good point to one before this bad point
if (id - lastGood > 2)
{
painter->DrawMarkers(this->MarkerStyle, false,
points + 2 * (lastGood + 1),
id - lastGood - 1,
colors ? colors + 4 * (lastGood + 1) : 0,
nColorComponents);
}
lastGood = id;
}
}
else
{
painter->DrawMarkers(this->MarkerStyle, false, this->Points);
// draw all of the points
painter->DrawMarkers(this->MarkerStyle, false,
points, this->Points->GetNumberOfPoints(),
colors, nColorComponents);
}
}
......@@ -672,6 +715,22 @@ void vtkPlotPoints::FindBadPoints()
}
}
// add points from the ValidPointMask
if (this->ValidPointMask)
{
for (vtkIdType i = 0; i < n; i++)
{
if (this->ValidPointMask->GetValue(i) == 0)
{
this->BadPoints->InsertNextValue(i);
}
}
}
// sort bad points
std::sort(this->BadPoints->GetPointer(0),
this->BadPoints->GetPointer(this->BadPoints->GetNumberOfTuples()));
if (this->BadPoints->GetNumberOfTuples() == 0)
{
this->BadPoints->Delete();
......
......@@ -34,6 +34,7 @@
#include "vtkNew.h" // For ivars
#include "vtkRenderingCoreEnums.h" // For marker enum
class vtkCharArray;
class vtkContext2D;
class vtkTable;
class vtkPoints2D;
......@@ -147,6 +148,11 @@ public:
vtkGetMacro(MarkerSize, float);
vtkSetMacro(MarkerSize, float);
// Description:
// Get/set the valid point mask array name.
vtkGetMacro(ValidPointMaskName, vtkStdString)
vtkSetMacro(ValidPointMaskName, vtkStdString)
//BTX
protected:
vtkPlotPoints();
......@@ -190,6 +196,15 @@ protected:
// pair that has an infinity, -infinity or not a number value.
vtkIdTypeArray* BadPoints;
// Description:
// Array which marks valid points in the array. If NULL (the default), all
// points in the input array are considered valid.
vtkCharArray* ValidPointMask;
// Description:
// Name of the valid point mask array.
vtkStdString ValidPointMaskName;
// Description:
// The point cache is marked dirty until it has been initialized.
vtkTimeStamp BuildTime;
......
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