aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel/src/image.c')
-rw-r--r--libcrystfel/src/image.c49
1 files changed, 49 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;