diff --git a/src/main/java/bdv/gui/BigWarpInitDialog.java b/src/main/java/bdv/gui/BigWarpInitDialog.java index 5db52b6f..6409b1ce 100644 --- a/src/main/java/bdv/gui/BigWarpInitDialog.java +++ b/src/main/java/bdv/gui/BigWarpInitDialog.java @@ -62,6 +62,7 @@ import bigwarp.transforms.metadata.N5TransformMetadataParser; import bigwarp.transforms.metadata.N5TransformTreeCellRenderer; import ij.IJ; +import ij.ImageJ; import ij.ImagePlus; import ij.Macro; import ij.Prefs; @@ -164,6 +165,26 @@ public BigWarpInitDialog( final String title, final DatasetService datasetServic }; } + public static void main( String[] args ) { + + final ImageJ ij = new ImageJ(); +// runBigWarp( "/home/john/tmp/boats_lm.csv", +// new String[]{ "/home/john/tmp/boats.tif", "/home/john/tmp/boats.tif" }, +// new String[]{ "true", "false" }, +// null); + +// runBigWarp( "/home/john/tmp/boats_lm2.csv", +// new String[]{ "/home/john/tmp/boats.tif", "/home/john/tmp/boats-HR.tif" }, +// new String[]{ "true", "false" }, +// null); + +// runBigWarp( "file:///home/john/Documents/presentations/20231130_BdvCommunity/demo/boats-hr-project.json ", +// null, +// null, +// null); + + new BigWarpInitDialog("bigwarp test").createAndShow(); + } public void setInitialRecorderState( final boolean initialRecorderState ) { @@ -172,10 +193,11 @@ public void setInitialRecorderState( final boolean initialRecorderState ) public static < T extends NativeType > BigWarp runBigWarp( final String projectLandmarkPath, final String[] images, final String[] moving, final String[] transforms ) { + final String projectLandmarkPathTrim = projectLandmarkPath == null ? null : projectLandmarkPath.trim(); final BigWarpData< T > data = BigWarpInit.initData(); - final boolean haveProjectLandmarkArg = projectLandmarkPath != null && !projectLandmarkPath.isEmpty(); - final boolean haveProject = haveProjectLandmarkArg && projectLandmarkPath.endsWith(".json"); - final boolean haveLandmarks = haveProjectLandmarkArg && projectLandmarkPath.endsWith(".csv"); + final boolean haveProjectLandmarkArg = projectLandmarkPathTrim != null && !projectLandmarkPathTrim.isEmpty(); + final boolean haveProject = haveProjectLandmarkArg && projectLandmarkPathTrim.trim().endsWith(".json"); + final boolean haveLandmarks = haveProjectLandmarkArg && projectLandmarkPathTrim.trim().endsWith(".csv"); final int nThreads = IJ.getInstance() != null ? Prefs.getThreads() : 1; final BigWarpViewerOptions bwOpts = ( BigWarpViewerOptions ) BigWarpViewerOptions.options().numRenderingThreads( nThreads ); @@ -238,9 +260,9 @@ public static < T extends NativeType > BigWarp runBigWarp( final String pr bw = new BigWarp<>( data, bwOpts, new ProgressWriterIJ() ); if( haveProject ) - bw.loadSettings( projectLandmarkPath, true ); + bw.loadSettings( projectLandmarkPathTrim, true ); else if( haveLandmarks ) - bw.loadLandmarks(projectLandmarkPath); + bw.loadLandmarks( projectLandmarkPathTrim ); } catch ( final SpimDataException e ) { @@ -269,7 +291,7 @@ public > void runBigWarp() final BigWarpData< T > data = BigWarpInit.initData(); - projectLandmarkPath = projectLandmarkPath == null ? projectPathTxt.getText() : projectLandmarkPath; + projectLandmarkPath = projectLandmarkPath == null ? projectPathTxt.getText().trim() : projectLandmarkPath; final boolean haveProjectLandmarkArg = projectLandmarkPath != null && !projectLandmarkPath.isEmpty(); final boolean haveProject = haveProjectLandmarkArg && projectLandmarkPath.endsWith(".json"); final boolean haveLandmarks = haveProjectLandmarkArg && projectLandmarkPath.endsWith(".csv"); diff --git a/src/main/java/bigwarp/BigWarp.java b/src/main/java/bigwarp/BigWarp.java index 50d6ff66..781d3bee 100755 --- a/src/main/java/bigwarp/BigWarp.java +++ b/src/main/java/bigwarp/BigWarp.java @@ -40,6 +40,7 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; +import java.net.URI; import java.net.URISyntaxException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -4074,10 +4075,19 @@ protected void loadLandmarks() public void loadLandmarks( final String filename ) { - final File file = new File( filename ); - setLastDirectory( file.getParentFile() ); - if( filename.endsWith( "csv" )) + final String filenameTrim = filename.trim(); + String name = filenameTrim; + try { + final URI uri = new URI( filenameTrim ); + if( !uri.getScheme().isEmpty()) + name = uri.getSchemeSpecificPart(); + } + catch ( URISyntaxException e ) { } + + final File file = new File( name ); + setLastDirectory( file.getParentFile() ); + if( name.endsWith( "csv" )) { try { @@ -4088,7 +4098,7 @@ public void loadLandmarks( final String filename ) e1.printStackTrace(); } } - else if( filename.endsWith( "json" )) + else if( name.endsWith( "json" )) { TransformWriterJson.read( file, this ); } @@ -4301,10 +4311,19 @@ public void loadSettings( final String jsonOrXmlFilename ) throws IOException, public void loadSettings( final String jsonOrXmlFilename, boolean overwriteSources ) throws IOException, JDOMException { - if ( jsonOrXmlFilename.endsWith( ".xml" ) ) + final String filenameTrim = jsonOrXmlFilename.trim(); + String name = filenameTrim; + try { + final URI uri = new URI( filenameTrim ); + if( uri != null && uri.getScheme() != null ) + name = uri.getSchemeSpecificPart(); + } + catch ( URISyntaxException e ) { } + + if ( name.endsWith( ".xml" ) ) { final SAXBuilder sax = new SAXBuilder(); - final Document doc = sax.build( jsonOrXmlFilename ); + final Document doc = sax.build( name ); final Element root = doc.getRootElement(); /* add default sources if present */ @@ -4338,7 +4357,7 @@ public void loadSettings( final String jsonOrXmlFilename, boolean overwriteSourc { final BigwarpSettings settings = getSettings(); settings.setOverwriteSources( overwriteSources ); - settings.read( new JsonReader( new FileReader( jsonOrXmlFilename ) ) ); + settings.read( new JsonReader( new FileReader( name ) ) ); // TODO I may need this // Executors.newSingleThreadExecutor().execute(new Runnable() {