aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-05-15 17:16:21 +0200
committerThomas White <taw@physics.org>2023-07-28 13:22:04 +0200
commite6cee18a78236c5bb763c024e586c7154c82535c (patch)
tree371519b356a4b5465e87e92f2a9100db89aed756
parent451ebfa705126e95c0186aac285f0c32bc01b83e (diff)
Transfer detector hierarchy to detgeom
-rw-r--r--libcrystfel/src/datatemplate.c48
-rw-r--r--libcrystfel/src/detgeom.c12
-rw-r--r--libcrystfel/src/detgeom.h20
3 files changed, 79 insertions, 1 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index 814d244d..fc63b93c 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -1817,6 +1817,52 @@ static int detector_flat(const DataTemplate *dtempl)
}
+static struct detgeom_panel_group *walk_group(const DataTemplate *dtempl,
+ const struct panel_group_template *gt,
+ struct detgeom *detgeom)
+{
+ struct detgeom_panel_group *gr;
+
+ if ( gt == NULL ) return NULL;
+
+ gr = malloc(sizeof(struct detgeom_panel_group));
+ if ( gr == NULL ) return NULL;
+
+ gr->name = strdup(gt->name);
+ gr->n_children = gt->n_children;
+
+ if ( gr->n_children == 0 ) {
+
+ /* Leaf node */
+ gr->children = NULL;
+ gr->panel = detgeom_find_panel(detgeom, gr->name);
+ if ( gr->panel == NULL ) {
+ ERROR("Couldn't find panel %s for leaf group\n", gr->name);
+ return NULL;
+ }
+
+ } else {
+
+ int i;
+
+ gr->panel = NULL;
+ gr->children = malloc(gt->n_children*sizeof(struct detgeom_panel_group *));
+ if ( gr->children == NULL ) {
+ free(gr);
+ return NULL;
+ }
+
+ for ( i=0; i<gt->n_children; i++ ) {
+ gr->children[i] = walk_group(dtempl, gt->children[i], detgeom);
+ if ( gr->children[i] == NULL ) return NULL;
+ }
+
+ }
+
+ return gr;
+}
+
+
struct detgeom *create_detgeom(struct image *image,
const DataTemplate *dtempl,
int two_d_only)
@@ -1941,6 +1987,8 @@ struct detgeom *create_detgeom(struct image *image,
}
+ detgeom->top_group = walk_group(dtempl, find_group(dtempl, "top"), detgeom);
+
return detgeom;
}
diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c
index 58e52f01..bd98aed2 100644
--- a/libcrystfel/src/detgeom.c
+++ b/libcrystfel/src/detgeom.c
@@ -174,3 +174,15 @@ double detgeom_mean_camera_length(struct detgeom *dg)
return mean;
}
+
+
+struct detgeom_panel *detgeom_find_panel(struct detgeom *dg, const char *name)
+{
+ int i;
+ for ( i=0; i<dg->n_panels; i++ ) {
+ if ( strcmp(dg->panels[i].name, name) == 0 ) {
+ return &dg->panels[i];
+ }
+ }
+ return NULL;
+}
diff --git a/libcrystfel/src/detgeom.h b/libcrystfel/src/detgeom.h
index 7f291a7a..b06ccb8f 100644
--- a/libcrystfel/src/detgeom.h
+++ b/libcrystfel/src/detgeom.h
@@ -86,12 +86,28 @@ struct detgeom_panel
};
+struct detgeom_panel_group
+{
+ char *name;
+ int n_children;
+
+ /* If n_children > 0, here are the child groups */
+ const struct detgeom_panel_group **children;
+
+ /* If n_children == 0, this is a leaf node, so: */
+ struct detgeom_panel *panel;
+};
+
+
struct detgeom
{
struct detgeom_panel *panels;
- int n_panels;
+ int n_panels;
+
+ struct detgeom_panel_group *top_group;
};
+
extern void detgeom_transform_coords(struct detgeom_panel *p,
double fs, double ss,
double wavelength,
@@ -107,6 +123,8 @@ extern void show_panel(struct detgeom_panel *p);
extern double detgeom_mean_camera_length(struct detgeom *dg);
+extern struct detgeom_panel *detgeom_find_panel(struct detgeom *dg, const char *name);
+
#ifdef __cplusplus
}
#endif