[vtkusers] Pointer to pixels.

Jordi Inglada jordi.inglada at cnes.fr
Wed Dec 13 17:26:28 EST 2000


On Wed, Dec 13, 2000 at 08:51:13AM +0100, Patrick de Koning wrote:
> 
> 
> Jordi Inglada wrote:
> > 
> > Hello all.
> > 
> > I am taking my first steps with Vtk. Since I have a considerable
> > amount of code written by myself for image processing stuff, I would
> > like to reuse it together with vtk. In order to do this I need to put
> > the output of some image filters into, let's say, an array of
> > floats. If aFilter->GetOutput() returns a pointer of type
> > vtkImageData, how can I individually access the pixels?
> > 
> > Thanks.
> > 
> Use aFilter->GetOutput()->GetScalarPointer() to get a void pointer to
> the first element of the array, then just cast to float if the imagedata
> is float.
>

Thanks for your reply. I have tried this and it doesn't seem to work.
If I do aFilter->GetOutput()->GetScalarPointer(), I get a message like
this:

ERROR: In vtkImageData.cxx, line 1295
vtkImageData (0x862b4d8): Attempt to allocate scalars before scalar
type was set!.

So I have tried this:

 vtkImageData* id = aFilter->GetOutput();
 id->SetScalarType(VTK_FLOAT);
 float* thedata = (float*) (id->GetScalarPointer());

but I get a segmentation fault when trying to acces the data. So I
have also tried to set the dimensions

  
 int* dims;
 dims = new int[10];
 dims[0]=xdim;dims[1]=ydim;dims[2]=1;
 id->SetDimensions(dims);
 float* thedata = (float*) (id->GetScalarPointer());

But now, all the pixels are equal to zero. 

What am I doing wrong?

Thanks again.

-- 
Jordi Inglada
CNES - Centre Spatial de Toulouse
DSO/OT/QTIS/SR - BPI 811
18, avenue Edouard Belin
31401 Toulouse Cedex 04 - France
Tel. +33.(0)5.61.27.33.97 - Fax. +33.(0)5.61.28.31.09




More information about the vtkusers mailing list