IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2020, 2:04:27 PM (6 years ago)
Author:
tdeboer
Message:

quick undo

File:
1 edited

Legend:

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

    r41340 r41341  
    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 */
    210
    311int extract (int argc, char **argv) {
    412 
    5   int i, j;
    6   float *Vin, *Vout;
    7   int sx, sy, nx, ny, NX, NY;
    8   int Sx, Sy, Nx, Ny;
     13  int N;
    914  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  }
    1024
    1125  if (argc != 11) {
     
    1529
    1630  if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
    17   NX = in[0].matrix.Naxis[0];
    18   NY = in[0].matrix.Naxis[1];
     31  int NX = in[0].matrix.Naxis[0];
     32  int NY = in[0].matrix.Naxis[1];
    1933
    20   sx = atof (argv[3]);
    21   sy = atof (argv[4]);
    22   nx = atof (argv[5]);
    23   ny = atof (argv[6]);
     34  int sx = atof (argv[3]);
     35  int sy = atof (argv[4]);
     36  int nx = atof (argv[5]);
     37  int ny = atof (argv[6]);
    2438
    25   Sx = atof (argv[7]);
    26   Sy = atof (argv[8]);
    27   Nx = atof (argv[9]);
    28   Ny = atof (argv[10]);
     39  int Sx = atof (argv[7]);
     40  int Sy = atof (argv[8]);
     41  int Nx = atof (argv[9]);
     42  int Ny = atof (argv[10]);
    2943
    3044  if ((Sy + ny > Ny) || (Sx + nx > Nx)) {
    31     gprint (GP_ERR, "mismatch between source and dest regions\n");
     45    gprint (GP_ERR, "source pixels extend beyond target pixels\n");
    3246    gprint (GP_ERR, "%d + %d > %d or %d + %d > %d\n", Sy, ny, Ny, Sx, nx, Nx);
    33     return (FALSE);
     47    // return (FALSE);
    3448  }
     49
     50  // XXX : allow source region to fall outside source image
    3551
    3652  /* region is not on first image */
     
    3955      (sy > in[0].matrix.Naxis[1])) {
    4056    gprint (GP_ERR, "region outside of source image\n");
    41     return (FALSE);
     57    // return (FALSE);
    4258  }
    4359
    44   if ((Sx + nx > Nx) || (Sy + ny > Ny)) {
    45     gprint (GP_ERR, "source region larger than dest region\n");
    46     return (FALSE);
    47   }
    4860  if ((Sx < 0) || (Sy < 0)) {
    4961    gprint (GP_ERR, "dest region out of range\n");
    50     return (FALSE);
     62    // return (FALSE);
    5163  }
    5264
     
    7688  }
    7789
    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++) {
     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++) {
    84132      if (i + sx < 0) continue;
    85133      if (i + sx >= NX) continue;
    86       *Vout = *Vin;
     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];
    87147    }
    88148  }
     
    91151
    92152}
    93 
Note: See TracChangeset for help on using the changeset viewer.