Example #1
0
 // Added by Marcel Boeglin 2013.09.22
 private Overlay projectHyperStackRois(Overlay overlay) {
   if (overlay == null) return null;
   int t1 = imp.getFrame();
   int channels = projImage.getNChannels();
   int slices = 1;
   int frames = projImage.getNFrames();
   Overlay overlay2 = new Overlay();
   Roi roi;
   int c, z, t;
   int size = channels * slices * frames;
   for (Roi r : overlay.toArray()) {
     c = r.getCPosition();
     z = r.getZPosition();
     t = r.getTPosition();
     roi = (Roi) r.clone();
     if (size == channels) { // current time frame
       if (z >= startSlice && z <= stopSlice && t == t1 || c == 0) {
         roi.setPosition(c);
         overlay2.add(roi);
       }
     } else if (size == frames * channels) { // all time frames
       if (z >= startSlice && z <= stopSlice) roi.setPosition(c, 1, t);
       else if (z == 0) roi.setPosition(c, 0, t);
       else continue;
       overlay2.add(roi);
     }
   }
   return overlay2;
 }
 /** @deprecated replaced by ImagePlus.setOverlay(ij.gui.Overlay) */
 public void setDisplayList(Vector list) {
   if (list != null) {
     Overlay list2 = new Overlay();
     list2.setVector(list);
     setOverlay(list2);
   } else setOverlay(null);
   if (overlay != null)
     overlay.drawLabels(overlay.size() > 0 && overlay.get(0).getStrokeColor() == null);
   else customRoi = false;
   repaint();
 }
 /** Return the ROI Manager "Show All" list as an overlay. */
 public Overlay getShowAllList() {
   if (!showAllROIs) return null;
   if (showAllList != null) return showAllList;
   RoiManager rm = RoiManager.getInstance();
   if (rm == null) return null;
   Roi[] rois = rm.getRoisAsArray();
   if (rois.length == 0) return null;
   Overlay overlay = new Overlay();
   for (int i = 0; i < rois.length; i++) overlay.add((Roi) rois[i].clone());
   return overlay;
 }
 /** @deprecated replaced by ImagePlus.setOverlay(Shape, Color, BasicStroke) */
 public void setDisplayList(Shape shape, Color color, BasicStroke stroke) {
   if (shape == null) {
     setOverlay(null);
     return;
   }
   Roi roi = new ShapeRoi(shape);
   roi.setStrokeColor(color);
   roi.setStroke(stroke);
   Overlay list = new Overlay();
   list.add(roi);
   setOverlay(list);
 }
Example #5
0
 // Added by Marcel Boeglin 2013.09.23
 private Overlay projectStackRois(Overlay overlay) {
   if (overlay == null) return null;
   Overlay overlay2 = new Overlay();
   Roi roi;
   int s;
   for (Roi r : overlay.toArray()) {
     s = r.getPosition();
     roi = (Roi) r.clone();
     if (s >= startSlice && s <= stopSlice || s == 0) {
       roi.setPosition(s);
       overlay2.add(roi);
     }
   }
   return overlay2;
 }
 void drawAllROIs(Graphics g) {
   RoiManager rm = RoiManager.getInstance();
   if (rm == null) {
     rm = Interpreter.getBatchModeRoiManager();
     if (rm != null && rm.getList().getItemCount() == 0) rm = null;
   }
   if (rm == null) {
     // if (showAllList!=null)
     //	overlay = showAllList;
     showAllROIs = false;
     repaint();
     return;
   }
   initGraphics(g, null, showAllColor);
   Hashtable rois = rm.getROIs();
   java.awt.List list = rm.getList();
   boolean drawLabels = rm.getDrawLabels();
   currentRoi = null;
   int n = list.getItemCount();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " \"Show All\" ROIs");
   if (labelRects == null || labelRects.length != n) labelRects = new Rectangle[n];
   if (!drawLabels) showAllList = new Overlay();
   else showAllList = null;
   if (imp == null) return;
   int currentImage = imp.getCurrentSlice();
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = Prefs.useNamesAsLabels;
   for (int i = 0; i < n; i++) {
     String label = list.getItem(i);
     Roi roi = (Roi) rois.get(label);
     if (roi == null) continue;
     if (showAllList != null) showAllList.add(roi);
     if (i < 200 && drawLabels && roi == imp.getRoi()) currentRoi = roi;
     if (Prefs.showAllSliceOnly && imp.getStackSize() > 1) {
       if (hyperstack && roi.getPosition() == 0) {
         int c = roi.getCPosition();
         int z = roi.getZPosition();
         int t = roi.getTPosition();
         if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame))
           drawRoi(g, roi, drawLabels ? i : -1);
       } else {
         int position = roi.getPosition();
         if (position == 0) position = getSliceNumber(roi.getName());
         if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i : -1);
       }
     } else drawRoi(g, roi, drawLabels ? i : -1);
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
Example #7
0
 private boolean deleteOverlayRoi(ImagePlus imp) {
   if (imp == null) return false;
   Overlay overlay = null;
   ImageCanvas ic = imp.getCanvas();
   if (ic != null) overlay = ic.getShowAllList();
   if (overlay == null) overlay = imp.getOverlay();
   if (overlay == null) return false;
   Roi roi = imp.getRoi();
   for (int i = 0; i < overlay.size(); i++) {
     Roi roi2 = overlay.get(i);
     if (roi2 == roi) {
       overlay.remove(i);
       imp.deleteRoi();
       ic = imp.getCanvas();
       if (ic != null) ic.roiManagerSelect(roi, true);
       return true;
     }
   }
   return false;
 }
