From aada11e09edca22f816f4471c73fff6d6a383256 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 15 Jun 2023 12:07:14 +0200 Subject: detgeom: Add references from children to parents This allows us to start from the panel and work upwards to the top-level group, which makes hierarchical gradient calculation much easier. --- libcrystfel/src/datatemplate.c | 16 ++++++++++++---- libcrystfel/src/detgeom.c | 4 +++- libcrystfel/src/detgeom.h | 9 ++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'libcrystfel/src') diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index 28567b6f..2126f313 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1807,8 +1807,10 @@ 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 panel_group_template *gt, + struct detgeom *detgeom, + int hierarchy_level, + int member_index) { struct detgeom_panel_group *gr; @@ -1829,6 +1831,7 @@ static struct detgeom_panel_group *walk_group(const DataTemplate *dtempl, ERROR("Couldn't find panel %s for leaf group\n", gr->name); return NULL; } + gr->panel->group = gr; } else { @@ -1842,12 +1845,16 @@ static struct detgeom_panel_group *walk_group(const DataTemplate *dtempl, } for ( i=0; in_children; i++ ) { - gr->children[i] = walk_group(dtempl, gt->children[i], detgeom); + gr->children[i] = walk_group(dtempl, gt->children[i], + detgeom, hierarchy_level+1, i); if ( gr->children[i] == NULL ) return NULL; + gr->children[i]->parent = gr; } } + gr->member_index = member_index; + gr->hierarchy_level = hierarchy_level; return gr; } @@ -1976,7 +1983,8 @@ struct detgeom *create_detgeom(struct image *image, } - detgeom->top_group = walk_group(dtempl, find_group(dtempl, "all"), detgeom); + detgeom->top_group = walk_group(dtempl, find_group(dtempl, "all"), detgeom, 0, 0); + detgeom->top_group->parent = NULL; return detgeom; } diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c index 7f458343..988d3f28 100644 --- a/libcrystfel/src/detgeom.c +++ b/libcrystfel/src/detgeom.c @@ -199,7 +199,9 @@ static void detgeom_show_group(const struct detgeom_panel_group *group, int leve return; } - STATUS("%s\n", group->name); + STATUS("%s (level %i, index %i)\n", group->name, + group->hierarchy_level, + group->member_index); for ( i=0; in_children; i++ ) { detgeom_show_group(group->children[i], level+1); diff --git a/libcrystfel/src/detgeom.h b/libcrystfel/src/detgeom.h index 0b37e9f1..917b6bd3 100644 --- a/libcrystfel/src/detgeom.h +++ b/libcrystfel/src/detgeom.h @@ -83,6 +83,9 @@ struct detgeom_panel int w; int h; /*@}*/ + + /** \name Leaf group containing this panel (only) */ + const struct detgeom_panel_group *group; }; @@ -91,8 +94,12 @@ struct detgeom_panel_group char *name; int n_children; + struct detgeom_panel_group *parent; + int hierarchy_level; + int member_index; + /* If n_children > 0, here are the child groups */ - const struct detgeom_panel_group **children; + struct detgeom_panel_group **children; /* If n_children == 0, this is a leaf node, so: */ struct detgeom_panel *panel; -- cgit v1.2.3