From 8b883cd945ec49ec117ceee3b82760eb20d5c3a6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 16 Oct 2009 17:12:49 +0200 Subject: Perform the indexing, and test --- src/main.c | 5 ++++- src/sim-main.c | 4 ++-- src/templates.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 257a1169..9c678667 100644 --- a/src/main.c +++ b/src/main.c @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) struct image image; - printf("%6i: %s\n", i+1, in_files[i]); + printf("%6i: %s ", i+1, in_files[i]); image.width = 512; image.height = 512; @@ -112,6 +112,9 @@ int main(int argc, char *argv[]) try_templates(&image, templates); + printf("%6.2f %6.2f\n", rad2deg(image.omega), + rad2deg(image.tilt)); + } return 0; diff --git a/src/sim-main.c b/src/sim-main.c index f794cdda..9c7c6c3c 100644 --- a/src/sim-main.c +++ b/src/sim-main.c @@ -72,8 +72,8 @@ int main(int argc, char *argv[]) list = image_list_new(); image.width = 512; image.height = 512; - image.tilt = deg2rad(10.0); - image.omega = deg2rad(0.0); + image.tilt = deg2rad(32.0); + image.omega = deg2rad(40.0); image.fmode = FORMULATION_CLEN; image.x_centre = 255.5; image.y_centre = 255.5; diff --git a/src/templates.c b/src/templates.c index 33dc1720..a66607e1 100644 --- a/src/templates.c +++ b/src/templates.c @@ -134,7 +134,48 @@ TemplateList *generate_templates(UnitCell *cell, struct image params) } +int try_template(struct image *image, struct template template) +{ + int fit = 0; + struct template_feature *f; + + f = template.features; + while ( f != NULL ) { + + int x, y; + + x = f->x; + y = f->y; /* Discards digits after the decimal point */ + + fit += image->data[y*image->width+x]; + + f = f->next; + + } + + return fit; +} + + int try_templates(struct image *image, TemplateList *list) { + int i; + int fit_max = 0; + int i_max = 0; + + for ( i=0; in_templates; i++ ) { + + int fit; + + fit = try_template(image, list->templates[i]); + if ( fit > fit_max ) { + fit_max = fit; + i_max = i; + } + + } + image->omega = list->templates[i_max].omega; + image->tilt = list->templates[i_max].tilt; + return 0; } -- cgit v1.2.3