Changeset 5542
- Timestamp:
- Nov 18, 2005, 9:39:29 AM (20 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 3 edited
-
astro/psCoord.c (modified) (17 diffs)
-
astro/psCoord.h (modified) (4 diffs)
-
math/psPolynomial.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psCoord.c
r5294 r5542 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.8 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-1 0-12 21:02:20$12 * @version $Revision: 1.89 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-11-18 19:39:29 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 57 57 "transform" is linear. 58 58 59 This program assumes that the inverse of the following linear equations:60 X2 = A + (B * X1) + (C * Y1);61 Y2 = D + (E * X1) + (F * Y1);62 is63 Y1 = (Y2 - ((E/B) * X2) - D + ((E*A)/B)) / (F - ((C*E)/B));64 X1 = (Y2 - ((F/C) * X2) - D + ((F*A)/C)) / (E - ((F*B)/C));65 or66 X1 = (-D + ((F*A)/C)) / (E - ((F*B)/C)) +67 (X2 * -((F/C) / (E - ((F*B)/C)))) +68 (Y2 * (1.0 / (E - ((F*B)/C))));69 Y1 = (-D + ((E*A)/B))/(F - ((C*E)/B)) +70 (X2 * -((E/B) / (F - ((C*E)/B)))) +71 (Y2 * (1.0 / (F - ((C*E)/B))));72 73 59 XXX: Since there is now a general psPlaneTransformInvert() function, we 74 60 should rename this. 75 61 76 XXX: Use the ADD version which is based on determinants. 62 To derive this transformation, start with the simple 2-by-2 matrix inversion 63 based on discriminants. This will invert the 64 (x_2, y_2) = matrix(a b c d) * vector (x, y) 65 where there are no constant terms. Then you substitute 66 x_2 = x_1 - e 67 y_2 = y_1 - f 68 for (x_2, y_2) to get the desired inverse. 77 69 *****************************************************************************/ 78 70 psPlaneTransform *p_psPlaneTransformLinearInvert(psPlaneTransform *transform) 79 71 { 80 PS_ASSERT_PTR_NON_NULL(transform, 0); 81 PS_ASSERT_PTR_NON_NULL(transform->x, 0); 82 PS_ASSERT_PTR_NON_NULL(transform->y, 0); 83 84 psF64 A = 0.0; 85 psF64 B = 0.0; 86 psF64 C = 0.0; 87 psF64 D = 0.0; 88 psF64 E = 0.0; 89 psF64 F = 0.0; 90 91 A = transform->x->coeff[0][0]; 92 if (transform->x->nX >= 1) { 93 B = transform->x->coeff[1][0]; 94 } 95 if (transform->x->nY >= 1) { 96 C = transform->x->coeff[0][1]; 97 } 98 D = transform->y->coeff[0][0]; 99 if (transform->y->nX >= 1) { 100 E = transform->y->coeff[1][0]; 101 } 102 if (transform->y->nY >= 1) { 103 F = transform->y->coeff[0][1]; 104 } 105 106 psPlaneTransform *out = psPlaneTransformAlloc(2, 2); 107 108 /* This is sample code from IfA. It didn't work initially, and I did not 109 spend any time debugging it. 110 72 PS_ASSERT_PTR_NON_NULL(transform, NULL); 73 PS_ASSERT_PTR_NON_NULL(transform->x, NULL); 74 PS_ASSERT_PTR_NON_NULL(transform->y, NULL); 75 if ((transform->x->nX < 1) || 76 (transform->x->nY < 1) || 77 (transform->y->nX < 1) || 78 (transform->y->nY < 1)) { 79 psLogMsg(__func__, PS_LOG_WARN, "WARNING: input transform is not invertible."); 80 return(NULL); 81 } 82 83 psPlaneTransform *out = psPlaneTransformAlloc(1, 1); 84 85 if (0) { 86 //This is sample code from IfA. It didn't work initially, and I did not 87 //spend any time debugging it. 111 88 psF64 a = transform->x->coeff[1][0]; 112 89 psF64 b = transform->x->coeff[0][1]; … … 118 95 psF64 invDet = 1.0 / (a * d - b * c); // Inverse of the determinant 119 96 120 // Not entirely sure why this works, but it appears to do so ....................................!97 // Not entirely sure why this works, but it appears to do so 121 98 out->x->coeff[1][0] = invDet * a; 122 99 out->x->coeff[0][1] = - invDet * b; … … 126 103 out->x->coeff[0][0] = - invDet * (d * e + c * f); 127 104 out->y->coeff[0][0] = - invDet * (b * e + a * f); 128 */ 129 out->x->coeff[0][0] = (-D + ((F*A)/C)) / (E - ((F*B)/C)); 130 out->x->coeff[1][0] = -(F/C) / (E - ((F*B)/C)); 131 out->x->coeff[0][1] = 1.0 / (E - ((F*B)/C)); 132 out->y->coeff[0][0] = (-D + ((E*A)/B)) / (F - ((C*E)/B)); 133 out->y->coeff[1][0] = -(E/B) / (F - ((C*E)/B)); 134 out->y->coeff[0][1] = 1.0 / (F - ((C*E)/B)); 105 } 106 107 if (1) { 108 psF64 A = transform->x->coeff[1][0]; 109 psF64 B = transform->x->coeff[0][1]; 110 psF64 C = transform->y->coeff[1][0]; 111 psF64 D = transform->y->coeff[0][1]; 112 psF64 E = transform->x->coeff[0][0]; 113 psF64 F = transform->y->coeff[0][0]; 114 psF64 invDet = 1.0 / (A * D - B * C); 115 116 out->x->coeff[1][0] = invDet * D; 117 out->x->coeff[0][1] = invDet * -B; 118 out->y->coeff[1][0] = invDet * -C; 119 out->y->coeff[0][1] = invDet * A; 120 121 // 122 // This comes from substituting the (x_2 = x_1 - e) and (y_2 = y_1 - f) equations: 123 // 124 out->x->coeff[0][0] = invDet * (B * F - D * E); 125 out->y->coeff[0][0] = invDet * (E * C - A * F); 126 127 } 128 // printf("HMMM: out->x: (%f %f %f)\n", out->x->coeff[0][0], out->x->coeff[1][0], out->x->coeff[0][1]); 129 // printf("HMMM: out->y: (%f %f %f)\n", out->y->coeff[0][0], out->y->coeff[1][0], out->y->coeff[0][1]); 135 130 136 131 return(out); … … 143 138 144 139 Returns: 145 1: if linear 146 0: otherwise 147 148 XXX: This should be a psBool 140 true: if linear 141 false: otherwise 149 142 *****************************************************************************/ 150 ps S32p_psIsProjectionLinear(psPlaneTransform *transform)151 { 152 PS_ASSERT_PTR_NON_NULL(transform, 0);153 PS_ASSERT_PTR_NON_NULL(transform->x, 0);154 PS_ASSERT_PTR_NON_NULL(transform->y, 0);143 psBool p_psIsProjectionLinear(psPlaneTransform *transform) 144 { 145 PS_ASSERT_PTR_NON_NULL(transform, false); 146 PS_ASSERT_PTR_NON_NULL(transform->x, false); 147 PS_ASSERT_PTR_NON_NULL(transform->y, false); 155 148 156 149 for (psS32 i=0;i<(1 + transform->x->nX);i++) { … … 160 153 ((i == 0) && (j == 1)) || 161 154 ((i == 1) && (j == 0)))) { 162 return( 0);155 return(false); 163 156 } 164 157 } … … 172 165 ((i == 0) && (j == 1)) || 173 166 ((i == 1) && (j == 0)))) { 174 return( 0);167 return(false); 175 168 } 176 169 } … … 178 171 } 179 172 180 return( 1);173 return(true); 181 174 } 182 175 … … 215 208 216 209 psPlaneTransform *pt = psAlloc(sizeof(psPlaneTransform)); 217 pt->x = psPolynomial2DAlloc(n1 -1, n2-1, PS_POLYNOMIAL_ORD);218 pt->y = psPolynomial2DAlloc(n1 -1, n2-1, PS_POLYNOMIAL_ORD);210 pt->x = psPolynomial2DAlloc(n1, n2, PS_POLYNOMIAL_ORD); 211 pt->y = psPolynomial2DAlloc(n1, n2, PS_POLYNOMIAL_ORD); 219 212 220 213 psMemSetDeallocator(pt, (psFreeFunc) planeTransformFree); … … 243 236 } 244 237 245 psPlane* psPlaneTransformApply(psPlane* out, 246 const psPlaneTransform* transform, 247 const psPlane* coords) 238 psPlane* psPlaneTransformApply( 239 psPlane* out, 240 const psPlaneTransform* transform, 241 const psPlane* coords) 248 242 { 249 243 PS_ASSERT_PTR_NON_NULL(transform, NULL); … … 256 250 } 257 251 258 out->x = psPolynomial2DEval( 259 transform->x, 260 coords->x, 261 coords->y 262 ); 263 264 out->y = psPolynomial2DEval( 265 transform->y, 266 coords->x, 267 coords->y 268 ); 252 out->x = psPolynomial2DEval(transform->x, coords->x, coords->y); 253 out->y = psPolynomial2DEval(transform->y, coords->x, coords->y); 269 254 270 255 return (out); … … 383 368 384 369 385 psPlane* psProject(const psSphere* coord, 386 const psProjection* projection) 370 psPlane* p_psProject( 371 psPlane *outPlane, 372 const psSphere* coord, 373 const psProjection* projection) 387 374 { 388 375 PS_ASSERT_PTR_NON_NULL(coord, NULL); … … 393 380 394 381 // Allocate return value 395 psPlane* out = psPlaneAlloc(); 382 psPlane* out = NULL; 383 if (outPlane == NULL) { 384 out = psPlaneAlloc(); 385 } else { 386 out = outPlane; 387 } 396 388 397 389 // Convert to projection spherical coordinate system … … 435 427 } 436 428 437 psSphere* psDeproject(const psPlane* coord, 438 const psProjection* projection) 429 psPlane* psProject(const psSphere* coord, 430 const psProjection* projection) 431 { 432 return(p_psProject(NULL, coord, projection)); 433 } 434 435 psSphere* p_psDeproject( 436 psSphere *outSphere, 437 const psPlane* coord, 438 const psProjection* projection) 439 439 { 440 440 PS_ASSERT_PTR_NON_NULL(coord, NULL); … … 445 445 446 446 // Allocate return sphere structure 447 psSphere* out = psSphereAlloc(); 447 psSphere *out = NULL; 448 if (outSphere == NULL) { 449 out = psSphereAlloc(); 450 } else { 451 out = outSphere; 452 // XXX: Do a memory checkpointer. 453 } 448 454 449 455 // Remove plate scales … … 490 496 } 491 497 498 psSphere* psDeproject(const psPlane* coord, 499 const psProjection* projection) 500 { 501 return(p_psDeproject(NULL, coord, projection)); 502 } 503 504 492 505 /***************************************************************************** 493 506 multiplyDPoly2D(trans1, trans2): Takes two 2-D polynomials as input and … … 813 826 { 814 827 PS_ASSERT_PTR_NON_NULL(in, NULL); 828 PS_ASSERT_PTR_NON_NULL(in->x, NULL); 829 PS_ASSERT_PTR_NON_NULL(in->y, NULL); 830 if ((in->x->nX < 1) || 831 (in->x->nY < 1) || 832 (in->y->nX < 1) || 833 (in->y->nY < 1)) { 834 psLogMsg(__func__, PS_LOG_WARN, "WARNING: input transform is not invertible."); 835 return(NULL); 836 } 815 837 // 816 838 // If the transform is linear, then invert it exactly and return. -
trunk/psLib/src/astro/psCoord.h
r4966 r5542 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1.4 6$ $Name: not supported by cvs2svn $14 * @date $Date: 2005- 09-07 23:51:20$13 * @version $Revision: 1.47 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-11-18 19:39:29 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 290 290 ); 291 291 292 psPlane* p_psProject( 293 psPlane *out, 294 const psSphere* coord, ///< coordinate to project 295 const psProjection* projection ///< parameters of the projection 296 ); 297 292 298 /** Reverse projection of a linear coordinate to a spherical coordinate system 293 299 * … … 295 301 */ 296 302 psSphere* psDeproject( 303 const psPlane* coord, ///< coordinate to project 304 const psProjection* projection ///< parameters of the projection 305 ); 306 307 /** Private reverse projection of a linear coordinate to a spherical coordinate system 308 * 309 * @return psPlane* projected coordinate 310 */ 311 psSphere* p_psDeproject( 312 psSphere *outSphere, 297 313 const psPlane* coord, ///< coordinate to project 298 314 const psProjection* projection ///< parameters of the projection … … 314 330 * the order of the projection 315 331 */ 316 ps S32p_psIsProjectionLinear(332 psBool p_psIsProjectionLinear( 317 333 psPlaneTransform *transform ///< transform to test for linearity 318 334 ); 335 319 336 320 337 /** inverts a given transformation. -
trunk/psLib/src/math/psPolynomial.c
r5294 r5542 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.13 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-1 0-12 21:02:20$9 * @version $Revision: 1.131 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-11-18 19:39:29 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 644 644 psPolynomialType type) 645 645 { 646 PS_ASSERT_INT_ POSITIVE(nX, NULL);647 PS_ASSERT_INT_ POSITIVE(nY, NULL);646 PS_ASSERT_INT_NONNEGATIVE(nX, NULL); 647 PS_ASSERT_INT_NONNEGATIVE(nY, NULL); 648 648 649 649 unsigned int x = 0; … … 682 682 psPolynomialType type) 683 683 { 684 PS_ASSERT_INT_ POSITIVE(nX, NULL);685 PS_ASSERT_INT_ POSITIVE(nY, NULL);686 PS_ASSERT_INT_ POSITIVE(nZ, NULL);684 PS_ASSERT_INT_NONNEGATIVE(nX, NULL); 685 PS_ASSERT_INT_NONNEGATIVE(nY, NULL); 686 PS_ASSERT_INT_NONNEGATIVE(nZ, NULL); 687 687 688 688 unsigned int x = 0; … … 731 731 psPolynomialType type) 732 732 { 733 PS_ASSERT_INT_ POSITIVE(nX, NULL);734 PS_ASSERT_INT_ POSITIVE(nY, NULL);735 PS_ASSERT_INT_ POSITIVE(nZ, NULL);736 PS_ASSERT_INT_ POSITIVE(nT, NULL);733 PS_ASSERT_INT_NONNEGATIVE(nX, NULL); 734 PS_ASSERT_INT_NONNEGATIVE(nY, NULL); 735 PS_ASSERT_INT_NONNEGATIVE(nZ, NULL); 736 PS_ASSERT_INT_NONNEGATIVE(nT, NULL); 737 737 738 738 unsigned int x = 0;
Note:
See TracChangeset
for help on using the changeset viewer.
