public void build() { this.buildLines(); this.buildVector(); this.lineWidth = Math.round(roi.getStrokeWidth()); this.lineWidth = this.lineWidth < 1 ? 1 : this.lineWidth; }
private void drawRoundedRect(ImageProcessor ip) { int margin = (int)getStrokeWidth()/2; BufferedImage bi = new BufferedImage(width+margin*2+1, height+margin*2+1, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g = bi.createGraphics(); if (stroke!=null) g.setStroke(stroke); g.drawRoundRect(margin, margin, width, height, cornerDiameter, cornerDiameter); ByteProcessor mask = new ByteProcessor(bi); ip.setRoi(x-margin, y-margin, width+margin*2+1, height+margin*2+1); ip.fill(mask); }
private void drawRoundedRect(ImageProcessor ip) { int margin = (int)getStrokeWidth()/2; BufferedImage bi = new BufferedImage(width+margin*2+1, height+margin*2+1, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g = bi.createGraphics(); if (stroke!=null) g.setStroke(stroke); g.drawRoundRect(margin, margin, width, height, cornerDiameter, cornerDiameter); ByteProcessor mask = new ByteProcessor(bi); ip.setRoi(x-margin, y-margin, width+margin*2+1, height+margin*2+1); ip.fill(mask); }
protected void updateClipRect() { clipX = (x<=oldX)?x:oldX; clipY = (y<=oldY)?y:oldY; clipWidth = ((x+width>=oldX+oldWidth)?x+width:oldX+oldWidth) - clipX + 1; clipHeight = ((y+height>=oldY+oldHeight)?y+height:oldY+oldHeight) - clipY + 1; int m = 3; if (ic!=null) { double mag = ic.getMagnification(); if (mag<1.0) m = (int)(4.0/mag); } m += clipRectMargin(); m = (int)(m+getStrokeWidth()*2); clipX-=m; clipY-=m; clipWidth+=m*2; clipHeight+=m*2; }
protected void updateClipRect() { clipX = (x<=oldX)?x:oldX; clipY = (y<=oldY)?y:oldY; clipWidth = ((x+width>=oldX+oldWidth)?x+width:oldX+oldWidth) - clipX + 1; clipHeight = ((y+height>=oldY+oldHeight)?y+height:oldY+oldHeight) - clipY + 1; int m = 3; if (ic!=null) { double mag = ic.getMagnification(); if (mag<1.0) m = (int)(4.0/mag); } m += clipRectMargin(); m = (int)(m+getStrokeWidth()*2); clipX-=m; clipY-=m; clipWidth+=m*2; clipHeight+=m*2; }
/** Copy the attributes (outline color, fill color, outline width) of 'roi2' to the this selection. */ public void copyAttributes(Roi roi2) { this. strokeColor = roi2. strokeColor; this.fillColor = roi2.fillColor; this.setStrokeWidth(roi2.getStrokeWidth()); this.setName(roi2.getName()); }
/** Copy the attributes (outline color, fill color, outline width) of 'roi2' to the this selection. */ public void copyAttributes(Roi roi2) { this. strokeColor = roi2. strokeColor; this.fillColor = roi2.fillColor; this.setStrokeWidth(roi2.getStrokeWidth()); this.setName(roi2.getName()); }
/** Draws the selection outline on the specified ImageProcessor. @see ij.process.ImageProcessor#setColor @see ij.process.ImageProcessor#setLineWidth */ public void drawPixels(ImageProcessor ip) { endPaste(); int saveWidth = ip.getLineWidth(); if (getStrokeWidth()>1f) ip.setLineWidth((int)Math.round(getStrokeWidth())); if (cornerDiameter>0) drawRoundedRect(ip); else { if (ip.getLineWidth()==1) ip.drawRect(x, y, width+1, height+1); else ip.drawRect(x, y, width, height); } ip.setLineWidth(saveWidth); if (Line.getWidth()>1 || getStrokeWidth()>1) updateFullWindow = true; }
private void assignPropertiesToOverlay(final Overlay overlay, final Roi roi) { overlay.setName(roi.getName()); overlay.setLineWidth(roi.getStrokeWidth()); final Color strokeColor = roi.getStrokeColor(); final Color fillColor = roi.getFillColor(); if (strokeColor != null) { overlay.setLineColor(AWTColors.getColorRGB(strokeColor)); } if (fillColor != null) { overlay.setFillColor(AWTColors.getColorRGBA(fillColor)); overlay.setAlpha(fillColor.getAlpha()); } }
/** * @deprecated * replaced by ImageProcessor.fill(Roi) */ public void fill(ImageProcessor ip) { ip.setColor(Toolbar.getForegroundColor()); if (isLineSelection()) { if (isStraightLine() && roi.getStrokeWidth()>1 && !(roi instanceof Arrow)) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(ip); } else ip.fill(); // fill with foreground color }
/** * @deprecated * replaced by ImageProcessor.fill(Roi) */ public void fill(ImageProcessor ip) { ip.setColor(Toolbar.getForegroundColor()); if (isLineSelection()) { if (isStraightLine() && roi.getStrokeWidth()>1 && !(roi instanceof Arrow)) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(ip); } else ip.fill(); // fill with foreground color }
public void clear(ImageProcessor ip) { ip.setColor(Toolbar.getBackgroundColor()); if (isLineSelection()) { if (isStraightLine() && roi.getStrokeWidth()>1) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(); } else if (roi!=null && roi instanceof TextRoi) ((TextRoi)roi).clear(ip); else ip.fill(); // fill with background color ip.setColor(Toolbar.getForegroundColor()); }
public void clear(ImageProcessor ip) { ip.setColor(Toolbar.getBackgroundColor()); if (isLineSelection()) { if (isStraightLine() && roi.getStrokeWidth()>1) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(); } else if (roi!=null && roi instanceof TextRoi) ((TextRoi)roi).clear(ip); else ip.fill(); // fill with background color ip.setColor(Toolbar.getForegroundColor()); }
Roi convertLineToPolygon(Roi roi, ImageProcessor ip) { if (roi==null) return null; ip.resetRoi(); ip.setColor(0); ip.fill(); ip.setColor(255); if (roi.getType()==Roi.LINE && roi.getStrokeWidth()>1) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(ip); //new ImagePlus("ip", ip.duplicate()).show(); ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); return tts.convert(ip); }
Roi convertLineToPolygon(Roi roi, ImageProcessor ip) { if (roi==null) return null; ip.resetRoi(); ip.setColor(0); ip.fill(); ip.setColor(255); if (roi.getType()==Roi.LINE && roi.getStrokeWidth()>1) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(ip); //new ImagePlus("ip", ip.duplicate()).show(); ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); return tts.convert(ip); }
private void drawRoi(Roi roi, Graphics g) { if (roi==currentRoi) { Color lineColor = roi.getStrokeColor(); Color fillColor = roi.getFillColor(); float lineWidth = roi.getStrokeWidth(); roi.setStrokeColor(null); roi.setFillColor(null); boolean strokeSet = roi.getStroke()!=null; if (strokeSet) roi.setStrokeWidth(1); roi.draw(g); roi.setStrokeColor(lineColor); if (strokeSet) roi.setStrokeWidth(lineWidth); roi.setFillColor(fillColor); currentRoi = null; } else roi.draw(g); }
/** Fills the ROI with the current fill/draw value. * @see #setColor(Color) * @see #setValue(double) * @see #fill(Roi) */ public void fill(Roi roi) { if (roi!=null && roi.isLine()) { if ((roi instanceof Line) && roi.getStrokeWidth()>1 && !(roi instanceof Arrow)) fillPolygon(roi.getPolygon()); else roi.drawPixels(this); return; } ImageProcessor m = getMask(); Rectangle r = getRoi(); setRoi(roi); fill(getMask()); setMask(m); setRoi(r); }
private void drawRoi(Roi roi, Graphics g) { if (roi==currentRoi) { Color lineColor = roi.getStrokeColor(); Color fillColor = roi.getFillColor(); float lineWidth = roi.getStrokeWidth(); roi.setStrokeColor(null); roi.setFillColor(null); boolean strokeSet = roi.getStroke()!=null; if (strokeSet) roi.setStrokeWidth(1); roi.draw(g); roi.setStrokeColor(lineColor); if (strokeSet) roi.setStrokeWidth(lineWidth); roi.setFillColor(fillColor); currentRoi = null; } else roi.draw(g); }
void getLine() { Variable vx1 = getFirstVariable(); Variable vy1 = getNextVariable(); Variable vx2 = getNextVariable(); Variable vy2 = getNextVariable(); Variable lineWidth = getLastVariable(); ImagePlus imp = getImage(); double x1=-1, y1=-1, x2=-1, y2=-1; Roi roi = imp.getRoi(); if (roi!=null && roi.getType()==Roi.LINE) { Line line = (Line)roi; x1=line.x1d; y1=line.y1d; x2=line.x2d; y2=line.y2d; } vx1.setValue(x1); vy1.setValue(y1); vx2.setValue(x2); vy2.setValue(y2); lineWidth.setValue(roi!=null?roi.getStrokeWidth():1); }
void getLine() { Variable vx1 = getFirstVariable(); Variable vy1 = getNextVariable(); Variable vx2 = getNextVariable(); Variable vy2 = getNextVariable(); Variable lineWidth = getLastVariable(); ImagePlus imp = getImage(); double x1=-1, y1=-1, x2=-1, y2=-1; Roi roi = imp.getRoi(); if (roi!=null && roi.getType()==Roi.LINE) { Line line = (Line)roi; x1=line.x1d; y1=line.y1d; x2=line.x2d; y2=line.y2d; } vx1.setValue(x1); vy1.setValue(y1); vx2.setValue(x2); vy2.setValue(y2); lineWidth.setValue(roi!=null?roi.getStrokeWidth():1); }