[vtkusers] vtkDataSet::GetCell(vtkIdType) with multiple cell objects

Sunrise helios.corona at gmail.com
Fri Jan 11 00:15:00 EST 2013


I have problem of using GetCell  in vtkDataSet. Consider the following 
methods:

Method 1- vtkCell * = vtkDataSet->GetCell(vtkIdType)         // fails if 
I declare more than one cell
Method 2- vtkDataSet->GetCell(vtkidType,vtkGenericCell)   // this one 
works well.

By comparing two overloads of GetCell, the first one fails if I declare 
two cell objects, while second method is working fine. Here are examples 
of both, assume I want to get two cells with different CellIds:

// Method 1

vtkSmartPointer<vtkTriangle> Cell1 = 
vtkTriangle::SafeDownCast(MyDataSet->GetCell(CellId1));
vtkSmartPointer<vtkTriangle> Cell2 = 
vtkTriangle::SafeDownCast(MyDataSet->GetCell(CellId2));

// now see the problem here

if(Cell1 == Cell2)
{
     std::cout << "They should be different!!" << std::endl;
}

Or by printing Cell1->GetPointId(SomeIdHere), we can see both Cell1 and 
Cell2 are the same. Why?

// Method 2

vtkSmartPointer<vtkGenericCell> Cell1 = 
vtkSmartPointer<vtkGenericCell>::New();
vtkSmartPointer<vtkGenericCell> Cell2 = 
vtkSmartPointer<vtkGenericCell>::New();

MyDataSet->GetCell(CellId1,GenericCell1);
MyDataSet->GetCell(CellId2,GenericCell2);

Cell1->SetCellTypeToTriangle();
Cell2->SetCellTypeToTriangle();

Since the second method copies cell by value to allocated memory on 
stack, it works fine.

But I would like to know why the first method gets into the problem? and 
how to avoid it? Using first method is preferred since I do not have to 
declare Generic cell instead of Triangle, and also I do not have to copy 
cell from data to an other object.

Thanks.



More information about the vtkusers mailing list