aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2013-06-01 19:01:52 -0700
committerThomas White <taw@physics.org>2013-06-02 10:15:47 -0700
commit7e874c2629b8e4aa8c388d72566d6ca00673da77 (patch)
tree884d07e0172a4adfae937c33c66ddc703bd8941e /libcrystfel
parent3104cf229230151e8ca158144952d474f4b61aa3 (diff)
Rigid group stuff
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/detector.c99
-rw-r--r--libcrystfel/src/detector.h15
-rw-r--r--libcrystfel/src/integration.c9
-rw-r--r--libcrystfel/src/reax.c12
4 files changed, 88 insertions, 47 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index f7ff135e..a30d3ccf 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -480,11 +480,12 @@ static struct panel *new_panel(struct detector *det, const char *name)
new = &det->panels[det->n_panels-1];
memcpy(new, &det->defaults, sizeof(struct panel));
+ strcpy(new->name, name);
+
/* Create a new copy of the camera length location if needed */
if ( new->clen_from != NULL ) {
new->clen_from = strdup(new->clen_from);
}
- strcpy(new->name, name);
return new;
}
@@ -537,32 +538,68 @@ static struct badregion *find_bad_region_by_name(struct detector *det,
}
-static char *find_or_add_rg(struct detector *det, const char *name)
+static struct rigid_group *find_or_add_rg(struct detector *det,
+ const char *name)
{
int i;
- char **new;
- char *tmp;
+ struct rigid_group **new;
+ struct rigid_group *rg;
- for ( i=0; i<det->num_rigid_groups; i++ ) {
+ for ( i=0; i<det->n_rigid_groups; i++ ) {
- if ( strcmp(det->rigid_groups[i], name) == 0 ) {
+ if ( strcmp(det->rigid_groups[i]->name, name) == 0 ) {
return det->rigid_groups[i];
}
}
new = realloc(det->rigid_groups,
- (1+det->num_rigid_groups)*sizeof(char *));
+ (1+det->n_rigid_groups)*sizeof(struct rigid_group *));
if ( new == NULL ) return NULL;
det->rigid_groups = new;
- tmp = strdup(name);
- det->rigid_groups[det->num_rigid_groups] = tmp;
+ rg = malloc(sizeof(struct rigid_group));
+ if ( rg == NULL ) return NULL;
- det->num_rigid_groups++;
+ det->rigid_groups[det->n_rigid_groups++] = rg;
- return tmp;
+ rg->name = strdup(name);
+ rg->panels = NULL;
+ rg->n_panels = 0;
+
+ return rg;
+}
+
+
+static void add_to_rigid_group(struct rigid_group *rg, struct panel *p)
+{
+ struct panel **pn;
+
+ pn = realloc(rg->panels, (1+rg->n_panels)*sizeof(struct panel *));
+ if ( pn == NULL ) {
+ ERROR("Couldn't add panel to rigid group.\n");
+ return;
+ }
+
+ assert(p->rigid_group == rg);
+ rg->panels = pn;
+ rg->panels[rg->n_panels++] = p;
+}
+
+
+static void fix_up_rigid_groups(struct detector *det)
+{
+ int i;
+
+ for ( i=0; i<det->n_panels; i++ ) {
+
+ struct panel *p = &det->panels[i];
+ if ( p->rigid_group != NULL ) {
+ add_to_rigid_group(p->rigid_group, p);
+ }
+
+ }
}
@@ -775,7 +812,7 @@ struct detector *get_detector_geometry(const char *filename)
det->mask_good = 0;
det->mask_bad = 0;
det->mask = NULL;
- det->num_rigid_groups = 0;
+ det->n_rigid_groups = 0;
det->rigid_groups = NULL;
/* The default defaults... */
@@ -1012,6 +1049,10 @@ out:
}
+ /* Fix up rigid group panel pointers now that the panels and RGs have
+ * stopped being realloc()ed */
+ fix_up_rigid_groups(det);
+
find_min_max_d(det);
if ( reject ) return NULL;
@@ -1026,9 +1067,6 @@ void free_detector_geometry(struct detector *det)
{
int i;
- for ( i=0; i<det->num_rigid_groups; i++ ) {
- free(det->rigid_groups[i]);
- }
free(det->rigid_groups);
for ( i=0; i<det->n_panels; i++ ) {
@@ -1062,18 +1100,6 @@ struct detector *copy_geom(const struct detector *in)
out->bad = malloc(out->n_bad * sizeof(struct badregion));
memcpy(out->bad, in->bad, out->n_bad * sizeof(struct badregion));
- if ( in->rigid_groups != NULL ) {
-
- out->rigid_groups = malloc(out->num_rigid_groups*sizeof(char *));
- memcpy(out->rigid_groups, in->rigid_groups,
- out->num_rigid_groups*sizeof(char *));
-
- for ( i=0; i<in->num_rigid_groups; i++ ) {
- out->rigid_groups[i] = strdup(in->rigid_groups[i]);
- }
-
- }
-
for ( i=0; i<out->n_panels; i++ ) {
struct panel *p;
@@ -1088,22 +1114,19 @@ struct detector *copy_geom(const struct detector *in)
}
- for ( i=0; i<in->num_rigid_groups; i++ ) {
+ for ( i=0; i<in->n_panels; i++ ) {
- int j;
- char *rg = in->rigid_groups[i];
- char *rgn = out->rigid_groups[i];
+ struct rigid_group *rg;
- for ( j=0; j<in->n_panels; j++ ) {
+ rg = in->panels[i].rigid_group;
+ if ( rg == NULL ) continue;
- if ( in->panels[j].rigid_group == rg ) {
- out->panels[j].rigid_group = rgn;
- }
-
- }
+ out->panels[i].rigid_group = find_or_add_rg(out, rg->name);
}
+ fix_up_rigid_groups(out);
+
return out;
}
@@ -1303,7 +1326,7 @@ int write_detector_geometry(const char *filename, struct detector *det)
if ( p->rigid_group != NULL ) {
fprintf(fh, "%s/rigid_group = %s\n",
- p->name, p->rigid_group);
+ p->name, p->rigid_group->name);
}
}
diff --git a/libcrystfel/src/detector.h b/libcrystfel/src/detector.h
index 0f9be817..b6a90fbf 100644
--- a/libcrystfel/src/detector.h
+++ b/libcrystfel/src/detector.h
@@ -46,6 +46,15 @@ struct hdfile;
extern "C" {
#endif
+
+struct rigid_group
+{
+ char *name;
+ struct panel **panels;
+ int n_panels;
+};
+
+
struct panel
{
char name[1024]; /* Name for this panel */
@@ -62,7 +71,7 @@ struct panel
double res; /* Resolution in pixels per metre */
char badrow; /* 'x' or 'y' */
int no_index; /* Don't index peaks in this panel if non-zero */
- char *rigid_group; /* Rigid group name */
+ struct rigid_group *rigid_group; /* Rigid group */
double adu_per_eV; /* Number of ADU per eV */
double max_adu; /* Treat pixel as unreliable if higher than this */
@@ -106,8 +115,8 @@ struct detector
unsigned int mask_bad;
unsigned int mask_good;
- char **rigid_groups;
- int num_rigid_groups;
+ struct rigid_group **rigid_groups;
+ int n_rigid_groups;
/* Location of the pixel furthest away from the beam position, which
* will have the largest value of 2theta regardless of camera length
diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c
index 967ffb9c..1a2c0585 100644
--- a/libcrystfel/src/integration.c
+++ b/libcrystfel/src/integration.c
@@ -1095,6 +1095,11 @@ static int suitable_reference(struct intcontext *ic, struct peak_box *bx)
}
+static void refine_rigid_groups(struct intcontext *ic)
+{
+}
+
+
static void measure_all_intensities(IntegrationMethod meth, RefList *list,
struct image *image, UnitCell *cell,
double ir_inn, double ir_mid, double ir_out)
@@ -1245,6 +1250,8 @@ static void measure_all_intensities(IntegrationMethod meth, RefList *list,
}
}
+ refine_rigid_groups(&ic);
+
free_intcontext(&ic);
image->num_saturated_peaks = n_saturated;
@@ -1646,6 +1653,8 @@ static void integrate_rings(IntegrationMethod meth, Crystal *cr,
}
+ refine_rigid_groups(&ic);
+
free_intcontext(&ic);
crystal_set_num_saturated_reflections(cr, n_saturated);
diff --git a/libcrystfel/src/reax.c b/libcrystfel/src/reax.c
index 2a599b40..cfc86ba4 100644
--- a/libcrystfel/src/reax.c
+++ b/libcrystfel/src/reax.c
@@ -128,7 +128,7 @@ struct reax_private
static void fill_and_transform(struct dvec *dir, ImageFeatureList *flist,
int nel, double pmax, double *fft_in,
fftw_complex *fft_out, fftw_plan plan,
- const char *rg, struct detector *det)
+ const struct rigid_group *rg, struct detector *det)
{
int n, i;
@@ -191,7 +191,7 @@ static double check_dir(struct dvec *dir, ImageFeatureList *flist,
int nel, double pmax, double *fft_in,
fftw_complex *fft_out, fftw_plan plan,
struct reax_search *s,
- const char *rg, struct detector *det)
+ const struct rigid_group *rg, struct detector *det)
{
int i;
double tot;
@@ -553,7 +553,7 @@ static struct reax_search *search_all_axes(UnitCell *cell, double pmax)
static double get_model_phase(double x, double y, double z, ImageFeatureList *f,
int nel, double pmax, double *fft_in,
fftw_complex *fft_out, fftw_plan plan,
- int smin, int smax, const char *rg,
+ int smin, int smax, const struct rigid_group *rg,
struct detector *det)
{
struct dvec dir;
@@ -589,7 +589,7 @@ static double get_model_phase(double x, double y, double z, ImageFeatureList *f,
static void refine_rigid_group(struct image *image, UnitCell *cell,
- const char *rg, double pmax,
+ const struct rigid_group *rg, double pmax,
double *fft_in, fftw_complex *fft_out,
fftw_plan plan, int smin, int smax,
struct detector *det, struct reax_private *pr)
@@ -716,8 +716,8 @@ static UNUSED void refine_all_rigid_groups(struct image *image, UnitCell *cell,
{
int i;
- for ( i=0; i<image->det->num_rigid_groups; i++ ) {
- refine_rigid_group(image, cell, image->det->rigid_groups[i],
+ for ( i=0; i<image->det->n_rigid_groups; i++ ) {
+ refine_rigid_group(image, cell, &image->det->rigid_groups[i],
pmax, fft_in, fft_out, plan, smin, smax,
det, p);
}