aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/datatemplate.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-05-16 11:09:19 +0200
committerThomas White <taw@physics.org>2023-07-28 13:22:05 +0200
commit3e8caf1258140119b5fbce74cc1040da7e8d280e (patch)
treecddaff5d240fbae70283548c3bef193f862eb535 /libcrystfel/src/datatemplate.c
parent0a9f19f83f8dd408266ead176a96f5b6dfe5a686 (diff)
Implement data_template_translate_group_{px,m}()
Diffstat (limited to 'libcrystfel/src/datatemplate.c')
-rw-r--r--libcrystfel/src/datatemplate.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 1cde78f9..fc0e7f0e 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -2057,3 +2057,67 @@ double data_template_get_clen_if_possible(const DataTemplate *dt)
detgeom_free(dg);
return clen;
}
+
+
+static int translate_group_contents(DataTemplate *dtempl,
+ const struct panel_group_template *group,
+ double x, double y, double z,
+ int is_metres)
+{
+ int i;
+
+ if ( group->n_children == 0 ) {
+
+ struct panel_template *p = find_panel_by_name(dtempl, group->name);
+ if ( p == NULL ) return 1;
+
+ if ( is_metres ) {
+ p->cnx += x/p->pixel_pitch;
+ p->cny += y/p->pixel_pitch;
+ p->cnz_offset += z;
+ } else {
+ p->cnx += x;
+ p->cny += y;
+ p->cnz_offset += z*p->pixel_pitch;
+ }
+
+ } else {
+ for ( i=0; i<group->n_children; i++ ) {
+ translate_group_contents(dtempl, group->children[i],
+ x, y, z, is_metres);
+ }
+ }
+
+ return 0;
+}
+
+
+/**
+ * Alters dtempl by shifting the named panel group by x,y,z in the CrystFEL
+ * coordinate system. x,y,z are in pixels, and all panels in the group must
+ * have the same pixel size (but, this will not be checked).
+ *
+ * \returns zero for success, non-zero on error
+ */
+int data_template_translate_group_px(DataTemplate *dtempl, const char *group_name,
+ double x, double y, double z)
+{
+ const struct panel_group_template *group = find_group(dtempl, group_name);
+ if ( group == NULL ) return 1;
+ return translate_group_contents(dtempl, group, x, y, z, 0);
+}
+
+
+/**
+ * Alters dtempl by shifting the named panel group by x,y,z in the CrystFEL
+ * coordinate system. x,y,z are in metres.
+ *
+ * \returns zero for success, non-zero on error
+ */
+int data_template_translate_group_m(DataTemplate *dtempl, const char *group_name,
+ double x, double y, double z)
+{
+ const struct panel_group_template *group = find_group(dtempl, group_name);
+ if ( group == NULL ) return 1;
+ return translate_group_contents(dtempl, group, x, y, z, 1);
+}