Changeset 4568 for trunk/psLib/src/math/psFunctions.c
- Timestamp:
- Jul 15, 2005, 2:06:33 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psFunctions.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psFunctions.c
r4567 r4568 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-07-1 5 23:19:41$9 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-07-16 00:06:32 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 1818 1818 must exist n+1 points in "knots". 1819 1819 1820 XXX: Ensure that domain[i+1] != domain[i]1820 XXX: Is this really needed anymore? 1821 1821 1822 XXX: What should be the defualty type for knots be? psF32 is assumed. 1822 XXX: Ensure that knots[i+1] != knots[i] 1823 1824 XXX: What should be the default type for knots be? psF32 is assumed. 1823 1825 *****************************************************************************/ 1824 psSpline1D *psSpline1DAlloc( int numSplines, 1825 int order, 1826 float min, 1827 float max) 1828 { 1826 psSpline1D *psSpline1DAlloc(int numSplines, 1827 int order, 1828 float min, 1829 float max) 1830 { 1831 printf("HEY: psSpline1DAlloc()\n"); 1829 1832 PS_ASSERT_INT_NONNEGATIVE(numSplines, NULL); 1830 1833 PS_ASSERT_INT_NONNEGATIVE(order, NULL); 1831 1834 PS_ASSERT_FLOAT_NON_EQUAL(max, min, NULL); 1832 1835 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 } 1864 1870 1865 1871 /***************************************************************************** 1866 XXX: What should be the defualty type for knots be? psF32 is assumed. 1872 XXX: Is there a psLib function for this? 1873 *****************************************************************************/ 1874 psVector *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 /***************************************************************************** 1894 XXX: What should be the default type for knots, spline polys? psF32 is assumed. 1867 1895 *****************************************************************************/ 1868 1896 psSpline1D *psSpline1DAllocGeneric(const psVector *bounds, 1869 1897 int order) 1870 1898 { 1899 printf("HEY: psSpline1DAllocGeneric()\n"); 1871 1900 PS_ASSERT_VECTOR_NON_NULL(bounds, NULL); 1872 1901 PS_ASSERT_VECTOR_NON_EMPTY(bounds, NULL); 1902 PS_ASSERT_VECTOR_TYPE(bounds, PS_TYPE_F32, NULL); 1873 1903 PS_ASSERT_INT_NONNEGATIVE(order, NULL); 1874 1904 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; 1882 1907 tmpSpline->n = numSplines; 1883 1908 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 // 1884 1913 tmpSpline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *)); 1885 for ( i=0;i<numSplines;i++) {1914 for (psS32 i=0;i<numSplines;i++) { 1886 1915 (tmpSpline->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD); 1887 1916 } 1888 1917 1889 // This should be set by thepsVectorFitSpline1D()1918 // This will be computed by psVectorFitSpline1D() 1890 1919 tmpSpline->p_psDeriv2 = NULL; 1891 1920 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); 1904 1939 return(tmpSpline); 1905 1940 }
Note:
See TracChangeset
for help on using the changeset viewer.
