Changeset 12773 for trunk/Ohana/src/addstar/src/sky_tessalation.c
- Timestamp:
- Apr 6, 2007, 6:07:30 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/addstar/src/sky_tessalation.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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));
Note:
See TracChangeset
for help on using the changeset viewer.
