Your understanding is correct, however I cannot use GetScalarComponentAsDouble and SetScalarComponentAsDouble because they are way too slow in Java.  Do you have any other suggestions for how to do this or will I have to write it myself in C++?<br>
<br><div class="gmail_quote">On Fri, Mar 25, 2011 at 12:29 PM, David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Jonathan,<br>
<br>
If I understand correctly, you have several binary images with exactly<br>
the same dimensions.  And you want to collapse them into a single<br>
image, by storing a bitfield in the pixels of that image.  So:<br>
<br>
To set bit &quot;i&quot; in pixel &quot;xyz&quot; (C++ code):<br>
int a = int(image.GetScalarComponentAsDouble(x, y, z, 0));<br>
a |= (1 &lt;&lt; i);<br>
image.SetScalarComponentAsDouble(x, y, z, a);<br>
<br>
To clear bit &quot;i&quot; in pixel &quot;xyz&quot;:<br>
int a = int(image.GetScalarComponentAsDouble(x, y, z, 0));<br>
a &amp;= ~(1 &lt;&lt; i);<br>
image.SetScalarComponentAsDouble(x, y, z, a);<br>
<br>
To test bit &quot;i&quot; in pixel &quot;xyz&quot;:<br>
int a = int(image.GetScalarComponentAsDouble(x, y, z, 0));<br>
return ((a &gt;&gt; i) &amp; 1);<br>
<br>
But I&#39;m not sure if this is what you are trying to do.  I didn&#39;t fully<br>
understand your pseudocode.<br>
<br>
 - David<br>
<div><div></div><div class="h5"><br>
<br>
<br>
On Fri, Mar 25, 2011 at 1:08 PM, Jonathan Morra &lt;<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>&gt; wrote:<br>
&gt; I&#39;m in Java and storing a large number of binary vtkImageData&#39;s.  I know<br>
&gt; this is inefficient, and am searching for a better way to store them.  Right<br>
&gt; now I have a hash of the vtkImageData&#39;s and a get/put function.  Basically I<br>
&gt; want to mimic this get/put but with better storage.  I was thinking one way<br>
&gt; to do this is to use bitwise logical operations to store the information in<br>
&gt; the binary masks.  For instance, if we have 2 binary images, then we could<br>
&gt; store that information in 1 vtkImageData using the following pseudo code.<br>
&gt; private static final int IMAGE1_BIT_CHANNEL = 0;<br>
&gt; private static final int IMAGE2_BIT_CHANNEL = 1;<br>
&gt; private vtkImageData storedImage;<br>
&gt; vtkImageData get(String image)  {<br>
&gt;     int channel = image eq &quot;image1&quot; ? IMAGE1_BIT_CHANNEL :<br>
&gt; IMAGE2_BIT_CHANNEL;<br>
&gt;     vtkImageData return = new vtkImageData();<br>
&gt;     foreach (pixel in storedImage)<br>
&gt;         if (pixel at bit channel)<br>
&gt;             return[pixel] = 1;<br>
&gt;         else<br>
&gt;             return[pixel] = 0;<br>
&gt;     return return;<br>
&gt; }<br>
&gt; void put(String image, vtkImageData binaryImage) {<br>
&gt;     int channel = image eq &quot;image1&quot; ? IMAGE1_BIT_CHANNEL :<br>
&gt; IMAGE2_BIT_CHANNEL;<br>
&gt;     foreach (pixel in binaryImage)<br>
&gt;         if (pixel)<br>
&gt;             storedImage at bit in channel = 1;<br>
&gt;         else<br>
&gt;             storedImage at bit in channel = 0;<br>
&gt; }<br>
&gt; This could be extended easily for 8 channels for a char image for instance.<br>
&gt;  This operation would have to be very fast though cause it is done often on<br>
&gt; the UI thread.<br>
&gt; 1.  Is there a way to do this in VTK with Java?<br>
&gt; 2.  Is this the best scheme for accomplishing my goal?<br>
&gt; 3.  Is there a better scheme for doing this?<br>
&gt; Thanks.<br>
</div></div>&gt; _______________________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the VTK FAQ at:<br>
&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br>