Skip to content

Commit

Permalink
add BlockData as parameters for SameTileMatchCreator.java as Michael …
Browse files Browse the repository at this point in the history
…proposed, makes sense ... question is if we need generics for BlockParameter and BlockFactory (which we would in case a specific SameTileMatchCreator.java implementation requires a certain type of either
  • Loading branch information
StephanPreibisch committed Aug 19, 2023
1 parent fb6285e commit e0f35ee
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class ZBlockSolver< Z, G extends Model< G >, R > extends BlockSolver< Z, G, R, ZBlockFactory >
{
final G globalModel;
final SameTileMatchCreator< R > sameTileMatchCreator;
final SameTileMatchCreator< R, ZBlockFactory > sameTileMatchCreator;

final int maxPlateauWidth;
final double maxAllowedError;
Expand All @@ -46,7 +46,7 @@ public class ZBlockSolver< Z, G extends Model< G >, R > extends BlockSolver< Z,

public ZBlockSolver(
final G globalModel,
final SameTileMatchCreator< R > sameTileMatchCreator,
final SameTileMatchCreator< R, ZBlockFactory > sameTileMatchCreator,
final int maxPlateauWidth,
final double maxAllowedError,
final int maxIterations,
Expand Down Expand Up @@ -143,7 +143,7 @@ public ZBlockSolver(
final R modelA = solveItemA.idToNewModel().get( tileId );
final R modelB = solveItemB.idToNewModel().get( tileId );

sameTileMatchCreator.addMatches( tileSpecAB, modelA, modelB, matchesAtoB );
sameTileMatchCreator.addMatches( tileSpecAB, modelA, modelB, solveItemA, solveItemB, matchesAtoB );
}

final Tile< G > tileA = blockToTile.get( solveItemA );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@

import mpicbg.models.PointMatch;
import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.BlockFactory;

public interface SameTileMatchCreator< R >
public interface SameTileMatchCreator< R, F extends BlockFactory< F > >
{
/**
* Add a reasonable number of matches to the provided List that map the same TileSpec from one BlockData to another
*
* @param tileSpec - the TileSpec of the common TileSpec for which we have two models
* @param modelA - model of BlockData A, needs to be applied to p
* @param modelB - model of BlockData A, needs to be applied to q
* @param blockContextA - the block that is queried for context data
* @param blockContextB - the block that is queried for context data
* @param matchesAtoB - list to add the PointMatches to
*/
public void addMatches(
TileSpec tileSpec,
R modelA, // TODO: Pair< BlockDataA, modelA >
R modelB, // TODO: Pair< BlockDataB, modelB >
R modelA,
R modelB,
BlockData<?, R, ?, F> blockContextA,
BlockData<?, R, ?, F> blockContextB,
List< PointMatch > matchesAtoB );


// TODO: IMPORTANT: you need both blocks, blockA for modelA and blockB for modelB, no (see above)
// TODO: that would also get rid of the method below that is just needed for some implementations and seems incomplete
/**
/*
* Set the block context in which the matches are created - this is required for the intensity based match creator
* @param blockContext - the block that is queried for context data
*/
void setBlockContext(BlockData<?, ?, ?, ?> blockContext);
//void setBlockContext(BlockData<?, ?, ?, ?> blockContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mpicbg.models.Point;
import mpicbg.models.PointMatch;
import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.BlockFactory;

/**
* Note: this code would work with any CoordinateTransform, however it is only the right thing to do if the underlying model is some 2D-affine
Expand All @@ -16,7 +17,7 @@
*
* @param <R> - the result model of the block solves
*/
public class SameTileMatchCreatorAffine2D< R extends Affine2D< R > > implements SameTileMatchCreator< R >
public class SameTileMatchCreatorAffine2D< R extends Affine2D< R >, F extends BlockFactory< F > > implements SameTileMatchCreator< R, F >
{
final int samplesPerDimension;

Expand All @@ -28,7 +29,12 @@ public SameTileMatchCreatorAffine2D( final int samplesPerDimension )
public SameTileMatchCreatorAffine2D() { this( 2 ); }

@Override
public void addMatches(TileSpec tileSpec, R modelA, R modelB, List<PointMatch> matchesAtoB)
public void addMatches(
TileSpec tileSpec,
R modelA, R modelB,
BlockData<?, R, ?, F> blockContextA,
BlockData<?, R, ?, F> blockContextB,
List<PointMatch> matchesAtoB)
{
// make a regular grid
final double sampleWidth = (tileSpec.getWidth() - 1.0) / (samplesPerDimension - 1.0);
Expand All @@ -49,9 +55,4 @@ public void addMatches(TileSpec tileSpec, R modelA, R modelB, List<PointMatch> m
}
}
}

// not needed for alignment
@Override
public void setBlockContext(final BlockData<?, ?, ?, ?> blockContext) {}

}
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package org.janelia.render.client.newsolver.assembly.matches;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import mpicbg.models.Point;
import org.janelia.alignment.spec.TileSpec;
import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.BlockFactory;

import mpicbg.models.AffineModel1D;
import mpicbg.models.Point;
import mpicbg.models.PointMatch;
import org.janelia.render.client.newsolver.BlockData;

public class SameTileMatchCreatorAffineIntensity implements SameTileMatchCreator<ArrayList<AffineModel1D>> {
public class SameTileMatchCreatorAffineIntensity< F extends BlockFactory< F > > implements SameTileMatchCreator<ArrayList<AffineModel1D>, F> {

private BlockData<?, ?, ?, ?> blockContext = null;
@Override
public void addMatches(
final TileSpec tileSpec,
final ArrayList<AffineModel1D> modelsA,
final ArrayList<AffineModel1D> modelsB,
final BlockData<?, ArrayList<AffineModel1D>, ?, F> blockContextA,
final BlockData<?, ArrayList<AffineModel1D>, ?, F> blockContextB,
final List<PointMatch> matchesAtoB) {

if (modelsA.size() != modelsB.size())
throw new IllegalArgumentException("Lists of models for A and B must have the same size");

final ArrayList<Double> averages = blockContext.idToAverages().get(tileSpec.getTileId());
// TODO: in this case it doesn't matter if it's A or B, for other cases the blocks might be useful
final ArrayList<Double> averages = blockContextA.idToAverages().get(tileSpec.getTileId());

final int nModels = modelsA.size();
for (int i = 0; i < nModels; ++i) {
Expand All @@ -41,10 +43,4 @@ public void addMatches(
matchesAtoB.add(new PointMatch(new Point(p), new Point(q)));
}
}

@Override
public void setBlockContext(final BlockData<?, ?, ?, ?> blockContext) {
this.blockContext = blockContext;
}

}

0 comments on commit e0f35ee

Please sign in to comment.