Skip to content

Commit

Permalink
fix: project and landmark file parsin
Browse files Browse the repository at this point in the history
* clean up whitespace and scheme when drag+drop
  • Loading branch information
bogovicj committed Nov 29, 2023
1 parent 4288aa1 commit 8b80dca
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
34 changes: 28 additions & 6 deletions src/main/java/bdv/gui/BigWarpInitDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand All @@ -172,10 +193,11 @@ public void setInitialRecorderState( final boolean initialRecorderState )

public static < T extends NativeType<T> > 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 );
Expand Down Expand Up @@ -238,9 +260,9 @@ public static < T extends NativeType<T> > 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 )
{
Expand Down Expand Up @@ -269,7 +291,7 @@ public <T extends NativeType<T>> 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");
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/bigwarp/BigWarp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 8b80dca

Please sign in to comment.