[vtkusers] Best vtkPolyData comparison approach

Muhammad Nour mnour.ai at hotmail.com
Mon Jun 15 16:01:15 EDT 2015


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				locator->SetDataSet(data2);				locator->BuildLocator();
				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

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150615/cb8fbe0f/attachment.html>


More information about the vtkusers mailing list