Skip to content

Commit

Permalink
Add automated spot radius configuring
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Dec 2, 2024
1 parent fc00784 commit c74ff7d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ private void initDataSource( DataSource dataSource, String log )

if ( dataSource instanceof SpotDataSource )
{

// build spots image from spots table
final SpotImageCreator spotImageCreator = new SpotImageCreator( ( SpotDataSource ) dataSource, this );
DataStore.addImage( spotImageCreator.get() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ private void initSpotRadiusItem()
for ( SourceAndConverter sourceAndConverter : sourceAndConverters )
{
final SpotAnnotationImage spotAnnotationImage = ( SpotAnnotationImage ) DataStore.sourceToImage().get( sourceAndConverter );
spotRadiusItem.setValue( this, spotAnnotationImage.getRadius() );

Double radius = spotAnnotationImage.getRadius();
if ( radius != null )
spotRadiusItem.setValue( this, radius );
else
spotRadiusItem.setValue( this, 1.0D );

return;
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/embl/mobie/lib/SpotImageCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ public SpotAnnotationImage< AnnotatedSpot > get()

final DefaultAnnData< AnnotatedSpot > spotAnnData = new DefaultAnnData<>( tableModel );

spotAnnotationImage = new SpotAnnotationImage( spotDataSource.getName(), spotAnnData, 1.0, spotDataSource.boundingBoxMin, spotDataSource.boundingBoxMax );
spotAnnotationImage = new SpotAnnotationImage(
spotDataSource.getName(),
spotAnnData,
null,
spotDataSource.boundingBoxMin,
spotDataSource.boundingBoxMax );
}

return spotAnnotationImage;
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/org/embl/mobie/lib/image/SpotAnnotationImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ public class SpotAnnotationImage< AS extends AnnotatedSpot > implements Annotati
private Source< ? extends Volatile< UnsignedIntType > > volatileSource = null;
private KDTree< AS > kdTree;
private RealMaskRealInterval mask;
private double radius;
private Double radius;
private double[] boundingBoxMin;
private double[] boundingBoxMax;
private AffineTransform3D affineTransform3D;
private Source< AnnotationType< AS > > source;
private TransformedSource< AnnotationType< AS > > transformedSource;

public SpotAnnotationImage( String name, DefaultAnnData< AS > annData, double radius, @Nullable double[] boundingBoxMin, @Nullable double[] boundingBoxMax )
public SpotAnnotationImage(
String name,
DefaultAnnData< AS > annData,
@Nullable Double radius,
@Nullable double[] boundingBoxMin,
@Nullable double[] boundingBoxMax )
{
this.name = name;
this.annData = annData;
Expand All @@ -77,14 +82,17 @@ public SpotAnnotationImage( String name, DefaultAnnData< AS > annData, double ra
createImage();
}

public double getRadius()
public Double getRadius()
{
return radius;
}

public void setRadius( double radius )
public void setRadius( Double radius )
{
this.radius = radius;
if ( radius != null )
{
this.radius = radius;
}
}

private void createImage()
Expand All @@ -107,6 +115,16 @@ private void createImage()

mask = GeomMasks.closedBox( boundingBoxMin, boundingBoxMax );

if ( radius == null)
{
// Assign each spot an area that is a fraction of the total
// covered area divided by the number of spots.
// A = Pi R^2 => R ~ Sqrt( A )
double area = ( mask.realMax( 0 ) - mask.realMin( 0 ) )
* ( mask.realMax( 1 ) - mask.realMin( 1 ) );
radius = Math.sqrt( area / annotations.size() ) / 10.0;
}

// TODO: code duplication with RegionLabelImage
final ArrayList< Integer > timePoints = configureTimePoints();
final Interval interval = Intervals.smallestContainingInterval( getMask() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class SpotDisplay< AR extends AnnotatedRegion > extends AbstractAnnotatio

private Set< String > selectedSpotIds;

public double spotRadius = 1.0D;
public Double spotRadius;

// Runtime

Expand Down

0 comments on commit c74ff7d

Please sign in to comment.