Skip to content

Commit

Permalink
for points delete the roi manager roi once everyhting has been processed
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 3, 2024
1 parent 441af69 commit 5aa5275
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/main/java/ai/nets/samj/ij/ui/Consumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ public <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> getFo
@Override
public List<Rectangle> getRectRoisOnFocusImage() {
Roi roi = IJ.getImage().getRoi();
List<Rectangle> list = getRectRoisFromRoiManager();
//List<Rectangle> list = getRectRoisFromRoiManager();
List<Rectangle> list = new ArrayList<Rectangle>();
if (roi == null)
return list;
if (roi.getType() != Roi.RECTANGLE)
Expand All @@ -255,38 +256,54 @@ public List<Rectangle> getRectRoisOnFocusImage() {
public List<int[]> getPointRoisOnFocusImage() {
Roi roi = IJ.getImage().getRoi();
List<int[]> list = getPointRoisFromRoiManager();
//List<int[]> list = new ArrayList<int[]>();
if (roi == null)
return list;
if (roi.getType() != Roi.POINT)
return list;
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()});
int[] arr = new int[] {(int) p.getX(), (int) p.getY()};
if (list.stream().anyMatch(a -> Arrays.equals(a, arr)))
continue;
list.add(arr);
}
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();
int ii = -1;
if (roiManagerRois != null) {
ii ++;
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]);
if (!iter.hasNext()) {
try {
RoiManagerPrivateViolator.deleteRoiAtPosition(RoiManager.getInstance(), ii);
} catch (NoSuchFieldException | SecurityException | NoSuchMethodException
| IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
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();
Roi roi = IJ.getImage().getRoi();
if (roi != null && 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]) {
Expand Down Expand Up @@ -329,7 +346,7 @@ private List<Rectangle> getRectRoisFromRoiManager() {
Roi[] rois = RoiManager.getInstance().getRoisAsArray();
if (rois.length == 0)
return list;
list = Arrays.stream(rois).filter(rr -> rr.getType() != Roi.RECTANGLE)
list = Arrays.stream(rois).filter(rr -> rr.getType() == Roi.RECTANGLE)
.map(rr -> rr.getBounds()).collect(Collectors.toList());
return list;
}
Expand All @@ -339,13 +356,14 @@ private List<int[]> getPointRoisFromRoiManager() {
Roi[] rois = RoiManager.getInstance().getRoisAsArray();
if (rois.length == 0)
return list;
List<Roi> roiList = Arrays.stream(rois).filter(rr -> rr.getType() != Roi.POINT).collect(Collectors.toList());
List<Roi> roiList = Arrays.stream(rois).filter(rr -> rr.getType() == Roi.POINT).collect(Collectors.toList());
for (Roi rr : roiList) {
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()});
}
rr.setImage(activeImage);
}
return list;
}
Expand Down

0 comments on commit 5aa5275

Please sign in to comment.