* mln/algebra/vec.hh (mln::algebra::vec<n, T>::normalize):
Use mln::norm::l2 instead of ad hoc code.
---
milena/ChangeLog | 7 +++++++
milena/mln/algebra/vec.hh | 30 +++++++++++++++++++++++-------
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0f3bc29..fae6012 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2008-12-30 Roland Levillain <roland(a)lrde.epita.fr>
+ Simplify the normalization of vectors.
+
+ * mln/algebra/vec.hh (mln::algebra::vec<n, T>::normalize):
+ Use mln::norm::l2 instead of ad hoc code.
+
+2008-12-30 Roland Levillain <roland(a)lrde.epita.fr>
+
More complex-related aliases.
* mln/core/alias/complex_geometry.hh
diff --git a/milena/mln/algebra/vec.hh b/milena/mln/algebra/vec.hh
index 2a61693..1434930 100644
--- a/milena/mln/algebra/vec.hh
+++ b/milena/mln/algebra/vec.hh
@@ -39,6 +39,7 @@
# include <mln/core/concept/object.hh>
# include <mln/literal/zero.hh>
+# include <mln/norm/l2.hh>
# include <mln/trait/all.hh>
# include <mln/trait/value_.hh>
# include <mln/fun/i2v/all_to.hh>
@@ -64,7 +65,10 @@ namespace mln
struct zero_t;
}
-
+ namespace norm {
+ template <unsigned n, typename C>
+ mln_sum(C) l2(const algebra::vec<n,C>& vec);
+ }
namespace trait
@@ -211,6 +215,18 @@ namespace mln
unsigned size() const;
+ /* FIXME: What if the vector is null? Even if we choose not to
+ handle this case, we should *state* in the documentation the
+ behavior of this method.
+
+ I (Roland) have added an assertion to detect ``erroneous''
+ cases, but we might want something different.
+ ``Implementation defined'' or ``undefined behavior'' is fine
+ by me, as long as the documentation mentions it.
+
+ FWIW, Trimesh's developers chose to set all the coordinates
+ of a vector being normalized to 1, when it norm is equal or
+ lower (sic) to zero. */
const vec<n, T>& normalize();
/// Constructor; coordinates are set by function \p f.
@@ -306,7 +322,8 @@ namespace mln
operator-(const vec<n,T>& lhs, const vec<n,U>& rhs);
// vec * vec
-
+
+ /// Scalar product (dot product).
template <unsigned n, typename T, typename U>
mln_sum_x(T,U)
operator*(const vec<n,T>& lhs, const vec<n,U>& rhs);
@@ -331,6 +348,7 @@ namespace mln
// vprod // FIXME: Generalize...
+ /// Vectorial product (cross product).
template <typename T, typename U>
vec<3, mln_trait_op_times(T,U)> // FIXME: Sum of product...
vprod(const vec<3, T>& lhs, const vec<3, U>& rhs);
@@ -431,12 +449,10 @@ namespace mln
inline
const vec<n, T>& vec<n, T>::normalize()
{
- float n_l2 = 0;
- for (unsigned i = 0; i < n; ++i)
- n_l2 += data_[i] * data_[i];
- n_l2 = float(std::sqrt(n_l2));
+ float l2_norm = float(norm::l2(*this));
+ mln_assertion(l2_norm > 0.f);
for (unsigned i = 0; i < n; ++i)
- data_[i] = static_cast<T>(data_[i] / n_l2);
+ data_[i] = static_cast<T>(data_[i] / l2_norm);
return *this;
}
--
1.6.0.4
* mln/core/alias/complex_geometry.hh
(mln::discrete_plane_2complex_geometry)
* mln/core/alias/complex_image.hh
(mln::int_u8_2complex_image2d):
New typedefs.
Typos & aesthetic changes.
---
milena/ChangeLog | 11 +++++++++++
milena/mln/core/alias/complex_geometry.hh | 7 ++++++-
milena/mln/core/alias/complex_image.hh | 20 ++++++++++++++++++--
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index aa168d3..0f3bc29 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,16 @@
2008-12-30 Roland Levillain <roland(a)lrde.epita.fr>
+ More complex-related aliases.
+
+ * mln/core/alias/complex_geometry.hh
+ (mln::discrete_plane_2complex_geometry)
+ * mln/core/alias/complex_image.hh
+ (mln::int_u8_2complex_image2d):
+ New typedefs.
+ Typos & aesthetic changes.
+
+2008-12-30 Roland Levillain <roland(a)lrde.epita.fr>
+
Clean up apps/statues/ a bit.
* apps/statues/mesh-max-curv.cc, apps/statues/mesh-pinv-curv.cc,
diff --git a/milena/mln/core/alias/complex_geometry.hh b/milena/mln/core/alias/complex_geometry.hh
index d4e3a75..44fa899 100644
--- a/milena/mln/core/alias/complex_geometry.hh
+++ b/milena/mln/core/alias/complex_geometry.hh
@@ -40,8 +40,13 @@ namespace mln
{
/// \brief Type alias for the geometry of a 2-complex located in a
+ /// discrete 2-dimensional plane (with integer coordinates).
+ typedef mln::geom::complex_geometry<2, point2d>
+ discrete_plane_2complex_geometry;
+
+ /// \brief Type alias for the geometry of a 2-complex located in a
/// 3-dimensional space (with floating-point coordinates).
- typedef mln::geom::complex_geometry<2,point3df> space_2complex_geometry;
+ typedef mln::geom::complex_geometry<2, point3df> space_2complex_geometry;
} // end of namespace mln
diff --git a/milena/mln/core/alias/complex_image.hh b/milena/mln/core/alias/complex_image.hh
index 6336d6b..0d8e379 100644
--- a/milena/mln/core/alias/complex_image.hh
+++ b/milena/mln/core/alias/complex_image.hh
@@ -40,6 +40,22 @@
namespace mln
{
+ /*------------------------------.
+ | 2-d plane 2-complex aliases. |
+ `------------------------------*/
+
+ /// \brief Type alias for an 8-bit gray-level image based on a
+ /// 2-complex, where 0-faces are located at discrete (integer)
+ /// 2-dimensional points.
+ typedef
+ mln::complex_image<2, mln::discrete_plane_2complex_geometry,
+ mln::value::int_u8>
+ int_u8_2complex_image2d;
+
+
+ /*------------------------------.
+ | 3-d space 2-complex aliases. |
+ `------------------------------*/
/// \brief Type alias for a binary image based on a 2-complex, where
/// 0-faces are located at floating-point 3-dimensional points.
@@ -47,14 +63,14 @@ namespace mln
mln::complex_image<2, mln::space_2complex_geometry, bool>
bin_2complex_image3df;
- /// \brief Type alias for an 8-bit grey-level image based on a
+ /// \brief Type alias for an 8-bit gray-level image based on a
/// 2-complex, where 0-faces are located at floating-point
/// 3-dimensional points.
typedef
mln::complex_image<2, mln::space_2complex_geometry, mln::value::int_u8>
int_u8_2complex_image3df;
- /// \brief Type alias for a grey-level image based on a 2-complex,
+ /// \brief Type alias for a gray-level image based on a 2-complex,
/// where 0-faces are located at floating-point 3-dimensional
/// points.
typedef
--
1.6.0.4