Skip to content

Commit

Permalink
add method to find area to encode
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed May 28, 2024
1 parent 2deed03 commit e5d0c61
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/ai/nets/samj/ij/ui/IJ1PromptsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
import ai.nets.samj.ui.PromptsResultsDisplay;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
Expand Down Expand Up @@ -225,7 +227,8 @@ public void notifyException(SAMJException type, Exception ex) {
} else if (SAMJException.ENCODING == type) {
IJ.error("Error providing or processing the prompts", nMessage);
} else {
IJ.error(nMessage);
IJ.error(ex.toString());
ex.printStackTrace();
}

}
Expand Down Expand Up @@ -524,7 +527,7 @@ private void submitAndClearPoints() {
//TODO log.info("Image window: Processing now points, this count: "+collectedPoints.size());
isCollectingPoints = false;
activeImage.deleteRoi();
Rectangle zoomedRectangle = this.activeCanvas.getSrcRect();
Rectangle zoomedRectangle = findEncodingArea();
try {
if (activeImage.getWidth() * activeImage.getHeight() > Math.pow(AbstractSamJ.MAX_ENCODED_AREA_RS, 2)
|| activeImage.getWidth() > AbstractSamJ.MAX_ENCODED_SIDE || activeImage.getHeight() > AbstractSamJ.MAX_ENCODED_SIDE)
Expand All @@ -542,6 +545,18 @@ private void submitAndClearPoints() {
temporalNegROIs = new ArrayList<Roi>();
}

private Rectangle findEncodingArea() {
Rectangle zoomedRectangle = this.activeCanvas.getSrcRect();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();
Rectangle bounds = this.activeCanvas.getBounds();

double xRatio = zoomedRectangle.x / width;
double yRatio = zoomedRectangle.y / height;
return this.activeCanvas.getSrcRect();
}

private void submitRectPrompt(Interval rectInterval) {
try {
addToRoiManager(promptsToNet.fetch2dSegmentation(rectInterval), "rect");
Expand Down

0 comments on commit e5d0c61

Please sign in to comment.