[vtkusers] bit wise operations for vtkImageData

Jonathan Morra jonmorra at gmail.com
Fri Mar 25 15:08:43 EDT 2011


I'm in Java and storing a large number of binary vtkImageData's.  I know
this is inefficient, and am searching for a better way to store them.  Right
now I have a hash of the vtkImageData's and a get/put function.  Basically I
want to mimic this get/put but with better storage.  I was thinking one way
to do this is to use bitwise logical operations to store the information in
the binary masks.  For instance, if we have 2 binary images, then we could
store that information in 1 vtkImageData using the following pseudo code.

private static final int IMAGE1_BIT_CHANNEL = 0;
private static final int IMAGE2_BIT_CHANNEL = 1;
private vtkImageData storedImage;

vtkImageData get(String image)  {
    int channel = image eq "image1" ? IMAGE1_BIT_CHANNEL :
IMAGE2_BIT_CHANNEL;
    vtkImageData return = new vtkImageData();
    foreach (pixel in storedImage)
        if (pixel at bit channel)
            return[pixel] = 1;
        else
            return[pixel] = 0;
    return return;
}

void put(String image, vtkImageData binaryImage) {
    int channel = image eq "image1" ? IMAGE1_BIT_CHANNEL :
IMAGE2_BIT_CHANNEL;
    foreach (pixel in binaryImage)
        if (pixel)
            storedImage at bit in channel = 1;
        else
            storedImage at bit in channel = 0;
}

This could be extended easily for 8 channels for a char image for instance.
 This operation would have to be very fast though cause it is done often on
the UI thread.
1.  Is there a way to do this in VTK with Java?
2.  Is this the best scheme for accomplishing my goal?
3.  Is there a better scheme for doing this?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110325/9fa503e8/attachment.htm>


More information about the vtkusers mailing list