Skip to content

Commit

Permalink
fix Save As XML
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Nov 7, 2024
1 parent 35e3a20 commit 6219d60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
40 changes: 13 additions & 27 deletions src/main/java/net/preibisch/mvrecon/fiji/plugin/XMLSaveAs.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
*/
package net.preibisch.mvrecon.fiji.plugin;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;

import org.bigdataviewer.n5.N5CloudImageLoader;

import bdv.img.hdf5.Hdf5ImageLoader;
import bdv.img.n5.N5ImageLoader;
Expand Down Expand Up @@ -97,40 +93,30 @@ public static URI saveAs( final SpimData2 data, final String suggestedFileName )
IOFunctions.println( "New XML: " + newXMLPath );
IOFunctions.println( "New base path: " + newBaseDir );

if ( N5CloudImageLoader.class.isInstance( imgLoader ) )
{
final URI n5URI = ((N5CloudImageLoader)imgLoader).getN5URI();

IOFunctions.println( "Path of cloud N5 (stays in old location): " + n5URI );
data.getSequenceDescription().setImgLoader( new N5CloudImageLoader( null, n5URI, data.getSequenceDescription() ) );
}
else if ( N5ImageLoader.class.isInstance( imgLoader ) )
{
final URI n5URI = ((N5ImageLoader)imgLoader).getN5URI();

IOFunctions.println( "Path of N5 (stays in old location): " + n5URI );
data.getSequenceDescription().setImgLoader( new N5ImageLoader( new File( URITools.fromURI( n5URI ) ), data.getSequenceDescription() ) );
}
else if ( Hdf5ImageLoader.class.isInstance( imgLoader ) )
{
final Hdf5ImageLoader h5ImgLoader = (Hdf5ImageLoader)imgLoader;
final File h5File = h5ImgLoader.getHdf5File();

IOFunctions.println( "HDF5 file (stays in old location): " + h5File );
data.getSequenceDescription().setImgLoader( new Hdf5ImageLoader(h5File, h5ImgLoader.getPartitions(), data.getSequenceDescription()) );
}

data.setBasePathURI( newBaseDir );

// make sure interestpoints are saved to the new location as well
for ( final ViewInterestPointLists vipl : data.getViewInterestPoints().getViewInterestPoints().values() )
vipl.getHashMap().values().forEach( ipl ->
{
// first load
ipl.getInterestPointsCopy();
ipl.getCorrespondingInterestPointsCopy();

// then set base dir (otherwise loading fails)
ipl.setBaseDir( newBaseDir ); // also sets 'isModified' flags
});

// make sure PSF's are saved to the new location as well
data.getPointSpreadFunctions().getPointSpreadFunctions().values().forEach( psf ->
{
// first load
psf.load();

// then set base dir (otherwise loading fails)
psf.setBaseDir( newBaseDir );
});

LoadParseQueryXML.defaultXMLURI = newXMLPath.toString();

return newXMLPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ public abstract class GenericLoadParseQueryXML<
protected ArrayList< ActionListener > listener = null;
protected GenericDialog gd = null;

protected boolean isPrefetched = false;

public Button defineNewDataset = null;

/*
Expand Down Expand Up @@ -181,15 +179,15 @@ else if ( SplitViewerImgLoader.class.isInstance( loader ) )
uri = null;
}

if ( uri != null && !isPrefetched && ( URITools.isS3( uri ) || URITools.isGC( uri ) ) )
System.out.println( "ImageLoader URI: " + uri );

if ( uri != null && ( URITools.isS3( uri ) || URITools.isGC( uri ) ) )
{
IOFunctions.println( "Setting cloud fetcher threads for '" + uri + "' to: " + URITools.cloudThreads );
URITools.setNumFetcherThreads( data.getSequenceDescription().getImgLoader(), URITools.cloudThreads );

IOFunctions.println( "Prefetching with " + URITools.cloudThreads + " threads: for '" + uri + "'");
URITools.prefetch( data.getSequenceDescription().getImgLoader(), URITools.cloudThreads );

isPrefetched = true;
}

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class PointSpreadFunction
private final static String subDirFile = "psf";
private final static String subPath = "psf.n5";

private final URI xmlBasePath;
private URI xmlBasePath;
private final String file;
private Img< FloatType > img;
private boolean modified;
Expand Down Expand Up @@ -81,6 +81,13 @@ public void setPSF( final Img< FloatType > img )
this.img = img;
}

public URI getBaseDir() { return xmlBasePath; }
public void setBaseDir( final URI baseDir )
{
this.xmlBasePath = baseDir;
this.modified = true;
}

public String getFile() { return file; }
public boolean isModified() { return modified; }
public synchronized boolean isLoaded() { return img != null; }
Expand Down

0 comments on commit 6219d60

Please sign in to comment.