Skip to content

Commit afc573b

Browse files
committed
change default dir to the fiji folder
1 parent 5acf61a commit afc573b

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

src/main/java/ai/nets/samj/ij/SAMJ_Annotator.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.awt.GraphicsEnvironment;
2323
import java.awt.Rectangle;
24+
import java.io.File;
2425
import java.io.IOException;
2526
import java.util.ArrayList;
2627
import java.util.List;
@@ -38,11 +39,14 @@
3839
import ij.gui.GUI;
3940
import ij.plugin.PlugIn;
4041
import ij.plugin.frame.Recorder;
42+
import io.bioimage.modelrunner.system.PlatformDetection;
4143
import net.imglib2.RandomAccessibleInterval;
4244
import net.imglib2.type.NativeType;
4345
import net.imglib2.type.numeric.RealType;
4446
import net.imglib2.type.numeric.integer.UnsignedShortType;
4547
import ai.nets.samj.ij.ui.Consumer;
48+
import ai.nets.samj.ij.utils.Constants;
49+
import ai.nets.samj.install.SamEnvManagerAbstract;
4650
import ai.nets.samj.models.AbstractSamJ.BatchCallback;
4751

4852
// TODO I (Carlos) don't know how to develop in IJ2 @Plugin(type = Command.class, menuPath = "Plugins>SAMJ>Annotator")
@@ -106,6 +110,15 @@ public void deleteRectPrompt(List<int[]> promptList) {
106110
}
107111

108112
};
113+
114+
static
115+
{
116+
// IMPORTANT: Set the DEFAULT DIR WHERE MODELS ARE DOWNLOADED TO THE WANTED DIR.
117+
// IF NOT IN MACS IT WILL DEFAULT TO "/" AND RAISE AN ERROR
118+
SamEnvManagerAbstract.DEFAULT_DIR = Constants.FIJI_FOLDER + File.separator + "appose_"
119+
+ ((!PlatformDetection.isMacOS() || !PlatformDetection.isUsingRosseta()) ? PlatformDetection.getArch()
120+
: PlatformDetection.ARCH_ARM64 );
121+
}
109122

110123
// TODO I (Carlos) don't know how to develop in IJ2 @Parameter
111124
//private LogService logService = new LogService();
@@ -142,7 +155,6 @@ public void run() throws IOException, InterruptedException {
142155
public void error(String text) {System.out.println("network -- " + text);}
143156
};
144157

145-
146158
SwingUtilities.invokeLater(() -> {
147159
MainGUI samjDialog = new MainGUI(new Consumer());
148160
GUI.center(samjDialog);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*-
2+
* #%L
3+
* Plugin to help image annotation with SAM-based Deep Learning models
4+
* %%
5+
* Copyright (C) 2024 SAMJ developers.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package ai.nets.samj.ij.utils;
21+
22+
import java.io.File;
23+
24+
import io.bioimage.modelrunner.system.PlatformDetection;
25+
26+
public class Constants {
27+
28+
/**
29+
* The folder of Fiji
30+
*/
31+
public static final String FIJI_FOLDER = getFijiFolder();
32+
33+
private static String getFijiFolder() {
34+
File jvmFolder = new File(System.getProperty("java.home"));
35+
String imageJExecutable;
36+
if (PlatformDetection.isWindows())
37+
imageJExecutable = "fiji-windows-x64.exe";
38+
else if (PlatformDetection.isLinux())
39+
imageJExecutable = "fiji-linux-x64";
40+
else if (PlatformDetection.isMacOS() && PlatformDetection.getArch().equals(PlatformDetection.ARCH_ARM64))
41+
imageJExecutable = "Fiji.App/Contents/MacOS/fiji-macos-arm64";
42+
else if (PlatformDetection.isMacOS())
43+
imageJExecutable = "Fiji.App/Contents/MacOS/fiji-macos-x64";
44+
else
45+
throw new IllegalArgumentException("Unsupported Operating System");
46+
while (true && jvmFolder != null) {
47+
jvmFolder = jvmFolder.getParentFile();
48+
if (new File(jvmFolder + File.separator + imageJExecutable).isFile())
49+
return jvmFolder.getAbsolutePath();
50+
}
51+
return getImageJFolder();
52+
}
53+
54+
private static String getImageJFolder() {
55+
File jvmFolder = new File(System.getProperty("java.home"));
56+
String imageJExecutable;
57+
if (PlatformDetection.isWindows())
58+
imageJExecutable = "ImageJ-win64.exe";
59+
else if (PlatformDetection.isLinux())
60+
imageJExecutable = "ImageJ-linux64";
61+
else if (PlatformDetection.isMacOS())
62+
imageJExecutable = "Contents/MacOS/ImageJ-macosx";
63+
else
64+
throw new IllegalArgumentException("Unsupported Operating System");
65+
while (true && jvmFolder != null) {
66+
jvmFolder = jvmFolder.getParentFile();
67+
if (new File(jvmFolder + File.separator + imageJExecutable).isFile())
68+
return jvmFolder.getAbsolutePath();
69+
}
70+
return new File("").getAbsolutePath();
71+
// TODO remove throw new RuntimeException("Unable to find the path to the ImageJ/Fiji being used.");
72+
}
73+
}

0 commit comments

Comments
 (0)