diff options
author | Thomas White <taw27@cam.ac.uk> | 2008-10-02 17:59:15 +0100 |
---|---|---|
committer | Thomas White <taw27@cam.ac.uk> | 2008-10-02 17:59:15 +0100 |
commit | 7087e28879c6f9eecac121929087acbca771d427 (patch) | |
tree | 646cb1ebb262317445146bd851e5473f08888746 | |
parent | 963efe005ccb4698762dd9437c827e718f01ab88 (diff) | |
parent | 8310cde840be611931c24a0fb3e1b9861eecb676 (diff) |
Merge branch 'master' into simple-search
Conflicts:
src/refine.c
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | Makefile.am | 11 | ||||
-rwxr-xr-x | autogen.sh | 8 | ||||
-rw-r--r-- | src/.gitignore | 7 | ||||
-rw-r--r-- | src/Makefile.am | 18 | ||||
-rw-r--r-- | src/control.h | 4 | ||||
-rw-r--r-- | src/displaywindow.c | 143 | ||||
-rw-r--r-- | src/displaywindow.h | 4 | ||||
-rw-r--r-- | src/glbits.c | 5 | ||||
-rw-r--r-- | src/imagedisplay.c | 70 | ||||
-rw-r--r-- | src/imagedisplay.h | 19 | ||||
-rw-r--r-- | src/mapping.c | 19 | ||||
-rw-r--r-- | src/mapping.h | 7 | ||||
-rw-r--r-- | src/refine.c | 3 | ||||
-rw-r--r-- | src/refinetest2d.c | 18 | ||||
-rw-r--r-- | src/refinetest3d1.c (renamed from src/refinetest3d.c) | 25 | ||||
-rw-r--r-- | src/refinetest3d2.c | 191 | ||||
-rw-r--r-- | src/refinetest3d3.c | 187 |
18 files changed, 621 insertions, 127 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97650f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +config.h +config.log +config.status +configure +stamp-h1 diff --git a/Makefile.am b/Makefile.am index 3bd800e..e59af98 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,8 @@ -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/refine.h src/gtk-valuegraph.h src/intensities.h src/glbits.h src/gtk-valuegraph.h +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/refine.h src/gtk-valuegraph.h \ + src/intensities.h src/glbits.h src/gtk-valuegraph.h SUBDIRS = src data -TESTS = src/refinetest2d src/refinetest3d +TESTS = src/refinetest2d src/refinetest3d1 src/refinetest3d2 src/refinetest3d3 diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..bf85949 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +aclocal +autoconf +#libtoolize +autoheader +automake -a + diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..1fbde8f --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,7 @@ +*.o +.deps +refinetest2d +refinetest3d1 +refinetest3d2 +refinetest3d3 +dtr diff --git a/src/Makefile.am b/src/Makefile.am index 117b738..d6e39c6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,15 +1,21 @@ -bin_PROGRAMS = dtr refinetest2d refinetest3d +bin_PROGRAMS = dtr refinetest2d refinetest3d1 refinetest3d2 refinetest3d3 -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 refine.c gtk-valuegraph.c intensities.c glbits.c +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 refine.c gtk-valuegraph.c intensities.c glbits.c dtr_LDADD = @LIBS@ @GTK_LIBS@ -lm @GTKGLEXT_LIBS@ -lgsl -lgslcblas -lutil refinetest2d_SOURCES = refinetest2d.c reflections.c basis.c utils.c reproject.c image.c refine.c mapping.c control.c refinetest2d_LDADD = @LIBS@ @GTK_LIBS@ -lm -lgsl -lgslcblas -lutil -refinetest3d_SOURCES = refinetest3d.c reflections.c basis.c utils.c reproject.c image.c refine.c mapping.c control.c -refinetest3d_LDADD = @LIBS@ @GTK_LIBS@ -lm -lgsl -lgslcblas -lutil +refinetest3d1_SOURCES = refinetest3d1.c reflections.c basis.c utils.c reproject.c image.c refine.c mapping.c control.c +refinetest3d1_LDADD = @LIBS@ @GTK_LIBS@ -lm -lgsl -lgslcblas -lutil + +refinetest3d2_SOURCES = refinetest3d2.c reflections.c basis.c utils.c reproject.c image.c refine.c mapping.c control.c +refinetest3d2_LDADD = @LIBS@ @GTK_LIBS@ -lm -lgsl -lgslcblas -lutil + +refinetest3d3_SOURCES = refinetest3d3.c reflections.c basis.c utils.c reproject.c image.c refine.c mapping.c control.c +refinetest3d3_LDADD = @LIBS@ @GTK_LIBS@ -lm -lgsl -lgslcblas -lutil AM_CFLAGS = -Wall -g @CFLAGS@ @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ AM_CPPFLAGS = -DDATADIR=\""$(datadir)"\" -I/usr/include/GL diff --git a/src/control.h b/src/control.h index 4b97970..5dcbc89 100644 --- a/src/control.h +++ b/src/control.h @@ -3,7 +3,7 @@ * * Common control structure * - * (c) 2007 Thomas White <taw27@cam.ac.uk> + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> * * dtr - Diffraction Tomography Reconstruction * @@ -76,7 +76,7 @@ typedef struct cctx_struct { struct imagelist_struct *images; /* "Output" */ - struct reflectionlist_struct *reflectionlist; /* Measured reflections (and stuff added to get displayed with them) */ + struct reflectionlist_struct *reflectionlist; /* Measured reflections */ struct dw_struct *dw; struct basis_struct *cell; /* Current estimate of the reciprocal unit cell */ struct reflectionlist_struct *cell_lattice; /* Reflections calculated from 'cell' */ diff --git a/src/displaywindow.c b/src/displaywindow.c index a038c8c..fe97f73 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -130,15 +130,16 @@ static void displaywindow_about(GtkWidget *widget, DisplayWindow *dw) { gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(window), PACKAGE_NAME); gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window), PACKAGE_VERSION); - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(window), "(c) 2006-2007 Thomas White and contributors"); + gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(window), "(c) 2006-2008 Thomas White and contributors"); gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(window), "Diffraction Tomography Reconstruction"); - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(window), "(c) 2006-2007 Thomas White <taw27@cam.ac.uk>\n" - "Virtual trackball (c) Copyright 1993, 1994, Silicon Graphics, Inc.\n" - "See Credits for a full list of contributors\n" - "\n" - "Research funded by:\n" - "FEI Electron Optics B.V.\n" - "The Engineering and Physical Sciences Research Council"); + gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(window), + "(c) 2006-2008 Thomas White <taw27@cam.ac.uk>\n" + "Virtual trackball (c) Copyright 1993, 1994, Silicon Graphics, Inc.\n" + "See Credits for a full list of contributors\n" + "\n" + "Research funded by:\n" + "FEI Electron Optics B.V.\n" + "The Engineering and Physical Sciences Research Council"); gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(window), "http://www-hrem.msm.cam.ac.uk/"); gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(window), authors); @@ -223,7 +224,8 @@ static gint displaywindow_savecache(GtkWidget *widget, DisplayWindow *dw) { GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); - g_signal_connect(G_OBJECT(dw->savecache_window), "response", G_CALLBACK(displaywindow_savecache_response), dw->ctx); + g_signal_connect(G_OBJECT(dw->savecache_window), "response", G_CALLBACK(displaywindow_savecache_response), + dw->ctx); gtk_widget_show_all(dw->savecache_window); return 0; @@ -272,7 +274,8 @@ static gint displaywindow_setaxis(GtkWidget *widget, DisplayWindow *dw) { GtkWidget *label; dw->tiltaxis_window = gtk_dialog_new_with_buttons("Set Tilt Axis Position", GTK_WINDOW(dw->window), - GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CLOSE, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CLOSE, GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); vbox = gtk_vbox_new(FALSE, 0); hbox = gtk_hbox_new(TRUE, 0); @@ -378,37 +381,45 @@ static void displaywindow_addmenubar(DisplayWindow *dw) { GtkActionEntry entries[] = { - { "FileAction", NULL, "_File", NULL, NULL, NULL }, - { "SaveCacheAction", "filesave", "Save Image Analysis to _Cache", NULL, NULL, G_CALLBACK(displaywindow_savecache) }, - { "SaveHKLAction", GTK_STOCK_SAVE, "Save Reflections", NULL, NULL, G_CALLBACK(displaywindow_savehkl) }, - { "CloseAction", GTK_STOCK_QUIT, "_Quit", NULL, NULL, G_CALLBACK(displaywindow_close) }, - - { "ViewAction", NULL, "_View", NULL, NULL, NULL }, - - { "ToolsAction", NULL, "_Tools", NULL, NULL, NULL }, - { "DirAxAction", "dtr-dirax", "Start _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) }, - { "DirAxReRunAction", NULL, "Run another DirAx cycle", NULL, NULL, G_CALLBACK(displaywindow_dirax_rerun) }, - { "StopDirAxAction", NULL, "Stop DirAx", NULL, NULL, G_CALLBACK(displaywindow_dirax_stop) }, - { "RefineStepAction", "dtr-refine", "Refine Unit Cell", NULL, NULL, G_CALLBACK(displaywindow_refinestep) }, - { "RefineSeqAction", "dtr-refineall", "Run Refinement Sequence", NULL, NULL, G_CALLBACK(displaywindow_refinestack) }, - { "SetAxisAction", "dtr-tiltaxis", "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) }, - { "ExtractIntensitiesAction", "dtr-quantify", "Quantify Reflection Intensities", NULL, NULL, G_CALLBACK(displaywindow_extract) }, - - { "HelpAction", NULL, "_Help", NULL, NULL, NULL }, - { "AboutAction", GTK_STOCK_ABOUT, "_About DTR...", NULL, NULL, G_CALLBACK(displaywindow_about) }, - - { "ButtonDirAxAction", "dtr-dirax", "Run _DirAx", NULL, NULL, G_CALLBACK(displaywindow_dirax) }, - { "ButtonTiltAxisAction", "dtr-tiltaxis", "Tilt Axis", NULL, NULL, G_CALLBACK(displaywindow_setaxis) }, - { "ButtonRefineStepAction", "dtr-refine", "Refine", NULL, NULL, G_CALLBACK(displaywindow_refinestep) }, - { "ButtonRefineSeqAction", "dtr-refineall", "Sequence", NULL, NULL, G_CALLBACK(displaywindow_refinestack) }, - { "ButtonFirstImageAction", GTK_STOCK_GOTO_FIRST, "First Image", NULL, NULL, G_CALLBACK(displaywindow_image_first) }, - { "ButtonPrevImageAction", GTK_STOCK_GO_BACK, "Previous Image", NULL, NULL, G_CALLBACK(displaywindow_image_prev) }, - { "ButtonNextImageAction", GTK_STOCK_GO_FORWARD, "Next Image", NULL, NULL, G_CALLBACK(displaywindow_image_next) }, - { "ButtonLastImageAction", GTK_STOCK_GOTO_LAST, "Last Image", NULL, NULL, G_CALLBACK(displaywindow_image_last) }, - { "ButtonExtractIntensitiesAction", "dtr-quantify", "Quantify", NULL, NULL, G_CALLBACK(displaywindow_extract) }, - + { "FileAction", NULL, "_File", NULL, NULL, NULL }, + { "SaveCacheAction", "filesave", "Save Image Analysis to _Cache", + NULL, NULL, G_CALLBACK(displaywindow_savecache) }, + { "SaveHKLAction", GTK_STOCK_SAVE, "Save Reflections", NULL, NULL, G_CALLBACK(displaywindow_savehkl) }, + { "CloseAction", GTK_STOCK_QUIT, "_Quit", NULL, NULL, G_CALLBACK(displaywindow_close) }, + + { "ViewAction", NULL, "_View", NULL, NULL, NULL }, + + { "ToolsAction", NULL, "_Tools", NULL, NULL, NULL }, + { "DirAxAction", "dtr-dirax", "Start _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) }, + { "DirAxReRunAction", NULL, "Run another DirAx cycle", NULL, NULL, G_CALLBACK(displaywindow_dirax_rerun) }, + { "StopDirAxAction", NULL, "Stop DirAx", NULL, NULL, G_CALLBACK(displaywindow_dirax_stop) }, + { "RefineStepAction", "dtr-refine", "Refine Unit Cell", NULL, NULL, G_CALLBACK(displaywindow_refinestep) }, + { "RefineSeqAction", "dtr-refineall", "Run Refinement Sequence", + NULL, NULL, G_CALLBACK(displaywindow_refinestack) }, + { "SetAxisAction", "dtr-tiltaxis", "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) }, + { "ExtractIntensitiesAction", "dtr-quantify", "Quantify Reflection Intensities", + NULL, NULL, G_CALLBACK(displaywindow_extract) }, + + { "HelpAction", NULL, "_Help", NULL, NULL, NULL }, + { "AboutAction", GTK_STOCK_ABOUT, "_About DTR...", NULL, NULL, G_CALLBACK(displaywindow_about) }, + + { "ButtonDirAxAction", "dtr-dirax", "Run _DirAx", NULL, NULL, G_CALLBACK(displaywindow_dirax) }, + { "ButtonTiltAxisAction", "dtr-tiltaxis", "Tilt Axis", NULL, NULL, G_CALLBACK(displaywindow_setaxis) }, + { "ButtonRefineStepAction", "dtr-refine", "Refine", NULL, NULL, G_CALLBACK(displaywindow_refinestep) }, + { "ButtonRefineSeqAction", "dtr-refineall", "Sequence", NULL, NULL, G_CALLBACK(displaywindow_refinestack) }, + { "ButtonFirstImageAction", GTK_STOCK_GOTO_FIRST, "First Image", + NULL, NULL, G_CALLBACK(displaywindow_image_first) }, + { "ButtonPrevImageAction", GTK_STOCK_GO_BACK, "Previous Image", + NULL, NULL, G_CALLBACK(displaywindow_image_prev) }, + { "ButtonNextImageAction", GTK_STOCK_GO_FORWARD, "Next Image", + NULL, NULL, G_CALLBACK(displaywindow_image_next) }, + { "ButtonLastImageAction", GTK_STOCK_GOTO_LAST, "Last Image", + NULL, NULL, G_CALLBACK(displaywindow_image_last) }, + { "ButtonExtractIntensitiesAction", "dtr-quantify", "Quantify", NULL, NULL, G_CALLBACK(displaywindow_extract) }, + }; guint n_entries = G_N_ELEMENTS(entries); @@ -425,9 +436,12 @@ static void displaywindow_addmenubar(DisplayWindow *dw) { guint n_radios2 = G_N_ELEMENTS(radios2); GtkToggleActionEntry toggles[] = { - { "CubeAction", NULL, "Show 100 nm^-1 _Cube", NULL, NULL, G_CALLBACK(displaywindow_changecube), dw->cube }, - { "LinesAction", NULL, "Show Indexing Lines", NULL, NULL, G_CALLBACK(displaywindow_changelines), dw->lines }, - { "BackgroundAction", NULL, "Show Coloured Background", NULL, NULL, G_CALLBACK(displaywindow_changebackground), dw->background }, + { "CubeAction", NULL, "Show 100 nm^-1 _Cube", + NULL, NULL, G_CALLBACK(displaywindow_changecube), dw->cube }, + { "LinesAction", NULL, "Show Indexing Lines", + NULL, NULL, G_CALLBACK(displaywindow_changelines), dw->lines }, + { "BackgroundAction", NULL, "Show Coloured Background", + NULL, NULL, G_CALLBACK(displaywindow_changebackground), dw->background }, }; guint n_toggles = G_N_ELEMENTS(toggles); @@ -435,8 +449,10 @@ static void displaywindow_addmenubar(DisplayWindow *dw) { dw->action_group = gtk_action_group_new("dtrdisplaywindow"); gtk_action_group_add_actions(dw->action_group, entries, n_entries, dw); - gtk_action_group_add_radio_actions(dw->action_group, radios, n_radios, -1, G_CALLBACK(displaywindow_changeview), dw); - gtk_action_group_add_radio_actions(dw->action_group, radios2, n_radios2, -1, G_CALLBACK(displaywindow_changemode), dw); + gtk_action_group_add_radio_actions(dw->action_group, radios, n_radios, + -1, G_CALLBACK(displaywindow_changeview), dw); + gtk_action_group_add_radio_actions(dw->action_group, radios2, n_radios2, + -1, G_CALLBACK(displaywindow_changemode), dw); gtk_action_group_add_toggle_actions(dw->action_group, toggles, n_toggles, dw); dw->ui = gtk_ui_manager_new(); @@ -497,9 +513,10 @@ void displaywindow_update_imagestack(DisplayWindow *dw) { /* Now connect partners */ for ( j=0; j<image->rflist->n_features; j++ ) { if ( image->rflist->features[j].partner ) { - imagedisplay_add_line(dw->stack, image->rflist->features[j].x, image->rflist->features[j].y, - image->rflist->features[j].partner->x, image->rflist->features[j].partner->y, - IMAGEDISPLAY_MARK_LINE_1); + imagedisplay_add_line(dw->stack, + image->rflist->features[j].x, image->rflist->features[j].y, + image->rflist->features[j].partner->x, image->rflist->features[j].partner->y, + IMAGEDISPLAY_MARK_LINE_1); } } } @@ -535,6 +552,15 @@ void displaywindow_update_imagestack(DisplayWindow *dw) { } +static void displaywindow_switch_page(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, DisplayWindow *dw) { + if ( dw->realised && (page_num == 0) ) { + int i; + for ( i=0; i<2; i++ ) { + glbits_expose(dw->drawing_area, NULL, dw); + } + } +} + DisplayWindow *displaywindow_open(ControlContext *ctx) { const char *filename; @@ -569,6 +595,7 @@ DisplayWindow *displaywindow_open(ControlContext *ctx) { dw->lines = FALSE; dw->background = TRUE; dw->cur_image = 0; + dw->realised = 0; dw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(dw->window), title); @@ -577,10 +604,6 @@ DisplayWindow *displaywindow_open(ControlContext *ctx) { gtk_container_add(GTK_CONTAINER(dw->window), dw->bigvbox); displaywindow_addmenubar(dw); - dw->status_bar = gtk_statusbar_new(); - gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(dw->status_bar), FALSE); - gtk_box_pack_end(GTK_BOX(dw->bigvbox), dw->status_bar, FALSE, FALSE, 0); - g_signal_connect(GTK_OBJECT(dw->window), "destroy", G_CALLBACK(displaywindow_closedown), dw); notebook = gtk_notebook_new(); @@ -598,12 +621,15 @@ DisplayWindow *displaywindow_open(ControlContext *ctx) { gtk_widget_set_size_request(dw->drawing_area, 640, 640); gtk_widget_set_gl_capability(dw->drawing_area, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dw->drawing_area, gtk_label_new("Reconstruction")); - gtk_widget_add_events(dw->drawing_area, GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_VISIBILITY_NOTIFY_MASK); + gtk_widget_add_events(dw->drawing_area, + GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_VISIBILITY_NOTIFY_MASK); g_signal_connect(GTK_OBJECT(dw->drawing_area), "configure_event", G_CALLBACK(glbits_configure), dw); g_signal_connect(GTK_OBJECT(dw->drawing_area), "realize", G_CALLBACK(glbits_realise), dw); g_signal_connect(GTK_OBJECT(dw->drawing_area), "expose_event", G_CALLBACK(glbits_expose), dw); - g_signal_connect(GTK_OBJECT(dw->drawing_area), "button_press_event", G_CALLBACK(displaywindow_gl_button_press), dw); - g_signal_connect(GTK_OBJECT(dw->drawing_area), "motion_notify_event", G_CALLBACK(displaywindow_gl_motion_notify), dw); + g_signal_connect(GTK_OBJECT(dw->drawing_area), "button_press_event", + G_CALLBACK(displaywindow_gl_button_press), dw); + g_signal_connect(GTK_OBJECT(dw->drawing_area), "motion_notify_event", + G_CALLBACK(displaywindow_gl_motion_notify), dw); g_signal_connect(GTK_OBJECT(dw->drawing_area), "destroy", G_CALLBACK(displaywindow_gl_destroyed), dw); if ( ctx->images->n_images > 0 ) { @@ -612,9 +638,12 @@ DisplayWindow *displaywindow_open(ControlContext *ctx) { gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dw->stack->vbox, gtk_label_new("Image Stack")); displaywindow_update_imagestack(dw); } else { - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), gtk_label_new("No Images to Display"), gtk_label_new("Image Stack")); + gtk_notebook_append_page(GTK_NOTEBOOK(notebook), gtk_label_new("No Images to Display"), + gtk_label_new("Image Stack")); } + g_signal_connect(GTK_OBJECT(notebook), "switch-page", G_CALLBACK(displaywindow_switch_page), dw); + displaywindow_enable_cell_functions(dw, FALSE); displaywindow_update_dirax(ctx, dw); d = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/file/savehkl"); diff --git a/src/displaywindow.h b/src/displaywindow.h index d0173f4..052e7d3 100644 --- a/src/displaywindow.h +++ b/src/displaywindow.h @@ -3,7 +3,7 @@ * * The display window * - * (c) 2007 Thomas White <taw27@cam.ac.uk> + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> * * dtr - Diffraction Tomography Reconstruction * @@ -39,7 +39,6 @@ typedef struct dw_struct { GtkActionGroup *action_group; GtkWidget *window; GtkWidget *bigvbox; - GtkWidget *status_bar; GtkWidget *drawing_area; GtkWidget *savecache_window; @@ -68,6 +67,7 @@ typedef struct dw_struct { GLuint gl_vshader_lightpp; GLuint gl_fshader_lightpp; GLuint gl_program_lightpp; + int realised; /* Display parameters */ DisplayWindowView view; diff --git a/src/glbits.c b/src/glbits.c index d32fc0c..ba03adf 100644 --- a/src/glbits.c +++ b/src/glbits.c @@ -676,8 +676,8 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw) GLfloat w = dw->drawing_area->allocation.width; GLfloat h = dw->drawing_area->allocation.height; GLfloat aspect = w/h; - GLfloat bg_top[] = { 0.6, 0.9, 0.8, 1.0 }; - GLfloat bg_bot[] = { 0.3, 0.7, 0.5, 1.0 }; + GLfloat bg_top[] = { 0.0, 0.3, 1.0, 1.0 }; + GLfloat bg_bot[] = { 0.0, 0.7, 1.0, 1.0 }; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -934,6 +934,7 @@ gint glbits_realise(GtkWidget *widget, DisplayWindow *dw) { glbits_set_ortho(dw, w, h); glbits_first_prepare(dw); + dw->realised = 1; gdk_gl_drawable_gl_end(gldrawable); diff --git a/src/imagedisplay.c b/src/imagedisplay.c index 00b7285..42026d2 100644 --- a/src/imagedisplay.c +++ b/src/imagedisplay.c @@ -3,7 +3,7 @@ * * Show raw and processed images * - * (c) 2007 Thomas White <taw27@cam.ac.uk> + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> * * dtr - Diffraction Tomography Reconstruction * @@ -23,6 +23,7 @@ #include "imagedisplay.h" #include "utils.h" +#include "mapping.h" /* Free pixbuf data when reference count drops to zero */ static void imagedisplay_free_data(guchar *image_eightbit, ImageDisplay *imagedisplay) { @@ -167,6 +168,33 @@ void imagedisplay_close(ImageDisplay *imagedisplay) { } } +static void imagedisplay_add_scalebar(ImageDisplay *imagedisplay, GtkWidget *drawingarea, + double scale, double xoffs, double yoffs) { + + PangoLayout *layout; + double sb; + PangoRectangle rect; + int bwidth, bheight; + int view_height = imagedisplay->view_height; + + sb = mapping_scale_bar_length(&imagedisplay->imagerecord); + layout = gtk_widget_create_pango_layout(drawingarea, "1 nm^-1"); + pango_layout_get_pixel_extents(layout, &rect, NULL); + + bwidth = (sb*scale)+20; + bheight = rect.height+30; + if ( rect.width > bwidth ) bwidth = rect.width+20; + gdk_draw_rectangle(drawingarea->window, drawingarea->style->bg_gc[GTK_WIDGET_STATE(drawingarea)], TRUE, + xoffs+20, yoffs+view_height-20-bheight, + bwidth, bheight); + gdk_draw_line(drawingarea->window, imagedisplay->gc_scalebar, + xoffs+30, yoffs+view_height-30, + xoffs+30+(scale*sb), yoffs+view_height-30); + gdk_draw_layout(drawingarea->window, drawingarea->style->fg_gc[GTK_WIDGET_STATE(drawingarea)], + xoffs+30, yoffs+view_height-20-bheight+10, layout); + +} + #define imagedisplay_draw_line(gc,x1,y1,x2,y2) (gdk_draw_line(drawingarea->window,gc, \ xoffs+(x1), yoffs+imagedisplay->view_height-1-(y1), \ xoffs+(x2), yoffs+imagedisplay->view_height-1-(y2))) @@ -181,7 +209,8 @@ static gboolean imagedisplay_redraw(GtkWidget *drawingarea, GdkEventExpose *even yoffs = ((double)imagedisplay->drawingarea_height - imagedisplay->view_height) / 2; scale = (double)imagedisplay->view_width/imagedisplay->imagerecord.width; - gdk_draw_pixbuf(drawingarea->window, drawingarea->style->bg_gc[GTK_WIDGET_STATE(drawingarea)], imagedisplay->pixbuf_scaled, + gdk_draw_pixbuf(drawingarea->window, drawingarea->style->bg_gc[GTK_WIDGET_STATE(drawingarea)], + imagedisplay->pixbuf_scaled, 0, 0, xoffs, yoffs, imagedisplay->view_width, imagedisplay->view_height, GDK_RGB_DITHER_NONE, 0, 0); @@ -201,6 +230,9 @@ static gboolean imagedisplay_redraw(GtkWidget *drawingarea, GdkEventExpose *even * tan(imagedisplay->imagerecord.omega)) * scale); } + /* Add scale bar */ + imagedisplay_add_scalebar(imagedisplay, drawingarea, scale, xoffs, yoffs); + /* NB This calls the function above, which sorts out stuff */ if ( imagedisplay->flags & IMAGEDISPLAY_SHOW_CENTRE ) { imagedisplay_draw_line(imagedisplay->gc_centre, @@ -245,8 +277,9 @@ static gboolean imagedisplay_redraw(GtkWidget *drawingarea, GdkEventExpose *even default : gc = imagedisplay->gc_marks_1; break; } - if ( (cur->type == IMAGEDISPLAY_MARK_CIRCLE_1) || (cur->type == IMAGEDISPLAY_MARK_CIRCLE_2) - || (cur->type == IMAGEDISPLAY_MARK_CIRCLE_3) ) { + if ( (cur->type == IMAGEDISPLAY_MARK_CIRCLE_1) + || (cur->type == IMAGEDISPLAY_MARK_CIRCLE_2) + || (cur->type == IMAGEDISPLAY_MARK_CIRCLE_3) ) { double r; @@ -307,6 +340,11 @@ static gint imagedisplay_realize(GtkWidget *widget, ImageDisplay *imagedisplay) gdk_color_parse("#00ddff", &colour); gdk_gc_set_rgb_fg_color(imagedisplay->gc_marks_3, &colour); + imagedisplay->gc_scalebar = gdk_gc_new(imagedisplay->drawingarea->window); + gdk_color_parse("#000000", &colour); + gdk_gc_set_rgb_fg_color(imagedisplay->gc_scalebar, &colour); + gdk_gc_set_line_attributes(imagedisplay->gc_scalebar, 5, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER); + imagedisplay->realised = TRUE; return 0; @@ -351,10 +389,14 @@ ImageDisplay *imagedisplay_new_nowindow(ImageRecord imagerecord, ImageDisplayFla G_CALLBACK(imagedisplay->mouse_click_func), callback_data); } - g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "realize", G_CALLBACK(imagedisplay_realize), imagedisplay); - g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "destroy", G_CALLBACK(imagedisplay_destroyed), imagedisplay); - g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "configure_event", G_CALLBACK(imagedisplay_configure_event), imagedisplay); - g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "expose-event", G_CALLBACK(imagedisplay_redraw), imagedisplay); + g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "realize", + G_CALLBACK(imagedisplay_realize), imagedisplay); + g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "destroy", + G_CALLBACK(imagedisplay_destroyed), imagedisplay); + g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "configure_event", + G_CALLBACK(imagedisplay_configure_event), imagedisplay); + g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "expose-event", + G_CALLBACK(imagedisplay_redraw), imagedisplay); return imagedisplay; @@ -362,7 +404,8 @@ ImageDisplay *imagedisplay_new_nowindow(ImageRecord imagerecord, ImageDisplayFla /* Display an image */ ImageDisplay *imagedisplay_open_with_message(ImageRecord imagerecord, const char *title, const char *message, - ImageDisplayFlags flags, GCallback mouse_click_func, gpointer callback_data) { + ImageDisplayFlags flags, GCallback mouse_click_func, + gpointer callback_data) { ImageDisplay *imagedisplay; GdkGeometry geom; @@ -375,7 +418,8 @@ ImageDisplay *imagedisplay_open_with_message(ImageRecord imagerecord, const char gtk_window_set_title(GTK_WINDOW(imagedisplay->window), imagedisplay->title); geom.min_width = 128; geom.min_height = 128; - gtk_window_set_geometry_hints(GTK_WINDOW(imagedisplay->window), GTK_WIDGET(imagedisplay->drawingarea), &geom, GDK_HINT_MIN_SIZE); + gtk_window_set_geometry_hints(GTK_WINDOW(imagedisplay->window), GTK_WIDGET(imagedisplay->drawingarea), + &geom, GDK_HINT_MIN_SIZE); gtk_window_set_default_size(GTK_WINDOW(imagedisplay->window), 512, 512); @@ -411,7 +455,8 @@ void imagedisplay_add_mark(ImageDisplay *imagedisplay, double x, double y, Image } -void imagedisplay_add_line(ImageDisplay *imagedisplay, double x1, double y1, double x2, double y2, ImageDisplayMarkType type) { +void imagedisplay_add_line(ImageDisplay *imagedisplay, double x1, double y1, + double x2, double y2, ImageDisplayMarkType type) { ImageDisplayMark *new; @@ -436,6 +481,7 @@ void imagedisplay_add_line(ImageDisplay *imagedisplay, double x1, double y1, dou void imagedisplay_force_redraw(ImageDisplay *imagedisplay) { imagedisplay_rescale(imagedisplay, imagedisplay->drawingarea_width, imagedisplay->drawingarea_height); - gtk_widget_queue_draw_area(imagedisplay->drawingarea, 0, 0, imagedisplay->drawingarea_width, imagedisplay->drawingarea_height); + gtk_widget_queue_draw_area(imagedisplay->drawingarea, 0, 0, imagedisplay->drawingarea_width, + imagedisplay->drawingarea_height); } diff --git a/src/imagedisplay.h b/src/imagedisplay.h index 325ea96..3462a83 100644 --- a/src/imagedisplay.h +++ b/src/imagedisplay.h @@ -3,7 +3,7 @@ * * Show raw and processed images * - * (c) 2007 Thomas White <taw27@cam.ac.uk> + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> * * dtr - Diffraction Tomography Reconstruction * @@ -70,6 +70,7 @@ typedef struct imagedisplay_struct { GdkGC *gc_marks_1; GdkGC *gc_marks_2; GdkGC *gc_marks_3; + GdkGC *gc_scalebar; gboolean realised; unsigned int drawingarea_width; @@ -80,12 +81,20 @@ typedef struct imagedisplay_struct { } ImageDisplay; 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); + ImageDisplayFlags flags, GCallback mouse_click_func, + gpointer callback_data); + extern ImageDisplay *imagedisplay_new_nowindow(ImageRecord imagerecord, ImageDisplayFlags flags, const char *message, - GCallback mouse_click_func, gpointer callback_data); -extern void imagedisplay_add_mark(ImageDisplay *imagedisplay, double x, double y, ImageDisplayMarkType type, double weight); -extern void imagedisplay_add_line(ImageDisplay *imagedisplay, double x1, double y1, double x2, double y2, ImageDisplayMarkType type); + GCallback mouse_click_func, gpointer callback_data); + +extern void imagedisplay_add_mark(ImageDisplay *imagedisplay, double x, double y, ImageDisplayMarkType type, + double weight); + +extern void imagedisplay_add_line(ImageDisplay *imagedisplay, double x1, double y1, + double x2, double y2, 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/mapping.c b/src/mapping.c index c9872f9..4897450 100644 --- a/src/mapping.c +++ b/src/mapping.c @@ -3,7 +3,7 @@ * * 3D Mapping * - * (c) 2007 Thomas White <taw27@cam.ac.uk> + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> * * dtr - Diffraction Tomography Reconstruction * @@ -128,6 +128,20 @@ int mapping_scale(ImageFeature *refl, double *ddx, double *ddy) { } +/* Return the length of a 1 nm^-1 scale bar in the given image (in pixels) + * Result only strictly valid at the centre of the image */ +double mapping_scale_bar_length(ImageRecord *image) { + + switch ( image->fmode ) { + case FORMULATION_PIXELSIZE : return 1.0e9/image->pixel_size; + case FORMULATION_CLEN : return image->camera_len*image->lambda; + default : fprintf(stderr, "Unrecognised formulation mode in mapping_scale_bar_length.\n"); + } + + return 0.0; + +} + void mapping_map_features(ControlContext *ctx) { int i; @@ -146,7 +160,8 @@ void mapping_map_features(ControlContext *ctx) { double nx, ny, nz, twotheta; - if ( !mapping_map_to_space(&ctx->images->images[i].features->features[j], &nx, &ny, &nz, &twotheta) ) { + if ( !mapping_map_to_space(&ctx->images->images[i].features->features[j], + &nx, &ny, &nz, &twotheta) ) { reflection_add(ctx->reflectionlist, nx, ny, nz, ctx->images->images[i].features->features[j].intensity, REFLECTION_NORMAL); } diff --git a/src/mapping.h b/src/mapping.h index 8b23550..82d2f04 100644 --- a/src/mapping.h +++ b/src/mapping.h @@ -3,7 +3,7 @@ * * 3D Mapping * - * (c) 2007 Thomas White <taw27@cam.ac.uk> + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> * * dtr - Diffraction Tomography Reconstruction * @@ -18,10 +18,13 @@ #include "reflections.h" #include "control.h" +#include "image.h" -extern void mapping_rotate(double x, double y, double z, double *ddx, double *ddy, double *ddz, double omega, double tilt); +extern void mapping_rotate(double x, double y, double z, double *ddx, double *ddy, double *ddz, + double omega, double tilt); extern int mapping_map_to_space(ImageFeature *refl, double *ddx, double *ddy, double *ddz, double *twotheta); extern int mapping_scale(ImageFeature *refl, double *ddx, double *ddy); +extern double mapping_scale_bar_length(ImageRecord *image); extern void mapping_adjust_axis(ControlContext *ctx, double offset); extern void mapping_map_features(ControlContext *ctx); diff --git a/src/refine.c b/src/refine.c index 20fc431..5d1b59a 100644 --- a/src/refine.c +++ b/src/refine.c @@ -272,7 +272,8 @@ double refine_do_cell(ControlContext *ctx) { rf->partner->x = old_x; rf->partner->y = old_y; #if REFINE_DEBUG - printf("=> %+10.5f %+10.5f nm^-1\n", dx/DISPFACTOR, dy/DISPFACTOR); + double mod = sqrt(dx*dx + dy*dy)/DISPFACTOR; + printf("=> %+10.5f %+10.5f nm^-1 (length %10.5f nm^1)\n", dx/DISPFACTOR, dy/DISPFACTOR, mod); #endif /* REFINE_DEBUG */ d[f].dx = dx; diff --git a/src/refinetest2d.c b/src/refinetest2d.c index cdc0c8d..1c30348 100644 --- a/src/refinetest2d.c +++ b/src/refinetest2d.c @@ -44,47 +44,47 @@ static int check_cell(Basis *cell, Basis *cell_real) { fail = 0; if ( fabs(cell->a.x - cell_real->a.x) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: ax not determined correctly (got %8f, should be %8f)\n", + fprintf(stderr, "refinetest2d: ax not determined correctly (got %8f, should be %8f)\n", cell->a.x/1e9, cell_real->a.x/1e9); fail = 1; } if ( fabs(cell->a.y - cell_real->a.y) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: ay not determined correctly (got %8f, should be %8f)\n", + fprintf(stderr, "refinetest2d: ay not determined correctly (got %8f, should be %8f)\n", cell->a.y/1e9, cell_real->a.y/1e9); fail = 1; } // if ( fabs(cell->a.z - cell_real->a.z) > 0.01e9 ) { -// fprintf(stderr, "refinetest3d: az not determined correctly (got %8f, should be %8f)\n", +// fprintf(stderr, "refinetest2d: az not determined correctly (got %8f, should be %8f)\n", // cell->a.z/1e9, cell_real->a.z/1e9); // fail = 1; // } if ( fabs(cell->b.x - cell_real->b.x) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: bx not determined correctly (got %8f, should be %8f)\n", + fprintf(stderr, "refinetest2d: bx not determined correctly (got %8f, should be %8f)\n", cell->b.x/1e9, cell_real->b.x/1e9); fail = 1; } if ( fabs(cell->b.y - cell_real->b.y) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: by not determined correctly (got %8f, should be %8f)\n", + fprintf(stderr, "refinetest2d: by not determined correctly (got %8f, should be %8f)\n", cell->b.y/1e9, cell_real->b.y/1e9); fail = 1; } // if ( fabs(cell->b.z - cell_real->b.z) > 0.01e9 ) { -// fprintf(stderr, "refinetest3d: bz not determined correctly (got %8f, should be %8f)\n", +// fprintf(stderr, "refinetest2d: bz not determined correctly (got %8f, should be %8f)\n", // cell->b.z/1e9, cell_real->b.z/1e9); // fail = 1; // } // if ( fabs(cell->c.x - cell_real->c.x) > 0.01e9 ) { -// fprintf(stderr, "refinetest3d: cx not determined correctly (got %8f, should be %8f)\n", +// fprintf(stderr, "refinetest2d: cx not determined correctly (got %8f, should be %8f)\n", // cell->c.x/1e9, cell_real->c.x/1e9); // fail = 1; // } // if ( fabs(cell->c.y - cell_real->c.y) > 0.01e9 ) { -// fprintf(stderr, "refinetest3d: cy not determined correctly (got %8f, should be %8f)\n", +// fprintf(stderr, "refinetest2d: cy not determined correctly (got %8f, should be %8f)\n", // cell->c.y/1e9, cell_real->c.y/1e9); // fail = 1; // } // if ( fabs(cell->c.z - cell_real->c.z) > 0.01e9 ) { -// fprintf(stderr, "refinetest3d: cz not determined correctly (got %8f, should be %8f)\n", +// fprintf(stderr, "refinetest2d: cz not determined correctly (got %8f, should be %8f)\n", // cell->c.z/1e9, cell_real->c.z/1e9); // fail = 1; // } diff --git a/src/refinetest3d.c b/src/refinetest3d1.c index cbe8be2..cd8cc84 100644 --- a/src/refinetest3d.c +++ b/src/refinetest3d1.c @@ -1,5 +1,5 @@ /* - * refinetest3d.c + * refinetest3d1.c * * Unit test for refinement procedure in 3D * @@ -27,13 +27,6 @@ #include "displaywindow.h" #include "mrc.h" -/* Return a random number x, -max < x < +max */ -static double random_plusminus(double max) { - - return max; - -} - static int check_cell(Basis *cell, Basis *cell_real) { int fail; @@ -86,13 +79,6 @@ static int check_cell(Basis *cell, Basis *cell_real) { } else { printf("by is OK.\n"); } - if ( fabs(cell->b.z - cell_real->b.z) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: bz not determined correctly (got %8f, should be %8f)\n", - cell->b.z/1e9, cell_real->b.z/1e9); - fail = 1; - } else { - printf("bz is OK.\n"); - } if ( fabs(cell->c.x - cell_real->c.x) > 0.01e9 ) { fprintf(stderr, "refinetest3d: cx not determined correctly (got %8f, should be %8f)\n", cell->c.x/1e9, cell_real->c.x/1e9); @@ -100,13 +86,6 @@ static int check_cell(Basis *cell, Basis *cell_real) { } else { printf("cx is OK.\n"); } - if ( fabs(cell->c.y - cell_real->c.y) > 0.01e9 ) { - fprintf(stderr, "refinetest3d: cy not determined correctly (got %8f, should be %8f)\n", - cell->c.y/1e9, cell_real->c.y/1e9); - fail = 1; - } else { - printf("cy is OK.\n"); - } if ( fabs(cell->c.z - cell_real->c.z) > 0.01e9 ) { fprintf(stderr, "refinetest3d: cz not determined correctly (got %8f, should be %8f)\n", cell->c.z/1e9, cell_real->c.z/1e9); @@ -115,6 +94,8 @@ static int check_cell(Basis *cell, Basis *cell_real) { printf("cz is OK.\n"); } + printf("bz and cy not checked in this test.\n"); + return fail; } diff --git a/src/refinetest3d2.c b/src/refinetest3d2.c new file mode 100644 index 0000000..38ea72e --- /dev/null +++ b/src/refinetest3d2.c @@ -0,0 +1,191 @@ +/* + * refinetest3d2.c + * + * Unit test for refinement procedure in 3D + * + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> + * + * dtr - Diffraction Tomography Reconstruction + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdlib.h> +#include <math.h> + +#include "basis.h" +#include "reflections.h" +#include "image.h" +#include "reproject.h" +#include "refine.h" +#include "utils.h" +#include "mapping.h" +#include "control.h" +#include "displaywindow.h" +#include "mrc.h" + +static int check_cell(Basis *cell, Basis *cell_real) { + + int fail; + + printf(" Refinement Actual\n"); + printf("---------------------------\n"); + printf("ax %+8f %+8f\n", cell->a.x/1e9, cell_real->a.x/1e9); + printf("ay %+8f %+8f\n", cell->a.y/1e9, cell_real->a.y/1e9); + printf("az %+8f %+8f\n", cell->a.z/1e9, cell_real->a.z/1e9); + printf("bx %+8f %+8f\n", cell->b.x/1e9, cell_real->b.x/1e9); + printf("by %+8f %+8f\n", cell->b.y/1e9, cell_real->b.y/1e9); + printf("bz %+8f %+8f\n", cell->b.z/1e9, cell_real->b.z/1e9); + printf("cx %+8f %+8f\n", cell->c.x/1e9, cell_real->c.x/1e9); + printf("cy %+8f %+8f\n", cell->c.y/1e9, cell_real->c.y/1e9); + printf("cz %+8f %+8f\n", cell->c.z/1e9, cell_real->c.z/1e9); + + fail = 0; + if ( fabs(cell->a.x - cell_real->a.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ax not determined correctly (got %8f, should be %8f)\n", + cell->a.x/1e9, cell_real->a.x/1e9); + fail = 1; + } else { + printf("ax is OK.\n"); + } + if ( fabs(cell->a.y - cell_real->a.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ay not determined correctly (got %8f, should be %8f)\n", + cell->a.y/1e9, cell_real->a.y/1e9); + fail = 1; + } else { + printf("ay is OK.\n"); + } + if ( fabs(cell->a.z - cell_real->a.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: az not determined correctly (got %8f, should be %8f)\n", + cell->a.z/1e9, cell_real->a.z/1e9); + fail = 1; + } else { + printf("az is OK.\n"); + } + if ( fabs(cell->b.x - cell_real->b.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: bx not determined correctly (got %8f, should be %8f)\n", + cell->b.x/1e9, cell_real->b.x/1e9); + fail = 1; + } else { + printf("bx is OK.\n"); + } + if ( fabs(cell->b.y - cell_real->b.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: by not determined correctly (got %8f, should be %8f)\n", + cell->b.y/1e9, cell_real->b.y/1e9); + fail = 1; + } else { + printf("by is OK.\n"); + } + if ( fabs(cell->b.z - cell_real->b.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: bz not determined correctly (got %8f, should be %8f)\n", + cell->b.z/1e9, cell_real->b.z/1e9); + fail = 1; + } else { + printf("bz is OK.\n"); + } + if ( fabs(cell->c.x - cell_real->c.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cx not determined correctly (got %8f, should be %8f)\n", + cell->c.x/1e9, cell_real->c.x/1e9); + fail = 1; + } else { + printf("cx is OK.\n"); + } + if ( fabs(cell->c.y - cell_real->c.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cy not determined correctly (got %8f, should be %8f)\n", + cell->c.y/1e9, cell_real->c.y/1e9); + fail = 1; + } else { + printf("cx is OK.\n"); + } + if ( fabs(cell->c.z - cell_real->c.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cz not determined correctly (got %8f, should be %8f)\n", + cell->c.z/1e9, cell_real->c.z/1e9); + fail = 1; + } else { + printf("cz is OK.\n"); + } + + return fail; + +} + +int main(int argc, char *argv[]) { + + ControlContext *ctx; + ReflectionList *reflections_real; + Basis *cell_real; + int fail; + + ctx = control_ctx_new(); + ctx->omega = deg2rad(0.0); + ctx->lambda = lambda(300.0e3); /* 300 keV */ + ctx->fmode = FORMULATION_PIXELSIZE; + ctx->x_centre = 256; + ctx->y_centre = 256; + ctx->pixel_size = 5e7; + image_add(ctx->images, NULL, 512, 512, deg2rad(00.0), ctx); + ctx->images->images[0].features = image_feature_list_new(); + image_add(ctx->images, NULL, 512, 512, deg2rad(90.0), ctx); + ctx->images->images[1].features = image_feature_list_new(); + ctx->omega = deg2rad(90.0); + image_add(ctx->images, NULL, 512, 512, deg2rad(90.0), ctx); + ctx->images->images[2].features = image_feature_list_new(); + + /* Fudge to avoid horrifying pointer-related death */ + ctx->dw = malloc(sizeof(DisplayWindow)); + ctx->dw->cur_image = 0; + + /* The "true" cell */ + cell_real = malloc(sizeof(Basis)); + cell_real->a.x = 5.0e9; cell_real->a.y = 0.0e9; cell_real->a.z = 0.0e9; + cell_real->b.x = 0.0e9; cell_real->b.y = 5.0e9; cell_real->b.z = 0.0e9; + cell_real->c.x = 0.0e9; cell_real->c.y = 0.0e9; cell_real->c.z = 5.0e9; + /* The "real" reflections */ + reflections_real = reflection_list_from_cell(cell_real); + ctx->images->images[0].features = reproject_get_reflections(&ctx->images->images[0], reflections_real); + ctx->images->images[1].features = reproject_get_reflections(&ctx->images->images[1], reflections_real); + ctx->images->images[2].features = reproject_get_reflections(&ctx->images->images[2], reflections_real); + + /* The "model" cell to be refined */ + ctx->cell = malloc(sizeof(Basis)); + ctx->cell->a.x = 5.0e9; ctx->cell->a.y = 0.1e9; ctx->cell->a.z = 0.1e9; + ctx->cell->b.x = 0.1e9; ctx->cell->b.y = 5.0e9; ctx->cell->b.z = 0.1e9; + ctx->cell->c.x = 0.1e9; ctx->cell->c.y = 0.1e9; ctx->cell->c.z = 5.0e9; + ctx->cell_lattice = reflection_list_from_cell(ctx->cell); + ctx->images->images[0].rflist = reproject_get_reflections(&ctx->images->images[0], ctx->cell_lattice); + reproject_partner_features(ctx->images->images[0].rflist, &ctx->images->images[0]); + ctx->images->images[1].rflist = reproject_get_reflections(&ctx->images->images[1], ctx->cell_lattice); + reproject_partner_features(ctx->images->images[1].rflist, &ctx->images->images[1]); + ctx->images->images[2].rflist = reproject_get_reflections(&ctx->images->images[2], ctx->cell_lattice); + reproject_partner_features(ctx->images->images[2].rflist, &ctx->images->images[2]); + + refine_do_cell(ctx); + image_feature_list_free(ctx->images->images[0].rflist); + image_feature_list_free(ctx->images->images[1].rflist); + image_feature_list_free(ctx->images->images[2].rflist); + + fail = check_cell(ctx->cell, cell_real); + + free(ctx); + + if ( fail ) return 1; + + printf("\n3D refinement test OK.\n"); + + return 0; + +} + +/* Dummy function stubs */ +#include "gtk-valuegraph.h" +void displaywindow_update_imagestack(DisplayWindow *dw) { }; +void displaywindow_enable_cell_functions(DisplayWindow *dw, gboolean g) { }; +void displaywindow_update(DisplayWindow *dw) { }; +void displaywindow_error(const char *msg, DisplayWindow *dw) { }; +guint gtk_value_graph_get_type() { return 0; }; +GtkWidget *gtk_value_graph_new() { return NULL; }; +void gtk_value_graph_set_data(GtkValueGraph *vg, double *data, unsigned int n) { }; + diff --git a/src/refinetest3d3.c b/src/refinetest3d3.c new file mode 100644 index 0000000..de8a792 --- /dev/null +++ b/src/refinetest3d3.c @@ -0,0 +1,187 @@ +/* + * refinetest3d3.c + * + * Unit test for refinement procedure in 3D + * + * (c) 2007-2008 Thomas White <taw27@cam.ac.uk> + * + * dtr - Diffraction Tomography Reconstruction + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdlib.h> +#include <math.h> + +#include "basis.h" +#include "reflections.h" +#include "image.h" +#include "reproject.h" +#include "refine.h" +#include "utils.h" +#include "mapping.h" +#include "control.h" +#include "displaywindow.h" +#include "mrc.h" + +static int check_cell(Basis *cell, Basis *cell_real) { + + int fail; + + printf(" Refinement Actual\n"); + printf("---------------------------\n"); + printf("ax %+8f %+8f\n", cell->a.x/1e9, cell_real->a.x/1e9); + printf("ay %+8f %+8f\n", cell->a.y/1e9, cell_real->a.y/1e9); + printf("az %+8f %+8f\n", cell->a.z/1e9, cell_real->a.z/1e9); + printf("bx %+8f %+8f\n", cell->b.x/1e9, cell_real->b.x/1e9); + printf("by %+8f %+8f\n", cell->b.y/1e9, cell_real->b.y/1e9); + printf("bz %+8f %+8f\n", cell->b.z/1e9, cell_real->b.z/1e9); + printf("cx %+8f %+8f\n", cell->c.x/1e9, cell_real->c.x/1e9); + printf("cy %+8f %+8f\n", cell->c.y/1e9, cell_real->c.y/1e9); + printf("cz %+8f %+8f\n", cell->c.z/1e9, cell_real->c.z/1e9); + + fail = 0; + if ( fabs(cell->a.x - cell_real->a.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ax not determined correctly (got %8f, should be %8f)\n", + cell->a.x/1e9, cell_real->a.x/1e9); + fail = 1; + } else { + printf("ax is OK.\n"); + } + if ( fabs(cell->a.y - cell_real->a.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: ay not determined correctly (got %8f, should be %8f)\n", + cell->a.y/1e9, cell_real->a.y/1e9); + fail = 1; + } else { + printf("ay is OK.\n"); + } + if ( fabs(cell->a.z - cell_real->a.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: az not determined correctly (got %8f, should be %8f)\n", + cell->a.z/1e9, cell_real->a.z/1e9); + fail = 1; + } else { + printf("az is OK.\n"); + } + if ( fabs(cell->b.x - cell_real->b.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: bx not determined correctly (got %8f, should be %8f)\n", + cell->b.x/1e9, cell_real->b.x/1e9); + fail = 1; + } else { + printf("bx is OK.\n"); + } + if ( fabs(cell->b.y - cell_real->b.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: by not determined correctly (got %8f, should be %8f)\n", + cell->b.y/1e9, cell_real->b.y/1e9); + fail = 1; + } else { + printf("by is OK.\n"); + } + if ( fabs(cell->b.z - cell_real->b.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: bz not determined correctly (got %8f, should be %8f)\n", + cell->b.z/1e9, cell_real->b.z/1e9); + fail = 1; + } else { + printf("bz is OK.\n"); + } + if ( fabs(cell->c.x - cell_real->c.x) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cx not determined correctly (got %8f, should be %8f)\n", + cell->c.x/1e9, cell_real->c.x/1e9); + fail = 1; + } else { + printf("cx is OK.\n"); + } + if ( fabs(cell->c.y - cell_real->c.y) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cy not determined correctly (got %8f, should be %8f)\n", + cell->c.y/1e9, cell_real->c.y/1e9); + fail = 1; + } else { + printf("cx is OK.\n"); + } + if ( fabs(cell->c.z - cell_real->c.z) > 0.01e9 ) { + fprintf(stderr, "refinetest3d: cz not determined correctly (got %8f, should be %8f)\n", + cell->c.z/1e9, cell_real->c.z/1e9); + fail = 1; + } else { + printf("cz is OK.\n"); + } + + return fail; + +} + +int main(int argc, char *argv[]) { + + ControlContext *ctx; + ReflectionList *reflections_real; + Basis *cell_real; + int fail; + int i; + + ctx = control_ctx_new(); + ctx->omega = deg2rad(45.0); + ctx->lambda = lambda(300.0e3); /* 300 keV */ + ctx->fmode = FORMULATION_PIXELSIZE; + ctx->x_centre = 256; + ctx->y_centre = 256; + ctx->pixel_size = 5e7; + for ( i=0; i<=90; i++ ) { + image_add(ctx->images, NULL, 512, 512, deg2rad(i), ctx); + ctx->images->images[i].features = image_feature_list_new(); + } + + /* Fudge to avoid horrifying pointer-related death */ + ctx->dw = malloc(sizeof(DisplayWindow)); + ctx->dw->cur_image = 0; + + /* The "true" cell */ + cell_real = malloc(sizeof(Basis)); + cell_real->a.x = 5.0e9; cell_real->a.y = 0.0e9; cell_real->a.z = 0.0e9; + cell_real->b.x = 0.0e9; cell_real->b.y = 5.0e9; cell_real->b.z = 0.0e9; + cell_real->c.x = 0.0e9; cell_real->c.y = 0.0e9; cell_real->c.z = 5.0e9; + /* The "real" reflections */ + reflections_real = reflection_list_from_cell(cell_real); + for ( i=0; i<=90; i++ ) { + ctx->images->images[i].features = reproject_get_reflections(&ctx->images->images[i], reflections_real); + } + + /* The "model" cell to be refined */ + ctx->cell = malloc(sizeof(Basis)); + ctx->cell->a.x = 5.0e9; ctx->cell->a.y = 0.1e9; ctx->cell->a.z = 0.1e9; + ctx->cell->b.x = 0.1e9; ctx->cell->b.y = 5.0e9; ctx->cell->b.z = 0.1e9; + ctx->cell->c.x = 0.1e9; ctx->cell->c.y = 0.1e9; ctx->cell->c.z = 5.0e9; + ctx->cell_lattice = reflection_list_from_cell(ctx->cell); + for ( i=0; i<ctx->images->n_images; i++ ) { + ctx->images->images[i].rflist = reproject_get_reflections(&ctx->images->images[i], ctx->cell_lattice); + reproject_partner_features(ctx->images->images[i].rflist, &ctx->images->images[i]); + } + + refine_do_cell(ctx); + for ( i=0; i<ctx->images->n_images; i++ ) { + image_feature_list_free(ctx->images->images[i].rflist); + } + + fail = check_cell(ctx->cell, cell_real); + + free(ctx); + + if ( fail ) return 1; + + printf("\n3D refinement test OK.\n"); + + return 0; + +} + +/* Dummy function stubs */ +#include "gtk-valuegraph.h" +void displaywindow_update_imagestack(DisplayWindow *dw) { }; +void displaywindow_enable_cell_functions(DisplayWindow *dw, gboolean g) { }; +void displaywindow_update(DisplayWindow *dw) { }; +void displaywindow_error(const char *msg, DisplayWindow *dw) { }; +guint gtk_value_graph_get_type() { return 0; }; +GtkWidget *gtk_value_graph_new() { return NULL; }; +void gtk_value_graph_set_data(GtkValueGraph *vg, double *data, unsigned int n) { }; + |