Mercurial > hg > minc-tools
changeset 1537:8b9213171e74
Apply Peter Neelin patch for xfm concatenation. More test cases.
author | stever <stever> |
---|---|
date | Mon, 02 Jun 2003 02:49:35 +0000 |
parents | 8acab48ddfff |
children | 83c26a940d5d |
files | .cvsignore BUGS ChangeLog Makefile.am TODO testdir/Makefile.am testdir/create_grid_xfm.c testdir/t1.xfm testdir/test_xfm.c testdir/xfmconcat_02.sh volume_io/MNI_formats/gen_xf_io.c volume_io/Testing/check_xfm.sh |
diffstat | 12 files changed, 197 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/BUGS @@ -0,0 +1,12 @@ +Date: Tue, 06 May 2003 09:46:32 -0400 +From: Natasa Kovacevic <nkovacev@pandora.bioinfo.sickkids.on.ca> + +I beleive that there is a bug in xfmconcat in case when more then one +grid transform gets concatenated (here I am refering to minc-1.0, so +disregard the whole thing if it has been fixed in 1.1). What happens +is that all grid files involved in concatenation get the same +name. This way they get overwritten during copying and the end product +is a transfrom in which all displacement volumes are one and the same, +namely the last one that appears in the concatenation. + +
--- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,21 @@ 2003-06-01 Steve M. Robbins <steve@nyongwa.montreal.qc.ca> + * testdir/Makefile.am (script_tests): + + * Makefile.am (SUBDIRS): Process volume_io before testdir, + because tests may link against volume_io. + + * volume_io/MNI_formats/gen_xf_io.c (output_one_transform): + Update *volume_count after writing a grid transform (thanks, Peter + Neelin). + * testdir/create_grid_xfm.c: New. Utility to create grid transformation. - * testdir/xfmconcat_01.sh: New. Test concatenation of grid + * testdir/test_xfm.c: Copied from volume_io/Testing/test-xfm.c. + + * testdir/xfmconcat_01.sh: + * testdir/xfmconcat_02.sh: New. Test concatenation of grid transformations. 2003-03-17 Bert Vincent <bert@bic.mni.mcgill.ca> @@ -41,7 +53,7 @@ 2003-01-10 Steve M. Robbins <steve@nyongwa.montreal.qc.ca> * testdir/Makefile.am (INCLUDES): - * volume_io/Testing//Makefile.am (INCLUDES): Set includes for + * volume_io/Testing/Makefile.am (INCLUDES): Set includes for test files. * Makefile.am (EXTRA_DIST, dist-hook): Distribute fortran @@ -59,7 +71,7 @@ * volume_io/Documentation/Makefile.am: New. * volume_io/Testing/check_xfm.sh: - * volume_io/Testing/check_xfm.sh + * volume_io/Testing/test-xfm.c: * volume_io/Testing/t1.xfm: * volume_io/Testing/t2.xfm: * volume_io/Testing/t3.xfm:
--- a/Makefile.am +++ b/Makefile.am @@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = check-news subdir-objects ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = . testdir doc volume_io +SUBDIRS = . volume_io testdir doc # Add these to the include searches.
--- a/TODO +++ b/TODO @@ -2,3 +2,10 @@ * Add "-version" flag to all executables. +* rationalize the testing into "testdir/". I initially put + stuff in volume_io/Testing in order to separate the testing of + minc proper from testing of volume_io. But some of the "minc" + utilities (xfmconcat, xfminvert) use volume_io, so there is no + real separation, it seems. Might as well move all testing stuff + to testdir. +
--- a/testdir/Makefile.am +++ b/testdir/Makefile.am @@ -1,17 +1,21 @@ INCLUDES = -I$(top_srcdir)/libsrc -LDADD = ../libminc.la +LDADD = ../libvolume_io.la ../libminc.la -sh_tests = xfmconcat_01.sh +script_tests = \ + run_tests.csh \ + xfmconcat_01.sh \ + xfmconcat_02.sh + all-local: - chmod +x $(sh_tests) + cd $(srcdir) && chmod +x $(script_tests) -TESTS = run_tests.csh $(sh_tests) +TESTS = $(script_tests) check_PROGRAMS = minc test_mconv minc_types icv icv_range \ icv_dim test_speed icv_dim1 icv_fillvalue \ - create_grid_xfm + test_xfm create_grid_xfm -EXTRA_DIST = run_tests.csh $(expect_files) +EXTRA_DIST = $(script_tests) $(expect_files) t1.xfm CLEANFILES = test.mnc _* @@ -34,5 +38,3 @@ icv_range.out: ; minc_types.out: ; -create_grid_xfm_LDADD = ../libvolume_io.la ../libminc.la -
--- a/testdir/create_grid_xfm.c +++ b/testdir/create_grid_xfm.c @@ -3,7 +3,7 @@ #include <stdio.h> #include <volume_io.h> -#include "libsrc/time_stamp.h" +#include "time_stamp.h" int main( int ac, char* av[] )
new file mode 100644 --- /dev/null +++ b/testdir/t1.xfm @@ -0,0 +1,8 @@ +MNI Transform File +% Single linear transformation. + +Transform_Type = Linear; +Linear_Transform = + 1 0 0 10 + 0 1 0 20 + 0 0 1 30;
new file mode 100644 --- /dev/null +++ b/testdir/test_xfm.c @@ -0,0 +1,91 @@ + +#include <stdio.h> +#include <stdlib.h> + +#include <volume_io.h> + + +Real tolerance = 1e-8; + + +int is_equal_real( Real e, Real a ) +{ + return fabs(e-a) < tolerance; +} + + + +/* Args: expected, actual. + */ +void assert_equal_point( Real ex, Real ey, Real ez, + Real ax, Real ay, Real az, + const char* msg ) +{ + if ( is_equal_real(ex,ax) && + is_equal_real(ey,ay) && + is_equal_real(ez,az) ) + return; + + printf( "%s failure.\n" + "Expected: %f %f %f\n" + " Actual: %f %f %f\n", + msg, ex,ey,ez, ax,ay,az ); + + exit(3); +} + + + +int main( int ac, char* av[] ) +{ + int N; + General_transform xfm; + + + if ( ac != 3 && ac != 4 ) { + fprintf( stderr, "usage: %s N transform.xfm [tolerance]\n", av[0] ); + return 1; + } + + N = atoi( av[1] ); + if ( input_transform_file( av[2], &xfm ) != OK ) { + fprintf( stderr, "Failed to load transform '%s'\n", av[2] ); + return 2; + } + + if ( ac == 4 ) { + tolerance = atof( av[3] ); + printf( "Setting tolerance to %f.\n", tolerance ); + } + + while (N-- > 0) { + Real x = 500.0 * ( drand48() - 0.5 ); + Real y = 500.0 * ( drand48() - 0.5 ); + Real z = 500.0 * ( drand48() - 0.5 ); + + Real tx,ty,tz; + Real a,b,c; + + general_transform_point( &xfm, x,y,z, &tx,&ty,&tz ); + + /* Check that general_inverse_transform_point() and + invert_general_transform() behave sensibly. + */ + general_inverse_transform_point( &xfm, tx,ty,tz, &a,&b,&c ); + assert_equal_point( x,y,z, a,b,c, + "general_inverse_transform_point()" ); + + invert_general_transform( &xfm ); + + general_transform_point( &xfm, tx,ty,tz, &a,&b,&c ); + assert_equal_point( x,y,z, a,b,c, + "general_transform_point() / inverted xfm" ); + + general_inverse_transform_point( &xfm, x,y,z, &a,&b,&c ); + assert_equal_point( tx,ty,tz, a,b,c, + "general_inverse_transform_point() / inverted xfm" ); + } + + return 0; +} +
new file mode 100755 --- /dev/null +++ b/testdir/xfmconcat_02.sh @@ -0,0 +1,42 @@ +#! /bin/sh +# +# Test application of concatenated transforms. + +set -e + +# _t1.xfm is linear transform. +# _t2.xfm is inverse of _t1 +# _t3.xfm is grid transform. +# _t4.xfm is inverse of _t3 + +cp $srcdir/t1.xfm _t1.xfm +../xfminvert _t1.xfm _t2.xfm +dd if=/dev/zero | ../rawtominc -vector 3 -byte -clobber _grid.mnc 8 8 8 +./create_grid_xfm _grid.mnc _t3.xfm +../xfminvert _t3.xfm _t4.xfm + + +# Test primary transforms. +# +./test_xfm 10000 _t1.xfm +./test_xfm 10000 _t2.xfm +./test_xfm 10000 _t3.xfm +./test_xfm 10000 _t4.xfm + + +# Test concatenations. +# +../xfmconcat _t1.xfm _t3.xfm _t5.xfm +./test_xfm 10000 _t5.xfm + +../xfmconcat _t1.xfm _t4.xfm _t6.xfm +./test_xfm 10000 _t6.xfm + +../xfmconcat _t5.xfm _t6.xfm _t7.xfm +./test_xfm 10000 _t7.xfm + +../xfminvert _t7.xfm _t8.xfm +./test_xfm 10000 _t8.xfm + +../xfmconcat _t8.xfm _t2.xfm _t4.xfm _t7.xfm _t9.xfm +./test_xfm 10000 _t9.xfm
--- a/volume_io/MNI_formats/gen_xf_io.c +++ b/volume_io/MNI_formats/gen_xf_io.c @@ -15,7 +15,7 @@ #include <internal_volume_io.h> #ifndef lint -static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/MNI_formats/gen_xf_io.c,v 1.21 2001-04-24 13:38:47 neelin Exp $"; +static char rcsid[] = "$Header: /private-cvsroot/minc/volume_io/MNI_formats/gen_xf_io.c,v 1.22 2003-06-02 02:49:36 stever Exp $"; #endif /*--------------------- file format keywords ------------------------------ */ @@ -64,6 +64,7 @@ @OUTPUT : @RETURNS : @DESCRIPTION: Outputs a transform to the MNI transform file. + : Increment *volume_count. @METHOD : @GLOBALS : @CALLS : @@ -180,6 +181,11 @@ (void) sprintf( volume_filename, "%s_grid_%d.mnc", prefix_filename, *volume_count ); + /* Increment the volume counter as a side-effect to ensure that grid + * files have different names. + */ + (*volume_count)++; + /*--- decide where to write the volume file */ base_filename = remove_directories_from_filename( volume_filename );
--- a/volume_io/Testing/check_xfm.sh +++ b/volume_io/Testing/check_xfm.sh @@ -6,8 +6,8 @@ ./test-xfm 10000 $srcdir/t1.xfm ./test-xfm 10000 $srcdir/t2.xfm -# Here's an illustration of how lousy the grid-transform inversion is: -# using a tolerance of 0.8 will fail! +# Transformation t3 is non-injective, so we have to set the tolerance +# fairly large. ./test-xfm 10000 $srcdir/t3.xfm 0.9