Changeset 12775
- Timestamp:
- Apr 6, 2007, 5:47:41 PM (19 years ago)
- Location:
- trunk/Ohana/src/addstar
- Files:
-
- 5 edited
-
include/skycells.h (modified) (2 diffs)
-
src/args_skycells.c (modified) (2 diffs)
-
src/gstars.c (modified) (1 diff)
-
src/sky_tessalation.c (modified) (15 diffs)
-
src/skycells.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/include/skycells.h
r12773 r12775 52 52 int VERBOSE; 53 53 int MODE; 54 double SCALE; 54 55 55 56 void SetProtect PROTO((int mode)); … … 65 66 Point sky_divide_edge (Point v1, Point v2); 66 67 SkyTriangle *sky_base_triangles (int *ntriangles); 67 int sky_tessalation_init ( );68 int sky_tessalation_init (double scale); 68 69 int sky_triangle_to_rectangle (Image *image, SkyTriangle *triangle); 69 70 70 Image *sky_tessalation (int level, int *nimages, int mode );71 Image *sky_tessalation_triangles (int level, int *nimages );72 Image *sky_tessalation_squares (int level, int *nimages );71 Image *sky_tessalation (int level, int *nimages, int mode, double scale); 72 Image *sky_tessalation_triangles (int level, int *nimages, double scale); 73 Image *sky_tessalation_squares (int level, int *nimages, double scale); -
trunk/Ohana/src/addstar/src/args_skycells.c
r12773 r12775 5 5 6 6 int i, N; 7 char *ptr; 7 8 8 9 /* check for help request */ … … 26 27 } 27 28 28 if (argc == 2) return (TRUE); 29 /* what type of output files? */ 30 SCALE = 1.0; 31 if ((N = get_argument (argc, argv, "-scale"))) { 32 remove_argument (N, &argc, argv); 33 SCALE = atof (argv[N]); 34 remove_argument (N, &argc, argv); 35 } 36 37 if (argc == 2) { 38 strtol (argv[1], &ptr, 10); 39 if (*ptr == 0) return (TRUE); 40 } 29 41 30 42 fprintf (stderr, "USAGE: skycells (level) [-triangles] [-scale arcsec/pix]\n"); -
trunk/Ohana/src/addstar/src/gstars.c
r12732 r12775 1 1 # include "addstar.h" 2 3 // XXX where and when should I call RegisterMosaic??4 2 5 3 Stars *gstars (char *filename, int *Nstars, Image **images, int *Nimages, int photcode) { -
trunk/Ohana/src/addstar/src/sky_tessalation.c
r12773 r12775 1 1 # include "skycells.h" 2 2 # include "assert.h" 3 # define iSWAP(X,Y) {int tmp=(X); (X) = (Y); (Y) = tmp;} 3 4 4 5 static Coords *refcoords = NULL; 5 6 Image *sky_tessalation (int level, int *nimages, int mode) { 6 static int warned = FALSE; 7 8 Image *sky_tessalation (int level, int *nimages, int mode, double scale) { 7 9 8 10 Image *images; 9 11 10 12 if (mode == SQUARES) { 11 images = sky_tessalation_squares (level, nimages );13 images = sky_tessalation_squares (level, nimages, scale); 12 14 return images; 13 15 } 14 16 15 17 if (mode == TRIANGLES) { 16 images = sky_tessalation_triangles (level, nimages );18 images = sky_tessalation_triangles (level, nimages, scale); 17 19 return images; 18 20 } … … 21 23 } 22 24 23 Image *sky_tessalation_triangles (int level, int *nimages ) {25 Image *sky_tessalation_triangles (int level, int *nimages, double scale) { 24 26 25 27 int i, Ndigit, Ntriangles; … … 31 33 snprintf (format, 16, "skytri.%%0%dd", Ndigit); 32 34 33 sky_tessalation_init ( );35 sky_tessalation_init (scale); 34 36 35 37 tri = sky_base_triangles (&Ntriangles); … … 51 53 } 52 54 53 Image *sky_tessalation_squares (int level, int *nimages ) {55 Image *sky_tessalation_squares (int level, int *nimages, double scale) { 54 56 55 57 int i, N, Ndigit, Ntriangles; … … 62 64 snprintf (format, 16, "skycell.%%0%dd", Ndigit); 63 65 64 sky_tessalation_init ( );66 sky_tessalation_init (scale); 65 67 66 68 tri = sky_base_triangles (&Ntriangles); … … 77 79 } 78 80 81 // FILE *f1 = fopen ("center.keep.dat", "w"); 82 // FILE *f2 = fopen ("center.drop.dat", "w"); 83 79 84 ALLOCATE (outimage, Image, Ntriangles); 80 85 for (i = N = 0; i < Ntriangles; i++) { 81 if (!strcmp(image[i].coords.ctype, "DROP")) continue; 86 if (!strcmp(image[i].coords.ctype, "DROP")) { 87 // fprintf (f2, "%f %f\n", tri[i].r, tri[i].d); 88 continue; 89 } else { 90 // fprintf (f1, "%f %f\n", tri[i].r, tri[i].d); 91 } 82 92 memcpy (&outimage[N], &image[i], sizeof(Image)); 83 93 snprintf (outimage[N].name, 32, format, i); … … 85 95 } 86 96 free (image); 97 98 // fclose (f1); 99 // fclose (f2); 87 100 88 101 *nimages = N; … … 159 172 int sky_triangle_to_rectangle (Image *image, SkyTriangle *triangle) { 160 173 161 int i, n, parity, peak, b1, b2, NX, NY ;174 int i, n, parity, peak, b1, b2, NX, NY, right; 162 175 double xv[3], yv[3]; // coordinates of the vertex in the reference projection 163 176 double xo, yo, xc, yc, angle, scale; 164 177 double Xmin, Xmax, Ymin, Ymax; 165 178 double dB, dP, s1, s2, r1, r2, dr, dx, dy; 179 double angle_b1, angle_b2, slope; 166 180 167 181 // calculate the triangle coordinates in r,d … … 195 209 b1 = (peak + 1) % 3; 196 210 b2 = (peak + 2) % 3; 211 212 // angle is from the center to the peak corner 213 angle_b1 = DEG_RAD*atan(yv[b1] / xv[b1]); 214 angle_b2 = DEG_RAD*atan(yv[b2] / xv[b2]); 215 216 // if one of the base-center angles is very small, the parity is marginal. Use additional 217 // information to choose the parity. note that both angle_b1 and angle_b2 cannot be close to 218 // zero. 219 if (fabs(angle_b1) < 10.0) { 220 right = (xv[b1] > 0); // pointing left or right? 221 slope = (xv[peak] - xv[b2]) / (yv[peak] - yv[b2]); 222 if ( right && (slope >= 0.0)) parity = +1; 223 if ( right && (slope < 0.0)) parity = -1; 224 if (!right && (slope <= 0.0)) parity = +1; 225 if (!right && (slope > 0.0)) parity = -1; 226 if (parity > 0) { 227 if (yv[peak] < yv[b2]) iSWAP(peak, b2); // require peak to be top (bottom) point 228 } else { 229 if (yv[peak] > yv[b2]) iSWAP(peak, b2); // require peak to be top (bottom) point 230 } 231 angle = atan2(parity*xv[peak], parity*yv[peak]); // note that this is x/y not y/x (and in radians) 232 } 233 if (fabs(angle_b2) < 10.0) { 234 right = (xv[b2] > 0); // pointing left or right? 235 slope = (xv[peak] - xv[b1]) / (yv[peak] - yv[b1]); // tilt of opposite line 236 if ( right && (slope >= 0.0)) parity = +1; 237 if ( right && (slope < 0.0)) parity = -1; 238 if (!right && (slope <= 0.0)) parity = +1; 239 if (!right && (slope > 0.0)) parity = -1; 240 if (parity > 0) { 241 if (yv[peak] < yv[b1]) iSWAP(peak, b1); // require peak to be top (bottom) point 242 } else { 243 if (yv[peak] > yv[b1]) iSWAP(peak, b1); // require peak to be top (bottom) point 244 } 245 angle = atan2(parity*xv[peak], parity*yv[peak]); // note that this is x/y not y/x (and in radians) 246 } 197 247 198 248 // xo, yo is the center of the baseline … … 229 279 NY = hypot((xv[peak]-xo),(yv[peak]-yo)); 230 280 231 232 281 memset (image, 0, sizeof(Image)); 233 282 image[0].coords = *refcoords; … … 237 286 image[0].coords.pc2_2 = +cos(angle); 238 287 239 // XXX crpix1,2 should be one of the corners for RA---TAN!!! 240 // 0.5NX + xc, 0.5NY + yc or something like that 241 // is this the right sign? 288 // crpix1,crpix2 is the projection center 242 289 image[0].coords.crpix1 = 0.5*NX - xc; 243 290 image[0].coords.crpix2 = 0.5*NY - yc; 244 291 245 292 // only keep one of the parity images 246 if ( parity == +1) {293 if (((triangle[0].d >= 0) && (parity == +1)) || ((triangle[0].d < 0) && (parity == -1))) { 247 294 strcpy (image[0].coords.ctype, "RA---TAN"); 248 295 } else { … … 250 297 } 251 298 if ((NX > 60000) || (NY > 60000)) { 299 if (!warned) { 300 fprintf (stderr, "warning: NX,NY too big for DVO limits; modifying pixel scale\n"); 301 warned = TRUE; 302 } 252 303 scale = NX / 60000.0; 253 304 scale = MAX(scale, NY / 60000.0); … … 317 368 out[4*i + 3].vertex[j] = out[4*i + j].vertex[1]; 318 369 } 319 # if (0)320 fprintf (stdout, "%f %f %f %f %f %f %f %f %f\n",321 in[i].vertex[0].x, in[i].vertex[0].y, in[i].vertex[0].z,322 in[i].vertex[1].x, in[i].vertex[1].y, in[i].vertex[1].z,323 in[i].vertex[2].x, in[i].vertex[2].y, in[i].vertex[2].z);324 for (j = 0; j < 4; j++) {325 fprintf (stdout, "%f %f %f %f %f %f %f %f %f\n",326 out[4*i+j].vertex[0].x, out[4*i+j].vertex[0].y, out[4*i+j].vertex[0].z,327 out[4*i+j].vertex[1].x, out[4*i+j].vertex[1].y, out[4*i+j].vertex[1].z,328 out[4*i+j].vertex[2].x, out[4*i+j].vertex[2].y, out[4*i+j].vertex[2].z);329 }330 # endif331 370 Nt += 4; 332 371 } … … 440 479 } 441 480 442 int sky_tessalation_init ( ) {481 int sky_tessalation_init (double scale) { 443 482 444 483 ALLOCATE (refcoords, Coords, 1); 445 484 refcoords[0].crval1 = refcoords[0].crval2 = 0.0; 446 485 refcoords[0].crpix1 = refcoords[0].crpix2 = 0.0; 447 refcoords[0].cdelt1 = refcoords[0].cdelt2 = 1.0/ 3600;486 refcoords[0].cdelt1 = refcoords[0].cdelt2 = scale / 3600; 448 487 refcoords[0].pc1_1 = refcoords[0].pc2_2 = 1.0; 449 488 refcoords[0].pc1_2 = refcoords[0].pc2_1 = 0.0; … … 453 492 return (TRUE); 454 493 } 455 456 457 458 /*** this code was an attempt to fit the triangle boundaries into NX, NY ***/459 # if (0)460 for (n = 0; n < 3; n++) {461 // we will project to the triangle center position462 refcoords[0].crval1 = triangle[0].r;463 refcoords[0].crval2 = triangle[0].d;464 465 // find the size, rotation, and parity of the image466 // project the vertices and find the image parity467 parity = 1;468 for (i = 0; i < 3; i++) {469 RD_to_XY (&xv[i], &yv[i], triangle[0].rv[i], triangle[0].dv[i], refcoords);470 parity *= SIGN(yv[i]);471 }472 473 // choose the peak vertex474 peak = -1;475 for (i = 0; (peak == -1) && (i < 3); i++) {476 if (parity == SIGN(yv[i])) {477 peak = i;478 }479 }480 assert (peak != -1);481 482 // find the base and height483 b1 = (peak + 1) % 3;484 b2 = (peak + 2) % 3;485 486 // xo, yo is the center of the baseline487 xo = 0.5*(xv[b2] + xv[b1]);488 yo = 0.5*(yv[b2] + yv[b1]);489 490 if (n != 2) {491 // xc, yc is the true image center492 xc = 0.5*(xv[peak] + xo);493 yc = 0.5*(yv[peak] + yo);494 XY_to_RD (&triangle[0].r, &triangle[0].d, xc, yc, refcoords);495 }496 }497 498 NX = hypot((xv[b2]-xv[b1]),(yv[b2]-yv[b1]));499 NY = hypot((xv[peak]-xo),(yv[peak]-yo));500 angle = atan2(parity*xv[peak], parity*yv[peak]); // note that this is x/y not y/x (and in radians)501 502 memset (image, 0, sizeof(Image));503 image[0].coords = *refcoords;504 image[0].coords.pc1_1 = +cos(angle);505 image[0].coords.pc1_2 = +sin(angle);506 image[0].coords.pc2_1 = -sin(angle);507 image[0].coords.pc2_2 = +cos(angle);508 509 if (parity == 1) {510 strcpy (image[0].coords.ctype, "TRP--TAN");511 } else {512 strcpy (image[0].coords.ctype, "TRM--TAN");513 }514 sprintf (image[0].name, "test.%03d", i);515 if ((NX > 60000) || (NY > 60000)) {516 scale = NX / 60000.0;517 scale = MAX(scale, NY / 60000.0);518 NX /= scale;519 NY /= scale;520 image[0].coords.cdelt1 *= scale;521 image[0].coords.cdelt2 *= scale;522 }523 image[0].NX = NX;524 image[0].NY = NY;525 image[0].code = 1;526 # endif -
trunk/Ohana/src/addstar/src/skycells.c
r12773 r12775 8 8 FITS_DB db; 9 9 10 // XXX for test data11 Coords coords;12 double r, d;13 14 10 SetSignals (); 15 11 ConfigInit_skycells (&argc, argv); 16 12 args_skycells (argc, argv); 17 13 level = atoi (argv[1]); 18 19 images = sky_tessalation (level, &Nimages, MODE );14 15 images = sky_tessalation (level, &Nimages, MODE, SCALE); 20 16 21 17 /*** update the image table ***/ … … 45 41 exit (0); 46 42 } 47 48 # if (0)49 coords.crval1 = coords.crval2 = 0.0;50 coords.crpix1 = coords.crpix2 = 0.0;51 coords.cdelt1 = coords.cdelt2 = 1.0 / 3600;52 coords.pc1_1 = coords.pc2_2 = 1.0;53 coords.pc1_2 = coords.pc2_1 = 0.0;54 coords.Npolyterms = 0;55 memset (coords.polyterms, 0, 14*sizeof(float));56 strcpy (coords.ctype, "TRP--TAN");57 58 /** quick demo to create a set of triangular images **/59 Nimages = 100;60 ALLOCATE (images, Image, Nimages);61 for (r = 0, i = 0; r < 10; r++) {62 for (d = 0; d < 10; d++, i++) {63 memset (&images[i], 0, sizeof(Image));64 images[i].coords = coords;65 images[i].coords.crval1 = r;66 images[i].coords.crval2 = d;67 if (i%2) strcpy (images[i].coords.ctype, "TRM--TAN");68 sprintf (images[i].name, "test.%03d", i);69 images[i].NX = 1000;70 images[i].NY = 1000;71 images[i].code = 1;72 }73 }74 # endif75
Note:
See TracChangeset
for help on using the changeset viewer.
