From 29d8699dc6c30baa0958d1b8ed52b916da046991 Mon Sep 17 00:00:00 2001 From: Stephan Saalfeld Date: Thu, 5 Mar 2009 18:19:06 +0100 Subject: [PATCH] Added clone() method to CoordinateTransform and all implementing classes. Added two test scripts for MovingLeastSquaresTransform and TransformMeshMapping --- mpicbg/trakem2/transform/CoordinateTransform.java | 2 + .../trakem2/transform/CoordinateTransformList.java | 9 ++++ .../transform/MovingLeastSquaresTransform.java | 12 ++++- mpicbg/trakem2/transform/RigidModel2D.java | 11 ++++ mpicbg/trakem2/transform/TranslationModel2D.java | 11 ++++ test/movingleastsquarestransform.js | 59 ++++++++++++++++++++++ test/transformmeshmapping.js | 27 ++++++++++ 7 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 test/movingleastsquarestransform.js create mode 100644 test/transformmeshmapping.js diff --git a/mpicbg/trakem2/transform/CoordinateTransform.java b/mpicbg/trakem2/transform/CoordinateTransform.java index 9936757c..1c79c728 100644 --- a/mpicbg/trakem2/transform/CoordinateTransform.java +++ b/mpicbg/trakem2/transform/CoordinateTransform.java @@ -52,4 +52,6 @@ public interface CoordinateTransform extends mpicbg.models.CoordinateTransform * @return */ public String toDataString(); + + public CoordinateTransform clone(); } diff --git a/mpicbg/trakem2/transform/CoordinateTransformList.java b/mpicbg/trakem2/transform/CoordinateTransformList.java index 91da09e9..b1d94723 100644 --- a/mpicbg/trakem2/transform/CoordinateTransformList.java +++ b/mpicbg/trakem2/transform/CoordinateTransformList.java @@ -41,4 +41,13 @@ public class CoordinateTransformList extends mpicbg.models.CoordinateTransformLi { return ""; } + + @Override + final public CoordinateTransformList clone() + { + final CoordinateTransformList ctl = new CoordinateTransformList(); + for ( mpicbg.models.CoordinateTransform ct : l ) + ctl.add( ( ( CoordinateTransform )ct ).clone() ); + return ctl; + } } diff --git a/mpicbg/trakem2/transform/MovingLeastSquaresTransform.java b/mpicbg/trakem2/transform/MovingLeastSquaresTransform.java index b62fbc21..20d0a56e 100644 --- a/mpicbg/trakem2/transform/MovingLeastSquaresTransform.java +++ b/mpicbg/trakem2/transform/MovingLeastSquaresTransform.java @@ -85,5 +85,15 @@ public class MovingLeastSquaresTransform extends mpicbg.models.MovingLeastSquare { return indent + ""; } - + + @Override + /** + * TODO Make this more efficient + */ + final public MovingLeastSquaresTransform clone() + { + final MovingLeastSquaresTransform t = new MovingLeastSquaresTransform(); + t.init( toDataString() ); + return t; + } } diff --git a/mpicbg/trakem2/transform/RigidModel2D.java b/mpicbg/trakem2/transform/RigidModel2D.java index 624fd4fd..12e62b62 100644 --- a/mpicbg/trakem2/transform/RigidModel2D.java +++ b/mpicbg/trakem2/transform/RigidModel2D.java @@ -47,4 +47,15 @@ public class RigidModel2D extends mpicbg.models.RigidModel2D implements Coordina { return Math.atan2( sin, cos ) + " " + tx + " " + ty; } + + @Override + /** + * TODO Make this more efficient + */ + final public RigidModel2D clone() + { + final RigidModel2D t = new RigidModel2D(); + t.init( toDataString() ); + return t; + } } diff --git a/mpicbg/trakem2/transform/TranslationModel2D.java b/mpicbg/trakem2/transform/TranslationModel2D.java index e7b16304..3371c495 100644 --- a/mpicbg/trakem2/transform/TranslationModel2D.java +++ b/mpicbg/trakem2/transform/TranslationModel2D.java @@ -46,4 +46,15 @@ public class TranslationModel2D extends mpicbg.models.TranslationModel2D impleme { return tx + " " + ty; } + + @Override + /** + * TODO Make this more efficient + */ + final public TranslationModel2D clone() + { + final TranslationModel2D t = new TranslationModel2D(); + t.init( toDataString() ); + return t; + } } diff --git a/test/movingleastsquarestransform.js b/test/movingleastsquarestransform.js new file mode 100644 index 00000000..65a2348a --- /dev/null +++ b/test/movingleastsquarestransform.js @@ -0,0 +1,59 @@ +importClass( Packages.mpicbg.trakem2.transform.MovingLeastSquaresTransform ); + +IJ.log( ">>> Test mpicbg.trakem2.transform.MovingLeastSquaresTransform >>>" ); + +var l1 = new java.lang.reflect.Array.newInstance( java.lang.Float.TYPE, 2 ); +l1[ 0 ] = 40; +l1[ 1 ] = 40; + +var l2 = new java.lang.reflect.Array.newInstance( java.lang.Float.TYPE, 2 ); +l2[ 0 ] = 300; +l2[ 1 ] = 200; + +var l3 = new java.lang.reflect.Array.newInstance( java.lang.Float.TYPE, 2 ); +l3[ 0 ] = 300; +l3[ 1 ] = 40; + +var w1 = new java.lang.reflect.Array.newInstance( java.lang.Float.TYPE, 2 ); +w1[ 0 ] = 80; +w1[ 1 ] = 80; + +var w2 = new java.lang.reflect.Array.newInstance( java.lang.Float.TYPE, 2 ); +w2[ 0 ] = 260; +w2[ 1 ] = 160; + +var w3 = new java.lang.reflect.Array.newInstance( java.lang.Float.TYPE, 2 ); +w3[ 0 ] = 240; +w3[ 1 ] = 80; + +var dataString = + "rigid 1 " + + l1[ 0 ] + " " + l1[ 1 ] + " " + + w1[ 0 ] + " " + w1[ 1 ] + " " + + l2[ 0 ] + " " + l2[ 1 ] + " " + + w2[ 0 ] + " " + w2[ 1 ] + " " + + l3[ 0 ] + " " + l3[ 1 ] + " " + + w3[ 0 ] + " " + w3[ 1 ]; + +var m = new MovingLeastSquaresTransform(); +m.init( dataString ); + +var l1p = m.apply( l1 ); +var l2p = m.apply( l2 ); +var l3p = m.apply( l3 ); + +if ( + w1[ 0 ] == l1p[ 0 ] && + w1[ 1 ] == l1p[ 1 ] && + w2[ 0 ] == l2p[ 0 ] && + w2[ 1 ] == l2p[ 1 ] && + w3[ 0 ] == l3p[ 0 ] && + w3[ 1 ] == l3p[ 1 ] ) + IJ.log( " + transferring control points correctly passed" ) +else + IJ.error( " - transferring control points correctly failed" ) + +IJ.log( "<<< Test mpicbg.trakem2.transform.MovingLeastSquaresTransform <<<" ); + +//IJ.run( "Clown (14K)" ); + diff --git a/test/transformmeshmapping.js b/test/transformmeshmapping.js new file mode 100644 index 00000000..04d95f4b --- /dev/null +++ b/test/transformmeshmapping.js @@ -0,0 +1,27 @@ +importClass( Packages.mpicbg.trakem2.transform.MovingLeastSquaresTransform ); +importClass( Packages.mpicbg.trakem2.transform.TransformMesh ); +importClass( Packages.mpicbg.trakem2.transform.TransformMeshMapping ); +importClass( Packages.java.awt.Color ); + +IJ.log( ">>> Test mpicbg.trakem2.transform.TransformMeshMapping >>>" ); + +var m = new MovingLeastSquaresTransform(); +m.init( "rigid 1 40 40 80 80 280 160 220 140 280 40 200 80" ); +IJ.run( "Clown (14K)" ); +var imp = IJ.getImage(); +for ( var i = 1; i <= 6; ++i ) +{ + var n = Math.pow( 2, i ); + IJ.log( n ); + var mesh = new TransformMesh( m, n, imp.getWidth(), imp.getHeight() ); + var mapping = new TransformMeshMapping( mesh ); + var impMapping = new ImagePlus( n + " mapping", mapping.createMappedImage( imp.getProcessor() ) ); + var impMappingInterpolated = new ImagePlus( n + " interpolated mapping", mapping.createMappedImageInterpolated( imp.getProcessor() ) ); + impMapping.show(); + impMappingInterpolated.show(); + impMapping.getCanvas().setDisplayList( mesh.illustrateMesh(), Color.white, null ); + impMappingInterpolated.getCanvas().setDisplayList( mesh.illustrateMesh(), Color.white, null ); +} + +IJ.log( " + mapping passed" ) +IJ.log( "<<< Test mpicbg.trakem2.transform.TransformMeshMapping <<<" ); -- 2.11.4.GIT