[vtkusers] Bug in vtkUnstructuredGrid::GetListOfUniqueCellTypes

Roman Putanowicz putanowi at iecn.u-nancy.fr
Sat Feb 8 09:43:59 EST 2003


Hi All, 

I am using VTK 4.0 but also checked the CVS and the code is 
the same. The function vtkUnstructuredMesh::GetListOfUniqueCellTypes
should return the array of unique cell types but it does not.

I attached the simple program and data to show the case.

Below is my fix. The original code was not checking the whole
'uniqueTypes' and thus the bug. From comparing original code
and the fix should bee clear what was wrong. 

Cheers

Romek


void vtkUnstructuredGrid::GetListOfUniqueCellTypes(vtkUnsignedCharArray *uniqueTypes)
{
  unsigned char type;
  unsigned char found;

  if (this->Types)
    {
    type = Types->GetValue(0);
    uniqueTypes->InsertNextValue(type);

    for (int cellId = 0; cellId < this->GetNumberOfCells(); cellId++)
      {
      type = Types->GetValue(cellId);
      found = 0;
      for (int i = 0; i < uniqueTypes->GetMaxId()+1; i++)
        {
        if (type == uniqueTypes->GetValue(i))
          {
          found = 1;
          break; //cell is not unique, return control to outer loop
          }
        }
      if (found == 0)
        { // cell type was not found on the uniqueTypes list so add it
          uniqueTypes->InsertNextValue(type);
        }
      }
    }
}

-------------- next part --------------
#include <iostream>
#include "vtkRenderWindowInteractor.h"
#include "vtkUnstructuredGridReader.h"

using namespace std;

int main( int argc, char *argv[] )
{
  if (argc < 2) 
  {
    cerr << "Usage: " << argv[0] << " vtk_file" << endl;
    cerr << "        vtk_file - file with unstructured grid" << endl;
    exit(1); 
  }

  vtkUnstructuredGridReader *reader = vtkUnstructuredGridReader::New();
     reader->SetFileName(argv[1]);
     reader->Update();

  vtkUnstructuredGrid *ugrid = reader->GetOutput();

  vtkIdType nTypes;
  vtkUnsignedCharArray *cellTypes = vtkUnsignedCharArray::New();

  ugrid->GetListOfUniqueCellTypes(cellTypes);

  nTypes = cellTypes->GetNumberOfTuples();

  cout << "Number of cell types : " << nTypes << endl;
 
  cout << "Cells types: \n";
  for (vtkIdType i=0; i<nTypes; i++) 
  {
    cout << (int)cellTypes->GetValue(i) << endl; 
  } 

  cellTypes->Delete();
  reader->Delete();
  return 0;
} /* end of main */
-------------- next part --------------
# vtk DataFile Version 4.0
2D scalar data
ASCII
           
DATASET UNSTRUCTURED_GRID
POINTS 5 float 
0 0 0 
1 0 0
1 1 0
0 1 0
0 0 1

CELLS 4 18
3 0 1 2
3 0 2 3
4 0 1 2 4
4 0 2 3 4


CELL_TYPES 4 
5
5
10
10

POINT_DATA 5
SCALARS scalars float 1
LOOKUP_TABLE default
0 0 2 1 8


More information about the vtkusers mailing list