Skip to content

Commit

Permalink
Merge branch 'tpsRmMpicbg'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Aug 10, 2017
2 parents 82105fd + 8806267 commit 013dae1
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 72 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<dependency>
<groupId>jitk</groupId>
<artifactId>jitk-tps</artifactId>
<version>2.1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/bdv/viewer/BigWarpOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

import javax.swing.JTable;

import jitk.spline.ThinPlateR2LogRSplineKernelTransform;
import mpicbg.models.CoordinateTransform;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.realtransform.RealTransform;
import bdv.gui.BigWarpLandmarkPanel;
import bdv.viewer.state.ViewerState;
import bigwarp.landmarks.LandmarkTableModel;
Expand All @@ -27,7 +26,7 @@ public class BigWarpOverlay {

protected LandmarkTableModel landmarkModel;

protected CoordinateTransform estimatedXfm;
protected RealTransform estimatedXfm;

protected boolean isTransformed = false;

Expand Down Expand Up @@ -214,13 +213,14 @@ else if( hoveredIndex == index )

/**
* Update data to show in the overlay.
* @param state the viewer state
*/
public void setViewerState( final ViewerState state )
{
this.state = state;
}

public void setEstimatedTransform( final ThinPlateR2LogRSplineKernelTransform estimatedXfm )
public void setEstimatedTransform( final RealTransform estimatedXfm )
{
this.estimatedXfm = estimatedXfm;
}
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/bigwarp/BigWarp.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,10 @@ else if ( ARGBType.class.isInstance( baseType ) )

/**
* TODO Make a PR that updates this method in InitializeViewerState in bdv-core
* @param cumulativeMinCutoff
* @param cumulativeMaxCutoff
* @param state
* @param setupAssignments
* @param cumulativeMinCutoff the min image intensity
* @param cumulativeMaxCutoff the max image intensity
* @param state the viewer state
* @param setupAssignments the setup assignments
*/
public static void initBrightness( final double cumulativeMinCutoff, final double cumulativeMaxCutoff, final ViewerState state, final SetupAssignments setupAssignments )
{
Expand Down Expand Up @@ -1026,6 +1026,7 @@ public int getSelectedUnpairedRow( boolean isMoving )
*
* @param ptarray the point location
* @param isMoving is the point location in moving image space
* @param viewer the viewer panel
* @return an error string if an error occurred, empty string otherwise
*/
public String addPoint( final double[] ptarray, final boolean isMoving, final BigWarpViewerPanel viewer )
Expand Down Expand Up @@ -1074,6 +1075,7 @@ protected int selectedLandmark( final double[] pt, final boolean isMoving )
*
* @param pt the point location
* @param isMoving is the point location in moving image space
* @param selectInTable also select the landmark in the table
* @return the index of the selected landmark
*/
protected int selectedLandmark( final double[] pt, final boolean isMoving, final boolean selectInTable )
Expand Down Expand Up @@ -1774,8 +1776,9 @@ private void setTransformationAll( final ThinPlateR2LogRSplineKernelTransform tr
final WarpMagnitudeSource< ? > wmSrc = ( ( WarpMagnitudeSource< ? > ) sources.get( warpMagSourceIndex ).getSpimSource() );
final GridSource< ? > gSrc = ( ( GridSource< ? > ) sources.get( gridSourceIndex ).getSpimSource() );

wmSrc.setWarp( transform );
gSrc.setWarp( transform );
TpsTransformWrapper tpsRealXfm = new TpsTransformWrapper( 3, transform );
wmSrc.setWarp( tpsRealXfm );
gSrc.setWarp( tpsRealXfm );
}

public boolean restimateTransformation()
Expand Down Expand Up @@ -1840,6 +1843,7 @@ protected int detectNumDims()

/**
* The display will be in 3d if any of the input sources are 3d.
* @param sources the sources
* @return dimension of the input sources
*/
protected static int detectNumDims( Collection< SourceAndConverter< ? > > sources )
Expand Down Expand Up @@ -2210,6 +2214,8 @@ public void mouseMoved( final MouseEvent e )

/**
* Adds a point in the moving and fixed images at the same point.
* @param pt the point
* @param isMovingImage is the point in moving image space
*/
public void addFixedPoint( final RealPoint pt, final boolean isMovingImage )
{
Expand Down
1 change: 0 additions & 1 deletion src/main/java/bigwarp/landmarks/LandmarkTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ public void updateAllWarpedPoints()
* necessary.
* <p>
* An action is taken if, for the input row if:
* <p>
* <ul><li>1) There is a point in moving space, and
* <li>2) There is not a point in target space, and
* <li>3) A transformation has been estimated.
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/bigwarp/source/GridRandomAccess.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package bigwarp.source;

