public void runFilterPlugIn(Object theFilter, String cmd, String arg) { new PlugInFilterRunner(theFilter, cmd, arg); }
private void applyMacro(ImageProcessor ip) { if (macro2==null) return; macro = macro2; ip.setSliceNumber(pfr.getSliceNumber()); boolean showProgress = pfr.getSliceNumber()==1 && !Interpreter.isBatchMode(); applyMacro(ip, macro, showProgress); if (pfr.getSliceNumber()==1) ip.resetMinAndMax(); }
@Override public void roiModified(ImagePlus imp, int id) { if( imp == imagePlus ) { // set preview to false to restart plugin filter runner gd.getPreviewCheckbox().setState( false ); pfr.dialogItemChanged( gd, new ActionEvent( gd.getPreviewCheckbox(), ActionEvent.ACTION_PERFORMED, "Preview" ) ); } } };
/** stop the background process responsible for preview as fast as possible and wait until the preview thread has finished */ private void killPreview() { if (previewThread == null) return; synchronized (this) { previewThread.interrupt(); //ask for premature finishing (interrupt first -> no keepPreview) bgPreviewOn = false; //tell a possible background thread to terminate when it has finished if (roisForThread!=null) interruptRoiThreads(roisForThread); } waitForPreviewDone(); imp.setOverlay(originalOverlay); }
Thread bgThread = new Thread(this, command+" "+y1+"-"+y2); Rectangle roi2 = new Rectangle(roi.x, y1, roi.width, y2-y1+1); roisForThread.put(bgThread, duplicateProcessor(ip, roi2)); bgThread.start(); if (IJ.debugMode) IJ.log(" main thread "+y1+"-"+(roi.y+roi.height)); Rectangle roi2 = new Rectangle(roi.x, y1, roi.width, roi.y+roi.height-y1); ((PlugInFilter)theFilter).run(duplicateProcessor(ip, roi2)); // current thread does the rest pass++; if (roisForThread != null) { interruptRoiThreads(roisForThread); //interrupt all threads and join
if (!checkImagePlus(imp, flags, command)) return; // check whether the PlugInFilter can handle this image type if ((flags&PlugInFilter.NO_IMAGE_REQUIRED)!=0) flags = ((ExtendedPlugInFilter)theFilter).showDialog(imp, command, this); // D I A L O G (may include preview) } catch(Exception e) { killPreview(); if (Macro.MACRO_CANCELED.equals(e.getMessage())) throw new RuntimeException(Macro.MACRO_CANCELED); previewCheckbox!=null && previewCheckboxOn) { bgKeepPreview = true; waitForPreviewDone(); processedAsPreview = imp.getCurrentSlice(); } else { killPreview(); previewTime = 0; if (!doStack) { // single image FloatProcessor fp = null; prepareProcessor(ip, imp); announceSliceNumber(imp.getCurrentSlice()); if (theFilter instanceof ExtendedPlugInFilter) ((ExtendedPlugInFilter)theFilter).setNPasses(nPasses); processOneImage(ip, fp, snapshotDone); // may also set snapShotDone if ((flags&PlugInFilter.NO_CHANGES)==0) { // (filters doing no modifications don't change undo status) if (snapshotDone) processStack(startSlice, slices); // the current thread does the rest
/** Process a stack or part of it. The slice given by class variable * processedAsPreview remains unchanged. * @param firstSlice Slice number of the first slice to be processed * @param endSlice Slice number of the last slice to be processed */ private void processStack(int firstSlice, int endSlice) { ImageStack stack = imp.getStack(); ImageProcessor ip = stack.getProcessor(firstSlice); prepareProcessor(ip, imp); ip.setLineWidth(Line.getWidth()); //in contrast to imp.getProcessor, stack.getProcessor does not do this FloatProcessor fp = null; int slices = imp.getNSlices(); for (int i=firstSlice; i<=endSlice; i++) { if (i != processedAsPreview) { announceSliceNumber(i); ip.setPixels(stack.getPixels(i)); ip.setSliceNumber(i); processOneImage(ip, fp, false); if (IJ.escapePressed()) {IJ.beep(); break;} } } }
killPreview(); return true; } else
if ((flags&PlugInFilter.SNAPSHOT)!=0) fp.snapshot(); if (doStack) IJ.showProgress(pass/(double)nPasses); processChannelUsingThreads(fp); if (thread.isInterrupted()) return; if ((flags&PlugInFilter.NO_CHANGES)==0) ipChanged = true; if (doStack) IJ.showProgress(pass/(double)nPasses); processChannelUsingThreads(ip);
if (!checkImagePlus(imp, flags, command)) return; // check whether the PlugInFilter can handle this image type if ((flags&PlugInFilter.NO_IMAGE_REQUIRED)!=0) flags = ((ExtendedPlugInFilter)theFilter).showDialog(imp, command, this); // D I A L O G (may include preview) } catch(Exception e) { killPreview(); if (Macro.MACRO_CANCELED.equals(e.getMessage())) throw new RuntimeException(Macro.MACRO_CANCELED); previewCheckbox!=null && previewCheckboxOn) { bgKeepPreview = true; waitForPreviewDone(); processedAsPreview = imp.getCurrentSlice(); } else { killPreview(); previewTime = 0; if (!doStack) { // single image FloatProcessor fp = null; prepareProcessor(ip, imp); announceSliceNumber(imp.getCurrentSlice()); if (theFilter instanceof ExtendedPlugInFilter) ((ExtendedPlugInFilter)theFilter).setNPasses(nPasses); processOneImage(ip, fp, snapshotDone); // may also set snapShotDone if ((flags&PlugInFilter.NO_CHANGES)==0) { // (filters doing no modifications don't change undo status) if (snapshotDone) processStack(startSlice, slices); // the current thread does the rest
/** Process a stack or part of it. The slice given by class variable * processedAsPreview remains unchanged. * @param firstSlice Slice number of the first slice to be processed * @param endSlice Slice number of the last slice to be processed */ private void processStack(int firstSlice, int endSlice) { ImageStack stack = imp.getStack(); ImageProcessor ip = stack.getProcessor(firstSlice); prepareProcessor(ip, imp); ip.setLineWidth(Line.getWidth()); //in contrast to imp.getProcessor, stack.getProcessor does not do this FloatProcessor fp = null; int slices = imp.getNSlices(); for (int i=firstSlice; i<=endSlice; i++) { if (i != processedAsPreview) { announceSliceNumber(i); ip.setPixels(stack.getPixels(i)); ip.setSliceNumber(i); processOneImage(ip, fp, false); if (IJ.escapePressed()) {IJ.beep(); break;} } } }
/** stop the background process responsible for preview as fast as possible and wait until the preview thread has finished */ private void killPreview() { if (previewThread == null) return; synchronized (this) { previewThread.interrupt(); //ask for premature finishing (interrupt first -> no keepPreview) bgPreviewOn = false; //tell a possible background thread to terminate when it has finished if (roisForThread!=null) interruptRoiThreads(roisForThread); } waitForPreviewDone(); imp.setOverlay(originalOverlay); }
Thread bgThread = new Thread(this, command+" "+y1+"-"+y2); Rectangle roi2 = new Rectangle(roi.x, y1, roi.width, y2-y1+1); roisForThread.put(bgThread, duplicateProcessor(ip, roi2)); bgThread.start(); if (IJ.debugMode) IJ.log(" main thread "+y1+"-"+(roi.y+roi.height)); Rectangle roi2 = new Rectangle(roi.x, y1, roi.width, roi.y+roi.height-y1); ((PlugInFilter)theFilter).run(duplicateProcessor(ip, roi2)); // current thread does the rest pass++; if (roisForThread != null) { interruptRoiThreads(roisForThread); //interrupt all threads and join
killPreview(); return true; } else
if ((flags&PlugInFilter.SNAPSHOT)!=0) fp.snapshot(); if (doStack) IJ.showProgress(pass/(double)nPasses); processChannelUsingThreads(fp); if (thread.isInterrupted()) return; if ((flags&PlugInFilter.NO_CHANGES)==0) ipChanged = true; if (doStack) IJ.showProgress(pass/(double)nPasses); processChannelUsingThreads(ip);
originalOverlay = imp.getOverlay(); FloatProcessor fp = null; prepareProcessor(ip, imp); announceSliceNumber(imp.getCurrentSlice()); if (!snapshotDone && (flags&PlugInFilter.NO_CHANGES)==0) { ip.snapshot(); break interruptable; processOneImage(ip, fp, true); // P R O C E S S (sets ipChanged) IJ.showProgress(1.0); if (thread.isInterrupted())
public void runFilterPlugIn(Object theFilter, String cmd, String arg) { new PlugInFilterRunner(theFilter, cmd, arg); }
private void applyMacro(ImageProcessor ip) { if (macro2==null) return; macro = macro2; ip.setSliceNumber(pfr.getSliceNumber()); boolean showProgress = pfr.getSliceNumber()==1 && !Interpreter.isBatchMode(); applyMacro(ip, macro, showProgress); if (pfr.getSliceNumber()==1) ip.resetMinAndMax(); }
@Override public void roiModified( ImagePlus imp, int id ) { if( imp == imagePlus ) { // set preview to false to restart plugin filter runner gd.getPreviewCheckbox().setState( false ); pfr.dialogItemChanged( gd, new ActionEvent( gd.getPreviewCheckbox(), ActionEvent.ACTION_PERFORMED, "Preview" ) ); } } };
originalOverlay = imp.getOverlay(); FloatProcessor fp = null; prepareProcessor(ip, imp); announceSliceNumber(imp.getCurrentSlice()); if (!snapshotDone && (flags&PlugInFilter.NO_CHANGES)==0) { ip.snapshot(); break interruptable; processOneImage(ip, fp, true); // P R O C E S S (sets ipChanged) IJ.showProgress(1.0); if (thread.isInterrupted())