[vtkusers] Pointer to pixels

Patrick de Koning patrick at lkeb.azl.nl
Thu Dec 14 03:14:37 EST 2000


Jordi Inglada wrote:
> 
> 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!.
> 
You could try calling aFilter->GetOutput()->Update() first, to execute
the pipeline

> 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
> 
This might because the output of the filter isn't float. Use
id->GetScalarType() to get the correct type and cast to this type,  or
use vtkImageCast to cast the image to floats.

> 
>  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
> 
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers

-- 
--------------------------------------------------------------------
Ir. P.J.H. de Koning                    Leiden University Medical Center
Department of Radiology, C2S            Division of Image Processing
P.O. Box 9600                           2300 RC  LEIDEN
the Netherlands                         Tel. +31-71-5266206  
Fax +31-71-5266801                      Email patrick at lkeb.azl.nl




More information about the vtkusers mailing list