[vtkusers] about vtkImageMask

Sean Ziegeler seanzig at users.sourceforge.net
Mon Jan 14 10:20:54 EST 2008


>> Could anyone tell me why the mask input in the
>> vtkImageMask is type "unsigned char"?
>> I think if it could be bool/bit, it could save a lot
>> of memory, since we only need values 0 and 1 in a
>> mask?
> 
> I'm not a specialist but I would say that booleans are coded on 8 bits
> (even if they can take only two values). I know no processor capable of
> handling 1 bit values. So using boolean would _not_ save any memory.

The processor cannot handle single bits directly, but you could write 
code using logical bit operations (bit shifts, bitwise-and's, etc.) to 
pack each bit into a byte and to extract each back out.  It would save 
8x space, but all the extra ops will probably slow you down by at least 
8x, if not more.  Also the code would get rather hairy.  All-in-all, 
using bytes is probably better.

-Sean




More information about the vtkusers mailing list