IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2020, 1:54:47 PM (6 years ago)
Author:
tdeboer
Message:

revert to working Ohana build

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/extract.c

    r41164 r41340  
    11# include "data.h"
    2 
    3 /* <from> : source image, must exist
    4    <to>   : target image -- if it does not exist, it is created of size (Nx,Ny)
    5    sx, sy : source starting coordinate -- need not be on a valid image pixel
    6    nx, ny : number of source pixels -- currently must not go out of bounds -> allow out-of-bounds
    7    Sx, Sy : target starting coordinate -- need not be on a valid image pixel
    8    Nx, Ny : redundant information UNLESS <to> does exist (in which case it is required information) -> make Nx,Ny optional if <to> exists?
    9  */
    102
    113int extract (int argc, char **argv) {
    124 
    13   int N;
     5  int i, j;
     6  float *Vin, *Vout;
     7  int sx, sy, nx, ny, NX, NY;
     8  int Sx, Sy, Nx, Ny;
    149  Buffer *in, *out;
    15 
    16   float initValue = 0.0;
    17   int initOutput = FALSE;
    18   if ((N = get_argument (argc, argv, "-init"))) {
    19     remove_argument (N, &argc, argv);
    20     initValue = atof (argv[N]);
    21     remove_argument (N, &argc, argv);
    22     initOutput = TRUE;
    23   }
    2410
    2511  if (argc != 11) {
     
    2915
    3016  if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
    31   int NX = in[0].matrix.Naxis[0];
    32   int NY = in[0].matrix.Naxis[1];
     17  NX = in[0].matrix.Naxis[0];
     18  NY = in[0].matrix.Naxis[1];
    3319
    34   int sx = atof (argv[3]);
    35   int sy = atof (argv[4]);
    36   int nx = atof (argv[5]);
    37   int ny = atof (argv[6]);
     20  sx = atof (argv[3]);
     21  sy = atof (argv[4]);
     22  nx = atof (argv[5]);
     23  ny = atof (argv[6]);
    3824
    39   int Sx = atof (argv[7]);
    40   int Sy = atof (argv[8]);
    41   int Nx = atof (argv[9]);
    42   int Ny = atof (argv[10]);
     25  Sx = atof (argv[7]);
     26  Sy = atof (argv[8]);
     27  Nx = atof (argv[9]);
     28  Ny = atof (argv[10]);
    4329
    4430  if ((Sy + ny > Ny) || (Sx + nx > Nx)) {
    45     gprint (GP_ERR, "source pixels extend beyond target pixels\n");
     31    gprint (GP_ERR, "mismatch between source and dest regions\n");
    4632    gprint (GP_ERR, "%d + %d > %d or %d + %d > %d\n", Sy, ny, Ny, Sx, nx, Nx);
    47     // return (FALSE);
     33    return (FALSE);
    4834  }
    49 
    50   // XXX : allow source region to fall outside source image
    5135
    5236  /* region is not on first image */
     
    5539      (sy > in[0].matrix.Naxis[1])) {
    5640    gprint (GP_ERR, "region outside of source image\n");
    57     // return (FALSE);
     41    return (FALSE);
    5842  }
    5943
     44  if ((Sx + nx > Nx) || (Sy + ny > Ny)) {
     45    gprint (GP_ERR, "source region larger than dest region\n");
     46    return (FALSE);
     47  }
    6048  if ((Sx < 0) || (Sy < 0)) {
    6149    gprint (GP_ERR, "dest region out of range\n");
    62     // return (FALSE);
     50    return (FALSE);
    6351  }
    6452
     
    8876  }
    8977
    90   // (NX,NY) : source image dimensions
    91   // (Nx,Ny) : target image dimensions
    92 
    93   // allow (sx, sy), (Sx, Sy) to be off image
    94   // allow (sx+nx, sy+ny) to be off image
    95 
    96   // if (sx < 0) {
    97   //   nx += sx;
    98   //   sx = 0;
    99   // }
    100   // if (sx > NX) sx = NX;
    101   //
    102   // if (Sx < 0) {
    103   //   Nx += sx;
    104   //   sx = 0;
    105   // }
    106   // if (sx > NX) sx = NX;
    107  
    108   float *Vin = (float *)(in[0].matrix.buffer);
    109   float *Vout = (float *)(out[0].matrix.buffer);
    110 
    111   if (initOutput) {
    112     for (int j = 0; j < Ny; j++) {
    113       for (int i = 0; i < Nx; i++) {
    114         Vout[i + Nx*j] = initValue;
    115       }
    116     }
    117   }
    118 
    119   int Nps = NX*NY;
    120   int Npt = Nx*Ny;
    121 
    122   for (int j = 0; j < ny; j++) {
    123     if (j + sy < 0) continue; // not yet on source image
    124     if (j + Sy < 0) continue; // not yet on target image
    125     if (j + sy >= NY) continue; // past edge of source image
    126     if (j + Sy >= Ny) continue; // past edge of target image
    127 
    128     // Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 
    129     // Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx;   
    130 
    131     for (int i = 0; i < nx; i++) {
     78  for (j = 0; j < ny; j++) {
     79    if (j + sy < 0) continue;
     80    if (j + sy >= NY) continue;
     81    Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 
     82    Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx;   
     83    for (i = 0; i < nx; i++, Vin++, Vout++) {
    13284      if (i + sx < 0) continue;
    13385      if (i + sx >= NX) continue;
    134       if (i + Sx < 0) continue;
    135       if (i + Sx >= Nx) continue;
    136 
    137       int ps = i + sx + (j + sy)*NX;
    138       int pt = i + Sx + (j + Sy)*Nx;
    139 
    140       myAssert (pt >= 0, "oops 1");
    141       myAssert (pt < Npt, "oops 2");
    142 
    143       myAssert (ps >= 0, "oops 3");
    144       myAssert (ps < Nps, "oops 4");
    145 
    146       Vout[pt] = Vin[ps];
     86      *Vout = *Vin;
    14787    }
    14888  }
     
    15191
    15292}
     93
Note: See TracChangeset for help on using the changeset viewer.