Posted by
Michael Schmid on
Mar 31, 2009; 5:22pm
URL: http://imagej.273.s1.nabble.com/Contradiction-with-show-method-tp3693120p3693129.html
Hi David,
as far as my experience told me, you have a separate thread for
displaying images also on single-processor machines. I think that it
is the paint method of ImageCanvas that runs in the separate thread,
causing the behavior noticed by you.
Swing components can have a paintSafely method that is not multi-
threaded, but I don't think that you can have something like this
with awt components used by ImageJ.
The usual way of displaying an intermediate result of processing is
to duplicate the ImageProcessor and use this copy for display only,
without modifying it any further.
Also note that ImageCanvas.paint is also called if an image gets
obscured by a foreground image and has to be repainted.
Thus I suspect that your method 3 would only work as long as the
image stays in the foreground - but this may depend on whether the
operating system or graphics card does some buffering or not.
Michael
________________________________________________________________
On 30 Mar 2009, at 19:40, David Webster wrote:
> To All,
>
> Wilhelm, I reran my tests and got the same results. Howeve, I
> should have
> included my case 2 as a normal result. Only case 1 seems to be odd.
> For what
> it's worth, I am using IJ 1.42k.
>
> Micheal, I am running Windows XP2002 SP3. I am using a Pentim 4
> from 2005,
> that is only a single core. I don't know if it mutithreds or not.
>
> David
>
>
>
> On Mon, Mar 30, 2009 at 1:26 AM, Michael Schmid
> <
[hidden email]>wrote:
>
>> Hi David,
>>
>> Java is multi-threaded; displaying images is usually done in a
>> separate
>> thread. Especially on multiprocessor machines, this improves
>> performance.
>>
>> Thus, it can easily happen that "im1.show();" displays the image a
>> few
>> thenths of a second after that method is called; at that time the
>> data are
>> modified already.
>>
>> (not a bug, a feature ;-)
>>
>> Michael
>> ________________________________________________________________
>>
>>
>> On 29 Mar 2009, at 22:34, David William Webster wrote:
>>
>> I am learning Java via th "monkey see, monkey do" method and get
>> what seems
>>> to be a contradiction.
>>>
>>> I ran a test similar to the one shown in Burger and Berge on page
>>> 502.(see
>>> run method below). Without the updateAndDraw(), the invert()
>>> result should not be display'ed. But,
>>> In case 1, with the wait(2000) and updateAndDraw() commented out,
>>> I get the inverted image being displayed (It shouldn't be).
>>> In case 2, I use the wait(200) and get only the original image being
>>> displayed.
>>> In case 3, I add the updateAndDraw() and get the inverted image.
>>> Only case 3 makes any sense
>>>
>>>
>>> public void run(ImageProcessor ip) {
>>>
>>> ImageProcessor ip1 = ip.duplicate();
>>> ImagePlus im1 = new ImagePlus("im1",ip1);
>>> im1.show();
>>> //IJ.wait(2000);
>>> ip1.invert();
>>> //im1.updateAndDraw();
>>> }
>>>
>>> David Webster
>>>
>>