IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 27, 2008, 1:24:12 PM (18 years ago)
Author:
eugene
Message:

unified zoom and remap functions to include flips and wide-view image

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/src/CursorOps.c

    r16255 r16256  
    11# include "Ximage.h"
    22
    3 void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
     3// input coordinates are relative to the picture bounding box
     4void Picture_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
    45
    5   double xs, ys, expand;
     6  double expand;
    67
    78  expand = 1.0;
     
    1213  }
    1314 
    14   // pixel coordinates in picture frame
    15   xs = x2 - picture[0].x;
    16   ys = y2 - picture[0].y;
    17 
    18   // picture[0].X,Y is the offset relative to picture[0].Xo,Yo
    19   *x1 = expand*(xs - 0.5*picture[0].dx) + picture[0].Xo - picture[0].X;
    20   *y1 = expand*(ys - 0.5*picture[0].dy) + picture[0].Yo - picture[0].Y;
     15  // picture[0].X,Y is the image coordinate in the center of the picture
     16  *x1 = expand*(x2 - 0.5*picture[0].dx) + picture[0].X;
     17  *y1 = expand*(y2 - 0.5*picture[0].dy) + picture[0].Y;
    2118}
    2219
    23 void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) {
     20// input coordinates are relative to the X window
     21void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
    2422
    25   double xs, ys, expand;
     23  double xp, yp;
     24
     25  // pixel coordinates in picture frame
     26  xp = x2 - picture[0].x;
     27  yp = y2 - picture[0].y;
     28
     29  Picture_to_Image (x1, y1, xp, yp, picture);
     30}
     31
     32void Image_to_Picture (double *x1, double *y1, double x2, double y2, Picture *picture) {
     33
     34  double expand;
    2635
    2736  /* notice that here, expand is the reciprocal of the expand above */
     
    3443 
    3544  // pixel coordinates in picture frame
    36   xs = expand*(x2 - picture[0].Xo + picture[0].X) + 0.5*picture[0].dx;
    37   ys = expand*(y2 - picture[0].Yo + picture[0].Y) + 0.5*picture[0].dy;
     45  *x1 = expand*(x2 - picture[0].X) + 0.5*picture[0].dx;
     46  *y1 = expand*(y2 - picture[0].Y) + 0.5*picture[0].dy;
     47}
     48
     49void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) {
     50
     51  double xp, yp;
     52
     53  Image_to_Picture (&xp, &yp, x2, y2, picture);
    3854
    3955  // pixel coordinates in screen frame
    40   *x1 = xs + picture[0].x;
    41   *y1 = ys + picture[0].y;
     56  *x1 = xp + picture[0].x;
     57  *y1 = yp + picture[0].y;
    4258}
    4359
     60// input coordinates are relative to the picture bounding box
     61void Picture_Lower (int *i_start, int *j_start, Matrix *matrix, Picture *picture) {
     62
     63  double Ix, Iy, Sx, Sy;
     64
     65  // Ix, Iy are the image coordinates of the specified screen pixel
     66  Picture_to_Image (&Ix, &Iy, 0.0, 0.0, picture);
     67
     68  // Ix, Iy are now limited to valid image coordinates
     69  Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
     70  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
     71
     72  // round up to nearest pixel boundary
     73  if (Ix > (int)(Ix)) Ix = (int)(Ix) + 1;
     74  if (Iy > (int)(Iy)) Iy = (int)(Iy) + 1;
     75
     76  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     77  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
     78
     79  // i_start, j_start are now limited to valid screen coordinates
     80  *i_start = MIN (MAX (Sx, 0), picture[0].dx);
     81  *j_start = MIN (MAX (Sy, 0), picture[0].dy);
     82}
     83 
     84// input coordinates are relative to the picture bounding box
     85void Picture_Upper (int *i_end, int *j_end, Matrix *matrix, Picture *picture) {
     86
     87  double Ix, Iy, Sx, Sy;
     88
     89  // Ix, Iy are the image coordinates of the specified screen pixel
     90  Picture_to_Image (&Ix, &Iy, picture[0].dx, picture[0].dy, picture);
     91
     92  // Ix, Iy are now limited to valid image coordinates
     93  Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
     94  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
     95
     96  // round down to nearest pixel boundary
     97  if (Ix > (int)(Ix)) Ix = (int)(Ix);
     98  if (Iy > (int)(Iy)) Iy = (int)(Iy);
     99
     100  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     101  Image_to_Picture (&Sx, &Sy, Ix, Iy, picture);
     102
     103  // i_start, j_start are now limited to valid screen coordinates
     104  *i_end = MIN (MAX (Sx, 0), picture[0].dx);
     105  *j_end = MIN (MAX (Sy, 0), picture[0].dy);
     106}
Note: See TracChangeset for help on using the changeset viewer.