From 3e8caf1258140119b5fbce74cc1040da7e8d280e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 16 May 2023 11:09:19 +0200 Subject: Implement data_template_translate_group_{px,m}() --- libcrystfel/src/datatemplate.c | 64 ++++++++++++++++++++++++++++++++++++++++++ libcrystfel/src/datatemplate.h | 8 ++++++ 2 files changed, 72 insertions(+) (limited to 'libcrystfel/src') 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; in_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); +} diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h index 255b0c1d..cce3eb2d 100644 --- a/libcrystfel/src/datatemplate.h +++ b/libcrystfel/src/datatemplate.h @@ -83,6 +83,14 @@ extern struct detgeom *data_template_get_2d_detgeom_if_possible(const DataTempla extern void data_template_show_hierarchy(const DataTemplate *dtempl); +extern int data_template_translate_group_px(DataTemplate *dtempl, + const char *group_name, + double x, double y, double z); + +extern int data_template_translate_group_m(DataTemplate *dtempl, + const char *group_name, + double x, double y, double z); + #ifdef __cplusplus } #endif -- cgit v1.2.3