From 89199e9a97d6f7efbe473c7447374acc857adeca Mon Sep 17 00:00:00 2001 From: Valerio mariani Date: Fri, 8 May 2015 10:54:17 +0200 Subject: Added colour scale to geoptimiser error maps --- libcrystfel/src/render.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ libcrystfel/src/render.h | 3 +- src/geoptimiser.c | 16 ++++++++-- 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/libcrystfel/src/render.c b/libcrystfel/src/render.c index 17318782..2dcb7b93 100644 --- a/libcrystfel/src/render.c +++ b/libcrystfel/src/render.c @@ -104,6 +104,84 @@ static void render_rgb(double val, double max, } +static void render_geoptimiser(double val, double max, + double *rp, double *gp, double *bp) +{ + double r; + double p; + + r = val/max; + + if ( val < 0.0 ) { + *rp = 0.0; + *gp = 0.0; + *bp = 0.0; + return; + } + + if ( r >= 0.0 && r < 0.059 ) { + p = (r-0.0)/(0.059-0.0); + *rp = 0.0; + *gp = 0.0; + *bp = ((91.0/256.0)-0.0)*p; + return; + } + + if ( r >= 0.059 && r < 0.220 ) { + p = (r-0.059)/(0.220-0.059); + *rp = ((122.0/256.0)-0.0)*p; + *gp = 0.0; + *bp = ((227.0/256.0)-(91.0/256.0))*p+(91.0/256.0); + return; + } + + if ( r >= 0.220 && r < 0.376 ) { + p = (r-0.220)/(0.376-0.220); + *rp = ((195.0/256.0)-(122.0/256.0))*p+(122.0/256.0); + *gp = 0.0; + *bp = ((93.0/256.0)-(227.0/256.0))*p+(227.0/256.0); + return; + } + + if ( r >= 0.376 && r < 0.498 ) { + p = (r-0.376)/(0.498-0.376); + *rp = ((238.0/256.0)-(195.0/256.0))*p+(195.0/256.0); + *gp = ((76.0/256.0)-0.0)*p; + *bp = (0.0-(93.0/256.0))*p+(93.0/256.0); + return; + } + + if ( r >= 0.498 && r < 0.564 ) { + p = (r-0.498)/(0.564-0.498); + *rp = (1.0-(238.0/256.0))*p+(238.0/256.0); + *gp = ((117.0/256.0)-(76.0/256.0))*p+(76.0/256.0); + *bp = 0.0; + return; + } + + if ( r >= 0.564 && r < 0.815 ) { + p = (r-0.564)/(0.815-0.564); + *rp = 1.0; + *gp = ((234.0/256.0)-(117.0/256.0))*p+(117.0/256.0); + *bp = 0.0; + return; + } + + if ( r >= 0.815 && r < 1.0 ) { + p = (r-0.815)/(1.0-0.815); + *rp = 1.0; + *gp = (1.0-(234.0/256.0))*p+(234.0/256.0); + *bp = (1.0-0.0)*p; + return; + } + + if ( r >= 1.0 ) { + *rp = 1.0; *gp = 1.0; *bp = 1.0; + return; + } +} + + static void render_ratio(double val, double max, double *rp, double *gp, double *bp) { @@ -164,5 +242,9 @@ void render_scale(double val, double max, int scale, case SCALE_RATIO : render_ratio(val, max, rp, gp, bp); break; + + case SCALE_GEOPTIMISER : + render_geoptimiser(val, max, rp, gp, bp); + break; } } diff --git a/libcrystfel/src/render.h b/libcrystfel/src/render.h index a4da922d..c2e5965a 100644 --- a/libcrystfel/src/render.h +++ b/libcrystfel/src/render.h @@ -38,7 +38,8 @@ enum { SCALE_COLOUR, SCALE_MONO, SCALE_INVMONO, - SCALE_RATIO + SCALE_RATIO, + SCALE_GEOPTIMISER }; #ifdef __cplusplus diff --git a/src/geoptimiser.c b/src/geoptimiser.c index 1605e363..90875f54 100644 --- a/src/geoptimiser.c +++ b/src/geoptimiser.c @@ -2129,7 +2129,7 @@ static int draw_detector(cairo_surface_t *surf, struct image *image, cr = cairo_create(surf); unpack_slab(image); - pixbufs = render_panels(image, 1, 0, 1, &n_pixbufs); + pixbufs = render_panels(image, 1, 4, 1, &n_pixbufs); /* Blank grey background */ cairo_rectangle(cr, 0.0, 0.0, rect.width, rect.height); @@ -2178,6 +2178,8 @@ static int save_data_to_png(char *filename, struct detector *det, struct image im; int i; struct rectangle rect; + GdkPixbuf *col_scale; + cairo_t *cr; cairo_status_t r; cairo_surface_t *surf; @@ -2217,11 +2219,21 @@ static int save_data_to_png(char *filename, struct detector *det, /* Add a thin border */ rect.width += 2.0; rect.height += 2.0; - surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, rect.width, + surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, rect.width + 20, rect.height); draw_detector(surf, &im, rect); + col_scale = render_get_colour_scale(20, rect.height, 4); + + cr = cairo_create(surf); + cairo_identity_matrix(cr); + cairo_translate(cr, rect.width, 0.0); + cairo_rectangle(cr, 0.0, 0.0, 20.0, rect.height); + gdk_cairo_set_source_pixbuf(cr, col_scale, 0.0, 0.0); + cairo_fill(cr); + cairo_destroy(cr); + r = cairo_surface_write_to_png(surf, filename); if (r != CAIRO_STATUS_SUCCESS) { free(im.data); -- cgit v1.2.3