[vtkusers] Re: Draw and Color Polygons

Janny Dong janny.dong at gmail.com
Mon Oct 1 12:24:03 EDT 2007


Hi Eugene,

To use your method, do I have to separate the points for the three polygons
to three groups and input points to vtkPoints and vtkCellArray instead of
reading them from the file? Is the first part of your code (reading data
from file) related to the second part (the part worked fine for you)? I have
trouble constructing 3 cells after reading in all the points... I can add
all the data to vtkPoints with

//Read the vtk data file.
vtkPolyDataReader *usa = vtkPolyDataReader::New();
usa->SetFileName("greatlakes.vtk");
for (int i = 0; i < usa->GetOutput()->GetNumberOfPoints(); i++)
points->InsertNextPoint(usa->GetOutput()->GetPoint(i));

But I can not insert part of the points to another instance of vtkPoints
like:

for (i = 0,i<882; i++)
points2->InsertNextPoint(usa->GetOutput()->GetPoint(i));

Any thoughts?
Thanks
Janny

On 9/30/07, Eugene Dorfman <justadreamer2007 at gmail.com> wrote:
>
> Ok, I would do it simpler for the first approximation (for 1 polygon):
>
> vtkPolyDataMapper *map = vtkPolyDataMapper::New();
> vtkPolyDataReader *reader = ... New();
> /*Read your data*/
> vtkPolyData *data = reader->GetOutput();
> map->SetInput(data);
> /*add a mapper to renderer and render*/
>
>
> Then. What worked fine for me was:
>
> vtkPoints* points = ...::New();
> vtkCellArray* cellArray = ...::New();
>
> vtkIdList *idList = new vtkIdList::New();
> vtkPoints* points1 = ...::New();
>
> points->GetPoints(idList,points1);
> cellArray->InsertNextCell(points->GetNumberOfPoints());  //inserting a
> cell for 1 polygon
> for (int i=0;i<points->GetNumberOfPoints();i++)
>        cellArray->InsertCellPoint(idList[i]);
>
> //now we have constructed 1 cell
> vtkPolyData *polyData = ...::New();
> polyData->SetPoints(points);
> polyData->SetPolys(cellArray);
> vtkPolyDataMapper * map = ...::New();
> map->SetInput(polyData);
>
> //then render
>
> so we constructed single cell of a shape of your polygon - should work.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071001/0c7356e8/attachment.htm>


More information about the vtkusers mailing list