aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/image.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2024-01-18 09:46:26 +0100
committerThomas White <taw@physics.org>2024-02-06 16:59:34 +0100
commit604c081d5f8dffc7a78cb07c245dae531342db04 (patch)
tree71d1d900e23c6c2c0a3761a9e485dd040d07d659 /libcrystfel/src/image.c
parent513827a44d1ddd395f677a74617b42934ca9bc64 (diff)
Crystals shouldn't own RefLists (part 2)
This commit replaces image.crystals with an array of small structs, each consisting of a Crystal-RefList pair. index.c and stream.c are updated, more to follow.
Diffstat (limited to 'libcrystfel/src/image.c')
-rw-r--r--libcrystfel/src/image.c28
1 files changed, 20 insertions, 8 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;
}