[vtkusers] Bug in vtkDataArrayTemplate.txx?

David C Thompson dcthomp at sandia.gov
Thu Sep 20 21:33:53 EDT 2007


Hi all,

	I believe vtkDataArrayTemplate<T>::DataChanged() should invoke
this->Modified(). Otherwise, RemoveTuple, SetArray, Initialize, and
several other methods will not result in the MTime of the array being
updated. Since this MTime is used when comparing the array modification
time to the cached component ranges, it can lead to the array bounds
being incorrect. I have verified this behavior with a modified
Common/Testing/Cxx/TestDataArray.cxx (attached).

	If no one objects, I will add the call to Modified() and check in the
modified version of Common/Testing/Cxx/TestDataArray.cxx to prevent
regressions.

	David
-------------- next part --------------
#include "vtkIntArray.h"
#include "vtkDoubleArray.h"

int TestDataArray(int,char *[])
{
  double range[2];
  vtkIntArray* array = vtkIntArray::New();
  array->GetRange( range, 0 );
  if ( range[0] != VTK_DOUBLE_MAX || range[1] != VTK_DOUBLE_MIN )
    {
    cerr << "Getting range of empty array failed, min: " << range[0] << " max: " << range[1] << "\n";
    array->Delete();
    return 1;
    }
  int cc;
  for ( cc = 0; cc < 10; cc ++ )
    {
    array->InsertNextTuple1(cc);
    }
  array->RemoveFirstTuple();
  array->RemoveTuple(3);
  array->RemoveTuple(4);
  array->GetRange( range, 0 );
  if ( range[0] != 1. || range[1] != 9. )
    {
    cerr << "Getting range of array {1,2,3,5,7,8,9} failed, min: " << range[0] << " max: " << range[1] << "\n";
    array->Delete();
    return 1;
    }
  array->RemoveLastTuple();
  array->GetRange( range, 0 );
  if ( range[0] != 1. || range[1] != 8. )
    {
    cerr << "Getting range of array {1,2,3,5,7,8} failed, min: " << range[0] << " max: " << range[1] << "\n";
    array->Delete();
    return 1;
    }
  int ca[] = { 1, 2, 3, 5, 7, 8 };
  cout << "Array:";
  for ( cc = 0; cc < array->GetNumberOfTuples(); ++cc )
    {
    if ( array->GetTuple1(cc) != ca[cc] )
      {
      cerr << "Problem with array: " << array->GetTuple1(cc) << " <> " << ca[cc] << endl;
      return 1;
      }
    cout << " " << array->GetTuple1(cc);
    }
  cout << endl;
  array->Delete();

  vtkDoubleArray* farray = vtkDoubleArray::New();
  farray->SetNumberOfComponents(3);
  for ( cc = 0; cc < 10; cc ++ )
    {
    farray->InsertNextTuple3( cc + 0.1, cc + 0.2, cc + 0.3);
    }
  farray->RemoveFirstTuple();
  farray->RemoveTuple(3);
  farray->RemoveTuple(4);
  farray->RemoveLastTuple();
  cout << "Array:";
  for ( cc = 0; cc < farray->GetNumberOfTuples(); ++cc )
    {
    double* fa = farray->GetTuple3(cc);
    double fc[3];
    fc[0] = ca[cc] + .1;
    fc[1] = ca[cc] + .2;
    fc[2] = ca[cc] + .3;
    for (int i = 0; i < 3; i++)
      {
      if (fa[i] != fc[i])
        {
        cerr << "Problem with array: " << fa[i] << " <> " << fc[i] << endl;
        return 1;
        }
      }
    cout << " " << fa[0] << "," << fa[1] << "," << fa[2];
    }
  cout << endl;
  farray->Delete();
  return 0;
}


More information about the vtkusers mailing list