So after some more work, I figured out that&#39;s it definitely the setCharArray method that&#39;s not working.<div><br></div><div>After testing I have realized that this works but is very slow (too slow to be usable)</div>
<div><br></div><div><div><div>private void setCharArray(vtkImageData image, char[] array) {</div><div>        vtkCharArray ca = new vtkCharArray();</div><div>        ca.Initialize();</div><div>        ca.SetNumberOfValues(array.length);</div>
<div>        //ca.SetJavaArray(array);</div><div>        int i=0;</div><div>        for (char data : array) {</div><div>            ca.SetValue(i, data);</div><div>            ++i;</div><div>        }</div><div>        ca.Modified();</div>
<div>        ca.SetName(&quot;ImageScalars&quot;);</div><div>        image.GetPointData().SetScalars(ca);</div><div>        image.Update();</div><div>}</div></div><div><br></div><div>and this does not work (but it is fast about it&#39;s not working)</div>
<div><br></div><div><div><div>private void setCharArray(vtkImageData image, char[] array) {</div><div>        vtkCharArray ca = new vtkCharArray();</div><div>        ca.Initialize();</div><div>        ca.SetNumberOfValues(array.length);</div>
<div>        ca.SetJavaArray(array);</div><div>        /*int i=0;</div><div>        for (char data : array) {</div><div>            ca.SetValue(i, data);</div><div>            ++i;</div><div>        }*/</div><div>        ca.Modified();</div>
<div>        ca.SetName(&quot;ImageScalars&quot;);</div><div>        image.GetPointData().SetScalars(ca);</div><div>        image.Update();</div><div>    }</div></div></div><div><br></div><div>Why isn&#39;t SetJavaArray() working?</div>
<br><div class="gmail_quote">On Mon, Mar 28, 2011 at 2:17 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;">
I can&#39;t see anything that is obviously wrong, but my experience<br>
with Java is limited.<br>
<font color="#888888"><br>
 - David<br>
</font><div><div></div><div class="h5"><br>
<br>
On Mon, Mar 28, 2011 at 2:42 PM, Jonathan Morra &lt;<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>&gt; wrote:<br>
&gt; After playing around a little bit, I have come up with the following that&#39;s<br>
&gt; not currently working.  Could you please advise me why this isn&#39;t working.<br>
&gt; Thanks<br>
&gt; put() {<br>
&gt;         // Organ data contains a list of char[]<br>
&gt;         final char[] storedCharArray = organData.get(imageNumber);<br>
&gt;         final char[] binaryCharArray = getCharArray(binaryOrgan);<br>
&gt;         int i=0;<br>
&gt;         for (char binaryData : binaryCharArray) {<br>
&gt;             char storedData = storedCharArray[i];<br>
&gt;             if (binaryData == 0)<br>
&gt;                 storedData &amp;= ~(1 &lt;&lt; bitNumber);<br>
&gt;             else<br>
&gt;                 storedData |= (1 &lt;&lt; bitNumber);<br>
&gt;             storedCharArray[i] = storedData;<br>
&gt;             ++i;<br>
&gt;         }<br>
&gt; get() {<br>
&gt;         vtkImageData binaryImage = // Get blank image of correct dimensions,<br>
&gt; orientation, spacing, etc.<br>
&gt;         final char[] storedCharArray = organData.get(imageNumber);<br>
&gt;         final char[] binaryCharArray = getCharArray(binaryImage);<br>
&gt;         int i=0;<br>
&gt;         for (char storedData : storedCharArray) {<br>
&gt;             binaryCharArray[i] = (char)((storedData &gt;&gt; bitNumber) &amp; 1);<br>
&gt;             ++i;<br>
&gt;         }<br>
&gt;         setCharArray(binaryImage, binaryCharArray);<br>
&gt; private void setCharArray(vtkImageData image, char[] array) {<br>
&gt;<br>
&gt;  ((vtkCharArray)image.GetPointData().GetScalars()).SetJavaArray(array);<br>
&gt;     }<br>
&gt;     private char[] getCharArray(vtkImageData image) {<br>
&gt;         vtkPointData points = image.GetPointData();<br>
&gt;         vtkCharArray ca = (vtkCharArray)points.GetScalars();<br>
&gt;         char[] chars = ca.GetJavaArray();<br>
&gt;         return chars;<br>
&gt;     }<br>
&gt;<br>
&gt; On Fri, Mar 25, 2011 at 12:48 PM, David Gobbi &lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; In python it is possible to access the VTK data arrays directly via<br>
&gt;&gt; python&#39;s buffer interface, so that&#39;s what I use when I want to quickly<br>
&gt;&gt; move pixel data back and forth from python to VTK.  It allows me to<br>
&gt;&gt; use a VTK array (including the one that the image uses to store its<br>
&gt;&gt; pixels) as if it was a native python array.<br>
&gt;&gt;<br>
&gt;&gt; I have a feeling that the only way you will be able to rapidly do VTK<br>
&gt;&gt; pixel operations of any kind from Java, is if someone adds a similar<br>
&gt;&gt; feature to the Java wrappers.<br>
&gt;&gt;<br>
&gt;&gt;  - David<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Fri, Mar 25, 2011 at 1:31 PM, Jonathan Morra &lt;<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt; Your understanding is correct, however I cannot<br>
&gt;&gt; &gt; use GetScalarComponentAsDouble and SetScalarComponentAsDouble because<br>
&gt;&gt; &gt; they<br>
&gt;&gt; &gt; are way too slow in Java.  Do you have any other suggestions for how to<br>
&gt;&gt; &gt; do<br>
&gt;&gt; &gt; this or will I have to write it myself in C++?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Fri, Mar 25, 2011 at 12:29 PM, David Gobbi &lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt;<br>
&gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hi Jonathan,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; If I understand correctly, you have several binary images with exactly<br>
&gt;&gt; &gt;&gt; the same dimensions.  And you want to collapse them into a single<br>
&gt;&gt; &gt;&gt; image, by storing a bitfield in the pixels of that image.  So:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; To set bit &quot;i&quot; in pixel &quot;xyz&quot; (C++ code):<br>
&gt;&gt; &gt;&gt; int a = int(image.GetScalarComponentAsDouble(x, y, z, 0));<br>
&gt;&gt; &gt;&gt; a |= (1 &lt;&lt; i);<br>
&gt;&gt; &gt;&gt; image.SetScalarComponentAsDouble(x, y, z, a);<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; To clear bit &quot;i&quot; in pixel &quot;xyz&quot;:<br>
&gt;&gt; &gt;&gt; int a = int(image.GetScalarComponentAsDouble(x, y, z, 0));<br>
&gt;&gt; &gt;&gt; a &amp;= ~(1 &lt;&lt; i);<br>
&gt;&gt; &gt;&gt; image.SetScalarComponentAsDouble(x, y, z, a);<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; To test bit &quot;i&quot; in pixel &quot;xyz&quot;:<br>
&gt;&gt; &gt;&gt; int a = int(image.GetScalarComponentAsDouble(x, y, z, 0));<br>
&gt;&gt; &gt;&gt; return ((a &gt;&gt; i) &amp; 1);<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; But I&#39;m not sure if this is what you are trying to do.  I didn&#39;t fully<br>
&gt;&gt; &gt;&gt; understand your pseudocode.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  - David<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On Fri, Mar 25, 2011 at 1:08 PM, Jonathan Morra &lt;<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>&gt;<br>
&gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt; I&#39;m in Java and storing a large number of binary vtkImageData&#39;s.  I<br>
&gt;&gt; &gt;&gt; &gt; know<br>
&gt;&gt; &gt;&gt; &gt; this is inefficient, and am searching for a better way to store them.<br>
&gt;&gt; &gt;&gt; &gt;  Right<br>
&gt;&gt; &gt;&gt; &gt; now I have a hash of the vtkImageData&#39;s and a get/put function.<br>
&gt;&gt; &gt;&gt; &gt;  Basically I<br>
&gt;&gt; &gt;&gt; &gt; want to mimic this get/put but with better storage.  I was thinking<br>
&gt;&gt; &gt;&gt; &gt; one<br>
&gt;&gt; &gt;&gt; &gt; way<br>
&gt;&gt; &gt;&gt; &gt; to do this is to use bitwise logical operations to store the<br>
&gt;&gt; &gt;&gt; &gt; information<br>
&gt;&gt; &gt;&gt; &gt; in<br>
&gt;&gt; &gt;&gt; &gt; the binary masks.  For instance, if we have 2 binary images, then we<br>
&gt;&gt; &gt;&gt; &gt; could<br>
&gt;&gt; &gt;&gt; &gt; store that information in 1 vtkImageData using the following pseudo<br>
&gt;&gt; &gt;&gt; &gt; code.<br>
&gt;&gt; &gt;&gt; &gt; private static final int IMAGE1_BIT_CHANNEL = 0;<br>
&gt;&gt; &gt;&gt; &gt; private static final int IMAGE2_BIT_CHANNEL = 1;<br>
&gt;&gt; &gt;&gt; &gt; private vtkImageData storedImage;<br>
&gt;&gt; &gt;&gt; &gt; vtkImageData get(String image)  {<br>
&gt;&gt; &gt;&gt; &gt;     int channel = image eq &quot;image1&quot; ? IMAGE1_BIT_CHANNEL :<br>
&gt;&gt; &gt;&gt; &gt; IMAGE2_BIT_CHANNEL;<br>
&gt;&gt; &gt;&gt; &gt;     vtkImageData return = new vtkImageData();<br>
&gt;&gt; &gt;&gt; &gt;     foreach (pixel in storedImage)<br>
&gt;&gt; &gt;&gt; &gt;         if (pixel at bit channel)<br>
&gt;&gt; &gt;&gt; &gt;             return[pixel] = 1;<br>
&gt;&gt; &gt;&gt; &gt;         else<br>
&gt;&gt; &gt;&gt; &gt;             return[pixel] = 0;<br>
&gt;&gt; &gt;&gt; &gt;     return return;<br>
&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt; &gt;&gt; &gt; void put(String image, vtkImageData binaryImage) {<br>
&gt;&gt; &gt;&gt; &gt;     int channel = image eq &quot;image1&quot; ? IMAGE1_BIT_CHANNEL :<br>
&gt;&gt; &gt;&gt; &gt; IMAGE2_BIT_CHANNEL;<br>
&gt;&gt; &gt;&gt; &gt;     foreach (pixel in binaryImage)<br>
&gt;&gt; &gt;&gt; &gt;         if (pixel)<br>
&gt;&gt; &gt;&gt; &gt;             storedImage at bit in channel = 1;<br>
&gt;&gt; &gt;&gt; &gt;         else<br>
&gt;&gt; &gt;&gt; &gt;             storedImage at bit in channel = 0;<br>
&gt;&gt; &gt;&gt; &gt; }<br>
&gt;&gt; &gt;&gt; &gt; This could be extended easily for 8 channels for a char image for<br>
&gt;&gt; &gt;&gt; &gt; instance.<br>
&gt;&gt; &gt;&gt; &gt;  This operation would have to be very fast though cause it is done<br>
&gt;&gt; &gt;&gt; &gt; often<br>
&gt;&gt; &gt;&gt; &gt; on<br>
&gt;&gt; &gt;&gt; &gt; the UI thread.<br>
&gt;&gt; &gt;&gt; &gt; 1.  Is there a way to do this in VTK with Java?<br>
&gt;&gt; &gt;&gt; &gt; 2.  Is this the best scheme for accomplishing my goal?<br>
&gt;&gt; &gt;&gt; &gt; 3.  Is there a better scheme for doing this?<br>
&gt;&gt; &gt;&gt; &gt; Thanks.<br>
&gt;&gt; &gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Visit other Kitware open-source projects at<br>
&gt;&gt; &gt;&gt; &gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Please keep messages on-topic and check the VTK FAQ at:<br>
&gt;&gt; &gt;&gt; &gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; &gt;&gt; &gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div>