[vtkusers] vtkUnstructuredGrid - how to detect if a cell as neighbors?
Teresa Azevedo
dce06003 at fe.up.pt
Tue Oct 27 10:46:15 EDT 2009
Hi all.
I would like to extract the boundary cells of an unstructured grid,
that is, those who have at least one face with no neighbors.
Here is a test code, that builds an unstructured grid, with two voxels
that share one face. When I check if a cell of the grid has neighbors,
the code prompts a message box. Unfortunately, when I run it, I never
get the message.
Can someone tell me what I am doing wrong?
vtkUnstructuredGrid* aVoxelGrid = vtkUnstructuredGrid::New();
aVoxelGrid->Allocate(2, 2);
vtkPoints* vPts = vtkPoints::New();
vPts->SetNumberOfPoints(16);
vPts->InsertPoint( 0, 0, 0, 0);
vPts->InsertPoint( 1, 1, 0, 0);
vPts->InsertPoint( 2, 0, 1, 0);
vPts->InsertPoint( 3, 1, 1, 0);
vPts->InsertPoint( 4, 0, 0, 1);
vPts->InsertPoint( 5, 1, 0, 1);
vPts->InsertPoint( 6, 0, 1, 1);
vPts->InsertPoint( 7, 1, 1, 1);
vtkVoxel* vl = vtkVoxel::New();
vl->GetPointIds()->SetId(0, 0);
vl->GetPointIds()->SetId(1, 1);
vl->GetPointIds()->SetId(2, 2);
vl->GetPointIds()->SetId(3, 3);
vl->GetPointIds()->SetId(4, 4);
vl->GetPointIds()->SetId(5, 5);
vl->GetPointIds()->SetId(6, 6);
vl->GetPointIds()->SetId(7, 7);
aVoxelGrid->InsertNextCell(VTK_VOXEL, vl->GetPointIds());
vPts->InsertPoint( 8, 0, 0, 1);
vPts->InsertPoint( 9, 1, 0, 1);
vPts->InsertPoint( 10, 0, 1, 1);
vPts->InsertPoint( 11, 1, 1, 1);
vPts->InsertPoint( 12, 0, 0, 2);
vPts->InsertPoint( 13, 1, 0, 2);
vPts->InsertPoint( 14, 0, 1, 2);
vPts->InsertPoint( 15, 1, 1, 2);
vtkVoxel* v2 = vtkVoxel::New();
v2->GetPointIds()->SetId(0, 8);
v2->GetPointIds()->SetId(1, 9);
v2->GetPointIds()->SetId(2, 10);
v2->GetPointIds()->SetId(3, 11);
v2->GetPointIds()->SetId(4, 12);
v2->GetPointIds()->SetId(5, 13);
v2->GetPointIds()->SetId(6, 14);
v2->GetPointIds()->SetId(7, 15);
aVoxelGrid->InsertNextCell(VTK_VOXEL, v2->GetPointIds());
aVoxelGrid->SetPoints(vPts);
aVoxelGrid->Update();
vtkGenericCell* cell = vtkGenericCell::New();
for( int i = 0; i < aVoxelGrid->GetNumberOfCells(); i++ )
{
aVoxelGrid->GetCell( i, cell );
vtkIdList* cellNeighbors = vtkIdList::New();
int numFaces = cell->GetNumberOfFaces();
for ( int j = 0; j < numFaces; j++ )
{
vtkCell* face = cell->GetFace( j );
aVoxelGrid->GetCellNeighbors( i, face->PointIds, cellNeighbors);
if ( cellNeighbors->GetNumberOfIds() > 0 )
{
MessageBox(NULL, "Cell has neighbors!", NULL, MB_OK);
}
}
}
Thank you all.
Teresa
More information about the vtkusers
mailing list