[vtkusers] vtkImageData creation and use

Koning, P.J.H. de (LKEB) P.J.H.de_Koning at lumc.nl
Mon Sep 2 03:15:59 EDT 2002


31-08-02 11:01:45, "Monica Hernandez" <moniquisma at colacao.es> wrote:

First, you need to call vktimage->AllocateScalars() before trying to fill the image. Second, it looks like you are incrementing the pointer to much.
If you only use the ptr++ statement, that should be enough.

Maybe you need to call SetDimensions before the AllocateScalars, but i'm not to sure if thats necessary.

Good luck.

>Greetings:
>I want to create an vtkImageData object with some specified parameters 
>and use it for accessing to its scalar values.
>If I do this:
>
>//begining of program
>//using vtk 3.0
>#include <vtkImageData.h>
>
>//creation of the vtkImageData object with the specified parameters
> vtkImageData *vtkimage = vtkImageData::New();
>  vtkimage->SetExtent(0,49,0,49,0,49);
>  vtkimage->SetScalarType(VTK_FLOAT);
>  vtkimage->SetSpacing(1.0,1.0,1.0);
>  vtkimage->SetOrigin(0,0,0);
>  vtkimage->SetNumberOfScalarComponents(1);
>  float *ptr = (float*) vtkimage->GetScalarPointer();
>  int incX, incY, incZ, ext[6];
>  vtkimage->GetContinuousIncrements(ext,incX,incY,incZ);
>
> for (int z=0; z<50; z++){
>    for (int y=0; y<50; y++){
>      for (int x=0; x<50; x++){
>        cerr << x <<" " << y << " " << z << endl;
>          cerr << *ptr <<endl;
>          ptr++;
>      }
>      ptr +=incY;
>    }
>    ptr +=incZ;
>  }
>//end of program
>
>Things observed:
>1) When I execute this code there is a fatal error at x=34 y=18 z=49.
>2)Also incX=1091008010 and incY=-1287636448 (I don't know if the function 
>GetContinuosIncrements is working correctly, maybe the error is here)
>
>I would like to know how can I access with ptr to all possible scalar 
>values of my object.
>
>Thank you very much.
>
>
>--------------------------------------------------------------------------
>----------------------------------------
>Mónica Hernández Giménez
>Lab. 3.05 Dpto. Ingeniería Electrónica y Comunicaciones 
>Centro Politécnico Superior. Universidad de Zaragoza 
>Tlfno. (+34) 976761000 Ext.5288 
>Fax: (+34) 976762111 
>e-mail: mhg at posta.unizar.es
>--------------------------------------------------------------------------
>----------------------------------------
>
>
>_______________________________________________
>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
>





More information about the vtkusers mailing list