[vtkusers] Convert vtkUnstructuredGrid to vtkPolyData

David Doria daviddoria at gmail.com
Fri Nov 11 07:00:44 EST 2011


On Thu, Nov 10, 2011 at 7:17 PM, mandalin <mandalin147 at gmail.com> wrote:
> Greetings !
>
> *So, from buildings and terrain information, I have populated a
> vtkUnstructuredGrid with VTK_POLYGON as follows :*
>
> //Store the positions of the vertices
>    vtkPoints *GeometryVertices = vtkPoints::New();
>
>    GeometryVertices->Allocate(NumVertices);
>
>    for(int i=0; i<NumVertices; i++)
>    {
>        GeometryVertices->InsertPoint(i, unique_corners[i].x,
> unique_corners[i].y, unique_corners[i].z);
>    }
>
>    //Makeing an array of ID's for each polygon
>    vtkIdList** pointIDs;
>    pointIDs= new vtkIdList *[NumWalls];
>
>    int cornersperwall;
>
>    for(int wallind=0; wallind<NumWalls; wallind++)
>    {   cornersperwall=walls[wallind].corners.size();
>       // std::cout&lt;&lt;&quot;Corners in this wall
> &quot;&lt;&lt;cornersperwall&lt;&lt;std::endl;
>        pointIDs[wallind]= vtkIdList::New();
>
>        for(int cornerind=0; cornerind&lt;walls[wallind].corners.size();
> cornerind++)
>        {
>
> pointIDs[wallind]->InsertNextId(walls[wallind].corner_indices[cornerind]);
>        }
>    }
>
>
>    //Make the Polygons
>    vtkUnstructuredGrid * ugridGeom= vtkUnstructuredGrid::New();
>    ugridGeom->Allocate(totnumcnx+10);
>
>    for(int wallind=0; wallind<NumWalls; wallind++)
>    {   //if(wallind==9) //excludes ground planes
>        //{
>            for(int cornerind=0; cornerind&lt;walls[wallind].corners.size();
> cornerind++)
>            {   ugridGeom->InsertNextCell(VTK_POLYGON, pointIDs[wallind]);
>            }
>        //}
>    }
>
>
> *NOW, I would like to convert this to vtkPolyData so that I may later probe
> and interpolate*
>
> *When I use *
>
>        vtkGeometryFilter * geometryFilter =  vtkGeometryFilter::New();
>        geometryFilter->SetInput(ugridGeom);
>        geometryFilter->Update();
>
>        vtkPolyData* polydata = geometryFilter->GetOutput();
>
>        std::cout << "Output has " << polydata->GetNumberOfPoints() << "
> points." << std::endl;
>
> *
> I find that there are 0 points. *
>
>
> Any suggestions ?
>
> Thanks in advance,
> ~Amanda

The GeometryFilter should works - but you could also try
vtkDataSetSurfaceFilter:

http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/DataSetSurfaceFilter

However, why are you not just creating a vtkPolyData to start with? It
seems like you only have 2D cells (polygons), so there is no need for
a vtkUnstructuredGrid.

David



More information about the vtkusers mailing list