Skip to content

Commit

Permalink
add fromXML(URI) calls, for now these are copies of fromXML(File)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Dec 3, 2024
1 parent 9805791 commit 85f1068
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static mpicbg.spim.data.XmlKeys.IMGLOADER_TAG;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -87,6 +88,43 @@ public Element toXml( final SplitImgLoader imgLoader, final File basePath )
return elem;
}

@Override
public SplitImgLoader fromXml(
final Element elem, URI basePath,
final AbstractSequenceDescription<?, ?, ?> sequenceDescription )
{
final HashMap< Integer, Integer > new2oldSetupId = new HashMap<>();
final HashMap< Integer, Interval > newSetupId2Interval = new HashMap<>();

for ( final Element setup : elem.getChild( XmlIoSplitViewerImgLoader.SETUPIDS_NAME ).getChildren( XmlIoSplitViewerImgLoader.SETUPIDS_TAG ) )
XmlIoSplitViewerImgLoader.setupFromXML( setup, new2oldSetupId, newSetupId2Interval );

try
{
final XmlIoSequenceDescription xmlIoSequenceDescription = new XmlIoSequenceDescription();
final Element sdElem = elem.getChild( xmlIoSequenceDescription.getTag() );
if ( sdElem == null )
throw new SpimDataIOException( "no <" + xmlIoSequenceDescription.getTag() + "> element found." );
final SequenceDescription oldSD = xmlIoSequenceDescription.fromXml( sdElem, basePath );

ImgLoader underlyingImgLoader = null;

final Element imgLoaderElem = elem.getChild( IMGLOADER_TAG );
final String format = imgLoaderElem.getAttributeValue( IMGLOADER_FORMAT_ATTRIBUTE_NAME );
final XmlIoBasicImgLoader< ? > imgLoaderIo = ImgLoaders.createXmlIoForFormat( format );
underlyingImgLoader = (ImgLoader)imgLoaderIo.fromXml( imgLoaderElem, basePath, oldSD );

return new SplitImgLoader( underlyingImgLoader, new2oldSetupId, newSetupId2Interval, oldSD );
}
catch( Exception e )
{
IOFunctions.println( "Unable to load underlying Sequence Description & ImgLoader, stopping." );
e.printStackTrace();
System.exit( 0 );
return null;
}
}

@Override
public SplitImgLoader fromXml(
final Element elem, File basePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static mpicbg.spim.data.XmlKeys.IMGLOADER_TAG;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -87,6 +88,43 @@ public Element toXml( final SplitMultiResolutionImgLoader imgLoader, final File
return elem;
}

@Override
public SplitMultiResolutionImgLoader fromXml(
final Element elem, URI basePath,
final AbstractSequenceDescription<?, ?, ?> sequenceDescription )
{
final HashMap< Integer, Integer > new2oldSetupId = new HashMap<>();
final HashMap< Integer, Interval > newSetupId2Interval = new HashMap<>();

for ( final Element setup : elem.getChild( XmlIoSplitViewerImgLoader.SETUPIDS_NAME ).getChildren( XmlIoSplitViewerImgLoader.SETUPIDS_TAG ) )
XmlIoSplitViewerImgLoader.setupFromXML( setup, new2oldSetupId, newSetupId2Interval );

try
{
final XmlIoSequenceDescription xmlIoSequenceDescription = new XmlIoSequenceDescription();
final Element sdElem = elem.getChild( xmlIoSequenceDescription.getTag() );
if ( sdElem == null )
throw new SpimDataIOException( "no <" + xmlIoSequenceDescription.getTag() + "> element found." );
final SequenceDescription oldSD = xmlIoSequenceDescription.fromXml( sdElem, basePath );

MultiResolutionImgLoader underlyingImgLoader = null;

final Element imgLoaderElem = elem.getChild( IMGLOADER_TAG );
final String format = imgLoaderElem.getAttributeValue( IMGLOADER_FORMAT_ATTRIBUTE_NAME );
final XmlIoBasicImgLoader< ? > imgLoaderIo = ImgLoaders.createXmlIoForFormat( format );
underlyingImgLoader = (MultiResolutionImgLoader)imgLoaderIo.fromXml( imgLoaderElem, basePath, oldSD );

return new SplitMultiResolutionImgLoader( underlyingImgLoader, new2oldSetupId, newSetupId2Interval, oldSD );
}
catch( Exception e )
{
IOFunctions.println( "Unable to load underlying Sequence Description & ImgLoader, stopping." );
e.printStackTrace();
System.exit( 0 );
return null;
}
}

@Override
public SplitMultiResolutionImgLoader fromXml(
final Element elem, File basePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static mpicbg.spim.data.XmlKeys.IMGLOADER_TAG;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -139,6 +140,41 @@ protected static < L extends BasicImgLoader > Element createImgLoaderElement( fi
return imgLoaderIo.toXml( ( L ) imgLoader, basePath );
}

@Override
public SplitViewerImgLoader fromXml( final Element elem, final URI basePathURI, AbstractSequenceDescription< ?, ?, ? > sequenceDescription )
{
final HashMap< Integer, Integer > new2oldSetupId = new HashMap<>();
final HashMap< Integer, Interval > newSetupId2Interval = new HashMap<>();

for ( final Element setup : elem.getChild( SETUPIDS_NAME ).getChildren( SETUPIDS_TAG ) )
setupFromXML( setup, new2oldSetupId, newSetupId2Interval );

try
{
final XmlIoSequenceDescription xmlIoSequenceDescription = new XmlIoSequenceDescription();
final Element sdElem = elem.getChild( xmlIoSequenceDescription.getTag() );
if ( sdElem == null )
throw new SpimDataIOException( "no <" + xmlIoSequenceDescription.getTag() + "> element found." );
final SequenceDescription oldSD = xmlIoSequenceDescription.fromXml( sdElem, basePathURI );

ViewerImgLoader underlyingImgLoader = null;

final Element imgLoaderElem = elem.getChild( IMGLOADER_TAG );
final String format = imgLoaderElem.getAttributeValue( IMGLOADER_FORMAT_ATTRIBUTE_NAME );
final XmlIoBasicImgLoader< ? > imgLoaderIo = ImgLoaders.createXmlIoForFormat( format );
underlyingImgLoader = (ViewerImgLoader)imgLoaderIo.fromXml( imgLoaderElem, basePathURI, oldSD );

return new SplitViewerImgLoader( underlyingImgLoader, new2oldSetupId, newSetupId2Interval, oldSD );
}
catch( Exception e )
{
IOFunctions.println( "Unable to load underlying Sequence Description & ImgLoader, stopping." );
e.printStackTrace();
System.exit( 0 );
return null;
}
}

@Override
public SplitViewerImgLoader fromXml(
final Element elem, File basePath,
Expand Down

0 comments on commit 85f1068

Please sign in to comment.