[vtk-developers] vtkCellLinks reusability

lucantiga at softhome.net lucantiga at softhome.net
Mon Mar 10 14:02:10 EST 2003


Hey developers,
 some time ago I posted this message on the users list but I got no 
answer. It's not a crucial bug but it made me lose some time.

vtkCellLinks::Reset() consistently with the behaviour in other arrays,
sets MaxId to -1 without freeing the memory. This is handy in iterations,
because it allows you to reuse the class without deallocating and
reallocating the Array. The problem is that vtkCellLinks::Reset() does 
not initialize the elements of Array, and BuildLinks starts by calling
IncrementLinkCount (which increments the elements of Array) for each point
in cell. The result is that if you reuse vtkCellLinks (for example
supplying another Connectivity cell array) after calling Reset(), your
previous links will still be there, and the link count will start from 
the ncells of the previous links.
A possible fix is the following

void vtkCellLinks::Reset()
{
  for (vtkIdType i=0; i <= MaxId; i++)
    {
    this->Array[i].ncells = 0;
    delete[] this->Array[i].cells;
    this->Array[i].cells = NULL;
    }
  this->MaxId = -1;
}

Alternatively Reset() colud be left as it is, and the above for cycle 
could be placed before the link count in BuildLinks (both overloaded 
versions)
Thanks

luca









More information about the vtk-developers mailing list