diff options
author | Thomas White <taw@physics.org> | 2022-11-24 15:27:29 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-11-24 17:48:13 +0100 |
commit | 2754cd0ecdd199f46edf656100a4a9cd0440b7a1 (patch) | |
tree | 26d8cf71310750702d69ad3d97ac6d2e9221f8aa | |
parent | acb2e3cb545b64fe94f399e18ae91577ffcac6d0 (diff) |
GUI: Colour scale, part 3: Use the values in CrystFELImageView
-rw-r--r-- | src/crystfel_gui.c | 19 | ||||
-rw-r--r-- | src/crystfelcolourscale.c | 36 | ||||
-rw-r--r-- | src/crystfelcolourscale.h | 4 | ||||
-rw-r--r-- | src/crystfelimageview.c | 62 | ||||
-rw-r--r-- | src/crystfelimageview.h | 5 | ||||
-rw-r--r-- | src/gui_project.c | 1 | ||||
-rw-r--r-- | src/gui_project.h | 1 |
7 files changed, 76 insertions, 52 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index 81f563a8..25b7e1d8 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -282,7 +282,9 @@ void update_imageview(struct crystfelproject *proj) crystfel_colour_scale_scan_image(CRYSTFEL_COLOUR_SCALE(proj->colscale), proj->cur_image); - crystfel_colour_scale_auto_range(CRYSTFEL_COLOUR_SCALE(proj->colscale)); + if ( !proj->range_set ) { + crystfel_colour_scale_auto_range(CRYSTFEL_COLOUR_SCALE(proj->colscale)); + } gtk_widget_set_sensitive(proj->next_button, !(proj->cur_frame == proj->n_frames-1)); @@ -965,6 +967,19 @@ static void clear_log_sig(GtkMenuItem *widget, } +static void colscale_change_sig(CrystFELColourScale *colscale, + struct crystfelproject *proj) +{ + double lo, hi; + crystfel_colour_scale_get_range(colscale, &lo, &hi); + crystfel_image_view_set_colour_scale(CRYSTFEL_IMAGE_VIEW(proj->imageview), + lo, hi); + if ( proj->cur_image != NULL ) { + proj->range_set = 1; + } +} + + static void add_log_menu_items(GtkTextView *textview, GtkWidget *popup, struct crystfelproject *proj) @@ -1206,6 +1221,8 @@ int main(int argc, char *argv[]) proj.colscale = crystfel_colour_scale_new(); gtk_box_pack_start(GTK_BOX(iv_hbox), proj.colscale, FALSE, FALSE, 0.0); + g_signal_connect(proj.colscale, "range-changed", + G_CALLBACK(colscale_change_sig), &proj); /* Icon region at left */ proj.icons = gtk_vbox_new(FALSE, 0.0); diff --git a/src/crystfelcolourscale.c b/src/crystfelcolourscale.c index 8b91abe1..85a1fce9 100644 --- a/src/crystfelcolourscale.c +++ b/src/crystfelcolourscale.c @@ -67,6 +67,14 @@ static gint button_press_sig(GtkWidget *window, GdkEventButton *event, } +static gint button_release_sig(GtkWidget *window, GdkEventButton *event, + CrystFELColourScale *cs) +{ + g_signal_emit_by_name(cs, "range-changed"); + return FALSE; +} + + static void make_histogram(CrystFELColourScale *cs) { int i; @@ -93,8 +101,6 @@ static gint motion_sig(GtkWidget *window, GdkEventMotion *event, CrystFELColourScale *cs) { double span = cs->hi - cs->lo; - //double ddx = event->x - cs->drag_start_x; - //double ddy = event->y - cs->drag_start_y; cs->lo = cs->drag_min + span*(event->y - cs->drag_start_y)/cs->visible_height; cs->hi = cs->lo + span; @@ -158,6 +164,7 @@ static void handle_scroll_click(double zoom_scale, CrystFELColourScale *cs, { cs->lo = pos - (pos - cs->lo)*zoom_scale; cs->hi = pos + (cs->hi - pos)*zoom_scale; + g_signal_emit_by_name(cs, "range-changed"); } @@ -226,6 +233,9 @@ static void crystfel_colour_scale_class_init(CrystFELColourScaleClass *klass) GTK_WIDGET_CLASS(klass)->get_preferred_width = get_preferred_width; GTK_WIDGET_CLASS(klass)->get_preferred_height = get_preferred_height; GTK_WIDGET_CLASS(klass)->get_preferred_height_for_width = NULL; + + g_signal_new("range-changed", CRYSTFEL_TYPE_COLOUR_SCALE, + G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } @@ -249,6 +259,8 @@ GtkWidget *crystfel_colour_scale_new() G_CALLBACK(realise_sig), cs); g_signal_connect(G_OBJECT(cs), "button-press-event", G_CALLBACK(button_press_sig), cs); + g_signal_connect(G_OBJECT(cs), "button-release-event", + G_CALLBACK(button_release_sig), cs); g_signal_connect(G_OBJECT(cs), "motion-notify-event", G_CALLBACK(motion_sig), cs); g_signal_connect(G_OBJECT(cs), "configure-event", @@ -290,6 +302,8 @@ void crystfel_colour_scale_auto_range(CrystFELColourScale *cs) cs->hi = mean + 10.0*sqrt(variance); make_histogram(cs); + + g_signal_emit_by_name(cs, "range-changed"); } @@ -300,7 +314,14 @@ void crystfel_colour_scale_scan_image(CrystFELColourScale *cs, int pn; long int n_pix; - if ( image == NULL ) return; + if ( image == NULL ) { + for ( i=0; i<COLSCALE_SAMPLE_SIZE; i++ ) { + cs->sample[i] = 0; + } + cs->n_samples = COLSCALE_SAMPLE_SIZE; + make_histogram(cs); + return; + } n_pix = 0; for ( pn=0; pn<image->detgeom->n_panels; pn++ ) { @@ -332,3 +353,12 @@ void crystfel_colour_scale_scan_image(CrystFELColourScale *cs, make_histogram(cs); } + + +void crystfel_colour_scale_get_range(CrystFELColourScale *cs, + double *scale_min, + double *scale_max) +{ + *scale_min = cs->lo; + *scale_max = cs->hi; +} diff --git a/src/crystfelcolourscale.h b/src/crystfelcolourscale.h index 3bc03e29..6ca97b10 100644 --- a/src/crystfelcolourscale.h +++ b/src/crystfelcolourscale.h @@ -87,8 +87,8 @@ extern void crystfel_colour_scale_scan_image(CrystFELColourScale *cs, struct image *image); extern void crystfel_colour_scale_get_range(CrystFELColourScale *cs, - double scale_min, - double scale_max); + double *scale_min, + double *scale_max); extern void crystfel_colour_scale_auto_range(CrystFELColourScale *cs); diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c index 88cfb149..03350204 100644 --- a/src/crystfelimageview.c +++ b/src/crystfelimageview.c @@ -908,6 +908,8 @@ GtkWidget *crystfel_image_view_new() iv->need_rerender = 0; iv->need_recentre = 1; iv->resolution_rings = 0; + iv->scale_lo = 0.0; + iv->scale_hi = 100000.0; g_signal_connect(G_OBJECT(iv), "destroy", G_CALLBACK(destroy_sig), iv); @@ -996,7 +998,7 @@ static void free_pixbuf(guchar *data, gpointer p) static GdkPixbuf *render_panel(float *data, int *badmap, int w, int h, - int scale_type, double scale_top) + int scale_type, double scale_lo, double scale_hi) { @@ -1013,7 +1015,7 @@ static GdkPixbuf *render_panel(float *data, int *badmap, int w, int h, if ( !badmap[i] ) { - colscale_lookup(data[i], scale_top, + colscale_lookup(data[i]-scale_lo, scale_hi-scale_lo, scale_type, &r, &g, &b); pixbuf_data[3*i+0] = 255*r; @@ -1040,46 +1042,6 @@ static GdkPixbuf *render_panel(float *data, int *badmap, int w, int h, } -static double auto_scale_top(const struct image *image) -{ - int pn; - double total_mean = 0.0; - double total_variance = 0.0; - - for ( pn=0; pn<image->detgeom->n_panels; pn++ ) { - - long int i, j; - int w, h; - float *data; - float this_mean; - - w = image->detgeom->panels[pn].w; - h = image->detgeom->panels[pn].h; - - data = malloc(w*h*sizeof(float)); - if ( data == NULL ) return 100.0; - - j = 0; - for ( i=0; i<w*h; i++ ) { - if ( !image->bad[pn][i] ) { - data[j++] = image->dp[pn][i]; - } - } - - this_mean = gsl_stats_float_mean(data, 1, j); - - total_mean += this_mean; - total_variance += gsl_stats_float_variance_m(data, 1, j, - this_mean); - - free(data); - } - - return (total_mean/image->detgeom->n_panels) - + 10.0*sqrt(total_variance/image->detgeom->n_panels); -} - - static void center_adjustment(GtkAdjustment *adj) { double min = gtk_adjustment_get_lower(adj); @@ -1093,7 +1055,6 @@ static int rerender_image(CrystFELImageView *iv) { int i; double min_x, min_y, max_x, max_y; - double scale_top; if ( iv->image == NULL ) return 0; if ( iv->image->detgeom == NULL ) return 0; @@ -1108,14 +1069,13 @@ static int rerender_image(CrystFELImageView *iv) } } - scale_top = auto_scale_top(iv->image); - for ( i=0; i<iv->image->detgeom->n_panels; i++ ) { iv->pixbufs[i] = render_panel(iv->image->dp[i], iv->image->bad[i], iv->image->detgeom->panels[i].w, iv->image->detgeom->panels[i].h, - SCALE_COLOUR, scale_top); + SCALE_COLOUR, + iv->scale_lo, iv->scale_hi); if ( iv->pixbufs[i] == NULL ) return 1; } @@ -1235,3 +1195,13 @@ void crystfel_image_view_set_resolution_rings(CrystFELImageView *iv, iv->need_rerender = 1; redraw(iv); } + + +void crystfel_image_view_set_colour_scale(CrystFELImageView *iv, + double lo, double hi) +{ + iv->scale_lo = lo; + iv->scale_hi = hi; + iv->need_rerender = 1; + redraw(iv); +} diff --git a/src/crystfelimageview.h b/src/crystfelimageview.h index aa7d61d2..30926ece 100644 --- a/src/crystfelimageview.h +++ b/src/crystfelimageview.h @@ -69,6 +69,8 @@ struct _crystfelimageview /* Redraw/scroll stuff */ int need_rerender; int need_recentre; + double scale_lo; + double scale_hi; GtkScrollablePolicy hpol; GtkScrollablePolicy vpol; GtkAdjustment *hadj; @@ -137,4 +139,7 @@ extern void crystfel_image_view_set_refl_box_size(CrystFELImageView *iv, extern void crystfel_image_view_set_resolution_rings(CrystFELImageView *iv, int rings); +extern void crystfel_image_view_set_colour_scale(CrystFELImageView *iv, + double lo, double hi); + #endif /* CRYSTFELIMAGEVIEW_H */ diff --git a/src/gui_project.c b/src/gui_project.c index 00a217af..11f27059 100644 --- a/src/gui_project.c +++ b/src/gui_project.c @@ -1196,6 +1196,7 @@ int default_project(struct crystfelproject *proj) proj->max_frames = 0; proj->n_random_history = 0; memset(proj->random_history, 0, N_RANDOM_HISTORY*sizeof(int)); + proj->range_set = 0; proj->filenames = NULL; proj->events = NULL; proj->peak_params = NULL; diff --git a/src/gui_project.h b/src/gui_project.h index 75524a81..bbecd0ba 100644 --- a/src/gui_project.h +++ b/src/gui_project.h @@ -284,6 +284,7 @@ struct crystfelproject { GtkWidget *prev_button; GtkWidget *first_button; GtkWidget *last_button; + int range_set; int unsaved; |