Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 private void drawSpline(
     Graphics g,
     float[] xpoints,
     float[] ypoints,
     int npoints,
     boolean closed,
     boolean fill,
     boolean isActiveOverlayRoi) {
   double srcx = 0.0, srcy = 0.9, mag = 1.0;
   if (ic != null) {
     Rectangle srcRect = ic.getSrcRect();
     srcx = srcRect.x;
     srcy = srcRect.y;
     mag = ic.getMagnification();
   }
   double xd = x, yd = y;
   Graphics2D g2d = (Graphics2D) g;
   GeneralPath path = new GeneralPath();
   double offset = getOffset(0.5);
   if (mag == 1.0 && srcx == 0.0 && srcy == 0.0) {
     path.moveTo(xpoints[0] + xd, ypoints[0] + yd);
     for (int i = 1; i < npoints; i++) path.lineTo(xpoints[i] + xd, ypoints[i] + yd);
   } else {
     path.moveTo((xpoints[0] - srcx + xd) * mag + offset, (ypoints[0] - srcy + yd + offset) * mag);
     for (int i = 1; i < npoints; i++)
       path.lineTo(
           (xpoints[i] - srcx + xd + offset) * mag, (ypoints[i] - srcy + yd + offset) * mag);
   }
   if (closed)
     path.lineTo((xpoints[0] - srcx + xd + offset) * mag, (ypoints[0] - srcy + yd + offset) * mag);
   if (fill) {
     if (isActiveOverlayRoi) {
       g2d.setColor(Color.cyan);
       g2d.draw(path);
     } else g2d.fill(path);
   } else g2d.draw(path);
 }
Esempio n. 3
0
 public void draw(Graphics g) {
   Color color = strokeColor != null ? strokeColor : ROIColor;
   if (fillColor != null) color = fillColor;
   g.setColor(color);
   mag = getMagnification();
   int sw = (int) (width * mag);
   int sh = (int) (height * mag);
   int sw2 = (int) (0.14645 * width * mag);
   int sh2 = (int) (0.14645 * height * mag);
   int sx1 = screenX(x);
   int sy1 = screenY(y);
   int sx2 = sx1 + sw / 2;
   int sy2 = sy1 + sh / 2;
   int sx3 = sx1 + sw;
   int sy3 = sy1 + sh;
   Graphics2D g2d = (Graphics2D) g;
   if (stroke != null) g2d.setStroke(getScaledStroke());
   if (fillColor != null) g.fillOval(sx1, sy1, sw, sh);
   else g.drawOval(sx1, sy1, sw, sh);
   if (state != CONSTRUCTING && clipboard == null && !overlay) {
     int size2 = HANDLE_SIZE / 2;
     drawHandle(g, sx1 + sw2 - size2, sy1 + sh2 - size2);
     drawHandle(g, sx3 - sw2 - size2, sy1 + sh2 - size2);
     drawHandle(g, sx3 - sw2 - size2, sy3 - sh2 - size2);
     drawHandle(g, sx1 + sw2 - size2, sy3 - sh2 - size2);
     drawHandle(g, sx2 - size2, sy1 - size2);
     drawHandle(g, sx3 - size2, sy2 - size2);
     drawHandle(g, sx2 - size2, sy3 - size2);
     drawHandle(g, sx1 - size2, sy2 - size2);
   }
   drawPreviousRoi(g);
   if (updateFullWindow) {
     updateFullWindow = false;
     imp.draw();
   }
   if (state != NORMAL) showStatus();
 }
Esempio n. 4
0
 void drawZoomIndicator(Graphics g) {
   int x1 = 10;
   int y1 = 10;
   double aspectRatio = (double) imageHeight / imageWidth;
   int w1 = 64;
   if (aspectRatio > 1.0) w1 = (int) (w1 / aspectRatio);
   int h1 = (int) (w1 * aspectRatio);
   if (w1 < 4) w1 = 4;
   if (h1 < 4) h1 = 4;
   int w2 = (int) (w1 * ((double) srcRect.width / imageWidth));
   int h2 = (int) (h1 * ((double) srcRect.height / imageHeight));
   if (w2 < 1) w2 = 1;
   if (h2 < 1) h2 = 1;
   int x2 = (int) (w1 * ((double) srcRect.x / imageWidth));
   int y2 = (int) (h1 * ((double) srcRect.y / imageHeight));
   if (zoomIndicatorColor == null) zoomIndicatorColor = new Color(128, 128, 255);
   g.setColor(zoomIndicatorColor);
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   g.drawRect(x1, y1, w1, h1);
   if (w2 * h2 <= 200 || w2 < 10 || h2 < 10) g.fillRect(x1 + x2, y1 + y2, w2, h2);
   else g.drawRect(x1 + x2, y1 + y2, w2, h2);
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 public void draw(Graphics g) {
   updatePolygon();
   Color color = strokeColor != null ? strokeColor : ROIColor;
   boolean hasHandles = xSpline != null || type == POLYGON || type == POLYLINE || type == ANGLE;
   boolean isActiveOverlayRoi = !overlay && isActiveOverlayRoi();
   if (isActiveOverlayRoi && !hasHandles) {
     if (color == Color.cyan) color = Color.magenta;
     else color = Color.cyan;
   }
   boolean fill = false;
   mag = getMagnification();
   if (fillColor != null && !isLine() && state != CONSTRUCTING) {
     color = fillColor;
     fill = true;
   }
   g.setColor(color);
   Graphics2D g2d = (Graphics2D) g;
   if (stroke != null && !isActiveOverlayRoi) g2d.setStroke(getScaledStroke());
   if (xSpline != null) {
     if (type == POLYLINE || type == FREELINE) {
       drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         drawSpline(g, xSpline, ySpline, splinePoints, false, fill, isActiveOverlayRoi);
       }
     } else drawSpline(g, xSpline, ySpline, splinePoints, true, fill, isActiveOverlayRoi);
   } else {
     if (type == POLYLINE || type == FREELINE || type == ANGLE || state == CONSTRUCTING) {
       g.drawPolyline(xp2, yp2, nPoints);
       if (wideLine && !overlay) {
         g2d.setStroke(onePixelWide);
         g.setColor(getColor());
         g.drawPolyline(xp2, yp2, nPoints);
       }
     } else {
       if (fill) {
         if (isActiveOverlayRoi) {
           g.setColor(Color.cyan);
           g.drawPolygon(xp2, yp2, nPoints);
         } else g.fillPolygon(xp2, yp2, nPoints);
       } else g.drawPolygon(xp2, yp2, nPoints);
     }
     if (state == CONSTRUCTING && type != FREEROI && type != FREELINE) drawStartBox(g);
   }
   if (hasHandles && state != CONSTRUCTING && clipboard == null && !overlay) {
     int size2 = HANDLE_SIZE / 2;
     if (activeHandle > 0)
       drawHandle(g, xp2[activeHandle - 1] - size2, yp2[activeHandle - 1] - size2);
     if (activeHandle < nPoints - 1)
       drawHandle(g, xp2[activeHandle + 1] - size2, yp2[activeHandle + 1] - size2);
     handleColor = strokeColor != null ? strokeColor : ROIColor;
     drawHandle(g, xp2[0] - size2, yp2[0] - size2);
     handleColor = Color.white;
     for (int i = 1; i < nPoints; i++) drawHandle(g, xp2[i] - size2, yp2[i] - size2);
   }
   drawPreviousRoi(g);
   if (!(state == MOVING_HANDLE || state == CONSTRUCTING || state == NORMAL)) showStatus();
   if (updateFullWindow) {
     updateFullWindow = false;
     imp.draw();
   }
 }