[vtkusers] Bug (?? + solution) in vtkPolyData::GetCell(int cellId, vtkGeneri cCell *cell)
Schaap, J.A. (LKEB)
J.A.Schaap at lumc.nl
Wed Feb 28 10:45:09 EST 2001
Hi,
I'm not sure if this is a bug, or if my filter generates corrupt polydata
output...
But, I think the following piece of code is not correct. (Copied from
vtkPolyData.cxx dated 2-2-2001)
//-------------------------
//Begin Code snippet
//-------------------------
void vtkPolyData::GetCell(int cellId, vtkGenericCell *cell)
{
int i, loc, numPts, *pts;
unsigned char type;
float x[3];
if ( !this->Cells )
{
this->BuildCells();
}
type = this->Cells->GetCellType(cellId);
loc = this->Cells->GetCellLocation(cellId);
switch (type)
{
case VTK_VERTEX:
cell->SetCellTypeToVertex();
this->Verts->GetCell(loc,numPts,pts);
break;
case VTK_POLY_VERTEX:
cell->SetCellTypeToPolyVertex();
this->Verts->GetCell(loc,numPts,pts);
cell->PointIds->SetNumberOfIds(numPts); //reset number of points
cell->Points->SetNumberOfPoints(numPts);
break;
case VTK_LINE:
cell->SetCellTypeToLine();
this->Lines->GetCell(loc,numPts,pts);
break;
case VTK_POLY_LINE:
cell->SetCellTypeToPolyLine();
this->Lines->GetCell(loc,numPts,pts);
cell->PointIds->SetNumberOfIds(numPts); //reset number of points
cell->Points->SetNumberOfPoints(numPts);
break;
case VTK_TRIANGLE:
cell->SetCellTypeToTriangle();
this->Polys->GetCell(loc,numPts,pts);
break;
case VTK_QUAD:
cell->SetCellTypeToQuad();
this->Polys->GetCell(loc,numPts,pts);
break;
case VTK_POLYGON:
cell->SetCellTypeToPolygon();
this->Polys->GetCell(loc,numPts,pts);
cell->PointIds->SetNumberOfIds(numPts); //reset number of points
cell->Points->SetNumberOfPoints(numPts);
break;
case VTK_TRIANGLE_STRIP:
cell->SetCellTypeToTriangleStrip();
this->Strips->GetCell(loc,numPts,pts);
cell->PointIds->SetNumberOfIds(numPts); //reset number of points
cell->Points->SetNumberOfPoints(numPts);
break;
default:
cell->SetCellTypeToEmptyCell();
}
for (i=0; i < numPts; i++)
{
cell->PointIds->SetId(i,pts[i]);
this->Points->GetPoint(pts[i], x);
cell->Points->SetPoint(i, x);
}
}
//-------------------------
//End Code snippet
//-------------------------
If the variable cell is set to EmptyCell (in the default case in the switch)
then it crashes in the following for-loop.
The solution is to either test is the cell is an EmptyCell before the for
loop, or to set numPts = 0 in the default case.
Best Regards, Jorrit.
--
Jorrit Schaap
Division of Image Processing
Leiden University Medical Center
+31 71 5266206
More information about the vtkusers
mailing list