IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 16, 2023, 10:30:15 AM (3 years ago)
Author:
eugene
Message:

add 2D, 3D, 4D versions of psVectorIRLSFitPolynomial, psPolynomialCopy, psPolynomialRecycle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/psLib/src/math/psPolynomial.c

    r42492 r42506  
    944944    bool match = true;
    945945    match &= (poly->type == type);
    946     match &= (poly->nX == type);
     946    match &= (poly->nX   == nX);
    947947
    948948    if (!match) {
    949         psFree (poly->coeff);
    950         psFree (poly->coeffErr);
    951         psFree (poly->coeffMask);
     949        polynomial1DFree (poly); // frees the coeffs
    952950
    953951        poly->type = type;
    954         poly->nX = nX;
     952        poly->nX   = nX;
    955953
    956954        poly->coeff = psAlloc((1 + nX) * sizeof(psF64));
     
    976974    bool match = true;
    977975    match &= (poly->type == type);
    978     match &= (poly->nX == type);
    979     match &= (poly->nY == type);
     976    match &= (poly->nX ==   nX);
     977    match &= (poly->nY ==   nY);
    980978
    981979    if (!match) {
    982         for (int i = 0; i < poly->nX + 1; i++) {
    983             psFree (poly->coeff[i]);
    984             psFree (poly->coeffErr[i]);
    985             psFree (poly->coeffMask[i]);
    986         }
    987         psFree (poly->coeff);
    988         psFree (poly->coeffErr);
    989         psFree (poly->coeffMask);
     980        polynomial2DFree (poly); // frees the coeffs
    990981
    991982        poly->type = type;
    992         poly->nX = nX;
    993         poly->nY = nY;
     983        poly->nX   = nX;
     984        poly->nY   = nY;
    994985
    995986        poly->coeff = psAlloc((1 + nX) * sizeof(psF64 *));
     
    10121003}
    10131004
    1014 // XXX 3D, 4D versions
     1005bool psPolynomial3DRecycle(psPolynomial3D *poly,
     1006                           psPolynomialType type,
     1007                           unsigned int nX,
     1008                           unsigned int nY,
     1009                           unsigned int nZ)
     1010{
     1011    PS_ASSERT_INT_NONNEGATIVE(nX, NULL);
     1012    PS_ASSERT_INT_NONNEGATIVE(nY, NULL);
     1013    PS_ASSERT_INT_NONNEGATIVE(nZ, NULL);
     1014
     1015    bool match = true;
     1016    match &= (poly->type == type);
     1017    match &= (poly->nX   == nX);
     1018    match &= (poly->nY   == nY);
     1019    match &= (poly->nZ   == nZ);
     1020
     1021    if (!match) {
     1022        polynomial3DFree (poly); // frees the coeffs
     1023
     1024        poly->type = type;
     1025        poly->nX = nX;
     1026        poly->nY = nY;
     1027        poly->nZ = nZ;
     1028
     1029        poly->coeff = psAlloc((nX + 1) * sizeof(psF64 **));
     1030        poly->coeffErr = psAlloc((nX + 1) * sizeof(psF64 **));
     1031        poly->coeffMask = (psMaskType ***)psAlloc((nX + 1) * sizeof(psMaskType **));
     1032        for (int ix = 0; ix < (1 + nX); ix++) {
     1033            poly->coeff[ix] = psAlloc((nY + 1) * sizeof(psF64 *));
     1034            poly->coeffErr[ix] = psAlloc((nY + 1) * sizeof(psF64 *));
     1035            poly->coeffMask[ix] = (psMaskType **)psAlloc((nY + 1) * sizeof(psMaskType *));
     1036            for (int iy = 0; iy < (nY + 1); iy++) {
     1037                poly->coeff[ix][iy] = psAlloc((nZ + 1) * sizeof(psF64));
     1038                poly->coeffErr[ix][iy] = psAlloc((nZ + 1) * sizeof(psF64));
     1039                poly->coeffMask[ix][iy] = (psMaskType *)psAlloc((nZ + 1) * sizeof(psMaskType));
     1040            }
     1041        }
     1042    }
     1043    for (int ix = 0; ix < (1 + nX); ix++) {
     1044        for (int iy = 0; iy < (1 + nY); iy++) {
     1045            for (int iz = 0; iz < (1 + nZ); iz++) {
     1046                poly->coeff[ix][iy][iz]     = 0.0;
     1047                poly->coeffErr[ix][iy][iz]  = 0.0;
     1048                poly->coeffMask[ix][iy][iz] = PS_POLY_MASK_NONE;
     1049            }
     1050        }
     1051    }
     1052    return(true);
     1053}
     1054
     1055bool psPolynomial4DRecycle(psPolynomial4D *poly,
     1056                           psPolynomialType type,
     1057                           unsigned int nX,
     1058                           unsigned int nY,
     1059                           unsigned int nZ,
     1060                           unsigned int nT)
     1061{
     1062    PS_ASSERT_INT_NONNEGATIVE(nX, NULL);
     1063    PS_ASSERT_INT_NONNEGATIVE(nY, NULL);
     1064    PS_ASSERT_INT_NONNEGATIVE(nZ, NULL);
     1065    PS_ASSERT_INT_NONNEGATIVE(nT, NULL);
     1066
     1067    bool match = true;
     1068    match &= (poly->type == type);
     1069    match &= (poly->nX   == nX);
     1070    match &= (poly->nY   == nY);
     1071    match &= (poly->nZ   == nZ);
     1072    match &= (poly->nT   == nT);
     1073
     1074    if (!match) {
     1075        polynomial4DFree (poly); // frees the coeffs
     1076
     1077        poly->type = type;
     1078        poly->nX = nX;
     1079        poly->nY = nY;
     1080        poly->nZ = nZ;
     1081        poly->nT = nT;
     1082
     1083        poly->coeff = psAlloc((nX + 1) * sizeof(psF64 ***));
     1084        poly->coeffErr = psAlloc((nX + 1) * sizeof(psF64 ***));
     1085        poly->coeffMask = (psMaskType ****)psAlloc((nX + 1) * sizeof(psMaskType ***));
     1086        for (int ix = 0; ix < (nX + 1); ix++) {
     1087            poly->coeff[ix] = psAlloc((nY + 1) * sizeof(psF64 **));
     1088            poly->coeffErr[ix] = psAlloc((nY + 1) * sizeof(psF64 **));
     1089            poly->coeffMask[ix] = (psMaskType ***)psAlloc((nY + 1) * sizeof(psMaskType **));
     1090            for (int iy = 0; iy < (nY + 1); iy++) {
     1091                poly->coeff[ix][iy] = psAlloc((nZ + 1) * sizeof(psF64 *));
     1092                poly->coeffErr[ix][iy] = psAlloc((nZ + 1) * sizeof(psF64 *));
     1093                poly->coeffMask[ix][iy] = (psMaskType **)psAlloc((nZ + 1) * sizeof(psMaskType *));
     1094                for (int iz = 0; iz < (nZ + 1); iz++) {
     1095                    poly->coeff[ix][iy][iz] = psAlloc((nT + 1) * sizeof(psF64));
     1096                    poly->coeffErr[ix][iy][iz] = psAlloc((nT + 1) * sizeof(psF64));
     1097                    poly->coeffMask[ix][iy][iz] = (psMaskType *)psAlloc((nT + 1) * sizeof(psMaskType));
     1098                }
     1099            }
     1100        }
     1101    }
     1102    for (int ix = 0; ix < (1 + nX); ix++) {
     1103        for (int iy = 0; iy < (1 + nY); iy++) {
     1104            for (int iz = 0; iz < (1 + nZ); iz++) {
     1105                for (int it = 0; it < (1 + nT); it++) {
     1106                    poly->coeff[ix][iy][iz][it]     = 0.0;
     1107                    poly->coeffErr[ix][iy][iz][it]  = 0.0;
     1108                    poly->coeffMask[ix][iy][iz][it] = PS_POLY_MASK_NONE;
     1109                }
     1110            }
     1111        }
     1112    }
     1113    return(true);
     1114}
     1115
     1116// ######## Copy polynomials ########
    10151117psPolynomial1D *psPolynomial1DCopy(psPolynomial1D *out,
    1016                                    psPolynomial1D *poly)
     1118                                   psPolynomial1D *poly)
    10171119{
    10181120    if (out == NULL) {
    1019         out = psPolynomial1DAlloc (poly->type, poly->nX);
     1121        out = psPolynomial1DAlloc (poly->type, poly->nX);
    10201122    } else {
    1021         psPolynomial1DRecycle (out, poly->type, poly->nX);
     1123        psPolynomial1DRecycle (out, poly->type, poly->nX);
    10221124    }
    10231125
     
    10301132}
    10311133psPolynomial2D *psPolynomial2DCopy(psPolynomial2D *out,
    1032                                    psPolynomial2D *poly)
     1134                                   psPolynomial2D *poly)
    10331135{
    10341136    if (out == NULL) {
    1035         out = psPolynomial2DAlloc (poly->type, poly->nX, poly->nY);
     1137        out = psPolynomial2DAlloc (poly->type, poly->nX, poly->nY);
    10361138    } else {
    1037         psPolynomial2DRecycle (out, poly->type, poly->nX, poly->nY);
     1139        psPolynomial2DRecycle (out, poly->type, poly->nX, poly->nY);
    10381140    }
    10391141
    10401142    for (int i = 0; i < (1 + poly->nX); i++) {
    1041         for (int j = 0; j < (1 + poly->nY); j++) {
    1042             out->coeff[i][j] = poly->coeff[i][j];
    1043             out->coeffErr[i][j] = poly->coeffErr[i][j];
    1044             out->coeffMask[i][j] = poly->coeffMask[i][j];
    1045         }
     1143        for (int j = 0; j < (1 + poly->nY); j++) {
     1144            out->coeff[i][j] = poly->coeff[i][j];
     1145            out->coeffErr[i][j] = poly->coeffErr[i][j];
     1146            out->coeffMask[i][j] = poly->coeffMask[i][j];
     1147        }
     1148    }
     1149    return(out);
     1150}
     1151psPolynomial3D *psPolynomial3DCopy(psPolynomial3D *out,
     1152                                   psPolynomial3D *poly)
     1153{
     1154    if (out == NULL) {
     1155        out = psPolynomial3DAlloc (poly->type, poly->nX, poly->nY, poly->nZ);
     1156    } else {
     1157        psPolynomial3DRecycle (out, poly->type, poly->nX, poly->nY, poly->nZ);
     1158    }
     1159
     1160    for (int ix = 0; ix < (1 + poly->nX); ix++) {
     1161        for (int iy = 0; iy < (1 + poly->nY); iy++) {
     1162            for (int iz = 0; iz < (1 + poly->nZ); iz++) {
     1163                out->coeff[ix][iy][iz] = poly->coeff[ix][iy][iz];
     1164                out->coeffErr[ix][iy][iz] = poly->coeffErr[ix][iy][iz];
     1165                out->coeffMask[ix][iy][iz] = poly->coeffMask[ix][iy][iz];
     1166            }
     1167        }
     1168    }
     1169    return(out);
     1170}
     1171psPolynomial4D *psPolynomial4DCopy(psPolynomial4D *out,
     1172                                   psPolynomial4D *poly)
     1173{
     1174    if (out == NULL) {
     1175        out = psPolynomial4DAlloc (poly->type, poly->nX, poly->nY, poly->nZ, poly->nT);
     1176    } else {
     1177        psPolynomial4DRecycle (out, poly->type, poly->nX, poly->nY, poly->nZ, poly->nT);
     1178    }
     1179
     1180    for (int ix = 0; ix < (1 + poly->nX); ix++) {
     1181        for (int iy = 0; iy < (1 + poly->nY); iy++) {
     1182            for (int iz = 0; iz < (1 + poly->nZ); iz++) {
     1183                for (int it = 0; it < (1 + poly->nT); it++) {
     1184                    out->coeff[ix][iy][iz][it] = poly->coeff[ix][iy][iz][it];
     1185                    out->coeffErr[ix][iy][iz][it] = poly->coeffErr[ix][iy][iz][it];
     1186                    out->coeffMask[ix][iy][iz][it] = poly->coeffMask[ix][iy][iz][it];
     1187                }
     1188            }
     1189        }
    10461190    }
    10471191    return(out);
     
    10801224
    10811225    switch (x->type.type) {
    1082     case PS_TYPE_F64:
     1226      case PS_TYPE_F64:
    10831227        tmp = psVectorAlloc(x->n, PS_TYPE_F64);
    10841228        for (unsigned int i=0;i<x->n;i++) {
     
    10861230        }
    10871231        break;
    1088     case PS_TYPE_F32:
     1232      case PS_TYPE_F32:
    10891233        tmp = psVectorAlloc(x->n, PS_TYPE_F32);
    10901234        for (unsigned int i=0;i<x->n;i++) {
     
    10921236        }
    10931237        break;
    1094     default:
     1238      default:
    10951239        psError(PS_ERR_UNKNOWN, false, "invalid input data type.\n");
    10961240        return (NULL);
Note: See TracChangeset for help on using the changeset viewer.