aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-03-20 16:20:26 +0100
committerThomas White <taw@physics.org>2020-07-29 18:42:57 +0200
commit00495061efdad11a047549b2628089d61f77ab85 (patch)
treef361be110db9e1b1e0e55e44dda521b99ca8a34c
parent4bbec7864eaa1a3752717f69202d1a622aff5217 (diff)
Add data_template_find_panel() and data_template_file_to_panel_coords()
-rw-r--r--libcrystfel/src/datatemplate.c30
-rw-r--r--libcrystfel/src/datatemplate.h6
2 files changed, 36 insertions, 0 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 282e61a6..f0e23ded 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -1240,3 +1240,33 @@ void data_template_free(DataTemplate *dt)
free(dt->bad);
free(dt);
}
+
+
+signed int data_template_find_panel(const DataTemplate *dt,
+ int fs, int ss)
+{
+ int p;
+
+ for ( p=0; p<dt->n_panels; p++ ) {
+ if ( (fs >= dt->panels[p].orig_min_fs)
+ && (fs < dt->panels[p].orig_max_fs+1)
+ && (ss >= dt->panels[p].orig_min_ss)
+ && (ss < dt->panels[p].orig_max_ss+1) ) return p;
+ }
+
+ return -1;
+}
+
+
+void data_template_file_to_panel_coords(const DataTemplate *dt,
+ float *pfs, float *pss)
+{
+ signed int pn = data_template_find_panel(dt, *pfs, *pss);
+ if ( pn == -1 ) {
+ ERROR("Can't convert coordinates - no panel found\n");
+ return;
+ }
+
+ *pfs = *pfs - dt->panels[pn].orig_min_fs;
+ *pss = *pss - dt->panels[pn].orig_min_ss;
+}
diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h
index 01292836..0adcdb0b 100644
--- a/libcrystfel/src/datatemplate.h
+++ b/libcrystfel/src/datatemplate.h
@@ -53,6 +53,12 @@ extern "C" {
extern DataTemplate *data_template_new_from_file(const char *filename);
extern void data_template_free(DataTemplate *dt);
+extern signed int data_template_find_panel(const DataTemplate *dt,
+ int fs, int ss);
+
+extern void data_template_file_to_panel_coords(const DataTemplate *dt,
+ float *pfs, float *pss);
+
#ifdef __cplusplus
}
#endif