Skip to content

Commit

Permalink
implemented generic assembly of blocks for the trivial case
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Aug 16, 2023
1 parent f5c295c commit e2cb2da
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
Expand All @@ -12,6 +14,7 @@
import java.util.concurrent.Future;
import java.util.function.Function;

import org.janelia.alignment.spec.ResolvedTileSpecCollection.TransformApplicationMethod;
import org.janelia.render.client.newsolver.blockfactories.ZBlockFactory;
import org.janelia.render.client.newsolver.blocksolveparameters.FIBSEMAlignmentParameters;
import org.janelia.render.client.newsolver.setup.AffineSolverSetup;
Expand All @@ -21,7 +24,9 @@
import org.janelia.render.client.newsolver.solvers.affine.AffineAlignBlockWorker;
import org.janelia.render.client.solver.DistributedSolveDeSerialize;
import org.janelia.render.client.solver.DistributedSolveWorker;
import org.janelia.render.client.solver.MinimalTileSpec;
import org.janelia.render.client.solver.SolveItemData;
import org.janelia.render.client.solver.SolveTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -152,6 +157,35 @@ public static void main( final String[] args ) throws IOException
final int maxId = WorkerTools.fixIds( allItems, solverSetup.col.maxId() );

LOG.info( "computed " + allItems.size() + " blocks, maxId=" + maxId);

/*
//
// Saving the result
//
LOG.info( "Saving targetstack=" + cmdLineSetup.targetStack );
//
// save the re-aligned part
//
final HashSet< Double > zToSaveSet = new HashSet<>();
for ( final TileSpec ts : solve.idToTileSpecGlobal.values() )
zToSaveSet.add( ts.getZ() );
List< Double > zToSave = new ArrayList<>( zToSaveSet );
Collections.sort( zToSave );
LOG.info("Saving from " + zToSave.get( 0 ) + " to " + zToSave.get( zToSave.size() - 1 ) );
SolveTools.saveTargetStackTiles( parameters.stack, parameters.targetStack, runParams, solve.idToFinalModelGlobal, null, zToSave, TransformApplicationMethod.REPLACE_LAST );
if ( parameters.completeTargetStack )
{
LOG.info( "Completing targetstack=" + parameters.targetStack );
SolveTools.completeStack( parameters.targetStack, runParams );
}
*/
}

public < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2D< S > >
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.janelia.render.client.newsolver.assembly;

import java.util.List;

import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.ZBlockFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import mpicbg.models.AffineModel2D;

public class Affine2DZBlockAssembler extends Assembler< AffineModel2D, ZBlockFactory >
{

public Affine2DZBlockAssembler( final List<BlockData<?, AffineModel2D, ?, ZBlockFactory>> blocks, final int startId)
{
super( blocks, startId );
}

@Override
public void assemble( )
{
}

private static final Logger LOG = LoggerFactory.getLogger(Affine2DZBlockAssembler.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.janelia.render.client.newsolver.assembly;

import java.util.HashSet;
import java.util.List;

import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.BlockFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import mpicbg.models.CoordinateTransform;

public abstract class Assembler< R extends CoordinateTransform, F extends BlockFactory< F > >
{
final List<BlockData<?, R, ?, F> > blocks;

int id;

public Assembler( final List<BlockData<?, R, ?, F> > blocks, final int startId )
{
this.id = startId;
this.blocks = blocks;
}

public AssemblyMaps< R > getAssembly()
{
AssemblyMaps< R > am;

// the trivial case of a single block, would crash with the code below
if ( ( am = handleTrivialCase() ) != null )
return am;
else
am = new AssemblyMaps< R >();

assemble();

return null;
}

public abstract void assemble();

/**
*
* @return - the result of the trivial case if it was a single block
*/
protected AssemblyMaps< R > handleTrivialCase()
{
if ( blocks.size() == 1 )
{
LOG.info( "Assembler: only a single block, no solve across blocks necessary." );

final AssemblyMaps< R > am = new AssemblyMaps< R >();

final BlockData< ?, R, ?, F > solveItem = blocks.get( 0 );

for ( int z = solveItem.minZ(); z <= solveItem.maxZ(); ++z )
{
// there is no overlap with any other solveItem (should be beginning or end of the entire stack)
final HashSet< String > tileIds = solveItem.zToTileId().get( z );

// if there are none, we continue with the next
if ( tileIds.size() == 0 )
continue;

am.zToTileIdGlobal.putIfAbsent( z, new HashSet<>() );

for ( final String tileId : tileIds )
{
am.zToTileIdGlobal.get( z ).add( tileId );
am.idToTileSpecGlobal.put( tileId, solveItem.rtsc().getTileSpec( tileId ) );
am.idToFinalModelGlobal.put( tileId, solveItem.idToNewModel().get( tileId ) );
}
}

return am;
}
else
{
return null;
}
}

/*
public static ResolvedTileSpecCollection combineAllTileSpecs( final List< BlockData<?, ?, ?, ?> > allItems )
{
final ResolvedTileSpecCollection rtsc = new ResolvedTileSpecCollection();
// TODO trautmane - improve this
// this should automatically get rid of duplicates due to the common tileId
for ( BlockData<?, ?, ?, ?> block : allItems )
block.rtsc().getTileSpecs().forEach( tileSpec -> rtsc.addTileSpecToCollection( tileSpec ) );
return rtsc;
}*/

private static final Logger LOG = LoggerFactory.getLogger(Assembler.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.janelia.render.client.newsolver.assembly;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import org.janelia.alignment.spec.TileSpec;

import mpicbg.models.CoordinateTransform;
import net.imglib2.util.Pair;

public class AssemblyMaps< R extends CoordinateTransform >
{
final public HashMap< String, R > idToFinalModelGlobal = new HashMap<>();
final public HashMap< String, TileSpec > idToTileSpecGlobal = new HashMap<>();
final public HashMap<Integer, HashSet<String> > zToTileIdGlobal = new HashMap<>();
final public HashMap< String, List< Pair< String, Double > > > idToErrorMapGlobal = new HashMap<>();
}

0 comments on commit e2cb2da

Please sign in to comment.