Commit b65dcc3c authored by Marcus D. Hanwell's avatar Marcus D. Hanwell

Fix bad point detection for large double values

The bad point detection was incorrectly detecting large double values
as bad, use templated code that works with the original type and a set
to ensure a sorted, unique list of bad points is generated. Modified
the test to use a second corner and one series that is very large to
test the functionality.

Change-Id: I08322a0b3fd728e496d2d5f1f1901054afe4eb7d
parent b8fa3b82
......@@ -56,8 +56,9 @@ int TestLinePlotDouble(int, char *[])
table->SetValue(i, 0, i * inc);
table->SetValue(i, 1, 1.0e-80 * cos(i * inc - 1.0) * 1.0e-8);
table->SetValue(i, 2, 1.0e-80 * sin(i * inc) * 1.0e-8);
table->SetValue(i, 3, 1.0e-80 * sin(i * inc - 1.0) * 1.0e-8);
table->SetValue(i, 3, 1.0e80 * sin(i * inc - 1.0));
}
table->SetValue(66, 2, vtkMath::Nan());
table->SetValue(4, 3, vtkMath::Inf());
// Add multiple line plots, setting the colors etc
......@@ -73,6 +74,7 @@ int TestLinePlotDouble(int, char *[])
line->SetInputData(table.GetPointer(), 0, 3);
line->SetColor(0, 0, 255, 255);
line->SetWidth(4.0);
chart->SetPlotCorner(line, 1);
// Render the scene and compare the image to a reference image
view->GetRenderWindow()->SetMultiSamples(0);
......
8f97512797f16d755285baf17d4cd838
6f9f5b172bfe165a145dc5b54db4102e
c609ecd12c80d3dcfdf0a43cc589db4a
3adab4f70db3f1a43d81d03cceb12925
......@@ -35,6 +35,7 @@
#include <vector>
#include <algorithm>
#include <limits>
#include <set>
// PIMPL for STL vector...
struct vtkIndexedVector2f
......@@ -497,6 +498,19 @@ bool vtkPlotPoints::SelectPointsInPolygon(const vtkContextPolygon &polygon)
//-----------------------------------------------------------------------------
namespace {
// Find any bad points in the supplied array.
template<typename T>
void SetBadPoints(T *data, vtkIdType n, std::set<vtkIdType> &bad)
{
for (vtkIdType i = 0; i < n; ++i)
{
if (vtkMath::IsInf(data[i]) || vtkMath::IsNan(data[i]))
{
bad.insert(i);
}
}
}
// Calculate the bounds from the original data.
template<typename A>
void ComputeBounds(A *a, int n, double bounds[2])
......@@ -832,27 +846,29 @@ void vtkPlotPoints::CalculateLogSeries()
void vtkPlotPoints::FindBadPoints()
{
// This should be run after CalculateLogSeries as a final step.
float* data = static_cast<float*>(this->Points->GetVoidPointer(0));
vtkIdType n = this->Points->GetNumberOfPoints();
if (!this->BadPoints)
{
this->BadPoints = vtkIdTypeArray::New();
}
else
{
this->BadPoints->SetNumberOfTuples(0);
}
// Scan through and find any bad points.
for (vtkIdType i = 0; i < n; ++i)
vtkTable *table = this->Data->GetInput();
vtkDataArray *array[2] = { 0, 0 };
if (!this->GetDataArrays(table, array))
{
vtkIdType p = 2*i;
if (vtkMath::IsInf(data[p]) || vtkMath::IsInf(data[p+1]) ||
vtkMath::IsNan(data[p]) || vtkMath::IsNan(data[p+1]))
return;
}
std::set<vtkIdType> bad;
if (!this->UseIndexForXSeries)
{
switch(array[0]->GetDataType())
{
this->BadPoints->InsertNextValue(i);
vtkTemplateMacro(
SetBadPoints(static_cast<VTK_TT*>(array[0]->GetVoidPointer(0)), n, bad));
}
}
switch(array[1]->GetDataType())
{
vtkTemplateMacro(
SetBadPoints(static_cast<VTK_TT*>(array[1]->GetVoidPointer(0)), n, bad));
}
// add points from the ValidPointMask
if (this->ValidPointMask)
......@@ -861,16 +877,29 @@ void vtkPlotPoints::FindBadPoints()
{
if (this->ValidPointMask->GetValue(i) == 0)
{
this->BadPoints->InsertNextValue(i);
bad.insert(i);
}
}
}
// sort bad points
std::sort(this->BadPoints->GetPointer(0),
this->BadPoints->GetPointer(this->BadPoints->GetNumberOfTuples()));
if (this->BadPoints->GetNumberOfTuples() == 0)
// If there are bad points copy them, if not ensure the pointer is null.
if (bad.size() > 0)
{
if (!this->BadPoints)
{
this->BadPoints = vtkIdTypeArray::New();
}
else
{
this->BadPoints->SetNumberOfTuples(0);
}
for (std::set<vtkIdType>::const_iterator it = bad.begin();
it != bad.end(); ++it)
{
this->BadPoints->InsertNextValue(*it);
}
}
else if (this->BadPoints)
{
this->BadPoints->Delete();
this->BadPoints = NULL;
......
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