From 8480b84bb4764577b8e02308af5dab66bf965536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Thu, 11 Nov 2010 17:04:37 +0000 Subject: [PATCH] Added some vector norm functions for L1 norm, and absolute mean,max,min(Thanks to Michal Nociar) git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@339 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Core/Geometry/VectorT_inc.hh | 78 ++++++++++++++++++++++- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/src/OpenMesh/Core/Geometry/VectorT_inc.hh b/src/OpenMesh/Core/Geometry/VectorT_inc.hh index ba6c4e69..7e14c8cf 100644 --- a/src/OpenMesh/Core/Geometry/VectorT_inc.hh +++ b/src/OpenMesh/Core/Geometry/VectorT_inc.hh @@ -416,7 +416,6 @@ public: #undef expr #endif } - //@} /** normalize vector, return normalized vector */ @@ -438,10 +437,37 @@ public: } return *this; } + + //@} + //------------------------------------------------------------ euclidean norm + + /// \name Non-Euclidean norm calculations + //@{ + + /// compute L1 (Manhattan) norm + inline Scalar l1_norm() const + { +#if DIM==N + Scalar s(0); +#define expr(i) s += abs(Base::values_[i]); + unroll(expr); +#undef expr + return s; +#else +#define expr(i) abs(Base::values_[i]) + return (unroll_comb(expr, +)); +#undef expr +#endif + } + + //@} //------------------------------------------------------------ max, min, mean + /// \name Minimum maximum and mean + //@{ + /// return the maximal component inline Scalar max() const { @@ -450,6 +476,17 @@ public: return m; } + /// return the maximal absolute component + inline Scalar max_abs() const + { + Scalar m(abs(Base::values_[0])); + for(int i=1; im) + m=abs(Base::values_[i]); + return m; + } + + /// return the minimal component inline Scalar min() const { @@ -458,6 +495,16 @@ public: return m; } + /// return the minimal absolute component + inline Scalar min_abs() const + { + Scalar m(abs(Base::values_[0])); + for(int i=1; i Base::values_[i]) Base::values_[i] = _rhs[i]; @@ -481,6 +545,15 @@ public: return *this; } + /// maximize values and signalize coordinate maximization + inline bool maximized(const vector_type& _rhs) { + bool result(false); +#define expr(i) if (_rhs[i] > Base::values_[i]) { Base::values_[i] =_rhs[i]; result = true; } + unroll(expr); +#undef expr + return result; + } + /// component-wise min inline vector_type min(const vector_type& _rhs) { return vector_type(*this).minimize(_rhs); @@ -491,8 +564,7 @@ public: return vector_type(*this).maximize(_rhs); } - - + //@} //------------------------------------------------------------ misc functions