aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-03-01 14:33:09 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:16 +0100
commita4ca7e3e65e4fbd36062b9c4f8d26c78b97d3fde (patch)
tree5c4725af4dc26f22597453dc009cf57cf7dedb3d
parent6341b8ee8d9be0b6fed14cf418161706e4caa5c5 (diff)
hdfsee: Do "numbers" according to geometry
-rw-r--r--src/detector.c40
-rw-r--r--src/detector.h2
-rw-r--r--src/displaywindow.c28
3 files changed, 58 insertions, 12 deletions
diff --git a/src/detector.c b/src/detector.c
index 703a7189..34ae8bea 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -561,15 +561,55 @@ struct detector *simple_geometry(const struct image *image)
geom->panels[0].max_ss = image->height-1;
geom->panels[0].cnx = -image->width / 2.0;
geom->panels[0].cny = -image->height / 2.0;
+
geom->panels[0].fsx = 1;
geom->panels[0].fsy = 0;
geom->panels[0].ssx = 0;
geom->panels[0].ssy = 1;
+ geom->panels[0].xfs = 1;
+ geom->panels[0].xss = 0;
+ geom->panels[0].yfs = 0;
+ geom->panels[0].yss = 1;
+
return geom;
}
+int reverse_2d_mapping(double x, double y, double *pfs, double *pss,
+ struct detector *det)
+{
+ int i;
+
+ for ( i=0; i<det->n_panels; i++ ) {
+
+ struct panel *p = &det->panels[i];
+ double cx, cy, fs, ss;
+
+ /* Get position relative to corner */
+ cx = x - p->cnx;
+ cy = y - p->cny;
+
+ /* Reverse the transformation matrix */
+ fs = cx*p->xfs + cy*p->yfs;
+ ss = cx*p->xss + cy*p->yss;
+
+ /* In range? */
+ if ( fs < 0 ) continue;
+ if ( ss < 0 ) continue;
+ if ( fs > (p->max_fs-p->min_fs+1) ) continue;
+ if ( ss > (p->max_ss-p->min_ss+1) ) continue;
+
+ *pfs = fs + p->min_fs;
+ *pss = ss + p->min_ss;
+ return 0;
+
+ }
+
+ return 1;
+}
+
+
static void check_extents(struct panel p, double *min_x, double *min_y,
double *max_x, double *max_y, double fs, double ss)
{
diff --git a/src/detector.h b/src/detector.h
index a232b712..6821ad27 100644
--- a/src/detector.h
+++ b/src/detector.h
@@ -78,5 +78,7 @@ extern void get_pixel_extents(struct detector *det,
extern void fill_in_values(struct detector *det, struct hdfile *f);
+extern int reverse_2d_mapping(double x, double y, double *pfs, double *pss,
+ struct detector *det);
#endif /* DETECTOR_H */
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 0045c191..b82e9998 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -26,6 +26,7 @@
#include "hdf5-file.h"
#include "hdfsee.h"
#include "utils.h"
+#include "detector.h"
static void displaywindow_error(DisplayWindow *dw, const char *message)
@@ -1032,22 +1033,25 @@ static void numbers_update(DisplayWindow *dw)
float val;
GtkWidget *l;
int x, y;
- int valid;
+ int invalid;
+ double dfs, dss;
+ int fs, ss;
x = dw->binning * dw->numbers_window->cx + (px-8);
y = dw->binning * dw->numbers_window->cy + (17-py-8);
-
- if ( (x>=dw->image->width) || (y>=dw->image->height) ) {
- valid = 0;
- val = 0;
- } else {
- val = dw->image->data[x+y*dw->image->width];
- valid = 1;
+ x += dw->min_x;
+ y += dw->min_y;
+
+ /* Map from unbinned mapped pixel coordinates to a panel */
+ invalid = reverse_2d_mapping(x, y, &dfs, &dss, dw->image->det);
+ fs = dfs; ss = dss;
+ if ( !invalid ) {
+ val = dw->image->data[fs+ss*dw->image->width];
}
- if ( (x>0) && (y>0) && valid ) {
- if ( val > 0 ) {
- if ( log(val)/log(10) < 5 ) {
+ if ( !invalid ) {
+ if ( val > 0.0 ) {
+ if ( log(val)/log(10.0) < 5 ) {
snprintf(s, 31, "%.0f", val);
} else {
snprintf(s, 31, "HUGE");
@@ -1060,7 +1064,7 @@ static void numbers_update(DisplayWindow *dw)
}
}
} else {
- strcpy(s, "--");
+ strcpy(s, "-");
}
l = dw->numbers_window->labels[px+17*py];
gtk_label_set_text(GTK_LABEL(l), s);