Skip to content

Commit

Permalink
BlockSolver does not need an instance of R, test that it should work …
Browse files Browse the repository at this point in the history
…with intensities
  • Loading branch information
StephanPreibisch committed Aug 17, 2023
1 parent a140723 commit 35b3e0b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.janelia.render.client.newsolver.assembly.Assembler;
import org.janelia.render.client.newsolver.assembly.ZBlockSolver;
import org.janelia.render.client.newsolver.assembly.matches.SameTileMatchCreatorAffine2D;
import org.janelia.render.client.newsolver.assembly.matches.SameTileMatchCreatorAffineIntensity;
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 @@ -24,9 +25,11 @@
import org.slf4j.LoggerFactory;

import mpicbg.models.Affine2D;
import mpicbg.models.AffineModel1D;
import mpicbg.models.AffineModel2D;
import mpicbg.models.Model;
import mpicbg.models.RigidModel2D;
import mpicbg.models.TranslationModel1D;

public class AffineDistributedSolver
{
Expand Down Expand Up @@ -150,17 +153,27 @@ public static void main( final String[] args ) throws IOException

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

final ZBlockSolver< RigidModel2D, AffineModel2D > solver =
/*
final ZBlockSolver< List< AffineModel1D >, TranslationModel1D, List< AffineModel1D > > solver1D =
new ZBlockSolver<>(
new TranslationModel1D(),
new SameTileMatchCreatorAffineIntensity(),
cmdLineSetup.maxPlateauWidthGlobal,
cmdLineSetup.maxAllowedErrorGlobal,
cmdLineSetup.maxIterationsGlobal,
cmdLineSetup.threadsGlobal );
*/

final ZBlockSolver< AffineModel2D, RigidModel2D, AffineModel2D > solver =
new ZBlockSolver<>(
new RigidModel2D(),
new AffineModel2D(),
new SameTileMatchCreatorAffine2D<>(),
new SameTileMatchCreatorAffine2D<AffineModel2D>(),
cmdLineSetup.maxPlateauWidthGlobal,
cmdLineSetup.maxAllowedErrorGlobal,
cmdLineSetup.maxIterationsGlobal,
cmdLineSetup.threadsGlobal );

final Assembler< RigidModel2D, AffineModel2D, ZBlockFactory > assembler = new Assembler<>( allItems, solver );
final Assembler< AffineModel2D, RigidModel2D, AffineModel2D, ZBlockFactory > assembler = new Assembler<>( allItems, solver );
assembler.createAssembly();

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,41 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Assembler< M, R, F extends BlockFactory< F > >
/**
*
* @author preibischs
*
* @param <Z> - the final output for each TileSpec
* @param <G> - model used for global solve
* @param <R> - the result from the block solves
* @param <F> - the blockFactory that was used
*/
public class Assembler< Z, G, R, F extends BlockFactory< F > >
{
final List<BlockData<?, R, ?, F> > blocks;
final BlockSolver< M, R, F > blockSolver;
final BlockSolver< Z, G, R, F > blockSolver;

/**
* @param blocks - all individually computed blocks
* @param startId - we may need to create DummyBlocks where z slices do not overlap with anything (beginning and end of stack)
*/
public Assembler(
final List<BlockData<?, R, ?, F> > blocks,
final BlockSolver< M, R, F > blockSolver )
final BlockSolver< Z, G, R, F > blockSolver )
{
this.blocks = blocks;
this.blockSolver = blockSolver;
}

public AssemblyMaps< M > createAssembly()
public AssemblyMaps< Z > createAssembly()
{
AssemblyMaps< M > am;
AssemblyMaps< Z > am;

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

// now compute the final alignment for each block
try
Expand All @@ -57,13 +66,13 @@ public AssemblyMaps< M > createAssembly()
*
* @return - the result of the trivial case if it was a single block
*/
protected AssemblyMaps< M > handleTrivialCase()
protected AssemblyMaps< Z > handleTrivialCase()
{
if ( blocks.size() == 1 )
{
LOG.info( "Assembler: only a single block, no solve across blocks necessary." );

final AssemblyMaps< M > am = new AssemblyMaps<>();
final AssemblyMaps< Z > am = new AssemblyMaps<>();

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

Expand All @@ -83,7 +92,7 @@ protected AssemblyMaps< M > handleTrivialCase()
am.zToTileIdGlobal.get( z ).add( tileId );
am.idToTileSpecGlobal.put( tileId, solveItem.rtsc().getTileSpec( tileId ) );

// TODO: Converter from R to M
// TODO: Converter from R to Z
//am.idToFinalModelGlobal.put( tileId, solveItem.idToNewModel().get( tileId ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.BlockFactory;

public interface BlockFusion< R, F extends BlockFactory< F > >
public interface BlockFusion< Z, G, R, F extends BlockFactory< F > >
{
public void globalFusion(
List< ? extends BlockData<?, R, ?, F> > blocks,
AssemblyMaps< ? > am );
AssemblyMaps< Z > am );
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import mpicbg.models.IllDefinedDataPointsException;
import mpicbg.models.NotEnoughDataPointsException;

public abstract class BlockSolver< M, R, F extends BlockFactory< F > >
public abstract class BlockSolver< Z, G, R, F extends BlockFactory< F > >
{
final private M globalModel;
final private G globalModel;

public BlockSolver( final M globalModel )
public BlockSolver( final G globalModel )
{
this.globalModel = globalModel;
}

public M globalModel() { return globalModel; }
public G globalSolveModel() { return globalModel; }

public abstract void globalSolve(
List< ? extends BlockData<?, R, ?, F> > blocks,
AssemblyMaps< M > am ) throws NotEnoughDataPointsException, IllDefinedDataPointsException, InterruptedException, ExecutionException;
AssemblyMaps< Z > am ) throws NotEnoughDataPointsException, IllDefinedDataPointsException, InterruptedException, ExecutionException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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;

public class ZBlockFusion< Z, G, R > implements BlockFusion< Z, G, R, ZBlockFactory >
{

@Override
public void globalFusion(List<? extends BlockData<?, R, ?, ZBlockFactory>> blocks, AssemblyMaps<Z> am) {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import net.imglib2.util.Pair;
import net.imglib2.util.ValuePair;

public class ZBlockSolver< M extends Model< M >, R > extends BlockSolver< M, R, ZBlockFactory >
public class ZBlockSolver< Z, G extends Model< G >, R > extends BlockSolver< Z, G, R, ZBlockFactory >
{
final M globalModel;
final R resultModel;
final G globalModel;
final SameTileMatchCreator< R > sameTileMatchCreator;

final int maxPlateauWidth;
Expand All @@ -36,8 +35,7 @@ public class ZBlockSolver< M extends Model< M >, R > extends BlockSolver< M, R,
final int numThreads;

public ZBlockSolver(
final M globalModel,
final R resultModel,
final G globalModel,
final SameTileMatchCreator< R > sameTileMatchCreator,
final int maxPlateauWidth,
final double maxAllowedError,
Expand All @@ -47,7 +45,6 @@ public ZBlockSolver(
super( globalModel );

this.globalModel = globalModel;
this.resultModel = resultModel;
this.sameTileMatchCreator = sameTileMatchCreator;
this.maxPlateauWidth = maxPlateauWidth;
this.maxAllowedError = maxAllowedError;
Expand All @@ -58,7 +55,7 @@ public ZBlockSolver(
@Override
public void globalSolve(
final List< ? extends BlockData<?, R, ?, ZBlockFactory > > blocks,
final AssemblyMaps< M > am ) throws NotEnoughDataPointsException, IllDefinedDataPointsException, InterruptedException, ExecutionException
final AssemblyMaps< Z > am ) throws NotEnoughDataPointsException, IllDefinedDataPointsException, InterruptedException, ExecutionException
{
// local structures required for solvig
final HashMap<
Expand All @@ -72,7 +69,7 @@ public void globalSolve(

final TileConfiguration tileConfigBlocks = new TileConfiguration();

final HashMap< BlockData<?, R, ?, ZBlockFactory >, Tile< M > > blockToTile = new HashMap<>();
final HashMap< BlockData<?, R, ?, ZBlockFactory >, Tile< G > > blockToTile = new HashMap<>();

// important: all images within one block must be connected to each other!

Expand All @@ -82,7 +79,7 @@ public void globalSolve(
for ( int a = 0; a < blocks.size() - 1; ++a )
{
final BlockData<?, R, ?, ZBlockFactory > solveItemA = blocks.get( a );
blockToTile.putIfAbsent( solveItemA, new Tile<M>( globalModel.copy() ) );
blockToTile.putIfAbsent( solveItemA, new Tile< G >( globalModel.copy() ) );

for ( int z = solveItemA.minZ(); z <= solveItemA.maxZ(); ++z )
{
Expand All @@ -94,7 +91,7 @@ public void globalSolve(
for ( int b = a + 1; b < blocks.size(); ++b )
{
final BlockData<?, R, ?, ZBlockFactory > solveItemB = blocks.get( b );
blockToTile.putIfAbsent( solveItemB, new Tile<M>( globalModel.copy() ) );
blockToTile.putIfAbsent( solveItemB, new Tile< G >( globalModel.copy() ) );

LOG.info( "globalSolve: solveItemB z range is {} to {}", solveItemB.minZ(), solveItemB.maxZ());

Expand Down Expand Up @@ -147,8 +144,8 @@ public void globalSolve(
sameTileMatchCreator.addMatches( tileSpecAB, modelA, modelB, matchesAtoB );
}

final Tile< M > tileA = blockToTile.get( solveItemA );
final Tile< M > tileB = blockToTile.get( solveItemB );
final Tile< G > tileA = blockToTile.get( solveItemA );
final Tile< G > tileB = blockToTile.get( solveItemB );

tileA.connect( tileB, matchesAtoB );

Expand Down Expand Up @@ -194,7 +191,7 @@ public void globalSolve(
final BlockData<?, R, ?, ZBlockFactory > solveItemB = null; //solveItemA.createCorrespondingDummySolveItem( id, z );

zToBlockPairs.get( z ).add( new ValuePair<>( new ValuePair<>( solveItemA, solveItemB ), tileIds ) );
blockToTile.putIfAbsent( solveItemB, new Tile<M>( globalModel.copy() ) );
blockToTile.putIfAbsent( solveItemB, new Tile< G >( globalModel.copy() ) );

//++id;

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

import java.util.List;

import org.janelia.alignment.spec.TileSpec;

import mpicbg.models.Affine2D;
import mpicbg.models.AffineModel1D;
import mpicbg.models.Point;
import mpicbg.models.PointMatch;

public class SameTileMatchCreatorAffineIntensity implements SameTileMatchCreator< List< AffineModel1D > >
{
final int samplesPerDimension;

public SameTileMatchCreatorAffineIntensity( final int samplesPerDimension )
{
this.samplesPerDimension = samplesPerDimension;
}

public SameTileMatchCreatorAffineIntensity() { this( 2 ); }

@Override
public void addMatches(TileSpec tileSpec, List< AffineModel1D > modelA, List< AffineModel1D > modelB, List<PointMatch> matchesAtoB)
{
// TODO: make 64 matches that map A to p and B to q

/*
// make a regular grid
final double sampleWidth = (tileSpec.getWidth() - 1.0) / (samplesPerDimension - 1.0);
final double sampleHeight = (tileSpec.getHeight() - 1.0) / (samplesPerDimension - 1.0);
for (int y = 0; y < samplesPerDimension; ++y)
{
final double sampleY = y * sampleHeight;
for (int x = 0; x < samplesPerDimension; ++x)
{
final double[] p = new double[] { x * sampleWidth, sampleY };
final double[] q = new double[] { x * sampleWidth, sampleY };
modelA.applyInPlace( p );
modelB.applyInPlace( q );
matchesAtoB.add(new PointMatch( new Point(p), new Point(q) ));
}
}
*/
}

}

0 comments on commit 35b3e0b

Please sign in to comment.