Changeset 6389
- Timestamp:
- Feb 8, 2006, 3:18:53 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astro/psCoord.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psCoord.c
r6388 r6389 10 10 * @author GLG, MHPCC 11 11 * 12 * @version $Revision: 1.11 0$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-02-09 0 0:52:18$12 * @version $Revision: 1.111 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-02-09 01:18:53 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 766 766 psPlaneTransformFit(trans, source, dest, nRejIter, sigmaClip) 767 767 768 XXX: This code ignores nRejIter and sigmaClip. 768 XXX: This code ignores nRejIter and sigmaClip. We must call the ClipFit 769 routines instead. 769 770 *****************************************************************************/ 770 771 bool psPlaneTransformFit( … … 824 825 PS_ASSERT_PTR_NON_NULL(in->x, NULL); 825 826 PS_ASSERT_PTR_NON_NULL(in->y, NULL); 826 if ((in->x->nX < 1) ||827 (in->x->nY < 1) || 828 (in->y->nX < 1) ||829 (in->y->nY < 1)) {827 PS_ASSERT_INT_LARGER_THAN(nSamples, 0, NULL); 828 829 // Reject a trivially non-invertible case. 830 if ((in->x->nX < 1) || (in->x->nY < 1) || (in->y->nX < 1) || (in->y->nY < 1)) { 830 831 psLogMsg(__func__, PS_LOG_WARN, "WARNING: input transform is not invertible."); 831 832 return(NULL); 832 833 } 834 835 // Ensure that the input transformation is symmetrical. 836 if ((in->x->nX != in->x->nY) || (in->y->nX != in->y->nY) || (in->x->nX != in->y->nX)) { 837 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Input transformation must have same nX==nY."); 838 } 839 833 840 // 834 841 // If the transform is linear, then invert it exactly and return. … … 839 846 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(nSamples, 1, NULL); 840 847 841 // Ensure that the input transformation is symmetrical. 842 if ((in->x->nX != in->x->nY) || 843 (in->y->nX != in->y->nY) || 844 (in->x->nX != in->y->nX)) { 845 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Input transformation must have same nX==nY."); 846 } 847 // XXX: recode or verify after poly changes 848 psS32 order = 1 + in->x->nX; 849 848 // 849 // Allocate a new psPlaneTransform if "out" is NULL, or has the wrong size. 850 // 851 psS32 order = in->x->nX; 850 852 psPlaneTransform *myPT = NULL; 851 psPlane *inCoord = psPlaneAlloc();852 psPlane *outCoord = psPlaneAlloc();853 854 //855 // Allocate a new psPlaneTransform if "out" is NULL, or has the wrong size.856 //857 853 if (out == NULL) { 858 // XXX: Verify this (poly order/nterm change)859 854 myPT = psPlaneTransformAlloc(order, order); 860 855 } else { 861 // XXX: recode or verify after poly changes 862 if (((1 + out->x->nX) == order) && ((1 + out->x->nY) == order) && 863 ((1 + out->y->nX) == order) && ((1 + out->y->nX) == order)) { 856 if ((out->x->nX == order) && (out->x->nY == order) && 857 (out->y->nX == order) && (out->y->nX == order)) { 864 858 myPT = out; 865 859 } else { … … 870 864 871 865 // 872 // Copy the input transform to myPT.873 //874 for (psS32 i = 0 ; i < (1 + in->x->nX) ; i++) {875 for (psS32 j = 0 ; j < (1 + in->x->nY) ; j++) {876 myPT->x->coeff[i][j] = in->x->coeff[i][j];877 }878 }879 for (psS32 i = 0 ; i < (1 + in->y->nX) ; i++) {880 for (psS32 j = 0 ; j < (1 + in->y->nY) ; j++) {881 myPT->y->coeff[i][j] = in->y->coeff[i][j];882 }883 }884 885 //886 // Create a grid of xin,yin --> xout,yout887 //888 psArray *inData = psArrayAlloc(nSamples * nSamples);889 psArray *outData = psArrayAlloc(nSamples * nSamples);890 for (psS32 i = 0 ; i < inData->n; i++) {891 inData->data[i] = (psPtr *) psPlaneAlloc();892 outData->data[i] = (psPtr *) psPlaneAlloc();893 }894 895 //896 866 // Initialize the grid. Since we want the inverse of the transformation, the 897 867 // inCoords are written to the outData vector, and the outCoords are written 898 868 // to the inData vector. 899 869 // 870 psVector *xIn = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64); 871 psVector *yIn = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64); 872 psVector *xOut = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64); 873 psVector *yOut = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64); 874 psPlane *inCoord = psPlaneAlloc(); 875 psPlane *outCoord = psPlaneAlloc(); 900 876 psS32 cnt = 0; 901 877 for (int yint = 0; yint < nSamples; yint++) { … … 904 880 inCoord->x = region.x0 + ((psF32) xint) * ((region.x1 - region.x0) / ((psF32) nSamples)); 905 881 (void)psPlaneTransformApply(outCoord, in, inCoord); 906 ((psPlane *) outData->data[cnt])->x = inCoord->x; 907 ((psPlane *) outData->data[cnt])->y = inCoord->y; 908 ((psPlane *) inData->data[cnt])->x = outCoord->x; 909 ((psPlane *) inData->data[cnt])->y = outCoord->y; 910 882 xOut->data.F64[cnt] = inCoord->x; 883 yOut->data.F64[cnt] = inCoord->y; 884 xIn->data.F64[cnt] = outCoord->x; 885 yIn->data.F64[cnt] = outCoord->y; 911 886 cnt++; 912 887 } 913 888 } 914 // XXX: what values should be used here? 915 bool rc = psPlaneTransformFit(myPT, inData, outData, 10, 100.0); 889 890 myPT->x = psVectorFitPolynomial2D(myPT->x, NULL, 0, xOut, NULL, xIn, yIn); 891 myPT->y = psVectorFitPolynomial2D(myPT->y, NULL, 0, yOut, NULL, xIn, yIn); 916 892 917 893 psFree(inCoord); 918 894 psFree(outCoord); 919 psFree(inData); 920 psFree(outData); 921 922 if (rc == true) { 923 return(myPT); 924 } else { 925 psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not fit a transform to coordinates."); 895 psFree(xIn); 896 psFree(yIn); 897 psFree(xOut); 898 psFree(yOut); 899 900 if ((myPT->x == NULL) || (myPT->y == NULL)) { 901 psError( PS_ERR_UNKNOWN, true, "psVectorFitPolynomial2D() returned NULL: could not fit a 2-D polynomial to the data.\n"); 902 psFree(out); 926 903 return(NULL); 927 904 } 928 } 905 906 return(myPT); 907 } 908 929 909 930 910 psPlane *psPlaneTransformDeriv(
Note:
See TracChangeset
for help on using the changeset viewer.
