IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25290


Ignore:
Timestamp:
Sep 8, 2009, 4:23:41 PM (17 years ago)
Author:
eugene
Message:

fix calculation of start and stop pixels to display all pixels consistently between zoom factors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/Ohana/src/kapa2/src/CursorOps.c

    r16270 r25290  
    22
    33// input coordinates are relative to the picture bounding box
     4// XXX pre-calculate fexpand, Xc, Yc when expand is set?
    45void Picture_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
    56
     
    1415 
    1516  // pixel coordinates in picture frame
    16   dx = expand*(x2 - 0.5*picture[0].dx);
    17   dy = expand*(y2 - 0.5*picture[0].dy);
     17  dx = expand*(x2 - (int)(0.5*picture[0].dx));
     18  dy = expand*(y2 - (int)(0.5*picture[0].dy));
     19
     20  // set the true center (image and screen pixel boundaries must be aligned)
     21  // Xc = (int)(picture[0].Xc / expand) * expand;
     22  // Yc = (int)(picture[0].Yc / expand) * expand;
    1823
    1924  // picture[0].X,Y is the image coordinate in the center of the picture
    20   *x1 = picture[0].flipx ? picture[0].X - dx : picture[0].X + dx;
    21   *y1 = picture[0].flipy ? picture[0].Y - dy : picture[0].Y + dy;
     25  *x1 = picture[0].flipx ? picture[0].Xc - dx : picture[0].Xc + dx;
     26  *y1 = picture[0].flipy ? picture[0].Yc - dy : picture[0].Yc + dy;
    2227}
    2328
     
    4651  }
    4752 
     53  // set the true center (image and screen pixel boundaries must be aligned)
     54  // Xc = ((int)(picture[0].Xc * expand)) / expand;
     55  // Yc = ((int)(picture[0].Yc * expand)) / expand;
     56
    4857  // pixel coordinates in picture frame
    49   dx = picture[0].flipx ? picture[0].X - x2 : x2 - picture[0].X;
    50   dy = picture[0].flipy ? picture[0].Y - y2 : y2 - picture[0].Y;
     58  dx = picture[0].flipx ? picture[0].Xc - x2 : x2 - picture[0].Xc;
     59  dy = picture[0].flipy ? picture[0].Yc - y2 : y2 - picture[0].Yc;
    5160   
    52   *x1 = expand*dx + 0.5*picture[0].dx;
    53   *y1 = expand*dy + 0.5*picture[0].dy;
     61  *x1 = expand*dx + (int)(0.5*picture[0].dx);
     62  *y1 = expand*dy + (int)(0.5*picture[0].dy);
    5463}
    5564
     
    6675
    6776// input coordinates are relative to the picture bounding box
    68 void Picture_Lower (int *i_start, int *j_start, Matrix *matrix, Picture *picture) {
     77void Picture_Lower (int *i_start, int *j_start, int *I_start, int *J_start, Matrix *matrix, Picture *picture) {
    6978
    7079  double Ix, Iy, Sx, Sy;
     
    7281  // Ix, Iy are the image coordinates of the specified screen pixel
    7382  Picture_to_Image (&Ix, &Iy, 0.0, 0.0, picture);
    74 
    75   // Ix, Iy are now limited to valid image coordinates
    76   Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
    77   Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
    7883
    7984  // round up (down) to nearest pixel boundary
     
    8489    Iy = picture[0].flipy ? (int)(Iy) : (int)(Iy) + 1;
    8590  }
     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  // I_start, J_start are the first displayed image pixel
     97  *I_start = Ix;
     98  *J_start = Iy;
    8699
    87100  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     
    94107 
    95108// input coordinates are relative to the picture bounding box
    96 void Picture_Upper (int *i_end, int *j_end, Matrix *matrix, Picture *picture) {
     109void Picture_Upper (int *i_end, int *j_end, int i_start, int j_start, Matrix *matrix, Picture *picture) {
    97110
     111  int nExtra;
    98112  double Ix, Iy, Sx, Sy;
    99113
     
    101115  Picture_to_Image (&Ix, &Iy, picture[0].dx, picture[0].dy, picture);
    102116
     117  // round down (up) to nearest pixel boundary
     118  if (Ix > (int)(Ix)) {
     119    Ix = picture[0].flipx ? (int)(Ix) + 1: (int)(Ix);
     120  }
     121  if (Iy > (int)(Iy)) {
     122    Iy = picture[0].flipy ? (int)(Iy) + 1: (int)(Iy);
     123  }
     124
    103125  // Ix, Iy are now limited to valid image coordinates
    104126  Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
    105127  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
    106128
    107   // round down (up) to nearest pixel boundary
    108   if (Ix > (int)(Ix)) {
    109     Ix = picture[0].flipx ? (int)(Ix) + 1 : (int)(Ix);
    110   }
    111   if (Iy > (int)(Iy)) {
    112     Iy = picture[0].flipy ? (int)(Iy) + 1: (int)(Iy);
    113   }
     129  // I_end, J_end are the last displayed image pixel
     130  // *I_end = Ix;
     131  // *J_end = Iy;
    114132
    115133  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
     
    119137  *i_end = MIN (MAX (Sx, 0), picture[0].dx);
    120138  *j_end = MIN (MAX (Sy, 0), picture[0].dy);
     139
     140  // round off error can leave us with a small number of extra pixels here.
     141  if (picture[0].expand > 1) {
     142    nExtra = (*i_end - i_start) % picture[0].expand;
     143    *i_end -= nExtra;
     144    nExtra = (*j_end - j_start) % picture[0].expand;
     145    *j_end -= nExtra;
     146  }
    121147}
Note: See TracChangeset for help on using the changeset viewer.