Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elliposid distance computer #22

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package ch.epfl.biop.bdv.command.transform;

import bdv.util.Elliptical3DTransform;
import ij.IJ;
import net.imglib2.util.LinAlgHelpers;
import org.scijava.Context;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.command.CommandService;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;

@Plugin(type = Command.class, menuPath = ScijavaBdvDefaults.RootMenu+"Sources>Transform>Compute Ellipsoid Transformed Distance")
public class ComputeEllipse3DTransformedDistanceCommand implements Command {

@Parameter
public Elliptical3DTransform e3Dt;

@Parameter ( stepSize = "0.001")
public Double radiusA = 1.1;

@Parameter ( stepSize = "0.001")
public Double angle1A = 1.0;

@Parameter ( stepSize = "0.001")
public Double angle2A = 2.4;

@Parameter ( stepSize = "0.001")
public Double radiusB = 1.1;

@Parameter ( stepSize = "0.001")
public Double angle1B = 2.2;

@Parameter ( stepSize = "0.001")
public Double angle2B = 3.8;

@Parameter ( min = "1" )
public int numSteps = 1;

@Parameter( type = ItemIO.OUTPUT )
public Double distance;

@Override
public void run() {

final double[] pA = new double[ 3 ];
pA[ 0 ] = radiusA; pA[ 1 ] = angle1A; pA[ 2 ] = angle2A;
final double[] pB = new double[ 3 ];
pB[ 0 ] = radiusB; pB[ 1 ] = angle1B; pB[ 2 ] = angle2B;

distance = computeDistance( pA, pB, numSteps );
}

private double computeDistance( double[] pA, double[] pB, int numSteps )
{
final double[] vAB = new double[ 3 ];
LinAlgHelpers.subtract( pB, pA, vAB );

final double[] p0 = new double[ 3 ];
final double[] p1 = new double[ 3 ];
final double[] vStep = new double[ 3 ];

copy( pA, p0 );

LinAlgHelpers.scale( vAB, 1.0 / numSteps, vStep );

double curvedDistance = 0.0;
for ( int i = 0; i < numSteps; i++ )
{
LinAlgHelpers.add( p0, vStep, p1 );
curvedDistance += distance( p0, p1 );
copy( p1, p0 );
}

return curvedDistance;
}

private void copy( double[] source, double[] target )
{
for ( int d = 0; d < source.length; d++ )
target[ d ] = source[ d ];
}

private double distance( double[] pA, double[] pB )
{
double[] pAtransformed = new double[ 3 ];
double[] pBtransformed = new double[ 3 ];
e3Dt.apply( pA, pAtransformed );
e3Dt.apply( pB, pBtransformed );
return LinAlgHelpers.distance( pAtransformed, pBtransformed );
}

public static void main( String[] args )
{
Context ctx = (Context ) IJ.runPlugIn("org.scijava.Context", "");
CommandService commandService = ctx.service( CommandService.class );
commandService.run( ComputeEllipse3DTransformedDistanceCommand.class, true );
}
}
48 changes: 48 additions & 0 deletions src/test/java/DemoComputeEllipticalDistance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import bdv.util.Elliptical3DTransform;
import ch.epfl.biop.bdv.command.transform.ComputeEllipse3DTransformedDistanceCommand;
import net.imagej.ImageJ;
import net.imagej.patcher.LegacyInjector;

public class DemoComputeEllipticalDistance
{

static {
LegacyInjector.preinit();
}

public static void main(String... args) {

// Initializes static SourceService and Display Service
ImageJ ij = new ImageJ();
ij.ui().showUI();

final ComputeEllipse3DTransformedDistanceCommand command = new ComputeEllipse3DTransformedDistanceCommand();
Elliptical3DTransform e3Dt = new Elliptical3DTransform();
e3Dt.setParameters(
"r1", 338.0,
"r2", 292.0,
"r3", 320.0,
"rx", 2.0,
"ry", 0.81,
"rz", 2.81,
"tx", 209.0,
"ty", 230.0,
"tz", -230.0);
command.e3Dt = e3Dt;
command.radiusA = 1.1;
command.angle1A = 1.0;
command.angle2A = 2.4;
command.radiusB = 1.1;
command.angle1B = 2.2;
command.angle2B = 3.8;

command.numSteps = 1;
command.run();
System.out.println("Distance, numSteps 1: " + command.distance );

command.numSteps = 100;
command.run();
System.out.println("Distance, numSteps 100: " + command.distance );
}

}
40 changes: 40 additions & 0 deletions src/test/java/DemoComputeEllipticalDistanceCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import bdv.util.Elliptical3DTransform;
import ch.epfl.biop.bdv.command.transform.ComputeEllipse3DTransformedDistanceCommand;
import ij.IJ;
import net.imagej.ImageJ;
import net.imagej.patcher.LegacyInjector;
import org.scijava.Context;
import org.scijava.command.CommandService;
import org.scijava.object.ObjectService;

public class DemoComputeEllipticalDistanceCommand
{

static {
LegacyInjector.preinit();
}

public static void main(String... args) {

ImageJ ij = new ImageJ();
ij.ui().showUI();

Elliptical3DTransform e3Dt = new Elliptical3DTransform();
e3Dt.setParameters(
"r1", 338.0,
"r2", 292.0,
"r3", 320.0,
"rx", 2.0,
"ry", 0.81,
"rz", 2.81,
"tx", 209.0,
"ty", 230.0,
"tz", -230.0);


Context ctx = (Context ) IJ.runPlugIn("org.scijava.Context", "");
ctx.getService( ObjectService.class).addObject( e3Dt );
ctx.service( CommandService.class ).run( ComputeEllipse3DTransformedDistanceCommand.class, true );
}

}