Changeset 12772
- Timestamp:
- Apr 6, 2007, 4:42:36 AM (19 years ago)
- Location:
- trunk/Ohana/src/addstar
- Files:
-
- 2 edited
-
include/skycells.h (modified) (1 diff)
-
src/sky_tessalation.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/include/skycells.h
r12749 r12772 64 64 SkyTriangle *sky_base_triangles (int *ntriangles); 65 65 int sky_tessalation_init (); 66 int sky_triangle_to_rectangle (Image *image, SkyTriangle *triangle); -
trunk/Ohana/src/addstar/src/sky_tessalation.c
r12753 r12772 6 6 Image *sky_tessalation (int level, int *nimages) { 7 7 8 int i, N triangles;8 int i, N, Ntriangles; 9 9 SkyTriangle *tri, *new; 10 Image *image ;10 Image *image, *outimage; 11 11 12 12 sky_tessalation_init (); … … 22 22 ALLOCATE (image, Image, Ntriangles); 23 23 for (i = 0; i < Ntriangles; i++) { 24 sky_triangle_to_image (&image[i], &tri[i]); 25 sprintf (image[i].name, "test.%03d", i); 24 // XXX add a user-option to choose betwen these 25 // sky_triangle_to_image (&image[i], &tri[i]); 26 sky_triangle_to_rectangle (&image[i], &tri[i]); 26 27 } 27 28 28 *nimages = Ntriangles; 29 return (image); 29 FILE *f1 = fopen ("par.1.dat", "w"); 30 FILE *f2 = fopen ("par.2.dat", "w"); 31 32 ALLOCATE (outimage, Image, Ntriangles); 33 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 } 40 memcpy (&outimage[N], &image[i], sizeof(Image)); 41 sprintf (outimage[N].name, "test.%03d", i); 42 N++; 43 } 44 free (image); 45 46 fclose (f1); 47 fclose (f2); 48 49 *nimages = N; 50 return (outimage); 30 51 } 31 52 … … 91 112 image[0].Mxxx = xv[1]; image[0].Mxyy = yv[1]; 92 113 image[0].Mxxy = xv[2]; image[0].Myyy = yv[2]; 114 115 return (TRUE); 116 } 117 118 // an allocated image is supplied, we fill in the values 119 // we are only keeping ~half of the images 120 int sky_triangle_to_rectangle (Image *image, SkyTriangle *triangle) { 121 122 int i, n, parity, peak, b1, b2, NX, NY; 123 double xv[3], yv[3]; // coordinates of the vertex in the reference projection 124 double xo, yo, xc, yc, angle, scale; 125 double Xmin, Xmax, Ymin, Ymax; 126 127 // calculate the triangle coordinates in r,d 128 sky_triangle_coords (triangle); 129 130 // we will project to the triangle center position 131 refcoords[0].crval1 = triangle[0].r; 132 refcoords[0].crval2 = triangle[0].d; 133 134 // find the size, rotation, and parity of the image 135 // project the vertices and find the image parity 136 parity = 1; 137 for (i = 0; i < 3; i++) { 138 RD_to_XY (&xv[i], &yv[i], triangle[0].rv[i], triangle[0].dv[i], refcoords); 139 parity *= SIGN(yv[i]); 140 } 141 142 // choose the peak vertex 143 peak = -1; 144 for (i = 0; (peak == -1) && (i < 3); i++) { 145 if (parity == SIGN(yv[i])) { 146 peak = i; 147 } 148 } 149 assert (peak != -1); 150 151 // find the base and height 152 b1 = (peak + 1) % 3; 153 b2 = (peak + 2) % 3; 154 155 // xo, yo is the center of the baseline 156 xo = 0.5*(xv[b2] + xv[b1]); 157 yo = 0.5*(yv[b2] + yv[b1]); 158 159 // xc, yc is the true image center 160 xc = 0.5*(xv[peak] + xo); 161 yc = 0.5*(yv[peak] + yo); 162 163 NX = hypot((xv[b2]-xv[b1]),(yv[b2]-yv[b1])); 164 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) 166 167 memset (image, 0, sizeof(Image)); 168 image[0].coords = *refcoords; 169 image[0].coords.pc1_1 = +cos(angle); 170 image[0].coords.pc1_2 = +sin(angle); 171 image[0].coords.pc2_1 = -sin(angle); 172 image[0].coords.pc2_2 = +cos(angle); 173 174 // XXX crpix1,2 should be one of the corners for RA---TAN!!! 175 // 0.5NX + xc, 0.5NY + yc or something like that 176 // is this the right sign? 177 image[0].coords.crpix1 = 0.5*NX - xc; 178 image[0].coords.crpix2 = 0.5*NY - yc; 179 180 // only keep one of the parity images 181 if (parity == +1) { 182 strcpy (image[0].coords.ctype, "RA---TAN"); 183 } else { 184 strcpy (image[0].coords.ctype, "DROP"); 185 } 186 if ((NX > 60000) || (NY > 60000)) { 187 scale = NX / 60000.0; 188 scale = MAX(scale, NY / 60000.0); 189 NX /= scale; 190 NY /= scale; 191 image[0].coords.cdelt1 *= scale; 192 image[0].coords.cdelt2 *= scale; 193 image[0].coords.crpix1 /= scale; 194 image[0].coords.crpix2 /= scale; 195 } 196 197 image[0].NX = NX; 198 image[0].NY = NY; 199 image[0].code = 1; // this needs to be set more sensibly 93 200 94 201 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
