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
This commit is contained in:
@@ -416,7 +416,6 @@ public:
|
|||||||
#undef expr
|
#undef expr
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
//@}
|
|
||||||
|
|
||||||
/** normalize vector, return normalized vector
|
/** normalize vector, return normalized vector
|
||||||
*/
|
*/
|
||||||
@@ -439,9 +438,36 @@ public:
|
|||||||
return *this;
|
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
|
//------------------------------------------------------------ max, min, mean
|
||||||
|
|
||||||
|
/// \name Minimum maximum and mean
|
||||||
|
//@{
|
||||||
|
|
||||||
/// return the maximal component
|
/// return the maximal component
|
||||||
inline Scalar max() const
|
inline Scalar max() const
|
||||||
{
|
{
|
||||||
@@ -450,6 +476,17 @@ public:
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return the maximal absolute component
|
||||||
|
inline Scalar max_abs() const
|
||||||
|
{
|
||||||
|
Scalar m(abs(Base::values_[0]));
|
||||||
|
for(int i=1; i<DIM; ++i)
|
||||||
|
if(abs(Base::values_[i])>m)
|
||||||
|
m=abs(Base::values_[i]);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// return the minimal component
|
/// return the minimal component
|
||||||
inline Scalar min() const
|
inline Scalar min() const
|
||||||
{
|
{
|
||||||
@@ -458,6 +495,16 @@ public:
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return the minimal absolute component
|
||||||
|
inline Scalar min_abs() const
|
||||||
|
{
|
||||||
|
Scalar m(abs(Base::values_[0]));
|
||||||
|
for(int i=1; i<DIM; ++i)
|
||||||
|
if(abs(Base::values_[i])<m)
|
||||||
|
m=abs(Base::values_[i]);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
/// return arithmetic mean
|
/// return arithmetic mean
|
||||||
inline Scalar mean() const {
|
inline Scalar mean() const {
|
||||||
Scalar m(Base::values_[0]);
|
Scalar m(Base::values_[0]);
|
||||||
@@ -465,6 +512,14 @@ public:
|
|||||||
return m/Scalar(DIM);
|
return m/Scalar(DIM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return absolute arithmetic mean
|
||||||
|
inline Scalar mean_abs() const {
|
||||||
|
Scalar m(abs(Base::values_[0]));
|
||||||
|
for(int i=1; i<DIM; ++i) m+=abs(Base::values_[i]);
|
||||||
|
return m/Scalar(DIM);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// minimize values: same as *this = min(*this, _rhs), but faster
|
/// minimize values: same as *this = min(*this, _rhs), but faster
|
||||||
inline vector_type minimize(const vector_type& _rhs) {
|
inline vector_type minimize(const vector_type& _rhs) {
|
||||||
#define expr(i) if (_rhs[i] < Base::values_[i]) Base::values_[i] = _rhs[i];
|
#define expr(i) if (_rhs[i] < Base::values_[i]) Base::values_[i] = _rhs[i];
|
||||||
@@ -473,6 +528,15 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// minimize values and signalize coordinate minimization
|
||||||
|
inline bool minimized(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;
|
||||||
|
}
|
||||||
|
|
||||||
/// maximize values: same as *this = max(*this, _rhs), but faster
|
/// maximize values: same as *this = max(*this, _rhs), but faster
|
||||||
inline vector_type maximize(const vector_type& _rhs) {
|
inline vector_type maximize(const vector_type& _rhs) {
|
||||||
#define expr(i) if (_rhs[i] > Base::values_[i]) Base::values_[i] = _rhs[i];
|
#define expr(i) if (_rhs[i] > Base::values_[i]) Base::values_[i] = _rhs[i];
|
||||||
@@ -481,6 +545,15 @@ public:
|
|||||||
return *this;
|
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
|
/// component-wise min
|
||||||
inline vector_type min(const vector_type& _rhs) {
|
inline vector_type min(const vector_type& _rhs) {
|
||||||
return vector_type(*this).minimize(_rhs);
|
return vector_type(*this).minimize(_rhs);
|
||||||
@@ -491,8 +564,7 @@ public:
|
|||||||
return vector_type(*this).maximize(_rhs);
|
return vector_type(*this).maximize(_rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------ misc functions
|
//------------------------------------------------------------ misc functions
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user