| eigensystem.hxx | | eigensystem.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 2004 by Ullrich Koethe */ | | /* Copyright 2004 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 515 | | skipping to change at line 515 | |
| | | | |
| int nn = rowCount(H); | | int nn = rowCount(H); | |
| int n = nn-1; | | int n = nn-1; | |
| int low = 0; | | int low = 0; | |
| int high = nn-1; | | int high = nn-1; | |
| T eps = VIGRA_CSTD::pow(2.0, sizeof(T) == sizeof(float) | | T eps = VIGRA_CSTD::pow(2.0, sizeof(T) == sizeof(float) | |
| ? -23.0 | | ? -23.0 | |
| : -52.0); | | : -52.0); | |
| T exshift = 0.0; | | T exshift = 0.0; | |
| T p=0,q=0,r=0,s=0,z=0,t,w,x,y; | | T p=0,q=0,r=0,s=0,z=0,t,w,x,y; | |
|
| T norm = vigra::linalg::norm(H); | | T norm = vigra::norm(H); | |
| | | | |
| // Outer loop over eigenvalue index | | // Outer loop over eigenvalue index | |
| int iter = 0; | | int iter = 0; | |
| while(n >= low) | | while(n >= low) | |
| { | | { | |
| | | | |
| // Look for single small sub-diagonal element | | // Look for single small sub-diagonal element | |
| int l = n; | | int l = n; | |
| while (l > low) | | while (l > low) | |
| { | | { | |
| | | | |
| skipping to change at line 1049 | | skipping to change at line 1049 | |
| if(!detail::hessenbergQrDecomposition(H, ev, de)) | | if(!detail::hessenbergQrDecomposition(H, ev, de)) | |
| return false; | | return false; | |
| | | | |
| for(unsigned int i=0; i < acols; ++i) | | for(unsigned int i=0; i < acols; ++i) | |
| { | | { | |
| ew(i,0) = std::complex<T>(de(i, 0), de(i, 1)); | | ew(i,0) = std::complex<T>(de(i, 0), de(i, 1)); | |
| } | | } | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | /** Compute the roots of a polynomial using the eigenvalue method. | |
| | | | |
| | | \a poly is a real polynomial (compatible to \ref vigra::PolynomialV | |
| | | iew), | |
| | | and \a roots a complex valued vector (compatible to <tt>std::vector | |
| | | </tt> | |
| | | with a <tt>value_type</tt> compatible to the type <tt>POLYNOMIAL::C | |
| | | omplex</tt>) to which | |
| | | the roots are appended. The function calls \ref nonsymmetricEigensy | |
| | | stem() with the standard | |
| | | companion matrix yielding the roots as eigenvalues. It returns <tt> | |
| | | false</tt> if | |
| | | it fails to converge. | |
| | | | |
| | | <b>\#include</b> "<a href="eigensystem_8hxx-source.html">vigra/eige | |
| | | nsystem.hxx</a>" or<br> | |
| | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/ | |
| | | linear_algebra.hxx</a>"<br> | |
| | | Namespaces: vigra and vigra::linalg | |
| | | | |
| | | \see polynomialRoots(), vigra::Polynomial | |
| | | */ | |
| | | template <class POLYNOMIAL, class VECTOR> | |
| | | bool polynomialRootsEigenvalueMethod(POLYNOMIAL const & poly, VECTOR & root | |
| | | s, bool polishRoots) | |
| | | { | |
| | | typedef typename POLYNOMIAL::value_type T; | |
| | | typedef typename POLYNOMIAL::Real Real; | |
| | | typedef typename POLYNOMIAL::Complex Complex; | |
| | | typedef Matrix<T> TMatrix; | |
| | | typedef Matrix<Complex> ComplexMatrix; | |
| | | | |
| | | int const degree = poly.order(); | |
| | | double const eps = poly.epsilon(); | |
| | | | |
| | | TMatrix inMatrix(degree, degree); | |
| | | for(int i = 0; i < degree; ++i) | |
| | | inMatrix(0, i) = -poly[degree - i - 1] / poly[degree]; | |
| | | for(int i = 0; i < degree - 1; ++i) | |
| | | inMatrix(i + 1, i) = NumericTraits<T>::one(); | |
| | | ComplexMatrix ew(degree, 1); | |
| | | TMatrix ev(degree, degree); | |
| | | bool success = nonsymmetricEigensystem(inMatrix, ew, ev); | |
| | | if(!success) | |
| | | return false; | |
| | | for(int i = 0; i < degree; ++i) | |
| | | { | |
| | | if(polishRoots) | |
| | | vigra::detail::laguerre1Root(poly, ew(i,0), 1); | |
| | | roots.push_back(vigra::detail::deleteBelowEpsilon(ew(i,0), eps)); | |
| | | } | |
| | | std::sort(roots.begin(), roots.end(), vigra::detail::PolynomialRootComp | |
| | | are<Real>(eps)); | |
| | | return true; | |
| | | } | |
| | | | |
| | | template <class POLYNOMIAL, class VECTOR> | |
| | | bool polynomialRootsEigenvalueMethod(POLYNOMIAL const & poly, VECTOR & root | |
| | | s) | |
| | | { | |
| | | return polynomialRootsEigenvalueMethod(poly, roots, true); | |
| | | } | |
| | | | |
| | | /** Compute the real roots of a real polynomial using the eigenvalue me | |
| | | thod. | |
| | | | |
| | | \a poly is a real polynomial (compatible to \ref vigra::PolynomialV | |
| | | iew), | |
| | | and \a roots a real valued vector (compatible to <tt>std::vector</t | |
| | | t> | |
| | | with a <tt>value_type</tt> compatible to the type <tt>POLYNOMIAL::R | |
| | | eal</tt>) to which | |
| | | the roots are appended. The function calls \ref polynomialRootsEige | |
| | | nvalueMethod() and | |
| | | throws away all complex roots. It returns <tt>false</tt> if it fail | |
| | | s to converge. | |
| | | | |
| | | <b>\#include</b> "<a href="eigensystem_8hxx-source.html">vigra/eige | |
| | | nsystem.hxx</a>" or<br> | |
| | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/ | |
| | | linear_algebra.hxx</a>"<br> | |
| | | Namespaces: vigra and vigra::linalg | |
| | | | |
| | | \see polynomialRealRoots(), vigra::Polynomial | |
| | | */ | |
| | | template <class POLYNOMIAL, class VECTOR> | |
| | | bool polynomialRealRootsEigenvalueMethod(POLYNOMIAL const & p, VECTOR & roo | |
| | | ts, bool polishRoots) | |
| | | { | |
| | | typedef typename NumericTraits<typename VECTOR::value_type>::ComplexPro | |
| | | mote Complex; | |
| | | ArrayVector<Complex> croots; | |
| | | if(!polynomialRootsEigenvalueMethod(p, croots)) | |
| | | return false; | |
| | | for(unsigned int i = 0; i < croots.size(); ++i) | |
| | | if(croots[i].imag() == 0.0) | |
| | | roots.push_back(croots[i].real()); | |
| | | return true; | |
| | | } | |
| | | | |
| | | template <class POLYNOMIAL, class VECTOR> | |
| | | bool polynomialRealRootsEigenvalueMethod(POLYNOMIAL const & p, VECTOR & roo | |
| | | ts) | |
| | | { | |
| | | return polynomialRealRootsEigenvalueMethod(p, roots, true); | |
| | | } | |
| | | | |
| //@} | | //@} | |
| | | | |
| } // namespace linalg | | } // namespace linalg | |
| | | | |
| using linalg::symmetricEigensystem; | | using linalg::symmetricEigensystem; | |
| using linalg::nonsymmetricEigensystem; | | using linalg::nonsymmetricEigensystem; | |
|
| | | using linalg::polynomialRootsEigenvalueMethod; | |
| | | using linalg::polynomialRealRootsEigenvalueMethod; | |
| | | | |
| } // namespace vigra | | } // namespace vigra | |
| | | | |
| #endif // VIGRA_EIGENSYSTEM_HXX | | #endif // VIGRA_EIGENSYSTEM_HXX | |
| | | | |
End of changes. 4 change blocks. |
| 2 lines changed or deleted | | 111 lines changed or added | |
|
| fftw.hxx | | fftw.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2002 by Ullrich Koethe */ | | /* Copyright 1998-2002 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 62 | | skipping to change at line 62 | |
| typedef fftw_real value_type; | | typedef fftw_real value_type; | |
| | | | |
| /** reference type (result of operator[]) | | /** reference type (result of operator[]) | |
| */ | | */ | |
| typedef fftw_real & reference; | | typedef fftw_real & reference; | |
| | | | |
| /** const reference type (result of operator[] const) | | /** const reference type (result of operator[] const) | |
| */ | | */ | |
| typedef fftw_real const & const_reference; | | typedef fftw_real const & const_reference; | |
| | | | |
|
| /** const reference type (result of operator[] const) | | /** iterator type (result of begin() ) | |
| */ | | */ | |
| typedef fftw_real * iterator; | | typedef fftw_real * iterator; | |
| | | | |
|
| /** const reference type (result of operator[] const) | | /** const iterator type (result of begin() const) | |
| */ | | */ | |
| typedef fftw_real const * const_iterator; | | typedef fftw_real const * const_iterator; | |
| | | | |
|
| | | /** The norm type (result of magnitde()) | |
| | | */ | |
| | | typedef fftw_real NormType; | |
| | | | |
| | | /** The squared norm type (result of squaredMagnitde()) | |
| | | */ | |
| | | typedef fftw_real SquaredNormType; | |
| | | | |
| /** Construct from real and imaginary part. | | /** Construct from real and imaginary part. | |
| Default: 0. | | Default: 0. | |
| */ | | */ | |
| FFTWComplex(value_type const & ire = 0.0, value_type const & iim = 0.0) | | FFTWComplex(value_type const & ire = 0.0, value_type const & iim = 0.0) | |
| { | | { | |
| re = ire; | | re = ire; | |
| im = iim; | | im = iim; | |
| } | | } | |
| | | | |
| /** Copy constructor. | | /** Copy constructor. | |
| | | | |
| skipping to change at line 144 | | skipping to change at line 152 | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| /** Unary negation. | | /** Unary negation. | |
| */ | | */ | |
| FFTWComplex operator-() const | | FFTWComplex operator-() const | |
| { return FFTWComplex(-re, -im); } | | { return FFTWComplex(-re, -im); } | |
| | | | |
| /** Squared magnitude x*conj(x) | | /** Squared magnitude x*conj(x) | |
| */ | | */ | |
|
| value_type squaredMagnitude() const | | SquaredNormType squaredMagnitude() const | |
| { return c_re(*this)*c_re(*this)+c_im(*this)*c_im(*this); } | | { return c_re(*this)*c_re(*this)+c_im(*this)*c_im(*this); } | |
| | | | |
| /** Magnitude (length of radius vector). | | /** Magnitude (length of radius vector). | |
| */ | | */ | |
|
| value_type magnitude() const | | NormType magnitude() const | |
| { return VIGRA_CSTD::sqrt(squaredMagnitude()); } | | { return VIGRA_CSTD::sqrt(squaredMagnitude()); } | |
| | | | |
| /** Phase angle. | | /** Phase angle. | |
| */ | | */ | |
| value_type phase() const | | value_type phase() const | |
| { return VIGRA_CSTD::atan2(c_im(*this),c_re(*this)); } | | { return VIGRA_CSTD::atan2(c_im(*this),c_re(*this)); } | |
| | | | |
| /** Access components as if number were a vector. | | /** Access components as if number were a vector. | |
| */ | | */ | |
| reference operator[](int i) | | reference operator[](int i) | |
| | | | |
| skipping to change at line 224 | | skipping to change at line 233 | |
| }; | | }; | |
| | | | |
| template<> | | template<> | |
| struct NumericTraits<FFTWComplex> | | struct NumericTraits<FFTWComplex> | |
| : public NumericTraits<fftw_complex> | | : public NumericTraits<fftw_complex> | |
| { | | { | |
| typedef FFTWComplex Type; | | typedef FFTWComplex Type; | |
| typedef FFTWComplex Promote; | | typedef FFTWComplex Promote; | |
| typedef FFTWComplex RealPromote; | | typedef FFTWComplex RealPromote; | |
| typedef FFTWComplex ComplexPromote; | | typedef FFTWComplex ComplexPromote; | |
|
| typedef fftw_real ValueType; | | typedef fftw_real ValueType; | |
| | | | |
| typedef VigraFalseType isIntegral; | | typedef VigraFalseType isIntegral; | |
| typedef VigraFalseType isScalar; | | typedef VigraFalseType isScalar; | |
| typedef VigraFalseType isOrdered; | | typedef VigraFalseType isOrdered; | |
| typedef VigraTrueType isComplex; | | typedef VigraTrueType isComplex; | |
| }; | | }; | |
| | | | |
|
| | | template<> | |
| | | struct NormTraits<fftw_complex> | |
| | | { | |
| | | typedef fftw_complex Type; | |
| | | typedef fftw_real SquaredNormType; | |
| | | typedef fftw_real NormType; | |
| | | }; | |
| | | | |
| | | template<> | |
| | | struct NormTraits<FFTWComplex> | |
| | | { | |
| | | typedef FFTWComplex Type; | |
| | | typedef fftw_real SquaredNormType; | |
| | | typedef fftw_real NormType; | |
| | | }; | |
| | | | |
| template <> | | template <> | |
| struct PromoteTraits<fftw_complex, fftw_complex> | | struct PromoteTraits<fftw_complex, fftw_complex> | |
| { | | { | |
| typedef fftw_complex Promote; | | typedef fftw_complex Promote; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct PromoteTraits<fftw_complex, double> | | struct PromoteTraits<fftw_complex, double> | |
| { | | { | |
| typedef fftw_complex Promote; | | typedef fftw_complex Promote; | |
| | | | |
| skipping to change at line 369 | | skipping to change at line 395 | |
| inline FFTWComplex::value_type abs(const FFTWComplex &a) | | inline FFTWComplex::value_type abs(const FFTWComplex &a) | |
| { | | { | |
| return a.magnitude(); | | return a.magnitude(); | |
| } | | } | |
| | | | |
| inline FFTWComplex conj(const FFTWComplex &a) | | inline FFTWComplex conj(const FFTWComplex &a) | |
| { | | { | |
| return FFTWComplex(a.re, -a.im); | | return FFTWComplex(a.re, -a.im); | |
| } | | } | |
| | | | |
|
| | | inline FFTWComplex::NormType norm(const FFTWComplex &a) | |
| | | { | |
| | | return a.magnitude(); | |
| | | } | |
| | | | |
| | | inline FFTWComplex::SquaredNormType squaredNorm(const FFTWComplex &a) | |
| | | { | |
| | | return a.squaredMagnitude(); | |
| | | } | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
| /* FFTWRealImage */ | | /* FFTWRealImage */ | |
| /* */ | | /* */ | |
| /********************************************************/ | | /********************************************************/ | |
| | | | |
| /* documentation: see fftw3.hxx | | /* documentation: see fftw3.hxx | |
| */ | | */ | |
| typedef BasicImage<fftw_real> FFTWRealImage; | | typedef BasicImage<fftw_real> FFTWRealImage; | |
| | | | |
| | | | |
| skipping to change at line 401 | | skipping to change at line 437 | |
| typedef iterator::iterator_category iterator_category; | | typedef iterator::iterator_category iterator_category; | |
| typedef iterator::value_type value_type; | | typedef iterator::value_type value_type; | |
| typedef iterator::reference reference; | | typedef iterator::reference reference; | |
| typedef iterator::index_reference index_reference; | | typedef iterator::index_reference index_reference; | |
| typedef iterator::pointer pointer; | | typedef iterator::pointer pointer; | |
| typedef iterator::difference_type difference_type; | | typedef iterator::difference_type difference_type; | |
| typedef iterator::row_iterator row_iterator; | | typedef iterator::row_iterator row_iterator; | |
| typedef iterator::column_iterator column_iterator; | | typedef iterator::column_iterator column_iterator; | |
| typedef VectorAccessor<FFTWComplex> default_accessor; | | typedef VectorAccessor<FFTWComplex> default_accessor; | |
| typedef VectorAccessor<FFTWComplex> DefaultAccessor; | | typedef VectorAccessor<FFTWComplex> DefaultAccessor; | |
|
| | | typedef VigraTrueType hasConstantStrides; | |
| }; | | }; | |
| | | | |
| template<> | | template<> | |
| struct IteratorTraits< | | struct IteratorTraits< | |
| ConstBasicImageIterator<FFTWComplex, FFTWComplex **> > | | ConstBasicImageIterator<FFTWComplex, FFTWComplex **> > | |
| { | | { | |
| typedef ConstBasicImageIterator<FFTWComplex, FFTWComplex **> Iterato
r; | | typedef ConstBasicImageIterator<FFTWComplex, FFTWComplex **> Iterato
r; | |
| typedef Iterator iterator; | | typedef Iterator iterator; | |
| typedef iterator::iterator_category iterator_category; | | typedef iterator::iterator_category iterator_category; | |
| typedef iterator::value_type value_type; | | typedef iterator::value_type value_type; | |
| typedef iterator::reference reference; | | typedef iterator::reference reference; | |
| typedef iterator::index_reference index_reference; | | typedef iterator::index_reference index_reference; | |
| typedef iterator::pointer pointer; | | typedef iterator::pointer pointer; | |
| typedef iterator::difference_type difference_type; | | typedef iterator::difference_type difference_type; | |
| typedef iterator::row_iterator row_iterator; | | typedef iterator::row_iterator row_iterator; | |
| typedef iterator::column_iterator column_iterator; | | typedef iterator::column_iterator column_iterator; | |
| typedef VectorAccessor<FFTWComplex> default_accessor; | | typedef VectorAccessor<FFTWComplex> default_accessor; | |
| typedef VectorAccessor<FFTWComplex> DefaultAccessor; | | typedef VectorAccessor<FFTWComplex> DefaultAccessor; | |
|
| | | typedef VigraTrueType hasConstantStrides; | |
| }; | | }; | |
| | | | |
| /* documentation: see fftw3.hxx | | /* documentation: see fftw3.hxx | |
| */ | | */ | |
| typedef BasicImage<FFTWComplex> FFTWComplexImage; | | typedef BasicImage<FFTWComplex> FFTWComplexImage; | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
| /* FFTWComplex-Accessors */ | | /* FFTWComplex-Accessors */ | |
| /* */ | | /* */ | |
| | | | |
End of changes. 11 change blocks. |
| 6 lines changed or deleted | | 43 lines changed or added | |
|
| fftw3.hxx | | fftw3.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2004 by Ullrich Koethe */ | | /* Copyright 1998-2004 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 89 | | skipping to change at line 89 | |
| typedef fftw_real value_type; | | typedef fftw_real value_type; | |
| | | | |
| /** reference type (result of operator[]) | | /** reference type (result of operator[]) | |
| */ | | */ | |
| typedef fftw_real & reference; | | typedef fftw_real & reference; | |
| | | | |
| /** const reference type (result of operator[] const) | | /** const reference type (result of operator[] const) | |
| */ | | */ | |
| typedef fftw_real const & const_reference; | | typedef fftw_real const & const_reference; | |
| | | | |
|
| /** const reference type (result of operator[] const) | | /** iterator type (result of begin() ) | |
| */ | | */ | |
| typedef fftw_real * iterator; | | typedef fftw_real * iterator; | |
| | | | |
|
| /** const reference type (result of operator[] const) | | /** const iterator type (result of begin() const) | |
| */ | | */ | |
| typedef fftw_real const * const_iterator; | | typedef fftw_real const * const_iterator; | |
| | | | |
|
| | | /** The norm type (result of magnitde()) | |
| | | */ | |
| | | typedef fftw_real NormType; | |
| | | | |
| | | /** The squared norm type (result of squaredMagnitde()) | |
| | | */ | |
| | | typedef fftw_real SquaredNormType; | |
| | | | |
| /** Construct from real and imaginary part. | | /** Construct from real and imaginary part. | |
| Default: 0. | | Default: 0. | |
| */ | | */ | |
| FFTWComplex(value_type const & re = 0.0, value_type const & im = 0.0) | | FFTWComplex(value_type const & re = 0.0, value_type const & im = 0.0) | |
| { | | { | |
| data_[0] = re; | | data_[0] = re; | |
| data_[1] = im; | | data_[1] = im; | |
| } | | } | |
| | | | |
| /** Copy constructor. | | /** Copy constructor. | |
| | | | |
| skipping to change at line 187 | | skipping to change at line 195 | |
| const_reference im() const | | const_reference im() const | |
| { return data_[1]; } | | { return data_[1]; } | |
| | | | |
| /** Unary negation. | | /** Unary negation. | |
| */ | | */ | |
| FFTWComplex operator-() const | | FFTWComplex operator-() const | |
| { return FFTWComplex(-data_[0], -data_[1]); } | | { return FFTWComplex(-data_[0], -data_[1]); } | |
| | | | |
| /** Squared magnitude x*conj(x) | | /** Squared magnitude x*conj(x) | |
| */ | | */ | |
|
| value_type squaredMagnitude() const | | SquaredNormType squaredMagnitude() const | |
| { return data_[0]*data_[0]+data_[1]*data_[1]; } | | { return data_[0]*data_[0]+data_[1]*data_[1]; } | |
| | | | |
| /** Magnitude (length of radius vector). | | /** Magnitude (length of radius vector). | |
| */ | | */ | |
|
| value_type magnitude() const | | NormType magnitude() const | |
| { return VIGRA_CSTD::sqrt(squaredMagnitude()); } | | { return VIGRA_CSTD::sqrt(squaredMagnitude()); } | |
| | | | |
| /** Phase angle. | | /** Phase angle. | |
| */ | | */ | |
| value_type phase() const | | value_type phase() const | |
| { return VIGRA_CSTD::atan2(data_[1], data_[0]); } | | { return VIGRA_CSTD::atan2(data_[1], data_[0]); } | |
| | | | |
| /** Access components as if number were a vector. | | /** Access components as if number were a vector. | |
| */ | | */ | |
| reference operator[](int i) | | reference operator[](int i) | |
| | | | |
| skipping to change at line 275 | | skipping to change at line 283 | |
| typedef fftw_real ValueType; | | typedef fftw_real ValueType; | |
| | | | |
| typedef VigraFalseType isIntegral; | | typedef VigraFalseType isIntegral; | |
| typedef VigraFalseType isScalar; | | typedef VigraFalseType isScalar; | |
| typedef VigraFalseType isOrdered; | | typedef VigraFalseType isOrdered; | |
| typedef VigraTrueType isComplex; | | typedef VigraTrueType isComplex; | |
| | | | |
| // etc. | | // etc. | |
| }; | | }; | |
| | | | |
|
| | | template<> | |
| | | struct NormTraits<fftw_complex> | |
| | | { | |
| | | typedef fftw_complex Type; | |
| | | typedef fftw_real SquaredNormType; | |
| | | typedef fftw_real NormType; | |
| | | }; | |
| | | | |
| | | template<> | |
| | | struct NormTraits<FFTWComplex> | |
| | | { | |
| | | typedef FFTWComplex Type; | |
| | | typedef fftw_real SquaredNormType; | |
| | | typedef fftw_real NormType; | |
| | | }; | |
| | | | |
| template <> | | template <> | |
| struct PromoteTraits<fftw_complex, fftw_complex> | | struct PromoteTraits<fftw_complex, fftw_complex> | |
| { | | { | |
| typedef fftw_complex Promote; | | typedef fftw_complex Promote; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct PromoteTraits<fftw_complex, double> | | struct PromoteTraits<fftw_complex, double> | |
| { | | { | |
| typedef fftw_complex Promote; | | typedef fftw_complex Promote; | |
| | | | |
| skipping to change at line 363 | | skipping to change at line 389 | |
| static FFTWComplex zero() { return FFTWComplex(0.0, 0.0); } | | static FFTWComplex zero() { return FFTWComplex(0.0, 0.0); } | |
| static FFTWComplex one() { return FFTWComplex(1.0, 0.0); } | | static FFTWComplex one() { return FFTWComplex(1.0, 0.0); } | |
| static FFTWComplex nonZero() { return one(); } | | static FFTWComplex nonZero() { return one(); } | |
| | | | |
| static const Promote & toPromote(const Type & v) { return v; } | | static const Promote & toPromote(const Type & v) { return v; } | |
| static const RealPromote & toRealPromote(const Type & v) { return v; } | | static const RealPromote & toRealPromote(const Type & v) { return v; } | |
| static const Type & fromPromote(const Promote & v) { return v; } | | static const Type & fromPromote(const Promote & v) { return v; } | |
| static const Type & fromRealPromote(const RealPromote & v) { return v;
} | | static const Type & fromRealPromote(const RealPromote & v) { return v;
} | |
| }; | | }; | |
| | | | |
|
| | | template<> | |
| | | struct NormTraits<fftw_complex> | |
| | | { | |
| | | typedef fftw_complex Type; | |
| | | typedef fftw_real SquaredNormType; | |
| | | typedef fftw_real NormType; | |
| | | }; | |
| | | | |
| | | template<> | |
| | | struct NormTraits<FFTWComplex> | |
| | | { | |
| | | typedef FFTWComplex Type; | |
| | | typedef fftw_real SquaredNormType; | |
| | | typedef fftw_real NormType; | |
| | | }; | |
| | | | |
| template <> | | template <> | |
| struct PromoteTraits<fftw_complex, fftw_complex> | | struct PromoteTraits<fftw_complex, fftw_complex> | |
| { | | { | |
| typedef fftw_complex Promote; | | typedef fftw_complex Promote; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
| struct PromoteTraits<fftw_complex, double> | | struct PromoteTraits<fftw_complex, double> | |
| { | | { | |
| typedef fftw_complex Promote; | | typedef fftw_complex Promote; | |
| | | | |
| skipping to change at line 529 | | skipping to change at line 571 | |
| { | | { | |
| return a.magnitude(); | | return a.magnitude(); | |
| } | | } | |
| | | | |
| /// complex conjugate | | /// complex conjugate | |
| inline FFTWComplex conj(const FFTWComplex &a) | | inline FFTWComplex conj(const FFTWComplex &a) | |
| { | | { | |
| return FFTWComplex(a.re(), -a.im()); | | return FFTWComplex(a.re(), -a.im()); | |
| } | | } | |
| | | | |
|
| | | /// norm (= magnitude) | |
| | | inline FFTWComplex::NormType norm(const FFTWComplex &a) | |
| | | { | |
| | | return a.magnitude(); | |
| | | } | |
| | | | |
| | | /// squared norm (= squared magnitude) | |
| | | inline FFTWComplex::SquaredNormType squaredNorm(const FFTWComplex &a) | |
| | | { | |
| | | return a.squaredMagnitude(); | |
| | | } | |
| | | | |
| //@} | | //@} | |
| | | | |
| /** \addtogroup StandardImageTypes | | /** \addtogroup StandardImageTypes | |
| */ | | */ | |
| //@{ | | //@{ | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
| /* FFTWRealImage */ | | /* FFTWRealImage */ | |
| /* */ | | /* */ | |
| | | | |
| skipping to change at line 576 | | skipping to change at line 630 | |
| typedef iterator::iterator_category iterator_category; | | typedef iterator::iterator_category iterator_category; | |
| typedef iterator::value_type value_type; | | typedef iterator::value_type value_type; | |
| typedef iterator::reference reference; | | typedef iterator::reference reference; | |
| typedef iterator::index_reference index_reference; | | typedef iterator::index_reference index_reference; | |
| typedef iterator::pointer pointer; | | typedef iterator::pointer pointer; | |
| typedef iterator::difference_type difference_type; | | typedef iterator::difference_type difference_type; | |
| typedef iterator::row_iterator row_iterator; | | typedef iterator::row_iterator row_iterator; | |
| typedef iterator::column_iterator column_iterator; | | typedef iterator::column_iterator column_iterator; | |
| typedef VectorAccessor<FFTWComplex> default_accessor; | | typedef VectorAccessor<FFTWComplex> default_accessor; | |
| typedef VectorAccessor<FFTWComplex> DefaultAccessor; | | typedef VectorAccessor<FFTWComplex> DefaultAccessor; | |
|
| | | typedef VigraTrueType hasConstantStrides; | |
| }; | | }; | |
| | | | |
| template<> | | template<> | |
| struct IteratorTraits< | | struct IteratorTraits< | |
| ConstBasicImageIterator<FFTWComplex, FFTWComplex **> > | | ConstBasicImageIterator<FFTWComplex, FFTWComplex **> > | |
| { | | { | |
| typedef ConstBasicImageIterator<FFTWComplex, FFTWComplex **> Iterato
r; | | typedef ConstBasicImageIterator<FFTWComplex, FFTWComplex **> Iterato
r; | |
| typedef Iterator iterator; | | typedef Iterator iterator; | |
| typedef iterator::iterator_category iterator_category; | | typedef iterator::iterator_category iterator_category; | |
| typedef iterator::value_type value_type; | | typedef iterator::value_type value_type; | |
| typedef iterator::reference reference; | | typedef iterator::reference reference; | |
| typedef iterator::index_reference index_reference; | | typedef iterator::index_reference index_reference; | |
| typedef iterator::pointer pointer; | | typedef iterator::pointer pointer; | |
| typedef iterator::difference_type difference_type; | | typedef iterator::difference_type difference_type; | |
| typedef iterator::row_iterator row_iterator; | | typedef iterator::row_iterator row_iterator; | |
| typedef iterator::column_iterator column_iterator; | | typedef iterator::column_iterator column_iterator; | |
| typedef VectorAccessor<FFTWComplex> default_accessor; | | typedef VectorAccessor<FFTWComplex> default_accessor; | |
| typedef VectorAccessor<FFTWComplex> DefaultAccessor; | | typedef VectorAccessor<FFTWComplex> DefaultAccessor; | |
|
| | | typedef VigraTrueType hasConstantStrides; | |
| }; | | }; | |
| | | | |
| /** Complex (FFTWComplex) image. | | /** Complex (FFTWComplex) image. | |
| It uses \ref vigra::BasicImageIterator and \ref vigra::StandardAcce
ssor and | | It uses \ref vigra::BasicImageIterator and \ref vigra::StandardAcce
ssor and | |
| their const counterparts to access the data. | | their const counterparts to access the data. | |
| | | | |
| <b>\#include</b> "<a href="fftw3_8hxx-source.html">vigra/fftw3.hxx<
/a>" (for FFTW 3) or<br> | | <b>\#include</b> "<a href="fftw3_8hxx-source.html">vigra/fftw3.hxx<
/a>" (for FFTW 3) or<br> | |
| <b>\#include</b> "<a href="fftw_8hxx-source.html">vigra/fftw.hxx</a
>" (for deprecated FFTW 2)<br> | | <b>\#include</b> "<a href="fftw_8hxx-source.html">vigra/fftw.hxx</a
>" (for deprecated FFTW 2)<br> | |
| Namespace: vigra | | Namespace: vigra | |
| */ | | */ | |
| | | | |
End of changes. 11 change blocks. |
| 5 lines changed or deleted | | 59 lines changed or added | |
|
| imageiterator.hxx | | imageiterator.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2002 by Ullrich Koethe */ | | /* Copyright 1998-2002 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 419 | | skipping to change at line 419 | |
| <td><tt>IteratorTraits<ImageIterator>::column_iterator</tt></td><
td>the associated column iterator</td> | | <td><tt>IteratorTraits<ImageIterator>::column_iterator</tt></td><
td>the associated column iterator</td> | |
| </tr> | | </tr> | |
| <tr> | | <tr> | |
| <td><tt>IteratorTraits<ImageIterator>::DefaultAccessor</tt></td> | | <td><tt>IteratorTraits<ImageIterator>::DefaultAccessor</tt></td> | |
| <td>the default accessor to be used with the iterator</td> | | <td>the default accessor to be used with the iterator</td> | |
| </tr> | | </tr> | |
| <tr> | | <tr> | |
| <td><tt>IteratorTraits<ImageIterator>::default_accessor</tt></td> | | <td><tt>IteratorTraits<ImageIterator>::default_accessor</tt></td> | |
| <td>the default accessor to be used with the iterator</td> | | <td>the default accessor to be used with the iterator</td> | |
| </tr> | | </tr> | |
|
| | | <tr> | |
| | | <td><tt>IteratorTraits<ImageIterator>::hasConstantStrides</tt></t | |
| | | d> | |
| | | <td>whether the iterator uses constant strides on the underlying memory | |
| | | (always <tt>VigraTrueType</tt> for <tt>ImageIterator</tt>s).</td> | |
| | | </tr> | |
| </table> | | </table> | |
| </p> | | </p> | |
| */ | | */ | |
| //@{ | | //@{ | |
| | | | |
| namespace detail { | | namespace detail { | |
| | | | |
| template <class StridedOrUnstrided> | | template <class StridedOrUnstrided> | |
| class DirectionSelector; | | class DirectionSelector; | |
| | | | |
| | | | |
| skipping to change at line 1150 | | skipping to change at line 1155 | |
| /********************************************************/ | | /********************************************************/ | |
| | | | |
| #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION | | #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION | |
| | | | |
| template <class T> | | template <class T> | |
| struct IteratorTraits<ImageIterator<T> > | | struct IteratorTraits<ImageIterator<T> > | |
| : public IteratorTraitsBase<ImageIterator<T> > | | : public IteratorTraitsBase<ImageIterator<T> > | |
| { | | { | |
| typedef typename AccessorTraits<T>::default_accessor DefaultAccessor; | | typedef typename AccessorTraits<T>::default_accessor DefaultAccessor; | |
| typedef DefaultAccessor default_accessor; | | typedef DefaultAccessor default_accessor; | |
|
| | | typedef VigraTrueType hasConstantStride
s; | |
| }; | | }; | |
| | | | |
| template <class T> | | template <class T> | |
| struct IteratorTraits<ConstImageIterator<T> > | | struct IteratorTraits<ConstImageIterator<T> > | |
| : public IteratorTraitsBase<ConstImageIterator<T> > | | : public IteratorTraitsBase<ConstImageIterator<T> > | |
| { | | { | |
| typedef typename AccessorTraits<T>::default_const_accessor DefaultAcce
ssor; | | typedef typename AccessorTraits<T>::default_const_accessor DefaultAcce
ssor; | |
| typedef DefaultAccessor default_accessor; | | typedef DefaultAccessor default_accessor; | |
|
| | | typedef VigraTrueType hasConstantStride
s; | |
| }; | | }; | |
| | | | |
| template <class T> | | template <class T> | |
| struct IteratorTraits<StridedImageIterator<T> > | | struct IteratorTraits<StridedImageIterator<T> > | |
| : public IteratorTraitsBase<StridedImageIterator<T> > | | : public IteratorTraitsBase<StridedImageIterator<T> > | |
| { | | { | |
| typedef typename AccessorTraits<T>::default_accessor DefaultAccessor; | | typedef typename AccessorTraits<T>::default_accessor DefaultAccessor; | |
| typedef DefaultAccessor default_accessor; | | typedef DefaultAccessor default_accessor; | |
|
| | | typedef VigraTrueType hasConstantStride
s; | |
| }; | | }; | |
| | | | |
| template <class T> | | template <class T> | |
| struct IteratorTraits<ConstStridedImageIterator<T> > | | struct IteratorTraits<ConstStridedImageIterator<T> > | |
| : public IteratorTraitsBase<ConstStridedImageIterator<T> > | | : public IteratorTraitsBase<ConstStridedImageIterator<T> > | |
| { | | { | |
| typedef typename AccessorTraits<T>::default_const_accessor DefaultAcce
ssor; | | typedef typename AccessorTraits<T>::default_const_accessor DefaultAcce
ssor; | |
| typedef DefaultAccessor default_accessor; | | typedef DefaultAccessor default_accessor; | |
|
| | | typedef VigraTrueType hasConstantStride
s; | |
| }; | | }; | |
| | | | |
| #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION | | #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION | |
| | | | |
| #define VIGRA_DEFINE_ITERATORTRAITS(VALUETYPE) \ | | #define VIGRA_DEFINE_ITERATORTRAITS(VALUETYPE) \ | |
| template <> \ | | template <> \ | |
| struct IteratorTraits<ImageIterator<VALUETYPE > > \ | | struct IteratorTraits<ImageIterator<VALUETYPE > > \ | |
| : public IteratorTraitsBase<ImageIterator<VALUETYPE > > \ | | : public IteratorTraitsBase<ImageIterator<VALUETYPE > > \ | |
| { \ | | { \ | |
| typedef typename AccessorTraits<VALUETYPE >::default_accessor Defa
ultAccessor; \ | | typedef typename AccessorTraits<VALUETYPE >::default_accessor Defa
ultAccessor; \ | |
| typedef DefaultAccessor default_acces
sor; \ | | typedef DefaultAccessor default_acces
sor; \ | |
|
| | | typedef VigraTrueType hasConstantSt
rides; \ | |
| }; \ | | }; \ | |
| \ | | \ | |
| template <> \ | | template <> \ | |
| struct IteratorTraits<ConstImageIterator<VALUETYPE > > \ | | struct IteratorTraits<ConstImageIterator<VALUETYPE > > \ | |
| : public IteratorTraitsBase<ConstImageIterator<VALUETYPE > > \ | | : public IteratorTraitsBase<ConstImageIterator<VALUETYPE > > \ | |
| { \ | | { \ | |
| typedef typename AccessorTraits<VALUETYPE >::default_const_accessor
DefaultAccessor; \ | | typedef typename AccessorTraits<VALUETYPE >::default_const_accessor
DefaultAccessor; \ | |
| typedef DefaultAccessor default_acces
sor; \ | | typedef DefaultAccessor default_acces
sor; \ | |
|
| | | typedef VigraTrueType hasConstantSt
rides; \ | |
| }; \ | | }; \ | |
| template <> \ | | template <> \ | |
| struct IteratorTraits<StridedImageIterator<VALUETYPE > > \ | | struct IteratorTraits<StridedImageIterator<VALUETYPE > > \ | |
| : public IteratorTraitsBase<StridedImageIterator<VALUETYPE > > \ | | : public IteratorTraitsBase<StridedImageIterator<VALUETYPE > > \ | |
| { \ | | { \ | |
| typedef typename AccessorTraits<VALUETYPE >::default_accessor Defa
ultAccessor; \ | | typedef typename AccessorTraits<VALUETYPE >::default_accessor Defa
ultAccessor; \ | |
| typedef DefaultAccessor default_acces
sor; \ | | typedef DefaultAccessor default_acces
sor; \ | |
|
| | | typedef VigraTrueType hasConstantSt
rides; \ | |
| }; \ | | }; \ | |
| \ | | \ | |
| template <> \ | | template <> \ | |
| struct IteratorTraits<ConstStridedImageIterator<VALUETYPE > > \ | | struct IteratorTraits<ConstStridedImageIterator<VALUETYPE > > \ | |
| : public IteratorTraitsBase<ConstStridedImageIterator<VALUETYPE > > \ | | : public IteratorTraitsBase<ConstStridedImageIterator<VALUETYPE > > \ | |
| { \ | | { \ | |
| typedef typename AccessorTraits<VALUETYPE >::default_const_accessor
DefaultAccessor; \ | | typedef typename AccessorTraits<VALUETYPE >::default_const_accessor
DefaultAccessor; \ | |
| typedef DefaultAccessor default_acces
sor; \ | | typedef DefaultAccessor default_acces
sor; \ | |
|
| | | typedef VigraTrueType hasConstantSt
rides; \ | |
| }; | | }; | |
| | | | |
| VIGRA_DEFINE_ITERATORTRAITS(RGBValue<unsigned char>) | | VIGRA_DEFINE_ITERATORTRAITS(RGBValue<unsigned char>) | |
| VIGRA_DEFINE_ITERATORTRAITS(RGBValue<short>) | | VIGRA_DEFINE_ITERATORTRAITS(RGBValue<short>) | |
| VIGRA_DEFINE_ITERATORTRAITS(RGBValue<int>) | | VIGRA_DEFINE_ITERATORTRAITS(RGBValue<int>) | |
| VIGRA_DEFINE_ITERATORTRAITS(RGBValue<float>) | | VIGRA_DEFINE_ITERATORTRAITS(RGBValue<float>) | |
| VIGRA_DEFINE_ITERATORTRAITS(RGBValue<double>) | | VIGRA_DEFINE_ITERATORTRAITS(RGBValue<double>) | |
| | | | |
| #define VIGRA_PIXELTYPE TinyVector<unsigned char, 2> | | #define VIGRA_PIXELTYPE TinyVector<unsigned char, 2> | |
| VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE) | | VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE) | |
| | | | |
| skipping to change at line 1539 | | skipping to change at line 1552 | |
| typedef typename iterator::iterator_category iterator_category; | | typedef typename iterator::iterator_category iterator_category; | |
| typedef typename iterator::value_type value_type; | | typedef typename iterator::value_type value_type; | |
| typedef typename iterator::reference reference; | | typedef typename iterator::reference reference; | |
| typedef typename iterator::index_reference index_reference; | | typedef typename iterator::index_reference index_reference; | |
| typedef typename iterator::pointer pointer; | | typedef typename iterator::pointer pointer; | |
| typedef typename iterator::difference_type difference_type; | | typedef typename iterator::difference_type difference_type; | |
| typedef typename iterator::row_iterator row_iterator; | | typedef typename iterator::row_iterator row_iterator; | |
| typedef typename iterator::column_iterator column_iterator; | | typedef typename iterator::column_iterator column_iterator; | |
| typedef StandardConstAccessor<T> DefaultAccessor; | | typedef StandardConstAccessor<T> DefaultAccessor; | |
| typedef StandardConstAccessor<T> default_accessor; | | typedef StandardConstAccessor<T> default_accessor; | |
|
| | | typedef VigraTrueType hasConstantStride
s; | |
| }; | | }; | |
| | | | |
| #endif | | #endif | |
| | | | |
| typedef Diff2D CoordinateIterator; | | typedef Diff2D CoordinateIterator; | |
| | | | |
| /** \class CoordinateIterator | | /** \class CoordinateIterator | |
| | | | |
| This used to be a separate class, | | This used to be a separate class, | |
| but has now become an alias for \ref vigra::Diff2D. This is possible be
cause | | but has now become an alias for \ref vigra::Diff2D. This is possible be
cause | |
| | | | |
End of changes. 11 change blocks. |
| 1 lines changed or deleted | | 16 lines changed or added | |
|
| iteratortraits.hxx | | iteratortraits.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2002 by Ullrich Koethe */ | | /* Copyright 1998-2002 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 54 | | skipping to change at line 54 | |
| typedef typename iterator::iterator_category iterator_category; | | typedef typename iterator::iterator_category iterator_category; | |
| typedef typename iterator::value_type value_type; | | typedef typename iterator::value_type value_type; | |
| typedef typename iterator::reference reference; | | typedef typename iterator::reference reference; | |
| typedef typename iterator::index_reference index_reference; | | typedef typename iterator::index_reference index_reference; | |
| typedef typename iterator::pointer pointer; | | typedef typename iterator::pointer pointer; | |
| typedef typename iterator::difference_type difference_type; | | typedef typename iterator::difference_type difference_type; | |
| typedef typename iterator::row_iterator row_iterator; | | typedef typename iterator::row_iterator row_iterator; | |
| typedef typename iterator::column_iterator column_iterator; | | typedef typename iterator::column_iterator column_iterator; | |
| typedef StandardAccessor<value_type> DefaultAccessor; | | typedef StandardAccessor<value_type> DefaultAccessor; | |
| typedef StandardAccessor<value_type> default_accessor; | | typedef StandardAccessor<value_type> default_accessor; | |
|
| | | | |
| | | typedef VigraTrueType/VigraFalseType hasConstantStrides; | |
| }; | | }; | |
| \endcode | | \endcode | |
| | | | |
| By (partially) specializing this template for an iterator class | | By (partially) specializing this template for an iterator class | |
| the defaults given above can be changed as appropriate. For example, it
erators | | the defaults given above can be changed as appropriate. For example, it
erators | |
| for rgb images are associated with <TT>RGBAccessor<value_type></TT> | | for rgb images are associated with <TT>RGBAccessor<value_type></TT> | |
| instead of <TT>StandardAccessor<value_type></TT>. To get the accessor | | instead of <TT>StandardAccessor<value_type></TT>. To get the accessor | |
| associated with a given iterator, use code like this: | | associated with a given iterator, use code like this: | |
| | | | |
| \code | | \code | |
| | | | |
| skipping to change at line 78 | | skipping to change at line 80 | |
| Accessor a; | | Accessor a; | |
| ... | | ... | |
| } | | } | |
| \endcode | | \endcode | |
| | | | |
| This technique is, for example, used by the | | This technique is, for example, used by the | |
| \ref IteratorBasedArgumentObjectFactories. The possibility to retrieve
the default accessor by means of a traits | | \ref IteratorBasedArgumentObjectFactories. The possibility to retrieve
the default accessor by means of a traits | |
| class is especially important since this information is not | | class is especially important since this information is not | |
| contained in the iterator directly. | | contained in the iterator directly. | |
| | | | |
|
| | | The member <tt>hasConstantStrides</tt> is useful for certain | |
| | | optimizations: it helps to decide whether we can replace iterator | |
| | | operations such as <tt>iter++</tt> ot <tt>iter =+ n</tt> with | |
| | | corresponding pointer operations (which may be faster), where | |
| | | the pointer is obtained as the address of iterator's pointee | |
| | | (the object the iterator currently refers to). | |
| | | This flag would be tt>VigraFalseType</tt> for a | |
| | | <tt>std::list<int>::iterator</tt>, but is <tt>VigraTrueType</tt> | |
| | | for most VIGRA iterators. | |
| | | | |
| <b>\#include</b> "<a href="iteratortraits_8hxx-source.html">vigra/itera
tortraits.hxx</a>" | | <b>\#include</b> "<a href="iteratortraits_8hxx-source.html">vigra/itera
tortraits.hxx</a>" | |
| Namespace: vigra | | Namespace: vigra | |
| */ | | */ | |
| template <class T> | | template <class T> | |
| struct IteratorTraits | | struct IteratorTraits | |
| { | | { | |
| typedef T Iterator; | | typedef T Iterator; | |
| typedef Iterator iterator; | | typedef Iterator iterator; | |
| typedef typename iterator::iterator_category iterator_category; | | typedef typename iterator::iterator_category iterator_category; | |
| typedef typename iterator::value_type value_type; | | typedef typename iterator::value_type value_type; | |
| typedef typename iterator::reference reference; | | typedef typename iterator::reference reference; | |
| typedef typename iterator::index_reference index_reference; | | typedef typename iterator::index_reference index_reference; | |
| typedef typename iterator::pointer pointer; | | typedef typename iterator::pointer pointer; | |
| typedef typename iterator::difference_type difference_type; | | typedef typename iterator::difference_type difference_type; | |
| typedef typename iterator::row_iterator row_iterator; | | typedef typename iterator::row_iterator row_iterator; | |
| typedef typename iterator::column_iterator column_iterator; | | typedef typename iterator::column_iterator column_iterator; | |
| typedef typename | | typedef typename | |
| AccessorTraits<value_type>::default_accessor DefaultAccessor; | | AccessorTraits<value_type>::default_accessor DefaultAccessor; | |
| typedef DefaultAccessor default_accessor; | | typedef DefaultAccessor default_accessor; | |
|
| | | | |
| | | // default: disable the constant strides optimization | |
| | | typedef VigraFalseType hasConstantStrides; | |
| }; | | }; | |
| | | | |
| template <class T> | | template <class T> | |
| struct IteratorTraitsBase | | struct IteratorTraitsBase | |
| { | | { | |
| typedef T Iterator; | | typedef T Iterator; | |
| typedef Iterator iterator; | | typedef Iterator iterator; | |
| typedef typename iterator::iterator_category iterator_category; | | typedef typename iterator::iterator_category iterator_category; | |
| typedef typename iterator::value_type value_type; | | typedef typename iterator::value_type value_type; | |
| typedef typename iterator::reference reference; | | typedef typename iterator::reference reference; | |
| | | | |
End of changes. 4 change blocks. |
| 1 lines changed or deleted | | 16 lines changed or added | |
|
| mathutil.hxx | | mathutil.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
|
| /* Copyright 1998-2002 by Ullrich Koethe */ | | /* Copyright 1998-2005 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 67 | | skipping to change at line 67 | |
| | | | |
| namespace vigra { | | namespace vigra { | |
| | | | |
| #ifndef __sun | | #ifndef __sun | |
| | | | |
| /** \addtogroup MathFunctions Mathematical Functions | | /** \addtogroup MathFunctions Mathematical Functions | |
| | | | |
| Useful mathematical functions and functors. | | Useful mathematical functions and functors. | |
| */ | | */ | |
| //@{ | | //@{ | |
|
| /*! The error function. | | /*! The error function. | |
| | | | |
|
| With the exception of Solaris (where <tt>erf()</tt> is provided as an e | | If <tt>erf()</tt> is not provided in the C standard math library (a | |
| xtension of the | | s it should according to the | |
| C math library), VIGRA implements <tt>erf()</tt> as an approximation of | | new C99 standard ?), VIGRA implements <tt>erf()</tt> as an approxim | |
| the error | | ation of the error | |
| function | | function | |
| | | | |
|
| \f[ | | \f[ | |
| \mbox{erf}(x) = \int_0^x e^{-x^2} dx | | \mbox{erf}(x) = \int_0^x e^{-x^2} dx | |
| \f] | | \f] | |
| | | | |
|
| according to the formula given in Press et al. "Numerical Recipes". | | according to the formula given in Press et al. "Numerical Recipes". | |
| | | | |
|
| <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathutil.hx | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| x</a>"<br> | | l.hxx</a>"<br> | |
| Namespace: vigra | | Namespace: vigra | |
| */ | | */ | |
| template <class T> | | template <class T> | |
| double erf(T x) | | double erf(T x) | |
| { | | { | |
| double t = 1.0/(1.0+0.5*VIGRA_CSTD::fabs(x)); | | double t = 1.0/(1.0+0.5*VIGRA_CSTD::fabs(x)); | |
| double ans = t*VIGRA_CSTD::exp(-x*x-1.26551223+t*(1.00002368+t*(0.37409
196+ | | double ans = t*VIGRA_CSTD::exp(-x*x-1.26551223+t*(1.00002368+t*(0.37409
196+ | |
| t*(0.09678418+t*(-0.18628806+t*(0.27886
807+ | | t*(0.09678418+t*(-0.18628806+t*(0.27886
807+ | |
| t*(-1.13520398+t*(1.48851587+t*(-0.8221
5223+ | | t*(-1.13520398+t*(1.48851587+t*(-0.8221
5223+ | |
| t*0.17087277))))))))); | | t*0.17087277))))))))); | |
| if (x >= 0.0) | | if (x >= 0.0) | |
| return 1.0 - ans; | | return 1.0 - ans; | |
| | | | |
| skipping to change at line 103 | | skipping to change at line 103 | |
| return ans - 1.0; | | return ans - 1.0; | |
| } | | } | |
| | | | |
| #else | | #else | |
| | | | |
| using VIGRA_CSTD::erf; | | using VIGRA_CSTD::erf; | |
| | | | |
| #endif | | #endif | |
| | | | |
| // import functions into namespace vigra which VIGRA is going to overload | | // import functions into namespace vigra which VIGRA is going to overload | |
|
| using std::abs; | | | |
| using VIGRA_CSTD::pow; | | using VIGRA_CSTD::pow; | |
| using VIGRA_CSTD::floor; | | using VIGRA_CSTD::floor; | |
| using VIGRA_CSTD::ceil; | | using VIGRA_CSTD::ceil; | |
|
| | | using std::abs; | |
| | | | |
|
| /*! The square function. | | #define VIGRA_DEFINE_UNSIGNED_ABS(T) \ | |
| | | inline T abs(T t) { return t; } | |
| | | | |
|
| sq(x) is needed so often that it makes sense to define it as a function | | VIGRA_DEFINE_UNSIGNED_ABS(bool) | |
| . | | VIGRA_DEFINE_UNSIGNED_ABS(unsigned char) | |
| | | VIGRA_DEFINE_UNSIGNED_ABS(unsigned short) | |
| | | VIGRA_DEFINE_UNSIGNED_ABS(unsigned int) | |
| | | VIGRA_DEFINE_UNSIGNED_ABS(unsigned long) | |
| | | | |
|
| <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathutil.hx | | #undef VIGRA_DEFINE_UNSIGNED_ABS | |
| x</a>"<br> | | | |
| Namespace: vigra | | /*! The rounding function. | |
| */ | | | |
| | | Defined for all floating point types. Rounds towards the nearest in | |
| | | teger for both | |
| | | positive and negative inputs. | |
| | | | |
| | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| | | l.hxx</a>"<br> | |
| | | Namespace: vigra | |
| | | */ | |
| | | inline float round(float t) | |
| | | { | |
| | | return t >= 0.0 | |
| | | ? floor(t + 0.5) | |
| | | : ceil(t - 0.5); | |
| | | } | |
| | | | |
| | | inline double round(double t) | |
| | | { | |
| | | return t >= 0.0 | |
| | | ? floor(t + 0.5) | |
| | | : ceil(t - 0.5); | |
| | | } | |
| | | | |
| | | inline long double round(long double t) | |
| | | { | |
| | | return t >= 0.0 | |
| | | ? floor(t + 0.5) | |
| | | : ceil(t - 0.5); | |
| | | } | |
| | | | |
| | | /*! The square function. | |
| | | | |
| | | sq(x) is needed so often that it makes sense to define it as a func | |
| | | tion. | |
| | | | |
| | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| | | l.hxx</a>"<br> | |
| | | Namespace: vigra | |
| | | */ | |
| template <class T> | | template <class T> | |
| inline | | inline | |
| typename NumericTraits<T>::Promote sq(T t) | | typename NumericTraits<T>::Promote sq(T t) | |
| { | | { | |
| return t*t; | | return t*t; | |
| } | | } | |
| | | | |
| #ifdef VIGRA_NO_HYPOT | | #ifdef VIGRA_NO_HYPOT | |
|
| /*! Compute the Euclidean distance. | | /*! Compute the Euclidean distance (length of the hypothenuse of a righ
t-angled triangle). | |
| | | | |
|
| The hypot() function returns the sqrt(a*a + b*b). | | The hypot() function returns the sqrt(a*a + b*b). | |
| It is implemented in a way that minimizes round-off error. | | It is implemented in a way that minimizes round-off error. | |
| | | | |
|
| <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathutil.hx | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| x</a>"<br> | | l.hxx</a>"<br> | |
| Namespace: vigra | | Namespace: vigra | |
| */ | | */ | |
| template <class T> | | template <class T> | |
| T hypot(T a, T b) | | T hypot(T a, T b) | |
| { | | { | |
| T absa = abs(a), absb = abs(b); | | T absa = abs(a), absb = abs(b); | |
| if (absa > absb) | | if (absa > absb) | |
| return absa * VIGRA_CSTD::sqrt(1.0 + sq(absb/absa)); | | return absa * VIGRA_CSTD::sqrt(1.0 + sq(absb/absa)); | |
| else | | else | |
| return absb == NumericTraits<T>::zero() | | return absb == NumericTraits<T>::zero() | |
| ? NumericTraits<T>::zero() | | ? NumericTraits<T>::zero() | |
| : absb * VIGRA_CSTD::sqrt(1.0 + sq(absa/absb)); | | : absb * VIGRA_CSTD::sqrt(1.0 + sq(absa/absb)); | |
| } | | } | |
| | | | |
| #else | | #else | |
| | | | |
| using ::hypot; | | using ::hypot; | |
| | | | |
| #endif | | #endif | |
| | | | |
|
| /*! The sign function. | | /*! The sign function. | |
| | | | |
|
| Returns 1, 0, or -1 depending on the signm of \a t. | | Returns 1, 0, or -1 depending on the sign of \a t. | |
| | | | |
|
| <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathutil.hx | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| x</a>"<br> | | l.hxx</a>"<br> | |
| Namespace: vigra | | Namespace: vigra | |
| */ | | */ | |
| template <class T> | | template <class T> | |
| T sign(T t) | | T sign(T t) | |
| { | | { | |
| return t > NumericTraits<T>::zero() | | return t > NumericTraits<T>::zero() | |
| ? NumericTraits<T>::one() | | ? NumericTraits<T>::one() | |
| : t < NumericTraits<T>::zero() | | : t < NumericTraits<T>::zero() | |
| ? -NumericTraits<T>::one() | | ? -NumericTraits<T>::one() | |
| : NumericTraits<T>::zero(); | | : NumericTraits<T>::zero(); | |
| } | | } | |
| | | | |
|
| /*! The binary sign function. | | /*! The binary sign function. | |
| | | | |
|
| Transfers the sign of \a t2 to \a t1. | | Transfers the sign of \a t2 to \a t1. | |
| | | | |
|
| <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathutil.hx | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| x</a>"<br> | | l.hxx</a>"<br> | |
| Namespace: vigra | | Namespace: vigra | |
| */ | | */ | |
| template <class T1, class T2> | | template <class T1, class T2> | |
| T1 sign(T1 t1, T2 t2) | | T1 sign(T1 t1, T2 t2) | |
| { | | { | |
| return t2 >= NumericTraits<T2>::zero() | | return t2 >= NumericTraits<T2>::zero() | |
| ? abs(t1) | | ? abs(t1) | |
| : -abs(t1); | | : -abs(t1); | |
| } | | } | |
| | | | |
|
| | | #define VIGRA_DEFINE_NORM(T) \ | |
| | | inline NormTraits<T>::SquaredNormType squaredNorm(T t) { return sq(t); | |
| | | } \ | |
| | | inline NormTraits<T>::NormType norm(T t) { return abs(t); } | |
| | | | |
| | | VIGRA_DEFINE_NORM(bool) | |
| | | VIGRA_DEFINE_NORM(signed char) | |
| | | VIGRA_DEFINE_NORM(unsigned char) | |
| | | VIGRA_DEFINE_NORM(short) | |
| | | VIGRA_DEFINE_NORM(unsigned short) | |
| | | VIGRA_DEFINE_NORM(int) | |
| | | VIGRA_DEFINE_NORM(unsigned int) | |
| | | VIGRA_DEFINE_NORM(long) | |
| | | VIGRA_DEFINE_NORM(unsigned long) | |
| | | VIGRA_DEFINE_NORM(float) | |
| | | VIGRA_DEFINE_NORM(double) | |
| | | VIGRA_DEFINE_NORM(long double) | |
| | | | |
| | | #undef VIGRA_DEFINE_NORM | |
| | | | |
| | | template <class T> | |
| | | inline typename NormTraits<std::complex<T> >::SquaredNormType | |
| | | squaredNorm(std::complex<T> const & t) | |
| | | { | |
| | | return sq(t.real()) + sq(t.imag()); | |
| | | } | |
| | | | |
| | | #ifdef DOXYGEN // only for documentation | |
| | | /*! The squared norm of a numerical object. | |
| | | | |
| | | For scalar types: equals <tt>vigra::sq(t)</tt><br>. | |
| | | For vectorial types: equals <tt>vigra::dot(t, t)</tt><br>. | |
| | | For complex types: equals <tt>vigra::sq(t.real()) + vigra::sq(t.ima | |
| | | g())</tt><br>. | |
| | | For matrix types: results in the squared Frobenius norm (sum of squ | |
| | | ares of the matrix elements). | |
| | | */ | |
| | | NormTraits<T>::SquaredNormType squaredNorm(T const & t); | |
| | | | |
| | | #endif | |
| | | | |
| | | /*! The norm of a numerical object. | |
| | | | |
| | | For scalar types: implemented as <tt>abs(t)</tt><br> | |
| | | otherwise: implemented as <tt>sqrt(squaredNorm(t))</tt>. | |
| | | | |
| | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| | | l.hxx</a>"<br> | |
| | | Namespace: vigra | |
| | | */ | |
| | | template <class T> | |
| | | inline typename NormTraits<T>::NormType | |
| | | norm(T const & t) | |
| | | { | |
| | | return VIGRA_CSTD::sqrt(static_cast<typename NormTraits<T>::NormType>(s | |
| | | quaredNorm(t))); | |
| | | } | |
| | | | |
| | | namespace detail { | |
| | | | |
| | | // both f1 and f2 are unsigned here | |
| | | template<class FPT> | |
| | | inline | |
| | | FPT safeFloatDivision( FPT f1, FPT f2 ) | |
| | | { | |
| | | return f2 < NumericTraits<FPT>::one() && f1 > f2 * NumericTraits<FPT>: | |
| | | :max() | |
| | | ? NumericTraits<FPT>::max() | |
| | | : (f2 > NumericTraits<FPT>::one() && f1 < f2 * NumericTrait | |
| | | s<FPT>::smallestPositive()) || | |
| | | f1 == NumericTraits<FPT>::zero() | |
| | | ? NumericTraits<FPT>::zero() | |
| | | : f1/f2; | |
| | | } | |
| | | | |
| | | } // namespace detail | |
| | | | |
| | | /*! Tolerance based floating-point comparison. | |
| | | | |
| | | Check whether two floating point numbers are equal within the given | |
| | | tolerance. | |
| | | This is useful because floating point numbers that should be equal | |
| | | in theory are | |
| | | rarely exactly equal in practice. If the tolerance \a epsilon is no | |
| | | t given, | |
| | | twice the machine epsilon is used. | |
| | | | |
| | | <b>\#include</b> "<a href="mathutil_8hxx-source.html">vigra/mathuti | |
| | | l.hxx</a>"<br> | |
| | | Namespace: vigra | |
| | | */ | |
| | | template <class T1, class T2> | |
| | | bool closeAtTolerance(T1 l, T2 r, typename PromoteTraits<T1, T2>::Promote e | |
| | | psilon) | |
| | | { | |
| | | typedef typename PromoteTraits<T1, T2>::Promote T; | |
| | | if(l == 0.0 && r != 0.0) | |
| | | return VIGRA_CSTD::fabs(r) <= epsilon; | |
| | | if(l != 0.0 && r == 0.0) | |
| | | return VIGRA_CSTD::fabs(r) <= epsilon; | |
| | | T diff = VIGRA_CSTD::fabs( l - r ); | |
| | | T d1 = detail::safeFloatDivision<T>( diff, VIGRA_CSTD::fabs( r ) ); | |
| | | T d2 = detail::safeFloatDivision<T>( diff, VIGRA_CSTD::fabs( l ) ); | |
| | | | |
| | | return (d1 <= epsilon && d2 <= epsilon); | |
| | | } | |
| | | | |
| | | template <class T1, class T2> | |
| | | bool closeAtTolerance(T1 l, T2 r) | |
| | | { | |
| | | typedef typename PromoteTraits<T1, T2>::Promote T; | |
| | | return closeAtTolerance(l, r, 2.0 * NumericTraits<T>::epsilon()); | |
| | | } | |
| | | | |
| //@} | | //@} | |
| | | | |
| } // namespace vigra | | } // namespace vigra | |
| | | | |
| #endif /* VIGRA_MATHUTIL_HXX */ | | #endif /* VIGRA_MATHUTIL_HXX */ | |
| | | | |
End of changes. 22 change blocks. |
| 43 lines changed or deleted | | 200 lines changed or added | |
|
| matrix.hxx | | matrix.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 2004 by Gunnar Kedenburg and Ullrich Koethe */ | | /* Copyright 2004 by Gunnar Kedenburg and Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| /************************************************************************/ | | /************************************************************************/ | |
| | | | |
| #ifndef VIGRA_MATRIX_HXX | | #ifndef VIGRA_MATRIX_HXX | |
| #define VIGRA_MATRIX_HXX | | #define VIGRA_MATRIX_HXX | |
| | | | |
| #include <cmath> | | #include <cmath> | |
| #include <iosfwd> | | #include <iosfwd> | |
| #include <iomanip> | | #include <iomanip> | |
| #include "vigra/multi_array.hxx" | | #include "vigra/multi_array.hxx" | |
| #include "vigra/mathutil.hxx" | | #include "vigra/mathutil.hxx" | |
|
| | | #include "vigra/numerictraits.hxx" | |
| | | | |
| namespace vigra | | namespace vigra | |
| { | | { | |
| | | | |
| namespace linalg | | namespace linalg | |
| { | | { | |
| | | | |
| template <class T, class C> | | template <class T, class C> | |
|
| inline std::size_t rowCount(const MultiArrayView<2, T, C> &x); | | inline unsigned int rowCount(const MultiArrayView<2, T, C> &x); | |
| | | | |
| template <class T, class C> | | template <class T, class C> | |
|
| inline std::size_t columnCount(const MultiArrayView<2, T, C> &x); | | inline unsigned int columnCount(const MultiArrayView<2, T, C> &x); | |
| | | | |
| template <class T, class C> | | template <class T, class C> | |
| MultiArrayView <2, T, C> | | MultiArrayView <2, T, C> | |
| rowVector(MultiArrayView <2, T, C> const & m, int d); | | rowVector(MultiArrayView <2, T, C> const & m, int d); | |
| | | | |
| template <class T, class C> | | template <class T, class C> | |
| MultiArrayView <2, T, C> | | MultiArrayView <2, T, C> | |
| columnVector(MultiArrayView<2, T, C> const & m, int d); | | columnVector(MultiArrayView<2, T, C> const & m, int d); | |
| | | | |
|
| template <class T, class C> | | | |
| T squaredNorm(const MultiArrayView<2, T, C> &a); | | | |
| | | | |
| template <class T, class ALLOC> | | template <class T, class ALLOC> | |
| class TemporaryMatrix; | | class TemporaryMatrix; | |
| | | | |
| template <class T, class C1, class C2> | | template <class T, class C1, class C2> | |
| void transpose(const MultiArrayView<2, T, C1> &v, MultiArrayView<2, T, C2>
&r); | | void transpose(const MultiArrayView<2, T, C1> &v, MultiArrayView<2, T, C2>
&r); | |
| | | | |
| template <class T, class C> | | template <class T, class C> | |
| bool isSymmetric(const MultiArrayView<2, T, C> &v); | | bool isSymmetric(const MultiArrayView<2, T, C> &v); | |
| | | | |
|
| | | enum RawArrayMemoryLayout { RowMajor, ColumnMajor }; | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
| /* Matrix */ | | /* Matrix */ | |
| /* */ | | /* */ | |
| /********************************************************/ | | /********************************************************/ | |
| | | | |
| /** Matrix class. | | /** Matrix class. | |
| | | | |
| This is the basic class for all linear algebra computations. Matrices a
re | | This is the basic class for all linear algebra computations. Matrices a
re | |
| strored in a <i>column-major</i> format, i.e. the row index is varying
fastest. | | strored in a <i>column-major</i> format, i.e. the row index is varying
fastest. | |
| | | | |
| skipping to change at line 107 | | skipping to change at line 107 | |
| typedef Matrix<T, ALLOC> matrix_type; | | typedef Matrix<T, ALLOC> matrix_type; | |
| typedef TemporaryMatrix<T, ALLOC> temp_type; | | typedef TemporaryMatrix<T, ALLOC> temp_type; | |
| typedef MultiArrayView<2, T, UnstridedArrayTag> view_type; | | typedef MultiArrayView<2, T, UnstridedArrayTag> view_type; | |
| typedef typename BaseType::value_type value_type; | | typedef typename BaseType::value_type value_type; | |
| typedef typename BaseType::pointer pointer; | | typedef typename BaseType::pointer pointer; | |
| typedef typename BaseType::const_pointer const_pointer; | | typedef typename BaseType::const_pointer const_pointer; | |
| typedef typename BaseType::reference reference; | | typedef typename BaseType::reference reference; | |
| typedef typename BaseType::const_reference const_reference; | | typedef typename BaseType::const_reference const_reference; | |
| typedef typename BaseType::difference_type difference_type; | | typedef typename BaseType::difference_type difference_type; | |
| typedef ALLOC allocator_type; | | typedef ALLOC allocator_type; | |
|
| | | typedef typename BaseType::SquaredNormType SquaredNormType; | |
| | | typedef typename BaseType::NormType NormType; | |
| | | | |
| /** default constructor | | /** default constructor | |
| */ | | */ | |
| Matrix() | | Matrix() | |
| {} | | {} | |
| | | | |
| /** construct with given allocator | | /** construct with given allocator | |
| */ | | */ | |
| explicit Matrix(ALLOC const & alloc) | | explicit Matrix(ALLOC const & alloc) | |
| : BaseType(alloc) | | : BaseType(alloc) | |
| {} | | {} | |
| | | | |
|
| /** construct with given shape and init with all | | /** construct with given shape and init all | |
| elements with zero. Note that the order of the axes is | | elements with zero. Note that the order of the axes is | |
| <tt>difference_type(rows, columns)</tt> which | | <tt>difference_type(rows, columns)</tt> which | |
| is the opposite of the usual VIGRA convention. | | is the opposite of the usual VIGRA convention. | |
| */ | | */ | |
| explicit Matrix(const difference_type &shape, | | explicit Matrix(const difference_type &shape, | |
| ALLOC const & alloc = allocator_type()) | | ALLOC const & alloc = allocator_type()) | |
| : BaseType(shape, alloc) | | : BaseType(shape, alloc) | |
| {} | | {} | |
| | | | |
|
| /** construct with given shape and init with all | | /** construct with given shape and init all | |
| elements with zero. Note that the order of the axes is | | elements with zero. Note that the order of the axes is | |
| <tt>(rows, columns)</tt> which | | <tt>(rows, columns)</tt> which | |
| is the opposite of the usual VIGRA convention. | | is the opposite of the usual VIGRA convention. | |
| */ | | */ | |
|
| Matrix(std::size_t rows, std::size_t columns, | | Matrix(unsigned int rows, unsigned int columns, | |
| ALLOC const & alloc = allocator_type()) | | ALLOC const & alloc = allocator_type()) | |
| : BaseType(difference_type(rows, columns), alloc) | | : BaseType(difference_type(rows, columns), alloc) | |
| {} | | {} | |
| | | | |
|
| /** construct with given shape and init with all | | /** construct with given shape and init all | |
| elements with the constant \a init. Note that the order of the
axes is | | elements with the constant \a init. Note that the order of the
axes is | |
| <tt>difference_type(rows, columns)</tt> which | | <tt>difference_type(rows, columns)</tt> which | |
| is the opposite of the usual VIGRA convention. | | is the opposite of the usual VIGRA convention. | |
| */ | | */ | |
| Matrix(const difference_type &shape, const_reference init, | | Matrix(const difference_type &shape, const_reference init, | |
| allocator_type const & alloc = allocator_type()) | | allocator_type const & alloc = allocator_type()) | |
| : BaseType(shape, init, alloc) | | : BaseType(shape, init, alloc) | |
| {} | | {} | |
| | | | |
|
| /** construct with given shape and init with all | | /** construct with given shape and init all | |
| elements with the constant \a init. Note that the order of the
axes is | | elements with the constant \a init. Note that the order of the
axes is | |
| <tt>(rows, columns)</tt> which | | <tt>(rows, columns)</tt> which | |
| is the opposite of the usual VIGRA convention. | | is the opposite of the usual VIGRA convention. | |
| */ | | */ | |
|
| Matrix(std::size_t rows, std::size_t columns, const_reference init, | | Matrix(unsigned int rows, unsigned int columns, const_reference init, | |
| allocator_type const & alloc = allocator_type()) | | allocator_type const & alloc = allocator_type()) | |
| : BaseType(difference_type(rows, columns), init, alloc) | | : BaseType(difference_type(rows, columns), init, alloc) | |
| {} | | {} | |
| | | | |
| /** construct with given shape and copy data from C-style array \a
init. | | /** construct with given shape and copy data from C-style array \a
init. | |
|
| Data in this array are expected to be given in column-major | | Unless \a layout is <tt>ColumnMajor</tt>, the elements in this | |
| order (the C standard order) and will automatically be | | array | |
| converted to the required column-major format. Note that the or | | are assumed to be given in row-major order (the C standard orde | |
| der of the axes is | | r) and | |
| <tt>difference_type(rows, columns)</tt> which | | will automatically be converted to the required column-major fo | |
| | | rmat. | |
| | | Note that the order of the axes is <tt>difference_type(rows, co | |
| | | lumns)</tt> which | |
| is the opposite of the usual VIGRA convention. | | is the opposite of the usual VIGRA convention. | |
| */ | | */ | |
|
| Matrix(const difference_type &shape, const_pointer init, | | Matrix(const difference_type &shape, const_pointer init, RawArrayMemory
Layout layout = RowMajor, | |
| allocator_type const & alloc = allocator_type()) | | allocator_type const & alloc = allocator_type()) | |
|
| : BaseType(shape, alloc) | | : BaseType(shape, alloc) // FIXME: this function initializes the memory
twice | |
| { | | { | |
|
| difference_type trans(shape[1], shape[0]); | | if(layout == RowMajor) | |
| linalg::transpose(MultiArrayView<2, T>(trans, const_cast<pointer>(i | | { | |
| nit)), *this); | | difference_type trans(shape[1], shape[0]); | |
| | | linalg::transpose(MultiArrayView<2, T>(trans, const_cast<pointe | |
| | | r>(init)), *this); | |
| | | } | |
| | | else | |
| | | { | |
| | | std::copy(init, init + elementCount(), this->data()); | |
| | | } | |
| } | | } | |
| | | | |
| /** construct with given shape and copy data from C-style array \a
init. | | /** construct with given shape and copy data from C-style array \a
init. | |
|
| Data in this array are expected to be given in column-major | | Unless \a layout is <tt>ColumnMajor</tt>, the elements in this | |
| order (the C standard order) and will automatically be | | array | |
| converted to the required column-major format. Note that the or | | are assumed to be given in row-major order (the C standard orde | |
| der of | | r) and | |
| the axes is <tt>(rows, columns)</tt> which | | will automatically be converted to the required column-major fo | |
| | | rmat. | |
| | | Note that the order of the axes is <tt>(rows, columns)</tt> whi | |
| | | ch | |
| is the opposite of the usual VIGRA convention. | | is the opposite of the usual VIGRA convention. | |
| */ | | */ | |
|
| Matrix(std::size_t rows, std::size_t columns, const_pointer init, | | Matrix(unsigned int rows, unsigned int columns, const_pointer init, Raw
ArrayMemoryLayout layout = RowMajor, | |
| allocator_type const & alloc = allocator_type()) | | allocator_type const & alloc = allocator_type()) | |
|
| : BaseType(difference_type(rows, columns), alloc) | | : BaseType(difference_type(rows, columns), alloc) // FIXME: this functi
on initializes the memory twice | |
| { | | { | |
|
| difference_type trans(columns, rows); | | if(layout == RowMajor) | |
| linalg::transpose(MultiArrayView<2, T>(trans, const_cast<pointer>(i | | { | |
| nit)), *this); | | difference_type trans(columns, rows); | |
| | | linalg::transpose(MultiArrayView<2, T>(trans, const_cast<pointe | |
| | | r>(init)), *this); | |
| | | } | |
| | | else | |
| | | { | |
| | | std::copy(init, init + elementCount(), this->data()); | |
| | | } | |
| } | | } | |
| | | | |
| /** copy constructor. Allocates new memory and | | /** copy constructor. Allocates new memory and | |
| copies tha data. | | copies tha data. | |
| */ | | */ | |
| Matrix(const Matrix &rhs) | | Matrix(const Matrix &rhs) | |
| : BaseType(rhs) | | : BaseType(rhs) | |
| {} | | {} | |
| | | | |
| /** construct from temporary matrix, which looses its data. | | /** construct from temporary matrix, which looses its data. | |
| | | | |
| skipping to change at line 256 | | skipping to change at line 272 | |
| */ | | */ | |
| template <class U, class C> | | template <class U, class C> | |
| Matrix & operator=(const MultiArrayView<2, U, C> &rhs) | | Matrix & operator=(const MultiArrayView<2, U, C> &rhs) | |
| { | | { | |
| BaseType::operator=(rhs); // has the correct semantics already | | BaseType::operator=(rhs); // has the correct semantics already | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| /** Create a matrix view that represents the row vector of row \a d
. | | /** Create a matrix view that represents the row vector of row \a d
. | |
| */ | | */ | |
|
| view_type rowVector(std::size_t d) const | | view_type rowVector(unsigned int d) const | |
| { | | { | |
| return vigra::linalg::rowVector(*this, d); | | return vigra::linalg::rowVector(*this, d); | |
| } | | } | |
| | | | |
| /** Create a matrix view that represents the column vector of colum
n \a d. | | /** Create a matrix view that represents the column vector of colum
n \a d. | |
| */ | | */ | |
|
| view_type columnVector(std::size_t d) const | | view_type columnVector(unsigned int d) const | |
| { | | { | |
| return vigra::linalg::columnVector(*this, d); | | return vigra::linalg::columnVector(*this, d); | |
| } | | } | |
| | | | |
| /** number of rows (height) of the matrix. | | /** number of rows (height) of the matrix. | |
| */ | | */ | |
|
| std::size_t rowCount() const | | unsigned int rowCount() const | |
| { | | { | |
| return this->m_shape[0]; | | return this->m_shape[0]; | |
| } | | } | |
| | | | |
| /** number of columns (width) of the matrix. | | /** number of columns (width) of the matrix. | |
| */ | | */ | |
|
| std::size_t columnCount() const | | unsigned int columnCount() const | |
| { | | { | |
| return this->m_shape[1]; | | return this->m_shape[1]; | |
| } | | } | |
| | | | |
| /** number of elements (width*height) of the matrix. | | /** number of elements (width*height) of the matrix. | |
| */ | | */ | |
|
| std::size_t elementCount() const | | unsigned int elementCount() const | |
| { | | { | |
| return rowCount()*columnCount(); | | return rowCount()*columnCount(); | |
| } | | } | |
| | | | |
| /** check whether the matrix is symmetric. | | /** check whether the matrix is symmetric. | |
| */ | | */ | |
| bool isSymmetric() const | | bool isSymmetric() const | |
| { | | { | |
| return vigra::linalg::isSymmetric(*this); | | return vigra::linalg::isSymmetric(*this); | |
| } | | } | |
| | | | |
| #ifdef DOXYGEN | | #ifdef DOXYGEN | |
| // repeat the index functions for documentation. In real code, they are inh
erited. | | // repeat the index functions for documentation. In real code, they are inh
erited. | |
| | | | |
| /** read/write access to matrix element <tt>(row, column)</tt>. | | /** read/write access to matrix element <tt>(row, column)</tt>. | |
| Note that the order of the argument is the opposite of the usua
l | | Note that the order of the argument is the opposite of the usua
l | |
| VIGRA convention due to column-major matrix order. | | VIGRA convention due to column-major matrix order. | |
| */ | | */ | |
|
| value_type & operator()(std::size_t row, std::size_t column); | | value_type & operator()(unsigned int row, unsigned int column); | |
| | | | |
| /** read access to matrix element <tt>(row, column)</tt>. | | /** read access to matrix element <tt>(row, column)</tt>. | |
| Note that the order of the argument is the opposite of the usua
l | | Note that the order of the argument is the opposite of the usua
l | |
| VIGRA convention due to column-major matrix order. | | VIGRA convention due to column-major matrix order. | |
| */ | | */ | |
|
| value_type operator()(std::size_t row, std::size_t column) const; | | value_type operator()(unsigned int row, unsigned int column) const; | |
| #endif | | #endif | |
| | | | |
| /** squared Frobenius norm. Sum of squares of the matrix elements. | | /** squared Frobenius norm. Sum of squares of the matrix elements. | |
| */ | | */ | |
|
| value_type squaredNorm() const | | SquaredNormType squaredNorm() const | |
| { | | { | |
|
| return vigra::linalg::squaredNorm(*this); | | return BaseType::squaredNorm(); | |
| } | | } | |
| | | | |
| /** Frobenius norm. Root of sum of squares of the matrix elements. | | /** Frobenius norm. Root of sum of squares of the matrix elements. | |
| */ | | */ | |
|
| value_type norm() const | | NormType norm() const | |
| { | | { | |
|
| return VIGRA_CSTD::sqrt(squaredNorm()); | | return BaseType::norm(); | |
| } | | } | |
| | | | |
| /** transpose matrix in-place (precondition: matrix must be square) | | /** transpose matrix in-place (precondition: matrix must be square) | |
| */ | | */ | |
| Matrix & transpose(); | | Matrix & transpose(); | |
| | | | |
| /** add \a other to this (sizes must match). | | /** add \a other to this (sizes must match). | |
| */ | | */ | |
| template <class U, class C> | | template <class U, class C> | |
| Matrix & operator+=(MultiArrayView<2, U, C> const & other); | | Matrix & operator+=(MultiArrayView<2, U, C> const & other); | |
| | | | |
| skipping to change at line 436 | | skipping to change at line 452 | |
| typedef TemporaryMatrix<T, ALLOC> temp_type; | | typedef TemporaryMatrix<T, ALLOC> temp_type; | |
| typedef MultiArrayView<2, T, UnstridedArrayTag> view_type; | | typedef MultiArrayView<2, T, UnstridedArrayTag> view_type; | |
| typedef typename BaseType::value_type value_type; | | typedef typename BaseType::value_type value_type; | |
| typedef typename BaseType::pointer pointer; | | typedef typename BaseType::pointer pointer; | |
| typedef typename BaseType::const_pointer const_pointer; | | typedef typename BaseType::const_pointer const_pointer; | |
| typedef typename BaseType::reference reference; | | typedef typename BaseType::reference reference; | |
| typedef typename BaseType::const_reference const_reference; | | typedef typename BaseType::const_reference const_reference; | |
| typedef typename BaseType::difference_type difference_type; | | typedef typename BaseType::difference_type difference_type; | |
| typedef ALLOC allocator_type; | | typedef ALLOC allocator_type; | |
| | | | |
|
| TemporaryMatrix(std::size_t rows, std::size_t columns) | | TemporaryMatrix(unsigned int rows, unsigned int columns) | |
| : BaseType(rows, columns, ALLOC()) | | : BaseType(rows, columns, ALLOC()) | |
| {} | | {} | |
| | | | |
|
| TemporaryMatrix(std::size_t rows, std::size_t columns, const_reference
init) | | TemporaryMatrix(unsigned int rows, unsigned int columns, const_referenc
e init) | |
| : BaseType(rows, columns, init, ALLOC()) | | : BaseType(rows, columns, init, ALLOC()) | |
| {} | | {} | |
| | | | |
| template<class U, class C> | | template<class U, class C> | |
| TemporaryMatrix(const MultiArrayView<2, U, C> &rhs) | | TemporaryMatrix(const MultiArrayView<2, U, C> &rhs) | |
| : BaseType(rhs) | | : BaseType(rhs) | |
| {} | | {} | |
| | | | |
| TemporaryMatrix(const TemporaryMatrix &rhs) | | TemporaryMatrix(const TemporaryMatrix &rhs) | |
| : BaseType() | | : BaseType() | |
| | | | |
| skipping to change at line 502 | | skipping to change at line 518 | |
| */ | | */ | |
| //@{ | | //@{ | |
| | | | |
| /** Number of rows of a matrix represented as a <tt>MultiArrayView<2
,...></tt> | | /** Number of rows of a matrix represented as a <tt>MultiArrayView<2
,...></tt> | |
| | | | |
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | |
| Namespaces: vigra and vigra::linalg | | Namespaces: vigra and vigra::linalg | |
| */ | | */ | |
| template <class T, class C> | | template <class T, class C> | |
|
| inline std::size_t rowCount(const MultiArrayView<2, T, C> &x) | | inline unsigned int rowCount(const MultiArrayView<2, T, C> &x) | |
| { | | { | |
| return x.shape(0); | | return x.shape(0); | |
| } | | } | |
| | | | |
| /** Number of columns of a matrix represented as a <tt>MultiArrayView&l
t;2,...></tt> | | /** Number of columns of a matrix represented as a <tt>MultiArrayView&l
t;2,...></tt> | |
| | | | |
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | |
| Namespaces: vigra and vigra::linalg | | Namespaces: vigra and vigra::linalg | |
| */ | | */ | |
| template <class T, class C> | | template <class T, class C> | |
|
| inline std::size_t columnCount(const MultiArrayView<2, T, C> &x) | | inline unsigned int columnCount(const MultiArrayView<2, T, C> &x) | |
| { | | { | |
| return x.shape(1); | | return x.shape(1); | |
| } | | } | |
| | | | |
| /** Create a row vector view for row \a d of the matrix \a m | | /** Create a row vector view for row \a d of the matrix \a m | |
| | | | |
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | |
| Namespaces: vigra and vigra::linalg | | Namespaces: vigra and vigra::linalg | |
| */ | | */ | |
| | | | |
| skipping to change at line 568 | | skipping to change at line 584 | |
| if(size != columnCount(m)) | | if(size != columnCount(m)) | |
| return false; | | return false; | |
| | | | |
| for(unsigned int i = 0; i < size; ++i) | | for(unsigned int i = 0; i < size; ++i) | |
| for(unsigned int j = i+1; j < size; ++j) | | for(unsigned int j = i+1; j < size; ++j) | |
| if(m(j, i) != m(i, j)) | | if(m(j, i) != m(i, j)) | |
| return false; | | return false; | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | #ifdef DOXYGEN // documentation only -- function is already defined in vigr | |
| | | a/multi_array.hxx | |
| | | | |
| /** calculate the squared Frobenius norm of a matrix. | | /** calculate the squared Frobenius norm of a matrix. | |
| Equal to the sum of squares of the matrix elements. | | Equal to the sum of squares of the matrix elements. | |
| | | | |
|
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a | |
| >" or<br> | | >" | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line | | Namespace: vigra | |
| ar_algebra.hxx</a>"<br> | | | |
| Namespaces: vigra and vigra::linalg | | | |
| */ | | */ | |
|
| template <class T, class C> | | template <class T, class ALLOC> | |
| T squaredNorm(const MultiArrayView<2, T, C> &a) | | typename Matrix<T, ALLLOC>::SquaredNormType | |
| { | | squaredNorm(const Matrix<T, ALLLOC> &a); | |
| const unsigned int rows = rowCount(a); | | | |
| const unsigned int cols = columnCount(a); | | | |
| T ret = NumericTraits<T>::zero(); | | | |
| for(unsigned int j = 0; j < cols; ++j) | | | |
| for(unsigned int i = 0; i < rows; ++i) | | | |
| ret += sq(a(i, j)); | | | |
| return ret; | | | |
| } | | | |
| | | | |
|
| /** calculate the squared norm of a vector. | | /** calculate the squared Frobenius norm of a matrix. | |
| Equal to the sum of squares of the vector elements. | | Equal to the sum of squares of the matrix elements. | |
| | | | |
|
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a | |
| >" or<br> | | >" | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line | | Namespace: vigra | |
| ar_algebra.hxx</a>"<br> | | | |
| Namespaces: vigra and vigra::linalg | | | |
| */ | | */ | |
|
| template <class T, class C> | | template <class T, class ALLOC> | |
| T squaredNorm(const MultiArrayView<1, T, C> &a) | | typename Matrix<T, ALLLOC>::NormType | |
| { | | norm(const Matrix<T, ALLLOC> &a); | |
| const unsigned int size = a.elementCount(); | | | |
| T ret = NumericTraits<T>::zero(); | | | |
| for(unsigned int i = 0; i < size; ++i) | | | |
| ret += sq(a(i)); | | | |
| return ret; | | | |
| } | | | |
| | | | |
| /** calculate the Frobenius norm of a matrix or vector. | | | |
| Equal to the square root of sum of squares of the matrix elements. | | | |
| | | | |
|
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a | | #endif // DOXYGEN | |
| >" or<br> | | | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line | | | |
| ar_algebra.hxx</a>"<br> | | | |
| Namespaces: vigra and vigra::linalg | | | |
| */ | | | |
| template <unsigned int N, class T, class C> | | | |
| T norm(const MultiArrayView<N, T, C> &a) | | | |
| { | | | |
| return VIGRA_CSTD::sqrt(squaredNorm(a)); | | | |
| } | | | |
| | | | |
| /** initialize the given square matrix as an identity matrix. | | /** initialize the given square matrix as an identity matrix. | |
| | | | |
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | |
| Namespaces: vigra and vigra::linalg | | Namespaces: vigra and vigra::linalg | |
| */ | | */ | |
| template <class T, class C> | | template <class T, class C> | |
| void identityMatrix(MultiArrayView<2, T, C> &r) | | void identityMatrix(MultiArrayView<2, T, C> &r) | |
| { | | { | |
| | | | |
| skipping to change at line 1169 | | skipping to change at line 1160 | |
| return TemporaryMatrix<T>(b) *= a; | | return TemporaryMatrix<T>(b) *= a; | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
| inline TemporaryMatrix<T> | | inline TemporaryMatrix<T> | |
| operator*(T a, const TemporaryMatrix<T> &b) | | operator*(T a, const TemporaryMatrix<T> &b) | |
| { | | { | |
| return const_cast<TemporaryMatrix<T> &>(b) *= b; | | return const_cast<TemporaryMatrix<T> &>(b) *= b; | |
| } | | } | |
| | | | |
|
| | | /** multiply matrix \a a with TinyVector \a b. | |
| | | \a a must be of size <tt>N x N</tt>. Vector \a b and the result | |
| | | vector are interpreted as column vectors. | |
| | | | |
| | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a | |
| | | >" or<br> | |
| | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line | |
| | | ar_algebra.hxx</a>"<br> | |
| | | Namespace: vigra::linalg | |
| | | */ | |
| | | template <class T, class A, int N, class DATA, class DERIVED> | |
| | | TinyVector<T, N> | |
| | | operator*(const Matrix<T, A> &a, const TinyVectorBase<T, N, DATA, DERIVED> | |
| | | &b) | |
| | | { | |
| | | vigra_precondition(N == rowCount(a) && N == columnCount(a), | |
| | | "operator*(Matrix, TinyVector): Shape mismatch."); | |
| | | | |
| | | TinyVector<T, N> res = TinyVectorView<T, N>(&a(0,0)) * b[0]; | |
| | | for(unsigned int i = 1; i < N; ++i) | |
| | | res += TinyVectorView<T, N>(&a(0,i)) * b[i]; | |
| | | return res; | |
| | | } | |
| | | | |
| | | /** multiply TinyVector \a a with matrix \a b. | |
| | | \a b must be of size <tt>N x N</tt>. Vector \a a and the result | |
| | | vector are interpreted as row vectors. | |
| | | | |
| | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a | |
| | | >" or<br> | |
| | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line | |
| | | ar_algebra.hxx</a>"<br> | |
| | | Namespace: vigra::linalg | |
| | | */ | |
| | | template <class T, int N, class DATA, class DERIVED, class A> | |
| | | TinyVector<T, N> | |
| | | operator*(const TinyVectorBase<T, N, DATA, DERIVED> &a, const Matrix<T, A> | |
| | | &b) | |
| | | { | |
| | | vigra_precondition(N == rowCount(b) && N == columnCount(b), | |
| | | "operator*(TinyVector, Matrix): Shape mismatch."); | |
| | | | |
| | | TinyVector<T, N> res; | |
| | | for(unsigned int i = 0; i < N; ++i) | |
| | | res[i] = dot(a, TinyVectorView<T, N>(&b(0,i))); | |
| | | return res; | |
| | | } | |
| | | | |
| /** perform matrix multiplication of matrices \a a and \a b. | | /** perform matrix multiplication of matrices \a a and \a b. | |
| \a a and \a b must have matching shapes. | | \a a and \a b must have matching shapes. | |
| The result is returned as a temporary matrix. | | The result is returned as a temporary matrix. | |
| | | | |
| <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | | <b>\#include</b> "<a href="matrix_8hxx-source.html">vigra/matrix.hxx</a
>" or<br> | |
| <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | | <b>\#include</b> "<a href="linear__algebra_8hxx-source.html">vigra/line
ar_algebra.hxx</a>"<br> | |
| Namespace: vigra::linalg | | Namespace: vigra::linalg | |
| */ | | */ | |
| template <class T, class C1, class C2> | | template <class T, class C1, class C2> | |
| inline TemporaryMatrix<T> | | inline TemporaryMatrix<T> | |
| | | | |
| skipping to change at line 1272 | | skipping to change at line 1305 | |
| inline TemporaryMatrix<T> | | inline TemporaryMatrix<T> | |
| operator/(const TemporaryMatrix<T> &a, T b) | | operator/(const TemporaryMatrix<T> &a, T b) | |
| { | | { | |
| return const_cast<TemporaryMatrix<T> &>(a) /= b; | | return const_cast<TemporaryMatrix<T> &>(a) /= b; | |
| } | | } | |
| | | | |
| //@} | | //@} | |
| | | | |
| } // namespace linalg | | } // namespace linalg | |
| | | | |
|
| | | using linalg::RowMajor; | |
| | | using linalg::ColumnMajor; | |
| using linalg::Matrix; | | using linalg::Matrix; | |
| using linalg::identityMatrix; | | using linalg::identityMatrix; | |
| using linalg::diagonalMatrix; | | using linalg::diagonalMatrix; | |
|
| using linalg::squaredNorm; | | | |
| using linalg::norm; | | | |
| using linalg::transpose; | | using linalg::transpose; | |
| using linalg::dot; | | using linalg::dot; | |
| using linalg::outer; | | using linalg::outer; | |
| using linalg::rowCount; | | using linalg::rowCount; | |
| using linalg::columnCount; | | using linalg::columnCount; | |
| using linalg::rowVector; | | using linalg::rowVector; | |
| using linalg::columnVector; | | using linalg::columnVector; | |
| using linalg::isSymmetric; | | using linalg::isSymmetric; | |
| | | | |
|
| | | /********************************************************/ | |
| | | /* */ | |
| | | /* NormTraits */ | |
| | | /* */ | |
| | | /********************************************************/ | |
| | | | |
| | | template <class T, class ALLOC> | |
| | | struct NormTraits<linalg::Matrix<T, ALLOC> > | |
| | | { | |
| | | typedef linalg::Matrix<T, ALLOC> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| | | template <class T, class ALLOC> | |
| | | struct NormTraits<linalg::TemporaryMatrix<T, ALLOC> > | |
| | | { | |
| | | typedef linalg::TemporaryMatrix<T, ALLOC> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| } // namespace vigra | | } // namespace vigra | |
| | | | |
| namespace std { | | namespace std { | |
| | | | |
| /** \addtogroup LinearAlgebraFunctions Matrix functions | | /** \addtogroup LinearAlgebraFunctions Matrix functions | |
| */ | | */ | |
| //@{ | | //@{ | |
| | | | |
| /** print a matrix \a m to the stream \a s. | | /** print a matrix \a m to the stream \a s. | |
| | | | |
| | | | |
End of changes. 47 change blocks. |
| 95 lines changed or deleted | | 159 lines changed or added | |
|
| multi_array.hxx | | multi_array.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 2003 by Gunnar Kedenburg */ | | /* Copyright 2003 by Gunnar Kedenburg */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* ( Version 1.3.0, Sep 10 2004 ) */ | | /* ( Version 1.3.0, Sep 10 2004 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| | | | |
| skipping to change at line 162 | | skipping to change at line 162 | |
| template <> | | template <> | |
| struct MultiIteratorChooser <UnstridedArrayTag> | | struct MultiIteratorChooser <UnstridedArrayTag> | |
| { | | { | |
| template <unsigned int N, class T, class REFERENCE, class POINTER> | | template <unsigned int N, class T, class REFERENCE, class POINTER> | |
| struct Traverser | | struct Traverser | |
| { | | { | |
| typedef MultiIterator <N, T, REFERENCE, POINTER> type; | | typedef MultiIterator <N, T, REFERENCE, POINTER> type; | |
| }; | | }; | |
| }; | | }; | |
| | | | |
|
| | | /********************************************************/ | |
| | | /* */ | |
| | | /* helper functions */ | |
| | | /* */ | |
| | | /********************************************************/ | |
| | | | |
| template <class DestIterator, class Shape, class T, int N> | | template <class DestIterator, class Shape, class T, int N> | |
| void | | void | |
| initMultiArrayData(DestIterator d, Shape const & shape, T const & init, Met
aInt<N>) | | initMultiArrayData(DestIterator d, Shape const & shape, T const & init, Met
aInt<N>) | |
| { | | { | |
| DestIterator dend = d + shape[N]; | | DestIterator dend = d + shape[N]; | |
| for(; d != dend; ++d) | | for(; d != dend; ++d) | |
| { | | { | |
| initMultiArrayData(d.begin(), shape, init, MetaInt<N-1>()); | | initMultiArrayData(d.begin(), shape, init, MetaInt<N-1>()); | |
| } | | } | |
| } | | } | |
| | | | |
| skipping to change at line 228 | | skipping to change at line 234 | |
| void | | void | |
| uninitializedCopyMultiArrayData(SrcIterator s, Shape const & shape, T * & d
, ALLOC & a, MetaInt<0>) | | uninitializedCopyMultiArrayData(SrcIterator s, Shape const & shape, T * & d
, ALLOC & a, MetaInt<0>) | |
| { | | { | |
| SrcIterator send = s + shape[0]; | | SrcIterator send = s + shape[0]; | |
| for(; s != send; ++s, ++d) | | for(; s != send; ++s, ++d) | |
| { | | { | |
| a.construct(d, *s); | | a.construct(d, *s); | |
| } | | } | |
| } | | } | |
| | | | |
|
| | | template <class SrcIterator, class Shape, class T, int N> | |
| | | void | |
| | | squaredNormOfMultiArray(SrcIterator s, Shape const & shape, T & result, Met | |
| | | aInt<N>) | |
| | | { | |
| | | SrcIterator send = s + shape[N]; | |
| | | for(; s != send; ++s) | |
| | | { | |
| | | squaredNormOfMultiArray(s.begin(), shape, result, MetaInt<N-1>()); | |
| | | } | |
| | | } | |
| | | | |
| | | template <class SrcIterator, class Shape, class T> | |
| | | void | |
| | | squaredNormOfMultiArray(SrcIterator s, Shape const & shape, T & result, Met | |
| | | aInt<0>) | |
| | | { | |
| | | SrcIterator send = s + shape[0]; | |
| | | for(; s != send; ++s) | |
| | | { | |
| | | result += *s * *s; | |
| | | } | |
| | | } | |
| | | | |
| } // namespace detail | | } // namespace detail | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
| /* MultiArrayView */ | | /* MultiArrayView */ | |
| /* */ | | /* */ | |
| /********************************************************/ | | /********************************************************/ | |
| | | | |
| // forward declaration | | // forward declaration | |
| template <unsigned int N, class T, class C = UnstridedArrayTag> | | template <unsigned int N, class T, class C = UnstridedArrayTag> | |
| | | | |
| skipping to change at line 333 | | skipping to change at line 361 | |
| C>::template Traverser <actual_dimension, T, T const &, T const *>:
:type const_traverser; | | C>::template Traverser <actual_dimension, T, T const &, T const *>:
:type const_traverser; | |
| | | | |
| /** the view type associated with this array. | | /** the view type associated with this array. | |
| */ | | */ | |
| typedef MultiArrayView <N, T, C> view_type; | | typedef MultiArrayView <N, T, C> view_type; | |
| | | | |
| /** the matrix type associated with this array. | | /** the matrix type associated with this array. | |
| */ | | */ | |
| typedef MultiArray <N, T> matrix_type; | | typedef MultiArray <N, T> matrix_type; | |
| | | | |
|
| | | /** the squared norm type (return type of array.squaredNorm()). | |
| | | */ | |
| | | typedef typename NormTraits<T>::SquaredNormType SquaredNormType; | |
| | | | |
| | | /** the norm type (return type of array.norm()). | |
| | | */ | |
| | | typedef typename NumericTraits<SquaredNormType>::RealPromote NormType; | |
| | | | |
| protected: | | protected: | |
| | | | |
| /** the shape of the image pointed to is stored here. | | /** the shape of the image pointed to is stored here. | |
| */ | | */ | |
| difference_type m_shape; | | difference_type m_shape; | |
| | | | |
| /** the strides (offset of a sample to the next) for every dimensio
n | | /** the strides (offset of a sample to the next) for every dimensio
n | |
| are stored here. | | are stored here. | |
| */ | | */ | |
| difference_type m_stride; | | difference_type m_stride; | |
| | | | |
| skipping to change at line 582 | | skipping to change at line 618 | |
| return m_stride; | | return m_stride; | |
| } | | } | |
| | | | |
| /** return the array's stride at a certain dimension. | | /** return the array's stride at a certain dimension. | |
| */ | | */ | |
| int stride (int n) const | | int stride (int n) const | |
| { | | { | |
| return m_stride [n]; | | return m_stride [n]; | |
| } | | } | |
| | | | |
|
| | | /** return the squared norm of the array (sum of squares of the arr | |
| | | ay elements). | |
| | | */ | |
| | | SquaredNormType squaredNorm() const | |
| | | { | |
| | | SquaredNormType res = NumericTraits<SquaredNormType>::zero(); | |
| | | detail::squaredNormOfMultiArray(traverser_begin(), shape(), res, Me | |
| | | taInt<actual_dimension-1>()); | |
| | | return res; | |
| | | } | |
| | | | |
| | | /** return the norm of the array (equals <tt>sqrt(array.squaredNorm | |
| | | ())</tt>). | |
| | | */ | |
| | | NormType norm() const | |
| | | { | |
| | | return VIGRA_CSTD::sqrt(static_cast<NormType>(this->squaredNorm())) | |
| | | ; | |
| | | } | |
| | | | |
| /** return the pointer to the image data | | /** return the pointer to the image data | |
| */ | | */ | |
| pointer data () const | | pointer data () const | |
| { | | { | |
| return m_ptr; | | return m_ptr; | |
| } | | } | |
| | | | |
| /** returns the N-dimensional MultiIterator pointing | | /** returns the N-dimensional MultiIterator pointing | |
| to the first element in every dimension. | | to the first element in every dimension. | |
| */ | | */ | |
| | | | |
| skipping to change at line 810 | | skipping to change at line 862 | |
| std::copy (m_stride.begin (), m_stride.begin () + n, stride.begin (
)); | | std::copy (m_stride.begin (), m_stride.begin () + n, stride.begin (
)); | |
| std::copy (m_stride.begin () + n+1, m_stride.end (), | | std::copy (m_stride.begin () + n+1, m_stride.end (), | |
| stride.begin () + n); | | stride.begin () + n); | |
| } | | } | |
| return MultiArrayView <N-1, T, StridedArrayTag> | | return MultiArrayView <N-1, T, StridedArrayTag> | |
| (shape, stride, m_ptr + d * m_stride[n]); | | (shape, stride, m_ptr + d * m_stride[n]); | |
| } | | } | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
|
| | | /* norm */ | |
| | | /* */ | |
| | | /********************************************************/ | |
| | | | |
| | | template <unsigned int N, class T, class C> | |
| | | struct NormTraits<MultiArrayView <N, T, C> > | |
| | | { | |
| | | typedef MultiArrayView <N, T, C> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| | | template <unsigned int N, class T, class C> | |
| | | inline typename MultiArrayView <N, T, C>::SquaredNormType | |
| | | squaredNorm(MultiArrayView <N, T, C> const & a) | |
| | | { | |
| | | return a.squaredNorm(); | |
| | | } | |
| | | | |
| | | template <unsigned int N, class T, class C> | |
| | | inline typename MultiArrayView <N, T, C>::NormType | |
| | | norm(MultiArrayView <N, T, C> const & a) | |
| | | { | |
| | | return a.norm(); | |
| | | } | |
| | | | |
| | | /********************************************************/ | |
| | | /* */ | |
| /* MultiArray */ | | /* MultiArray */ | |
| /* */ | | /* */ | |
| /********************************************************/ | | /********************************************************/ | |
| | | | |
| /** \brief Main <TT>MultiArray</TT> class containing the memory | | /** \brief Main <TT>MultiArray</TT> class containing the memory | |
| management. | | management. | |
| | | | |
| This class inherits the interface of MultiArrayView, and implements | | This class inherits the interface of MultiArrayView, and implements | |
| the memory ownership. | | the memory ownership. | |
| MultiArray's are always unstrided, striding them creates a MultiArrayView. | | MultiArray's are always unstrided, striding them creates a MultiArrayView. | |
| | | | |
| skipping to change at line 903 | | skipping to change at line 983 | |
| const_traverser; | | const_traverser; | |
| | | | |
| /** sequential (random access) iterator type | | /** sequential (random access) iterator type | |
| */ | | */ | |
| typedef T * iterator; | | typedef T * iterator; | |
| | | | |
| /** sequential (random access) const iterator type | | /** sequential (random access) const iterator type | |
| */ | | */ | |
| typedef T * const_iterator; | | typedef T * const_iterator; | |
| | | | |
|
| | | /** the squared norm type (return type of squaredNorm(array)). | |
| | | */ | |
| | | typedef typename view_type::SquaredNormType SquaredNormType; | |
| | | | |
| | | /** the norm type (return type of norm(array)). | |
| | | */ | |
| | | typedef typename view_type::NormType NormType; | |
| | | | |
| protected: | | protected: | |
| | | | |
| /** the allocator used to allocate the memory | | /** the allocator used to allocate the memory | |
| */ | | */ | |
| allocator_type m_alloc; | | allocator_type m_alloc; | |
| | | | |
| /** allocate memory for s pixels, write its address into the given | | /** allocate memory for s pixels, write its address into the given | |
| pointer and initialize the pixels with init. | | pointer and initialize the pixels with init. | |
| */ | | */ | |
| void allocate (pointer &ptr, std::size_t s, const_reference init); | | void allocate (pointer &ptr, std::size_t s, const_reference init); | |
| | | | |
| skipping to change at line 1244 | | skipping to change at line 1332 | |
| if (ptr == 0) | | if (ptr == 0) | |
| return; | | return; | |
| for (std::size_t i = 0; i < s; ++i) | | for (std::size_t i = 0; i < s; ++i) | |
| m_alloc.destroy (ptr + i); | | m_alloc.destroy (ptr + i); | |
| m_alloc.deallocate (ptr, s); | | m_alloc.deallocate (ptr, s); | |
| ptr = 0; | | ptr = 0; | |
| } | | } | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
|
| | | /* NormTraits */ | |
| | | /* */ | |
| | | /********************************************************/ | |
| | | | |
| | | template <unsigned int N, class T, class A> | |
| | | struct NormTraits<MultiArray <N, T, A> > | |
| | | { | |
| | | typedef MultiArray <N, T, A> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| | | /********************************************************/ | |
| | | /* */ | |
| /* argument object factories */ | | /* argument object factories */ | |
| /* */ | | /* */ | |
| /********************************************************/ | | /********************************************************/ | |
| | | | |
| template <unsigned int N, class T, class C> | | template <unsigned int N, class T, class C> | |
| inline triple<typename MultiArrayView<N,T,C>::const_traverser, | | inline triple<typename MultiArrayView<N,T,C>::const_traverser, | |
| typename MultiArrayView<N,T,C>::difference_type, | | typename MultiArrayView<N,T,C>::difference_type, | |
| typename AccessorTraits<T>::default_const_accessor > | | typename AccessorTraits<T>::default_const_accessor > | |
| srcMultiArrayRange( MultiArrayView<N,T,C> const & array ) | | srcMultiArrayRange( MultiArrayView<N,T,C> const & array ) | |
| { | | { | |
| | | | |
End of changes. 8 change blocks. |
| 1 lines changed or deleted | | 109 lines changed or added | |
|
| numerictraits.hxx | | numerictraits.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2002 by Ullrich Koethe */ | | /* Copyright 1998-2002 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 50 | | skipping to change at line 50 | |
| | | | |
| <DL> | | <DL> | |
| <DT> | | <DT> | |
| <IMG BORDER=0 ALT="-" SRC="documents/bullet.gif"> | | <IMG BORDER=0 ALT="-" SRC="documents/bullet.gif"> | |
| \ref NumericTraits | | \ref NumericTraits | |
| <DD><em>Unary traits for promotion, conversion, creation of arithmetic
objects</em> | | <DD><em>Unary traits for promotion, conversion, creation of arithmetic
objects</em> | |
| <DT> | | <DT> | |
| <IMG BORDER=0 ALT="-" SRC="documents/bullet.gif"> | | <IMG BORDER=0 ALT="-" SRC="documents/bullet.gif"> | |
| \ref PromoteTraits | | \ref PromoteTraits | |
| <DD><em>Binary traits for promotion of arithmetic objects</em> | | <DD><em>Binary traits for promotion of arithmetic objects</em> | |
|
| | | <IMG BORDER=0 ALT="-" SRC="documents/bullet.gif"> | |
| | | \ref NormTraits | |
| | | <DD><em>Unary traits for the calculation of the norm and squared norm o | |
| | | f arithmetic objects</em> | |
| </DL> | | </DL> | |
| | | | |
| These traits classes contain information that is used by generic | | These traits classes contain information that is used by generic | |
| algorithms and data structures to determine intermediate and result | | algorithms and data structures to determine intermediate and result | |
| types of numerical calculations, to convert between different | | types of numerical calculations, to convert between different | |
| representations of arithmetic types, and to create certain important | | representations of arithmetic types, and to create certain important | |
| constants of each type. Thus, algorithms and data structures | | constants of each type. Thus, algorithms and data structures | |
| operating that need arithmetic operations can be made more | | operating that need arithmetic operations can be made more | |
| independent from the actual data representation. | | independent from the actual data representation. | |
| | | | |
| | | | |
| skipping to change at line 359 | | skipping to change at line 362 | |
| convert to <TT>Promote</TT> type | | convert to <TT>Promote</TT> type | |
| </td></tr> | | </td></tr> | |
| </table> | | </table> | |
| | | | |
| PromoteTraits for the built-in types are defined in <b>\#include</b> | | PromoteTraits for the built-in types are defined in <b>\#include</b> | |
| "<a href="numerictraits_8hxx-source.html">vigra/numerictraits.hxx</a>" | | "<a href="numerictraits_8hxx-source.html">vigra/numerictraits.hxx</a>" | |
| | | | |
| Namespace: vigra | | Namespace: vigra | |
| */ | | */ | |
| | | | |
|
| | | /** \page NormTraits template<> struct NormTraits<ArithmeticType> | |
| | | | |
| | | Unary traits for the calculation of the norm and squared norm of arithm | |
| | | etic objects. | |
| | | | |
| | | <b>\#include</b> | |
| | | "<a href="numerictraits_8hxx-source.html">vigra/numerictraits.hxx</a>" | |
| | | | |
| | | This traits class is used to determine appropriate result types | |
| | | for the functions norm() and squaredNorm(). These functions are always | |
| | | declared like this (where <tt>ArithmeticType</tt> is a type thats suppo | |
| | | rts a norm): | |
| | | | |
| | | \code | |
| | | NormTraits<ArithmeticType>::NormType norm(ArithmeticType const & | |
| | | t); | |
| | | NormTraits<ArithmeticType>::SquaredNormType squaredNorm(ArithmeticType | |
| | | const & t); | |
| | | \endcode | |
| | | | |
| | | The following members are defined in <b> <TT>NormTraits<ArithmeticType> | |
| | | </TT></b>: | |
| | | | |
| | | <table> | |
| | | <tr><td> | |
| | | <b> <TT>typedef ArithmeticType Type;</TT></b> | |
| | | </td><td> | |
| | | the type itself | |
| | | </td></tr> | |
| | | <tr><td> | |
| | | <b> <TT>typedef ... SquaredNormType;</TT></b> | |
| | | </td><td> | |
| | | result of <tt>squaredNorm(ArithmeticType)</tt> | |
| | | </td></tr> | |
| | | <tr><td> | |
| | | <b> <TT>typedef ... NormType;</TT></b> | |
| | | </td><td> | |
| | | result of <tt>norm(ArithmeticType)</tt><br> | |
| | | Usually equal to <tt>NumericTraits<SquaredNormType>::Real | |
| | | Promote | |
| | | </td></tr> | |
| | | </table> | |
| | | | |
| | | NormTraits for the built-in types are defined in <b>\#include</b> | |
| | | "<a href="numerictraits_8hxx-source.html">vigra/numerictraits.hxx</a>" | |
| | | | |
| | | Namespace: vigra | |
| | | */ | |
| | | | |
| namespace vigra { | | namespace vigra { | |
| | | | |
| struct Error_NumericTraits_not_specialized_for_this_case { }; | | struct Error_NumericTraits_not_specialized_for_this_case { }; | |
| | | | |
| template<class A> | | template<class A> | |
| struct NumericTraits | | struct NumericTraits | |
| { | | { | |
| typedef Error_NumericTraits_not_specialized_for_this_case Type; | | typedef Error_NumericTraits_not_specialized_for_this_case Type; | |
| typedef Error_NumericTraits_not_specialized_for_this_case Promote; | | typedef Error_NumericTraits_not_specialized_for_this_case Promote; | |
| typedef Error_NumericTraits_not_specialized_for_this_case RealPromote; | | typedef Error_NumericTraits_not_specialized_for_this_case RealPromote; | |
| | | | |
| skipping to change at line 861 | | skipping to change at line 907 | |
| | | | |
| static Promote toPromote(Type const & v) { return v; } | | static Promote toPromote(Type const & v) { return v; } | |
| static Type fromPromote(Promote const & v) { return v; } | | static Type fromPromote(Promote const & v) { return v; } | |
| static Type fromRealPromote(RealPromote v) { return Type(v); } | | static Type fromRealPromote(RealPromote v) { return Type(v); } | |
| }; | | }; | |
| | | | |
| #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION | | #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION | |
| | | | |
| /********************************************************/ | | /********************************************************/ | |
| /* */ | | /* */ | |
|
| /* PromoteTraits */ | | /* NormTraits */ | |
| | | /* */ | |
| | | /********************************************************/ | |
| | | | |
| | | struct Error_NormTraits_not_specialized_for_this_case { }; | |
| | | | |
| | | template<class A> | |
| | | struct NormTraits | |
| | | { | |
| | | typedef Error_NormTraits_not_specialized_for_this_case Type; | |
| | | typedef Error_NormTraits_not_specialized_for_this_case SquaredNormType; | |
| | | typedef Error_NormTraits_not_specialized_for_this_case NormType; | |
| | | }; | |
| | | | |
| | | #define VIGRA_DEFINE_NORM_TRAITS(T) \ | |
| | | template <> struct NormTraits<T> { \ | |
| | | typedef T Type; \ | |
| | | typedef NumericTraits<T>::Promote SquaredNormType; \ | |
| | | typedef T NormType; \ | |
| | | }; | |
| | | | |
| | | VIGRA_DEFINE_NORM_TRAITS(bool) | |
| | | VIGRA_DEFINE_NORM_TRAITS(signed char) | |
| | | VIGRA_DEFINE_NORM_TRAITS(unsigned char) | |
| | | VIGRA_DEFINE_NORM_TRAITS(short) | |
| | | VIGRA_DEFINE_NORM_TRAITS(unsigned short) | |
| | | VIGRA_DEFINE_NORM_TRAITS(int) | |
| | | VIGRA_DEFINE_NORM_TRAITS(unsigned int) | |
| | | VIGRA_DEFINE_NORM_TRAITS(long) | |
| | | VIGRA_DEFINE_NORM_TRAITS(unsigned long) | |
| | | VIGRA_DEFINE_NORM_TRAITS(float) | |
| | | VIGRA_DEFINE_NORM_TRAITS(double) | |
| | | VIGRA_DEFINE_NORM_TRAITS(long double) | |
| | | | |
| | | #undef VIGRA_DEFINE_NORM_TRAITS | |
| | | | |
| | | #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION | |
| | | | |
| | | template<class T> | |
| | | struct NormTraits<std::complex<T> > | |
| | | { | |
| | | typedef std::complex<T> Type; | |
| | | typedef typename NormTraits<T>::SquaredNormType SquaredNor | |
| | | mType; | |
| | | typedef typename NumericTraits<SquaredNormType>::RealPromote NormType; | |
| | | }; | |
| | | | |
| | | #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION | |
| | | | |
| | | /********************************************************/ | |
| | | /* */ | |
| | | /* PromoteTraits */ | |
| /* */ | | /* */ | |
| /********************************************************/ | | /********************************************************/ | |
| | | | |
| struct Error_PromoteTraits_not_specialized_for_this_case { }; | | struct Error_PromoteTraits_not_specialized_for_this_case { }; | |
| | | | |
| template<class A, class B> | | template<class A, class B> | |
| struct PromoteTraits | | struct PromoteTraits | |
| { | | { | |
| typedef Error_PromoteTraits_not_specialized_for_this_case Promote; | | typedef Error_PromoteTraits_not_specialized_for_this_case Promote; | |
| }; | | }; | |
| | | | |
| skipping to change at line 1882 | | skipping to change at line 1978 | |
| }; | | }; | |
| | | | |
| #if !defined(_MSC_VER) || _MSC_VER >= 1300 | | #if !defined(_MSC_VER) || _MSC_VER >= 1300 | |
| # define VIGRA_SPECIALIZED_CAST(type) \ | | # define VIGRA_SPECIALIZED_CAST(type) \ | |
| template <> \ | | template <> \ | |
| struct RequiresExplicitCast<type> { \ | | struct RequiresExplicitCast<type> { \ | |
| static type cast(float v) \ | | static type cast(float v) \ | |
| { return NumericTraits<type>::fromRealPromote(v); } \ | | { return NumericTraits<type>::fromRealPromote(v); } \ | |
| static type cast(double v) \ | | static type cast(double v) \ | |
| { return NumericTraits<type>::fromRealPromote(v); } \ | | { return NumericTraits<type>::fromRealPromote(v); } \ | |
|
| | | static type cast(type v) \ | |
| | | { return v; } \ | |
| template <class U> \ | | template <class U> \ | |
| static type cast(U v) \ | | static type cast(U v) \ | |
|
| { return v; } \ | | { return static_cast<type>(v); } \ | |
| \ | | \ | |
| }; | | }; | |
| #else | | #else | |
| # define VIGRA_SPECIALIZED_CAST(type) \ | | # define VIGRA_SPECIALIZED_CAST(type) \ | |
| template <> \ | | template <> \ | |
| struct RequiresExplicitCast<type> { \ | | struct RequiresExplicitCast<type> { \ | |
| static type cast(float v) \ | | static type cast(float v) \ | |
| { return NumericTraits<type>::fromRealPromote(v); } \ | | { return NumericTraits<type>::fromRealPromote(v); } \ | |
| static type cast(double v) \ | | static type cast(double v) \ | |
| { return NumericTraits<type>::fromRealPromote(v); } \ | | { return NumericTraits<type>::fromRealPromote(v); } \ | |
| | | | |
End of changes. 6 change blocks. |
| 3 lines changed or deleted | | 109 lines changed or added | |
|
| polynomial.hxx | | polynomial.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2004 by Ullrich Koethe */ | | /* Copyright 1998-2004 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 185 | | skipping to change at line 185 | |
| /** Adjust the polynomial's order if the highest coefficients are n
ear zero. | | /** Adjust the polynomial's order if the highest coefficients are n
ear zero. | |
| The order is reduced as long as the absolute value does not exc
eed | | The order is reduced as long as the absolute value does not exc
eed | |
| the given \a epsilon. | | the given \a epsilon. | |
| */ | | */ | |
| void minimizeOrder(double epsilon = 0.0); | | void minimizeOrder(double epsilon = 0.0); | |
| | | | |
| /** Normalize the polynomial, i.e. dived by the highest coefficient
. | | /** Normalize the polynomial, i.e. dived by the highest coefficient
. | |
| */ | | */ | |
| void normalize(); | | void normalize(); | |
| | | | |
|
| | | void balance(); | |
| | | | |
| /** Get iterator for the coefficient sequence. | | /** Get iterator for the coefficient sequence. | |
| */ | | */ | |
| iterator begin() | | iterator begin() | |
| { return coeffs_; } | | { return coeffs_; } | |
| | | | |
| /** Get end iterator for the coefficient sequence. | | /** Get end iterator for the coefficient sequence. | |
| */ | | */ | |
| iterator end() | | iterator end() | |
| { return begin() + size(); } | | { return begin() + size(); } | |
| | | | |
| | | | |
| skipping to change at line 395 | | skipping to change at line 397 | |
| | | | |
| template <class T> | | template <class T> | |
| void | | void | |
| PolynomialView<T>::normalize() | | PolynomialView<T>::normalize() | |
| { | | { | |
| for(unsigned int i = 0; i<order_; ++i) | | for(unsigned int i = 0; i<order_; ++i) | |
| coeffs_[i] /= coeffs_[order_]; | | coeffs_[i] /= coeffs_[order_]; | |
| coeffs_[order_] = T(1.0); | | coeffs_[order_] = T(1.0); | |
| } | | } | |
| | | | |
|
| | | template <class T> | |
| | | void | |
| | | PolynomialView<T>::balance() | |
| | | { | |
| | | Real p0 = abs(coeffs_[0]), po = abs(coeffs_[order_]); | |
| | | Real norm = (p0 > 0.0) | |
| | | ? VIGRA_CSTD::sqrt(p0*po) | |
| | | : po; | |
| | | for(unsigned int i = 0; i<=order_; ++i) | |
| | | coeffs_[i] /= norm; | |
| | | } | |
| | | | |
| /*****************************************************************/ | | /*****************************************************************/ | |
| /* */ | | /* */ | |
| /* Polynomial */ | | /* Polynomial */ | |
| /* */ | | /* */ | |
| /*****************************************************************/ | | /*****************************************************************/ | |
| | | | |
| /** Polynomial with internally managed array. | | /** Polynomial with internally managed array. | |
| | | | |
| Most interesting functionality is inherited from \ref vigra::Polynomial
View. | | Most interesting functionality is inherited from \ref vigra::Polynomial
View. | |
| | | | |
| | | | |
| skipping to change at line 706 | | skipping to change at line 720 | |
| { | | { | |
| /* divide tops and bottom by b.imag() */ | | /* divide tops and bottom by b.imag() */ | |
| const double ratio = b.real() / b.imag(); | | const double ratio = b.real() / b.imag(); | |
| const double denom = b.real() * ratio + b.imag(); | | const double denom = b.real() * ratio + b.imag(); | |
| return std::complex<T>((a.real() * ratio + a.imag()) / denom
, | | return std::complex<T>((a.real() * ratio + a.imag()) / denom
, | |
| (a.imag() * ratio - a.real()) / denom); | | (a.imag() * ratio - a.real()) / denom); | |
| } | | } | |
| } | | } | |
| | | | |
| template <class T> | | template <class T> | |
|
| std::complex<T> deleteImaginaryBelowEpsilon(std::complex<T> const & x, doub
le eps) | | std::complex<T> deleteBelowEpsilon(std::complex<T> const & x, double eps) | |
| { | | { | |
|
| return std::abs(x.imag()) <= 2.0*eps*std::abs(x.real()) ? | | return std::abs(x.imag()) <= 2.0*eps*std::abs(x.real()) | |
| std::complex<T>(x.real()) | | ? std::complex<T>(x.real()) | |
| : x; | | : std::abs(x.real()) <= 2.0*eps*std::abs(x.imag()) | |
| | | ? std::complex<T>(NumericTraits<T>::zero(), x.imag()) | |
| | | : x; | |
| } | | } | |
| | | | |
| template <class POLYNOMIAL> | | template <class POLYNOMIAL> | |
| typename POLYNOMIAL::value_type | | typename POLYNOMIAL::value_type | |
| laguerreStartingGuess(POLYNOMIAL const & p) | | laguerreStartingGuess(POLYNOMIAL const & p) | |
| { | | { | |
| double N = p.order(); | | double N = p.order(); | |
| typename POLYNOMIAL::value_type centroid = -p[p.order()-1] / N / p[p.or
der()]; | | typename POLYNOMIAL::value_type centroid = -p[p.order()-1] / N / p[p.or
der()]; | |
| double dist = VIGRA_CSTD::pow(std::abs(p(centroid) / p[p.order()]), 1.0
/ N); | | double dist = VIGRA_CSTD::pow(std::abs(p(centroid) / p[p.order()]), 1.0
/ N); | |
| return centroid + dist; | | return centroid + dist; | |
| | | | |
| skipping to change at line 825 | | skipping to change at line 841 | |
| x = x1; | | x = x1; | |
| else | | else | |
| // cycle breaking trick according to Numerical Recipes | | // cycle breaking trick according to Numerical Recipes | |
| x = x - frac[(count+1)/10] * dx; | | x = x - frac[(count+1)/10] * dx; | |
| } | | } | |
| return count < maxiter ? | | return count < maxiter ? | |
| multiplicity : | | multiplicity : | |
| 0; | | 0; | |
| } | | } | |
| | | | |
|
| | | template <class Real> | |
| | | struct PolynomialRootCompare | |
| | | { | |
| | | Real epsilon; | |
| | | | |
| | | PolynomialRootCompare(Real eps) | |
| | | : epsilon(eps) | |
| | | {} | |
| | | | |
| | | template <class T> | |
| | | bool operator()(T const & l, T const & r) | |
| | | { | |
| | | return closeAtTolerance(l.real(), r.real(), epsilon) | |
| | | ? l.imag() < r.imag() | |
| | | : l.real() < r.real(); | |
| | | } | |
| | | }; | |
| | | | |
| } // namespace detail | | } // namespace detail | |
| | | | |
| /** \addtogroup Polynomials Polynomials and root determination | | /** \addtogroup Polynomials Polynomials and root determination | |
| | | | |
| Classes to represent polynomials and functions to find polynomial roots
. | | Classes to represent polynomials and functions to find polynomial roots
. | |
| */ | | */ | |
| //@{ | | //@{ | |
| | | | |
| /*****************************************************************/ | | /*****************************************************************/ | |
| /* */ | | /* */ | |
| | | | |
| skipping to change at line 846 | | skipping to change at line 880 | |
| /* */ | | /* */ | |
| /*****************************************************************/ | | /*****************************************************************/ | |
| | | | |
| /** Determine the roots of the polynomial <tt>poriginal</tt>. | | /** Determine the roots of the polynomial <tt>poriginal</tt>. | |
| | | | |
| The roots are appended to the vector <tt>roots</tt>, with optional root | | The roots are appended to the vector <tt>roots</tt>, with optional root | |
| polishing as specified by <tt>polishRoots</tt> (default: do polishing).
The function uses an | | polishing as specified by <tt>polishRoots</tt> (default: do polishing).
The function uses an | |
| improved version of Laguerre's algorithm. The improvements are as follo
ws: | | improved version of Laguerre's algorithm. The improvements are as follo
ws: | |
| | | | |
| <ul> | | <ul> | |
|
| <li>It uses an clever initial guess for the iteration, according to a p
roposal by Tien Chen</li> | | <li>It uses a clever initial guess for the iteration, according to a pr
oposal by Tien Chen</li> | |
| <li>It estimates each root's multiplicity, again according to Tien Chen
, and reduces multiplicity | | <li>It estimates each root's multiplicity, again according to Tien Chen
, and reduces multiplicity | |
| by switching to the polynomial's derivative (which has the same roo
t, with multiplicity | | by switching to the polynomial's derivative (which has the same roo
t, with multiplicity | |
|
| reduces by one), as proposed by C. Bond.</li> | | reduced by one), as proposed by C. Bond.</li> | |
| </ul> | | </ul> | |
| | | | |
| The algorithm has been successfully used for polynomials up to order 80
. | | The algorithm has been successfully used for polynomials up to order 80
. | |
| The function stops and returns <tt>false</tt> if an iteration fails to
converge within | | The function stops and returns <tt>false</tt> if an iteration fails to
converge within | |
| 80 steps. The type <tt>POLYNOMIAL</tt> must be compatible to | | 80 steps. The type <tt>POLYNOMIAL</tt> must be compatible to | |
| \ref vigra::PolynomialView, <tt>VECTOR</tt> must be compatible to <tt>s
td::vector</tt> | | \ref vigra::PolynomialView, <tt>VECTOR</tt> must be compatible to <tt>s
td::vector</tt> | |
| with a <tt>value_type</tt> compatible to the type <tt>POLYNOMIAL::Compl
ex</tt>. | | with a <tt>value_type</tt> compatible to the type <tt>POLYNOMIAL::Compl
ex</tt>. | |
| | | | |
| <b> Declaration:</b> | | <b> Declaration:</b> | |
| | | | |
| | | | |
| skipping to change at line 883 | | skipping to change at line 917 | |
| | | | |
| \code | | \code | |
| // encode the polynomial x^4 - 1 | | // encode the polynomial x^4 - 1 | |
| Polynomial<double> poly(4); | | Polynomial<double> poly(4); | |
| poly[0] = -1.0; | | poly[0] = -1.0; | |
| poly[4] = 1.0; | | poly[4] = 1.0; | |
| | | | |
| ArrayVector<std::complex<double> > roots; | | ArrayVector<std::complex<double> > roots; | |
| polynomialRoots(poly, roots); | | polynomialRoots(poly, roots); | |
| \endcode | | \endcode | |
|
| | | | |
| | | \see polynomialRootsEigenvalueMethod() | |
| */ | | */ | |
| template <class POLYNOMIAL, class VECTOR> | | template <class POLYNOMIAL, class VECTOR> | |
| bool polynomialRoots(POLYNOMIAL const & poriginal, VECTOR & roots, bool pol
ishRoots) | | bool polynomialRoots(POLYNOMIAL const & poriginal, VECTOR & roots, bool pol
ishRoots) | |
| { | | { | |
| typedef typename POLYNOMIAL::value_type T; | | typedef typename POLYNOMIAL::value_type T; | |
| typedef typename POLYNOMIAL::Real Real; | | typedef typename POLYNOMIAL::Real Real; | |
| typedef typename POLYNOMIAL::Complex Complex; | | typedef typename POLYNOMIAL::Complex Complex; | |
| typedef typename POLYNOMIAL::ComplexPolynomial WorkPolynomial; | | typedef typename POLYNOMIAL::ComplexPolynomial WorkPolynomial; | |
| | | | |
| double eps = poriginal.epsilon(); | | double eps = poriginal.epsilon(); | |
| | | | |
| skipping to change at line 907 | | skipping to change at line 943 | |
| return true; | | return true; | |
| | | | |
| Complex x = detail::laguerreStartingGuess(p); | | Complex x = detail::laguerreStartingGuess(p); | |
| | | | |
| unsigned int multiplicity = 1; | | unsigned int multiplicity = 1; | |
| bool triedConjugate = false; | | bool triedConjugate = false; | |
| | | | |
| // handle the high order cases | | // handle the high order cases | |
| while(p.order() > 2) | | while(p.order() > 2) | |
| { | | { | |
|
| if(std::abs(p[0]) < eps) | | p.balance(); | |
| | | | |
| | | // find root estimate using Laguerre's method on deflated polynomia | |
| | | l p; | |
| | | // zero return indicates failure to converge | |
| | | multiplicity = detail::laguerre1Root(p, x, multiplicity); | |
| | | | |
| | | if(multiplicity == 0) | |
| | | return false; | |
| | | // polish root on original polynomial poriginal; | |
| | | // zero return indicates failure to converge | |
| | | if(polishRoots && !detail::laguerre1Root(poriginal, x, multiplicity | |
| | | )) | |
| | | return false; | |
| | | x = detail::deleteBelowEpsilon(x, eps); | |
| | | roots.push_back(x); | |
| | | p.deflate(x); | |
| | | // determine the next starting guess | |
| | | if(multiplicity > 1) | |
| { | | { | |
|
| // the simple case: missing constant coefficient => zero root | | // probably multiple root => keep current root as starting gues | |
| roots.push_back(Complex(0.0)); | | s | |
| p.deflate(0.0); | | --multiplicity; | |
| x = detail::laguerreStartingGuess(p); | | triedConjugate = false; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| // find root estimate using Laguerre's method on deflated polyn | | // need a new starting guess | |
| omial p; | | if(x.imag() != 0.0 && !triedConjugate) | |
| // zero return indicates failure to converge | | | |
| multiplicity = detail::laguerre1Root(p, x, multiplicity); | | | |
| | | | |
| if(multiplicity == 0) | | | |
| return false; | | | |
| // polish root on original polynomial poriginal; | | | |
| // zero return indicates failure to converge | | | |
| if(polishRoots && !detail::laguerre1Root(poriginal, x, multipli | | | |
| city)) | | | |
| return false; | | | |
| x = detail::deleteImaginaryBelowEpsilon(x, eps); | | | |
| roots.push_back(x); | | | |
| p.deflate(x); | | | |
| // determine the next starting guess | | | |
| if(multiplicity > 1) | | | |
| { | | { | |
|
| // probably multiple root => keep current root as starting | | // if the root is complex and we don't already have | |
| guess | | // the conjugate root => try the conjugate as starting gues | |
| --multiplicity; | | s | |
| triedConjugate = false; | | triedConjugate = true; | |
| | | x = conj(x); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| // need a new starting guess | | // otherwise generate new starting guess | |
| if(x.imag() != 0.0 && !triedConjugate) | | triedConjugate = false; | |
| { | | x = detail::laguerreStartingGuess(p); | |
| // if the root is complex and we don't already have | | | |
| // the conjugate root => try the conjugate as starting | | | |
| guess | | | |
| triedConjugate = true; | | | |
| x = conj(x); | | | |
| } | | | |
| else | | | |
| { | | | |
| // otherwise generate new starting guess | | | |
| triedConjugate = false; | | | |
| x = detail::laguerreStartingGuess(p); | | | |
| } | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| // handle the low order cases | | // handle the low order cases | |
| if(p.order() == 2) | | if(p.order() == 2) | |
| { | | { | |
| Complex a = p[2]; | | Complex a = p[2]; | |
| Complex b = p[1]; | | Complex b = p[1]; | |
| Complex c = p[0]; | | Complex c = p[0]; | |
| Complex b2 = std::sqrt(b*b - 4.0*a*c); | | Complex b2 = std::sqrt(b*b - 4.0*a*c); | |
| Complex q; | | Complex q; | |
| if((conj(b)*b2).real() >= 0.0) | | if((conj(b)*b2).real() >= 0.0) | |
| q = -0.5 * (b + b2); | | q = -0.5 * (b + b2); | |
| else | | else | |
| q = -0.5 * (b - b2); | | q = -0.5 * (b - b2); | |
| x = detail::complexDiv(q, a); | | x = detail::complexDiv(q, a); | |
| if(polishRoots) | | if(polishRoots) | |
| detail::laguerre1Root(poriginal, x, 1); | | detail::laguerre1Root(poriginal, x, 1); | |
|
| roots.push_back(detail::deleteImaginaryBelowEpsilon(x, eps)); | | roots.push_back(detail::deleteBelowEpsilon(x, eps)); | |
| x = detail::complexDiv(c, q); | | x = detail::complexDiv(c, q); | |
| if(polishRoots) | | if(polishRoots) | |
| detail::laguerre1Root(poriginal, x, 1); | | detail::laguerre1Root(poriginal, x, 1); | |
|
| roots.push_back(detail::deleteImaginaryBelowEpsilon(x, eps)); | | roots.push_back(detail::deleteBelowEpsilon(x, eps)); | |
| } | | } | |
| else if(p.order() == 1) | | else if(p.order() == 1) | |
| { | | { | |
| x = detail::complexDiv(-p[0], p[1]); | | x = detail::complexDiv(-p[0], p[1]); | |
| if(polishRoots) | | if(polishRoots) | |
| detail::laguerre1Root(poriginal, x, 1); | | detail::laguerre1Root(poriginal, x, 1); | |
|
| roots.push_back(detail::deleteImaginaryBelowEpsilon(x, eps)); | | roots.push_back(detail::deleteBelowEpsilon(x, eps)); | |
| } | | } | |
|
| | | std::sort(roots.begin(), roots.end(), detail::PolynomialRootCompare<Rea
l>(eps)); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| template <class POLYNOMIAL, class VECTOR> | | template <class POLYNOMIAL, class VECTOR> | |
| inline bool | | inline bool | |
| polynomialRoots(POLYNOMIAL const & poriginal, VECTOR & roots) | | polynomialRoots(POLYNOMIAL const & poriginal, VECTOR & roots) | |
| { | | { | |
| return polynomialRoots(poriginal, roots, true); | | return polynomialRoots(poriginal, roots, true); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 1025 | | skipping to change at line 1054 | |
| | | | |
| \code | | \code | |
| // encode the polynomial x^4 - 1 | | // encode the polynomial x^4 - 1 | |
| Polynomial<double> poly(4); | | Polynomial<double> poly(4); | |
| poly[0] = -1.0; | | poly[0] = -1.0; | |
| poly[4] = 1.0; | | poly[4] = 1.0; | |
| | | | |
| ArrayVector<double> roots; | | ArrayVector<double> roots; | |
| polynomialRealRoots(poly, roots); | | polynomialRealRoots(poly, roots); | |
| \endcode | | \endcode | |
|
| | | | |
| | | \see polynomialRealRootsEigenvalueMethod() | |
| */ | | */ | |
| template <class POLYNOMIAL, class VECTOR> | | template <class POLYNOMIAL, class VECTOR> | |
| bool polynomialRealRoots(POLYNOMIAL const & p, VECTOR & roots, bool polishR
oots) | | bool polynomialRealRoots(POLYNOMIAL const & p, VECTOR & roots, bool polishR
oots) | |
| { | | { | |
| typedef typename NumericTraits<typename VECTOR::value_type>::ComplexPro
mote Complex; | | typedef typename NumericTraits<typename VECTOR::value_type>::ComplexPro
mote Complex; | |
| ArrayVector<Complex> croots; | | ArrayVector<Complex> croots; | |
| if(!polynomialRoots(p, croots, polishRoots)) | | if(!polynomialRoots(p, croots, polishRoots)) | |
| return false; | | return false; | |
| for(unsigned int i = 0; i < croots.size(); ++i) | | for(unsigned int i = 0; i < croots.size(); ++i) | |
| if(croots[i].imag() == 0.0) | | if(croots[i].imag() == 0.0) | |
| | | | |
End of changes. 19 change blocks. |
| 51 lines changed or deleted | | 82 lines changed or added | |
|
| rgbvalue.hxx | | rgbvalue.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2002 by Ullrich Koethe */ | | /* Copyright 1998-2002 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 80 | | skipping to change at line 80 | |
| public: | | public: | |
| /** STL-compatible definition of valuetype | | /** STL-compatible definition of valuetype | |
| */ | | */ | |
| typedef VALUETYPE value_type; | | typedef VALUETYPE value_type; | |
| /** STL-compatible definition of iterator | | /** STL-compatible definition of iterator | |
| */ | | */ | |
| typedef typename TinyVector<VALUETYPE, 3>::iterator iterator; | | typedef typename TinyVector<VALUETYPE, 3>::iterator iterator; | |
| /** STL-compatible definition of const iterator | | /** STL-compatible definition of const iterator | |
| */ | | */ | |
| typedef typename TinyVector<VALUETYPE, 3>::const_iterator const_iterato
r; | | typedef typename TinyVector<VALUETYPE, 3>::const_iterator const_iterato
r; | |
|
| | | /** squared norm type (result of squaredManitude()) | |
| | | */ | |
| | | typedef typename TinyVector<VALUETYPE, 3>::SquaredNormType SquaredNormT | |
| | | ype; | |
| | | /** norm type (result of magnitude()) | |
| | | */ | |
| | | typedef typename TinyVector<VALUETYPE, 3>::NormType NormType; | |
| | | | |
| /** Construct from explicit color values | | /** Construct from explicit color values | |
| */ | | */ | |
| RGBValue(value_type red, value_type green, value_type blue) | | RGBValue(value_type red, value_type green, value_type blue) | |
| : Base(red, green, blue) | | : Base(red, green, blue) | |
| {} | | {} | |
| | | | |
| /** Construct gray value | | /** Construct gray value | |
| */ | | */ | |
| RGBValue(value_type gray) | | RGBValue(value_type gray) | |
| | | | |
| skipping to change at line 188 | | skipping to change at line 194 | |
| */ | | */ | |
| value_type const & blue() const { return (*this)[2]; } | | value_type const & blue() const { return (*this)[2]; } | |
| | | | |
| /** Calculate luminance. | | /** Calculate luminance. | |
| */ | | */ | |
| value_type luminance() const { | | value_type luminance() const { | |
| return detail::RequiresExplicitCast<value_type>::cast(0.3*red() +
0.59*green() + 0.11*blue()); } | | return detail::RequiresExplicitCast<value_type>::cast(0.3*red() +
0.59*green() + 0.11*blue()); } | |
| | | | |
| /** Calculate magnitude. | | /** Calculate magnitude. | |
| */ | | */ | |
|
| typename NumericTraits<VALUETYPE>::RealPromote | | NormType magnitude() const { | |
| magnitude() const { | | | |
| return VIGRA_CSTD::sqrt( | | return VIGRA_CSTD::sqrt( | |
| (typename NumericTraits<VALUETYPE>::RealPromote)squaredMagnitud
e()); | | (typename NumericTraits<VALUETYPE>::RealPromote)squaredMagnitud
e()); | |
| } | | } | |
| | | | |
| /** Calculate squared magnitude. | | /** Calculate squared magnitude. | |
| */ | | */ | |
|
| typename NumericTraits<VALUETYPE>::Promote | | SquaredNormType squaredMagnitude() const { | |
| squaredMagnitude() const { | | | |
| return red()*red() + green()*green() + blue()*blue(); | | return red()*red() + green()*green() + blue()*blue(); | |
| } | | } | |
| | | | |
| /** Set red component. The type <TT>V</TT> of the passed | | /** Set red component. The type <TT>V</TT> of the passed | |
| in <TT>value</TT> is automatically converted to <TT>VALUETYPE</
TT>. | | in <TT>value</TT> is automatically converted to <TT>VALUETYPE</
TT>. | |
| */ | | */ | |
| template <class V> | | template <class V> | |
| void setRed(V value) { (*this)[0] = detail::RequiresExplicitCast<value_
type>::cast(value); } | | void setRed(V value) { (*this)[0] = detail::RequiresExplicitCast<value_
type>::cast(value); } | |
| | | | |
| /** Set green component.The type <TT>V</TT> of the passed | | /** Set green component.The type <TT>V</TT> of the passed | |
| | | | |
| skipping to change at line 296 | | skipping to change at line 300 | |
| { | | { | |
| typedef RGBValue<typename NumericTraits<T>::Promote> Promote; | | typedef RGBValue<typename NumericTraits<T>::Promote> Promote; | |
| typedef RGBValue<typename NumericTraits<T>::RealPromote> RealPromot
e; | | typedef RGBValue<typename NumericTraits<T>::RealPromote> RealPromot
e; | |
| | | | |
| typedef typename NumericTraits<T>::isIntegral isIntegral; | | typedef typename NumericTraits<T>::isIntegral isIntegral; | |
| typedef VigraFalseType isScalar; | | typedef VigraFalseType isScalar; | |
| | | | |
| // etc. | | // etc. | |
| }; | | }; | |
| | | | |
|
| | | template <class T> | |
| | | struct NormTraits<RGBValue<T> > | |
| | | { | |
| | | typedef RGBValue<T> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| template <class T1, class T2> | | template <class T1, class T2> | |
| struct PromoteTraits<RGBValue<T1>, RGBValue<T2> > | | struct PromoteTraits<RGBValue<T1>, RGBValue<T2> > | |
| { | | { | |
| typedef RGBValue<typename PromoteTraits<T1, T2>::Promote> Promote; | | typedef RGBValue<typename PromoteTraits<T1, T2>::Promote> Promote; | |
| }; | | }; | |
| \endcode | | \endcode | |
| | | | |
| <b>\#include</b> "<a href="rgbvalue_8hxx-source.html">vigra/rgbvalue.hx
x</a>"<br> | | <b>\#include</b> "<a href="rgbvalue_8hxx-source.html">vigra/rgbvalue.hx
x</a>"<br> | |
| Namespace: vigra | | Namespace: vigra | |
| | | | |
| | | | |
| skipping to change at line 352 | | skipping to change at line 364 | |
| NumericTraits<T>::fromPromote(v.green()), | | NumericTraits<T>::fromPromote(v.green()), | |
| NumericTraits<T>::fromPromote(v.blue())); | | NumericTraits<T>::fromPromote(v.blue())); | |
| } | | } | |
| static RGBValue<T> fromRealPromote(RealPromote const & v) { | | static RGBValue<T> fromRealPromote(RealPromote const & v) { | |
| return RGBValue<T>(NumericTraits<T>::fromRealPromote(v.red()), | | return RGBValue<T>(NumericTraits<T>::fromRealPromote(v.red()), | |
| NumericTraits<T>::fromRealPromote(v.green()), | | NumericTraits<T>::fromRealPromote(v.green()), | |
| NumericTraits<T>::fromRealPromote(v.blue())); | | NumericTraits<T>::fromRealPromote(v.blue())); | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| | | template <class T> | |
| | | struct NormTraits<RGBValue<T> > | |
| | | { | |
| | | typedef RGBValue<T> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| template <class T1, class T2> | | template <class T1, class T2> | |
| struct PromoteTraits<RGBValue<T1>, RGBValue<T2> > | | struct PromoteTraits<RGBValue<T1>, RGBValue<T2> > | |
| { | | { | |
| typedef RGBValue<typename PromoteTraits<T1, T2>::Promote> Promote; | | typedef RGBValue<typename PromoteTraits<T1, T2>::Promote> Promote; | |
| }; | | }; | |
| | | | |
| template <class T> | | template <class T> | |
| struct PromoteTraits<RGBValue<T>, double > | | struct PromoteTraits<RGBValue<T>, double > | |
| { | | { | |
| typedef RGBValue<typename NumericTraits<T>::RealPromote> Promote; | | typedef RGBValue<typename NumericTraits<T>::RealPromote> Promote; | |
| | | | |
| skipping to change at line 419 | | skipping to change at line 439 | |
| return res;\ | | return res;\ | |
| }\ | | }\ | |
| static RGBValue<T> fromRealPromote(RealPromote const & v) {\ | | static RGBValue<T> fromRealPromote(RealPromote const & v) {\ | |
| RGBValue<T> res;\ | | RGBValue<T> res;\ | |
| RGBValue<T>::iterator d = res.begin();\ | | RGBValue<T>::iterator d = res.begin();\ | |
| RealPromote::const_iterator s = v.begin();\ | | RealPromote::const_iterator s = v.begin();\ | |
| for(; d != res.end(); ++d, ++s)\ | | for(; d != res.end(); ++d, ++s)\ | |
| *d = NumericTraits<T>::fromRealPromote(*s);\ | | *d = NumericTraits<T>::fromRealPromote(*s);\ | |
| return res;\ | | return res;\ | |
| }\ | | }\ | |
|
| | | }; \ | |
| | | template<>\ | |
| | | struct NormTraits<RGBValue<T> >\ | |
| | | {\ | |
| | | typedef RGBValue<T> Type;\ | |
| | | typedef Type::SquaredNormType SquaredNormType; \ | |
| | | typedef Type::NormType NormType; \ | |
| }; | | }; | |
| | | | |
| #define RGBVALUE_PROMTRAITS1(type1) \ | | #define RGBVALUE_PROMTRAITS1(type1) \ | |
| template<> \ | | template<> \ | |
| struct PromoteTraits<RGBValue<type1>, RGBValue<type1> > \ | | struct PromoteTraits<RGBValue<type1>, RGBValue<type1> > \ | |
| { \ | | { \ | |
| typedef RGBValue<PromoteTraits<type1, type1>::Promote> Promote; \ | | typedef RGBValue<PromoteTraits<type1, type1>::Promote> Promote; \ | |
| static Promote toPromote(RGBValue<type1> const & v) { \ | | static Promote toPromote(RGBValue<type1> const & v) { \ | |
| return static_cast<Promote>(v); } \ | | return static_cast<Promote>(v); } \ | |
| }; | | }; | |
| | | | |
End of changes. 7 change blocks. |
| 5 lines changed or deleted | | 33 lines changed or added | |
|
| splines.hxx | | splines.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2004 by Ullrich Koethe */ | | /* Copyright 1998-2004 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| /************************************************************************/ | | /************************************************************************/ | |
| | | | |
| #ifndef VIGRA_SPLINES_HXX | | #ifndef VIGRA_SPLINES_HXX | |
| #define VIGRA_SPLINES_HXX | | #define VIGRA_SPLINES_HXX | |
| | | | |
| #include <cmath> | | #include <cmath> | |
| #include "vigra/config.hxx" | | #include "vigra/config.hxx" | |
| #include "vigra/mathutil.hxx" | | #include "vigra/mathutil.hxx" | |
| #include "vigra/polynomial.hxx" | | #include "vigra/polynomial.hxx" | |
| #include "vigra/array_vector.hxx" | | #include "vigra/array_vector.hxx" | |
|
| | | #include "vigra/fixedpoint.hxx" | |
| | | | |
| namespace vigra { | | namespace vigra { | |
| | | | |
| /** \addtogroup MathFunctions Mathematical Functions | | /** \addtogroup MathFunctions Mathematical Functions | |
| */ | | */ | |
| //@{ | | //@{ | |
| /* B-Splines of arbitrary order and interpolating Catmull/Rom splines. | | /* B-Splines of arbitrary order and interpolating Catmull/Rom splines. | |
| | | | |
| <b>\#include</b> "<a href="splines_8hxx-source.html">vigra/splines.hxx<
/a>"<br> | | <b>\#include</b> "<a href="splines_8hxx-source.html">vigra/splines.hxx<
/a>"<br> | |
| Namespace: vigra | | Namespace: vigra | |
| | | | |
| skipping to change at line 276 | | skipping to change at line 277 | |
| | | | |
| explicit BSplineBase(unsigned int derivativeOrder = 0) | | explicit BSplineBase(unsigned int derivativeOrder = 0) | |
| : derivativeOrder_(derivativeOrder) | | : derivativeOrder_(derivativeOrder) | |
| {} | | {} | |
| | | | |
| result_type operator()(argument_type x) const | | result_type operator()(argument_type x) const | |
| { | | { | |
| return exec(x, derivativeOrder_); | | return exec(x, derivativeOrder_); | |
| } | | } | |
| | | | |
|
| | | template <unsigned int IntBits, unsigned int FracBits> | |
| | | FixedPoint<IntBits, FracBits> operator()(FixedPoint<IntBits, FracBits> | |
| | | x) const | |
| | | { | |
| | | typedef FixedPoint<IntBits, FracBits> Value; | |
| | | return x.value < Value::ONE_HALF && -Value::ONE_HALF <= x.value | |
| | | ? Value(Value::ONE, FPNoShift) | |
| | | : Value(0, FPNoShift); | |
| | | } | |
| | | | |
| result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | | result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | |
| { | | { | |
| return exec(x, derivativeOrder_ + derivative_order); | | return exec(x, derivativeOrder_ + derivative_order); | |
| } | | } | |
| | | | |
| value_type operator[](value_type x) const | | value_type operator[](value_type x) const | |
| { return operator()(x); } | | { return operator()(x); } | |
| | | | |
| double radius() const | | double radius() const | |
| { return 0.5; } | | { return 0.5; } | |
| | | | |
| skipping to change at line 344 | | skipping to change at line 354 | |
| | | | |
| explicit BSpline(unsigned int derivativeOrder = 0) | | explicit BSpline(unsigned int derivativeOrder = 0) | |
| : derivativeOrder_(derivativeOrder) | | : derivativeOrder_(derivativeOrder) | |
| {} | | {} | |
| | | | |
| result_type operator()(argument_type x) const | | result_type operator()(argument_type x) const | |
| { | | { | |
| return exec(x, derivativeOrder_); | | return exec(x, derivativeOrder_); | |
| } | | } | |
| | | | |
|
| | | template <unsigned int IntBits, unsigned int FracBits> | |
| | | FixedPoint<IntBits, FracBits> operator()(FixedPoint<IntBits, FracBits> | |
| | | x) const | |
| | | { | |
| | | typedef FixedPoint<IntBits, FracBits> Value; | |
| | | int v = abs(x.value); | |
| | | return v < Value::ONE ? | |
| | | Value(Value::ONE - v, FPNoShift) | |
| | | : Value(0, FPNoShift); | |
| | | } | |
| | | | |
| result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | | result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | |
| { | | { | |
| return exec(x, derivativeOrder_ + derivative_order); | | return exec(x, derivativeOrder_ + derivative_order); | |
| } | | } | |
| | | | |
| value_type operator[](value_type x) const | | value_type operator[](value_type x) const | |
| { return operator()(x); } | | { return operator()(x); } | |
| | | | |
| double radius() const | | double radius() const | |
| { return 1.0; } | | { return 1.0; } | |
| | | | |
| skipping to change at line 431 | | skipping to change at line 451 | |
| | | | |
| explicit BSpline(unsigned int derivativeOrder = 0) | | explicit BSpline(unsigned int derivativeOrder = 0) | |
| : derivativeOrder_(derivativeOrder) | | : derivativeOrder_(derivativeOrder) | |
| {} | | {} | |
| | | | |
| result_type operator()(argument_type x) const | | result_type operator()(argument_type x) const | |
| { | | { | |
| return exec(x, derivativeOrder_); | | return exec(x, derivativeOrder_); | |
| } | | } | |
| | | | |
|
| | | template <unsigned int IntBits, unsigned int FracBits> | |
| | | FixedPoint<IntBits, FracBits> operator()(FixedPoint<IntBits, FracBits> | |
| | | x) const | |
| | | { | |
| | | typedef FixedPoint<IntBits, FracBits> Value; | |
| | | enum { ONE_HALF = Value::ONE_HALF, THREE_HALVES = ONE_HALF * 3, THR | |
| | | EE_QUARTERS = THREE_HALVES / 2, | |
| | | PREMULTIPLY_SHIFT1 = FracBits <= 16 ? 0 : FracBits - 16, | |
| | | PREMULTIPLY_SHIFT2 = FracBits - 1 <= 16 ? 0 : FracBits - 17, | |
| | | POSTMULTIPLY_SHIFT1 = FracBits - 2*PREMULTIPLY_SHIFT1, | |
| | | POSTMULTIPLY_SHIFT2 = FracBits - 2*PREMULTIPLY_SHIFT2 }; | |
| | | int v = abs(x.value); | |
| | | return v == ONE_HALF | |
| | | ? Value(ONE_HALF, FPNoShift) | |
| | | : v <= ONE_HALF | |
| | | ? Value(THREE_QUARTERS - | |
| | | (int)(sq((unsigned)v >> PREMULTIPLY_SHIFT2) | |
| | | >> POSTMULTIPLY_SHIFT2), FPNoShift) | |
| | | : v < THREE_HALVES | |
| | | ? Value((int)(sq((unsigned)(THREE_HALVES-v) >> | |
| | | PREMULTIPLY_SHIFT1) >> (POSTMULTIPLY_SHIFT1 + 1)), FPNoShift) | |
| | | : Value(0, FPNoShift); | |
| | | } | |
| | | | |
| result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | | result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | |
| { | | { | |
| return exec(x, derivativeOrder_ + derivative_order); | | return exec(x, derivativeOrder_ + derivative_order); | |
| } | | } | |
| | | | |
| value_type operator[](value_type x) const | | value_type operator[](value_type x) const | |
| { return operator()(x); } | | { return operator()(x); } | |
| | | | |
| double radius() const | | double radius() const | |
| { return 1.5; } | | { return 1.5; } | |
| | | | |
| skipping to change at line 537 | | skipping to change at line 577 | |
| | | | |
| explicit BSpline(unsigned int derivativeOrder = 0) | | explicit BSpline(unsigned int derivativeOrder = 0) | |
| : derivativeOrder_(derivativeOrder) | | : derivativeOrder_(derivativeOrder) | |
| {} | | {} | |
| | | | |
| result_type operator()(argument_type x) const | | result_type operator()(argument_type x) const | |
| { | | { | |
| return exec(x, derivativeOrder_); | | return exec(x, derivativeOrder_); | |
| } | | } | |
| | | | |
|
| | | template <unsigned int IntBits, unsigned int FracBits> | |
| | | FixedPoint<IntBits, FracBits> operator()(FixedPoint<IntBits, FracBits> | |
| | | x) const | |
| | | { | |
| | | typedef FixedPoint<IntBits, FracBits> Value; | |
| | | enum { ONE = Value::ONE, TWO = 2 * ONE, TWO_THIRDS = TWO / 3, ONE_S | |
| | | IXTH = ONE / 6, | |
| | | PREMULTIPLY_SHIFT = FracBits <= 16 ? 0 : FracBits - 16, | |
| | | POSTMULTIPLY_SHIFT = FracBits - 2*PREMULTIPLY_SHIFT }; | |
| | | int v = abs(x.value); | |
| | | return v == ONE | |
| | | ? Value(ONE_SIXTH, FPNoShift) | |
| | | : v < ONE | |
| | | ? Value(TWO_THIRDS + | |
| | | (((int)(sq((unsigned)v >> PREMULTIPLY_SHIFT) | |
| | | >> (POSTMULTIPLY_SHIFT + PREMULTIPLY_SHIFT)) | |
| | | * (((v >> 1) - ONE) >> PREMULTIPLY_S | |
| | | HIFT)) >> POSTMULTIPLY_SHIFT), FPNoShift) | |
| | | : v < TWO | |
| | | ? Value((int)((sq((unsigned)(TWO-v) >> PREMULTI | |
| | | PLY_SHIFT) >> (POSTMULTIPLY_SHIFT + PREMULTIPLY_SHIFT)) | |
| | | * ((unsigned)(TWO-v) >> PREMULTIPLY_S | |
| | | HIFT) / 6) >> POSTMULTIPLY_SHIFT, FPNoShift) | |
| | | : Value(0, FPNoShift); | |
| | | } | |
| | | | |
| result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | | result_type operator()(first_argument_type x, second_argument_type deri
vative_order) const | |
| { | | { | |
| return exec(x, derivativeOrder_ + derivative_order); | | return exec(x, derivativeOrder_ + derivative_order); | |
| } | | } | |
| | | | |
| result_type dx(argument_type x) const | | result_type dx(argument_type x) const | |
| { return operator()(x, 1); } | | { return operator()(x, 1); } | |
| | | | |
| result_type dxx(argument_type x) const | | result_type dxx(argument_type x) const | |
| { return operator()(x, 2); } | | { return operator()(x, 2); } | |
| | | | |
End of changes. 6 change blocks. |
| 1 lines changed or deleted | | 73 lines changed or added | |
|
| tinyvector.hxx | | tinyvector.hxx | |
| /************************************************************************/ | | /************************************************************************/ | |
| /* */ | | /* */ | |
| /* Copyright 1998-2002 by Ullrich Koethe */ | | /* Copyright 1998-2002 by Ullrich Koethe */ | |
| /* Cognitive Systems Group, University of Hamburg, Germany */ | | /* Cognitive Systems Group, University of Hamburg, Germany */ | |
| /* */ | | /* */ | |
| /* This file is part of the VIGRA computer vision library. */ | | /* This file is part of the VIGRA computer vision library. */ | |
|
| /* ( Version 1.3.2, Jan 27 2005 ) */ | | /* ( Version 1.3.3, Aug 18 2005 ) */ | |
| /* You may use, modify, and distribute this software according */ | | /* You may use, modify, and distribute this software according */ | |
| /* to the terms stated in the LICENSE file included in */ | | /* to the terms stated in the LICENSE file included in */ | |
| /* the VIGRA distribution. */ | | /* the VIGRA distribution. */ | |
| /* */ | | /* */ | |
| /* The VIGRA Website is */ | | /* The VIGRA Website is */ | |
| /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | | /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ | |
| /* Please direct questions, bug reports, and contributions to */ | | /* Please direct questions, bug reports, and contributions to */ | |
| /* koethe@informatik.uni-hamburg.de */ | | /* koethe@informatik.uni-hamburg.de */ | |
| /* */ | | /* */ | |
| /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | | /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ | |
| | | | |
| skipping to change at line 32 | | skipping to change at line 32 | |
| | | | |
| #ifndef VIGRA_TINYVECTOR_HXX | | #ifndef VIGRA_TINYVECTOR_HXX | |
| #define VIGRA_TINYVECTOR_HXX | | #define VIGRA_TINYVECTOR_HXX | |
| | | | |
| #include <cmath> // abs(double) | | #include <cmath> // abs(double) | |
| #include <cstdlib> // abs(int) | | #include <cstdlib> // abs(int) | |
| #include <iosfwd> // ostream | | #include <iosfwd> // ostream | |
| #include "vigra/config.hxx" | | #include "vigra/config.hxx" | |
| #include "vigra/error.hxx" | | #include "vigra/error.hxx" | |
| #include "vigra/numerictraits.hxx" | | #include "vigra/numerictraits.hxx" | |
|
| #include "vigra/error.hxx" | | #include "vigra/mathutil.hxx" | |
| | | | |
| namespace vigra { | | namespace vigra { | |
| | | | |
| using VIGRA_CSTD::abs; | | using VIGRA_CSTD::abs; | |
| using VIGRA_CSTD::ceil; | | using VIGRA_CSTD::ceil; | |
| using VIGRA_CSTD::floor; | | using VIGRA_CSTD::floor; | |
| | | | |
|
| | | template <class V1, int SIZE, class D1, class D2> | |
| | | class TinyVectorBase; | |
| | | | |
| | | template <class V1, int SIZE, class D1, class D2> | |
| | | inline | |
| | | typename TinyVectorBase<V1, SIZE, D1, D2>::SquaredNormType | |
| | | squaredNorm(TinyVectorBase<V1, SIZE, D1, D2> const & t); | |
| | | | |
| namespace detail { | | namespace detail { | |
| | | | |
| #define VIGRA_EXEC_LOOP(NAME, OPER) \ | | #define VIGRA_EXEC_LOOP(NAME, OPER) \ | |
| template <class T1, class T2> \ | | template <class T1, class T2> \ | |
| static void NAME(T1 * left, T2 const * right) \ | | static void NAME(T1 * left, T2 const * right) \ | |
| { \ | | { \ | |
| for(int i=0; i<LEVEL; ++i) \ | | for(int i=0; i<LEVEL; ++i) \ | |
| (left[i]) OPER (right[i]); \ | | (left[i]) OPER (right[i]); \ | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 110 | | skipping to change at line 118 | |
| | | | |
| template <class T1, class T2> | | template <class T1, class T2> | |
| static typename PromoteTraits<T1, T2>::Promote | | static typename PromoteTraits<T1, T2>::Promote | |
| dot(T1 const * left, T2 const * right) | | dot(T1 const * left, T2 const * right) | |
| { | | { | |
| typename PromoteTraits<T1, T2>::Promote res(*left * *right); | | typename PromoteTraits<T1, T2>::Promote res(*left * *right); | |
| for(int i=1; i<LEVEL; ++i) | | for(int i=1; i<LEVEL; ++i) | |
| res += left[i] * right[i]; | | res += left[i] * right[i]; | |
| return res; | | return res; | |
| } | | } | |
|
| | | | |
| | | template <class T> | |
| | | static typename NormTraits<T>::SquaredNormType | |
| | | squaredNorm(T const * d) | |
| | | { | |
| | | typename NormTraits<T>::SquaredNormType res = vigra::squaredNorm(* | |
| | | d); | |
| | | for(int i=1; i<LEVEL; ++i) | |
| | | res += vigra::squaredNorm(d[i]); | |
| | | return res; | |
| | | } | |
| }; | | }; | |
| | | | |
| template <int LEVEL> | | template <int LEVEL> | |
| struct UnrollDot | | struct UnrollDot | |
| { | | { | |
| template <class T> | | template <class T> | |
| static typename NumericTraits<T>::Promote | | static typename NumericTraits<T>::Promote | |
| dot(T const * d) | | dot(T const * d) | |
| { | | { | |
| return *d * *d + UnrollDot<LEVEL-1>::dot(d+1); | | return *d * *d + UnrollDot<LEVEL-1>::dot(d+1); | |
| | | | |
| skipping to change at line 148 | | skipping to change at line 166 | |
| } | | } | |
| | | | |
| template <class T1, class T2> | | template <class T1, class T2> | |
| static typename PromoteTraits<T1, T2>::Promote | | static typename PromoteTraits<T1, T2>::Promote | |
| dot(T1 const * left, T2 const * right) | | dot(T1 const * left, T2 const * right) | |
| { | | { | |
| return *left * *right; | | return *left * *right; | |
| } | | } | |
| }; | | }; | |
| | | | |
|
| | | template <int LEVEL> | |
| | | struct UnrollSquaredNorm | |
| | | { | |
| | | template <class T> | |
| | | static typename NormTraits<T>::SquaredNormType | |
| | | squaredNorm(T const * d) | |
| | | { | |
| | | return vigra::squaredNorm(*d) + UnrollSquaredNorm<LEVEL-1>::squared | |
| | | Norm(d+1); | |
| | | } | |
| | | }; | |
| | | | |
| | | template <> | |
| | | struct UnrollSquaredNorm<1> | |
| | | { | |
| | | template <class T> | |
| | | static typename NormTraits<T>::SquaredNormType | |
| | | squaredNorm(T const * d) | |
| | | { | |
| | | return vigra::squaredNorm(*d); | |
| | | } | |
| | | }; | |
| | | | |
| #undef VIGRA_EXEC_LOOP | | #undef VIGRA_EXEC_LOOP | |
| #undef VIGRA_EXEC_LOOP_SCALAR | | #undef VIGRA_EXEC_LOOP_SCALAR | |
| | | | |
| #define VIGRA_UNROLL_LOOP(NAME, OPER) \ | | #define VIGRA_UNROLL_LOOP(NAME, OPER) \ | |
| template <class T1, class T2> \ | | template <class T1, class T2> \ | |
| static void NAME(T1 * left, T2 const * right) \ | | static void NAME(T1 * left, T2 const * right) \ | |
| { \ | | { \ | |
| (*left) OPER (*right); \ | | (*left) OPER (*right); \ | |
| UnrollLoop<LEVEL-1>::NAME(left+1, right+1); \ | | UnrollLoop<LEVEL-1>::NAME(left+1, right+1); \ | |
| } | | } | |
| | | | |
| skipping to change at line 210 | | skipping to change at line 250 | |
| { | | { | |
| return UnrollDot<LEVEL>::dot(d); | | return UnrollDot<LEVEL>::dot(d); | |
| } | | } | |
| | | | |
| template <class T1, class T2> | | template <class T1, class T2> | |
| static typename PromoteTraits<T1, T2>::Promote | | static typename PromoteTraits<T1, T2>::Promote | |
| dot(T1 const * left, T2 const * right) | | dot(T1 const * left, T2 const * right) | |
| { | | { | |
| return UnrollDot<LEVEL>::dot(left, right); | | return UnrollDot<LEVEL>::dot(left, right); | |
| } | | } | |
|
| | | | |
| | | template <class T> | |
| | | static typename NormTraits<T>::SquaredNormType | |
| | | squaredNorm(T const * d) | |
| | | { | |
| | | return UnrollSquaredNorm<LEVEL>::squaredNorm(d); | |
| | | } | |
| }; | | }; | |
| | | | |
| #undef VIGRA_UNROLL_LOOP | | #undef VIGRA_UNROLL_LOOP | |
| #undef VIGRA_UNROLL_LOOP_SCALAR | | #undef VIGRA_UNROLL_LOOP_SCALAR | |
| | | | |
| template <> | | template <> | |
| struct UnrollLoop<0> | | struct UnrollLoop<0> | |
| { | | { | |
| template <class T1, class T2> | | template <class T1, class T2> | |
| static void assignCast(T1, T2) {} | | static void assignCast(T1, T2) {} | |
| | | | |
| skipping to change at line 361 | | skipping to change at line 408 | |
| typedef unsigned int size_type; | | typedef unsigned int size_type; | |
| | | | |
| /** STL-compatible definition of difference_type | | /** STL-compatible definition of difference_type | |
| */ | | */ | |
| typedef int difference_type; | | typedef int difference_type; | |
| | | | |
| /** the scalar type for the outer product | | /** the scalar type for the outer product | |
| */ | | */ | |
| typedef double scalar_multiplier; | | typedef double scalar_multiplier; | |
| | | | |
|
| | | /** the vector's squared norm type | |
| | | */ | |
| | | typedef typename NormTraits<VALUETYPE>::SquaredNormType SquaredNormType | |
| | | ; | |
| | | | |
| | | /** the vector's norm type | |
| | | */ | |
| | | typedef typename NumericTraits<SquaredNormType>::RealPromote NormType; | |
| | | | |
| /** the vector's size | | /** the vector's size | |
| */ | | */ | |
| enum { static_size = SIZE }; | | enum { static_size = SIZE }; | |
| | | | |
| /** Initialize from another sequence (must have length SIZE!) | | /** Initialize from another sequence (must have length SIZE!) | |
| */ | | */ | |
| template <class Iterator> | | template <class Iterator> | |
| void init(Iterator i, Iterator end) | | void init(Iterator i, Iterator end) | |
| { | | { | |
| vigra_precondition(end-i == SIZE, | | vigra_precondition(end-i == SIZE, | |
| | | | |
| skipping to change at line 420 | | skipping to change at line 475 | |
| /** Component-wise scalar divide-assignment | | /** Component-wise scalar divide-assignment | |
| */ | | */ | |
| DERIVED & operator/=(double r) | | DERIVED & operator/=(double r) | |
| { | | { | |
| Loop::divScalar(data_, r); | | Loop::divScalar(data_, r); | |
| return static_cast<DERIVED &>(*this); | | return static_cast<DERIVED &>(*this); | |
| } | | } | |
| | | | |
| /** Calculate magnitude. | | /** Calculate magnitude. | |
| */ | | */ | |
|
| typename NumericTraits<VALUETYPE>::RealPromote | | NormType magnitude() const | |
| magnitude() const | | | |
| { | | { | |
|
| return VIGRA_CSTD::sqrt( | | return VIGRA_CSTD::sqrt(static_cast<NormType>(squaredMagnitude())) | |
| (typename NumericTraits<VALUETYPE>::RealPromote)squaredMagni | | ; | |
| tude()); | | | |
| } | | } | |
| | | | |
| /** Calculate squared magnitude. | | /** Calculate squared magnitude. | |
| */ | | */ | |
|
| typename NumericTraits<VALUETYPE>::Promote | | SquaredNormType squaredMagnitude() const | |
| squaredMagnitude() const | | | |
| { | | { | |
|
| return Loop::dot(data_); | | return Loop::squaredNorm(data_); | |
| } | | } | |
| | | | |
| /** Access component by index. | | /** Access component by index. | |
| */ | | */ | |
| reference operator[](difference_type i) { return data_[i]; } | | reference operator[](difference_type i) { return data_[i]; } | |
| | | | |
| /** Get component by index. | | /** Get component by index. | |
| */ | | */ | |
| const_reference operator[](difference_type i) const { return data_[i];
} | | const_reference operator[](difference_type i) const { return data_[i];
} | |
| | | | |
| | | | |
| skipping to change at line 528 | | skipping to change at line 580 | |
| typedef typename BaseType::value_type value_type; | | typedef typename BaseType::value_type value_type; | |
| typedef typename BaseType::reference reference; | | typedef typename BaseType::reference reference; | |
| typedef typename BaseType::const_reference const_reference; | | typedef typename BaseType::const_reference const_reference; | |
| typedef typename BaseType::pointer pointer; | | typedef typename BaseType::pointer pointer; | |
| typedef typename BaseType::const_pointer const_pointer; | | typedef typename BaseType::const_pointer const_pointer; | |
| typedef typename BaseType::iterator iterator; | | typedef typename BaseType::iterator iterator; | |
| typedef typename BaseType::const_iterator const_iterator; | | typedef typename BaseType::const_iterator const_iterator; | |
| typedef typename BaseType::size_type size_type; | | typedef typename BaseType::size_type size_type; | |
| typedef typename BaseType::difference_type difference_type; | | typedef typename BaseType::difference_type difference_type; | |
| typedef typename BaseType::scalar_multiplier scalar_multiplier; | | typedef typename BaseType::scalar_multiplier scalar_multiplier; | |
|
| | | typedef typename BaseType::SquaredNormType SquaredNormType; | |
| | | typedef typename BaseType::NormType NormType; | |
| | | | |
| /** Construction with constant value | | /** Construction with constant value | |
| */ | | */ | |
| explicit TinyVector(value_type const & initial) | | explicit TinyVector(value_type const & initial) | |
| : BaseType() | | : BaseType() | |
| { | | { | |
| Loop::assignScalar(BaseType::begin(), initial); | | Loop::assignScalar(BaseType::begin(), initial); | |
| } | | } | |
| | | | |
| /** Construction with explicit values. | | /** Construction with explicit values. | |
| | | | |
| skipping to change at line 587 | | skipping to change at line 641 | |
| } | | } | |
| | | | |
| /** Copy constructor. | | /** Copy constructor. | |
| */ | | */ | |
| TinyVector(TinyVector const & r) | | TinyVector(TinyVector const & r) | |
| : BaseType() | | : BaseType() | |
| { | | { | |
| Loop::assign(BaseType::data_, r.data_); | | Loop::assign(BaseType::data_, r.data_); | |
| } | | } | |
| | | | |
|
| | | /** Constructor from C array. | |
| | | */ | |
| | | explicit TinyVector(const_pointer data) | |
| | | : BaseType() | |
| | | { | |
| | | Loop::assign(BaseType::data_, data); | |
| | | } | |
| | | | |
| /** Copy assignment. | | /** Copy assignment. | |
| */ | | */ | |
| TinyVector & operator=(TinyVector const & r) | | TinyVector & operator=(TinyVector const & r) | |
| { | | { | |
| Loop::assign(BaseType::data_, r.data_); | | Loop::assign(BaseType::data_, r.data_); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| /** Copy with type conversion. | | /** Copy with type conversion. | |
| */ | | */ | |
| | | | |
| skipping to change at line 666 | | skipping to change at line 728 | |
| typedef typename BaseType::value_type value_type; | | typedef typename BaseType::value_type value_type; | |
| typedef typename BaseType::reference reference; | | typedef typename BaseType::reference reference; | |
| typedef typename BaseType::const_reference const_reference; | | typedef typename BaseType::const_reference const_reference; | |
| typedef typename BaseType::pointer pointer; | | typedef typename BaseType::pointer pointer; | |
| typedef typename BaseType::const_pointer const_pointer; | | typedef typename BaseType::const_pointer const_pointer; | |
| typedef typename BaseType::iterator iterator; | | typedef typename BaseType::iterator iterator; | |
| typedef typename BaseType::const_iterator const_iterator; | | typedef typename BaseType::const_iterator const_iterator; | |
| typedef typename BaseType::size_type size_type; | | typedef typename BaseType::size_type size_type; | |
| typedef typename BaseType::difference_type difference_type; | | typedef typename BaseType::difference_type difference_type; | |
| typedef typename BaseType::scalar_multiplier scalar_multiplier; | | typedef typename BaseType::scalar_multiplier scalar_multiplier; | |
|
| | | typedef typename BaseType::SquaredNormType SquaredNormType; | |
| | | typedef typename BaseType::NormType NormType; | |
| | | | |
| /** Default constructor | | /** Default constructor | |
| (pointer to wrapped data is NULL). | | (pointer to wrapped data is NULL). | |
| */ | | */ | |
| TinyVectorView() | | TinyVectorView() | |
| : BaseType() | | : BaseType() | |
| { | | { | |
| BaseType::data_ = 0; | | BaseType::data_ = 0; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 810 | | skipping to change at line 874 | |
| { | | { | |
| typedef TinyVector<typename NumericTraits<T>::Promote, SIZE> Promot
e; | | typedef TinyVector<typename NumericTraits<T>::Promote, SIZE> Promot
e; | |
| typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> Re
alPromote; | | typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> Re
alPromote; | |
| | | | |
| typedef typename NumericTraits<T>::isIntegral isIntegral; | | typedef typename NumericTraits<T>::isIntegral isIntegral; | |
| typedef VigraFalseType isScalar; | | typedef VigraFalseType isScalar; | |
| | | | |
| // etc. | | // etc. | |
| }; | | }; | |
| | | | |
|
| | | template <class T, int SIZE> | |
| | | struct NormTraits<TinyVector<T, SIZE> > | |
| | | { | |
| | | typedef TinyVector<T, SIZE> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| template <class T1, class T2, SIZE> | | template <class T1, class T2, SIZE> | |
| struct PromoteTraits<TinyVector<T1, SIZE>, TinyVector<T2, SIZE> > | | struct PromoteTraits<TinyVector<T1, SIZE>, TinyVector<T2, SIZE> > | |
| { | | { | |
| typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> P
romote; | | typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> P
romote; | |
| }; | | }; | |
| \endcode | | \endcode | |
| | | | |
| <b>\#include</b> "<a href="tinyvector_8hxx-source.html">vigra/tinyvecto
r.hxx</a>"<br> | | <b>\#include</b> "<a href="tinyvector_8hxx-source.html">vigra/tinyvecto
r.hxx</a>"<br> | |
| Namespace: vigra | | Namespace: vigra | |
| | | | |
| | | | |
| skipping to change at line 902 | | skipping to change at line 974 | |
| typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> RealPr
omote; | | typedef TinyVector<typename NumericTraits<T>::RealPromote, SIZE> RealPr
omote; | |
| typedef TinyVector<typename NumericTraits<T>::ComplexPromote, SIZE> Com
plexPromote; | | typedef TinyVector<typename NumericTraits<T>::ComplexPromote, SIZE> Com
plexPromote; | |
| typedef T ValueType; | | typedef T ValueType; | |
| | | | |
| typedef typename NumericTraits<T>::isIntegral isIntegral; | | typedef typename NumericTraits<T>::isIntegral isIntegral; | |
| typedef VigraFalseType isScalar; | | typedef VigraFalseType isScalar; | |
| typedef VigraFalseType isOrdered; | | typedef VigraFalseType isOrdered; | |
| typedef VigraFalseType isComplex; | | typedef VigraFalseType isComplex; | |
| }; | | }; | |
| | | | |
|
| | | template <class T, int SIZE> | |
| | | struct NormTraits<TinyVector<T, SIZE> > | |
| | | { | |
| | | typedef TinyVector<T, SIZE> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| | | template <class T, int SIZE> | |
| | | struct NormTraits<TinyVectorView<T, SIZE> > | |
| | | { | |
| | | typedef TinyVector<T, SIZE> Type; | |
| | | typedef typename Type::SquaredNormType SquaredNormType; | |
| | | typedef typename Type::NormType NormType; | |
| | | }; | |
| | | | |
| template <class T1, class T2, int SIZE> | | template <class T1, class T2, int SIZE> | |
| struct PromoteTraits<TinyVector<T1, SIZE>, TinyVector<T2, SIZE> > | | struct PromoteTraits<TinyVector<T1, SIZE>, TinyVector<T2, SIZE> > | |
| { | | { | |
| typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promo
te; | | typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promo
te; | |
| }; | | }; | |
| | | | |
| template <class T1, class T2, int SIZE> | | template <class T1, class T2, int SIZE> | |
| struct PromoteTraits<TinyVectorView<T1, SIZE>, TinyVectorView<T2, SIZE> > | | struct PromoteTraits<TinyVectorView<T1, SIZE>, TinyVectorView<T2, SIZE> > | |
| { | | { | |
| typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promo
te; | | typedef TinyVector<typename PromoteTraits<T1, T2>::Promote, SIZE> Promo
te; | |
| | | | |
| skipping to change at line 998 | | skipping to change at line 1086 | |
| return res;\ | | return res;\ | |
| }\ | | }\ | |
| static TinyVector<T, SIZE> fromRealPromote(RealPromote const & v) {\ | | static TinyVector<T, SIZE> fromRealPromote(RealPromote const & v) {\ | |
| TinyVector<T, SIZE> res;\ | | TinyVector<T, SIZE> res;\ | |
| TinyVector<T, SIZE>::iterator d = res.begin(), dend = res.end();\ | | TinyVector<T, SIZE>::iterator d = res.begin(), dend = res.end();\ | |
| RealPromote::const_iterator s = v.begin();\ | | RealPromote::const_iterator s = v.begin();\ | |
| for(; d != dend; ++d, ++s)\ | | for(; d != dend; ++d, ++s)\ | |
| *d = NumericTraits<T>::fromRealPromote(*s);\ | | *d = NumericTraits<T>::fromRealPromote(*s);\ | |
| return res;\ | | return res;\ | |
| }\ | | }\ | |
|
| | | }; \ | |
| | | template<>\ | |
| | | struct NormTraits<TinyVector<T, SIZE> >\ | |
| | | {\ | |
| | | typedef TinyVector<T, SIZE> Type;\ | |
| | | typedef Type::SquaredNormType SquaredNormType; \ | |
| | | typedef Type::NormType NormType; \ | |
| }; | | }; | |
| | | | |
| #define TINYVECTOR_PROMTRAITS1(type1, SIZE) \ | | #define TINYVECTOR_PROMTRAITS1(type1, SIZE) \ | |
| template<> \ | | template<> \ | |
| struct PromoteTraits<TinyVector<type1, SIZE>, TinyVector<type1, SIZE> > \ | | struct PromoteTraits<TinyVector<type1, SIZE>, TinyVector<type1, SIZE> > \ | |
| { \ | | { \ | |
| typedef TinyVector<PromoteTraits<type1, type1>::Promote, SIZE> Promote;
\ | | typedef TinyVector<PromoteTraits<type1, type1>::Promote, SIZE> Promote;
\ | |
| static Promote toPromote(TinyVector<type1, SIZE> const & v) { \ | | static Promote toPromote(TinyVector<type1, SIZE> const & v) { \ | |
| return static_cast<Promote>(v); } \ | | return static_cast<Promote>(v); } \ | |
| }; | | }; | |
| | | | |
| skipping to change at line 1070 | | skipping to change at line 1165 | |
| */ | | */ | |
| //@{ | | //@{ | |
| | | | |
| /// component-wise addition | | /// component-wise addition | |
| template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | | template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | |
| inline | | inline | |
| typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promot
e | | typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promot
e | |
| operator+(TinyVectorBase<V1, SIZE, D1, D2> const & l, | | operator+(TinyVectorBase<V1, SIZE, D1, D2> const & l, | |
| TinyVectorBase<V2, SIZE, D3, D4> const & r) | | TinyVectorBase<V2, SIZE, D3, D4> const & r) | |
| { | | { | |
|
| typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::P | | return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZ | |
| romote res(l); | | E> >::Promote(l) += r; | |
| res += r; | | | |
| return res; | | | |
| } | | } | |
| | | | |
| /// component-wise subtraction | | /// component-wise subtraction | |
| template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | | template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | |
| inline | | inline | |
| typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promot
e | | typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promot
e | |
| operator-(TinyVectorBase<V1, SIZE, D1, D2> const & l, | | operator-(TinyVectorBase<V1, SIZE, D1, D2> const & l, | |
| TinyVectorBase<V2, SIZE, D3, D4> const & r) | | TinyVectorBase<V2, SIZE, D3, D4> const & r) | |
| { | | { | |
|
| typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::P | | return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZ | |
| romote res(l); | | E> >::Promote(l) -= r; | |
| res -= r; | | | |
| return res; | | | |
| } | | } | |
| | | | |
| /// component-wise multiplication | | /// component-wise multiplication | |
| template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | | template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | |
| inline | | inline | |
| typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promot
e | | typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2, SIZE> >::Promot
e | |
| operator*(TinyVectorBase<V1, SIZE, D1, D2> const & l, | | operator*(TinyVectorBase<V1, SIZE, D1, D2> const & l, | |
| TinyVectorBase<V2, SIZE, D3, D4> const & r) | | TinyVectorBase<V2, SIZE, D3, D4> const & r) | |
| { | | { | |
|
| typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZE> >::P | | return typename PromoteTraits<TinyVector<V1, SIZE>, TinyVector<V2 , SIZ | |
| romote res(l); | | E> >::Promote(l) *= r; | |
| res *= r; | | | |
| return res; | | | |
| } | | } | |
| | | | |
| /// component-wise left scalar multiplication | | /// component-wise left scalar multiplication | |
| template <class V, int SIZE, class D1, class D2> | | template <class V, int SIZE, class D1, class D2> | |
| inline | | inline | |
| typename NumericTraits<TinyVector<V, SIZE> >::RealPromote | | typename NumericTraits<TinyVector<V, SIZE> >::RealPromote | |
| operator*(double v, TinyVectorBase<V, SIZE, D1, D2> const & r) | | operator*(double v, TinyVectorBase<V, SIZE, D1, D2> const & r) | |
| { | | { | |
| return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(r) *=
v; | | return typename NumericTraits<TinyVector<V, SIZE> >::RealPromote(r) *=
v; | |
| } | | } | |
| | | | |
| skipping to change at line 1188 | | skipping to change at line 1277 | |
| template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | | template <class V1, int SIZE, class D1, class D2, class V2, class D3, class
D4> | |
| inline | | inline | |
| typename PromoteTraits<V1, V2>::Promote | | typename PromoteTraits<V1, V2>::Promote | |
| dot(TinyVectorBase<V1, SIZE, D1, D2> const & l, | | dot(TinyVectorBase<V1, SIZE, D1, D2> const & l, | |
| TinyVectorBase<V2, SIZE, D3, D4> const & r) | | TinyVectorBase<V2, SIZE, D3, D4> const & r) | |
| { | | { | |
| typedef typename detail::LoopType<SIZE>::type ltype; | | typedef typename detail::LoopType<SIZE>::type ltype; | |
| return ltype::dot(l.begin(), r.begin()); | | return ltype::dot(l.begin(), r.begin()); | |
| } | | } | |
| | | | |
|
| | | /// squared norm | |
| | | template <class V1, int SIZE, class D1, class D2> | |
| | | inline | |
| | | typename TinyVectorBase<V1, SIZE, D1, D2>::SquaredNormType | |
| | | squaredNorm(TinyVectorBase<V1, SIZE, D1, D2> const & t) | |
| | | { | |
| | | return t.squaredMagnitude(); | |
| | | } | |
| //@} | | //@} | |
| | | | |
| } // namespace vigra | | } // namespace vigra | |
| | | | |
| #endif // VIGRA_TINYVECTOR_HXX | | #endif // VIGRA_TINYVECTOR_HXX | |
| | | | |
End of changes. 21 change blocks. |
| 22 lines changed or deleted | | 122 lines changed or added | |
|