[vtkusers] Very important discovery\mistake !

Sebastien Auclair sxa at fluent.com
Tue Jun 3 12:06:34 EDT 2003


Calling "Delete" on a vtkObject doesn't delete it.
This is something that i forgot to watch ! (i.e. Reference counting )

We use a set of filters to generate a polydata that we want to keep. But we
no longer need the filters so we were deleting them.
We've just realized that these filters were never deleted ! and there are
thousands of them...

What would be the right approach to deal deleting reference counted
instances ...
Assuming that we are doing something like this :


###########################################
SomeClass::CreateHexPolyData ()
{
  vtkFloatArray *xCoords = vtkFloatArray::New();
 vtkFloatArray *yCoords = vtkFloatArray::New();
 vtkFloatArray *zCoords = vtkFloatArray::New();

 xCoords->InsertNextValue(0);
 xCoords->InsertNextValue(m_length);

 yCoords->InsertNextValue(0);
 yCoords->InsertNextValue(m_height);

 zCoords->InsertNextValue(0);
 zCoords->InsertNextValue(m_width);


 vtkRectilinearGrid * rgrid = vtkRectilinearGrid::New();
    rgrid->SetDimensions(2,2,2);
    rgrid->SetXCoordinates(xCoords);
    rgrid->SetYCoordinates(yCoords);
    rgrid->SetZCoordinates(zCoords);


 vtkGeometryFilter* geom = vtkGeometryFilter::New();
  geom->SetInput(rgrid);
  geom->SetExtent(0,1, 0,1, 0,1);
 geom->Update();

 vtkTransform* translate = vtkTransform::New();
 translate->PostMultiply();
 translate->Translate(minX, minY, minZ);
 translate->Update();

 vtkTransformPolyDataFilter* trans = vtkTransformPolyDataFilter::New();
 trans->SetTransform(translate);
 trans->SetInput(geom->GetOutput());
 trans->Update();


 m_polydata = vtkPolyData::New();
 m_polydata->DeepCopy(trans->GetOutput());
 m_polydata->Update();


 m_normal = vtkPolyDataNormals::New();
 m_normal->SetInput(m_polydata);
 m_normal->Update();

 geom->Delete();
 rgrid->Delete();
 xCoords->Delete();
 yCoords->Delete();
 zCoords->Delete();
 translate->Delete();
 trans->Delete();

}

##########################################

m_polydata and m_normal are the values we want to keep but we must get rid
of the filters and everything else !
Again, what would the correct approach be to make sure none of those filters
remains.
Thanks for any help !
________________________________________________
Seb





More information about the vtkusers mailing list