aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crystfel_gui.c84
-rw-r--r--src/crystfelimageview.c108
-rw-r--r--src/crystfelimageview.h25
-rw-r--r--src/gui_peaksearch.c45
-rw-r--r--src/gui_project.c1
-rw-r--r--src/gui_project.h1
6 files changed, 79 insertions, 185 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index 45934f24..ec300072 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -115,13 +115,12 @@ static void update_imageview(struct crystfelproject *proj)
char tmp[1024];
char *ev_str;
char *ev_sep;
+ struct image *image;
if ( proj->n_frames == 0 ) return;
if ( proj->stream != NULL ) {
- struct image *image;
-
if ( stream_select_chunk(proj->stream,
proj->cur_frame) )
{
@@ -141,47 +140,41 @@ static void update_imageview(struct crystfelproject *proj)
return;
}
- if ( image->ev != NULL ) {
- ev_str = image->ev;
- ev_sep = " ";
- } else {
- ev_str = "";
- ev_sep = "";
- }
- snprintf(tmp, 1023, "%s%s%s (frame %i of %i)",
- image->filename,
- ev_sep,
- ev_str,
- proj->cur_frame+1,
- proj->n_frames);
- gtk_label_set_text(GTK_LABEL(proj->image_info), tmp);
- crystfel_image_view_set_image(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- image->filename,
- image->ev);
-
- image_free(image);
-
} else {
- if ( proj->events[proj->cur_frame] != NULL ) {
- ev_str = proj->events[proj->cur_frame];
- ev_sep = " ";
- } else {
- ev_str = "";
- ev_sep = "";
+ image = image_read(proj->dtempl,
+ proj->filenames[proj->cur_frame],
+ proj->events[proj->cur_frame]);
+
+ if ( image == NULL ) {
+ ERROR("Failed to load image\n");
+ return;
}
- snprintf(tmp, 1023, "%s%s%s (frame %i of %i)",
- proj->filenames[proj->cur_frame],
- ev_sep,
- ev_str,
- proj->cur_frame+1,
- proj->n_frames);
- gtk_label_set_text(GTK_LABEL(proj->image_info), tmp);
- crystfel_image_view_set_image(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- proj->filenames[proj->cur_frame],
- proj->events[proj->cur_frame]);
}
+
+ /* Give CrystFELImageView a chance to free resources */
+ crystfel_image_view_set_image(CRYSTFEL_IMAGE_VIEW(proj->imageview),
+ NULL);
+ image_free(proj->cur_image);
+ proj->cur_image = image;
+
+ if ( proj->cur_image->ev != NULL ) {
+ ev_str = proj->cur_image->ev;
+ ev_sep = " ";
+ } else {
+ ev_str = "";
+ ev_sep = "";
+ }
+ snprintf(tmp, 1023, "%s%s%s (frame %i of %i)",
+ proj->cur_image->filename,
+ ev_sep,
+ ev_str,
+ proj->cur_frame+1,
+ proj->n_frames);
+ gtk_label_set_text(GTK_LABEL(proj->image_info), tmp);
+ crystfel_image_view_set_image(CRYSTFEL_IMAGE_VIEW(proj->imageview),
+ proj->cur_image);
}
@@ -301,9 +294,7 @@ static void finddata_response_sig(GtkWidget *dialog, gint resp,
/* Totally clean up the old list */
clear_project_files(proj);
crystfel_image_view_set_image(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- NULL, NULL);
- crystfel_image_view_set_datatemplate(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- NULL);
+ NULL);
g_free(proj->geom_filename);
proj->geom_filename = geom_filename;
@@ -314,9 +305,6 @@ static void finddata_response_sig(GtkWidget *dialog, gint resp,
g_free(proj->data_top_folder);
proj->data_top_folder = g_file_get_path(top);
- crystfel_image_view_set_datatemplate(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- proj->dtempl);
-
add_files(proj, top, proj->data_search_pattern,
proj->dtempl);
@@ -351,17 +339,13 @@ static void finddata_response_sig(GtkWidget *dialog, gint resp,
clear_project_files(proj);
crystfel_image_view_set_image(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- NULL, NULL);
- crystfel_image_view_set_datatemplate(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- NULL);
+ NULL);
stream_close(proj->stream);
proj->stream = st;
data_template_free(proj->dtempl);
proj->dtempl = dtempl;
- crystfel_image_view_set_datatemplate(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- proj->dtempl);
/* Set some defaults for things we won't be using */
g_free(proj->geom_filename);
@@ -889,8 +873,6 @@ int main(int argc, char *argv[])
if ( proj.geom_filename != NULL ) {
dtempl = data_template_new_from_file(proj.geom_filename);
if ( dtempl != NULL ) {
- crystfel_image_view_set_datatemplate(CRYSTFEL_IMAGE_VIEW(proj.imageview),
- dtempl);
proj.dtempl = dtempl;
}
}
diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c
index f36f0478..45a0bf96 100644
--- a/src/crystfelimageview.c
+++ b/src/crystfelimageview.c
@@ -45,9 +45,6 @@
#include "crystfelimageview.h"
-static int rerender_image(CrystFELImageView *iv);
-
-
static void scroll_interface_init(GtkScrollable *iface)
{
}
@@ -89,8 +86,6 @@ static void cleanup_image(CrystFELImageView *iv)
}
free(iv->pixbufs);
- image_free(iv->image);
-
iv->image = NULL;
iv->pixbufs = NULL;
}
@@ -99,8 +94,6 @@ static void cleanup_image(CrystFELImageView *iv)
static gint destroy_sig(GtkWidget *window, CrystFELImageView *iv)
{
cleanup_image(iv);
- free(iv->filename);
- free(iv->event);
return FALSE;
}
@@ -417,7 +410,6 @@ static void draw_peaks(cairo_t *cr, CrystFELImageView *iv,
static gint draw_sig(GtkWidget *window, cairo_t *cr, CrystFELImageView *iv)
{
- int i;
cairo_matrix_t m;
cairo_save(cr);
@@ -444,12 +436,8 @@ static gint draw_sig(GtkWidget *window, cairo_t *cr, CrystFELImageView *iv)
}
}
- for ( i=0; i<iv->num_peaklists; i++ ){
- if ( (iv->peaklists[i] != NULL)
- && (iv->image != NULL) )
- {
- draw_peaks(cr, iv , iv->peaklists[i]);
- }
+ if ( iv->show_peaks ) {
+ draw_peaks(cr, iv, iv->image->features);
}
cairo_restore(cr);
@@ -592,11 +580,8 @@ GtkWidget *crystfel_image_view_new()
iv->detector_w = 1.0;
iv->detector_h = 1.0;
iv->zoom = -1.0;
- iv->filename = NULL;
- iv->event = NULL;
iv->image = NULL;
- iv->num_peaklists = 0;
- iv->peaklists = NULL;
+ iv->show_peaks = 0;
iv->brightness = 1.0;
iv->pixbufs = NULL;
@@ -761,23 +746,6 @@ static double auto_scale_top(const struct image *image)
}
-static int reload_image(CrystFELImageView *iv)
-{
- if ( iv->dtempl == NULL ) return 0;
- if ( iv->filename == NULL ) return 0;
-
- cleanup_image(iv);
-
- iv->image = image_read(iv->dtempl, iv->filename, iv->event);
- if ( iv->image == NULL ) {
- ERROR("Failed to load image\n");
- return 1;
- }
-
- return rerender_image(iv);
-}
-
-
static int rerender_image(CrystFELImageView *iv)
{
int i;
@@ -785,6 +753,9 @@ static int rerender_image(CrystFELImageView *iv)
double border;
double scale_top;
+ if ( iv->image == NULL ) return 0;
+ if ( iv->image->detgeom == NULL ) return 0;
+
if ( iv->pixbufs == NULL ) {
iv->pixbufs = calloc(iv->image->detgeom->n_panels,
sizeof(GdkPixbuf *));
@@ -827,71 +798,26 @@ static int rerender_image(CrystFELImageView *iv)
}
-int crystfel_image_view_set_datatemplate(CrystFELImageView *iv,
- DataTemplate *dtempl)
-{
- iv->dtempl = dtempl;
- return reload_image(iv);
-}
-
-
int crystfel_image_view_set_image(CrystFELImageView *iv,
- const char *filename,
- const char *event)
-{
- int i;
-
- free(iv->filename);
- free(iv->event);
-
- /* Dump peak lists, because image is changing */
- for ( i=0; i<iv->num_peaklists; i++ ) {
- image_feature_list_free(iv->peaklists[i]);
- }
- free(iv->peaklists);
- iv->peaklists = NULL;
- iv->num_peaklists = 0;
-
- iv->filename = safe_strdup(filename);
- iv->event = safe_strdup(event);
- return reload_image(iv);
-}
-
-
-struct image *crystfel_image_view_get_image_struct(CrystFELImageView *iv)
+ const struct image *image)
{
- return iv->image;
+ cleanup_image(iv);
+ iv->image = image;
+ return rerender_image(iv);
}
-void crystfel_image_view_set_peaks(CrystFELImageView *iv,
- ImageFeatureList *peaks,
- int list_num)
+void crystfel_image_view_set_brightness(CrystFELImageView *iv,
+ double brightness)
{
- int i;
- if ( list_num >= iv->num_peaklists ) {
- ImageFeatureList **n_fl;
- n_fl = realloc(iv->peaklists,
- (list_num+1)*sizeof(ImageFeatureList*));
- if ( n_fl == NULL ) return;
- for ( i=iv->num_peaklists; i<list_num+1; i++ ) {
- n_fl[i] = NULL;
- }
- iv->peaklists = n_fl;
- iv->num_peaklists = list_num+1;
- }
- if ( iv->peaklists[list_num] != NULL ) {
- image_feature_list_free(iv->peaklists[list_num]);
- }
- iv->peaklists[list_num] = image_feature_list_copy(peaks);
-
- redraw(iv);
+ iv->brightness = brightness;
+ rerender_image(iv);
}
-void crystfel_image_view_set_brightness(CrystFELImageView *iv,
- double brightness)
+void crystfel_image_view_set_show_peaks(CrystFELImageView *iv,
+ int show_peaks)
{
- iv->brightness = brightness;
+ iv->show_peaks = show_peaks;
rerender_image(iv);
}
diff --git a/src/crystfelimageview.h b/src/crystfelimageview.h
index eafb0c44..d17f394f 100644
--- a/src/crystfelimageview.h
+++ b/src/crystfelimageview.h
@@ -81,16 +81,12 @@ struct _crystfelimageview
double offs_x;
double offs_y;
- DataTemplate *dtempl;
- char *filename;
- char *event;
- struct image *image;
- GdkPixbuf **pixbufs;
+ const struct image *image;
- int num_peaklists;
- ImageFeatureList **peaklists;
+ GdkPixbuf **pixbufs;
double brightness;
+ int show_peaks;
};
struct _crystfelimageviewclass
@@ -104,20 +100,13 @@ typedef struct _crystfelimageviewclass CrystFELImageViewClass;
extern GType crystfel_image_view_get_type(void);
extern GtkWidget *crystfel_image_view_new(void);
-extern int crystfel_image_view_set_datatemplate(CrystFELImageView *iv,
- DataTemplate *dtempl);
-
extern int crystfel_image_view_set_image(CrystFELImageView *iv,
- const char *filename,
- const char *event);
-
-extern struct image *crystfel_image_view_get_image_struct(CrystFELImageView *iv);
-
-extern void crystfel_image_view_set_peaks(CrystFELImageView *iv,
- ImageFeatureList *peaks,
- int list_num);
+ const struct image *image);
extern void crystfel_image_view_set_brightness(CrystFELImageView *iv,
double brightness);
+extern void crystfel_image_view_set_show_peaks(CrystFELImageView *iv,
+ int show_peaks);
+
#endif /* CRYSTFELIMAGEVIEW_H */
diff --git a/src/gui_peaksearch.c b/src/gui_peaksearch.c
index eedb558d..7a147278 100644
--- a/src/gui_peaksearch.c
+++ b/src/gui_peaksearch.c
@@ -48,23 +48,19 @@
void update_peaks(struct crystfelproject *proj)
{
-
if ( proj->n_frames == 0 ) return;
- if ( proj->show_peaks ) {
-
- struct image *image;
+ if ( proj->cur_image == NULL ) return;
- image = crystfel_image_view_get_image_struct(CRYSTFEL_IMAGE_VIEW(proj->imageview));
- if ( image == NULL ) return;
+ if ( proj->show_peaks ) {
- image_feature_list_free(image->features);
- image->features = NULL;
+ image_feature_list_free(proj->cur_image->features);
+ proj->cur_image->features = NULL;
switch ( proj->peak_search_params.method ) {
- case PEAK_ZAEF:
- search_peaks(image,
+ case PEAK_ZAEF:
+ search_peaks(proj->cur_image,
proj->peak_search_params.threshold,
proj->peak_search_params.min_sq_gradient,
proj->peak_search_params.min_snr,
@@ -74,8 +70,8 @@ void update_peaks(struct crystfelproject *proj)
1);
break;
- case PEAK_PEAKFINDER8:
- search_peaks_peakfinder8(image, 2048,
+ case PEAK_PEAKFINDER8:
+ search_peaks_peakfinder8(proj->cur_image, 2048,
proj->peak_search_params.threshold,
proj->peak_search_params.min_snr,
proj->peak_search_params.min_pix_count,
@@ -86,14 +82,14 @@ void update_peaks(struct crystfelproject *proj)
1);
break;
- case PEAK_HDF5:
- case PEAK_CXI:
- image->features = image_read_peaks(proj->dtempl,
- image->filename,
- image->ev,
- proj->peak_search_params.half_pixel_shift);
+ case PEAK_HDF5:
+ case PEAK_CXI:
+ proj->cur_image->features = image_read_peaks(proj->dtempl,
+ proj->cur_image->filename,
+ proj->cur_image->ev,
+ proj->peak_search_params.half_pixel_shift);
if ( proj->peak_search_params.revalidate ) {
- validate_peaks(image,
+ validate_peaks(proj->cur_image,
proj->peak_search_params.min_snr,
proj->peak_search_params.pk_inn,
proj->peak_search_params.pk_mid,
@@ -102,18 +98,17 @@ void update_peaks(struct crystfelproject *proj)
}
break;
- default:
+ default:
ERROR("This peak detection method not implemented!\n");
break;
}
- crystfel_image_view_set_peaks(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- image->features, 0);
+ crystfel_image_view_set_show_peaks(CRYSTFEL_IMAGE_VIEW(proj->imageview),
+ 1);
- } else {
- crystfel_image_view_set_peaks(CRYSTFEL_IMAGE_VIEW(proj->imageview),
- NULL, 0);
+ crystfel_image_view_set_image(CRYSTFEL_IMAGE_VIEW(proj->imageview),
+ proj->cur_image);
}
}
diff --git a/src/gui_project.c b/src/gui_project.c
index f803c103..9f610420 100644
--- a/src/gui_project.c
+++ b/src/gui_project.c
@@ -416,6 +416,7 @@ void default_project(struct crystfelproject *proj)
proj->stream_filename = NULL;
proj->stream = NULL;
proj->dtempl = NULL;
+ proj->cur_image = NULL;
/* Default parameter values */
proj->show_peaks = 0;
diff --git a/src/gui_project.h b/src/gui_project.h
index c2d540a9..aad71e2e 100644
--- a/src/gui_project.h
+++ b/src/gui_project.h
@@ -79,6 +79,7 @@ struct crystfelproject {
int unsaved;
int cur_frame;
+ struct image *cur_image;
char *geom_filename;
char *stream_filename;