Skip to content

Commit

Permalink
weight functions are created on the fly when requested (to allow clas…
Browse files Browse the repository at this point in the history
…s extensions)
  • Loading branch information
StephanPreibisch committed Aug 15, 2023
1 parent ecdb09c commit 4708770
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();

Expand All @@ -94,7 +92,13 @@ public BlockData(
public Map<String, ArrayList<Double>> 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; }
Expand All @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,4 +17,6 @@ public abstract class BlockFactory< F extends BlockFactory< F > > implements Ser

public abstract <M extends Model< M >, 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 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,11 @@ public <M extends Model< M >, 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 );
Expand Down Expand Up @@ -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<Function<Double, Double>> createWeightFunctions( final BlockData<?, ?, ?, ZBlockFactory > 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4708770

Please sign in to comment.