aboutsummaryrefslogtreecommitdiff
path: root/src/refine.c
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-10-30 17:29:17 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-10-30 17:29:17 +0000
commit4676d2c74e1a29d8aa5c0da56cb67ba7a6bb7e0f (patch)
tree097f2fbb5f36e8086bc62eee0f37771e0a0796f3 /src/refine.c
parent98ca230ab68e71cd29402ad689dd929abd46b3d5 (diff)
Refinement framework
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@185 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/refine.c')
-rw-r--r--src/refine.c137
1 files changed, 124 insertions, 13 deletions
diff --git a/src/refine.c b/src/refine.c
index ede96cb..aaefdf9 100644
--- a/src/refine.c
+++ b/src/refine.c
@@ -24,17 +24,17 @@
#include "reflections.h"
#include "image.h"
#include "reproject.h"
+#include "control.h"
+#include "mapping.h"
+/* Return the root sum squared deviation distance for all the "reprojectable" features in an image */
static double refine_image_deviation(ImageRecord *image, ReflectionList *cell_lattice) {
ImageFeatureList *rflist;
ImageFeatureList *flist;
- double xc, yc;
int i;
double total;
- xc = image->x_centre;
- yc = image->y_centre;
rflist = reproject_get_reflections(image, cell_lattice);
flist = image->features;
@@ -56,12 +56,59 @@ static double refine_image_deviation(ImageRecord *image, ReflectionList *cell_la
}
-void refine_open(DisplayWindow *dw) {
+/* Use the IPR algorithm to make "cell" fit the given image */
+static void refine_fit_image(Basis *cell, ImageRecord *image) {
+
+ ImageFeatureList *rflist;
+ ImageFeatureList *flist;
+ int i;
+ ReflectionList *cell_lattice;
+
+ cell_lattice = reflection_list_from_cell(cell);
+ rflist = reproject_get_reflections(image, cell_lattice);
+ flist = image->features;
+ reproject_partner_features(rflist, image);
+
+ for ( i=0; i<rflist->n_features; i++ ) {
+
+ double dx, dy;
+ double x, y, z, twotheta;
+ double old_x, old_y;
+
+ /* Skip if no partner */
+ if ( !rflist->features[i].partner ) continue;
+
+ /* Determine the difference vector */
+ dx = rflist->features[i].partner->x - rflist->features[i].x;
+ dy = rflist->features[i].partner->y - rflist->features[i].y;
+
+ /* Map the difference vector to the relevant tilted plane */
+ old_x = rflist->features[i].partner->x;
+ old_y = rflist->features[i].partner->y;
+ rflist->features[i].partner->x = dx;
+ rflist->features[i].partner->y = dy;
+ mapping_map_to_space(rflist->features[i].partner, &x, &y, &z, &twotheta);
+ rflist->features[i].partner->x = old_x;
+ rflist->features[i].partner->y = old_y;
+
+ printf("Feature %3i: %3i %3i %3i dev=%8e %8e %8e (%5f mrad)\n",
+ i, rflist->features[i].h, rflist->features[i].k, rflist->features[i].l, x, y, z, twotheta*1e3);
+
+ /* Work out weightings for a, b and c */
+
+
+ }
+
+ image_feature_list_free(rflist);
+
+}
+
+/* Display a graph of root sum squared deviation distance against some other parameter */
+static void refine_show_graph(ControlContext *ctx, int n) {
GtkWidget *window;
GtkWidget *graph;
double old_tilt;
- int n;
double *values;
size_t idx;
double tilt;
@@ -71,16 +118,16 @@ void refine_open(DisplayWindow *dw) {
gtk_window_set_title(GTK_WINDOW(window), "Refinement Graph");
graph = gtk_value_graph_new();
- dw->ctx->cell_lattice = reflection_list_from_cell(dw->ctx->cell);
- n = 0;
- idx = 0;
- old_tilt = dw->ctx->images->images[n].tilt;
+ ctx->cell_lattice = reflection_list_from_cell(ctx->cell);
+ old_tilt = ctx->images->images[n].tilt;
values = malloc(401*sizeof(double));
- for ( tilt=old_tilt-0.2; tilt<=old_tilt+0.2; tilt+=0.001 ) {
- dw->ctx->images->images[n].tilt = tilt;
- values[idx++] = refine_image_deviation(&dw->ctx->images->images[n], dw->ctx->cell_lattice);
+ tilt = old_tilt-0.2;
+ for ( idx=0; idx<401; idx++ ) {
+ ctx->images->images[n].tilt = tilt;
+ values[idx] = refine_image_deviation(&ctx->images->images[n], ctx->cell_lattice);
+ tilt += 0.001;
}
- dw->ctx->images->images[n].tilt = old_tilt;
+ ctx->images->images[n].tilt = old_tilt;
gtk_value_graph_set_data(GTK_VALUE_GRAPH(graph), values, idx);
gtk_container_add(GTK_CONTAINER(window), graph);
@@ -88,3 +135,67 @@ void refine_open(DisplayWindow *dw) {
}
+static gint refine_graph(GtkWidget *step_button, ControlContext *ctx) {
+ refine_show_graph(ctx, ctx->reproject_cur_image);
+ return 0;
+}
+
+static gint refine_step(GtkWidget *step_button, ControlContext *ctx) {
+
+ if ( ctx->reproject_id ) {
+ refine_fit_image(ctx->cell, &ctx->images->images[ctx->reproject_cur_image]);
+ } else {
+ displaywindow_error("Please first open the reprojection window and select the image to fit", ctx->dw);
+ }
+
+ return 0;
+
+}
+
+static gint refine_response(GtkWidget *refine_window, gint response, ControlContext *ctx) {
+
+ ctx->refine_window = NULL;
+ gtk_widget_destroy(refine_window);
+
+ return 0;
+
+}
+
+void refine_open(ControlContext *ctx) {
+
+ GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *table;
+ GtkWidget *step_button;
+ GtkWidget *graph_button;
+
+ if ( ctx->refine_window ) return;
+
+ ctx->refine_window = gtk_dialog_new_with_buttons("Refine Reconstruction", GTK_WINDOW(ctx->dw->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
+ gtk_window_set_default_size(GTK_WINDOW(ctx->refine_window), 256, -1);
+
+ vbox = gtk_vbox_new(FALSE, 0);
+ hbox = gtk_hbox_new(TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(ctx->refine_window)->vbox), GTK_WIDGET(hbox), FALSE, FALSE, 7);
+ gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), FALSE, FALSE, 5);
+
+ table = gtk_table_new(2, 1, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 5);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 5);
+ gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(table), FALSE, FALSE, 0);
+
+ step_button = gtk_button_new_with_label("Refine Lattice to Fit Current Pattern");
+ gtk_table_attach_defaults(GTK_TABLE(table), step_button, 1, 2, 1, 2);
+ g_signal_connect(G_OBJECT(step_button), "clicked", G_CALLBACK(refine_step), ctx);
+
+ graph_button = gtk_button_new_with_label("Show Graph of Deviation Against Parameter");
+ gtk_table_attach_defaults(GTK_TABLE(table), graph_button, 1, 2, 2, 3);
+ g_signal_connect(G_OBJECT(graph_button), "clicked", G_CALLBACK(refine_graph), ctx);
+
+ g_signal_connect(G_OBJECT(ctx->refine_window), "response", G_CALLBACK(refine_response), ctx);
+ gtk_widget_show_all(ctx->refine_window);
+
+
+}
+