Changeset 12773
- Timestamp:
- Apr 6, 2007, 6:07:30 AM (19 years ago)
- Location:
- trunk/Ohana/src/addstar
- Files:
-
- 4 edited
-
include/skycells.h (modified) (4 diffs)
-
src/args_skycells.c (modified) (1 diff)
-
src/sky_tessalation.c (modified) (6 diffs)
-
src/skycells.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/include/skycells.h
r12772 r12773 11 11 # include <arpa/inet.h> 12 12 # include <glob.h> 13 14 enum {SQUARES, TRIANGLES}; 13 15 14 16 typedef struct { … … 49 51 50 52 int VERBOSE; 53 int MODE; 51 54 52 55 void SetProtect PROTO((int mode)); … … 57 60 int ConfigInit_skycells (int *argc, char **argv); 58 61 59 Image *sky_tessalation (int level, int *nimages);60 62 int sky_triangle_to_image (Image *image, SkyTriangle *triangle); 61 63 int sky_triangle_coords (SkyTriangle *triangle); … … 65 67 int sky_tessalation_init (); 66 68 int sky_triangle_to_rectangle (Image *image, SkyTriangle *triangle); 69 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); -
trunk/Ohana/src/addstar/src/args_skycells.c
r12753 r12773 19 19 } 20 20 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 21 28 if (argc == 2) return (TRUE); 22 29 23 fprintf (stderr, "USAGE: skycells (level) \n");30 fprintf (stderr, "USAGE: skycells (level) [-triangles] [-scale arcsec/pix]\n"); 24 31 exit (2); 25 32 } -
trunk/Ohana/src/addstar/src/sky_tessalation.c
r12772 r12773 4 4 static Coords *refcoords = NULL; 5 5 6 Image *sky_tessalation (int level, int *nimages) { 7 8 int i, N, Ntriangles; 6 Image *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 23 Image *sky_tessalation_triangles (int level, int *nimages) { 24 25 int i, Ndigit, Ntriangles; 9 26 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); 11 32 12 33 sky_tessalation_init (); … … 22 43 ALLOCATE (image, Image, Ntriangles); 23 44 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 53 Image *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++) { 26 76 sky_triangle_to_rectangle (&image[i], &tri[i]); 27 77 } 28 78 29 FILE *f1 = fopen ("par.1.dat", "w");30 FILE *f2 = fopen ("par.2.dat", "w");31 32 79 ALLOCATE (outimage, Image, Ntriangles); 33 80 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; 40 82 memcpy (&outimage[N], &image[i], sizeof(Image)); 41 s printf (outimage[N].name, "test.%03d", i);83 snprintf (outimage[N].name, 32, format, i); 42 84 N++; 43 85 } 44 86 free (image); 45 46 fclose (f1);47 fclose (f2);48 87 49 88 *nimages = N; … … 124 163 double xo, yo, xc, yc, angle, scale; 125 164 double Xmin, Xmax, Ymin, Ymax; 165 double dB, dP, s1, s2, r1, r2, dr, dx, dy; 126 166 127 167 // calculate the triangle coordinates in r,d … … 149 189 assert (peak != -1); 150 190 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 151 194 // find the base and height 152 195 b1 = (peak + 1) % 3; … … 156 199 xo = 0.5*(xv[b2] + xv[b1]); 157 200 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; 158 223 159 224 // xc, yc is the true image center … … 163 228 NX = hypot((xv[b2]-xv[b1]),(yv[b2]-yv[b1])); 164 229 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 166 231 167 232 memset (image, 0, sizeof(Image)); -
trunk/Ohana/src/addstar/src/skycells.c
r12753 r12773 17 17 level = atoi (argv[1]); 18 18 19 images = sky_tessalation (level, &Nimages );19 images = sky_tessalation (level, &Nimages, MODE); 20 20 21 21 /*** update the image table ***/
Note:
See TracChangeset
for help on using the changeset viewer.
