Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic N5ImageLoader #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/main/java/bdv/img/n5/N5ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

public class N5ImageLoader implements ViewerImgLoader, MultiResolutionImgLoader
{
private final File n5File;
private final N5Reader n5;

// TODO: it would be good if this would not be needed
// find available setups from the n5
Expand All @@ -113,9 +113,9 @@ public class N5ImageLoader implements ViewerImgLoader, MultiResolutionImgLoader
*/
private final Map< Integer, SetupImgLoader > setupImgLoaders = new HashMap<>();

public N5ImageLoader( final File n5File, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
public N5ImageLoader( final N5Reader n5, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
this.n5File = n5File;
this.n5 = n5;
this.seq = sequenceDescription;
}

Expand All @@ -124,10 +124,16 @@ public File getN5File()
return n5File;
}

public void setN5File( File n5File )
{
this.n5File = n5File;
}

private File n5File;
private volatile boolean isOpen = false;
private FetcherThreads fetchers;
private VolatileGlobalCellCache cache;
private N5Reader n5;


private void open()
{
Expand All @@ -140,8 +146,6 @@ private void open()

try
{
this.n5 = new N5FSReader( n5File.getAbsolutePath() );

int maxNumLevels = 0;
final List< ? extends BasicViewSetup > setups = seq.getViewSetupsOrdered();
for ( final BasicViewSetup setup : setups )
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/bdv/img/n5/XmlIoN5ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@
package bdv.img.n5;

import java.io.File;
import java.io.IOException;

import mpicbg.spim.data.XmlHelpers;
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.ImgLoaderIo;
import mpicbg.spim.data.generic.sequence.XmlIoBasicImgLoader;
import org.janelia.saalfeldlab.n5.N5FSReader;
import org.jdom2.Element;

import static mpicbg.spim.data.XmlHelpers.loadPath;
Expand All @@ -56,7 +59,18 @@ public Element toXml( final N5ImageLoader imgLoader, final File basePath )
public N5ImageLoader fromXml( final Element elem, final File basePath, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
// final String version = elem.getAttributeValue( "version" );
final File path = loadPath( elem, "n5", basePath );
return new N5ImageLoader( path, sequenceDescription );

try
{
final File path = loadPath( elem, "n5", basePath );
final N5FSReader n5FSReader = new N5FSReader( path.getAbsolutePath() );
final N5ImageLoader n5ImageLoader = new N5ImageLoader( n5FSReader, sequenceDescription );
n5ImageLoader.setN5File( path );
return n5ImageLoader;
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
}
}