[vtkusers] vtkUnstructuredGrid - how to detect if a cell as neighbors?

Bryn Lloyd blloyd at vision.ee.ethz.ch
Tue Oct 27 11:06:33 EDT 2009


Hi Teresa,

The problem with you code is that you insert duplicate points. For two 
cubes that share one face you should have 12 points in total, since the 
interface is shared by both cubes. The neghborhood here is calculated 
from the point indices, not the point position.


FYI:
Have a look at the vtkDataSetSurfaceFilter. It will extract all surface 
cells from any input dataset (including vtkUnstructuredGrid).

If you set following switch: PassThroughCellIdsOn
the output surface cells will have an index array, which associates each 
surface cell with the corresponding input volume cell.

/Bryn


Teresa Azevedo wrote:
> 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
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: 
> http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 


-- 
-------------------------------------------------
Bryn Lloyd
Computer Vision Laboratory
ETH Zürich, Sternwartstrasse 7, ETF C110
CH - 8092 Zürich, Switzerland
Tel: +41 44 63 26668
Fax: +41 44 63 21199
-------------------------------------------------



More information about the vtkusers mailing list