Example #8
0
 // Added by Marcel Boeglin 2013.09.22
 private Overlay projectRGBHyperStackRois(Overlay overlay) {
   if (overlay == null) return null;
   int frames = projImage.getNFrames();
   int t1 = imp.getFrame();
   Overlay overlay2 = new Overlay();
   Roi roi;
   int c, z, t;
   for (Roi r : overlay.toArray()) {
     c = r.getCPosition();
     z = r.getZPosition();
     t = r.getTPosition();
     roi = (Roi) r.clone();
     if (z >= startSlice && z <= stopSlice || z == 0 || c == 0 || t == 0) {
       if (frames == 1 && t != t1 && t != 0) // current time frame
       continue;
       roi.setPosition(t);
       overlay2.add(roi);
     }
   }
   return overlay2;
 }
 void drawOverlay(Graphics g) {
   if (imp != null && imp.getHideOverlay()) return;
   Color labelColor = overlay.getLabelColor();
   if (labelColor == null) labelColor = Color.white;
   initGraphics(g, labelColor, Roi.getColor());
   int n = overlay.size();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " ROI display list");
   int currentImage = imp != null ? imp.getCurrentSlice() : -1;
   if (imp.getStackSize() == 1) currentImage = -1;
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = overlay.getDrawNames();
   boolean drawLabels = drawNames || overlay.getDrawLabels();
   for (int i = 0; i < n; i++) {
     if (overlay == null) break;
     Roi roi = overlay.get(i);
     if (hyperstack && roi.getPosition() == 0) {
       int c = roi.getCPosition();
       int z = roi.getZPosition();
       int t = roi.getTPosition();
       if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame))
         drawRoi(g, roi, drawLabels ? i + LIST_OFFSET : -1);
     } else {
       int position = roi.getPosition();
       if (position == 0 || position == currentImage)
         drawRoi(g, roi, drawLabels ? i + LIST_OFFSET : -1);
     }
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
Example #10
0
 void initGraphics(Graphics g, Color textColor, Color defaultColor) {
   if (smallFont == null) {
     smallFont = new Font("SansSerif", Font.PLAIN, 9);
     largeFont = new Font("SansSerif", Font.PLAIN, 12);
   }
   if (textColor != null) {
     labelColor = textColor;
     if (overlay != null && overlay.getDrawBackgrounds())
       bgColor =
           new Color(
               255 - labelColor.getRed(), 255 - labelColor.getGreen(), 255 - labelColor.getBlue());
     else bgColor = null;
   } else {
     int red = defaultColor.getRed();
     int green = defaultColor.getGreen();
     int blue = defaultColor.getBlue();
     if ((red + green + blue) / 3 < 128) labelColor = Color.white;
     else labelColor = Color.black;
     bgColor = defaultColor;
   }
   this.defaultColor = defaultColor;
   g.setColor(defaultColor);
 }
Example #11
0
 /** @deprecated replaced by ImagePlus.getOverlay() */
 public Vector getDisplayList() {
   if (overlay == null) return null;
   Vector displayList = new Vector();
   for (int i = 0; i < overlay.size(); i++) displayList.add(overlay.get(i));
   return displayList;
 }
Example #12
0
 /** @deprecated replaced by ImagePlus.setOverlay(Roi, Color, int, Color) */
 public void setDisplayList(Roi roi, Color color) {
   roi.setStrokeColor(color);
   Overlay list = new Overlay();
   list.add(roi);
   setOverlay(list);
 }
Example #13
0
 /** Use ImagePlus.setOverlay(ij.gui.Overlay). */
 public void setOverlay(Overlay overlay) {
   this.overlay = overlay;
   if (overlay != null) font = overlay.getLabelsFont();
   repaint();
 }