From dadacff0823b881b687e48312aafa5351d4818e0 Mon Sep 17 00:00:00 2001 From: taw27 Date: Fri, 2 May 2008 16:33:52 +0000 Subject: More testing git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@281 bf6ca9ba-c028-0410-8290-897cf20841d1 --- src/refine.c | 7 +++- src/refinetest2d.c | 85 ++++++++++++++++++++++++++++++++----------- src/refinetest3d.c | 105 +++++++++++++++++++++++++++++++++-------------------- 3 files changed, 133 insertions(+), 64 deletions(-) diff --git a/src/refine.c b/src/refine.c index d0fc8cc..b3ac84a 100644 --- a/src/refine.c +++ b/src/refine.c @@ -212,7 +212,7 @@ static void refine_simplex_contract(SimplexVertex *s, int v, int v_best) { s[v].dcx = s[v_best].dcx + 0.5 * (s[v].dcx - s[v_best].dcx); s[v].dcy = s[v_best].dcy + 0.5 * (s[v].dcy - s[v_best].dcy); s[v].dcz = s[v_best].dcz + 0.5 * (s[v].dcz - s[v_best].dcz); - + } static double refine_iteration(SimplexVertex *s, Deviation *d, int nf) { @@ -326,7 +326,7 @@ double refine_do_cell(ControlContext *ctx) { Deviation *d; double delta; int i, nf, f, it, maxiter; - const double tol = 0.0001e9; /* Stopping condition */ + const double tol = 0.00001e9; /* Stopping condition */ //const double tol = 0.001; /* For testing */ if ( !ctx->cell_lattice ) { @@ -342,6 +342,7 @@ double refine_do_cell(ControlContext *ctx) { /* Determine the size of the 'deviation table' */ nf = 0; for ( i=0; iimages->n_images; i++ ) { + int j; if ( !ctx->images->images[i].rflist ) { @@ -352,6 +353,8 @@ double refine_do_cell(ControlContext *ctx) { if ( ctx->images->images[i].rflist->features[j].partner != NULL ) nf++; } + printf("%i features from image %i\n", nf, i); + } if ( REFINE_DEBUG ) printf("RF: There are %i partnered features in total\n", nf); diff --git a/src/refinetest2d.c b/src/refinetest2d.c index 5df7f19..49a0c6b 100644 --- a/src/refinetest2d.c +++ b/src/refinetest2d.c @@ -26,6 +26,64 @@ #include "control.h" #include "displaywindow.h" +static int check_cell(Basis *cell, Basis *cell_real) { + + int fail; + +// printf(" Calculated Actual\n"); +// printf("---------------------------\n"); +// printf("ax %+8f %+8f\n", cell->a.x/1e9, cell_real->a.x/1e9); +// printf("ay %+8f %+8f\n", cell->a.y/1e9, cell_real->a.y/1e9); +// printf("az %+8f %+8f\n", cell->a.z/1e9, cell_real->a.z/1e9); +// printf("bx %+8f %+8f\n", cell->b.x/1e9, cell_real->b.x/1e9); +// printf("by %+8f %+8f\n", cell->b.y/1e9, cell_real->b.y/1e9); +// printf("bz %+8f %+8f\n", cell->b.z/1e9, cell_real->b.z/1e9); +// printf("cx %+8f %+8f\n", cell->c.x/1e9, cell_real->c.x/1e9); +// printf("cy %+8f %+8f\n", cell->c.y/1e9, cell_real->c.y/1e9); +// printf("cz %+8f %+8f\n", cell->c.z/1e9, cell_real->c.z/1e9); + + fail = 0; + if ( fabs(cell->a.x - cell_real->a.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ax not determined correctly (got %8f, should be %8f)\n", cell->a.x/1e9, cell_real->a.x/1e9); + fail = 1; + } + if ( fabs(cell->a.y - cell_real->a.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ay not determined correctly (got %8f, should be %8f)\n", cell->a.y/1e9, cell_real->a.y/1e9); + fail = 1; + } +// if ( fabs(cell->a.z - cell_real->a.z) > 0.01e9 ) { +// fprintf(stderr, "refinetest3d: az not determined correctly (got %8f, should be %8f)\n", cell->a.z/1e9, cell_real->a.z/1e9); +// fail = 1; +// } + if ( fabs(cell->b.x - cell_real->b.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: bx not determined correctly (got %8f, should be %8f)\n", cell->b.x/1e9, cell_real->b.x/1e9); + fail = 1; + } + if ( fabs(cell->b.y - cell_real->b.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: by not determined correctly (got %8f, should be %8f)\n", cell->b.y/1e9, cell_real->b.y/1e9); + fail = 1; + } +// if ( fabs(cell->b.z - cell_real->b.z) > 0.01e9 ) { +// fprintf(stderr, "refinetest3d: bz not determined correctly (got %8f, should be %8f)\n", cell->b.z/1e9, cell_real->b.z/1e9); +// fail = 1; +// } +// if ( fabs(cell->c.x - cell_real->c.x) > 0.01e9 ) { +// fprintf(stderr, "refinetest3d: cx not determined correctly (got %8f, should be %8f)\n", cell->c.x/1e9, cell_real->c.x/1e9); +// fail = 1; +// } +// if ( fabs(cell->c.y - cell_real->c.y) > 0.01e9 ) { +// fprintf(stderr, "refinetest3d: cy not determined correctly (got %8f, should be %8f)\n", cell->c.y/1e9, cell_real->c.y/1e9); +// fail = 1; +// } +// if ( fabs(cell->c.z - cell_real->c.z) > 0.01e9 ) { +// fprintf(stderr, "refinetest3d: cz not determined correctly (got %8f, should be %8f)\n", cell->c.z/1e9, cell_real->c.z/1e9); +// fail = 1; +// } + + return fail; + +} + int main(int argc, char *argv[]) { ControlContext *ctx; @@ -59,9 +117,10 @@ int main(int argc, char *argv[]) { /* The "model" cell to be refined */ ctx->cell = malloc(sizeof(Basis)); - ctx->cell->a.x = 5.2e9; ctx->cell->a.y = 0.1e9; ctx->cell->a.z = 0.0e9; - ctx->cell->b.x = 0.2e9; ctx->cell->b.y = 4.8e9; ctx->cell->b.z = 0.0e9; - ctx->cell->c.x = 0.0e9; ctx->cell->c.y = 0.0e9; ctx->cell->c.z = 5.0e9; + ctx->cell->a.x = 5.2e9; ctx->cell->a.y = 0.1e9; ctx->cell->a.z = 0.1e9; + ctx->cell->b.x = 0.2e9; ctx->cell->b.y = 4.8e9; ctx->cell->b.z = 0.1e9; + ctx->cell->c.x = 0.1e9; ctx->cell->c.y = 0.1e9; ctx->cell->c.z = 5.3e9; + ctx->cell_lattice = reflection_list_from_cell(ctx->cell); ctx->cell_lattice = reflection_list_from_cell(ctx->cell); ctx->images->images[0].rflist = reproject_get_reflections(&ctx->images->images[0], ctx->cell_lattice); reproject_partner_features(ctx->images->images[0].rflist, &ctx->images->images[0]); @@ -71,25 +130,7 @@ int main(int argc, char *argv[]) { reflection_list_from_new_cell(ctx->cell_lattice, ctx->cell); ctx->images->images[0].rflist = reproject_get_reflections(&ctx->images->images[0], ctx->cell_lattice); - fail = 0; - if ( fabs(ctx->cell->a.x - cell_real->a.x) > 0.01e9 ) { - fprintf(stderr, "refinetest2d: ax not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->a.y - cell_real->a.y) > 0.01e9 ) { - fprintf(stderr, "refinetest2d: ay not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->b.x - cell_real->b.x) > 0.01e9 ) { - fprintf(stderr, "refinetest2d: bx not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->b.y - cell_real->b.y) > 0.01e9 ) { - fprintf(stderr, "refinetest2d: by not determined correctly\n"); - fail = 1; - } - /* az, bz, cx, cy and cz are unconstrained hence will 'float' to meaningless values. - * This is ok. */ + fail = check_cell(ctx->cell, cell_real); free(ctx); diff --git a/src/refinetest3d.c b/src/refinetest3d.c index 5f6fd7e..c78adbb 100644 --- a/src/refinetest3d.c +++ b/src/refinetest3d.c @@ -25,6 +25,60 @@ #include "mapping.h" #include "control.h" #include "displaywindow.h" +#include "mrc.h" + +/* Return a random number x, -max < x < +max */ +static double random_plusminus(double max) { + + return max; + +} + +static int check_cell(Basis *cell, Basis *cell_real) { + + int fail; + + fail = 0; + if ( fabs(cell->a.x - cell_real->a.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ax not determined correctly (got %8f, should be %8f)\n", cell->a.x/1e9, cell_real->a.x/1e9); + fail = 1; + } + if ( fabs(cell->a.y - cell_real->a.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ay not determined correctly (got %8f, should be %8f)\n", cell->a.y/1e9, cell_real->a.y/1e9); + fail = 1; + } + if ( fabs(cell->a.z - cell_real->a.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: az not determined correctly (got %8f, should be %8f)\n", cell->a.z/1e9, cell_real->a.z/1e9); + fail = 1; + } + if ( fabs(cell->b.x - cell_real->b.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: bx not determined correctly (got %8f, should be %8f)\n", cell->b.x/1e9, cell_real->b.x/1e9); + fail = 1; + } + if ( fabs(cell->b.y - cell_real->b.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: by not determined correctly (got %8f, should be %8f)\n", cell->b.y/1e9, cell_real->b.y/1e9); + fail = 1; + } + if ( fabs(cell->b.z - cell_real->b.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: bz not determined correctly (got %8f, should be %8f)\n", cell->b.z/1e9, cell_real->b.z/1e9); + fail = 1; + } + if ( fabs(cell->c.x - cell_real->c.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cx not determined correctly (got %8f, should be %8f)\n", cell->c.x/1e9, cell_real->c.x/1e9); + fail = 1; + } + if ( fabs(cell->c.y - cell_real->c.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cy not determined correctly (got %8f, should be %8f)\n", cell->c.y/1e9, cell_real->c.y/1e9); + fail = 1; + } + if ( fabs(cell->c.z - cell_real->c.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cz not determined correctly (got %8f, should be %8f)\n", cell->c.z/1e9, cell_real->c.z/1e9); + fail = 1; + } + + return fail; + +} int main(int argc, char *argv[]) { @@ -44,6 +98,9 @@ int main(int argc, char *argv[]) { ctx->images->images[0].features = image_feature_list_new(); image_add(ctx->images, NULL, 512, 512, deg2rad(90.0), ctx); ctx->images->images[1].features = image_feature_list_new(); + //ctx->omega = deg2rad(90.0); + //image_add(ctx->images, NULL, 512, 512, deg2rad(90.0), ctx); + //ctx->images->images[2].features = image_feature_list_new(); /* Fudge to avoid horrifying pointer-related death */ ctx->dw = malloc(sizeof(DisplayWindow)); @@ -58,60 +115,28 @@ int main(int argc, char *argv[]) { reflections_real = reflection_list_from_cell(cell_real); ctx->images->images[0].features = reproject_get_reflections(&ctx->images->images[0], reflections_real); ctx->images->images[1].features = reproject_get_reflections(&ctx->images->images[1], reflections_real); -// printf("RT: %i test features generated.\n", ctx->images->images[0].features->n_features); + //ctx->images->images[2].features = reproject_get_reflections(&ctx->images->images[2], reflections_real); /* The "model" cell to be refined */ ctx->cell = malloc(sizeof(Basis)); - ctx->cell->a.x = 5.2e9; ctx->cell->a.y = 0.1e9; ctx->cell->a.z = 0.0e9; - ctx->cell->b.x = 0.2e9; ctx->cell->b.y = 4.8e9; ctx->cell->b.z = 0.0e9; + ctx->cell->a.x = 5.0e9; ctx->cell->a.y = 0.0e9; ctx->cell->a.z = 0.0e9; + ctx->cell->b.x = 0.0e9; ctx->cell->b.y = 5.0e9; ctx->cell->b.z = 0.0e9; ctx->cell->c.x = 0.0e9; ctx->cell->c.y = 0.0e9; ctx->cell->c.z = 5.0e9; + ctx->cell->a.x += random_plusminus(0.1e9); ctx->cell_lattice = reflection_list_from_cell(ctx->cell); ctx->images->images[0].rflist = reproject_get_reflections(&ctx->images->images[0], ctx->cell_lattice); reproject_partner_features(ctx->images->images[0].rflist, &ctx->images->images[0]); ctx->images->images[1].rflist = reproject_get_reflections(&ctx->images->images[1], ctx->cell_lattice); reproject_partner_features(ctx->images->images[1].rflist, &ctx->images->images[1]); + //ctx->images->images[2].rflist = reproject_get_reflections(&ctx->images->images[2], ctx->cell_lattice); + //reproject_partner_features(ctx->images->images[2].rflist, &ctx->images->images[2]); refine_do_cell(ctx); image_feature_list_free(ctx->images->images[0].rflist); image_feature_list_free(ctx->images->images[1].rflist); + //image_feature_list_free(ctx->images->images[2].rflist); - fail = 0; - if ( fabs(ctx->cell->a.x - cell_real->a.x) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: ax not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->a.y - cell_real->a.y) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: ay not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->a.z - cell_real->a.z) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: az not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->b.x - cell_real->b.x) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: bx not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->b.y - cell_real->b.y) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: by not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->b.z - cell_real->b.z) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: bz not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->c.x - cell_real->c.x) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: cx not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->c.y - cell_real->c.y) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: cy not determined correctly\n"); - fail = 1; - } - if ( fabs(ctx->cell->c.z - cell_real->c.z) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: cz not determined correctly\n"); - fail = 1; - } + fail = check_cell(ctx->cell, cell_real); free(ctx); -- cgit v1.2.3