diff options
author | Thomas White <taw@bitwiz.org.uk> | 2009-10-16 16:22:44 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2009-10-16 16:22:44 +0200 |
commit | f5dab4ce7e8aea035ee25ca8f818e5779eb88726 (patch) | |
tree | 9a491c7963e145c1d995acaddaed0dc6f21c5ae7 /src/templates.c | |
parent | a5289c2bbfdc7a04fc3f44b0cead930a2740394b (diff) |
Read image and generate templates
Diffstat (limited to 'src/templates.c')
-rw-r--r-- | src/templates.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/templates.c b/src/templates.c new file mode 100644 index 00000000..33dc1720 --- /dev/null +++ b/src/templates.c @@ -0,0 +1,140 @@ +/* + * templates.c + * + * Handle templates + * + * (c) 2006-2009 Thomas White <thomas.white@desy.de> + * + * template_index - Indexing diffraction patterns by template matching + * + */ + + +#define _GNU_SOURCE 1 +#include <stdlib.h> +#include <assert.h> +#include <math.h> +#include <stdio.h> + +#include "templates.h" +#include "cell.h" +#include "image.h" +#include "utils.h" +#include "relrod.h" + + +struct _templatelist +{ + int n_templates; + struct template *templates; +}; + + +struct template_feature +{ + float x; + float y; + struct template_feature *next; +}; + + +struct template +{ + float omega; + float tilt; + struct template_feature *features; +}; + + +static int template_add(TemplateList *list, struct template *template) +{ + if ( list->templates ) { + list->templates = realloc(list->templates, + (list->n_templates+1)*sizeof(struct template)); + } else { + assert(list->n_templates == 0); + list->templates = malloc(sizeof(struct template)); + } + + /* Copy the data */ + list->templates[list->n_templates] = *template; + + list->n_templates++; + + return list->n_templates - 1; +} + + +static TemplateList *template_list_new() +{ + TemplateList *list; + + list = malloc(sizeof(TemplateList)); + + list->n_templates = 0; + list->templates = NULL; + + return list; +} + + +TemplateList *generate_templates(UnitCell *cell, struct image params) +{ + TemplateList *list; + double omega, tilt; + + list = template_list_new(); + + omega = deg2rad(40.0); + + //for ( omega=deg2rad(-180); omega<deg2rad(180); omega+=deg2rad(1) ) { + + params.omega = omega; + + for ( tilt=0; tilt<deg2rad(180); tilt+=deg2rad(1) ) { + + struct template t; + struct template_feature *tfc; + int nrefl, i; + + t.omega = omega; + t.tilt = tilt; + t.features = malloc(sizeof(struct template_feature)); + t.features->next = NULL; + tfc = t.features; + + params.tilt = tilt; + get_reflections(¶ms, cell, 0.01e9); + + nrefl = image_feature_count(params.rflist); + for ( i=0; i<nrefl; i++ ) { + + struct imagefeature *f; + + f = image_get_feature(params.rflist, i); + + tfc->x = f->x; + tfc->y = f->y; + tfc->next = malloc(sizeof(struct template_feature)); + tfc = tfc->next; + + } + + template_add(list, &t); + + image_feature_list_free(params.rflist); + + printf("Generating templates... %+5.2f %+5.2f\r", + rad2deg(omega), rad2deg(tilt)); + + } + //} + + return list; +} + + +int try_templates(struct image *image, TemplateList *list) +{ + return 0; +} |