diff options
author | Thomas White <taw@physics.org> | 2015-10-05 17:22:41 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2015-10-05 18:03:18 +0200 |
commit | 759c067bbd2880deec264ced5152d8a37cec0f76 (patch) | |
tree | d460a46b8df94ab6e8a2c0f9ebd0f2a3afb3b724 /src/partial_sim.c | |
parent | 02d635bc0fdedf315e032b9356971bd7e4941158 (diff) |
partial_sim: Remove image->data
Diffstat (limited to 'src/partial_sim.c')
-rw-r--r-- | src/partial_sim.c | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/src/partial_sim.c b/src/partial_sim.c index 867183da..16e9cb88 100644 --- a/src/partial_sim.c +++ b/src/partial_sim.c @@ -170,6 +170,18 @@ static void calculate_partials(Crystal *cr, } +static signed int panel_number(struct detector *det, struct panel *p) +{ + int i; + + for ( i=0; i<det->n_panels; i++ ) { + if ( &det->panels[i] == p ) return i; + } + + return -1; +} + + static void draw_and_write_image(struct image *image, RefList *reflections, gsl_rng *rng, double background) { @@ -177,7 +189,26 @@ static void draw_and_write_image(struct image *image, RefList *reflections, RefListIterator *iter; int i; - image->data = calloc(image->width*image->height, sizeof(float)); + image->dp = malloc(image->det->n_panels*sizeof(float *)); + if ( image->dp == NULL ) { + ERROR("Failed to allocate data\n"); + return; + } + for ( i=0; i<image->det->n_panels; i++ ) { + + int j; + struct panel *p = &image->det->panels[i]; + + image->dp[i] = calloc(p->w * p->h, sizeof(float)); + if ( image->dp[i] == NULL ) { + ERROR("Failed to allocate data\n"); + return; + } + for ( j=0; j<p->w*p->h; j++ ) { + image->dp[i][j] = poisson_noise(rng, background); + } + + } for ( refl = first_refl(reflections, &iter); refl != NULL; @@ -186,26 +217,32 @@ static void draw_and_write_image(struct image *image, RefList *reflections, double Ip; double dfs, dss; int fs, ss; + struct panel *p; + signed int pn; Ip = get_intensity(refl); get_detector_pos(refl, &dfs, &dss); - fs = nearbyint(dfs); - ss = nearbyint(dss); + p = get_panel(refl); + pn = panel_number(image->det, p); /* Yeurgh */ + assert(pn != -1); + + fs = nearbyint(dfs) - p->min_fs; + ss = nearbyint(dss) - p->min_ss; assert(fs >= 0); assert(ss >= 0); - assert(fs < image->width); - assert(ss < image->height); - image->data[fs + image->width*ss] += Ip; - - } + assert(fs < p->w); + assert(ss < p->h); + image->dp[pn][fs + p->w*ss] += Ip; - for ( i=0; i<image->width*image->height; i++ ) { - image->data[i] += poisson_noise(rng, background); } hdf5_write_image(image->filename, image, NULL); - free(image->data); + + for ( i=0; i<image->det->n_panels; i++ ) { + free(image->dp[i]); + } + free(image->dp); } |