Changeset 15997
- Timestamp:
- Jan 4, 2008, 11:15:56 AM (18 years ago)
- Location:
- trunk/Ohana/src/addstar
- Files:
-
- 3 edited
-
include/skycells.h (modified) (2 diffs)
-
src/args_skycells.c (modified) (5 diffs)
-
src/sky_tessalation.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/include/skycells.h
r13186 r15997 24 24 double rv[3], dv[3]; // triangle center (2d) 25 25 } SkyTriangle; 26 27 typedef struct { 28 Coords coords; 29 int NX; 30 int NY; 31 int code; 32 char name[64]; 33 } SkyRectangle; 26 34 27 35 /* globals which define database info / data sources (KEEP) */ … … 52 60 int VERBOSE; 53 61 int MODE; 62 int FIX_NS; 54 63 int NMAX; 55 64 int NX_SUB, NY_SUB; 56 65 double SCALE; 66 double PADDING; 57 67 58 void SetProtect PROTO((int mode)); 59 int SetSignals PROTO(()); 60 int Shutdown PROTO((char *message, ...); ) 61 void TrapSignal PROTO((int sig)); 62 int args_skycells (int argc, char **argv); 63 int ConfigInit_skycells (int *argc, char **argv); 68 double EULER_A; 69 double EULER_B; 64 70 65 int sky_triangle_to_image (Image *image, SkyTriangle *triangle); 66 int sky_triangle_coords (SkyTriangle *triangle); 67 SkyTriangle *sky_divide_triangles (SkyTriangle *in, int *ntriangles); 68 Point sky_divide_edge (Point v1, Point v2); 69 SkyTriangle *sky_base_triangles (int *ntriangles); 70 int sky_tessalation_init (double scale); 71 int sky_triangle_to_rectangle (Image *image, SkyTriangle *triangle); 71 void SetProtect PROTO((int mode)); 72 int SetSignals PROTO(()); 73 int Shutdown PROTO((char *message, ...); ) 74 void TrapSignal PROTO((int sig)); 72 75 73 int sky_tessalation (FITS_DB *db, int level, int Nmax, int mode, double scale); 74 int sky_tessalation_triangles (FITS_DB *db, int level, int Nmax); 75 int sky_tessalation_squares (FITS_DB *db, int level, int Nmax); 76 int args_skycells PROTO((int argc, char **argv)); 77 int ConfigInit_skycells PROTO((int *argc, char **argv)); 78 int sky_tessalation PROTO((FITS_DB *db, int level, int Nmax, int mode, double scale)); 79 int sky_tessalation_init PROTO((double scale)); 80 int sky_tessalation_triangles PROTO((FITS_DB *db, int level, int Nmax)); 81 int sky_tessalation_squares PROTO((FITS_DB *db, int level, int Nmax)); 82 int sky_triangle_to_image PROTO((Image *image, SkyTriangle *triangle)); 83 int sky_triangle_to_rectangle PROTO((SkyRectangle *image, SkyTriangle *triangle)); 84 int sky_subdivide_image PROTO((Image *output, SkyRectangle *input, int Nx, int Ny)); 85 int sky_triangle_coords PROTO((SkyTriangle *triangle)); 86 SkyTriangle *sky_divide_triangles PROTO((SkyTriangle *in, int *ntriangles)); 87 SkyTriangle *sky_base_triangles PROTO((int *ntriangles)); 88 int sky_base_rotation PROTO((SkyTriangle *base, int Nbase)); 89 Point sky_divide_edge PROTO((Point v1, Point v2)); 76 90 77 // migrate to libdvo eventually78 int dvo_image_clear_vtable (FITS_DB *db);91 // XXX migrate to libdvo eventually 92 int dvo_image_clear_vtable PROTO((FITS_DB *db)); -
trunk/Ohana/src/addstar/src/args_skycells.c
r13186 r15997 4 4 int args_skycells (int argc, char **argv) { 5 5 6 int i,N;6 int N; 7 7 char *ptr; 8 8 … … 27 27 } 28 28 29 /* what type of output files? */ 30 FIX_NS = FALSE; 31 if ((N = get_argument (argc, argv, "-fix-ns"))) { 32 FIX_NS = TRUE; 33 remove_argument (N, &argc, argv); 34 } 35 29 36 /* pixel scale (arcsec/pixel) */ 30 37 SCALE = 1.0; … … 32 39 remove_argument (N, &argc, argv); 33 40 SCALE = atof (argv[N]); 41 remove_argument (N, &argc, argv); 42 } 43 44 /* pixel scale (arcsec/pixel) */ 45 EULER_A = EULER_B = 0.0; 46 if ((N = get_argument (argc, argv, "-euler"))) { 47 remove_argument (N, &argc, argv); 48 EULER_A = RAD_DEG*atof (argv[N]); 49 remove_argument (N, &argc, argv); 50 EULER_B = RAD_DEG*atof (argv[N]); 51 remove_argument (N, &argc, argv); 52 } 53 54 /* pixel scale (arcsec/pixel) */ 55 PADDING = 0.0; 56 if ((N = get_argument (argc, argv, "-padding"))) { 57 remove_argument (N, &argc, argv); 58 PADDING = atof (argv[N]); 34 59 remove_argument (N, &argc, argv); 35 60 } … … 61 86 } 62 87 63 fprintf (stderr, "USAGE: skycells (level) [-triangles] [-scale arcsec/pix] [-nmax Max Cells in memory] [-nx (Nx cells)] [-ny (Ny cells)]\n"); 88 fprintf (stderr, "USAGE: skycells (level) [-scale arcsec/pix] [-nx (Nx cells)] [-ny (Ny cells)]\n"); 89 fprintf (stderr, " [-h for details and other options]\n"); 64 90 exit (2); 65 91 } … … 71 97 72 98 fprintf (stderr, " -v : verbose mode\n"); 99 fprintf (stderr, " -triangles : save base triangles instead of skycells\n"); 100 fprintf (stderr, " -fix-ns : orient skycells with y-axis aligned with Dec\n"); 101 fprintf (stderr, " -scale : set pixel scale (default 1.0 arcsec / pixel)\n"); 102 fprintf (stderr, " -padding : pad skycells by this fraction in each dimension\n"); 103 fprintf (stderr, " -nmax : only keep nmax skycells in memory\n"); 104 fprintf (stderr, " -nx : subdivide skycell projection in x\n"); 105 fprintf (stderr, " -ny : subdivide skycell projection in y\n"); 73 106 fprintf (stderr, " -help : this list\n"); 74 107 fprintf (stderr, " -h : this list\n\n"); -
trunk/Ohana/src/addstar/src/sky_tessalation.c
r13886 r15997 3 3 # define iSWAP(X,Y) {int tmp=(X); (X) = (Y); (Y) = tmp;} 4 4 5 // we use a static refcoords structure to avoid multiple alloc / init steps 5 6 static Coords *refcoords = NULL; 6 static int warned = FALSE;7 7 8 8 int sky_tessalation (FITS_DB *db, int level, int Nmax, int mode, double scale) { … … 33 33 // generate the initial base set 34 34 base = sky_base_triangles (&Nbase); 35 36 sky_base_rotation (base, Nbase); 35 37 36 38 // how many triangles total for this level? … … 95 97 int sky_tessalation_squares (FITS_DB *db, int level, int Nmax) { 96 98 97 int i, j, Nname, Ndigit, Ntriangles, Nbase, N total, Ntop, Ltop, Nout, Nx, Ny;99 int i, j, Nname, Ndigit, Ntriangles, Nbase, Nimage, Ntotal, Ntop, Ltop, Nsubset, Nx, Ny; 98 100 double fLtop; 99 101 SkyTriangle *base, *tri, *new; 100 Image *image, *out; 102 SkyRectangle *rectangle, *subset; 103 Image *image; 101 104 char format[16]; 102 105 … … 106 109 // generate the initial base set 107 110 base = sky_base_triangles (&Nbase); 111 112 sky_base_rotation (base, Nbase); 108 113 109 114 // how many total cells for this level (multiply by subdivisions, if used)? … … 144 149 } 145 150 146 // convert the SkyTriangles to Image147 ALLOCATE ( image, Image, Ntriangles);151 // convert the SkyTriangles to SkyRectangles 152 ALLOCATE (rectangle, SkyRectangle, Ntriangles); 148 153 for (j = 0; j < Ntriangles; j++) { 149 sky_triangle_to_rectangle (& image[j], &tri[j]);154 sky_triangle_to_rectangle (&rectangle[j], &tri[j]); 150 155 } 151 156 152 157 // drop the appropriate subset 153 ALLOCATE ( out, Image, Ntriangles);154 for (j = N out = 0; j < Ntriangles; j++) {155 if (!strcmp( image[j].coords.ctype, "DROP")) continue;156 memcpy (& out[Nout], &image[j], sizeof(Image));157 snprintf ( out[Nout].name, 64, format, Nname);158 ALLOCATE (subset, SkyRectangle, Ntriangles); 159 for (j = Nsubset = 0; j < Ntriangles; j++) { 160 if (!strcmp(rectangle[j].coords.ctype, "DROP")) continue; 161 memcpy (&subset[Nsubset], &rectangle[j], sizeof(SkyRectangle)); 162 snprintf (subset[Nsubset].name, 64, format, Nname); 158 163 Nname++; 159 N out++;164 Nsubset++; 160 165 } 161 free ( image);166 free (rectangle); 162 167 163 168 // subdivide each image (Nx x Ny subcells) 164 if (Nx*Ny > 1) { 165 ALLOCATE (image, Image, Nx*Ny*Nout); 166 for (j = 0; j < Nout; j++) { 167 sky_subdivide_image (&image[j*Nx*Ny], &out[j], Nx, Ny); 168 } 169 free (out); 170 out = image; 171 Nout *= Nx*Ny; 169 Nimage = Nx*Ny*Nsubset; 170 ALLOCATE (image, Image, Nimage); 171 for (j = 0; j < Nsubset; j++) { 172 // convert the SkyRectangles to Images for output 173 sky_subdivide_image (&image[j*Nx*Ny], &subset[j], Nx, Ny); 172 174 } 173 175 174 176 /* add the new images and save */ 175 dvo_image_addrows (db, out, Nout);177 dvo_image_addrows (db, image, Nimage); 176 178 SetProtect (TRUE); 177 179 dvo_image_update (db, VERBOSE); … … 179 181 dvo_image_clear_vtable (db); 180 182 181 free (out); 183 free (subset); 184 free (image); 182 185 free (tri); 183 186 } … … 188 191 int sky_triangle_to_image (Image *image, SkyTriangle *triangle) { 189 192 190 int i, n, parity, peak, b1, b2,NX, NY;193 int i, NX, NY; 191 194 double xv[3], yv[3]; // coordinates of the vertex in the reference projection 192 double xo, yo, xc, yc, angle,scale;195 double scale; 193 196 double Xmin, Xmax, Ymin, Ymax; 194 197 … … 250 253 } 251 254 252 // an allocated image set is supplied, we fill in the values253 int sky_subdivide_image (Image *output, Image *input, int Nx, int Ny) {254 255 int i, j, N, NX, NY, Ndigit;256 char format[24];257 258 NX = input[0].NX/(double)Nx + 0.5;259 NY = input[0].NY/(double)Ny + 0.5;260 261 Ndigit = (int)(log10(Nx*Ny)) + 1 ;262 snprintf (format, 24, "%s.%%0%dd", input[0].name, Ndigit);263 264 N = 0;265 for (j = 0; j < Ny; j++) {266 for (i = 0; i < Nx; i++) {267 268 memcpy (&output[N], &input[0], sizeof(Image));269 snprintf (output[N].name, 64, format, N);270 271 // output[0].coords = input[0].coords;272 // strcpy (output[0].coords.ctype, input[0].coords.ctype);273 274 output[N].NX = NX;275 output[N].NY = NY;276 277 output[N].coords.crpix1 = input[0].coords.crpix1 - i*NX;278 output[N].coords.crpix2 = input[0].coords.crpix2 - j*NY;279 N++;280 }281 }282 return (TRUE);283 }284 285 255 // an allocated image is supplied, we fill in the values 286 256 // we are only keeping ~half of the images 287 int sky_triangle_to_rectangle ( Image *image, SkyTriangle *triangle) {288 289 int i, n,parity, peak, b1, b2, NX, NY, right;257 int sky_triangle_to_rectangle (SkyRectangle *rectangle, SkyTriangle *triangle) { 258 259 int i, parity, peak, b1, b2, NX, NY, right; 290 260 double xv[3], yv[3]; // coordinates of the vertex in the reference projection 291 double xo, yo, xc, yc, angle, scale; 292 double Xmin, Xmax, Ymin, Ymax; 261 double xo, yo, xc, yc, xcr, ycr, angle; 293 262 double dB, dP, s1, s2, r1, r2, dr, dx, dy; 294 263 double angle_b1, angle_b2, slope; … … 390 359 xc = 0.5*(xv[peak] + xo); 391 360 yc = 0.5*(yv[peak] + yo); 392 393 NX = hypot((xv[b2]-xv[b1]),(yv[b2]-yv[b1])); 394 NY = hypot((xv[peak]-xo),(yv[peak]-yo)); 395 396 memset (image, 0, sizeof(Image)); 397 image[0].coords = *refcoords; 398 image[0].coords.pc1_1 = +cos(angle); 399 image[0].coords.pc1_2 = +sin(angle); 400 image[0].coords.pc2_1 = -sin(angle); 401 image[0].coords.pc2_2 = +cos(angle); 402 361 362 // NX,NY are the size of the circumscribed square, expanded by PADDING 363 NX = hypot((xv[b2]-xv[b1]),(yv[b2]-yv[b1])) * (1 + PADDING); 364 NY = hypot((xv[peak]-xo),(yv[peak]-yo)) * (1 + PADDING); 365 366 memset (rectangle, 0, sizeof(SkyRectangle)); 367 rectangle[0].coords = *refcoords; 368 369 if (FIX_NS) { 370 rectangle[0].coords.pc1_1 = +1.0; 371 rectangle[0].coords.pc1_2 = +0.0; 372 rectangle[0].coords.pc2_1 = -0.0; 373 rectangle[0].coords.pc2_2 = +1.0; 374 xcr = xc*cos(angle) - yc*sin(angle); 375 ycr = yc*cos(angle) + xc*sin(angle); 376 } else { 377 rectangle[0].coords.pc1_1 = +cos(angle); 378 rectangle[0].coords.pc1_2 = +sin(angle); 379 rectangle[0].coords.pc2_1 = -sin(angle); 380 rectangle[0].coords.pc2_2 = +cos(angle); 381 xcr = xc; 382 ycr = yc; 383 } 384 403 385 // crpix1,crpix2 is the projection center 404 image[0].coords.crpix1 = 0.5*NX - xc;405 image[0].coords.crpix2 = 0.5*NY - yc;406 407 // only keep one of the parity images386 rectangle[0].coords.crpix1 = 0.5*NX - xcr; 387 rectangle[0].coords.crpix2 = 0.5*NY - ycr; 388 389 // only keep one of the parity rectangles 408 390 if (((triangle[0].d >= 0) && (parity == +1)) || ((triangle[0].d < 0) && (parity == -1))) { 409 strcpy ( image[0].coords.ctype, "DEC--TAN");391 strcpy (rectangle[0].coords.ctype, "DEC--TAN"); 410 392 } else { 411 strcpy (image[0].coords.ctype, "DROP"); 412 } 413 if ((NX > 60000) || (NY > 60000)) { 414 if (!warned) { 415 fprintf (stderr, "warning: NX,NY too big for DVO limits; modifying pixel scale\n"); 416 warned = TRUE; 417 } 418 scale = NX / 60000.0; 419 scale = MAX(scale, NY / 60000.0); 420 NX /= scale; 421 NY /= scale; 422 image[0].coords.cdelt1 *= scale; 423 image[0].coords.cdelt2 *= scale; 424 image[0].coords.crpix1 /= scale; 425 image[0].coords.crpix2 /= scale; 426 } 427 428 image[0].NX = NX; 429 image[0].NY = NY; 430 image[0].code = 1; // this needs to be set more sensibly 431 393 strcpy (rectangle[0].coords.ctype, "DROP"); 394 } 395 396 rectangle[0].NX = NX; 397 rectangle[0].NY = NY; 398 rectangle[0].code = 1; // this needs to be set more sensibly 399 400 return (TRUE); 401 } 402 403 // an allocated image set is supplied, we fill in the values 404 int sky_subdivide_image (Image *output, SkyRectangle *input, int Nx, int Ny) { 405 406 int i, j, N, NX, NY, Ndigit; 407 char format[24]; 408 409 NX = input[0].NX/(double)Nx + 0.5; 410 NY = input[0].NY/(double)Ny + 0.5; 411 412 // image[0].NX,NY are unsigned short: abort is we overflow 413 if ((NX > 0xffff) || (NY > 0xffff)) { 414 fprintf (stderr, "error: NX,NY too big for DVO limits; modifying pixel scale\n"); 415 exit (1); 416 } 417 418 Ndigit = (int)(log10(Nx*Ny)) + 1 ; 419 snprintf (format, 24, "%s.%%0%dd", input[0].name, Ndigit); 420 421 N = 0; 422 for (j = 0; j < Ny; j++) { 423 for (i = 0; i < Nx; i++) { 424 425 memset (&output[N], 0, sizeof(Image)); 426 memcpy (&output[N].coords, &input[0].coords, sizeof(Coords)); 427 428 snprintf (output[N].name, 64, format, N); 429 output[N].NX = NX; 430 output[N].NY = NY; 431 output[N].code = input[0].code; 432 433 output[N].coords.crpix1 = input[0].coords.crpix1 - i*NX; 434 output[N].coords.crpix2 = input[0].coords.crpix2 - j*NY; 435 N++; 436 } 437 } 432 438 return (TRUE); 433 439 } … … 520 526 // generate 0-level triangles 521 527 ALLOCATE (tri, SkyTriangle, 20); 528 529 for (i = 0; i < 20; i++) { 530 memset (&tri[i], 0, sizeof(SkyTriangle)); 531 } 522 532 523 533 ctht = cos(THETA); … … 594 604 } 595 605 606 int sky_base_rotation (SkyTriangle *base, int Nbase) { 607 608 // apply the three euler angles (A, B, C) 609 // XXX for now, just apply A and B 610 611 int i, j, ix; 612 float rot[3][3], v[3]; 613 614 rot[0][0] = +cos(EULER_A)*cos(EULER_B); 615 rot[1][0] = +sin(EULER_A)*cos(EULER_B); 616 rot[2][0] = +sin(EULER_B); 617 618 rot[0][1] = -sin(EULER_A); 619 rot[1][1] = +cos(EULER_A); 620 rot[2][1] = +0.0; 621 622 rot[0][2] = -cos(EULER_A)*sin(EULER_B); 623 rot[1][2] = -sin(EULER_A)*sin(EULER_B); 624 rot[2][2] = +cos(EULER_B); 625 626 for (i = 0; i < Nbase; i++) { 627 for (j = 0; j < 3; j++) { 628 for (ix = 0; ix < 3; ix++) { 629 v[ix] = 0.0; 630 v[ix] += base[i].vertex[j].x * rot[0][ix]; 631 v[ix] += base[i].vertex[j].y * rot[1][ix]; 632 v[ix] += base[i].vertex[j].z * rot[2][ix]; 633 } 634 base[i].vertex[j].x = v[0]; 635 base[i].vertex[j].y = v[1]; 636 base[i].vertex[j].z = v[2]; 637 } 638 } 639 return (TRUE); 640 } 641 596 642 int sky_tessalation_init (double scale) { 597 643 … … 611 657 int dvo_image_clear_vtable (FITS_DB *db) { 612 658 613 int Nimages; 614 int i, N, Nx, Ny; 659 int i; 615 660 616 661 // free memory used by the current vtable rows
Note:
See TracChangeset
for help on using the changeset viewer.
