[vtkusers] Filling vtkPoints and vtkCellArray fast

David Gobbi david.gobbi at gmail.com
Mon Jan 18 18:41:17 EST 2010


Hi Matt,

I think you're looking for the GetPointer() method.  Every
vtkDataArray has one.  It can return a pointer to the start of the
array.

   David


On Mon, Jan 18, 2010 at 3:45 PM, Matt <pspmatt at gmail.com> wrote:
> Ok! So, I have managed to use my underlying C arrays without much overhead.
> Here, is the code:
>
>   float *vtkPts = (float * ) argv[0];
>   int *vtkCells = (int * ) argv[1];
>   int PtsArraySize = * (int *)  argv[2];
>   int CellArraySize = * (int *)  argv[3];
>   int nCells = * (int *) argv[4];
>
>   // Here comes the vtk stuff
>
>     vtkSmartPointer <vtkFloatArray> pts_fltarr =
> vtkSmartPointer<vtkFloatArray>::New();
>     pts_fltarr->SetNumberOfComponents(3); // X,Y,Z
>     pts_fltarr->SetArray(vtkPts, PtsArraySize, 1);
>
>     vtkSmartPointer <vtkPoints> Points = vtkSmartPointer<vtkPoints>::New();
>     Points->SetData(pts_fltarr);
>
>
>     vtkSmartPointer <vtkIdTypeArray> Conn =
> vtkSmartPointer<vtkIdTypeArray>::New();
>     Conn->SetArray(vtkCells, CellArraySize,1);
>
>     vtkSmartPointer <vtkCellArray> Polys =
> vtkSmartPointer<vtkCellArray>::New();
>     Polys->SetCells(nCells,Conn);
>
>     vtkSmartPointer <vtkPolyData> Tracts = vtkSmartPointer
> <vtkPolyData>::New();
>
>     Tracts->SetPoints(Points);
>     Tracts->SetLines(Polys);
>     Tracts->Update();
>
>     vtkSmartPointer <vtkTubeFilter> Tubes =
> vtkSmartPointer<vtkTubeFilter>::New();
>     Tubes->SetInput(Tracts);
>     Tubes->SetRadius(.2);
>     Tubes->SetNumberOfSides(6);
>     Tubes->Update();
>
> ------------------------------
>
> Now, I want to pass back two new arrays to IDL that contains the point data
> and the triangle strip (connectivity).
> Again, if I could just access the arrays directly life would be much
> simpler.  However, it appears going in reverse might be harder than what I
> have already setup.
>
> This will give me the size needed for the arrays:
>
>     // pts
>     int NumPoints = Tubes->GetOutput()->GetNumberOfPoints();
>
>     // cells/strips/num of elemens in array
>     int NumConn = Tubes->GetOutput()->GetStrips()->GetSize();
>
> The plan would be to allocate an array of ints (vtkIdType) to hold the
> strips and an array of floats to hold the point data.  Both, 1D.
>
> Strips (connectivity):
> -------------------------------
>
> Tubes->GetOutput()->GetStrips()->GetData() // Will give me a vtkIdTypeArray
> - but I really want is an array of vtkIdType.
>   -- At this point, I'd like to use a getArray function like the setArray
> function - but, it doesn't exist.
>   -- So, do I need to loop through the whole vtkIdTypeArray and copy it into
> an array of vtkIdType??
>  -- or can I avoid this with some trick that I can't figure out?
>
> Points:
> ----------
> Tubes->GetOutput()->GetPoints() // will give me a vtkPoints object with all
> of my points
>
> -- Again, at this point, I'd like to be able to extract the float array in
> the same way I set it, i.e setdata()
> -- I don't see a good option to do this.
> -- Do, I need to go point-by-point filling a new float array?
>
>
> Let me know if you can think of a way I can accomplish this?  I can write my
> own code to it.  But, wonder if there is a way to do this and my lack of
> experience with vtk is not allowing me to see it.
>
> Thanks again,
>
> Matt



More information about the vtkusers mailing list