aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--data/displaywindow.ui1
-rw-r--r--src/Makefile.am2
-rw-r--r--src/control.h4
-rw-r--r--src/displaywindow.c8
-rw-r--r--src/imagedisplay.c26
-rw-r--r--src/imagedisplay.h8
-rw-r--r--src/main.c16
-rw-r--r--src/prealign.c58
-rw-r--r--src/prealign.h1
-rw-r--r--src/refine.c20
-rw-r--r--src/refine.h24
-rw-r--r--src/reproject.c53
13 files changed, 187 insertions, 36 deletions
diff --git a/Makefile.am b/Makefile.am
index 205c21a..218699f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
EXTRA_DIST = configure src/displaywindow.h src/trackball.h src/reflections.h src/control.h src/readpng.h src/mrc.h src/imagedisplay.h src/main.h \
data/displaywindow.ui src/utils.h src/itrans.h src/qdrp.h src/cache.h src/itrans-threshold.h src/basis.h \
src/itrans-zaefferer.h src/itrans-stat.h src/mapping.h src/reproject.h src/prealign.h \
- src/dirax.h src/image.h
+ src/dirax.h src/image.h src/refine.h
SUBDIRS = src data
diff --git a/data/displaywindow.ui b/data/displaywindow.ui
index 814f459..3260dac 100644
--- a/data/displaywindow.ui
+++ b/data/displaywindow.ui
@@ -20,6 +20,7 @@
<menuitem name="dirax" action="DirAxAction" />
<menuitem name="diraxstop" action="StopDirAxAction" />
<menuitem name="reproject" action="ReprojectAction" />
+ <menuitem name="refine" action="RefineAction" />
<separator />
<menuitem name="setaxis" action="SetAxisAction" />
<menuitem name="incraxis" action="IncrAxisAction" />
diff --git a/src/Makefile.am b/src/Makefile.am
index 0a3fbb2..78f8943 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
bin_PROGRAMS = dtr
dtr_SOURCES = main.c displaywindow.c trackball.c reflections.c readpng.c mrc.c imagedisplay.c utils.c itrans.c qdrp.c cache.c \
itrans-threshold.c itrans-zaefferer.c itrans-stat.c control.c mapping.c reproject.c prealign.c basis.c \
- dirax.c image.c
+ dirax.c image.c refine.c
dtr_LDADD = @LIBS@ @GTK_LIBS@ -lm @GTKGLEXT_LIBS@ -lgsl -lgslcblas -lutil
AM_CFLAGS = -Wall -g @CFLAGS@ @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@
AM_CPPFLAGS = -DDATADIR=\""$(datadir)"\"
diff --git a/src/control.h b/src/control.h
index a311b09..7de8025 100644
--- a/src/control.h
+++ b/src/control.h
@@ -48,6 +48,7 @@ typedef struct cctx_struct {
InputFileType inputfiletype;
PeakSearchMode psmode;
unsigned int prealign;
+ unsigned int finecentering;
unsigned int have_centres;
/* Input filename */
@@ -84,8 +85,7 @@ typedef struct cctx_struct {
/* GTK bits */
GtkWidget *combo_peaksearch;
GtkWidget *checkbox_prealign;
- GtkWidget *checkbox_savecache;
- GtkWidget *checkbox_dirax;
+ GtkWidget *checkbox_finecentering;
GtkWidget *cache_file_selector;
/* IPR stuff */
diff --git a/src/displaywindow.c b/src/displaywindow.c
index c93cb13..d37821e 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -34,6 +34,7 @@
#include "reproject.h"
#include "cache.h"
#include "mapping.h"
+#include "refine.h"
static void displaywindow_gl_set_ortho(DisplayWindow *dw, GLfloat w, GLfloat h) {
@@ -1085,6 +1086,12 @@ static gint displaywindow_setaxis(GtkWidget *widget, DisplayWindow *dw) {
return 0;
}
+
+static gint displaywindow_refine(GtkWidget *widget, DisplayWindow *dw) {
+ refine_open(dw);
+ return 0;
+}
+
static void displaywindow_addmenubar(DisplayWindow *dw) {
GtkActionEntry entries[] = {
@@ -1099,6 +1106,7 @@ static void displaywindow_addmenubar(DisplayWindow *dw) {
{ "DirAxAction", GTK_STOCK_EXECUTE, "Start _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) },
{ "StopDirAxAction", GTK_STOCK_CLOSE, "Stop DirAx", NULL, NULL, G_CALLBACK(displaywindow_dirax_stop) },
{ "ReprojectAction", NULL, "_Reproject Diffraction Patterns", NULL, NULL, G_CALLBACK(displaywindow_reproject) },
+ { "RefineAction", GTK_STOCK_EXECUTE, "Refine Reconstruction", NULL, NULL, G_CALLBACK(displaywindow_refine) },
{ "SetAxisAction", NULL, "Set Tilt Axis Position", NULL, NULL, G_CALLBACK(displaywindow_setaxis) },
{ "IncrAxisAction", NULL, "Increase Tilt Axis Position", "<Ctrl>Up", NULL, G_CALLBACK(displaywindow_incraxis) },
{ "DecrAxisAction", NULL, "Decrease Tilt Axis Position", "<Ctrl>Down", NULL, G_CALLBACK(displaywindow_decraxis) },
diff --git a/src/imagedisplay.c b/src/imagedisplay.c
index 2698ac1..26277a2 100644
--- a/src/imagedisplay.c
+++ b/src/imagedisplay.c
@@ -141,7 +141,8 @@ static void imagedisplay_destroyed(GtkWidget *widget, ImageDisplay *imagedisplay
g_object_unref(G_OBJECT(imagedisplay->gc_centre));
g_object_unref(G_OBJECT(imagedisplay->gc_tiltaxis));
- g_object_unref(G_OBJECT(imagedisplay->gc_marks));
+ g_object_unref(G_OBJECT(imagedisplay->gc_marks_1));
+ g_object_unref(G_OBJECT(imagedisplay->gc_marks_2));
free(imagedisplay);
@@ -201,7 +202,16 @@ static gboolean imagedisplay_redraw(GtkWidget *drawingarea, GdkEventExpose *even
cur = imagedisplay->marks;
while ( cur ) {
- gdk_draw_arc(drawingarea->window, imagedisplay->gc_marks, FALSE,
+
+ GdkGC *gc;
+
+ if ( cur->type == IMAGEDISPLAY_MARK_CIRCLE_2 ) {
+ gc = imagedisplay->gc_marks_2;
+ } else {
+ gc = imagedisplay->gc_marks_1;
+ }
+
+ gdk_draw_arc(drawingarea->window, gc, FALSE,
xoffs + cur->x*scale - 5,
yoffs + imagedisplay->view_height-1-cur->y*scale - 5,
11, 11, 0, 64*360);
@@ -224,9 +234,13 @@ static gint imagedisplay_realize(GtkWidget *widget, ImageDisplay *imagedisplay)
gdk_color_parse("#6600dd", &colour);
gdk_gc_set_rgb_fg_color(imagedisplay->gc_tiltaxis, &colour);
- imagedisplay->gc_marks = gdk_gc_new(imagedisplay->drawingarea->window);
+ imagedisplay->gc_marks_1 = gdk_gc_new(imagedisplay->drawingarea->window);
gdk_color_parse("#dd0000", &colour);
- gdk_gc_set_rgb_fg_color(imagedisplay->gc_marks, &colour);
+ gdk_gc_set_rgb_fg_color(imagedisplay->gc_marks_1, &colour);
+
+ imagedisplay->gc_marks_2 = gdk_gc_new(imagedisplay->drawingarea->window);
+ gdk_color_parse("#00dd00", &colour);
+ gdk_gc_set_rgb_fg_color(imagedisplay->gc_marks_2, &colour);
imagedisplay->realised = TRUE;
@@ -296,13 +310,13 @@ ImageDisplay *imagedisplay_open(ImageRecord image, const char *title, ImageDispl
return imagedisplay_open_with_message(image, title, NULL, flags, NULL, NULL);
}
-void imagedisplay_mark_circle(ImageDisplay *imagedisplay, double x, double y) {
+void imagedisplay_add_mark(ImageDisplay *imagedisplay, double x, double y, ImageDisplayMarkType type) {
ImageDisplayMark *new;
new = malloc(sizeof(ImageDisplayMark));
new->x = x; new->y = y;
- new->type = IMAGEDISPLAY_MARK_CIRCLE;
+ new->type = type;
new->next = NULL;
if ( !imagedisplay->marks ) {
diff --git a/src/imagedisplay.h b/src/imagedisplay.h
index f50d0c0..38d2fbe 100644
--- a/src/imagedisplay.h
+++ b/src/imagedisplay.h
@@ -29,7 +29,8 @@ typedef enum {
} ImageDisplayFlags;
typedef enum {
- IMAGEDISPLAY_MARK_CIRCLE
+ IMAGEDISPLAY_MARK_CIRCLE_1,
+ IMAGEDISPLAY_MARK_CIRCLE_2
} ImageDisplayMarkType;
typedef struct struct_imagedisplaymark {
@@ -56,7 +57,8 @@ typedef struct imagedisplay_struct {
GCallback mouse_click_func;
GdkGC *gc_centre;
GdkGC *gc_tiltaxis;
- GdkGC *gc_marks;
+ GdkGC *gc_marks_1;
+ GdkGC *gc_marks_2;
gboolean realised;
unsigned int drawingarea_width;
@@ -69,7 +71,7 @@ typedef struct imagedisplay_struct {
extern ImageDisplay *imagedisplay_open(ImageRecord image, const char *title, ImageDisplayFlags flags);
extern ImageDisplay *imagedisplay_open_with_message(ImageRecord image, const char *title, const char *message,
ImageDisplayFlags flags, GCallback mouse_click_func, gpointer callback_data);
-extern void imagedisplay_mark_circle(ImageDisplay *imagedisplay, double x, double y);
+extern void imagedisplay_add_mark(ImageDisplay *imagedisplay, double x, double y, ImageDisplayMarkType type);
extern void imagedisplay_force_redraw(ImageDisplay *imagedisplay);
extern void imagedisplay_put_data(ImageDisplay *imagedisplay, ImageRecord imagerecord);
extern void imagedisplay_close(ImageDisplay *imagedisplay);
diff --git a/src/main.c b/src/main.c
index 2d8b8ed..ed4c188 100644
--- a/src/main.c
+++ b/src/main.c
@@ -38,6 +38,9 @@ void main_do_reconstruction(ControlContext *ctx) {
if ( ctx->inputfiletype != INPUT_DRX ) {
prealign_sum_stack(ctx->images, ctx->have_centres);
+ if ( ctx->finecentering ) {
+ prealign_fine_centering(ctx->images);
+ }
mapping_create(ctx);
} /* else has already been created by dirax_load() */
@@ -71,6 +74,12 @@ static gint main_method_window_response(GtkWidget *method_window, gint response,
ctx->prealign = FALSE;
}
+ if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ctx->checkbox_finecentering)) ) {
+ ctx->finecentering = TRUE;
+ } else {
+ ctx->finecentering = FALSE;
+ }
+
ctx->cache_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctx->cache_file_selector));
gtk_widget_destroy(method_window);
@@ -92,7 +101,7 @@ static gint main_method_window_response(GtkWidget *method_window, gint response,
}
if ( ctx->prealign ) {
- prealign_do_series(ctx);
+ prealign_do_series(ctx); /* this will eventually call main_do_reconstruction() */
} else {
main_do_reconstruction(ctx);
}
@@ -135,7 +144,7 @@ void main_method_dialog_open(ControlContext *ctx) {
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(method_window)->vbox), GTK_WIDGET(hbox), FALSE, FALSE, 7);
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), FALSE, TRUE, 10);
- table = gtk_table_new(3, 2, FALSE);
+ table = gtk_table_new(4, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 5);
peaksearch_label = gtk_label_new("Peak Search: ");
@@ -161,6 +170,9 @@ void main_method_dialog_open(ControlContext *ctx) {
ctx->checkbox_prealign = gtk_check_button_new_with_label("Manually pre-align the image stack");
gtk_table_attach_defaults(GTK_TABLE(table), ctx->checkbox_prealign, 1, 3, 3, 4);
+ ctx->checkbox_finecentering = gtk_check_button_new_with_label("Perform fine pattern centering");
+ gtk_table_attach_defaults(GTK_TABLE(table), ctx->checkbox_finecentering, 1, 3, 4, 5);
+
if ( ctx->inputfiletype == INPUT_CACHE ) {
gtk_widget_set_sensitive(GTK_WIDGET(ctx->combo_peaksearch), FALSE);
gtk_combo_box_set_active(GTK_COMBO_BOX(ctx->combo_peaksearch), 5);
diff --git a/src/prealign.c b/src/prealign.c
index e383fa6..bccdb5e 100644
--- a/src/prealign.c
+++ b/src/prealign.c
@@ -18,6 +18,7 @@
#include "imagedisplay.h"
#include "main.h"
#include "image.h"
+#include "utils.h"
typedef struct {
int n;
@@ -72,6 +73,9 @@ void prealign_do_series(ControlContext *ctx) {
}
+/* Sum the image stack, taking pre-existing centres into account if available.
+ * If no centres available, select the brightest pixel from the sum and assign
+ * that as the centre to all the images. */
void prealign_sum_stack(ImageList *list, int have_centres) {
int twidth, theight;
@@ -173,3 +177,57 @@ void prealign_sum_stack(ImageList *list, int have_centres) {
}
+#define CENTERING_WINDOW_SIZE 20
+
+void prealign_fine_centering(ImageList *list) {
+
+ int i;
+
+ for ( i=0; i<list->n_images; i++ ) {
+
+ int sx, sy;
+ double max;
+ unsigned int did_something = 1;
+ int mask_x, mask_y;
+ int width, height;
+
+ width = list->images[i].width;
+ 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) ) {
+
+ 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 ( !did_something ) {
+
+ assert(mask_x<width);
+ assert(mask_y<height);
+ assert(mask_x>=0);
+ assert(mask_y>=0);
+
+ list->images[i].x_centre = mask_x;
+ list->images[i].y_centre = mask_y;
+
+ }
+
+ }
+
+ prealign_sum_stack(list, TRUE);
+
+}
+
diff --git a/src/prealign.h b/src/prealign.h
index c21390b..1dc9617 100644
--- a/src/prealign.h
+++ b/src/prealign.h
@@ -20,6 +20,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);
#endif /* PREALIGN_H */
diff --git a/src/refine.c b/src/refine.c
new file mode 100644
index 0000000..fba19fb
--- /dev/null
+++ b/src/refine.c
@@ -0,0 +1,20 @@
+/*
+ * refine.c
+ *
+ * Refine the reconstruction
+ *
+ * (c) 2007 Thomas White <taw27@cam.ac.uk>
+ *
+ * dtr - Diffraction Tomography Reconstruction
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "displaywindow.h"
+
+void refine_open(DisplayWindow *dw) {
+}
+
diff --git a/src/refine.h b/src/refine.h
new file mode 100644
index 0000000..679c47f
--- /dev/null
+++ b/src/refine.h
@@ -0,0 +1,24 @@
+/*
+ * refine.h
+ *
+ * Refine the reconstruction
+ *
+ * (c) 2007 Thomas White <taw27@cam.ac.uk>
+ *
+ * dtr - Diffraction Tomography Reconstruction
+ *
+ */
+
+#ifndef REFINE_H
+#define REFINE_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "displaywindow.h"
+
+extern void refine_open(DisplayWindow *dw);
+
+#endif /* REFINE_H */
+
diff --git a/src/reproject.c b/src/reproject.c
index 2c84326..b13dd66 100644
--- a/src/reproject.c
+++ b/src/reproject.c
@@ -85,6 +85,7 @@ ImageFeatureList *reproject_get_reflections(ImageRecord *image, ReflectionList *
double theta;
double x, y;
double rx, ry, rz;
+ double xtest, ytest;
/* Determine the intersection point */
xi = xl + s*nx; yi = yl + s*ny; zi = zl + s*nz;
@@ -153,12 +154,10 @@ ImageFeatureList *reproject_get_reflections(ImageRecord *image, ReflectionList *
return NULL;
}
- /* Adjust centre */
- x += image->x_centre;
- y += image->y_centre;
-
/* Sanity check */
- if ( (x>=0) && (x<image->width) && (y>=0) && (y<image->height) ) {
+ xtest = x + image->x_centre;
+ ytest = y + image->y_centre;
+ if ( (xtest>=0) && (xtest<image->width) && (ytest>=0) && (ytest<image->height) ) {
/* Record the reflection */
image_add_feature(flist, x, y, image, reflection->intensity);
@@ -178,10 +177,32 @@ ImageFeatureList *reproject_get_reflections(ImageRecord *image, ReflectionList *
}
-static gint reproject_clicked(GtkWidget *widget, GdkEventButton *event, ControlContext *ctx) {
+static void reproject_mark_peaks(ControlContext *ctx) {
ImageFeatureList *flist;
size_t j;
+ double xc, yc;
+
+ xc = ctx->images->images[ctx->reproject_cur_image].x_centre;
+ yc = ctx->images->images[ctx->reproject_cur_image].y_centre;
+
+ /* Draw the reprojected peaks */
+ flist = reproject_get_reflections(&ctx->images->images[ctx->reproject_cur_image], ctx->cell_lattice, ctx);
+ for ( j=0; j<flist->n_features; j++ ) {
+ imagedisplay_add_mark(ctx->reproject_id, xc+flist->features[j].x, yc+flist->features[j].y, IMAGEDISPLAY_MARK_CIRCLE_1);
+ }
+ image_feature_list_free(flist);
+
+ /* Now draw the original measured peaks */
+ flist = ctx->images->images[ctx->reproject_cur_image].features;
+ for ( j=0; j<flist->n_features; j++ ) {
+ imagedisplay_add_mark(ctx->reproject_id, xc+flist->features[j].x, yc+flist->features[j].y, IMAGEDISPLAY_MARK_CIRCLE_2);
+ }
+
+}
+
+static gint reproject_clicked(GtkWidget *widget, GdkEventButton *event, ControlContext *ctx) {
+
ctx->reproject_cur_image++;
if ( ctx->reproject_cur_image == ctx->images->n_images ) ctx->reproject_cur_image = 0;
@@ -189,11 +210,7 @@ static gint reproject_clicked(GtkWidget *widget, GdkEventButton *event, ControlC
imagedisplay_clear_circles(ctx->reproject_id);
reflectionlist_clear_markers(ctx->reflectionlist);
- flist = reproject_get_reflections(&ctx->images->images[ctx->reproject_cur_image], ctx->cell_lattice, ctx);
- for ( j=0; j<flist->n_features; j++ ) {
- imagedisplay_mark_circle(ctx->reproject_id, flist->features[j].x, flist->features[j].y);
- }
- image_feature_list_free(flist);
+ reproject_mark_peaks(ctx);
imagedisplay_put_data(ctx->reproject_id, ctx->images->images[ctx->reproject_cur_image]);
@@ -208,9 +225,6 @@ static gint reproject_closed(GtkWidget *widget, ControlContext *ctx) {
void reproject_open(ControlContext *ctx) {
- size_t j;
- ImageFeatureList *flist;
-
if ( ctx->reproject_id ) {
displaywindow_error("Reprojection window is already open.", ctx->dw);
return;
@@ -231,16 +245,13 @@ void reproject_open(ControlContext *ctx) {
ctx->cell_lattice = reflection_list_from_cell(ctx->cell);
ctx->reproject_cur_image = 0;
- ctx->reproject_id = imagedisplay_open_with_message(ctx->images->images[ctx->reproject_cur_image], "Current Image", "Click to change image",
+ ctx->reproject_id = imagedisplay_open_with_message(ctx->images->images[ctx->reproject_cur_image],
+ "Reprojected Diffraction Pattern", "Click to change image",
IMAGEDISPLAY_SHOW_CENTRE | IMAGEDISPLAY_SHOW_TILT_AXIS, G_CALLBACK(reproject_clicked), ctx);
- g_signal_connect(GTK_OBJECT(ctx->reproject_id->drawingarea), "destroy", G_CALLBACK(reproject_closed), ctx);
+ reproject_mark_peaks(ctx);
- flist = reproject_get_reflections(&ctx->images->images[ctx->reproject_cur_image], ctx->cell_lattice, ctx);
- for ( j=0; j<flist->n_features; j++ ) {
- imagedisplay_mark_circle(ctx->reproject_id, flist->features[j].x, flist->features[j].y);
- }
- image_feature_list_free(flist);
+ g_signal_connect(GTK_OBJECT(ctx->reproject_id->drawingarea), "destroy", G_CALLBACK(reproject_closed), ctx);
}