[vtkusers] vtkImageData python

shekharc Shekhar.Chandra at sci.monash.edu.au
Sun Dec 9 18:45:20 EST 2007


Hi Jose,

For the C++ API Docs:

virtual float 	GetScalarComponentAsFloat (int x, int y, int z, int 
component)
virtual void 	SetScalarComponentFromFloat (int x, int y, int z, int 
component, float v)
virtual double 	GetScalarComponentAsDouble (int x, int y, int z, int 
component)
virtual void 	SetScalarComponentFromDouble (int x, int y, int z, int 
component, double v)

Those will do what u want. U can also set the number of scalar 
components and their type. Just check out the Doxygen API Doc. Hope that 
helps.

Cheers
Shakes

Jose David Pfuturi Huisa wrote:
> Hello everybody
> I want to create an image with vtkImagedata, i saw an example using C++ 
> code as follows:
> int x,y;
> vtkImageData *image;
> image=vtkImageData::New();
> image->SetDimensions(256,256,1);
> image->SetScalarTypeToFloat();
> image->AllocateScalars();
> float *ptr=static_cast<float*>(image->GetScalarPointer());
> for(y=0;y<256;++y)
> {   for(x=0;x<256;++x)
>         {*ptr++=10.0*sin(0.1*x)*sin(0.1*y);
>         }
> }
> vtkImageViewer *viewer=vtkImageViewer::New();
> viewer->SetInput(image);
> viewer->SetColorWindow(20);
> viewer->SetColorLevel(0);
> viewer->Render();
>  
> How could i do it using Python? i tried to do it but GetScalarPointer() 
> returns a pointer and in c++ this pointer stores the scalar value each 
> position but on Python i dont know how i can do it.
> image=vtkImageData()
> image.SetDimensions(256,256,1)
> image.SetOrigin(0,0,0)
> image.SetScalarTypeToUnsignedChar ()
> image.AllocateScalars ()
> ptr=data.GetScalarPointer()
> for y in range(0,256):
>     for x in range(0,256):
>           #?
> viewer=vtkImageViewer();
> viewer.SetInput(image);
> viewer.SetColorWindow(20);
> viewer.SetColorLevel(0);
>  
> In *ptr++=10.0*sin(0.1*x)*sin(0.1*y) i suppose that it changes the pixel 
> value, true?
> if not then, an image has pixels, and this pixels has a RGB value, How 
> could i get this value (each pixel)?
>  
> thanks a lot
> 
> José
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> 
> ------------------------------------------------------------------------
> Tecnología, moda, motor, viajes,…suscríbete a nuestros boletines para 
> estar a la última MSN Newsletters 
> <http://newsletters.msn.com/hm/maintenanceeses.asp?L=ES&C=ES&P=WCMaintenance&Brand=WL&RU=http%3a%2f%2fmail.live.com>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list