Changeset 1823
- Timestamp:
- Sep 16, 2004, 4:14:52 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 8 edited
-
dataManip/psFunctions.c (modified) (7 diffs)
-
dataManip/psFunctions.h (modified) (3 diffs)
-
dataManip/psStats.c (modified) (6 diffs)
-
math/psPolynomial.c (modified) (7 diffs)
-
math/psPolynomial.h (modified) (3 diffs)
-
math/psSpline.c (modified) (7 diffs)
-
math/psSpline.h (modified) (3 diffs)
-
math/psStats.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psFunctions.c
r1784 r1823 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-09-1 0 23:20:29$9 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-09-17 02:14:52 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psMemory.h" 25 25 #include "psVector.h" 26 #include "psScalar.h" 26 27 #include "psTrace.h" 27 28 #include "psError.h" … … 1682 1683 1683 1684 /***************************************************************************** 1684 VectorBinDisect (): This is a private function which takes as input a vector1685 of floating point data as well as a single floating point values. The input 1686 vector values are assumed to be non-decreasing (v[i-1] <= v[j] for all j>=i). 1687 This routine does a binary disection of the vector and returns "i" such 1688 that (v[i] <= x <= v[i+1). If x lies outside the range of v[],1685 VectorBinDisectF32(): This is a private function which takes as input a 1686 vector of floating point data as well as a single floating point values. 1687 The input vector values are assumed to be non-decreasing (v[i-1] <= v[j] for 1688 all j>=i). This routine does a binary disection of the vector and returns 1689 "i" such that (v[i] <= x <= v[i+1). If x lies outside the range of v[], 1689 1690 then this routine prints a warning message and returns -1. 1691 1692 XXX: Macro this for a few different types. 1690 1693 *****************************************************************************/ 1691 int VectorBinDisect (float *bins,1692 int numBins,1693 float x)1694 int VectorBinDisectF32(float *bins, 1695 int numBins, 1696 float x) 1694 1697 { 1695 1698 int min; … … 1697 1700 int mid; 1698 1701 1699 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1700 "---- Calling VectorBinDisect (%f)\n", x);1702 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1703 "---- Calling VectorBinDisectF32(%f)\n", x); 1701 1704 1702 1705 if ((x < bins[0]) || 1703 1706 (x > bins[numBins-1])) { 1704 1707 psLogMsg(__func__, PS_LOG_WARN, 1705 "VectorBinDisect (): ordinate %f is outside vector range (%f - %f).",1708 "VectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).", 1706 1709 x, bins[0], bins[numBins-1]); 1707 1710 return(-1); … … 1713 1716 1714 1717 while (min != max) { 1715 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1718 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1716 1719 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1717 1720 min, mid, max, x, bins[mid]); 1718 1721 1719 1722 if (x == bins[mid]) { 1720 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect", 4, 1721 "---- Exiting VectorBinDisect(): bin %d\n", min); 1723 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1724 "---- Exiting VectorBinDisectF32(): bin %d\n", mid); 1725 return(mid); 1726 } else if (x < bins[mid]) { 1727 max = mid-1; 1728 } else { 1729 min = mid; 1730 } 1731 mid = ((max+1)+min)/2; 1732 } 1733 1734 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1735 "---- Exiting VectorBinDisectF32(): bin %d\n", min); 1736 return(min); 1737 } 1738 1739 /***************************************************************************** 1740 VectorBinDisectS32(): integer version of above. 1741 *****************************************************************************/ 1742 int VectorBinDisectS32(int *bins, 1743 int numBins, 1744 int x) 1745 { 1746 int min; 1747 int max; 1748 int mid; 1749 1750 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1751 "---- Calling VectorBinDisectS32(%f)\n", x); 1752 1753 if ((x < bins[0]) || 1754 (x > bins[numBins-1])) { 1755 psLogMsg(__func__, PS_LOG_WARN, 1756 "VectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).", 1757 x, bins[0], bins[numBins-1]); 1758 return(-1); 1759 } 1760 1761 min = 0; 1762 max = numBins-2; 1763 mid = ((max+1)-min)/2; 1764 1765 while (min != max) { 1766 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1767 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1768 min, mid, max, x, bins[mid]); 1769 1770 if (x == bins[mid]) { 1771 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1772 "---- Exiting VectorBinDisectS32(): bin %d\n", min); 1722 1773 return(min); 1723 1774 } else if (x < bins[mid]) { … … 1729 1780 } 1730 1781 1731 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1732 "---- Exiting VectorBinDisect (): bin %d\n", min);1782 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1783 "---- Exiting VectorBinDisectS32(): bin %d\n", min); 1733 1784 return(min); 1734 1785 } 1786 1787 /***************************************************************************** 1788 p_psVectorBinDisect(): A wrapper to the above VectorBinDisect(). 1789 *****************************************************************************/ 1790 int p_psVectorBinDisect(psVector *bins, 1791 psScalar *x) 1792 { 1793 if (x->type.type != bins->type.type) { 1794 // XXX: Generate error message. 1795 return(-1); 1796 } 1797 1798 if (x->type.type == PS_TYPE_S32) { 1799 return(VectorBinDisectS32(bins->data.S32, bins->n, x->data.S32)); 1800 } else if (x->type.type == PS_TYPE_F32) { 1801 return(VectorBinDisectF32(bins->data.F32, bins->n, x->data.F32)); 1802 } else { 1803 // XXX: Generate error message. 1804 } 1805 return(-1); 1806 } 1807 1808 /***************************************************************************** 1809 p_psInterpolate1D(): This routine will take as input n-element floating 1810 point arrays domain and range, and the x value, assumed to lie with the 1811 domain vector. It produces as output the n-order LaGrange interpolated 1812 value of x. 1813 1814 XXX: do we error check for non-distinct domain values? 1815 *****************************************************************************/ 1816 float p_psFullInterpolate1DF32(float *domain, 1817 float *range, 1818 int n, 1819 float x) 1820 { 1821 int i; 1822 int m; 1823 static psVector *p = NULL; 1824 psVectorRecycle(p, n, PS_TYPE_F32); 1825 p_psMemSetPersistent(p, true); 1826 1827 // From NR, during each iteration of the m loop, we are computing the 1828 // p_{i ... i+m} terms. 1829 for (m=0;m<n;m++) { 1830 for (i=0;i<n-m;i++) { 1831 if (m == 0) { 1832 p->data.F32[i] = range[i]; 1833 } else { 1834 // From NR: we are computing P_{i ... i+m} 1835 p->data.F32[i] = (((x-range[i+m]) * p->data.F32[i]) + 1836 ((range[i]-x) * p->data.F32[i+1])) / 1837 (domain[i] - domain[i+m]); 1838 } 1839 } 1840 } 1841 return(p->data.F32[0]); 1842 } 1843 1844 1845 // This is a 1846 float p_psInterpolate1DF32(float *domain, 1847 float *range, 1848 int n, 1849 int order, 1850 float x) 1851 { 1852 int binNum; 1853 int numIntPoints = order+1; 1854 int origin; 1855 1856 binNum = VectorBinDisectF32(domain, n, x); 1857 if (0 == numIntPoints%2) { 1858 origin = binNum - ((numIntPoints/2) - 1); 1859 } else { 1860 origin = binNum - (numIntPoints/2); 1861 if ((x-domain[binNum]) > (domain[binNum+1]-x)) { 1862 // x is closer to binNum+1. 1863 origin = 1 + (binNum - (numIntPoints/2)); 1864 } 1865 } 1866 if (origin < 0) { 1867 origin = 0; 1868 } 1869 if ((origin + numIntPoints) > n) { 1870 origin = n - numIntPoints; 1871 } 1872 1873 return(p_psFullInterpolate1DF32(&domain[origin], &range[origin], n, x)); 1874 } 1875 1876 /***************************************************************************** 1877 p_psInterpolate1D(): This routine will take as input psVectors domain and 1878 range, and the x value, assumed to lie with the domain vector. It produces 1879 as output the LaGrange interpolated value of a polynomial of the specified 1880 order around the point x. 1881 1882 XXX: This stuff does not work with a mask. 1883 *****************************************************************************/ 1884 float p_psInterpolate1D(psVector *domain, 1885 psVector *range, 1886 int order, 1887 psScalar *x) 1888 { 1889 if (domain->type.type != range->type.type != x->type.type) { 1890 // XXX psError 1891 } 1892 if (domain->n != range->n) { 1893 // XXX psError 1894 } 1895 if (order > (domain->n - 1)) { 1896 // XXX psError: not enough data points for order-order interpolation. 1897 } 1898 1899 if (x->type.type == PS_TYPE_F32) { 1900 return(p_psInterpolate1DF32(domain->data.F32, range->data.F32, 1901 domain->n, order, x->data.F32)); 1902 } else { 1903 // XXX psError: type not supported 1904 } 1905 1906 return(-1.0); 1907 } 1908 1735 1909 1736 1910 float psSpline1DEval(const psSpline1D *spline, … … 1741 1915 1742 1916 n = spline->n; 1743 binNum = VectorBinDisect (spline->domains, (spline->n)+1, x);1917 binNum = VectorBinDisectF32(spline->domains, (spline->n)+1, x); 1744 1918 if (binNum == -1) { 1745 1919 psLogMsg(__func__, PS_LOG_WARN, -
trunk/psLib/src/dataManip/psFunctions.h
r1775 r1823 12 12 * @author George Gusciora, MHPCC 13 13 * 14 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-09-1 0 02:52:02 $14 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-09-17 02:14:52 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 25 25 #include "psVector.h" 26 #include "psScalar.h" 26 27 27 28 /** \addtogroup Stats … … 405 406 psVector *data); 406 407 408 int p_psVectorBinDisect(psVector *bins, 409 psScalar *x); 407 410 408 411 /* \} */// End of MathGroup Functions 409 412 410 413 #endif 414 -
trunk/psLib/src/dataManip/psStats.c
r1722 r1823 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-09- 08 06:04:30$11 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-09-17 02:14:52 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1449 1449 void p_ps_FitTheGaussian() 1450 1450 { 1451 1452 1451 // Fit a Gaussian to the bins in the range MODE-dL to Mode+dL 1453 1452 // NOTE: This code uses the psMinimize.c functions to perform … … 1455 1454 // I am commenting this code out, and replacing it with code which 1456 1455 // calculates the mean directly on the robustHistogram. 1456 // 1457 // XXX: Replace this with the LaGrange interpolation stuff. 1457 1458 1458 1459 domain = psImageAlloc(1, robustHistogramVector->n, PS_TYPE_F32); … … 1671 1672 psHistogram* psVectorHistogram(psHistogram* out, 1672 1673 const psVector* restrict in, 1673 const psVector* restrict mask, unsigned int maskVal) 1674 const psVector* restrict mask, 1675 unsigned int maskVal) 1674 1676 { 1675 1677 int i = 0; // Loop index variable 1676 int j = 0; // Loop index variable1677 1678 float binSize = 0.0; // Histogram bin size 1678 1679 int binNum = 0; // A temporary bin number 1679 1680 int numBins = 0; // The total number of bins 1681 int tmp = 0; 1682 psScalar tmpScalar; 1683 tmpScalar.type.type = PS_TYPE_F32; 1680 1684 1681 1685 // NOTE: Verify that this is the correct action. … … 1708 1712 } 1709 1713 } 1714 1710 1715 // NOTE: determine the correct action for a variety of other cases: 1711 1716 // in vector has 0 elements, and histogram structure has zero bins. … … 1742 1747 // bin number requires a bit more work. 1743 1748 } else { 1744 // NOTE: This is slow. Put a smarter algorithm here to1745 // find the correct bin number (bin search, probably)1746 for (j = 0; j < (out->bounds->n) - 1; j++) {1747 if ((out->bounds->data.S32[j] <= in->data.F32[i]) &&1748 (in->data.F32[i] <= out->bounds->data.S32[j + 1])) {1749 (out->nums->data.S32[j])++;1750 }1749 tmpScalar.data.F32 = in->data.F32[i]; 1750 tmp = p_psVectorBinDisect(out->bounds, 1751 &tmpScalar); 1752 if (tmp == -1) { 1753 // XXX: Generate warning message 1754 } else { 1755 (out->nums->data.S32[tmp])++; 1751 1756 } 1752 1757 } -
trunk/psLib/src/math/psPolynomial.c
r1784 r1823 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-09-1 0 23:20:29$9 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-09-17 02:14:52 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psMemory.h" 25 25 #include "psVector.h" 26 #include "psScalar.h" 26 27 #include "psTrace.h" 27 28 #include "psError.h" … … 1682 1683 1683 1684 /***************************************************************************** 1684 VectorBinDisect (): This is a private function which takes as input a vector1685 of floating point data as well as a single floating point values. The input 1686 vector values are assumed to be non-decreasing (v[i-1] <= v[j] for all j>=i). 1687 This routine does a binary disection of the vector and returns "i" such 1688 that (v[i] <= x <= v[i+1). If x lies outside the range of v[],1685 VectorBinDisectF32(): This is a private function which takes as input a 1686 vector of floating point data as well as a single floating point values. 1687 The input vector values are assumed to be non-decreasing (v[i-1] <= v[j] for 1688 all j>=i). This routine does a binary disection of the vector and returns 1689 "i" such that (v[i] <= x <= v[i+1). If x lies outside the range of v[], 1689 1690 then this routine prints a warning message and returns -1. 1691 1692 XXX: Macro this for a few different types. 1690 1693 *****************************************************************************/ 1691 int VectorBinDisect (float *bins,1692 int numBins,1693 float x)1694 int VectorBinDisectF32(float *bins, 1695 int numBins, 1696 float x) 1694 1697 { 1695 1698 int min; … … 1697 1700 int mid; 1698 1701 1699 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1700 "---- Calling VectorBinDisect (%f)\n", x);1702 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1703 "---- Calling VectorBinDisectF32(%f)\n", x); 1701 1704 1702 1705 if ((x < bins[0]) || 1703 1706 (x > bins[numBins-1])) { 1704 1707 psLogMsg(__func__, PS_LOG_WARN, 1705 "VectorBinDisect (): ordinate %f is outside vector range (%f - %f).",1708 "VectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).", 1706 1709 x, bins[0], bins[numBins-1]); 1707 1710 return(-1); … … 1713 1716 1714 1717 while (min != max) { 1715 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1718 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1716 1719 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1717 1720 min, mid, max, x, bins[mid]); 1718 1721 1719 1722 if (x == bins[mid]) { 1720 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect", 4, 1721 "---- Exiting VectorBinDisect(): bin %d\n", min); 1723 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1724 "---- Exiting VectorBinDisectF32(): bin %d\n", mid); 1725 return(mid); 1726 } else if (x < bins[mid]) { 1727 max = mid-1; 1728 } else { 1729 min = mid; 1730 } 1731 mid = ((max+1)+min)/2; 1732 } 1733 1734 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1735 "---- Exiting VectorBinDisectF32(): bin %d\n", min); 1736 return(min); 1737 } 1738 1739 /***************************************************************************** 1740 VectorBinDisectS32(): integer version of above. 1741 *****************************************************************************/ 1742 int VectorBinDisectS32(int *bins, 1743 int numBins, 1744 int x) 1745 { 1746 int min; 1747 int max; 1748 int mid; 1749 1750 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1751 "---- Calling VectorBinDisectS32(%f)\n", x); 1752 1753 if ((x < bins[0]) || 1754 (x > bins[numBins-1])) { 1755 psLogMsg(__func__, PS_LOG_WARN, 1756 "VectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).", 1757 x, bins[0], bins[numBins-1]); 1758 return(-1); 1759 } 1760 1761 min = 0; 1762 max = numBins-2; 1763 mid = ((max+1)-min)/2; 1764 1765 while (min != max) { 1766 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1767 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1768 min, mid, max, x, bins[mid]); 1769 1770 if (x == bins[mid]) { 1771 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1772 "---- Exiting VectorBinDisectS32(): bin %d\n", min); 1722 1773 return(min); 1723 1774 } else if (x < bins[mid]) { … … 1729 1780 } 1730 1781 1731 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1732 "---- Exiting VectorBinDisect (): bin %d\n", min);1782 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1783 "---- Exiting VectorBinDisectS32(): bin %d\n", min); 1733 1784 return(min); 1734 1785 } 1786 1787 /***************************************************************************** 1788 p_psVectorBinDisect(): A wrapper to the above VectorBinDisect(). 1789 *****************************************************************************/ 1790 int p_psVectorBinDisect(psVector *bins, 1791 psScalar *x) 1792 { 1793 if (x->type.type != bins->type.type) { 1794 // XXX: Generate error message. 1795 return(-1); 1796 } 1797 1798 if (x->type.type == PS_TYPE_S32) { 1799 return(VectorBinDisectS32(bins->data.S32, bins->n, x->data.S32)); 1800 } else if (x->type.type == PS_TYPE_F32) { 1801 return(VectorBinDisectF32(bins->data.F32, bins->n, x->data.F32)); 1802 } else { 1803 // XXX: Generate error message. 1804 } 1805 return(-1); 1806 } 1807 1808 /***************************************************************************** 1809 p_psInterpolate1D(): This routine will take as input n-element floating 1810 point arrays domain and range, and the x value, assumed to lie with the 1811 domain vector. It produces as output the n-order LaGrange interpolated 1812 value of x. 1813 1814 XXX: do we error check for non-distinct domain values? 1815 *****************************************************************************/ 1816 float p_psFullInterpolate1DF32(float *domain, 1817 float *range, 1818 int n, 1819 float x) 1820 { 1821 int i; 1822 int m; 1823 static psVector *p = NULL; 1824 psVectorRecycle(p, n, PS_TYPE_F32); 1825 p_psMemSetPersistent(p, true); 1826 1827 // From NR, during each iteration of the m loop, we are computing the 1828 // p_{i ... i+m} terms. 1829 for (m=0;m<n;m++) { 1830 for (i=0;i<n-m;i++) { 1831 if (m == 0) { 1832 p->data.F32[i] = range[i]; 1833 } else { 1834 // From NR: we are computing P_{i ... i+m} 1835 p->data.F32[i] = (((x-range[i+m]) * p->data.F32[i]) + 1836 ((range[i]-x) * p->data.F32[i+1])) / 1837 (domain[i] - domain[i+m]); 1838 } 1839 } 1840 } 1841 return(p->data.F32[0]); 1842 } 1843 1844 1845 // This is a 1846 float p_psInterpolate1DF32(float *domain, 1847 float *range, 1848 int n, 1849 int order, 1850 float x) 1851 { 1852 int binNum; 1853 int numIntPoints = order+1; 1854 int origin; 1855 1856 binNum = VectorBinDisectF32(domain, n, x); 1857 if (0 == numIntPoints%2) { 1858 origin = binNum - ((numIntPoints/2) - 1); 1859 } else { 1860 origin = binNum - (numIntPoints/2); 1861 if ((x-domain[binNum]) > (domain[binNum+1]-x)) { 1862 // x is closer to binNum+1. 1863 origin = 1 + (binNum - (numIntPoints/2)); 1864 } 1865 } 1866 if (origin < 0) { 1867 origin = 0; 1868 } 1869 if ((origin + numIntPoints) > n) { 1870 origin = n - numIntPoints; 1871 } 1872 1873 return(p_psFullInterpolate1DF32(&domain[origin], &range[origin], n, x)); 1874 } 1875 1876 /***************************************************************************** 1877 p_psInterpolate1D(): This routine will take as input psVectors domain and 1878 range, and the x value, assumed to lie with the domain vector. It produces 1879 as output the LaGrange interpolated value of a polynomial of the specified 1880 order around the point x. 1881 1882 XXX: This stuff does not work with a mask. 1883 *****************************************************************************/ 1884 float p_psInterpolate1D(psVector *domain, 1885 psVector *range, 1886 int order, 1887 psScalar *x) 1888 { 1889 if (domain->type.type != range->type.type != x->type.type) { 1890 // XXX psError 1891 } 1892 if (domain->n != range->n) { 1893 // XXX psError 1894 } 1895 if (order > (domain->n - 1)) { 1896 // XXX psError: not enough data points for order-order interpolation. 1897 } 1898 1899 if (x->type.type == PS_TYPE_F32) { 1900 return(p_psInterpolate1DF32(domain->data.F32, range->data.F32, 1901 domain->n, order, x->data.F32)); 1902 } else { 1903 // XXX psError: type not supported 1904 } 1905 1906 return(-1.0); 1907 } 1908 1735 1909 1736 1910 float psSpline1DEval(const psSpline1D *spline, … … 1741 1915 1742 1916 n = spline->n; 1743 binNum = VectorBinDisect (spline->domains, (spline->n)+1, x);1917 binNum = VectorBinDisectF32(spline->domains, (spline->n)+1, x); 1744 1918 if (binNum == -1) { 1745 1919 psLogMsg(__func__, PS_LOG_WARN, -
trunk/psLib/src/math/psPolynomial.h
r1775 r1823 12 12 * @author George Gusciora, MHPCC 13 13 * 14 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-09-1 0 02:52:02 $14 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-09-17 02:14:52 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 25 25 #include "psVector.h" 26 #include "psScalar.h" 26 27 27 28 /** \addtogroup Stats … … 405 406 psVector *data); 406 407 408 int p_psVectorBinDisect(psVector *bins, 409 psScalar *x); 407 410 408 411 /* \} */// End of MathGroup Functions 409 412 410 413 #endif 414 -
trunk/psLib/src/math/psSpline.c
r1784 r1823 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-09-1 0 23:20:29$9 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-09-17 02:14:52 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psMemory.h" 25 25 #include "psVector.h" 26 #include "psScalar.h" 26 27 #include "psTrace.h" 27 28 #include "psError.h" … … 1682 1683 1683 1684 /***************************************************************************** 1684 VectorBinDisect (): This is a private function which takes as input a vector1685 of floating point data as well as a single floating point values. The input 1686 vector values are assumed to be non-decreasing (v[i-1] <= v[j] for all j>=i). 1687 This routine does a binary disection of the vector and returns "i" such 1688 that (v[i] <= x <= v[i+1). If x lies outside the range of v[],1685 VectorBinDisectF32(): This is a private function which takes as input a 1686 vector of floating point data as well as a single floating point values. 1687 The input vector values are assumed to be non-decreasing (v[i-1] <= v[j] for 1688 all j>=i). This routine does a binary disection of the vector and returns 1689 "i" such that (v[i] <= x <= v[i+1). If x lies outside the range of v[], 1689 1690 then this routine prints a warning message and returns -1. 1691 1692 XXX: Macro this for a few different types. 1690 1693 *****************************************************************************/ 1691 int VectorBinDisect (float *bins,1692 int numBins,1693 float x)1694 int VectorBinDisectF32(float *bins, 1695 int numBins, 1696 float x) 1694 1697 { 1695 1698 int min; … … 1697 1700 int mid; 1698 1701 1699 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1700 "---- Calling VectorBinDisect (%f)\n", x);1702 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1703 "---- Calling VectorBinDisectF32(%f)\n", x); 1701 1704 1702 1705 if ((x < bins[0]) || 1703 1706 (x > bins[numBins-1])) { 1704 1707 psLogMsg(__func__, PS_LOG_WARN, 1705 "VectorBinDisect (): ordinate %f is outside vector range (%f - %f).",1708 "VectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).", 1706 1709 x, bins[0], bins[numBins-1]); 1707 1710 return(-1); … … 1713 1716 1714 1717 while (min != max) { 1715 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1718 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1716 1719 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1717 1720 min, mid, max, x, bins[mid]); 1718 1721 1719 1722 if (x == bins[mid]) { 1720 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect", 4, 1721 "---- Exiting VectorBinDisect(): bin %d\n", min); 1723 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1724 "---- Exiting VectorBinDisectF32(): bin %d\n", mid); 1725 return(mid); 1726 } else if (x < bins[mid]) { 1727 max = mid-1; 1728 } else { 1729 min = mid; 1730 } 1731 mid = ((max+1)+min)/2; 1732 } 1733 1734 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectF32", 4, 1735 "---- Exiting VectorBinDisectF32(): bin %d\n", min); 1736 return(min); 1737 } 1738 1739 /***************************************************************************** 1740 VectorBinDisectS32(): integer version of above. 1741 *****************************************************************************/ 1742 int VectorBinDisectS32(int *bins, 1743 int numBins, 1744 int x) 1745 { 1746 int min; 1747 int max; 1748 int mid; 1749 1750 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1751 "---- Calling VectorBinDisectS32(%f)\n", x); 1752 1753 if ((x < bins[0]) || 1754 (x > bins[numBins-1])) { 1755 psLogMsg(__func__, PS_LOG_WARN, 1756 "VectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).", 1757 x, bins[0], bins[numBins-1]); 1758 return(-1); 1759 } 1760 1761 min = 0; 1762 max = numBins-2; 1763 mid = ((max+1)-min)/2; 1764 1765 while (min != max) { 1766 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1767 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", 1768 min, mid, max, x, bins[mid]); 1769 1770 if (x == bins[mid]) { 1771 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1772 "---- Exiting VectorBinDisectS32(): bin %d\n", min); 1722 1773 return(min); 1723 1774 } else if (x < bins[mid]) { … … 1729 1780 } 1730 1781 1731 psTrace(".psLib.dataManip.psFunctions.VectorBinDisect ", 4,1732 "---- Exiting VectorBinDisect (): bin %d\n", min);1782 psTrace(".psLib.dataManip.psFunctions.VectorBinDisectS32", 4, 1783 "---- Exiting VectorBinDisectS32(): bin %d\n", min); 1733 1784 return(min); 1734 1785 } 1786 1787 /***************************************************************************** 1788 p_psVectorBinDisect(): A wrapper to the above VectorBinDisect(). 1789 *****************************************************************************/ 1790 int p_psVectorBinDisect(psVector *bins, 1791 psScalar *x) 1792 { 1793 if (x->type.type != bins->type.type) { 1794 // XXX: Generate error message. 1795 return(-1); 1796 } 1797 1798 if (x->type.type == PS_TYPE_S32) { 1799 return(VectorBinDisectS32(bins->data.S32, bins->n, x->data.S32)); 1800 } else if (x->type.type == PS_TYPE_F32) { 1801 return(VectorBinDisectF32(bins->data.F32, bins->n, x->data.F32)); 1802 } else { 1803 // XXX: Generate error message. 1804 } 1805 return(-1); 1806 } 1807 1808 /***************************************************************************** 1809 p_psInterpolate1D(): This routine will take as input n-element floating 1810 point arrays domain and range, and the x value, assumed to lie with the 1811 domain vector. It produces as output the n-order LaGrange interpolated 1812 value of x. 1813 1814 XXX: do we error check for non-distinct domain values? 1815 *****************************************************************************/ 1816 float p_psFullInterpolate1DF32(float *domain, 1817 float *range, 1818 int n, 1819 float x) 1820 { 1821 int i; 1822 int m; 1823 static psVector *p = NULL; 1824 psVectorRecycle(p, n, PS_TYPE_F32); 1825 p_psMemSetPersistent(p, true); 1826 1827 // From NR, during each iteration of the m loop, we are computing the 1828 // p_{i ... i+m} terms. 1829 for (m=0;m<n;m++) { 1830 for (i=0;i<n-m;i++) { 1831 if (m == 0) { 1832 p->data.F32[i] = range[i]; 1833 } else { 1834 // From NR: we are computing P_{i ... i+m} 1835 p->data.F32[i] = (((x-range[i+m]) * p->data.F32[i]) + 1836 ((range[i]-x) * p->data.F32[i+1])) / 1837 (domain[i] - domain[i+m]); 1838 } 1839 } 1840 } 1841 return(p->data.F32[0]); 1842 } 1843 1844 1845 // This is a 1846 float p_psInterpolate1DF32(float *domain, 1847 float *range, 1848 int n, 1849 int order, 1850 float x) 1851 { 1852 int binNum; 1853 int numIntPoints = order+1; 1854 int origin; 1855 1856 binNum = VectorBinDisectF32(domain, n, x); 1857 if (0 == numIntPoints%2) { 1858 origin = binNum - ((numIntPoints/2) - 1); 1859 } else { 1860 origin = binNum - (numIntPoints/2); 1861 if ((x-domain[binNum]) > (domain[binNum+1]-x)) { 1862 // x is closer to binNum+1. 1863 origin = 1 + (binNum - (numIntPoints/2)); 1864 } 1865 } 1866 if (origin < 0) { 1867 origin = 0; 1868 } 1869 if ((origin + numIntPoints) > n) { 1870 origin = n - numIntPoints; 1871 } 1872 1873 return(p_psFullInterpolate1DF32(&domain[origin], &range[origin], n, x)); 1874 } 1875 1876 /***************************************************************************** 1877 p_psInterpolate1D(): This routine will take as input psVectors domain and 1878 range, and the x value, assumed to lie with the domain vector. It produces 1879 as output the LaGrange interpolated value of a polynomial of the specified 1880 order around the point x. 1881 1882 XXX: This stuff does not work with a mask. 1883 *****************************************************************************/ 1884 float p_psInterpolate1D(psVector *domain, 1885 psVector *range, 1886 int order, 1887 psScalar *x) 1888 { 1889 if (domain->type.type != range->type.type != x->type.type) { 1890 // XXX psError 1891 } 1892 if (domain->n != range->n) { 1893 // XXX psError 1894 } 1895 if (order > (domain->n - 1)) { 1896 // XXX psError: not enough data points for order-order interpolation. 1897 } 1898 1899 if (x->type.type == PS_TYPE_F32) { 1900 return(p_psInterpolate1DF32(domain->data.F32, range->data.F32, 1901 domain->n, order, x->data.F32)); 1902 } else { 1903 // XXX psError: type not supported 1904 } 1905 1906 return(-1.0); 1907 } 1908 1735 1909 1736 1910 float psSpline1DEval(const psSpline1D *spline, … … 1741 1915 1742 1916 n = spline->n; 1743 binNum = VectorBinDisect (spline->domains, (spline->n)+1, x);1917 binNum = VectorBinDisectF32(spline->domains, (spline->n)+1, x); 1744 1918 if (binNum == -1) { 1745 1919 psLogMsg(__func__, PS_LOG_WARN, -
trunk/psLib/src/math/psSpline.h
r1775 r1823 12 12 * @author George Gusciora, MHPCC 13 13 * 14 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-09-1 0 02:52:02 $14 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-09-17 02:14:52 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 25 25 #include "psVector.h" 26 #include "psScalar.h" 26 27 27 28 /** \addtogroup Stats … … 405 406 psVector *data); 406 407 408 int p_psVectorBinDisect(psVector *bins, 409 psScalar *x); 407 410 408 411 /* \} */// End of MathGroup Functions 409 412 410 413 #endif 414 -
trunk/psLib/src/math/psStats.c
r1722 r1823 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-09- 08 06:04:30$11 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-09-17 02:14:52 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 1449 1449 void p_ps_FitTheGaussian() 1450 1450 { 1451 1452 1451 // Fit a Gaussian to the bins in the range MODE-dL to Mode+dL 1453 1452 // NOTE: This code uses the psMinimize.c functions to perform … … 1455 1454 // I am commenting this code out, and replacing it with code which 1456 1455 // calculates the mean directly on the robustHistogram. 1456 // 1457 // XXX: Replace this with the LaGrange interpolation stuff. 1457 1458 1458 1459 domain = psImageAlloc(1, robustHistogramVector->n, PS_TYPE_F32); … … 1671 1672 psHistogram* psVectorHistogram(psHistogram* out, 1672 1673 const psVector* restrict in, 1673 const psVector* restrict mask, unsigned int maskVal) 1674 const psVector* restrict mask, 1675 unsigned int maskVal) 1674 1676 { 1675 1677 int i = 0; // Loop index variable 1676 int j = 0; // Loop index variable1677 1678 float binSize = 0.0; // Histogram bin size 1678 1679 int binNum = 0; // A temporary bin number 1679 1680 int numBins = 0; // The total number of bins 1681 int tmp = 0; 1682 psScalar tmpScalar; 1683 tmpScalar.type.type = PS_TYPE_F32; 1680 1684 1681 1685 // NOTE: Verify that this is the correct action. … … 1708 1712 } 1709 1713 } 1714 1710 1715 // NOTE: determine the correct action for a variety of other cases: 1711 1716 // in vector has 0 elements, and histogram structure has zero bins. … … 1742 1747 // bin number requires a bit more work. 1743 1748 } else { 1744 // NOTE: This is slow. Put a smarter algorithm here to1745 // find the correct bin number (bin search, probably)1746 for (j = 0; j < (out->bounds->n) - 1; j++) {1747 if ((out->bounds->data.S32[j] <= in->data.F32[i]) &&1748 (in->data.F32[i] <= out->bounds->data.S32[j + 1])) {1749 (out->nums->data.S32[j])++;1750 }1749 tmpScalar.data.F32 = in->data.F32[i]; 1750 tmp = p_psVectorBinDisect(out->bounds, 1751 &tmpScalar); 1752 if (tmp == -1) { 1753 // XXX: Generate warning message 1754 } else { 1755 (out->nums->data.S32[tmp])++; 1751 1756 } 1752 1757 }
Note:
See TracChangeset
for help on using the changeset viewer.
