Login  Register

Re: ImageJ undo notification

Posted by Jon Harman on Jul 13, 2007; 1:04am
URL: http://imagej.273.s1.nabble.com/ImageJ-undo-notification-tp3698860p3698862.html

Hi Michael,

I find the undo code to be pretty opaque, thanks for looking at it.

 From what you said would a simple solution be to add a method to check
whatToUndo?
Say a method like

    public static int status() {
    return whatToUndo;
        }

My code does the following to set up for undo:
Undo.setup(Undo.COMPOUND_FILTER, imp);
I guess that sets whatToUndo = COMPOUND_FILTER.
So my code could check it to see if it was "nothing" indicating that an
undo had been done.

Jon

Michael Schmid wrote:
 > Hi Jon,
 >
 >> Just wondering if there is any way my plugin can find out if
 >> undo has been done on an image.
 > In Undo.java, the whatToUndo variable is private, so you can't
 > use it to determine whether undo has been done or not.
 >
 > I see one possibility for a workaround:
 >
 > If you have a PlugInFilter that does not specify NO_CHANGES or
 > NO_UNDO, and you are working on a single image (not a full stack), a
 > snapshot (copy of the pixels) will be created when you run the filter.
 > If your filter really changes the image (if it is not a "null"
 > operation such as adding zero), the snapshot will be different
 > from the image after filtering, but equal to the image after
 > undo. So something like the following may work:
 > boolean undoDone = java.utils.Arrays.equals(ip.getPixels(),
ip.getSnapshotPixels())
 > An easier (though not 100% safe) way would be to remember a
 > hashcode of the pixels array after each operation and see whether
 > it has changed or been reverted to the previous state.
 >
 >> More generally I'd like to know the sequence of ImageJ commands
 >> that have been performed on an image.  Does ImageJ keep a log
 >> of this somewhere?
 > No, unless the Macro Recorder is active. As far as I understand
 > the Recorder.java code, the recorder has no public methods that
 > would allow reading what it has recorded.
 >
 > Even in case we had a method like
 >   public String Recorder.getRecordedText()
 > you should not expect to get the history of an image from the
 > recorder: Some operations are not recorded, e.g. selecting an
 > image by clicking onto it. So you never know which image a
 > command was acting on.
 >
 > For your own plugins, you can of course store a log of each
 > operation in the info of the ImagePlus.
 >
 > Having such a feature in ImageJ would be nice, but I fear it
 > would be a hell of work to implement it (more than 20 source
 > files make calls to the Recorder).
 > Also, a really proper recording of the workflow would be close
 > to impossible. E.g., processing may need several images,
 > involve duplicating or the Image Calculator (or plugins)
 > combining images, etc.
 >
 > Regards,
 >
 > Michael
 >