diff --git a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/BlockData.java b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/BlockData.java index e024bf1a3..d2e862387 100644 --- a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/BlockData.java +++ b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/BlockData.java @@ -72,14 +72,12 @@ public BlockData( final F blockFactory, // knows how it was created for assembly later? final P solveTypeParameters, final int id, - final ArrayList< Function< Double, Double > > weightF, final ResolvedTileSpecCollection rtsc ) { this.id = id; this.blockFactory = blockFactory; this.solveTypeParameters = solveTypeParameters; this.rtsc = rtsc; - this.weightF = weightF; this.sectionIdToZMap = new HashMap<>(); @@ -94,7 +92,13 @@ public BlockData( public Map> sectionIdToZMap() { return sectionIdToZMap; } public int getId() { return id; } - public double getWeight( final double location, final int dim ) { return weightF.get( dim ).apply( location ); } + public ArrayList< Function< Double, Double > > weightFunctions() + { + if ( weightF == null ) + this.weightF = blockFactory.createWeightFunctions( this ); + + return weightF; + } public P solveTypeParameters() { return solveTypeParameters; } public F blockFactory() { return blockFactory; } @@ -105,8 +109,6 @@ public BlockData( public HashMap< Integer, HashSet< String > > zToTileId() { return zToTileId; } - public ArrayList< Function< Double, Double > > weightFunctions() { return weightF; } - /** * Fetches basic data for all TileSpecs * diff --git a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/BlockFactory.java b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/BlockFactory.java index 225b7f9d5..0961d9bed 100644 --- a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/BlockFactory.java +++ b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/BlockFactory.java @@ -1,9 +1,11 @@ package org.janelia.render.client.newsolver.blockfactories; import java.io.Serializable; +import java.util.ArrayList; +import java.util.function.Function; -import org.janelia.alignment.spec.ResolvedTileSpecCollection; import org.janelia.render.client.newsolver.BlockCollection; +import org.janelia.render.client.newsolver.BlockData; import org.janelia.render.client.newsolver.blocksolveparameters.BlockDataSolveParameters; import mpicbg.models.CoordinateTransform; @@ -15,4 +17,6 @@ public abstract class BlockFactory< F extends BlockFactory< F > > implements Ser public abstract , R extends CoordinateTransform, P extends BlockDataSolveParameters< M, P > > BlockCollection< M, R, P, F > defineBlockCollection( final ParameterProvider< M, P > blockSolveParameterProvider ); + + public abstract ArrayList< Function< Double, Double > > createWeightFunctions( final BlockData< ?, ?, ?, F > block ); } diff --git a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/ZBlockFactory.java b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/ZBlockFactory.java index dece15d2e..0b16ee1b0 100644 --- a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/ZBlockFactory.java +++ b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/blockfactories/ZBlockFactory.java @@ -72,19 +72,11 @@ public , R extends CoordinateTransform, P extends BlockData System.out.println( "Loaded " + rtsc.getTileIds().size() + " tiles."); - // we also define our own distance functions - // here, xy doesn't matter, only z - final ArrayList< Function< Double, Double > > weightF = new ArrayList<>(); - weightF.add( (Function< Double, Double > & Serializable )(x) -> 0.0 ); - weightF.add( (Function< Double, Double > & Serializable )(y) -> 0.0 ); - weightF.add( (Function< Double, Double > & Serializable )(z) -> Math.abs( z - ( initBlock.maxZ() - initBlock.minZ() ) / 2 ) ); - final BlockData< M, R, P, ZBlockFactory > block = new BlockData<>( this, blockSolveParameterProvider.create( rtsc ), initBlock.getId(), - weightF, rtsc ); blockDataList.add( block ); @@ -182,4 +174,20 @@ public static List< ZBlockInit > defineBlockLayout( final int minZ, final int ma // we can return them in one list since each object knows if it is right or left return Stream.concat( leftSets.stream(), rightSets.stream() ).collect( Collectors.toList() ); } + + @Override + public ArrayList> createWeightFunctions( final BlockData block) + { + // we also define our own distance functions + // here, xy doesn't matter, only z + final ArrayList< Function< Double, Double > > weightF = new ArrayList<>(); + + weightF.add( (Function< Double, Double > & Serializable )(x) -> 0.0 ); + weightF.add( (Function< Double, Double > & Serializable )(y) -> 0.0 ); + // TODO: has to be between 0 and 1 + // TODO: needs the Block to know + weightF.add( (Function< Double, Double > & Serializable )(z) -> Math.abs( z - ( block.maxZ() - block.minZ() ) / 2 ) ); + + return weightF; + } } diff --git a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/solvers/affine/AffineAlignBlockWorker.java b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/solvers/affine/AffineAlignBlockWorker.java index 0667603ec..bea217af8 100644 --- a/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/solvers/affine/AffineAlignBlockWorker.java +++ b/render-ws-java-client/src/main/java/org/janelia/render/client/newsolver/solvers/affine/AffineAlignBlockWorker.java @@ -889,7 +889,6 @@ else if ( graphs.size() == 1 ) inputSolveItem.blockData().blockFactory(), // no copy necessary inputSolveItem.blockData().solveTypeParameters(), // no copy necessary id, - inputSolveItem.blockData().weightFunctions(), // no copy necessary newRTSC ) ); ++id;