[vtkusers] VTK/Examples/Cxx/ImageData/IterateImageData

David Doria daviddoria at gmail.com
Mon Dec 13 09:44:31 EST 2010


On Mon, Dec 13, 2010 at 9:14 AM, Rachel <aracha2010 at gmail.com> wrote:
>
> Thank you Davis. i got the same results as you but when i change the code as
> you see below, it gives me 0:
>
> I change the input image and I assigned 2.0 to each pixel (as in the example
> )

The problem is that the reader is creating an image with pixels of
type Unsigned Char.

You have to change the cast in both the loop setting the pixels and
reading the pixels:

Set loop:

unsigned char* pixel =
static_cast<unsigned char*>(imageData->GetScalarPointer(x,y,z));
pixel[0] = 2;

Get loop:

unsigned char* pixel =
static_cast<unsigned char*>(imageData->GetScalarPointer(x,y,z));
// do something with v
std::cout << (int)pixel[0] << " ";

David



More information about the vtkusers mailing list