aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/image.c31
-rw-r--r--src/image.h1
-rw-r--r--src/imagedisplay.c2
-rw-r--r--src/main.c31
-rw-r--r--src/mapping.c25
-rw-r--r--src/mapping.h2
-rw-r--r--src/prealign.c47
-rw-r--r--src/prealign.h1
-rw-r--r--src/refine.c14
-rw-r--r--src/reproject.c32
10 files changed, 121 insertions, 65 deletions
diff --git a/src/image.c b/src/image.c
index 96afe3c..5290cb4 100644
--- a/src/image.c
+++ b/src/image.c
@@ -11,9 +11,11 @@
#include <stdlib.h>
#include <assert.h>
+#include <math.h>
#include "control.h"
#include "image.h"
+#include "utils.h"
int image_add(ImageList *list, uint16_t *image, int width, int height, double tilt, ControlContext *ctx) {
@@ -114,3 +116,32 @@ void image_feature_list_free(ImageFeatureList *flist) {
}
+ImageFeature *image_feature_closest(ImageFeatureList *flist, double x, double y, double *d) {
+
+ int i;
+ double dmin = +HUGE_VAL;
+ int closest;
+ closest = 0;
+
+ for ( i=0; i<flist->n_features; i++ ) {
+
+ double d;
+
+ d = distance(flist->features[i].x, flist->features[i].y, x, y);
+
+ if ( d < dmin ) {
+ dmin = d;
+ closest = i;
+ }
+
+ }
+
+ if ( dmin <= 20.0 ) {
+ *d = dmin;
+ return &flist->features[closest];
+ }
+
+ return NULL;
+
+}
+
diff --git a/src/image.h b/src/image.h
index 87f330e..ebabee6 100644
--- a/src/image.h
+++ b/src/image.h
@@ -77,6 +77,7 @@ extern void image_feature_list_free(ImageFeatureList *flist);
extern void image_add_feature(ImageFeatureList *flist, double x, double y, ImageRecord *parent, double intensity);
extern void image_add_feature_index(ImageFeatureList *flist, double x, double y, ImageRecord *parent, double intensity,
signed int h, signed int k, signed int l);
+extern ImageFeature *image_feature_closest(ImageFeatureList *flist, double x, double y, double *d);
#endif /* IMAGE_H */
diff --git a/src/imagedisplay.c b/src/imagedisplay.c
index ceb36ff..8714722 100644
--- a/src/imagedisplay.c
+++ b/src/imagedisplay.c
@@ -109,6 +109,8 @@ void imagedisplay_put_data(ImageDisplay *imagedisplay, ImageRecord imagerecord)
}
}
+ memcpy(&imagedisplay->imagerecord, &imagerecord, sizeof(ImageRecord));
+
/* Create the pixbuf from the 8-bit display data */
imagedisplay->pixbuf = gdk_pixbuf_new_from_data(imagedisplay->data, GDK_COLORSPACE_RGB, FALSE, 8, w, h, w*3,
(GdkPixbufDestroyNotify)imagedisplay_free_data, imagedisplay);
diff --git a/src/main.c b/src/main.c
index 5335a19..be23b1b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,15 +33,44 @@
#include "prealign.h"
#include "control.h"
#include "dirax.h"
+#include "itrans.h"
void main_do_reconstruction(ControlContext *ctx) {
if ( ctx->inputfiletype != INPUT_DRX ) {
+
+ int val = 0;
+
+ /* Initial centering */
prealign_sum_stack(ctx->images, ctx->have_centres);
if ( ctx->finecentering ) {
prealign_fine_centering(ctx->images);
}
- mapping_create(ctx);
+
+ if ( !ctx->cache_filename ) {
+
+ int i;
+
+ /* Find all the features */
+ printf("MP: Analysing images..."); fflush(stdout);
+ for ( i=0; i<ctx->images->n_images; i++ ) {
+ ctx->images->images[i].features = itrans_process_image(&ctx->images->images[i], ctx->psmode);
+ }
+ printf("done.\n");
+
+ } else {
+
+ printf("MP: Loading previous image analysis from '%s'\n", ctx->cache_filename);
+ if ( cache_load(ctx->images, ctx->cache_filename) ) val = 1;
+
+ }
+
+ if ( ctx->finecentering ) {
+ prealign_feature_centering(ctx->images);
+ }
+
+ if ( !val ) mapping_map_features(ctx);
+
} /* else has already been created by dirax_load() */
if ( ctx->reflectionlist ) {
diff --git a/src/mapping.c b/src/mapping.c
index afe36c4..f9b47c0 100644
--- a/src/mapping.c
+++ b/src/mapping.c
@@ -16,7 +16,6 @@
#include "reflections.h"
#include "control.h"
-#include "itrans.h"
#include "image.h"
#include "displaywindow.h"
#include "cache.h"
@@ -92,7 +91,7 @@ int mapping_map_to_space(ImageFeature *refl, double *ddx, double *ddy, double *d
}
-static void mapping_map_features(ControlContext *ctx) {
+void mapping_map_features(ControlContext *ctx) {
int i;
@@ -122,28 +121,6 @@ static void mapping_map_features(ControlContext *ctx) {
}
-ReflectionList *mapping_create(ControlContext *ctx) {
-
- int i;
-
- if ( !ctx->cache_filename ) {
- /* Find all the features */
- printf("MP: Analysing images..."); fflush(stdout);
- for ( i=0; i<ctx->images->n_images; i++ ) {
- ctx->images->images[i].features = itrans_process_image(&ctx->images->images[i], ctx->psmode);
- }
- printf("done.\n");
- } else {
- printf("MP: Loading previous image analysis from '%s'\n", ctx->cache_filename);
- if ( cache_load(ctx->images, ctx->cache_filename) ) return NULL;
- }
-
- mapping_map_features(ctx);
-
- return ctx->reflectionlist;
-
-}
-
void mapping_adjust_axis(ControlContext *ctx, double offset) {
int i;
diff --git a/src/mapping.h b/src/mapping.h
index 380e876..208d46d 100644
--- a/src/mapping.h
+++ b/src/mapping.h
@@ -19,9 +19,9 @@
#include "reflections.h"
#include "control.h"
-extern ReflectionList *mapping_create(ControlContext *ctx);
extern void mapping_adjust_axis(ControlContext *ctx, double offset);
extern int mapping_map_to_space(ImageFeature *refl, double *ddx, double *ddy, double *ddz, double *twotheta);
+extern void mapping_map_features(ControlContext *ctx);
#endif /* MAPPING_H */
diff --git a/src/prealign.c b/src/prealign.c
index 9574946..955ef4d 100644
--- a/src/prealign.c
+++ b/src/prealign.c
@@ -177,7 +177,7 @@ void prealign_sum_stack(ImageList *list, int have_centres) {
}
-#define CENTERING_WINDOW_SIZE 20
+#define CENTERING_WINDOW_SIZE 50
void prealign_fine_centering(ImageList *list) {
@@ -195,22 +195,36 @@ void prealign_fine_centering(ImageList *list) {
height = list->images[i].height;
mask_x = list->images[i].x_centre;
mask_y = list->images[i].y_centre;
-
- while ( (did_something) && (distance(mask_x, mask_y, list->images[i].x_centre, list->images[i].y_centre)<50) ) {
+ while ( (did_something) && (distance(mask_x, mask_y, list->images[i].x_centre, list->images[i].y_centre)<100) ) {
+
+ double nmax, nmask_x, nmask_y;
+
+ nmax = 0.0;
+ nmask_x = 0;
+ nmask_y = 0;
max = list->images[i].image[mask_x+width*mask_y];
did_something = 0;
+
for ( sy=biggest(mask_y-CENTERING_WINDOW_SIZE/2, 0); sy<smallest(mask_y+CENTERING_WINDOW_SIZE/2, height); sy++ ) {
for ( sx=biggest(mask_x-CENTERING_WINDOW_SIZE/2, 0); sx<smallest(mask_x+CENTERING_WINDOW_SIZE/2, width); sx++ ) {
- if ( list->images[i].image[sx+width*sy] > max ) {
- max = list->images[i].image[sx+width*sy];
- mask_x = sx;
- mask_y = sy;
- did_something = 1;
+
+ if ( list->images[i].image[sx+width*sy] > nmax ) {
+ nmax = list->images[i].image[sx+width*sy];
+ nmask_x = sx;
+ nmask_y = sy;
}
+
}
}
+ if ( nmax > max ) {
+ max = nmax;
+ mask_x = nmask_x;
+ mask_y = nmask_y;
+ did_something = 1;
+ }
+
}
if ( !did_something ) {
@@ -233,3 +247,20 @@ void prealign_fine_centering(ImageList *list) {
}
+void prealign_feature_centering(ImageList *list) {
+
+ int i;
+
+ for ( i=0; i<list->n_images; i++ ) {
+
+ double d;
+ ImageFeature *feature;
+
+ feature = image_feature_closest(list->images[i].features, list->images[i].x_centre, list->images[i].y_centre, &d);
+ list->images[i].x_centre = feature->x;
+ list->images[i].y_centre = feature->y;
+
+ }
+
+}
+
diff --git a/src/prealign.h b/src/prealign.h
index 1dc9617..cb8bf9f 100644
--- a/src/prealign.h
+++ b/src/prealign.h
@@ -21,6 +21,7 @@
extern void prealign_do_series(ControlContext *ctx);
extern void prealign_sum_stack(ImageList *list, int have_centres);
extern void prealign_fine_centering(ImageList *list);
+extern void prealign_feature_centering(ImageList *list);
#endif /* PREALIGN_H */
diff --git a/src/refine.c b/src/refine.c
index 8f8761a..b2dd5d0 100644
--- a/src/refine.c
+++ b/src/refine.c
@@ -291,6 +291,19 @@ static gint refine_step(GtkWidget *step_button, ControlContext *ctx) {
}
+static gint refine_sequence(GtkWidget *step_button, ControlContext *ctx) {
+
+ if ( !ctx->cell ) {
+ displaywindow_error("No reciprocal unit cell has been found.", ctx->dw);
+ return 0;
+ }
+
+
+
+ return 0;
+
+}
+
static gint refine_response(GtkWidget *refine_window, gint response, ControlContext *ctx) {
ctx->refine_window = NULL;
@@ -344,6 +357,7 @@ void refine_open(ControlContext *ctx) {
gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 4, 5);
sequence_button = gtk_button_new_with_label("Run Sequencer");
gtk_table_attach_defaults(GTK_TABLE(table), sequence_button, 1, 2, 5, 6);
+ g_signal_connect(G_OBJECT(sequence_button), "clicked", G_CALLBACK(refine_sequence), ctx);
g_signal_connect(G_OBJECT(ctx->refine_window), "response", G_CALLBACK(refine_response), ctx);
gtk_widget_show_all(ctx->refine_window);
diff --git a/src/reproject.c b/src/reproject.c
index 2ff7e6c..095b39a 100644
--- a/src/reproject.c
+++ b/src/reproject.c
@@ -178,36 +178,6 @@ ImageFeatureList *reproject_get_reflections(ImageRecord *image, ReflectionList *
}
-/* Attempt to find the partner for "feature" from the feature list of "image" */
-static ImageFeature *reproject_find_partner(ImageFeature *feature, ImageRecord *image, double *d) {
-
- int i;
- double dmin = +HUGE_VAL;
- int closest;
- closest = 0;
-
- for ( i=0; i<image->features->n_features; i++ ) {
-
- double d;
-
- d = distance(image->features->features[i].x, image->features->features[i].y, feature->x, feature->y);
-
- if ( d < dmin ) {
- dmin = d;
- closest = i;
- }
-
- }
-
- if ( dmin <= 20.0 ) {
- *d = dmin;
- return &image->features->features[closest];
- }
-
- return NULL; /* No suitable partner found */
-
-}
-
/* Attempt to find partners from the feature list of "image" for each feature in "flist". */
void reproject_partner_features(ImageFeatureList *flist, ImageRecord *image) {
@@ -217,7 +187,7 @@ void reproject_partner_features(ImageFeatureList *flist, ImageRecord *image) {
double d = 0.0;
- flist->features[i].partner = reproject_find_partner(&flist->features[i], image, &d);
+ flist->features[i].partner = image_feature_closest(image->features, flist->features[i].x, flist->features[i].y, &d);
flist->features[i].partner_d = d;
}