1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
#ifndef lint
static char SccsId[] = "%W% %G%";
#endif
/* Module: prntcurs.c (Print coordinates and value at cursor)
* Purpose: Initialize params and organize drawing the magnifier window
* Subroutine: cursval() returns: void
* Xlib calls: XCheckWindowEvent(), XSync()
* Copyright: 1998 Smithsonian Astrophysical Observatory
* You may do anything you like with this file except remove
* this copyright. The Smithsonian Astrophysical Observatory
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
* Modified: {0} Doug Mink initial version 25 Oct 1994
* {1} Doug Mink changed wcs arguments 7 Jul 1995
* {2} Doug Mink Check for wcs 18 Oct 1995
* {3} Doug Mink Drop coor. sys. change 24 Jan 1996
* {4} Doug Mink Add 3rd image coord. 16 Jul 1998
* {n} <who> -- <does what> -- <when>
*/
#include <stdio.h>
#include <X11/Xlib.h> /* X window stuff */
#include <X11/Xutil.h> /* X window manager stuff */
#include "hfiles/struct.h" /* declare structure types */
#include "hfiles/extern.h" /* extern main SAOimage parameter structures */
#include "hfiles/constant.h" /* codes */
/*
* Subroutine: print_cursor
* Purpose: print location of a dispbox event
*/
void print_cursor ( event )
XEvent *event; /* XEvent for location of mouse */
{
double bufx, bufy, filex, filey;
void get_cursor_pos();
static void print_file_value();
(void)get_cursor_pos (event, &bufx, &bufy, &filex, &filey );
(void)print_file_value ( bufx, bufy, filex, filey );
}
/*
* Subroutine: get_cursor_pos
* Purpose: Find pointer coordinates
* Xlib calls: XCheckWindowEvent(), XSync()
*/
void get_cursor_pos ( event, bufx, bufy, filex, filey )
XEvent *event; /* i: XEvent for location of mouse */
double *bufx, *bufy;
double *filex, *filey;
{
void d_trans();
/* get only the most recent mouse moved event */
XSync(dispbox.display, 0);
while( XCheckWindowEvent(dispbox.display, dispbox.ID,
PointerMotionMask, event) );
/* get buffer coordinates */
*bufx = ((double)event->xmotion.x * (double)coord.disptobuf.inx_outx) +
(double) coord.disptobuf.iadd_outx;
*bufy = ((double)event->xmotion.y * (double)coord.disptobuf.iny_outy) +
(double) coord.disptobuf.iadd_outy;
d_trans(&coord.buftofile, *bufx, *bufy, filex, filey);
}
/*
* Subroutine: print_file_value
* Purpose: Print pointer coordinates and image value
*/
static void print_file_value ( bufX, bufY, fileX, fileY )
double bufX, bufY;
double fileX, fileY;
{
int val;
static char vstring[48], string[32], cstring[48];
void d_trans();
int lstr = 32;
int iswcs();
/* double xc,yc,xf,yf;
int offscl; */
if (img.filenimg > 1)
(void)sprintf(cstring, " %7.2f %7.2f %d", fileX, fileY, img.nimage);
else
(void)sprintf(cstring, " %7.2f %7.2f", fileX, fileY);
if ((bufX < coord.buf.X1) || (bufX > coord.buf.X2) ||
(bufY < coord.buf.Y1) || (bufY > coord.buf.Y2) )
(void)printf("%s x\n", cstring);
else if (img.fiscaled ) {
double rval;
if( (buffer.filebuf == NULL) ||
(buffer.filebuf == (char *)buffer.shortbuf) ) {
/* values scaled, originals not available */
val = buffer.shortbuf[(int)bufX + ((int)bufY * coord.buf.width)];
rval = ((double)val * img.fiscale) + img.fibias;
/* print strings with spaces padding out the end */
if( val <= buffer.clipmin )
sprintf(vstring, "%s <%.5g ", cstring, rval);
else if( val >= buffer.clipmax )
sprintf(vstring, "%s >%.5g ", cstring, rval);
else
sprintf(vstring, "%s %.5g ", cstring, rval);
} else {
/* values scaled, originals in filebuf */
double fbX, fbY;
d_trans (&coord.buftofbuf, bufX, bufY, &fbX, &fbY);
if( img.storage_type == ARR_I4 ) {
rval = (double)
*((int *)(buffer.filebuf +
(((int)fbX + ((int)fbY * coord.fbuf.width)) *
sizeof(int))));
} else if( img.storage_type == ARR_R4 ) {
rval = (double)
*((float *)(buffer.filebuf +
(((int)fbX + ((int)fbY * coord.fbuf.width)) *
sizeof(float))));
} else if( img.storage_type == ARR_R8 ) {
rval = *((double *)(buffer.filebuf +
(((int)fbX + ((int)fbY * coord.fbuf.width)) *
sizeof(double))));
} else
rval = 0.0;
if( img.fscaled )
rval = img.fbias + (rval * img.fscale);
sprintf(vstring, "%s %.5g ", cstring, rval);
}
if (iswcs (wcs)) {
(void)pix2wcst (wcs,fileX,fileY,string,lstr);
(void)printf("%s %s\n",string, vstring);
/* Test inverse subroutine
(void)pix2wcs (wcs,fileX,fileY,&xc,&yc);
(void)wcs2pix (wcs,xc,yc,&xf,&yf,&offscl);
(void) printf ("(%.2f,%.2f) -> %.5f %.5f -> (%.2f,%.2f)\n",
fileX,fileY,xc,yc,xf,yf); */
}
else
(void)printf("%s\n", vstring);
}
else {
val = buffer.shortbuf[(int)bufX + ((int)bufY * coord.buf.width)];
sprintf(vstring, " %7.2f %7.2f %6d ", fileX, fileY, val);
if (iswcs (wcs)) {
pix2wcst (wcs,fileX,fileY,string,lstr);
(void)printf("%s %s\n",string, vstring);
/* Test inverse subroutine
(void)pix2wcs (wcs,fileX,fileY,&xc,&yc);
(void)wcs2pix (wcs,xc,yc,&xf,&yf,&offscl);
(void) printf ("(%.2f,%.2f) -> %.5f %.5f -> (%.2f,%.2f)\n",
fileX,fileY,xc,yc,xf,yf); */
}
else
(void)printf("%s\n", vstring);
}
}
/*
* Subroutine: d_trans
* Purpose: Perform coordinate translation on double x and y values
*/
void d_trans ( trans, xin, yin, xout, yout )
Transform *trans;
double xin, yin;
double *xout, *yout;
{
if( trans->no_rot ) {
*xout = ((double)trans->inx_outx * xin) + (double)trans->add_outx;
*yout = ((double)trans->iny_outy * yin) + (double)trans->add_outy;
} else {
*xout = (double)trans->add_outx +
((double)trans->inx_outx * xin) + ((double)trans->iny_outx * yin);
*yout = (double)trans->add_outy +
((double)trans->inx_outy * xin) + ((double)trans->iny_outy * yin);
}
}
|