aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentf5dab4ce7e8aea035ee25ca8f818e5779eb88726 (diff)
Perform the indexing, and test
Diffstat (limited to 'src')
-rw-r--r--src/main.c5
-rw-r--r--src/sim-main.c4
-rw-r--r--src/templates.c41
3 files changed, 47 insertions, 3 deletions
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; 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;
}