Skip to content

Commit

Permalink
Block can now compute center of mass using the solveparameter object …
Browse files Browse the repository at this point in the history
…(queried by XYBlockFactory)
  • Loading branch information
StephanPreibisch committed Aug 27, 2023
1 parent df8eba5 commit 8e65023
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public ArrayList< Function< Double, Double > > createWeightFunctions()
return blockFactory.createWeightFunctions( this );
}

/**
* @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 P solveTypeParameters() { return solveTypeParameters; }
public F blockFactory() { return blockFactory; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Function;

Expand Down Expand Up @@ -133,7 +134,28 @@ public <M, R, P extends BlockDataSolveParameters<M, R, P>> BlockCollection<M, R,
public ArrayList<Function<Double, Double>> createWeightFunctions( final BlockData<?, ?, ?, XYBlockFactory> block )
{
// TODO Auto-generated method stub
return null;

// TODO: this will be ugly ... need to cast here, or make M part of BlockFactory - which is ugly too, projects all the way through
// and creates ugly long generics constructs, just tried it out

// TODO: Or the block must be able to compute it's center of mass and return it
// (which makes sense when we adjust intensities, because then the NEW model is for intensities, not for transformations)
// (so actually the parameter object should be able to compute the center of mass of a block)
// i.e. blockdata should delegate the center-of-mass computation to the parameter object

// compute current center-of-mass
final double[] center = block.centerOfMass();

// we also define our own distance functions
// here, z doesn't matter, only xy
final ArrayList< Function< Double, Double > > weightF = new ArrayList<>();

weightF.add( (x) -> 0.0 );
weightF.add( (y) -> 0.0 );

weightF.add( (z) -> 0.0 );

return weightF;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public BlockDataSolveParameters(

public M blockSolveModel() { return blockSolveModel; }

/**
* @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 abstract < F extends BlockFactory< F > > Worker< M, R, P, F > createWorker(
final BlockData< M, R, P, F > blockData,
final int startId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.janelia.render.client.newsolver.blocksolveparameters;

import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.function.Function;

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 @@ -144,4 +147,32 @@ public < F extends BlockFactory< F > > Worker< M, AffineModel2D, FIBSEMAlignment
{
return new AffineAlignBlockWorker<>( blockData, startId, threadsWorker );
}

@Override
public <F extends BlockFactory<F>> double[] centerOfMass( final BlockData<M, AffineModel2D, FIBSEMAlignmentParameters<M, S>, F> blockData)
{
final HashMap<String, AffineModel2D> models = blockData.idToNewModel();

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

for ( final Entry<String, AffineModel2D> entry : models.entrySet() )
{
final TileSpec ts = blockData.rtsc().getTileSpec( entry.getKey() );
final double[] coord = new double[] { (ts.getWidth() - 1) /2.0, (ts.getHeight() - 1) /2.0 };

entry.getValue().applyInPlace( coord );

c[ 0 ] += coord[ 0 ];
c[ 1 ] += coord[ 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 @@ -3,14 +3,14 @@
import java.io.IOException;
import java.util.ArrayList;

import mpicbg.models.AffineModel1D;

import org.janelia.render.client.RenderDataClient;
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.newsolver.solvers.intensity.AffineIntensityCorrectionBlockWorker;

import mpicbg.models.AffineModel1D;

/**
*
* @author minnerbe
Expand Down Expand Up @@ -68,4 +68,31 @@ 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;
}
}

0 comments on commit 8e65023

Please sign in to comment.