IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 12, 2025, 4:59:11 PM (8 months ago)
Author:
eugene
Message:

add command to modify section to place image center at specified location; prevent errors if section falls outside valid window

File:
1 edited

Legend:

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

    r29938 r42940  
    99  Section *section;
    1010
     11  // XXX the background must be set using KapaSectionBG
    1112  KiiScanMessage (sock, "%s %lf %lf %lf %lf %d", name, &x, &y, &dx, &dy, &bg);
     13
     14  // truncate section to 0.0 - 1.0
     15  x = MAX(MIN(x,1.0),0.0);
     16  y = MAX(MIN(y,1.0),0.0);
     17
     18  double xmax = MAX(MIN(x + dx, 1.0), 0.0);
     19  double ymax = MAX(MIN(y + dy, 1.0), 0.0);
     20  dx = xmax - x;
     21  dy = ymax - y;
    1222
    1323  MoveSection = FALSE;
     
    1525  N = GetSectionByName (name);
    1626  if (N < 0) {
    17     section = AddSection (name, x, y, dx, dy, bg);
     27    // new section is added with transparent background
     28    section = AddSection (name, x, y, dx, dy, -1);
    1829    MoveSection = TRUE;
    1930  } else {
     
    3041    section[0].dx = dx;
    3142    section[0].dy = dy;
    32     section[0].bg = bg;
     43    // do not change bg (must use KapaSectionBG)
     44    // section[0].bg = bg;
    3345  }
    3446
     
    5668
    5769  N = GetSectionByName (name);
     70  if (N < 0)  {
     71    fprintf (stderr, "section does not yet exist\n");
     72    return (TRUE);
     73  }
    5874  section = GetSectionByNumber (N);
    5975  image = section->image;
     
    8298  section[0].x = x;
    8399  section[0].y = y;
    84   section[0].bg = bg;
     100  // section[0].bg = bg;
    85101  section[0].dx = dx / graphic[0].dx;
    86102  section[0].dy = dy / graphic[0].dy;
     
    96112  return (TRUE);
    97113}
     114
     115// define the section, but do not create a graph or image
     116int DefineSectionCenterByImage (int sock) {
     117 
     118  int N;
     119  char name[128];
     120  double x, y, dx, dy;
     121  int dXm, dXp, dYm, dYp;
     122  double x0, y0, x1, y1, expand;
     123  Section *section;
     124  Graphic *graphic;
     125  KapaImageWidget *image;
     126
     127  // x,y is the center of the image, adjust section to contain the image
     128  KiiScanMessage (sock, "%s %lf %lf", name, &x, &y);
     129
     130  N = GetSectionByName (name);
     131  if (N < 0)  {
     132    fprintf (stderr, "section does not yet exist\n");
     133    return (TRUE);
     134  }
     135  section = GetSectionByNumber (N);
     136  image = section->image;
     137  if (!image) {
     138    fprintf (stderr, "no image to define section\n");
     139    return (TRUE);
     140  }
     141  SetActiveSectionByNumber (N);
     142
     143  graphic = GetGraphic ();
     144
     145  GetGraphBoundary (section, &x0, &y0, &x1, &y1, &dXm, &dXp, &dYm, &dYp);
     146
     147  expand = 1.0;
     148  if (image[0].picture.expand > 0) {
     149    expand = image[0].picture.expand;
     150  }
     151  if (image[0].picture.expand < 0) {
     152    expand = 1.0 / fabs((double)image[0].picture.expand);
     153  }
     154
     155  // pixel dimensions of the imaging region + boundary
     156  dx = MIN (image[0].image[0].matrix.Naxis[0]*expand + x1, graphic[0].dx);
     157  dy = MIN (image[0].image[0].matrix.Naxis[1]*expand + y1, graphic[0].dy);
     158
     159  // dx,dy cannot be larger than 1.0
     160
     161  // section[0].bg = bg;
     162  section[0].dx = dx / graphic[0].dx;
     163  section[0].dy = dy / graphic[0].dy;
     164
     165  // translate the section center (x,y) to the section corner
     166
     167  // desired center of section in pixels
     168  double Xc_pix = x*graphic->dx;
     169  double Yc_pix = y*graphic->dy;
     170
     171  // this is the size if the full image fits, saturate on graphic boundary
     172  double Xs_pix = MAX(MIN(Xc_pix - 0.5*dx, graphic->dx), 0.0);
     173  double Xe_pix = MAX(MIN(Xc_pix + 0.5*dx, graphic->dx), 0.0);
     174
     175  section[0].x  = Xs_pix / graphic->dx;
     176  section[0].dx = (Xe_pix - Xs_pix) / graphic->dx;
     177 
     178  double Ys_pix = MAX(MIN(Yc_pix - 0.5*dy, graphic->dy), 0.0);
     179  double Ye_pix = MAX(MIN(Yc_pix + 0.5*dy, graphic->dy), 0.0);
     180
     181  section[0].y  = Ys_pix / graphic->dy;
     182  section[0].dy = (Ye_pix - Ys_pix) / graphic->dy;
     183
     184  // if (section[0].x != x)   MoveSection = TRUE;
     185  // if (section[0].y != y)   MoveSection = TRUE;
     186  // if (section[0].dx != dx) MoveSection = TRUE;
     187  // if (section[0].dy != dy) MoveSection = TRUE;
     188
     189  SetSectionSizes (section);
     190  Refresh ();
     191
     192  return (TRUE);
     193}
Note: See TracChangeset for help on using the changeset viewer.