IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 15, 2005, 2:06:33 PM (21 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psFunctions.c

    r4567 r4568  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-07-15 23:19:41 $
     9 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-07-16 00:06:32 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    18181818    must exist n+1 points in "knots".
    18191819 
    1820 XXX: Ensure that domain[i+1] != domain[i]
     1820XXX: Is this really needed anymore?
    18211821 
    1822 XXX: What should be the defualty type for knots be?  psF32 is assumed.
     1822XXX: Ensure that knots[i+1] != knots[i]
     1823 
     1824XXX: What should be the default type for knots be?  psF32 is assumed.
    18231825 *****************************************************************************/
    1824 psSpline1D *psSpline1DAlloc( int numSplines,
    1825                              int order,
    1826                              float min,
    1827                              float max)
    1828 {
     1826psSpline1D *psSpline1DAlloc(int numSplines,
     1827                            int order,
     1828                            float min,
     1829                            float max)
     1830{
     1831    printf("HEY: psSpline1DAlloc()\n");
    18291832    PS_ASSERT_INT_NONNEGATIVE(numSplines, NULL);
    18301833    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
    18311834    PS_ASSERT_FLOAT_NON_EQUAL(max, min, NULL);
    18321835
    1833     psSpline1D *tmp = NULL;
    1834     psS32 i;
    1835     psF32 tmpDomain;
    1836     psF32 width;
    1837 
    1838     tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
    1839     tmp->n = numSplines;
    1840 
    1841     tmp->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
    1842     for (i=0;i<numSplines;i++) {
    1843         (tmp->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
    1844     }
    1845 
    1846     // This should be set by the psVectorFitSpline1D()
    1847     tmp->p_psDeriv2 = NULL;
    1848 
    1849     tmp->knots = psVectorAlloc(numSplines+1, PS_TYPE_F32);
    1850     width = (max - min) / ((psF32) numSplines);
    1851 
    1852     tmp->knots->data.F32[0] = min;
    1853     tmpDomain = min+width;
    1854     for (i=1;i<numSplines+1;i++) {
    1855         tmp->knots->data.F32[i] = tmpDomain;
    1856         tmpDomain+= width;
    1857     }
    1858     tmp->knots->data.F32[numSplines] = max;
    1859 
    1860     psMemSetDeallocator(tmp,(psFreeFunc)spline1DFree);
    1861     return(tmp);
    1862 }
    1863 
     1836    psSpline1D *tmpSpline = (psSpline1D *) psAlloc(sizeof(psSpline1D));
     1837    tmpSpline->n = numSplines;
     1838
     1839    //
     1840    // XXX: We might have to allocate single or double polynomials depending on the type
     1841    // of the psVector bounds.  For now, all knots and spline polynomials are 32-bit.
     1842    //
     1843    tmpSpline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
     1844    for (psS32 i=0;i<numSplines;i++) {
     1845        (tmpSpline->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
     1846    }
     1847
     1848    // This will be computed by psVectorFitSpline1D()
     1849    tmpSpline->p_psDeriv2 = NULL;
     1850
     1851    //
     1852    // XXX:Ensure that the knots are distinct, and monotonic.
     1853    //
     1854    tmpSpline->knots = psVectorAlloc(numSplines+1, PS_TYPE_F32);
     1855    if (tmpSpline->knots == NULL) {
     1856        printf("BAD\n");
     1857    } else {
     1858        printf("GOOD\n");
     1859    }
     1860    psF32 width = (max - min) / ((psF32) numSplines);
     1861    tmpSpline->knots->data.F32[0] = min;
     1862    for (psS32 i=1;i<numSplines;i++) {
     1863        tmpSpline->knots->data.F32[i] = min + (width * (psF32) i);
     1864    }
     1865    tmpSpline->knots->data.F32[numSplines] = max;
     1866
     1867    psMemSetDeallocator(tmpSpline, (psFreeFunc)spline1DFree);
     1868    return(tmpSpline);
     1869}
    18641870
    18651871/*****************************************************************************
    1866 XXX: What should be the defualty type for knots be?  psF32 is assumed.
     1872XXX: Is there a psLib function for this?
     1873 *****************************************************************************/
     1874psVector *PsVectorDup(psVector *in)
     1875{
     1876    psVector *out = psVectorAlloc(in->n, in->type.type);
     1877
     1878    if (in->type.type == PS_TYPE_F32) {
     1879        for (psS32 i = 0 ; i < in->n ; i++) {
     1880            out->data.F32[i] = in->data.F32[i];
     1881        }
     1882    } else if (in->type.type == PS_TYPE_F64) {
     1883        for (psS32 i = 0 ; i < in->n ; i++) {
     1884            out->data.F64[i] = in->data.F64[i];
     1885        }
     1886    } else {
     1887        printf("XXX: Generate an error here.\n");
     1888        return(NULL);
     1889    }
     1890    return(out);
     1891}
     1892
     1893/*****************************************************************************
     1894XXX: What should be the default type for knots, spline polys?  psF32 is assumed.
    18671895 *****************************************************************************/
    18681896psSpline1D *psSpline1DAllocGeneric(const psVector *bounds,
    18691897                                   int order)
    18701898{
     1899    printf("HEY: psSpline1DAllocGeneric()\n");
    18711900    PS_ASSERT_VECTOR_NON_NULL(bounds, NULL);
    18721901    PS_ASSERT_VECTOR_NON_EMPTY(bounds, NULL);
     1902    PS_ASSERT_VECTOR_TYPE(bounds, PS_TYPE_F32, NULL);
    18731903    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
    18741904
    1875     psSpline1D *tmpSpline = NULL;
    1876     unsigned int i;
    1877     unsigned int numSplines;
    1878 
    1879     tmpSpline = (psSpline1D *) psAlloc(sizeof(psSpline1D));
    1880 
    1881     numSplines = bounds->n - 1;
     1905    psSpline1D *tmpSpline = (psSpline1D *) psAlloc(sizeof(psSpline1D));
     1906    psS32 numSplines = bounds->n - 1;
    18821907    tmpSpline->n = numSplines;
    18831908
     1909    //
     1910    // XXX: We might have to allocate single or double polynomials depending on the type
     1911    // of the psVector bounds.  For now, all knots and spline polynomials are 32-bit.
     1912    //
    18841913    tmpSpline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
    1885     for (i=0;i<numSplines;i++) {
     1914    for (psS32 i=0;i<numSplines;i++) {
    18861915        (tmpSpline->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
    18871916    }
    18881917
    1889     // This should be set by the psVectorFitSpline1D()
     1918    // This will be computed by psVectorFitSpline1D()
    18901919    tmpSpline->p_psDeriv2 = NULL;
    18911920
    1892     tmpSpline->knots = psVectorAlloc(bounds->n, PS_TYPE_F32);
    1893 
    1894     for (i=0;i<bounds->n;i++) {
    1895         tmpSpline->knots->data.F32[i] = bounds->data.F32[i];
    1896         if (i<(bounds->n-1)) {
    1897             if (FLT_EPSILON >= fabs(bounds->data.F32[i+1]-bounds->data.F32[i])) {
    1898                 psError(PS_ERR_UNKNOWN, true, "data points must be distinct\n");
    1899             }
    1900         }
    1901     }
    1902 
    1903     psMemSetDeallocator(tmpSpline,(psFreeFunc)spline1DFree);
     1921    //
     1922    // Ensure that all knots are distinct.
     1923    // XXX:Ensure that the knots are monotonic.
     1924    //
     1925    for (psS32 i=0;i<bounds->n-1;i++) {
     1926        if (FLT_EPSILON >= fabs(bounds->data.F32[i+1]-bounds->data.F32[i])) {
     1927            psError(PS_ERR_UNKNOWN, true, "data points must be distinct\n");
     1928            return(NULL);
     1929        }
     1930    }
     1931    tmpSpline->knots = PsVectorDup((psVector *) bounds);
     1932    if (tmpSpline->knots == NULL) {
     1933        printf("BAD\n");
     1934    } else {
     1935        printf("GOOD\n");
     1936    }
     1937
     1938    psMemSetDeallocator(tmpSpline, (psFreeFunc)spline1DFree);
    19041939    return(tmpSpline);
    19051940}
Note: See TracChangeset for help on using the changeset viewer.