[vtkusers] Memory bug when cutting vtkPointSet/PolyData using vtkCutter?

Julia Schnabel j.schnabel at ucl.ac.uk
Thu May 11 05:26:38 EDT 2006


Hello,

I have been trying to find any info on this in the vk digest, but in vain.
Maybe someone could point me to the probably *very* obvious thing that I'm doing wrong.

When cutting a vtkPolyData repeatedly, the program will dramatically increase in memory
causing an "Abort". I'm using vtk 4.4.2, compiled with the VTK_DEBUG_LEAKS check on,
and I've also been using the DebugOn() methods, without gaining any more insight.

Here is a snippet of code - when calling this method repeately, the memory explodes
(I've also been trying to declare plane and cutter as static):

Thank you for any hints!
Julia

-- begin code snippet

void myViewer::DrawObject(vtkPolyData *points)
{
   if (points != NULL) {

     int i, j;
     double point[3], bounds[6], origin[3], normal[3];

     // Allocate vtk classes
     vtkPlane *plane   = vtkPlane::New();
     vtkCutter *cutter = vtkCutter::New();

     // Find out where to cut
     points->GetCenter(origin);
     points->GetBounds(bounds);
     switch (_viewerMode) {
     case Viewer_XY:
       origin[2] = (int)round(image->GetOrigin()._z);
       normal[0] = 0;
       normal[1] = 0;
       normal[2] = (-origin[1]*(bounds[0]-origin[0]) +
                    origin[0]*(bounds[1]-origin[1]));
       break;
     case Viewer_YZ:
       origin[0] = (int)round(image->GetOrigin()._x);
       normal[0] = (-origin[2]*(bounds[1]-origin[1]) +
                    origin[1]*(bounds[2]-origin[2]));
       normal[1] = 0;
       normal[2] = 0;
       break;
     case Viewer_XZ:
       origin[1] = (int)round(image->GetOrigin()._y);
       normal[0] = 0;
       normal[1] = (-origin[2]*(bounds[0]-origin[0]) +
                    origin[0]*(bounds[2]-origin[2]));
       normal[2] = 0;
       break;
     }

     // Set up plane and cutter
     plane->SetOrigin(origin);
     plane->SetNormal(normal);
     cutter->SetCutFunction(plane);
     cutter->SetInput(points);

     // Reslice object
     cutter->Modified();
     cutter->Update();

     // Loop over cells to get nodes
     for (i = 0; i < cutter->GetOutput()->GetNumberOfCells(); i++) {

       // Get pointIds from cell
       vtkIdList *ids = cutter->GetOutput()->GetCell(i)->GetPointIds();

       for (j = 0; j < ids->GetNumberOfIds(); j++) {

         // Get point from cell
         cutter->GetOutput()->GetPoints()->GetPoint(ids->GetId(j), point);

	// Print only point for now
	cerr << "Node " << j << " from cell " << i << " : "
              << point[0] << " " << point[1] << " " << point[2] << endl;
       }
     }

     // Be good
     plane->Delete();
     cutter->Delete();
   }
}


-- end code snippet



More information about the vtkusers mailing list