[vtkusers] Discovered And Fixed Bug In vtkDecimatePolylineFilter

Donny donnyz at charter.net
Sat Dec 4 08:55:34 EST 2010


Hello. I have discovered and fixed a bug in vtkDecimatePolylineFilter. The
bug occurs if you have a mixture of lines with 3 or more points and also
lines that are only 2 points.

 

The following is in the RequestData function:

 

for (cellId=0, inputLines->InitTraversal();
inputLines->GetNextCell(npts,pts); cellId++)

    {

    if ( npts < 3 )

      {

      newId = newLines->InsertNextCell(npts,pts);

      outCD->CopyData(inCD,cellId,newId);

      for (i=0; i < npts; i++)

        {

        newId = newPts->InsertNextPoint(inputPoints->GetPoint(pts[i]));

        outPD->CopyData(inPD,pts[i],newId);

        }

      continue; //skip the rest

      }

The call to newLines->InsertNextCell(npts,pts); is the incorrect overload to
call since we are inserting new points in the loop that follows the call.

This would work ok if we only had lines that were 2 points, but since we are
also decimating and then inserting points for lines that have 3 or more
points the "pts" argument is incorrect for the new polydata.

 

I have tested the code that produced the bug with the following fixes and it
works as intended.

 

Here is the fixed code with modified lines commented with red:

 

for (cellId=0, inputLines->InitTraversal();
inputLines->GetNextCell(npts,pts); cellId++)

    {

    if ( npts < 3 )

      {

      newId = newLines->InsertNextCell(npts); // Modified to call different
overload

      outCD->CopyData(inCD,cellId,newId);

      for (i=0; i < npts; i++)

        {

        newId = newPts->InsertNextPoint(inputPoints->GetPoint(pts[i]));

        newLines->InsertCellPoint(newId); // Added to correctly assign ID's

        outPD->CopyData(inPD,pts[i],newId);

        }

      continue; //skip the rest

      }

I do not know how to submit this to git, or if this is the correct procedure
for submitting bugs, so if somebody could kindly make the changes and submit
I would be greatful.

 

Thanks.

 

Donny Zimmerman

donnyz at charter.net

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101204/6dba4bbc/attachment.htm>


More information about the vtkusers mailing list