aboutsummaryrefslogtreecommitdiff
path: root/src/templates.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-10-16 17:12:49 +0200
committerThomas White <taw@bitwiz.org.uk>2009-10-16 17:12:49 +0200
commit8b883cd945ec49ec117ceee3b82760eb20d5c3a6 (patch)
treeb51dc51bf3529a1a80d2452beed6ca7b78e65633 /src/templates.c
parentf5dab4ce7e8aea035ee25ca8f818e5779eb88726 (diff)
Perform the indexing, and test
Diffstat (limited to 'src/templates.c')
-rw-r--r--src/templates.c41
1 files changed, 41 insertions, 0 deletions
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; i<list->n_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;
}