aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-02-22 10:32:21 +0100
committerThomas White <taw@physics.org>2010-02-22 10:32:21 +0100
commitf86c9795c72d0a75692f010c0f3ef37f1c899eca (patch)
tree95f9f8e8e28836be63dc25691eb07ace81f03101 /src
parent79fcc8f0938f0d8056b7b745eb96b89d133a571e (diff)
Add find_panel() routine to clean up a lot of things
Diffstat (limited to 'src')
-rw-r--r--src/detector.c44
-rw-r--r--src/detector.h2
-rw-r--r--src/diffraction.c20
-rw-r--r--src/index.c30
4 files changed, 40 insertions, 56 deletions
diff --git a/src/detector.c b/src/detector.c
index f4810a1b..4df14d77 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -171,25 +171,13 @@ void record_image(struct image *image, int do_water, int do_poisson,
double complex val;
double pix_area, Lsq;
double dsq, proj_area;
- int p;
+ struct panel *p;
int found = 0;
val = image->sfacs[x + image->width*y];
intensity = pow(cabs(val), 2.0);
- for ( p=0; p<image->det.n_panels; p++ ) {
- if ( (x >= image->det.panels[p].min_x)
- && (x <= image->det.panels[p].max_x)
- && (y >= image->det.panels[p].min_y)
- && (y <= image->det.panels[p].max_y) ) {
- found = 1;
- break;
- }
- }
- if ( !found ) {
- ERROR("No mapping found for %i,%i\n", x, y);
- return;
- }
+ p = find_panel(&image->det, x, y);
/* FIXME: Move to diffraction.c somehow */
if ( do_water ) {
@@ -207,17 +195,15 @@ void record_image(struct image *image, int do_water, int do_poisson,
}
/* Area of one pixel */
- pix_area = pow(1.0/image->det.panels[p].res, 2.0);
- Lsq = pow(image->det.panels[p].clen, 2.0);
+ pix_area = pow(1.0/p->res, 2.0);
+ Lsq = pow(p->clen, 2.0);
/* Area of pixel as seen from crystal (approximate) */
proj_area = pix_area * cos(image->twotheta[x + image->width*y]);
/* Calculate distance from crystal to pixel */
- dsq = pow(((double)x - image->det.panels[p].cx)
- / image->det.panels[p].res, 2.0);
- dsq += pow(((double)y - image->det.panels[p].cy)
- / image->det.panels[p].res, 2.0);
+ dsq = pow(((double)x - p->cx) / p->res, 2.0);
+ dsq += pow(((double)y - p->cy) / p->res, 2.0);
/* Projected area of pixel divided by distance squared */
sa = proj_area / (dsq + Lsq);
@@ -252,3 +238,21 @@ void record_image(struct image *image, int do_water, int do_poisson,
}
}
}
+
+
+struct panel *find_panel(struct detector *det, int x, int y)
+{
+ int p;
+
+ for ( p=0; p<det->n_panels; p++ ) {
+ if ( (x >= det->panels[p].min_x)
+ && (x <= det->panels[p].max_x)
+ && (y >= det->panels[p].min_y)
+ && (y <= det->panels[p].max_y) ) {
+ return &det->panels[p];
+ }
+ }
+ ERROR("No mapping found for %i,%i\n", x, y);
+
+ return NULL;
+}
diff --git a/src/detector.h b/src/detector.h
index 4a983313..4361d580 100644
--- a/src/detector.h
+++ b/src/detector.h
@@ -41,4 +41,6 @@ struct detector
extern void record_image(struct image *image, int do_water, int do_poisson,
int do_bloom);
+extern struct panel *find_panel(struct detector *det, int x, int y);
+
#endif /* DETECTOR_H */
diff --git a/src/diffraction.c b/src/diffraction.c
index bcfee476..b24b68b0 100644
--- a/src/diffraction.c
+++ b/src/diffraction.c
@@ -144,28 +144,20 @@ struct rvec get_q(struct image *image, unsigned int xs, unsigned int ys,
float twotheta, r, az;
float rx = 0.0;
float ry = 0.0;
- int p;
+ struct panel *p;
const unsigned int x = xs / sampling;
const unsigned int y = ys / sampling; /* Integer part only */
- for ( p=0; p<image->det.n_panels; p++ ) {
- if ( (x >= image->det.panels[p].min_x)
- && (x <= image->det.panels[p].max_x)
- && (y >= image->det.panels[p].min_y)
- && (y <= image->det.panels[p].max_y) ) {
- rx = ((float)xs - (sampling*image->det.panels[p].cx))
- / (sampling * image->det.panels[p].res);
- ry = ((float)ys - (sampling*image->det.panels[p].cy))
- / (sampling * image->det.panels[p].res);
- break;
- }
- }
+ p = find_panel(&image->det, x, y);
+
+ rx = ((float)xs - (sampling*p->cx)) / (sampling * p->res);
+ ry = ((float)ys - (sampling*p->cy)) / (sampling * p->res);
/* Calculate q-vector for this sub-pixel */
r = sqrt(pow(rx, 2.0) + pow(ry, 2.0));
- twotheta = atan2(r, image->det.panels[p].clen);
+ twotheta = atan2(r, p->clen);
az = atan2(ry, rx);
if ( ttp != NULL ) *ttp = twotheta;
diff --git a/src/index.c b/src/index.c
index 49e21bb7..7439cf66 100644
--- a/src/index.c
+++ b/src/index.c
@@ -36,34 +36,20 @@ int map_position(struct image *image, double dx, double dy,
double d;
double twotheta, psi;
const double k = 1.0 / image->lambda;
- int p;
- int found = 0;
+ struct panel *p;
double x = 0.0;
double y = 0.0;
- /* Perform the detector mapping for these coordinates */
- for ( p=0; p<image->det.n_panels; p++ ) {
- if ( (dx >= image->det.panels[p].min_x)
- && (dx <= image->det.panels[p].max_x)
- && (dy >= image->det.panels[p].min_y)
- && (dy <= image->det.panels[p].max_y) ) {
- x = ((double)dx - image->det.panels[p].cx);
- y = ((double)dy - image->det.panels[p].cy);
- found = 1;
- break;
- }
- }
- if ( !found ) {
- ERROR("No mapping found for %f,%f (map_position)\n", dx, dy);
- *rx = 0.0; *ry = 0.0; *rz = 0.0;
- return 1;
- }
+ p = find_panel(&image->det, dx, dy);
+
+ x = ((double)dx - p->cx);
+ y = ((double)dy - p->cy);
/* Convert pixels to metres */
- x /= image->det.panels[p].res;
- y /= image->det.panels[p].res; /* Convert pixels to metres */
+ x /= p->res;
+ y /= p->res; /* Convert pixels to metres */
d = sqrt((x*x) + (y*y));
- twotheta = atan2(d, image->det.panels[p].clen);
+ twotheta = atan2(d, p->clen);
psi = atan2(y, x);