aboutsummaryrefslogtreecommitdiff
path: root/src/dw-hdfsee.c
diff options
context:
space:
mode:
authorValerio Mariani <valerio.mariani@desy.de>2014-05-09 11:02:17 +0200
committerThomas White <taw@physics.org>2014-09-05 18:12:38 +0200
commit45492b842c3af2af542256417a8bab5bbc7bd5f7 (patch)
tree53fc320ad0734940c5a3fe2d075ae7417787432a /src/dw-hdfsee.c
parentae9fa9e6bfd1ed98a2b146d2e228c69a9cd651cc (diff)
Multi-event mode
Diffstat (limited to 'src/dw-hdfsee.c')
-rw-r--r--src/dw-hdfsee.c344
1 files changed, 216 insertions, 128 deletions
diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c
index 399436c0..6b49d3f7 100644
--- a/src/dw-hdfsee.c
+++ b/src/dw-hdfsee.c
@@ -9,9 +9,9 @@
*
* Authors:
* 2009-2013 Thomas White <taw@physics.org>
- * 2012 Richard Kirian
* 2014 Valerio Mariani
* 2014 Takanori Nakane
+ * 2012 Richard Kirian
*
* This file is part of CrystFEL.
*
@@ -50,6 +50,7 @@
#include "hdfsee.h"
#include "utils.h"
#include "filters.h"
+#include "events.h"
static void displaywindow_error(DisplayWindow *dw, const char *message)
@@ -72,6 +73,10 @@ static void displaywindow_error(DisplayWindow *dw, const char *message)
static gint displaywindow_closed(GtkWidget *window, DisplayWindow *dw)
{
+ if ( dw->hdfile != NULL ) {
+ hdfile_close(dw->hdfile);
+ }
+
if ( dw->surf != NULL ) cairo_surface_destroy(dw->surf);
if ( dw->pixbufs != NULL ) {
@@ -87,6 +92,7 @@ static gint displaywindow_closed(GtkWidget *window, DisplayWindow *dw)
}
if ( dw->image != NULL ) {
+
free(dw->image->filename);
free(dw->image->data);
free(dw->image->flags);
@@ -371,6 +377,10 @@ static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw)
draw_panel_rectangle(cr, &basic_m, dw, i);
cairo_fill(cr);
+ if ( dw->calib_mode && dw->calib_mode_show_focus ) {
+ maybe_draw_focus(dw, cr, i, &basic_m);
+ }
+
}
}
@@ -558,6 +568,7 @@ static void update_colscale(DisplayWindow *dw)
static void displaywindow_update(DisplayWindow *dw)
{
+
set_window_size(dw);
update_colscale(dw);
@@ -696,6 +707,10 @@ static gint displaywindow_set_binning(GtkWidget *widget, DisplayWindow *dw)
return 0;
}
+ if ( dw->hdfile == NULL ) {
+ return 0;
+ }
+
bd = malloc(sizeof(BinningDialog));
if ( bd == NULL ) return 0;
dw->binning_dialog = bd;
@@ -820,6 +835,10 @@ static gint displaywindow_set_boostint(GtkWidget *widget, DisplayWindow *dw)
return 0;
}
+ if ( dw->hdfile == NULL ) {
+ return 0;
+ }
+
bd = malloc(sizeof(BoostIntDialog));
if ( bd == NULL ) return 0;
dw->boostint_dialog = bd;
@@ -931,6 +950,10 @@ static gint displaywindow_set_ringradius(GtkWidget *widget, DisplayWindow *dw)
return 0;
}
+ if ( dw->hdfile == NULL ) {
+ return 0;
+ }
+
rd = malloc(sizeof(RingRadiusDialog));
if ( rd == NULL ) return 0;
dw->ringradius_dialog = rd;
@@ -1099,46 +1122,6 @@ static gint displaywindow_about(GtkWidget *widget, DisplayWindow *dw)
}
-//static int load_geometry_file(DisplayWindow *dw, struct image *image,
-// const char *filename)
-//{
-// struct detector *geom;
-// GtkWidget *w;
-// int using_loaded = 0;
-// if ( dw->image->det == dw->loaded_geom ) using_loaded = 1;
-
-// geom = get_detector_geometry(filename);
-// if ( geom == NULL ) {
-// displaywindow_error(dw, "Failed to load geometry file");
-// return -1;
-// }
-// fill_in_values(geom, dw->hdfile);
-
-// if ( (1+geom->max_fs != dw->image->width)
-// || (1+geom->max_ss != dw->image->height) ) {
-
-// displaywindow_error(dw, "Geometry doesn't match image.");
-// return -1;
-
-// }
-
-// /* Sort out the mess */
-// if ( dw->loaded_geom != NULL ) free_detector_geometry(dw->loaded_geom);
-// dw->loaded_geom = geom;
-// if ( using_loaded ) {
-// dw->image->det = dw->loaded_geom;
-// }
-
-// w = gtk_ui_manager_get_widget(dw->ui,
-// "/ui/displaywindow/view/usegeom");
-// gtk_widget_set_sensitive(GTK_WIDGET(w), TRUE);
-// gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), TRUE);
-// dw->use_geom = 1;
-
-// return 0;
-//}
-
-
static int save_geometry_file(DisplayWindow *dw)
{
GtkWidget *d;
@@ -1161,47 +1144,6 @@ static int save_geometry_file(DisplayWindow *dw)
}
-//static gint displaywindow_loadgeom_response(GtkWidget *d, gint response,
-// DisplayWindow *dw)
-//{
-// if ( response == GTK_RESPONSE_ACCEPT ) {
-
-// char *filename;
-
-// filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
-
-// if ( load_geometry_file(dw, dw->image, filename) == 0 ) {
-// displaywindow_update(dw);
-// }
-
-// g_free(filename);
-
-// }
-
-// gtk_widget_destroy(d);
-
-// return 0;
-//}
-
-
-//static gint displaywindow_load_geom(GtkWidget *widget, DisplayWindow *dw)
-//{
-// GtkWidget *d;
-
-// d = gtk_file_chooser_dialog_new("Load Geometry File",
-// GTK_WINDOW(dw->window),
-// GTK_FILE_CHOOSER_ACTION_OPEN,
-// GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-// GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
-// NULL);
-
-// g_signal_connect(G_OBJECT(d), "response",
-// G_CALLBACK(displaywindow_loadgeom_response), dw);
-
-// gtk_widget_show_all(d);
-
-// return 0;
-//}
static gint displaywindow_peak_overlay(GtkWidget *widget, DisplayWindow *dw)
{
GtkWidget *d;
@@ -1222,26 +1164,6 @@ static gint displaywindow_peak_overlay(GtkWidget *widget, DisplayWindow *dw)
}
-//static gint displaywindow_set_usegeom(GtkWidget *d, DisplayWindow *dw)
-//{
-// GtkWidget *w;
-
-// /* Get new value */
-// w = gtk_ui_manager_get_widget(dw->ui,
-// "/ui/displaywindow/view/usegeom");
-// dw->use_geom = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w));
-
-// if ( dw->use_geom ) {
-// dw->image->det = dw->loaded_geom;
-// } else {
-// dw->image->det = dw->simple_geom;
-// }
-
-// displaywindow_update(dw);
-
-// return 0;
-//}
-
static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw)
{
GtkWidget *w, *vbox;
@@ -1249,7 +1171,7 @@ static gint displaywindow_set_calibmode(GtkWidget *d, DisplayWindow *dw)
w = gtk_ui_manager_get_widget(dw->ui,
"/ui/displaywindow/tools/calibmode");
- if ( !dw->use_geom ) {
+ if ( dw->image->det == dw->simple_geom ) {
gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(w), 0);
return 0;
}
@@ -1475,6 +1397,10 @@ static gint displaywindow_show_numbers(GtkWidget *widget, DisplayWindow *dw)
return 0;
}
+ if ( dw->hdfile == NULL ) {
+ return 0;
+ }
+
nw = malloc(sizeof(struct numberswindow));
if ( nw == NULL ) return 0;
dw->numbers_window = nw;
@@ -1684,6 +1610,8 @@ static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox,
{ "PeaksAction", NULL, "Load Feature List...", NULL, NULL,
G_CALLBACK(displaywindow_peak_overlay) },
+ { "EventsAction", NULL, "_Events", NULL, NULL, NULL },
+
{ "HelpAction", NULL, "_Help", NULL, NULL, NULL },
{ "AboutAction", GTK_STOCK_ABOUT, "_About hdfsee...",
NULL, NULL,
@@ -1695,6 +1623,8 @@ static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox,
GtkToggleActionEntry toggles[] = {
{ "ColScaleAction", NULL, "Colour Scale", NULL, NULL,
G_CALLBACK(displaywindow_set_colscale), FALSE },
+ { "CalibModeAction", NULL, "Calibration Mode", NULL, NULL,
+ G_CALLBACK(displaywindow_set_calibmode), FALSE },
{ "RingsAction", NULL, "Resolution Rings", "F9", NULL,
G_CALLBACK(displaywindow_set_rings), dw->show_rings },
{ "ShowPeaksAction", NULL, "Features", "F8", NULL,
@@ -1748,14 +1678,13 @@ static void do_filters(DisplayWindow *dw)
}
}
-
struct newhdf {
DisplayWindow *dw;
GtkWidget *widget;
char name[1024];
};
-static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh, const char *filename)
+static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh)
{
gboolean a;
int fail;
@@ -1764,12 +1693,16 @@ static gint displaywindow_newhdf(GtkMenuItem *item, struct newhdf *nh, const cha
a = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(nh->widget));
if ( !a ) return 0;
- fail = hdf5_read2(filename, nh->dw->image, nh->name, 0, 1);
+
+ fail = hdf5_read(nh->dw->hdfile, nh->dw->image, nh->name, 0);
if ( fail ) {
ERROR("Couldn't load image");
return 1;
}
+ nh->dw->simple_geom = simple_geometry(nh->dw->image);
+ nh->dw->image->det = nh->dw->simple_geom;
+
do_filters(nh->dw);
displaywindow_update(nh->dw);
return 0;
@@ -1804,7 +1737,7 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
item = gtk_menu_item_new_with_label(names[i]);
sub = displaywindow_addhdfgroup(hdfile, names[i],
- dw, rgp, selectme);
+ dw, rgp, selectme);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), sub);
} else if ( is_image[i] ) {
@@ -1820,7 +1753,7 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
nh->dw = dw;
nh->widget = item;
g_signal_connect(G_OBJECT(item), "toggled",
- G_CALLBACK(displaywindow_newhdf), nh);
+ G_CALLBACK(displaywindow_newhdf), nh);
}
if ( (selectme != NULL)
@@ -1832,8 +1765,7 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
GTK_CHECK_MENU_ITEM(item), FALSE);
}
- *rgp = gtk_radio_menu_item_get_group(
- GTK_RADIO_MENU_ITEM(item));
+ *rgp = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item));
} else {
@@ -1842,7 +1774,7 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
item = gtk_menu_item_new_with_label(names[i]);
if ( hdfile_is_scalar(hdfile, names[i], 0) ) {
- tmp = hdfile_get_string_value(hdfile, names[i]);
+ tmp = hdfile_get_string_value(hdfile, names[i], NULL);
} else {
tmp = NULL;
}
@@ -1865,7 +1797,6 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
free(names[i]);
-
}
free(is_group);
@@ -1875,30 +1806,32 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile,
}
-static GtkWidget *displaywindow_createhdfmenus(const char *filename,
+static GtkWidget *displaywindow_createhdfmenus(struct hdfile *hdfile,
DisplayWindow *dw,
const char *selectme)
{
GSList *rg = NULL;
GtkWidget *w;
- struct hdfile *hdfile;
- hdfile = hdfile_open(filename);
- if ( hdfile == NULL ) {
- return NULL;
- }
w = displaywindow_addhdfgroup(hdfile, "/", dw, &rg, selectme);
- hdfile_close(hdfile);
+
return w;
}
-static int displaywindow_update_menus(DisplayWindow *dw, const char * filename, const char *selectme)
+struct newev {
+ DisplayWindow *dw;
+ GtkWidget *widget;
+ int new_ev;
+};
+
+
+static int displaywindow_update_menus(DisplayWindow *dw, const char *selectme)
{
GtkWidget *ms;
GtkWidget *w;
- ms = displaywindow_createhdfmenus(filename , dw, selectme);
+ ms = displaywindow_createhdfmenus(dw->hdfile, dw, selectme);
if ( ms == NULL ) return 1;
@@ -1912,6 +1845,91 @@ static int displaywindow_update_menus(DisplayWindow *dw, const char * filename,
}
+static gint displaywindow_newevent(GtkMenuItem *item, struct newev *ne)
+{
+ gboolean a;
+ int fail;
+
+ if ( ne->dw->not_ready_yet ) return 0;
+
+ a = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(ne->widget));
+ if ( !a ) return 0;
+
+ fail = hdf5_read2(ne->dw->hdfile, ne->dw->image,
+ ne->dw->ev_list->events[ne->new_ev], 0);
+ if ( fail ) {
+ ERROR("Couldn't load image");
+ return 1;
+ }
+
+ ne->dw->curr_event = ne->new_ev;
+
+ do_filters(ne->dw);
+ displaywindow_update(ne->dw);
+ return 0;
+}
+
+
+static int displaywindow_update_event_menu(DisplayWindow *dw,
+ struct event_list *ev_list,
+ int curr_event)
+{
+
+ int ei;
+ GtkWidget *w;
+ GtkWidget *ww;
+ GSList *grp = NULL;
+
+ w = gtk_ui_manager_get_widget(dw->ui,
+ "/ui/displaywindow/events");
+
+ ww = gtk_menu_new();
+
+ for ( ei=0; ei< ev_list->num_events; ei++ ) {
+
+ GtkWidget *www;
+ struct newev *ne;
+ char *ev_string;
+
+ ev_string = get_event_string(ev_list->events[ei]);
+ www = gtk_radio_menu_item_new_with_label(grp, ev_string);
+ free(ev_string);
+
+ ne = malloc(sizeof(struct newev));
+ if ( ne != NULL ) {
+
+ ne->widget = www;
+ ne->dw = dw;
+ ne->new_ev = ei;
+
+ g_signal_connect(G_OBJECT(www), "toggled",
+ G_CALLBACK(displaywindow_newevent), ne);
+
+ }
+
+ if ( ei == dw->curr_event ) {
+ gtk_check_menu_item_set_active(
+ GTK_CHECK_MENU_ITEM(www), TRUE);
+ } else {
+ gtk_check_menu_item_set_active(
+ GTK_CHECK_MENU_ITEM(www), FALSE);
+ }
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(ww), www);
+
+ grp = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(www));
+
+ }
+
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(w), ww);
+ gtk_widget_show_all(w);
+
+ return 0;
+
+}
+
+
+
static gint displaywindow_release(GtkWidget *widget, GdkEventButton *event,
DisplayWindow *dw)
{
@@ -2360,10 +2378,11 @@ static gint displaywindow_keypress(GtkWidget *widget, GdkEventKey *event,
}
-DisplayWindow *displaywindow_open(const char *filename, const char *peaks,
+DisplayWindow *displaywindow_open(char *filename, const char *peaks,
double boost, int binning,
int noisefilter, int calibmode, int colscale,
- const char *element, const char *geometry,
+ const char *element,
+ struct detector *det_geom,
const char *beam,
int show_rings, double *ring_radii,
int n_rings, double ring_size,
@@ -2374,6 +2393,7 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks,
GtkWidget *vbox;
int check;
GtkWidget *w;
+ GtkWidget *ww;
dw = calloc(1, sizeof(DisplayWindow));
if ( dw == NULL ) return NULL;
@@ -2385,6 +2405,7 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks,
dw->boostint = 1;
dw->motion_callback = 0;
dw->numbers_window = NULL;
+ dw->simple_geom = NULL;
dw->image = NULL;
dw->show_rings = show_rings;
dw->show_peaks = 0;
@@ -2404,6 +2425,9 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks,
dw->calib_mode_curr_p = NULL;
dw->calib_mode_show_focus = 1;
dw->statusbar = NULL;
+ dw->multi_event = 0;
+ dw->curr_event = 0;
+ dw->ev_list = NULL;
if ( beam != NULL ) {
dw->image->beam = get_beam_parameters(beam);
@@ -2411,15 +2435,65 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks,
dw->image->det = det_geom;
- check = hdf5_read(filename, dw->image, element, 0);
+ dw->hdfile = hdfile_open(filename);
+ if ( dw->hdfile == NULL ) {
+ ERROR("Couldn't open file: %s\n", filename);
+ free(dw);
+ return NULL;
+ }
+
+ if ( dw->image->det != NULL && ( dw->image->det->path_dim != 0 ||
+ dw->image->det->dim_dim != 0 )) {
+
+ dw->multi_event = 1;
+
+ dw->ev_list = fill_event_list(dw->hdfile, dw->image->det);
+
+ if ( dw->ev_list == NULL ) {
+ ERROR("Error while parsing file structure\n");
+ free_event_list(dw->ev_list);
+ free(dw);
+ return NULL;
+ }
+ if ( dw->ev_list->num_events == 0 ) {
+ ERROR("Multi-event geometry file but no events found in data file");
+ free_event_list(dw->ev_list);
+ free(dw);
+ return NULL;
+ } else {
+ dw->curr_event = 0;
+ }
+
+ }
+
+ if ( dw->image->det != NULL ) {
+
+ if ( dw->multi_event ) {
+ check = hdf5_read2(dw->hdfile, dw->image,
+ dw->ev_list->events[dw->curr_event], 0);
+ } else {
+ check = hdf5_read2(dw->hdfile, dw->image, NULL, 0);
+ }
+
+ } else {
+ check = hdf5_read(dw->hdfile, dw->image, element, 0);
+ }
if (check) {
ERROR("Couldn't load file\n");
free(dw);
+ hdfile_close(dw->hdfile);
return NULL;
}
+ dw->image->filename = strdup(filename);
+
+ if ( dw->image->det == NULL ) {
+ dw->simple_geom = simple_geometry(dw->image);
+ dw->image->det = dw->simple_geom;
+ }
+
/* Filters need geometry */
- do_filters(dw);
+ do_filters(dw);
/* Peak list provided at startup? */
if ( peaks != NULL ) {
@@ -2458,12 +2532,19 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks,
gtk_widget_show_all(dw->window);
w = gtk_ui_manager_get_widget(dw->ui,
- "/ui/displaywindow/view/images");
+ "/ui/displaywindow/view/images");
- if ( !single_panel_data_source(dw->image->det, element) ) {
+ if ( dw->image->det != dw->simple_geom ) {
gtk_widget_set_sensitive(GTK_WIDGET(w), FALSE);
}
+ ww = gtk_ui_manager_get_widget(dw->ui,
+ "/ui/displaywindow/events");
+
+ if ( dw->image->det == dw->simple_geom || dw->multi_event == 0) {
+ gtk_widget_set_sensitive(GTK_WIDGET(ww), FALSE);
+ }
+
displaywindow_update(dw);
gtk_widget_add_events(GTK_WIDGET(dw->drawingarea),
@@ -2482,7 +2563,14 @@ DisplayWindow *displaywindow_open(const char *filename, const char *peaks,
g_signal_connect(GTK_OBJECT(dw->drawingarea), "key-press-event",
G_CALLBACK(displaywindow_keypress), dw);
- displaywindow_update_menus(dw, filename, element);
+ if ( dw->image->det == dw->simple_geom ) {
+ displaywindow_update_menus(dw, element);
+ } else {
+ if ( dw->multi_event != 0 ) {
+ displaywindow_update_event_menu(dw, dw->ev_list, dw->curr_event);
+ }
+ }
+
dw->not_ready_yet = 0;
return dw;