Skip to content

Commit

Permalink
add default implementations of boundingbox() and centerofmass() to Bl…
Browse files Browse the repository at this point in the history
…ockDataSolveParameters.java, assuming the alignment does not change
  • Loading branch information
StephanPreibisch committed Aug 27, 2023
1 parent 8e65023 commit 4711bca
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ public ArrayList< Function< Double, Double > > createWeightFunctions()
/**
* @return - the center of mass of all tiles that are part of this solve. If the coordinates are changed, the current ones should be used.
*/
public double[] centerOfMass()
{
return solveTypeParameters().centerOfMass( this );
}
public double[] centerOfMass() { return solveTypeParameters().centerOfMass( this ); }

/**
* @return - the bounding box of all tiles that are part of this solve. If the coordinates are changed, the current ones should be used.
*/
public Pair<double[],double[]> boundingBox( final BlockData<M, R, P, F> blockData ) { return solveTypeParameters().boundingBox( blockData ); }

public P solveTypeParameters() { return solveTypeParameters; }
public F blockFactory() { return blockFactory; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.io.Serializable;

import org.janelia.alignment.spec.TileSpec;
import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.BlockFactory;
import org.janelia.render.client.newsolver.solvers.Worker;
import org.janelia.render.client.solver.SerializableValuePair;

import net.imglib2.util.Pair;

/**
*
Expand Down Expand Up @@ -44,10 +48,62 @@ public BlockDataSolveParameters(

public M blockSolveModel() { return blockSolveModel; }

/**
* @return - the bounding box of all tiles that are part of this solve. If the coordinates are changed, the current ones should be used.
*/
public <F extends BlockFactory<F>> Pair<double[],double[]> boundingBox( final BlockData<M, R, P, F> blockData )
{
double minX = Double.MAX_VALUE;
double maxX = -Double.MAX_VALUE;

double minY = Double.MAX_VALUE;
double maxY = -Double.MAX_VALUE;

double minZ = Double.MAX_VALUE;
double maxZ = -Double.MAX_VALUE;

for ( final TileSpec ts : blockData.rtsc().getTileSpecs() )
{
minX = Math.min( minX, ts.getMinX() );
minY = Math.min( minY, ts.getMinY() );
minZ = Math.min( minZ, ts.getZ() );

maxX = Math.max( maxX, ts.getMaxX() );
maxY = Math.max( maxY, ts.getMaxY() );
maxZ = Math.max( maxZ, ts.getZ() );
}

return new SerializableValuePair<>( new double[]{minX,minY,minZ}, new double[]{maxX,maxY,maxZ} );
}

/**
* @return - the center of mass of all tiles that are part of this solve. If the coordinates are changed, the current ones should be used.
*/
public abstract < F extends BlockFactory< F > > double[] centerOfMass( final BlockData<M, R, P, F > blockData );
public < F extends BlockFactory< F > > double[] centerOfMass( final BlockData< M, R, P, F > blockData )
{

final double[] c = new double[ 3 ];
int count = 0;

for ( final String tileId : blockData.idToNewModel().keySet() )
{
final TileSpec ts = blockData.rtsc().getTileSpec( tileId );

// the affine transform for the tile
final double[] tmp = ts.getWorldCoordinates( (ts.getWidth() - 1) /2.0, (ts.getHeight() - 1) /2.0 );

c[ 0 ] += tmp[ 0 ];
c[ 1 ] += tmp[ 1 ];
c[ 2 ] += ts.getZ();
++count;
}

c[ 0 ] /= (double)count;
c[ 1 ] /= (double)count;
c[ 2 ] /= (double)count;

return c;
}

public abstract < F extends BlockFactory< F > > Worker< M, R, P, F > createWorker(
final BlockData< M, R, P, F > blockData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public < F extends BlockFactory< F > > Worker< M, AffineModel2D, FIBSEMAlignment
@Override
public <F extends BlockFactory<F>> double[] centerOfMass( final BlockData<M, AffineModel2D, FIBSEMAlignmentParameters<M, S>, F> blockData)
{
if ( blockData.idToNewModel() == null || blockData.idToNewModel().size() == 0 )
return super.centerOfMass( blockData );

final HashMap<String, AffineModel2D> models = blockData.idToNewModel();

final double[] c = new double[ 3 ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.ArrayList;

import org.janelia.alignment.spec.TileSpec;
import org.janelia.render.client.newsolver.BlockData;
import org.janelia.render.client.newsolver.blockfactories.BlockFactory;
import org.janelia.render.client.newsolver.solvers.Worker;
Expand Down Expand Up @@ -68,31 +67,4 @@ public <F extends BlockFactory<F>> Worker<M, ArrayList<AffineModel1D>, FIBSEMInt
throw new RuntimeException(e);
}
}

@Override
public <F extends BlockFactory<F>> double[] centerOfMass( final BlockData<M, ArrayList<AffineModel1D>, FIBSEMIntensityCorrectionParameters<M>, F> blockData)
{

final double[] c = new double[ 3 ];
int count = 0;

for ( final String tileId : blockData.idToNewModel().keySet() )
{
final TileSpec ts = blockData.rtsc().getTileSpec( tileId );

// the affine transform for the tile
final double[] tmp = ts.getWorldCoordinates( (ts.getWidth() - 1) /2.0, (ts.getHeight() - 1) /2.0 );

c[ 0 ] += tmp[ 0 ];
c[ 1 ] += tmp[ 1 ];
c[ 2 ] += ts.getZ();
++count;
}

c[ 0 ] /= (double)count;
c[ 1 ] /= (double)count;
c[ 2 ] /= (double)count;

return c;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import org.janelia.render.client.newsolver.solvers.WorkerTools.LayerDetails;
import org.janelia.render.client.solver.ConstantAffineModel2D;
import org.janelia.render.client.solver.Graph;
import org.janelia.render.client.solver.SolveTools;
import org.janelia.render.client.solver.SerializableValuePair;
import org.janelia.render.client.solver.SolveItem;
import org.janelia.render.client.solver.SolveTools;
import org.janelia.render.client.solver.StabilizingAffineModel2D;
import org.janelia.render.client.solver.matchfilter.MatchFilter;
import org.janelia.render.client.solver.matchfilter.NoMatchFilter;
Expand Down Expand Up @@ -281,7 +280,7 @@ protected Tile<M> getOrBuildTile( final String id, final TileSpec tileSpec )
if (!inputSolveItem.idToTileMap().containsKey(id))
{
final Pair<Tile<M>, AffineModel2D> pair =
SolveTools.buildTileFromSpec( inputSolveItem.blockData().solveTypeParameters().blockSolveModel().copy(), SolveItem.samplesPerDimension, tileSpec );
SolveTools.buildTileFromSpec( inputSolveItem.blockData().solveTypeParameters().blockSolveModel().copy(), AffineBlockDataWrapper.samplesPerDimension, tileSpec );
tile = pair.getA();
inputSolveItem.idToTileMap().put(id, tile);
inputSolveItem.tileToIdMap().put(tile, id);
Expand Down

0 comments on commit 4711bca

Please sign in to comment.