[vtkusers] Using VTK Point Locator

Donald Johnson nalkar at earthlink.net
Fri Dec 7 02:02:45 EST 2007


Can anyone tell me what i am doing wrong here? Im trying to filter a  
very dense set of poly lines so that it can be viewed. My plan was to  
only add new poly lines that had no points close to the points of  
lines that had already been added to the output.  To do this  i  
created a vtkPointLocator and initialized it with a vtkPoints that  
contained only the points from the first line. I would then check the  
points of every other line and if none of the points where to close i  
would add them to the vtkPoints, rebuild the locator and continue.  
The problem is the locator always return the id -1 for the nearest  
point even when i check the first line, where it should find exact  
matches.



	// get the info objects
	vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
	vtkInformation *outInfo = outputVector->GetInformationObject(0);

	// get the input and ouptut
	vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->
		Get(vtkDataObject::DATA_OBJECT()));
	vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->
		Get(vtkDataObject::DATA_OBJECT()));

	vtkPoints   *inPts = input->GetPoints();
	vtkIdType   numPts = input->GetNumberOfPoints();
	
	vtkPoints *outPts = vtkPoints::New();
	outPts->Allocate(numPts);
	int n = outPts->GetNumberOfPoints();
	

	
	vtkPointData *inputPD = input->GetPointData();
	vtkCellData  *inputCD = input->GetCellData();
	
	
	vtkDebugMacro(<<"Beginning Line Spacing clean");
	if ( (numPts < 1) || (inPts == NULL ) )
	{
		vtkDebugMacro(<<"No data points");
		return 1;
     }

	vtkCellArray* inLines = input->GetLines();
	vtkIdType numLines = inLines->GetNumberOfCells();
	
	vtkCellArray* outLines = vtkCellArray::New();
	outLines->Allocate(numLines);
	
	
	if ( (numLines < 1) || (inLines == NULL ) )
	{
		vtkDebugMacro(<<"No data lines");
		return 1;
     }
	
	vtkIdType inCellID = 0, newId;
	int i, j;
	vtkIdType ptId;
	vtkIdType npts = 0;
	vtkIdType *pts = 0;
	double x[3];
	double newx[3];
	double d2;
	double bounds[6];
	vtkIdType insertPointId;
	vtkIdType insertCellId;
	
	// seed the output points and lines with the first line
	inLines->GetCell(0,npts,pts);
	for(i = 0; i < npts; ++i )
	{
		inPts->GetPoint(pts[i],x);
		insertPointId = outPts->InsertNextPoint(x);
	}
	insertCellId = outLines->InsertNextCell(npts,pts);
	
	
	// calculate the bounds of the input data set
	input->ComputeBounds();
	input->GetBounds(bounds);	
	// set the locator to insert into out points and use the input  
datasets bounds
	Locator->InitPointInsertion(outPts,bounds);
	Locator->BuildLocator();
	
	if ( !this->GetAbortExecute() && inLines->GetNumberOfCells() > 0 )
	{
		// loop should be from 1 to GetNumberOfCells -1
		for(i = 0; i < inLines->GetNumberOfCells(); ++i)
		{
			bool pass = true;
			for( j = 0; j < npts; ++j )
			{
				inPts->GetPoint(pts[j],x);
				ptId = Locator->FindClosestPoint(x); // ptId is always -1
				
				if ( ptId != -1 )
				{
					pass = false;
				}
			}
			
			if ( pass )
			{
				// add the points to the output points
				// add the line to output lines
				
			}
		}
	} 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071207/dc9ddf7d/attachment.htm>


More information about the vtkusers mailing list