[vtkusers] Filling vtkPoints and vtkCellArray fast
Matt
pspmatt at gmail.com
Tue Jan 19 10:54:59 EST 2010
Thanks David. You a were correct again. I thought I would post my solution
for posterity's sake.
float * pts = (float *
)Tubes->GetOutput()->GetPoints()->GetVoidPointer(0);
- in this case I needed to cast the void pointer to the underlying data
type which was float
int * CA = Tubes->GetOutput()->GetStrips()->GetPointer();
- better coding would probably use vtkIdType * instead of int *
Thanks
Matt
And, then pts[0], pts[1], pts[n-1] and the same for CA
On Mon, Jan 18, 2010 at 5:41 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100119/0a0ac26b/attachment.htm>
More information about the vtkusers
mailing list