Commit bc6eead6 authored by David Partyka's avatar David Partyka
Browse files

BUG: PIMPL the sorted vector, use that to cache.

Use a PIMPLed std::vector, and use that to cache the sorted points.

Conflicts:

	Charts/vtkPlotLine.cxx
parent 4622ecd6
......@@ -38,7 +38,15 @@
#include "vtkstd/vector"
#include "vtkstd/algorithm"
vtkCxxRevisionMacro(vtkPlotLine, "1.29");
// PIMPL for STL vector...
class vtkPlotLine::VectorPIMPL : public vtkstd::vector<vtkVector2f>
{
public:
VectorPIMPL(vtkVector2f* start, vtkVector2f* end)
: vtkstd::vector<vtkVector2f>::vector(start, end)
{
}
};
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlotLine);
......@@ -64,11 +72,7 @@ vtkPlotLine::~vtkPlotLine()
this->Points->Delete();
this->Points = NULL;
}
if (this->Sorted)
{
this->Sorted->Delete();
this->Sorted = NULL;
}
delete this->Sorted;
if (this->BadPoints)
{
this->BadPoints->Delete();
......@@ -448,26 +452,24 @@ bool vtkPlotLine::GetNearestPoint(const vtkVector2f& point,
return false;
}
// Sort the data if it has not been done already...
if (!this->Sorted)
{
this->Sorted = vtkPoints2D::New();
}
// Sort the data if necessary
if (this->Sorted->GetNumberOfPoints() == 0)
{
this->Sorted->DeepCopy(this->Points);
vtkVector2f* data =
static_cast<vtkVector2f*>(this->Sorted->GetVoidPointer(0));
vtkstd::vector<vtkVector2f> v(data, data+n);
vtkstd::sort(v.begin(), v.end(), compVector2fX);
static_cast<vtkVector2f*>(this->Points->GetVoidPointer(0));
this->Sorted = new VectorPIMPL(data, data+n);
vtkstd::sort(this->Sorted->begin(), this->Sorted->end(), compVector2fX);
}
// Set up our search array, use the STL lower_bound algorithm
vtkVector2f* data =
static_cast<vtkVector2f*>(this->Sorted->GetVoidPointer(0));
vtkstd::vector<vtkVector2f> v(data, data+n);
vtkstd::vector<vtkVector2f>::iterator low;
VectorPIMPL::iterator low;
VectorPIMPL &v = *this->Sorted;
cout << "Sorted array: " << endl;
for (size_t i = 0; i < v.size(); ++i)
{
cout << v[i].X() << "\t" << v[i].Y() << endl;
}
// Get the lowest point we might hit within the supplied tolerance
vtkVector2f lowPoint(point.X()-tol.X(), 0.0f);
......@@ -589,7 +591,8 @@ bool vtkPlotLine::UpdateTableCache(vtkTable *table)
this->Points->Modified();
if (this->Sorted)
{
this->Sorted->SetNumberOfPoints(0);
delete this->Sorted;
this->Sorted = 0;
}
this->BuildTime.Modified();
return true;
......
......@@ -122,7 +122,8 @@ protected:
// Description:
// Sorted points, used when searching for the nearest point.
vtkPoints2D* Sorted;
class VectorPIMPL;
VectorPIMPL* Sorted;
// Description:
// An array containing the indices of all the "bad points", meaning any x, y
......
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