[vtkusers] vtkUnstructuredGrid - how to detect if a cell as neighbors?
Teresa Azevedo
dce06003 at fe.up.pt
Tue Oct 27 11:16:10 EDT 2009
Hi, Wes. Thank you so much for your quick answer!
If I try your changes, I runs ok: I get two messages.
But my problem is: I have a set of voxels (with different sizes), from
which I build my grid. That is, I do not know which voxels share the
same face points.
Is there a way to check, on the point list, if a certain point is
already there?
Teresa
Quoting Wes Turner <wes.turner at kitware.com>:
> Teresa,
>
> I didn't try to run this, so there may be more issues than just this one,
> but you are duplicating points not sharing them. Try the changes I marked
> below.
>
> - Wes
>
> On Tue, Oct 27, 2009 at 10:46 AM, Teresa Azevedo <dce06003 at fe.up.pt> 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(0, 4);
> v2->GetPointIds()->SetId(1, 5);
> v2->GetPointIds()->SetId(2, 6);
> v2->GetPointIds()->SetId(3, 7);
>
>
>> 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
>>
>
>
>
> --
> Wesley D. Turner, Ph.D.
> Kitware, Inc.
> Technical Leader
> 28 Corporate Drive
> Clifton Park, NY 12065-8662
> Phone: 518-881-4920
>
More information about the vtkusers
mailing list