[vtkusers] vtkCellArray - efficient use
Burlen Loring
burlen.loring at kitware.com
Fri Jan 16 11:31:30 EST 2009
Here is an example using vertex cells.
vtkIdTypeArray *va=vtkIdTypeArray::New();
va->SetNumberOfTuples(2*nCells);
vtkIdType *verts=va->GetPointer(0);
vtkPoints *pts=vtkPoints::New();
pts->SetData(xyzArray);
for (int i=0; i<nCells; ++i)
{
verts[0]=1;
verts[1]=i;
verts+=2;
}
polydataset->SetPoints(pts);
pts->Delete();
vtkCellArray *cells=vtkCellArray::New();
cells->SetCells(static_cast<vtkIdType>(nCells),va);
polydataset->SetVerts(cells);
cells->Delete();
va->Delete();
Paul Harris wrote:
> Hi,
>
> I have the following code:
>
> vtkCellArray * p_cells = vtkCellArray::New();
>
> p_cells->Allocate( ids.size() );
>
> for ( vector<vtkIdType>::const_iterator id = ids.begin(), id_end =
> ids.end(); id != id_end; ++id )
> p_cells->InsertNextCell(1,&*c);
>
>
> But, I am not sure that my Allocate() call is correct. Should it be:
> Allocate(ids.size()*2);
>
> ... the reason I ask is that I wanted to try and use
> p_cells->WritePointer() to do the copying with a memcpy, but it looks
> like the format of a CellArray is something like:
>
> [cellid, pointid, cellid, pointid, cellid, pointid]
>
> if i had 2 points per cell it would be
> [cellid, point1, point2, cellid, point1, point2, etc]
>
> if this is so, then in order to create a cellarray of 20 points, each
> in their own cells, i'd need to alloc room for 40.
>
>
> Am I reading the code correctly?
> Does anyone do efficient copies, or does everyone use InsertNextEtc()
> methods?
>
> thanks,
> Paul
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
--
Burlen Loring
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x137
More information about the vtkusers
mailing list