Skip to content

Commit

Permalink
2024.11.09 (1.54m23; Overlay.setMinStrokeWidth)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Nov 9, 2024
1 parent 8dceb82 commit b026637
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ImageJ extends Frame implements ActionListener,

/** Plugins should call IJ.getVersion() or IJ.getFullVersion() to get the version string. */
public static final String VERSION = "1.54m";
public static final String BUILD = "18";
public static final String BUILD = "23";
public static Color backgroundColor = new Color(237,237,237);
/** SansSerif, 12-point, plain font. */
public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);
Expand Down
11 changes: 10 additions & 1 deletion ij/gui/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Overlay implements Iterable<Roi> {
private boolean isCalibrationBar;
private boolean selectable = true;
private boolean draggable = true;
private double minStrokeWidth = -1;

/** Constructs an empty Overlay. */
public Overlay() {
Expand All @@ -36,8 +37,11 @@ public Overlay(Roi roi) {

/** Adds an ROI to this Overlay. */
public void add(Roi roi) {
if (roi!=null)
if (roi!=null) {
if (minStrokeWidth>=0)
roi.setMinStrokeWidth(minStrokeWidth);
list.add(roi);
}
}

/** Adds an ROI to this Overlay using the specified name. */
Expand Down Expand Up @@ -479,6 +483,11 @@ public void setDraggable(boolean draggable) {
this.draggable = draggable;
}

/** Sets the minimum scaled stroke width (default is 0.05). */
public void setMinStrokeWidth(double minWidth) {
minStrokeWidth = minWidth;
}

/** Returns 'true' if ROIs in this overlay can be dragged by their labels. */
public boolean isDraggable() {
return draggable;
Expand Down
11 changes: 10 additions & 1 deletion ij/gui/Roi.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class Roi extends Object implements Cloneable, java.io.Serializable, Iter
private static int defaultGroup; // zero is no specific group
private static Color groupColor;
private static double defaultStrokeWidth;
private static float defaultMinStrokeWidth = 0.05f;
private float minStrokeWidth = defaultMinStrokeWidth;
private static String groupNamesString = Prefs.get(NAMES_KEY, null);
private static String[] groupNames;
private static boolean groupNamesChanged;
Expand Down Expand Up @@ -2065,6 +2067,7 @@ public void setNonScalable(boolean nonScalable) {
* @see #setUnscalableStrokeWidth(double)
* @see #setStrokeColor(Color)
* @see ij.ImagePlus#setOverlay(ij.gui.Overlay)
* @see setMineStrokeWidth(double)
*/
public void setStrokeWidth(float strokeWidth) {
if (strokeWidth<0f)
Expand All @@ -2091,6 +2094,11 @@ public void setStrokeWidth(double strokeWidth) {
setStrokeWidth((float)strokeWidth);
}

/** Sets the minimum scaled stroke width (default=0.05). */
public void setMinStrokeWidth(double minWidth) {
minStrokeWidth = (float)minWidth;
}

/** Sets the width of the line used to draw this ROI and
* prevents the width from increasing when the image
* is zoomed.
Expand Down Expand Up @@ -2132,7 +2140,8 @@ protected BasicStroke getScaledStroke() {
double mag = ic.getMagnification();
if (mag!=1.0) {
float width = (float)(stroke.getLineWidth()*mag);
//return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
if (width<minStrokeWidth)
width = minStrokeWidth;
return new BasicStroke(width, stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase());
} else
return stroke;
Expand Down
37 changes: 21 additions & 16 deletions ij/macro/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6765,16 +6765,6 @@ else if (name.equals("paste")) {
getImage().setOverlay(overlayClipboard);
return Double.NaN;
} else if (name.equals("pasteAndMerge")) {
/*
interp.getParens();
if (overlayClipboard==null)
interp.error("Overlay clipboard empty");
Overlay overlay = getImage().getOverlay();
if (overlay!=null)
getImage().setOverlay(overlay.add(overlayClipboard));
else
getImage().setOverlay(overlayClipboard);
*/
return Double.NaN;
} else if (name.equals("drawLabels")) {
overlayDrawLabels = getBooleanArg();
Expand All @@ -6798,11 +6788,13 @@ else if (name.equals("paste")) {
if (overlay==null && name.equals("size")) {
interp.getParens();
return 0.0;
} else if (name.equals("hidden"))
} else if (name.equals("hidden")) {
return overlay!=null && imp.getHideOverlay()?1.0:0.0;
else if (name.equals("addSelection") || name.equals("addRoi"))
} else if (name.equals("setMinStrokeWidth")) {
return setMinStrokeWidth(imp, overlay);
} else if (name.equals("addSelection") || name.equals("addRoi")) {
return overlayAddSelection(imp, overlay);
else if (name.equals("setPosition")) {
} else if (name.equals("setPosition")) {
addDrawingToOverlay(imp);
return overlaySetPosition(overlay);
} else if (name.equals("setFillColor"))
Expand Down Expand Up @@ -6954,7 +6946,7 @@ private double activateSelection(ImagePlus imp, Overlay overlay, boolean wait) {
ResultsTable.selectRow(roi);
return Double.NaN;
}

private double getOverlayElementBounds(Overlay overlay) {
int index = (int)getFirstArg();
Variable x = getNextVariable();
Expand All @@ -6971,7 +6963,7 @@ private double getOverlayElementBounds(Overlay overlay) {
height.setValue(r.height);
return Double.NaN;
}

double overlayAddSelection(ImagePlus imp, Overlay overlay) {
String strokeColor = null;
double strokeWidth = Double.NaN;
Expand Down Expand Up @@ -7014,6 +7006,16 @@ private double getOverlayElementBounds(Overlay overlay) {
return Double.NaN;
}

private double setMinStrokeWidth(ImagePlus imp, Overlay overlay) {
double minStrokeWidth = getArg();
if (overlay==null) {
overlay = new Overlay();
imp.setOverlay(overlay);
}
overlay.setMinStrokeWidth(minStrokeWidth);
return Double.NaN;
}

double overlaySetPosition(Overlay overlay) {
int c=0, z=0, t=0;
int nargs = 1;
Expand Down Expand Up @@ -7813,7 +7815,10 @@ private Variable doRoi() {
return new Variable(Colors.colorToString(color));
}
ImagePlus imp = getImage();
if (name.equals("paste")) {
if (name.equals("setMinStrokeWidth")) {
setMinStrokeWidth(imp, imp.getOverlay());
return null;
} else if (name.equals("paste")) {
interp.getParens();
//IJ.log("paste: "+roiClipboard);
if (roiClipboard!=null)
Expand Down
3 changes: 2 additions & 1 deletion ij/process/StackConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public void convertToGray16() {
}
((CompositeImage)imp).setLuts(luts);
imp.updateAndDraw();
}
} else if (scale)
imp.setDisplayRange(0,65535);
}

/** Converts this Stack to 32-bit (float) grayscale. */
Expand Down
8 changes: 7 additions & 1 deletion release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
<body>


<li> <u>1.54m16 28 October 2024</u>
<li> <u>1.54m23 9 November 2024</u>
<ul>
<li> Thanks to Kenneth Sloan, added the Overlay.setMinStrokeWidth(minStrokeWidth)
macro function and Java method that you can use to specify a
minimum scaled stroke width
(<a href="http://wsr.imagej.net/macros/Polygons.ijm">example</a>). DOC
<li> Thanks to Michael Cammer, the <i>Orthogonal Views</i> command
no longer removes overlays.
<li> Thanks to 'Patricia' and Herbie Gluender, the
Expand Down Expand Up @@ -36,6 +40,8 @@
-batch option.
<li> Thanks to Guenter Pudmich, fixed bug with the calculation
of 16 and 32 bit histogram bin widths.
<li> Thanks to Gilles Carpentier, fixed several Hyperstack type
conversion bugs.
</ul>

<li> <u>1.54k 15 September 2024</u>
Expand Down

0 comments on commit b026637

Please sign in to comment.