Posted by
Kenneth Sloan-2 on
Nov 28, 2019; 9:58pm
URL: http://imagej.273.s1.nabble.com/confusing-overlay-behavior-tp5022716p5022725.html
The new Overlay is set by: (approximate...I'm seeing some sloppiness in my actual code that needs to be cleaned up - this is y best effort at describing the actual EFFECT - but I could be mistaken)
====================================================================
// pre-condition - imagePlus may already have an Overlay present
...code to create ArrayList<Roi> gridRoiList
gridOverlay = new Overlay(); // brand new, virgin Overlay
for(Roi roi : gridRoiList) gridOverlay.add(roi);
imagePlus.setOverlay(gridOverlay);
====================================================================
At this point, the displayed image is perfect. ONLY the new Overlay is displayed.
Now...the complication...the ImagePlus in question is my own EXTENSION to ImagePlus, which also manipulates the overlay. When that happens, the relevant code is:
=========================================================================
for(Roi r : this.cursorRoiList) this.cursoerOverlay.add(r );
setOverlay(this.cursorOverlay);
updateAndDraw();
=========================================================================
'cursorOverlay' is maintained by the imagePlus extension and is private. It is created in the constructor and modified on cursor movement. The code is more complicated than I now like - because I was trying to accomodate Rois added to the Overlay by other processes. Now - it essentially removes all of its known Roi's and adds new ones.
The higher level code (at the top) is more fascist. It creates a new, virgin Overlay and "sets" it as the one and only Overlay.
Both sections of my code use ImagePlus.setOverlay(). It seems clear to me that the setOverlay() in the high level code completely nukes any previous Overlay attached to this ImagePlus.
But now...the ImagePlus is wrapped in an ImageStack, and that is displayed in a StackWindow (even though there is - in these tests - only 1 image). It occurs to me that either ImageStack or StackWindow might somehow cache the Overlay at some point in time.
I can experiment to try to determine when this might be. (...testing...it seems to be cached immediately before the gridOverlay is established).
My current theory is that "Duplicate" and "Save As" (and "Flatten", I think...testing....yes! Image->Overlay->Flatten shows the cursorOverlay!) somehow use a cached Overlay (inside either ImageStack or StackWindow).
The effect as seen by the user is:
a) the cursor behaves normally...
b) when a grid is created, the cursor Rois disappear and the gridOverlay appears
c) "Duplicate" produces an image with the cursor Overlay !
d) moving the cursor in the window (with SHIFT) triggers the cursorOverlay and the gridOverlay disappers - this
is what I expect.
We now have two images open on the screen - my original StackWindow showing ONLY the gridOverlay, and the new "duplicate" image which is identical in every way EXCEPT that it shows the old cursorOverlay.
Certainly "surprising" behavior!
fortunately for my weekend - Plugins->Utilities->Capture Image produces a new window showing the image with the gridOverlay (as expected). It is at screen resolution and is an RGB image - but that's just fine for this application.
If it matters - the original image is 768x768x32bits. The "captured" image is 768x768xRGB
Am I perhaps confused about what ImagePlus.setOverlay() does? I was under the impression that it completely replaces any existing Overlay and installs a brand new one. That is the effect I see on the screen - until I try "Duplicate", "Save As", or "Flatten". Somehow they all manage to find the old Overlay. Is there some sort of "update" call that I'm missing?
Ah...in my cursor-handling code, I do call "updateAndDraw()", but in my gridOverlay code, I just "setOverlay". It appears on the screen, so I thought I was done. Do I need to do anything else?
...this looks promising...
This is also good news because if it only involves changes to the top-level code, I have an easier maintenance task. Changing the lower level code for the ImagePlus extension would cause ripples.
So...bottom line - what is the PROPER Java code to tell an ImagePlus to rip out an existing Overlay and install a new one. So that it is both displayed AND noticed by "Duplicate", et al.
Time for turkey...
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html