Skip to content

Commit

Permalink
correct return object
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 1, 2024
1 parent 7abb47f commit cae6b94
Showing 1 changed file with 75 additions and 14 deletions.
89 changes: 75 additions & 14 deletions src/main/java/ai/nets/samj/ij/ui/Consumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand All @@ -28,6 +29,7 @@
import ij.gui.ImageCanvas;
import ij.gui.ImageWindow;
import ij.gui.Overlay;
import ij.gui.PointRoi;
import ij.gui.PolygonRoi;
import ij.gui.Roi;
import ij.gui.Toolbar;
Expand Down Expand Up @@ -237,16 +239,6 @@ public List<Rectangle> getRectRoisOnFocusImage() {
list.add(roi.getBounds());
return list;
}

private List<Rectangle> getRectRoisFromRoiManager() {
List<Rectangle> list = new ArrayList<Rectangle>();
Roi[] rois = RoiManager.getInstance().getRoisAsArray();
if (rois.length == 0)
return list;
list = Arrays.stream(rois).filter(rr -> rr.getType() != Roi.RECTANGLE)
.map(rr -> rr.getBounds()).collect(Collectors.toList());
return list;
}

@Override
public List<int[]> getPointRoisOnFocusImage() {
Expand All @@ -256,12 +248,80 @@ public List<int[]> getPointRoisOnFocusImage() {
return list;
if (roi.getType() != Roi.POINT)
return list;
while (roi.iterator().hasNext()) {
java.awt.Point p = roi.iterator().next();
Iterator<java.awt.Point> it = roi.iterator();
while (it.hasNext()) {
java.awt.Point p = it.next();
list.add(new int[] {(int) p.getX(), (int) p.getY()});
}
return list;
}

@Override
public void deletePointRoi(int[] pp) {
Roi roi = IJ.getImage().getRoi();
if (roi.getType() == Roi.POINT) {
PointRoi pRoi = (PointRoi) roi;
Iterator<java.awt.Point> iter = roi.iterator();
while (iter.hasNext()) {
java.awt.Point point = iter.next();
if (point.x == pp[0] && point.y == pp[1]) {
pRoi.deleteHandle(pp[0], pp[1]);
return;
}
}
}
Roi[] roiManagerRois = RoiManager.getInstance().getRoisAsArray();
for (Roi managerRoi : roiManagerRois) {
if (managerRoi.getType() != Roi.POINT)
continue;
PointRoi pRoi = (PointRoi) managerRoi;
Iterator<java.awt.Point> iter = pRoi.iterator();
while (iter.hasNext()) {
java.awt.Point point = iter.next();
if (point.x == pp[0] && point.y == pp[1]) {
pRoi.deleteHandle(pp[0], pp[1]);
return;
}
}
}
}

@Override
public void deleteRectRoi(Rectangle rect) {
Roi roi = IJ.getImage().getRoi();
if (roi.getType() == Roi.RECTANGLE) {
if (roi.getBounds() == rect) {
activeImage.deleteRoi();
return;
}
}
Roi[] roiManagerRois = RoiManager.getInstance().getRoisAsArray();
for (int i = 0; i < roiManagerRois.length; i ++) {
Roi managerRoi = roiManagerRois[i];
if (managerRoi.getType() != Roi.RECTANGLE)
continue;
if (roi.getBounds() == rect) {
try {
RoiManagerPrivateViolator.deleteRoiAtPosition(RoiManager.getInstance(), i);
} catch (NoSuchFieldException | SecurityException | NoSuchMethodException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return;
}

}
}

private List<Rectangle> getRectRoisFromRoiManager() {
List<Rectangle> list = new ArrayList<Rectangle>();
Roi[] rois = RoiManager.getInstance().getRoisAsArray();
if (rois.length == 0)
return list;
list = Arrays.stream(rois).filter(rr -> rr.getType() != Roi.RECTANGLE)
.map(rr -> rr.getBounds()).collect(Collectors.toList());
return list;
}

private List<int[]> getPointRoisFromRoiManager() {
List<int[]> list = new ArrayList<int[]>();
Expand All @@ -270,8 +330,9 @@ private List<int[]> getPointRoisFromRoiManager() {
return list;
List<Roi> roiList = Arrays.stream(rois).filter(rr -> rr.getType() != Roi.POINT).collect(Collectors.toList());
for (Roi rr : roiList) {
while (rr.iterator().hasNext()) {
java.awt.Point p = rr.iterator().next();
Iterator<java.awt.Point> it = rr.iterator();
while (it.hasNext()) {
java.awt.Point p = it.next();
list.add(new int[] {(int) p.getX(), (int) p.getY()});
}
}
Expand Down

0 comments on commit cae6b94

Please sign in to comment.