aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcrystfel/src/image.c49
-rw-r--r--libcrystfel/src/image.h4
2 files changed, 53 insertions, 0 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index 6caeeb3c..3cabef96 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -148,6 +148,55 @@ struct imagefeature *image_feature_closest(ImageFeatureList *flist,
}
+Reflection *image_reflection_closest(RefList *rlist,
+ double fs, double ss,
+ struct detector *det,
+ double *d)
+{
+
+ double dmin = HUGE_VAL;
+ Reflection *closest = NULL;
+ struct panel *p1;
+ Reflection *refl;
+ RefListIterator *iter;
+
+ p1 = find_panel(det, fs, ss);
+
+ for ( refl = first_refl(rlist, &iter);
+ refl != NULL;
+ refl = next_refl(refl, iter) )
+ {
+ double ds;
+ struct panel *p2;
+ double rfs, rss;
+
+ get_detector_pos(refl, &rfs, &rss);
+
+ p2 = find_panel(det, rfs, rss);
+
+ if ( p1 != p2 ) {
+ continue;
+ }
+
+ ds = distance(rfs, rss, fs, ss);
+
+ if ( ds < dmin ) {
+ dmin = ds;
+ closest = refl;
+ }
+
+ }
+
+ if ( dmin < +HUGE_VAL ) {
+ *d = dmin;
+ return closest;
+ }
+
+ *d = +INFINITY;
+ return NULL;
+}
+
+
int image_feature_count(ImageFeatureList *flist)
{
if ( flist == NULL ) return 0;
diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h
index 2498b5c2..e196d052 100644
--- a/libcrystfel/src/image.h
+++ b/libcrystfel/src/image.h
@@ -224,6 +224,10 @@ extern struct imagefeature *image_feature_closest(ImageFeatureList *flist,
double fs, double ss,
double *d, int *idx,
struct detector *det);
+extern Reflection *image_reflection_closest(RefList *rlist,
+ double fs, double ss,
+ struct detector *det,
+ double *d);
extern int image_feature_count(ImageFeatureList *flist);
extern struct imagefeature *image_get_feature(ImageFeatureList *flist, int idx);