diff options
-rw-r--r-- | libcrystfel/src/image.c | 28 | ||||
-rw-r--r-- | libcrystfel/src/image.h | 12 | ||||
-rw-r--r-- | libcrystfel/src/index.c | 9 | ||||
-rw-r--r-- | libcrystfel/src/stream.c | 48 |
4 files changed, 47 insertions, 50 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 9e9af85c..142598e3 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -317,35 +317,45 @@ void image_remove_feature(ImageFeatureList *flist, int idx) } -void image_add_crystal(struct image *image, Crystal *cryst) +void image_add_crystal_refls(struct image *image, + Crystal *cryst, + RefList *reflist) { - Crystal **crs; + struct crystal_refls *crs; int n; n = image->n_crystals; - crs = cfrealloc(image->crystals, (n+1)*sizeof(Crystal *)); + crs = cfrealloc(image->crystals, (n+1)*sizeof(struct crystal_refls)); if ( crs == NULL ) { ERROR("Failed to allocate memory for crystals.\n"); return; } - crs[n] = cryst; + crs[n].cr = cryst; + crs[n].refls = reflist; image->crystals = crs; image->n_crystals = n+1; } +void image_add_crystal(struct image *image, Crystal *cryst) +{ + image_add_crystal_refls(image, cryst, NULL); +} + + int remove_flagged_crystals(struct image *image) { int i; int n_bad = 0; for ( i=0; i<image->n_crystals; i++ ) { - if ( crystal_get_user_flag(image->crystals[i]) ) { + if ( crystal_get_user_flag(image->crystals[i].cr) ) { int j; - Crystal *deleteme = image->crystals[i]; + Crystal *deleteme = image->crystals[i].cr; cell_free(crystal_get_cell(deleteme)); crystal_free(deleteme); + reflist_free(image->crystals[i].refls); for ( j=i; j<image->n_crystals-1; j++ ) { image->crystals[j] = image->crystals[j+1]; } @@ -365,11 +375,13 @@ void free_all_crystals(struct image *image) int i; if ( image->crystals == NULL ) return; for ( i=0; i<image->n_crystals; i++ ) { - Crystal *cr = image->crystals[i]; + Crystal *cr = image->crystals[i].cr; cell_free(crystal_get_cell(cr)); - crystal_free(image->crystals[i]); + crystal_free(image->crystals[i].cr); + reflist_free(image->crystals[i].refls); } cffree(image->crystals); + image->crystals = NULL; image->n_crystals = 0; } diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h index 7e4bad1f..beb66810 100644 --- a/libcrystfel/src/image.h +++ b/libcrystfel/src/image.h @@ -110,6 +110,12 @@ typedef enum } DataSourceType; +struct crystal_refls +{ + Crystal *cr; + RefList *refls; +}; + struct image { /** The image data, by panel */ @@ -124,8 +130,8 @@ struct image /** Non-zero if the frame was determined to be a "hit" */ int hit; - /**Array of crystals in the image */ - Crystal **crystals; + /** Array of crystals (with reflection lists) in the image */ + struct crystal_refls *crystals; /** The number of crystals in the image (size of \p crystals) */ int n_crystals; @@ -218,6 +224,8 @@ extern ImageFeatureList *sort_peaks(ImageFeatureList *flist); extern ImageFeatureList *image_feature_list_copy(const ImageFeatureList *flist); extern void image_add_crystal(struct image *image, Crystal *cryst); +extern void image_add_crystal_refls(struct image *image, + Crystal *cryst, RefList *reflist); extern int remove_flagged_crystals(struct image *image); extern void free_all_crystals(struct image *image); diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index 4c35d2ca..7aea3b59 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -699,7 +699,7 @@ static int try_indexer(struct image *image, IndexingMethod indm, int this_crystal = image->n_crystals - i - 1; /* ... starting at the end of the (complete) list ... */ - Crystal *cr = image->crystals[this_crystal]; + Crystal *cr = image->crystals[this_crystal].cr; crystal_set_profile_radius(cr, 0.02e9); crystal_set_mosaicity(cr, 0.0); @@ -756,7 +756,7 @@ static int try_indexer(struct image *image, IndexingMethod indm, profile_start("cell-compare-to-others"); for ( j=0; j<this_crystal; j++ ) { - Crystal *that_cr = image->crystals[j]; + Crystal *that_cr = image->crystals[j].cr; /* 'tols' is in frac (not %) and radians */ const double tols[] = {0.1, 0.1, 0.1, deg2rad(5.0), @@ -908,7 +908,7 @@ static int finished_retry(IndexingMethod indm, IndexingFlags flags, if ( flags & INDEXING_MULTI ) { /* Remove "used" spots and try for another lattice */ Crystal *cr; - cr = image->crystals[image->n_crystals-1]; + cr = image->crystals[image->n_crystals-1].cr; return delete_explained_peaks(image, cr); } else { return 1; @@ -945,8 +945,7 @@ void index_pattern_4(struct image *image, IndexingPrivate *ipriv, int *ping, if ( ipriv == NULL ) return; - image->crystals = NULL; - image->n_crystals = 0; + free_all_crystals(image); /* No peaks? */ if ( image->features == NULL ) return; diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index edbeb7af..ffe68162 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -338,11 +338,9 @@ static int num_integrated_reflections(RefList *list) } -static int write_crystal(Stream *st, Crystal *cr, - int include_reflections) +static int write_crystal(Stream *st, Crystal *cr, RefList *reflist) { UnitCell *cell; - RefList *reflist; double asx, asy, asz; double bsx, bsy, bsz; double csx, csy, csz; @@ -389,7 +387,6 @@ static int write_crystal(Stream *st, Crystal *cr, fprintf(st->fh, "predict_refine/det_shift x = %.3f y = %.3f mm\n", det_shift_x*1e3, det_shift_y*1e3); - reflist = crystal_get_reflections(cr); if ( reflist != NULL ) { fprintf(st->fh, "diffraction_resolution_limit" @@ -406,20 +403,17 @@ static int write_crystal(Stream *st, Crystal *cr, } - if ( include_reflections ) { - - if ( reflist != NULL ) { + if ( reflist != NULL ) { - fprintf(st->fh, STREAM_REFLECTION_START_MARKER"\n"); - ret = write_stream_reflections(st->fh, reflist, - st->dtempl_write); - fprintf(st->fh, STREAM_REFLECTION_END_MARKER"\n"); + fprintf(st->fh, STREAM_REFLECTION_START_MARKER"\n"); + ret = write_stream_reflections(st->fh, reflist, + st->dtempl_write); + fprintf(st->fh, STREAM_REFLECTION_END_MARKER"\n"); - } else { + } else { - fprintf(st->fh, "No integrated reflections.\n"); + fprintf(st->fh, "No integrated reflections.\n"); - } } fprintf(st->fh, STREAM_CRYSTAL_END_MARKER"\n"); @@ -512,11 +506,11 @@ int stream_write_chunk(Stream *st, const struct image *i, } for ( j=0; j<i->n_crystals; j++ ) { - if ( crystal_get_user_flag(i->crystals[j]) ) { + if ( crystal_get_user_flag(i->crystals[j].cr) ) { continue; } - ret = write_crystal(st, i->crystals[j], - srf & STREAM_REFLECTIONS); + ret = write_crystal(st, i->crystals[j].cr, + srf & STREAM_REFLECTIONS ? i->crystals[j].refls : NULL); } fprintf(st->fh, STREAM_CHUNK_END_MARKER"\n"); @@ -564,8 +558,7 @@ static void read_crystal(Stream *st, struct image *image, char unique_axis = '*'; LatticeType lattice_type = L_TRICLINIC; Crystal *cr; - int n; - Crystal **crystals_new; + RefList *reflist = NULL; double shift_x, shift_y; as.u = 0.0; as.v = 0.0; as.w = 0.0; @@ -664,8 +657,6 @@ static void read_crystal(Stream *st, struct image *image, if ( (strcmp(line, STREAM_REFLECTION_START_MARKER) == 0) && (srf & STREAM_REFLECTIONS) ) { - - RefList *reflist; reflist = read_stream_reflections_2_3(st); if ( reflist == NULL ) { ERROR("Failed while reading reflections\n"); @@ -673,9 +664,6 @@ static void read_crystal(Stream *st, struct image *image, ERROR("Event = %s\n", image->ev); break; } - - crystal_set_reflections(cr, reflist); - } if ( strcmp(line, STREAM_CRYSTAL_END_MARKER) == 0 ) break; @@ -713,17 +701,7 @@ static void read_crystal(Stream *st, struct image *image, /* Unused at the moment */ crystal_set_mosaicity(cr, 0.0); - /* Add crystal to the list for this image */ - n = image->n_crystals+1; - crystals_new = cfrealloc(image->crystals, n*sizeof(Crystal *)); - - if ( crystals_new == NULL ) { - ERROR("Failed to expand crystal list!\n"); - } else { - image->crystals = crystals_new; - image->crystals[image->n_crystals++] = cr; - } - + image_add_crystal_refls(image, cr, reflist); } |