IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12773


Ignore:
Timestamp:
Apr 6, 2007, 6:07:30 AM (19 years ago)
Author:
eugene
Message:

adding triangle vs square options, expanding square to outer points

Location:
trunk/Ohana/src/addstar
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/include/skycells.h

    r12772 r12773  
    1111# include <arpa/inet.h>
    1212# include <glob.h>
     13
     14enum {SQUARES, TRIANGLES};
    1315
    1416typedef struct {
     
    4951
    5052int    VERBOSE;
     53int    MODE;
    5154
    5255void       SetProtect             PROTO((int mode));
     
    5760int ConfigInit_skycells (int *argc, char **argv);
    5861
    59 Image *sky_tessalation (int level, int *nimages);
    6062int sky_triangle_to_image (Image *image, SkyTriangle *triangle);
    6163int sky_triangle_coords (SkyTriangle *triangle);
     
    6567int sky_tessalation_init ();
    6668int sky_triangle_to_rectangle (Image *image, SkyTriangle *triangle);
     69
     70Image *sky_tessalation (int level, int *nimages, int mode);
     71Image *sky_tessalation_triangles (int level, int *nimages);
     72Image *sky_tessalation_squares (int level, int *nimages);
  • trunk/Ohana/src/addstar/src/args_skycells.c

    r12753 r12773  
    1919  }
    2020
     21  /* what type of output files? */
     22  MODE = SQUARES;
     23  if ((N = get_argument (argc, argv, "-triangles"))) {
     24    MODE = TRIANGLES;
     25    remove_argument (N, &argc, argv);
     26  }
     27
    2128  if (argc == 2) return (TRUE);
    2229
    23   fprintf (stderr, "USAGE: skycells (level)\n");
     30  fprintf (stderr, "USAGE: skycells (level) [-triangles] [-scale arcsec/pix]\n");
    2431  exit (2);
    2532}
  • trunk/Ohana/src/addstar/src/sky_tessalation.c

    r12772 r12773  
    44static Coords *refcoords = NULL;
    55
    6 Image *sky_tessalation (int level, int *nimages) {
    7 
    8   int i, N, Ntriangles;
     6Image *sky_tessalation (int level, int *nimages, int mode) {
     7
     8  Image *images;
     9
     10  if (mode == SQUARES) {
     11    images = sky_tessalation_squares (level, nimages);
     12    return images;
     13  }
     14
     15  if (mode == TRIANGLES) {
     16    images = sky_tessalation_triangles (level, nimages);
     17    return images;
     18  }
     19
     20  return NULL;
     21}
     22
     23Image *sky_tessalation_triangles (int level, int *nimages) {
     24
     25  int i, Ndigit, Ntriangles;
    926  SkyTriangle *tri, *new;
    10   Image *image, *outimage;
     27  Image *image;
     28  char format[16];
     29
     30  Ndigit = (int)(log10(20*pow(4.0, level))) + 1 ;
     31  snprintf (format, 16, "skytri.%%0%dd", Ndigit);
    1132
    1233  sky_tessalation_init ();
     
    2243  ALLOCATE (image, Image, Ntriangles);
    2344  for (i = 0; i < Ntriangles; i++) {
    24     // XXX add a user-option to choose betwen these
    25     // sky_triangle_to_image (&image[i], &tri[i]);
     45    sky_triangle_to_image (&image[i], &tri[i]);
     46    snprintf (image[i].name, 32, format, i);
     47  } 
     48
     49  *nimages = Ntriangles;
     50  return (image);
     51}
     52
     53Image *sky_tessalation_squares (int level, int *nimages) {
     54
     55  int i, N, Ndigit, Ntriangles;
     56  SkyTriangle *tri, *new;
     57  Image *image, *outimage;
     58  char format[16];
     59
     60  // XXX I need to adjust for the number of cell subdivisions
     61  Ndigit = (int)(log10(20*pow(4.0, level))) + 1 ;
     62  snprintf (format, 16, "skycell.%%0%dd", Ndigit);
     63
     64  sky_tessalation_init ();
     65
     66  tri = sky_base_triangles (&Ntriangles);
     67
     68  for (i = 0; i < level; i++) {
     69    new = sky_divide_triangles (tri, &Ntriangles);
     70    free (tri);
     71    tri = new;
     72  }
     73
     74  ALLOCATE (image, Image, Ntriangles);
     75  for (i = 0; i < Ntriangles; i++) {
    2676    sky_triangle_to_rectangle (&image[i], &tri[i]);
    2777  } 
    2878
    29   FILE *f1 = fopen ("par.1.dat", "w");
    30   FILE *f2 = fopen ("par.2.dat", "w");
    31 
    3279  ALLOCATE (outimage, Image, Ntriangles);
    3380  for (i = N = 0; i < Ntriangles; i++) {
    34     if (!strcmp(image[i].coords.ctype, "DROP")) {
    35       fprintf (f2, "%f %f\n", image[i].coords.crval1, image[i].coords.crval2);
    36       continue;
    37     } else {
    38       fprintf (f1, "%f %f\n", image[i].coords.crval1, image[i].coords.crval2);
    39     }
     81    if (!strcmp(image[i].coords.ctype, "DROP")) continue;
    4082    memcpy (&outimage[N], &image[i], sizeof(Image));
    41     sprintf (outimage[N].name, "test.%03d", i);
     83    snprintf (outimage[N].name, 32, format, i);
    4284    N++;
    4385  } 
    4486  free (image);
    45 
    46   fclose (f1);
    47   fclose (f2);
    4887
    4988  *nimages = N;
     
    124163  double xo, yo, xc, yc, angle, scale;
    125164  double Xmin, Xmax, Ymin, Ymax;
     165  double dB, dP, s1, s2, r1, r2, dr, dx, dy;
    126166
    127167  // calculate the triangle coordinates in r,d
     
    149189  assert (peak != -1);
    150190
     191  // angle is from the center to the peak corner
     192  angle = atan2(parity*xv[peak], parity*yv[peak]); // note that this is x/y not y/x (and in radians)
     193
    151194  // find the base and height
    152195  b1 = (peak + 1) % 3;
     
    156199  xo = 0.5*(xv[b2] + xv[b1]);
    157200  yo = 0.5*(yv[b2] + yv[b1]);
     201
     202  // find the max perpendicular distance from the peak
     203
     204  // dB[b1] == dB[b2] (since xo,yo is the midpoint of [b1] to [b2]
     205  dB = hypot(xo      -xv[b1], yo      -yv[b1]);
     206  dP = hypot(xv[peak]-xo,     yv[peak] -yo);
     207             
     208  // XXX we could just choose the point based on s1 vs s2...
     209  s1 = hypot(xv[peak]-xv[b1], yv[peak]-yv[b1]);
     210  s2 = hypot(xv[peak]-xv[b2], yv[peak]-yv[b2]);
     211
     212  r1 = (SQ(s1) - SQ(dB) - SQ(dP)) / (2*dP);
     213  r2 = (SQ(s2) - SQ(dB) - SQ(dP)) / (2*dP);
     214
     215  // dr >= 0
     216  dr = MAX (r1, r2);
     217
     218  dx = -parity*dr*sin(angle);
     219  dy = -parity*dr*cos(angle);
     220
     221  xo += dx;
     222  yo += dy;
    158223
    159224  // xc, yc is the true image center
     
    163228  NX = hypot((xv[b2]-xv[b1]),(yv[b2]-yv[b1]));
    164229  NY = hypot((xv[peak]-xo),(yv[peak]-yo));
    165   angle = atan2(parity*xv[peak], parity*yv[peak]); // note that this is x/y not y/x (and in radians)
     230
    166231
    167232  memset (image, 0, sizeof(Image));
  • trunk/Ohana/src/addstar/src/skycells.c

    r12753 r12773  
    1717  level = atoi (argv[1]);
    1818
    19   images = sky_tessalation (level, &Nimages);
     19  images = sky_tessalation (level, &Nimages, MODE);
    2020
    2121  /*** update the image table ***/
Note: See TracChangeset for help on using the changeset viewer.