aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-03-05 15:34:25 +0100
committerThomas White <taw@physics.org>2020-07-29 18:42:24 +0200
commitbd4ed1a96bcbaca39ad39ff6d31e4f1bbf8d74ee (patch)
tree433a66ab3a7442932087fe77b0b9ecad29692fe9
parent6516cc6c948f8e907dbe3863ef5e4d3f16cb1ecd (diff)
Add image_get_feature_const() and image_feature_list_copy()
-rw-r--r--libcrystfel/src/image.c32
-rw-r--r--libcrystfel/src/image.h3
2 files changed, 28 insertions, 7 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 63050a40..29761d7c 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -111,10 +111,7 @@ static int comp(const void *a, const void *b)
}
-/**
- * Strongest first.
- */
-ImageFeatureList *sort_peaks(ImageFeatureList *flist)
+ImageFeatureList *image_feature_list_copy(const ImageFeatureList *flist)
{
ImageFeatureList *n;
int nf, i;
@@ -132,15 +129,25 @@ ImageFeatureList *sort_peaks(ImageFeatureList *flist)
nf = 0;
for ( i=0; i<flist->n_features; i++ ) {
- struct imagefeature *f;
- f = image_get_feature(flist, i);
+ const struct imagefeature *f;
+ f = image_get_feature_const(flist, i);
if ( f == NULL ) continue;
n->features[nf++] = flist->features[i];
}
n->n_features = nf;
- qsort(n->features, nf, sizeof(struct imagefeature), comp);
+ return n;
+}
+
+/**
+ * Strongest first.
+ */
+ImageFeatureList *sort_peaks(ImageFeatureList *flist)
+{
+ ImageFeatureList *n = image_feature_list_copy(flist);
+ qsort(n->features, image_feature_count(n),
+ sizeof(struct imagefeature), comp);
return n;
}
@@ -238,6 +245,17 @@ int image_feature_count(ImageFeatureList *flist)
}
+const struct imagefeature *image_get_feature_const(const ImageFeatureList *flist,
+ int idx)
+{
+ /* Sanity check */
+ if ( flist == NULL ) return NULL;
+ if ( idx >= flist->n_features ) return NULL;
+
+ return &flist->features[idx];
+}
+
+
struct imagefeature *image_get_feature(ImageFeatureList *flist, int idx)
{
/* Sanity check */
diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h
index a7d7165f..fd85337c 100644
--- a/libcrystfel/src/image.h
+++ b/libcrystfel/src/image.h
@@ -222,7 +222,10 @@ extern Reflection *image_reflection_closest(RefList *rlist,
extern int image_feature_count(ImageFeatureList *flist);
extern struct imagefeature *image_get_feature(ImageFeatureList *flist, int idx);
+extern const struct imagefeature *image_get_feature_const(const ImageFeatureList *flist,
+ int idx);
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 int remove_flagged_crystals(struct image *image);