IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42940


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

Location:
trunk/Ohana/src/kapa2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r42821 r42940  
    8080int           DefineSection       PROTO((int sock));
    8181int           DefineSectionByImage PROTO((int sock));
     82int           DefineSectionCenterByImage PROTO((int sock));
    8283int           SetFont             PROTO((int sock));
    8384int           EraseCurrentPlot    PROTO((void));
  • trunk/Ohana/src/kapa2/src/CheckPipe.c

    r41341 r42940  
    245245  }
    246246 
     247  if (!strcmp (word, "CSEC")) {
     248    status = DefineSectionCenterByImage (sock);
     249    KiiSendCommand (sock, 4, "DONE");
     250    FINISHED (TRUE);
     251  }
     252 
    247253  if (!strcmp (word, "MSEC")) {
    248254    status = MoveSection (sock);
  • 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}
  • trunk/Ohana/src/kapa2/src/SetGraphSize.c

    r41344 r42940  
    1919  graphic = GetGraphic ();
    2020
     21  // graphic->dx,dy : size of the full window
     22  // (x0,y0) : distance of (LL) corner of box relative to section corner
     23  // (x1,y1) : distance of (UR) corner of box relative to section corner
    2124  double X0 = graphic[0].dx * section[0].x  + x0;
    2225  double Y0 = graphic[0].dy * section[0].y  + y0;
  • trunk/Ohana/src/kapa2/src/bDrawImage.c

    r41341 r42940  
    5959  if (Xs < 0) {
    6060    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
     61    fprintf (stderr, "Xs,Ys: %d,%d\n", Xs, Ys);
     62    fprintf (stderr, "dx,dy: %d,%d\n", dx, dy);
     63    fprintf (stderr, "picture.x,y: %d,%d\n", image[0].picture.x, image[0].picture.y);
     64    fprintf (stderr, "picture.dx,dy: %d,%d\n", image[0].picture.dx, image[0].picture.dy);
    6165    abort();
    6266  }
    6367  if (buffer[0].Nx < Xs + dx) {
    6468    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
     69    fprintf (stderr, "Xs,Ys: %d,%d\n", Xs, Ys);
     70    fprintf (stderr, "dx,dy: %d,%d\n", dx, dy);
     71    fprintf (stderr, "picture.x,y: %d,%d\n", image[0].picture.x, image[0].picture.y);
     72    fprintf (stderr, "picture.dx,dy: %d,%d\n", image[0].picture.dx, image[0].picture.dy);
    6573    abort();
    6674  }
    6775  if (Ys < 0) {
    6876    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
     77    fprintf (stderr, "Xs,Ys: %d,%d\n", Xs, Ys);
     78    fprintf (stderr, "dx,dy: %d,%d\n", dx, dy);
     79    fprintf (stderr, "picture.x,y: %d,%d\n", image[0].picture.x, image[0].picture.y);
     80    fprintf (stderr, "picture.dx,dy: %d,%d\n", image[0].picture.dx, image[0].picture.dy);
    6981    abort();
    7082  }
    7183  if (buffer[0].Ny < Ys + dy) {
    7284    fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");
     85    fprintf (stderr, "Xs,Ys: %d,%d\n", Xs, Ys);
     86    fprintf (stderr, "dx,dy: %d,%d\n", dx, dy);
     87    fprintf (stderr, "picture.x,y: %d,%d\n", image[0].picture.x, image[0].picture.y);
     88    fprintf (stderr, "picture.dx,dy: %d,%d\n", image[0].picture.dx, image[0].picture.dy);
    7389    abort();
    7490  }
Note: See TracChangeset for help on using the changeset viewer.