IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32695 for trunk/Ohana


Ignore:
Timestamp:
Nov 17, 2011, 2:17:35 PM (15 years ago)
Author:
eugene
Message:

fix psphotStack 2nd pass (subtract 1st pass sources from the correct image); fix PS color plotting; plug a leak in psphotStack

Location:
trunk
Files:
17 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Ohana/src/kapa2/include/prototypes.h

    r30606 r32695  
    126126void          PSPixmap24          PROTO((Graphic *graphic, KapaImageWidget *image, FILE *f));
    127127void          PSPixmap32          PROTO((Graphic *graphic, KapaImageWidget *image, FILE *f));
     128void          PSPixmap_3byte      PROTO((Graphic *graphic, KapaImageWidget *image, FILE *f));
    128129
    129130/* kapa bDraw Functions */
  • trunk/Ohana/src/kapa2/include/structures.h

    r29938 r32695  
    2626  XFontStruct   *font;
    2727  Cursor         cursor;
    28   int            x,  y;
    29   unsigned int   dx, dy;
     28  int            x,  y;       // corner coord in X world coords
     29  unsigned int   dx, dy;      // size of window in X coords
     30  int            xwin, ywin;  // corner coord of display subregion (eg, png, ps plot)
     31  int            dxwin, dywin; // corner coord of display subregion (eg, png, ps plot)
    3032  CCNode        *cube;
    3133  XColor        *cmap;
  • trunk/Ohana/src/kapa2/src/PSPixmap.c

    r16256 r32695  
    11# include "Ximage.h"
    2 
    3 // XXX this stuff has been broken by the conversion to the pixmap stuff
    42
    53void PSPixmap8 (Graphic *graphic, KapaImageWidget *image, FILE *f) {
     
    146144}
    147145
    148 # if (0)
    149 // XXX needs work!
    150 void PSPixmap32_RGB (Graphic *graphic, KapaImageWidget *image, FILE *f) {
    151 
    152   int i, k, m, val;
    153   double Nchar, Npix, start, slope, frac;
    154   unsigned int *buff;
    155   unsigned long back;
    156   unsigned char
    157 
    158   ALLOCATE (pixelR, unsigned char, graphic[0].Npixels);
    159   ALLOCATE (pixelG, unsigned char, graphic[0].Npixels);
    160   ALLOCATE (pixelB, unsigned char, graphic[0].Npixels);
     146# define WHITE_R 255
     147# define WHITE_G 255
     148# define WHITE_B 255
     149
     150void PSPixmap_3byte (Graphic *graphic, KapaImageWidget *image, FILE *f) {
     151
     152  int i, j, ii, jj;
     153  int i_start, i_end, j_start, j_end;
     154  int I_start, J_start;
     155  int dropback;  /* this is a bit of a kludge... */
     156  int dx, dy, DX, DY, inDX, inDY, Xs, Ys;
     157  int expand_in, expand_out;
     158  double expand, Ix, Iy;
     159  unsigned short *in_pix, *in_pix_ref;
     160  unsigned char *pixel1, *pixel2, *pixel3;
     161
     162  if (image == NULL) return;
     163
     164  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
     165  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     166  ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);
    161167
    162168  /** cmap[i].pixel must be defined even if X is not used **/
    163169  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    164     pixelR[i] = graphic[0].cmap[i].red >> 8;
    165     pixelG[i] = graphic[0].cmap[i].green >> 8;
    166     pixelB[i] = graphic[0].cmap[i].blue >> 8;
    167   }
    168 
    169   for (i = 0; i < image[0].picture.dy; i++) {
    170     for (k = 0; k < image[0].picture.dx; k++, buff++) {
    171       if (*buff == back)
    172         val = Nchar;
    173       else {
    174         for (m = 0; (graphic[0].cmap[m].pixel != *buff) && (m < Npix); m++);
    175         val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
    176       }
    177       fprintf (f, "%02x", val);
    178       if (!((k+1) % 40)) fprintf (f, "\n");
    179     }
    180     fprintf (f, "\n");
    181     buff -= 2*image[0].picture.dx;
    182   }
    183   return;
    184 }
    185 # endif
     170    pixel1[i] = graphic[0].cmap[i].red >> 8;
     171    pixel2[i] = graphic[0].cmap[i].green >> 8;
     172    pixel3[i] = graphic[0].cmap[i].blue >> 8;
     173  }
     174
     175  assert ((image[0].picture.expand >= 1) || (image[0].picture.expand <= -2));
     176  expand = expand_in = expand_out = 1.0;
     177  if (image[0].picture.expand > 0) {
     178    expand = 1 / (1.0*image[0].picture.expand);
     179    expand_out = image[0].picture.expand;
     180    expand_in  = 1;
     181  }
     182  if (image[0].picture.expand < 0) {
     183    expand = fabs((double)image[0].picture.expand);
     184    expand_out = 1;
     185    expand_in  = -image[0].picture.expand;
     186  }
     187
     188  Xs = image[0].picture.x;
     189  Ys = image[0].picture.y;
     190  dx = image[0].picture.dx;
     191  dy = image[0].picture.dy;
     192  DX = image[0].image[0].matrix.Naxis[0];
     193  DY = image[0].image[0].matrix.Naxis[1];
     194
     195  // i_start, j_start are the closest lit screen pixel to 0,0
     196  // I_start, J_start are the image pixel corresponding to i_start, j_start
     197  Picture_Lower (&i_start, &j_start, &I_start, &J_start, &image[0].image[0].matrix, &image[0].picture);
     198
     199  // i_end, j_end are the closest lit screen pixel to dx, dy
     200  // I_end, J_end are the image pixel corresponding to i_end, j_end
     201  Picture_Upper (&i_end, &j_end, i_start, j_start, &image[0].image[0].matrix, &image[0].picture);
     202
     203  assert (i_start <= i_end);
     204  assert (j_start <= j_end);
     205
     206  Ix = image[0].picture.flipx ? I_start - 1 : I_start;
     207  Iy = image[0].picture.flipy ? J_start - 1 : J_start;
     208
     209  inDX = image[0].picture.flipx ? -1 : +1;
     210  inDY = image[0].picture.flipy ? -1 : +1;
     211
     212  dropback = expand_out - (i_end - i_start) % expand_out;
     213  if ((i_end - i_start) % expand_out == 0) dropback = 0;
     214
     215  in_pix_ref  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
     216
     217  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     218
     219  // add in occasional return chars
     220
     221  /**** fill in bottom area ****/
     222  for (j = 0; j < j_start; j++) {
     223    for (i = 0; i < dx; i++) {
     224      fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     225    }
     226  }
     227 
     228  // probably could do this all smarter with scale operations in PS...
     229
     230  /*** fill in the image data region ***/
     231  for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += inDY*expand_in*DX) {
     232   
     233    // repeat the section below 'expand_out' times
     234    for (jj = 0; jj < expand_out; jj++) {
     235
     236      /* create one output image line */
     237      in_pix = in_pix_ref;
     238
     239      /**** fill in area to the left of the picture ****/
     240      for (i = 0; i < i_start; i++) {
     241        fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     242      }
     243   
     244      /*** fill in the picture region ***/
     245      for (i = i_start; i < i_end; i+=expand_out, in_pix += inDX*expand_in) {
     246        for (ii = 0; ii < expand_out; ii++) {
     247          fprintf (f, "%02x%02x%02x", pixel1[*in_pix], pixel2[*in_pix], pixel3[*in_pix]);
     248        }
     249      }
     250   
     251      /**** fill in area to the right of the picture ****/
     252      for (i = i_end; i < dx; i++) {
     253        fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     254      }
     255    }
     256  }
     257
     258  /**** fill in top area ****/
     259  for (j = j_end; j < dy; j++) {
     260    for (i = 0; i < dx; i++) {
     261      fprintf (f, "%02x%02x%02x", WHITE_R, WHITE_G, WHITE_B);
     262    }
     263  }
     264
     265  free (pixel1);
     266  free (pixel2);
     267  free (pixel3);
     268
     269  return;
     270}
  • trunk/Ohana/src/kapa2/src/PSimage.c

    r29938 r32695  
    1313  graphic = GetGraphic();
    1414
     15  // Update this to generate color PS images: I need to test if the image if color or BW (based
     16  // on the colormap).  If it is a color image, I need to generate a 24 bit image. the header
     17  // should look the same (Nx Ny 8 [1 0 0 1 0 0]) but then it should finish with "false 3
     18  // colorimage" instead of just "image" (see ../doc/color.image.s for an example).  the hex
     19  // string needs to have RGB represented as chars (2 hex chars per R,G,B).
     20  // the values come from the following map: image[0].pixmap[i] -> cmap[pixel].red -> R (0-255)
     21
    1522  fprintf (f, " newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath\n\n",
    1623           (int) image[0].picture.x,                       graphic->dy - (int) image[0].picture.y,
     
    2128  fprintf (f, "%d %d translate\n", (int) image[0].picture.x, graphic->dy - (int) image[0].picture.y - image[0].picture.dy);
    2229  fprintf (f, "%d %d 8\n", image[0].picture.dx, image[0].picture.dy);
    23   fprintf (f, "[1 0 0 1 0 0]\n");
     30  fprintf (f, "[1 0 0 -1 0 %d]\n", image[0].picture.dy);
     31  // write out the image in normal order, but flip in PS
     32
     33# if (0)
     34
    2435  fprintf (f, "{currentfile %d string readhexstring pop} image\n\n", image[0].picture.dx);
     36  PSPixmap_1byte (graphic, image, f);
    2537
    26   /******** First we draw the picture itself ********/
    27   /* in !USE_XWINDOW, we'll have to change this to use the JPEG function */
    28   switch (graphic[0].Nbits) {
    29   case 8:
    30     PSPixmap8 (graphic, image, f);
    31     break;
    32   case 16:
    33     PSPixmap16 (graphic, image, f);
    34     break;
    35   case 24:
    36     PSPixmap24 (graphic, image, f);
    37     break;
    38   case 32:
    39     PSPixmap32 (graphic, image, f);
    40     break;
    41   }
     38# else
     39
     40  fprintf (f, "{currentfile %d string readhexstring pop} false 3 colorimage\n\n", 3*image[0].picture.dx);
     41  PSPixmap_3byte (graphic, image, f);
     42
     43# endif
    4244
    4345  fprintf (f, "grestore %% end of image\n");
  • trunk/Ohana/src/kapa2/src/Sections.c

    r27790 r32695  
    237237  return (TRUE);
    238238}
     239
     240int SectionMinBoundary (Graphic *graphic) {
     241
     242    int i;
     243    int Xs = graphic->dx;
     244    int Ys = graphic->dy;
     245    int Xe = 0;
     246    int Ye = 0;
     247
     248    // the boundary for a single section should probably be adjusted depending on the
     249    // image status (should not include the imtool portion)
     250    for (i = 0; i < Nsections; i++) {
     251        Xs = MIN (Xs, sections[i][0].x);
     252        Ys = MIN (Ys, sections[i][0].y);
     253        Xe = MAX (Xe, sections[i][0].x + sections[i][0].dx);
     254        Ye = MAX (Ye, sections[i][0].y + sections[i][0].dy);
     255    }
     256
     257    if ((Xs >= Xe) || (Ys >- Ye)) {
     258        // default values for the region window
     259        graphic->xwin  = 0;
     260        graphic->ywin  = 0;
     261        graphic->dxwin = graphic->dx;
     262        graphic->dywin = graphic->dy;
     263    }   
     264   
     265    // set min/max boundary (min window containing max range of sections)
     266    graphic->xwin = Xs;
     267    graphic->ywin = Ys;
     268    graphic->dxwin = Xe - Xs;
     269    graphic->dywin = Ye - Ys;
     270    return TRUE;
     271}
  • trunk/Ohana/src/kapa2/src/SetUpGraphic.c

    r25757 r32695  
    1616  graphic->dx = 512;
    1717  graphic->dy = 512;
     18
     19  // default values for the region window
     20  graphic->xwin  = 0;
     21  graphic->ywin  = 0;
     22  graphic->dxwin = graphic->dx;
     23  graphic->dywin = graphic->dy;
    1824
    1925  if (!USE_XWINDOW) {
  • trunk/Ohana/src/kapa2/src/bDrawImage.c

    r29938 r32695  
    4747  }
    4848
    49   Xs = image[0].picture.x;
    50   Ys = image[0].picture.y;
     49  // Xs,Ys are in full-frame coords.  can we trim here?
     50  Xs = image[0].picture.x - graphic[0].xwin;
     51  Ys = image[0].picture.y - graphic[0].ywin;
    5152  dx = image[0].picture.dx;
    5253  dy = image[0].picture.dy;
     
    5455  DY = image[0].image[0].matrix.Naxis[1];
    5556
     57  // the created buffer is supposed to contain the output windows
    5658  if (buffer[0].Nx < Xs + dx) {
    5759    fprintf (stderr, "invalid condition\n");
  • trunk/Ohana/src/kapa2/src/bDrawIt.c

    r29938 r32695  
    1313  black = KapaColorByName ("black");
    1414
    15   buffer = bDrawBufferCreate (graphic->dx, graphic->dy, Nbyte, palette, Npalette);
     15  // SectionMinBoundary (graphic);
     16
     17  // if we want to trim, we'll need to carry about the start in graphic coords and
     18  // the dx,dy size. 
     19  buffer = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette);
    1620  bDrawSetStyle (buffer, black, 0, 0);
    1721 
  • trunk/Ohana/src/libdvo/src/dbExtractMeasures.c

    r31635 r32695  
    245245      break;
    246246    case MEAS_PAR: /* OK */
    247       value.Flt = average[0].R;
     247      value.Flt = average[0].P;
    248248      break;
    249249    case MEAS_PAR_ERR: /* OK */
    250       value.Flt = average[0].D;
     250      value.Flt = average[0].dP;
    251251      break;
    252252    case MEAS_CHISQ_POS: /* OK */
  • trunk/Ohana/src/libkapa/src/PSRotFont.c

    r30603 r32695  
    3232  dY = currentfont[65].ascent;
    3333 
     34  /***
     35
     36      update this to use the following PS code:
     37
     38      /ceshow { % (string) fontsize fontname x y
     39      gsave
     40      moveto findfont exch scalefont setfont % s
     41      gsave
     42      dup false charpath flattenpath pathbbox % s x0 y0 x1 y1
     43      grestore
     44      3 -1 roll sub % s x0 x1 dy
     45      3 1 roll sub % s dy -dx
     46      2 div exch % s -dx/2 dy
     47      -2 div % s -dx/2 -dy/2
     48      rmoveto show
     49      grestore
     50      } bind def
     51
     52   ***/
     53
    3454  /* apply appropriate offset */
    3555  Xoff = Yoff = 0;
  • trunk/Ohana/src/relastro/include/relastro.h

    r32346 r32695  
    317317int sun_ecliptic (double jd, double *lambda, double *beta, double *epsilon);
    318318int ParFactor (double *pR, double *pD, double R, double D, double T, double Tmean);
    319 int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts);
     319int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts, int XVERB);
    320320int FitPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *pR, double *pD, int Npts);
    321 int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts);
     321int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts, int XVERB);
    322322
    323323Mosaic *getMosaicForImage (off_t N);
  • trunk/Ohana/src/relastro/src/FitPM.c

    r32346 r32695  
    22
    33/* do we want an init function which does the alloc and a clear function to free? */
    4 int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts) {
     4int FitPM (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts, int XVERB) {
    55
    66  int i;
     
    7777    chisq += SQ(X[i] - Xf) / SQ(dX[i]);
    7878    chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
     79    if (XVERB) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
    7980  }
    8081  fit[0].Nfit = Npts;
  • trunk/Ohana/src/relastro/src/FitPMandPar.c

    r32346 r32695  
    22
    33/* do we want an init function which does the alloc and a clear function to free? */
    4 int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts) {
     4int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts, int XVERB) {
    55
    66  int i;
     
    9999  chisq = 0.0;
    100100  for (i = 0; i < Npts; i++) {
    101     Xf = fit[0].Ro + fit[0].uR*T[i] + fit[0].dp*pR[i];
    102     Yf = fit[0].Do + fit[0].uD*T[i] + fit[0].dp*pD[i];
     101    Xf = fit[0].Ro + fit[0].uR*T[i] + fit[0].p*pR[i];
     102    Yf = fit[0].Do + fit[0].uD*T[i] + fit[0].p*pD[i];
    103103    chisq += SQ(X[i] - Xf) / SQ(dX[i]);
    104104    chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
     105    if (XVERB) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
     106
    105107  }
    106108  fit[0].Nfit = Npts;
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r32346 r32695  
    913913  if (!finite(measure[0].dR) || !finite(measure[0].dD)) return FALSE;
    914914  if (!finite(measure[0].M)) return FALSE; //XXX is this necessary for all relastro tasks?
     915  if (!finite(measure[0].dM)) return FALSE; //XXX is this necessary for all relastro tasks?
    915916 
    916917  /* select measurements by photcode, or equiv photcode, if specified */
  • trunk/Ohana/src/relastro/src/UpdateObjects.c

    r32346 r32695  
    8484      /* calculate the average value of R,D for a single star */
    8585
     86      XVERB = FALSE;
     87
    8688      // skip objects which are known to be problematic
    8789      // XXX include this code or not?
     
    196198      }
    197199     
    198       XVERB = (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY);
     200      // XVERB |= (catalog[i].averge[j].objID == 0xc90) && (catalog[i].average[j].catID == 0x2a1e);
     201      XVERB |= (catalog[i].average[j].objID == OBJ_ID_SRC) && (catalog[i].average[j].catID == CAT_ID_SRC);
     202      XVERB |= (catalog[i].average[j].objID == OBJ_ID_DST) && (catalog[i].average[j].catID == CAT_ID_DST);
     203      // XVERB = (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY);
    199204
    200205      // to judge the quality of the PM and PAR fits, we need to fit all three models and compare Chisq
     
    211216        }         
    212217
    213         FitPM (&fitPM, X, dX, Y, dY, T, N);
    214 
    215         if (XVERB) fprintf (stderr, "fitted:  %f - %f : %f %f : %f %f : %f vs %f\n", Tmin, Tmax, fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.chisq, fitAve.chisq);
     218        FitPM (&fitPM, X, dX, Y, dY, T, N, XVERB);
     219
     220        if (XVERB) fprintf (stderr, "fitted PM:  %f - %f : %f %f : %f %f : %f vs %f\n", Tmin, Tmax, fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.chisq, fitAve.chisq);
    216221
    217222        // project Ro, Do back to RA,DEC
     
    230235          ParFactor (&pX[k], &pY[k], R[k], D[k], T[k], Tmean);
    231236        }
    232         FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N);
     237        FitPMandPar (&fitPAR, X, dX, Y, dY, T, pX, pY, N, XVERB);
    233238        XY_to_RD (&fitPAR.Ro, &fitPAR.Do, fitPAR.Ro, fitPAR.Do, &coords);
    234239        catalog[i].average[j].flags |= ID_STAR_FIT_PAR;
     
    275280        break;
    276281      }
    277       if (XVERB) fprintf (stderr, "A%f %f -> %f %f (%f,%f) pm=(%f %f)\n",
     282      if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f)\n",
    278283                          catalog[i].average[j].R,
    279284                          catalog[i].average[j].D,
  • trunk/Ohana/src/relastro/src/args.c

    r32346 r32695  
    1414  FIT_MODE = FIT_AVERAGE;
    1515
     16  OBJ_ID_SRC = OBJ_ID_DST = 0;
     17  CAT_ID_SRC = CAT_ID_DST = 0;
     18
    1619  if ((N = get_argument (argc, argv, "-merge-source"))) {
    1720    if (N > argc - 6) usage_merge_source();
     
    4043    remove_argument (N, &argc, argv);
    4144    FIT_TARGET = TARGET_OBJECTS;
     45  }
     46
     47  if ((N = get_argument (argc, argv, "-testobj1"))) {
     48    if (N > argc - 3) usage ();
     49    remove_argument (N, &argc, argv);
     50    OBJ_ID_SRC = strtol(argv[N], &endptr, 0);
     51    if (*endptr) usage ();
     52    remove_argument (N, &argc, argv);
     53    CAT_ID_SRC = strtol(argv[N], &endptr, 0);
     54    if (*endptr) usage ();
     55    remove_argument (N, &argc, argv);
     56  }
     57
     58  if ((N = get_argument (argc, argv, "-testobj2"))) {
     59    if (N > argc - 3) usage ();
     60    remove_argument (N, &argc, argv);
     61    OBJ_ID_DST = strtol(argv[N], &endptr, 0);
     62    if (*endptr) usage ();
     63    remove_argument (N, &argc, argv);
     64    CAT_ID_DST = strtol(argv[N], &endptr, 0);
     65    if (*endptr) usage ();
     66    remove_argument (N, &argc, argv);
    4267  }
    4368
Note: See TracChangeset for help on using the changeset viewer.