aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorValerio Mariani <valerio.mariani@desy.de>2015-01-26 16:34:46 +0100
committervalerio.mariani@desy.de <vmariani@cfeld-valerio2.desy.de>2015-01-27 14:10:47 +0100
commitec97a9b53bc56ec7789a5449959a9a7722abf681 (patch)
tree826a79d6802d10bc189022367c17247b7b5647a3 /libcrystfel
parent38f81ac432e313ed451eceb80c3f36ba6f1008e8 (diff)
Add image_reflection_closest()
Diffstat (limited to 'libcrystfel')
-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);