import jitk.spline.ThinPlateR2LogRSplineKernelTransform;
import mpicbg.models.CoordinateTransform;

import net.imglib2.AbstractLocalizable;
import net.imglib2.Localizable;
import net.imglib2.RandomAccess;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.type.numeric.RealType;

public class GridRandomAccess< T extends RealType<T>> extends AbstractLocalizable implements RandomAccess< T >
{

CoordinateTransform warp;
RealTransform warp;
T value;

protected GridRandomAccess( long[] dimensions )
{
this( dimensions, null, null );
}

protected GridRandomAccess( long[] dimensions, T value, CoordinateTransform warp )
protected GridRandomAccess( long[] dimensions, T value, RealTransform warp )
{
super( dimensions.length );
this.value = value;
Expand All @@ -30,8 +30,9 @@ public T get()

double[] mypt = new double[ this.numDimensions() ];
this.localize( mypt );

double[] warpRes = warp.apply( mypt );

double[] warpRes = new double[ warp.numTargetDimensions() ];
warp.apply( mypt, warpRes );

T out = value.copy();

Expand Down Expand Up @@ -62,8 +63,7 @@ private boolean withinRad( double[] pt1, double[] pt2, double rad )

public RandomAccess<T> copy()
{
return new GridRandomAccess< T >( new long[ position.length ], value.copy(),
((ThinPlateR2LogRSplineKernelTransform)warp) );
return new GridRandomAccess< T >( new long[ position.length ], value.copy(), warp );
}

public RandomAccess<T> copyRandomAccess()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package bigwarp.source;

import mpicbg.models.CoordinateTransform;
import net.imglib2.AbstractInterval;
import net.imglib2.Interval;
import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.type.numeric.RealType;

public class GridRandomAccessibleInterval<T extends RealType<T>> extends AbstractInterval implements RandomAccessibleInterval<T>
{
CoordinateTransform warp;
RealTransform warp;
GridRandomAccess< T > ra;

public GridRandomAccessibleInterval( Interval interval, T t, CoordinateTransform warp )
public GridRandomAccessibleInterval( Interval interval, T t, RealTransform warp )
{
super( interval );
this.warp = warp;
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/bigwarp/source/GridRealRandomAccess.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package bigwarp.source;

import bigwarp.source.GridSource.GRID_TYPE;
import jitk.spline.ThinPlateR2LogRSplineKernelTransform;
import mpicbg.models.CoordinateTransform;
import net.imglib2.AbstractRealLocalizable;
import net.imglib2.Localizable;
import net.imglib2.RealLocalizable;
import net.imglib2.RealRandomAccess;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.real.DoubleType;


public class GridRealRandomAccess< T extends RealType<T>> extends AbstractRealLocalizable implements RealRandomAccess< T >
{

protected CoordinateTransform warp;
protected RealTransform warp;

private T value;
private GRID_TYPE method = GRID_TYPE.MOD;
Expand All @@ -30,12 +29,12 @@ protected GridRealRandomAccess( double[] dimensions )
this( dimensions, null, null );
}

protected GridRealRandomAccess( double[] dimensions, T value, CoordinateTransform warp )
protected GridRealRandomAccess( double[] dimensions, T value, RealTransform warp )
{
this( dimensions, value, warp, GRID_TYPE.MOD );
}

protected GridRealRandomAccess( double[] dimensions, T value, CoordinateTransform warp, GRID_TYPE method )
protected GridRealRandomAccess( double[] dimensions, T value, RealTransform warp, GRID_TYPE method )
{
super( dimensions.length );
this.value = value;
Expand Down Expand Up @@ -92,10 +91,14 @@ private T getLine( double[] pt )
{
double[] warpRes;
if( warp != null )
warpRes = warp.apply( pt );
{
warpRes = new double[ warp.numTargetDimensions() ];
warp.apply( pt, warpRes );
}
else
{
warpRes = pt;

}
int nd = warpRes.length;
if( is2d )
nd = 2;
Expand Down Expand Up @@ -127,9 +130,7 @@ else if( tmp >= (gridSpacing - gridHalfWidth ) )
}

}

// if( i > 0 ) val /= i;


T out = value.copy();
if( val < gridWidth )
{
Expand All @@ -146,10 +147,15 @@ private T getMod( double[] pt )
{
double[] warpRes;
if( warp != null )
warpRes = warp.apply( pt );
{
warpRes = new double[ warp.numTargetDimensions() ];
warp.apply( pt, warpRes );
}
else
{
warpRes = pt;

}

double val = 0.0;
for( int d = 0; d < warpRes.length; d++ )
{
Expand Down Expand Up @@ -193,7 +199,7 @@ public RealRandomAccess<T> copy()
else
{
GridRealRandomAccess< T > ra = new GridRealRandomAccess< T >( new double[ position.length ], value.copy(),
((ThinPlateR2LogRSplineKernelTransform)warp), this.method );
warp, this.method );
ra.gridSpacing = this.gridSpacing;
ra.gridWidth = this.gridWidth;
ra.gridHalfWidth = this.gridHalfWidth;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package bigwarp.source;

import mpicbg.models.CoordinateTransform;
import net.imglib2.AbstractRealInterval;
import net.imglib2.Interval;
import net.imglib2.RealInterval;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.type.numeric.RealType;

public class GridRealRandomAccessibleRealInterval<T extends RealType<T>> extends AbstractRealInterval implements RealRandomAccessibleRealInterval<T>
{
GridRealRandomAccess<T> ra;

public GridRealRandomAccessibleRealInterval( Interval interval, T t, CoordinateTransform warp )
public GridRealRandomAccessibleRealInterval( Interval interval, T t, RealTransform warp )
{
super( interval );
ra = new GridRealRandomAccess< T >( new double[ interval.numDimensions() ], t, warp );
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/bigwarp/source/GridSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import bdv.viewer.Interpolation;
import bdv.viewer.Source;
import bigwarp.BigWarp.BigWarpData;
import mpicbg.models.CoordinateTransform;
import mpicbg.spim.data.sequence.VoxelDimensions;
import net.imglib2.Interval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealRandomAccessible;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.type.numeric.RealType;
import net.imglib2.view.Views;

Expand All @@ -28,7 +28,7 @@ public enum GRID_TYPE { MOD, LINE };

protected T type;

public GridSource( String name, BigWarpData data, T t, CoordinateTransform warp )
public GridSource( String name, BigWarpData data, T t, RealTransform warp )
{
this.name = name;
this.type = t.copy();
Expand Down Expand Up @@ -62,7 +62,7 @@ public void setGridWidth( double width )
//
// }

public void setWarp( CoordinateTransform warp )
public void setWarp( RealTransform warp )
{
gridImg.ra.warp = warp;
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/bigwarp/source/WarpMagnitudeRandomAccess.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package bigwarp.source;

import mpicbg.models.AbstractModel;
import mpicbg.models.CoordinateTransform;
import net.imglib2.AbstractRealLocalizable;
import net.imglib2.Localizable;
import net.imglib2.RealLocalizable;
import net.imglib2.RealRandomAccess;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.type.numeric.RealType;

public class WarpMagnitudeRandomAccess< T extends RealType<T>> extends AbstractRealLocalizable implements RealRandomAccess< T >
{

CoordinateTransform warp;
RealTransform warp;
AbstractModel<?> base;

T value;
Expand All @@ -21,7 +21,7 @@ protected WarpMagnitudeRandomAccess( double[] dimensions )
this( dimensions, null, null, null );
}

protected WarpMagnitudeRandomAccess( double[] dimensions, T value, CoordinateTransform warp, AbstractModel<?> base )
protected WarpMagnitudeRandomAccess( double[] dimensions, T value, RealTransform warp, AbstractModel<?> base )
{
super( dimensions.length );
if( warp != null)
Expand All @@ -40,9 +40,11 @@ public T get()
double[] mypt = new double[ this.numDimensions() ];
this.localize( mypt );

double[] warpRes = warp.apply( mypt );
double[] warpRes = new double[ warp.numTargetDimensions() ];
warp.apply( mypt, warpRes );

double[] baseRes = base.apply( mypt );

double dist = 0.0;
for( int d = 0; d < warpRes.length; d++ )
dist += ( warpRes[ d ] - baseRes[ d ] ) * ( warpRes[ d ] - baseRes[ d ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import jitk.spline.ThinPlateR2LogRSplineKernelTransform;
import mpicbg.models.AbstractModel;
import mpicbg.models.CoordinateTransform;
import net.imglib2.AbstractRealInterval;
import net.imglib2.FinalInterval;
import net.imglib2.FinalRealInterval;
import net.imglib2.Interval;
import net.imglib2.RealInterval;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.type.numeric.RealType;

public class WarpMagnitudeRandomAccessibleInterval<T extends RealType<T>> extends AbstractRealInterval implements RealRandomAccessibleRealInterval<T>
{

WarpMagnitudeRandomAccess< T > ra;

public WarpMagnitudeRandomAccessibleInterval( Interval interval, T t, CoordinateTransform warp, AbstractModel<?> base )
public WarpMagnitudeRandomAccessibleInterval( Interval interval, T t, RealTransform warp, AbstractModel<?> base )
{
super( interval );
ra = new WarpMagnitudeRandomAccess< T >( new double[ interval.numDimensions() ], t, warp, base );
Expand Down
Loading

0 comments on commit 013dae1

Please sign in to comment.