[vtkusers] Best vtkPolyData comparison approach

Miroslav Drahos mdrahos at thinksurgical.com
Mon Jun 15 16:59:14 EDT 2015

When you are comparing two sets of points, you might benefit from sorting them first.

You might want to consider wrapping a 3D point in a custom struct, e.g. Pt3D so that you can define a strict ordering, e.g. compare z-values first, then y-, then x-.
Then you would define a == functor (or operator) that would compare two points (here you would use the desired tolerance).
With this prep you could use two std containers (e.g. std::vector<Pt3D>), one for each set, run std::sort on them using the defined ordering and compare the two containers with std::equal using your custom == comparison.


From: vtkusers [vtkusers-bounces at vtk.org] On Behalf Of Muhammad Nour [mnour.ai at hotmail.com]
Sent: Monday, June 15, 2015 1:01 PM
To: vtkusers at vtk.org
Subject: [vtkusers] Best vtkPolyData comparison approach

Hi all,

I am using MS visual studio 2008 and vtk 5.10

I want compare two vtkPolyData objects, so I have written below function:
bool Matched(vtkPolyData* data1, vtkPolyData* data2, double tolerance)
if (data1 && data2) // Initial check
int pointCount1 = data1->GetNumberOfPoints(); // Get number of data1's point number
int pointCount2 = data2->GetNumberOfPoints(); // Get number of data2's point number

if (pointCount1 == pointCount2) // Check numbers
vtkPointLocator* locator = vtkPointLocator::New(); // Create new locator for data2

for (int i = 0; i < pointCount1; i++) // Loop each point from data1 and compare with closest point from data2
int pointID;
double point1[3], point2[3];
data1->GetPoint(i, point1); // Get point from data1
pointID = locator->FindClosestPoint(point1); // Get closest point ID from data2
data2->GetPoint(pointID, point2);

if (abs(point1[0] - point2[0]) > tolerance || abs(point1[2] - point2[2]) > tolerance) // Check difference for x and z coordinates
locator->Delete(); // Free memory

return false; // No need for check other points

locator->Delete(); // Free memory

return true;
return false;

Please note that I ignore y coordinate.

Any better suggestion will be appreciated.

Thank you all

More information about the vtkusers mailing list