Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
October 2007
- 8 participants
- 229 discussions
11 Oct '07
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update some classes with literals and precise int_u equiv.
* mln/literal/ops.hh: New.
* mln/literal/one.hh: New.
* mln/literal/all.hh: New.
* mln/value/int_u.hh: Update so that the equivalent type
really is 'unsigned'.
* mln/debug/all.hh: Clean-up.
* mln/core/point.hh,
* mln/core/window.hh,
* mln/core/neighb.hh,
* mln/core/dpoint.hh: New ctor overloads for coordinates.
* mln/core/ops.hh (operator+, operator*): New overloads for
unsigned.
(operator++, operator--): New FIXMEs.
* mln/core/concept/function.hh: New categories for sub-concepts
of Function.
* mln/core/concept/window.hh,
* mln/metal/vec.hh,
* mln/value/cast.hh,
* mln/value/internal/value_like.hh,
* mln/make/w_window.hh,
* mln/test/positive.hh,
* mln/convert/to_image.hh,
* mln/convert/to_std_set.hh,
* mln/convert/to_window.hh,
* mln/convert/to_dpoint.hh,
* mln/convert/to_w_window.hh,
* mln/geom/bbox.hh,
* mln/geom/shift.hh,
* mln/fun/v2v/saturate.hh,
* mln/win/octagon2d.hh,
* mln/morpho/hit_or_miss.hh,
* mln/norm/infty.hh,
* mln/norm/l2.hh,
* tests/window1d.cc,
* tests/morpho_dilation_max_h.cc,
* tests/morpho_erosion_min_h.cc,
* tests/dpoint2d.cc,
* tests/literal_zero.cc,
* tests/labeling_foreground.cc,
* tests/point1d.cc,
* tests/window2d.cc,
* tests/labeling_estimate.cc,
* tests/dpoint1d.cc,
* tests/dpoint3d.cc,
* tests/value_int_u8.cc,
* tests/point2d.cc: Update.
* TODO: Clear.
TODO | 9 +--
mln/convert/to_dpoint.hh | 2
mln/convert/to_image.hh | 4 -
mln/convert/to_std_set.hh | 4 -
mln/convert/to_w_window.hh | 2
mln/convert/to_window.hh | 12 ++---
mln/core/concept/function.hh | 41 +++++++++++++++++
mln/core/concept/window.hh | 4 -
mln/core/dpoint.hh | 65 +++++++++++++++++++++++-----
mln/core/neighb.hh | 44 ++++++++++++++++++-
mln/core/ops.hh | 20 ++++++++
mln/core/point.hh | 37 ++++++++++++++--
mln/core/window.hh | 42 ++++++++++++++++++
mln/debug/all.hh | 6 +-
mln/fun/v2v/saturate.hh | 12 +++--
mln/geom/bbox.hh | 2
mln/geom/shift.hh | 2
mln/literal/all.hh | 58 +++++++++++++++++++++++++
mln/literal/one.hh | 76 +++++++++++++++++++++++++++++++++
mln/literal/ops.hh | 89 +++++++++++++++++++++++++++++++++++++++
mln/make/w_window.hh | 4 -
mln/metal/vec.hh | 17 +++++--
mln/morpho/hit_or_miss.hh | 3 +
mln/norm/infty.hh | 27 +++++++++--
mln/norm/l2.hh | 3 +
mln/test/positive.hh | 7 ++-
mln/value/cast.hh | 2
mln/value/int_u.hh | 70 ++++++++++++++++++++++++++++--
mln/value/internal/value_like.hh | 2
mln/win/octagon2d.hh | 33 +++++++-------
tests/dpoint1d.cc | 4 -
tests/dpoint2d.cc | 4 -
tests/dpoint3d.cc | 4 -
tests/labeling_estimate.cc | 3 -
tests/labeling_foreground.cc | 2
tests/literal_zero.cc | 11 ++++
tests/morpho_dilation_max_h.cc | 2
tests/morpho_erosion_min_h.cc | 2
tests/point1d.cc | 3 +
tests/point2d.cc | 7 +++
tests/value_int_u8.cc | 7 ++-
tests/window1d.cc | 6 +-
tests/window2d.cc | 4 -
43 files changed, 661 insertions(+), 97 deletions(-)
Index: tests/window1d.cc
--- tests/window1d.cc (revision 1303)
+++ tests/window1d.cc (working copy)
@@ -46,8 +46,10 @@
mln_assertion(w.is_centered() = false);
mln_assertion(w.is_symmetric() = true);
- w.insert(make::dpoint1d(-1));
- w.insert(make::dpoint1d( 1));
+ // w.insert(-1,0); // Do not compile as expected.
+
+ w.insert(-1);
+ w.insert( 1);
image1d<bool> ima = convert::to_image(w);
debug::println(ima);
Index: tests/morpho_dilation_max_h.cc
--- tests/morpho_dilation_max_h.cc (revision 1303)
+++ tests/morpho_dilation_max_h.cc (working copy)
@@ -55,7 +55,7 @@
image2d<int_u8> lena = io::pgm::load("../img/lena.pgm");
{
- vec_p<point2d> vec = convert::to_vec_p(rec, point2d::zero);
+ vec_p<point2d> vec = convert::to_vec_p(rec, point2d::origin);
window2d win = convert::to_window(vec);
image2d<int_u8> out(lena.domain());
Index: tests/morpho_erosion_min_h.cc
--- tests/morpho_erosion_min_h.cc (revision 1303)
+++ tests/morpho_erosion_min_h.cc (working copy)
@@ -55,7 +55,7 @@
image2d<int_u8> lena = io::pgm::load("../img/lena.pgm");
{
- vec_p<point2d> vec = convert::to_vec_p(rec, point2d::zero);
+ vec_p<point2d> vec = convert::to_vec_p(rec, point2d::origin);
window2d win = convert::to_window(vec);
image2d<int_u8> out(lena.domain());
Index: tests/dpoint2d.cc
--- tests/dpoint2d.cc (revision 1303)
+++ tests/dpoint2d.cc (working copy)
@@ -48,8 +48,8 @@
mln_assertion(dp = q - p);
mln_assertion(q = p + dp);
- const int (&vec)[2] = dp.to_vec();
- mln_assertion(vec[0] = 3);
+ metal::vec<2, float> v = dp;
+ mln_assertion(v[0] / 2 = 1.5);
p += dp;
mln_assertion(q = p);
Index: tests/literal_zero.cc
--- tests/literal_zero.cc (revision 1303)
+++ tests/literal_zero.cc (working copy)
@@ -31,6 +31,9 @@
*/
#include <mln/literal/zero.hh>
+#include <mln/literal/one.hh>
+#include <mln/literal/ops.hh>
+#include <mln/value/int_u8.hh>
int main()
@@ -39,7 +42,15 @@
unsigned char c;
c = literal::zero;
+ mln_assertion(c = 0);
double d;
d = literal::zero;
+ mln_assertion(d = 0);
+
+ mln_assertion(literal::zero != literal::one);
+
+ value::int_u8 u(literal::zero), uu;
+ uu = literal::zero;
+ mln_assertion(u = 0);
}
Index: tests/labeling_foreground.cc
--- tests/labeling_foreground.cc (revision 1303)
+++ tests/labeling_foreground.cc (working copy)
@@ -50,7 +50,7 @@
out(lena.domain());
unsigned n;
- labeling::foreground((pw::value(lena) > pw::cst(127)) | lena.domain(),
+ labeling::foreground((pw::value(lena) > pw::cst(127u)) | lena.domain(),
c4(), out, n);
io::pgm::save(out, "out.pgm");
mln_assertion(n = 14);
Index: tests/point1d.cc
--- tests/point1d.cc (revision 1303)
+++ tests/point1d.cc (working copy)
@@ -43,6 +43,9 @@
// assignment
p[0] = 4;
+ metal::vec<1,int> v = p;
+ std::cout << v << std::endl;
+
p.ind() += 1;
mln_assertion(p.ind() = 5 && p[0] = 5);
Index: tests/window2d.cc
--- tests/window2d.cc (revision 1303)
+++ tests/window2d.cc (working copy)
@@ -46,8 +46,8 @@
mln_assertion(w.is_centered() = false);
mln_assertion(w.is_symmetric() = true);
- w.insert(make::dpoint2d(-1,-1));
- w.insert(make::dpoint2d( 1, 1));
+ w .insert(-1,-1)
+ .insert( 1, 1);
image2d<bool> ima = convert::to_image(w);
debug::println(ima);
Index: tests/labeling_estimate.cc
--- tests/labeling_estimate.cc (revision 1303)
+++ tests/labeling_estimate.cc (working copy)
@@ -49,8 +49,9 @@
image2d<int_u8> lena = io::pgm::load("../img/tiny.pgm"),
out(lena.domain());
+ // FIXME: Below, 127u (instead of 127) is mandatory to avoid a warning...
unsigned n;
- labeling::foreground((pw::value(lena) > pw::cst(127)) | lena.domain(),
+ labeling::foreground((pw::value(lena) > pw::cst(127u)) | lena.domain(),
c4(), out, n);
mln_assertion(n = 14);
Index: tests/dpoint1d.cc
--- tests/dpoint1d.cc (revision 1303)
+++ tests/dpoint1d.cc (working copy)
@@ -48,6 +48,6 @@
mln_assertion(dp = q - p);
mln_assertion(q = p + dp);
- const int (&vec)[1] = dp.to_vec();
- mln_assertion(vec[0] = 3);
+ metal::vec<1, float> v = dp;
+ mln_assertion(v[0] = 3);
}
Index: tests/dpoint3d.cc
--- tests/dpoint3d.cc (revision 1303)
+++ tests/dpoint3d.cc (working copy)
@@ -48,6 +48,6 @@
mln_assertion(dp = q - p);
mln_assertion(q = p + dp);
- const int (&vec)[3] = dp.to_vec();
- mln_assertion(vec[1] = 6);
+ metal::vec<3, float> v = dp;
+ mln_assertion(v[1] = 6);
}
Index: tests/value_int_u8.cc
--- tests/value_int_u8.cc (revision 1303)
+++ tests/value_int_u8.cc (working copy)
@@ -154,7 +154,12 @@
--i;
mln_assertion(i = 234);
- mln_assertion(-i = -234);
+ std::cout << (-i) << " FIXME Matthieu: add .f to literals " << i << std::endl;
+ mln_assertion(-i = -234); // FIXME: old version
+ mln_assertion(-i = -234.f); // FIXME: new better version
+
+ mln_assertion(i * -2 != 0.f);
+ std::cout << (i) << " " << (i * -2) << " " << (-2 * int(i)) << std::endl;
}
// Multiplication
Index: tests/point2d.cc
--- tests/point2d.cc (revision 1303)
+++ tests/point2d.cc (working copy)
@@ -32,6 +32,7 @@
#include <iostream>
#include <mln/core/point2d.hh>
+#include <mln/literal/all.hh>
@@ -62,6 +63,12 @@
point2d q_(5, 1);
mln_assertion(q_ = q);
}
+ {
+ point2d O(0,0);
+ point2d O_ = literal::zero;
+ mln_assertion(O_ = O);
+ mln_assertion(O = literal::zero);
+ }
q.set_all(0);
for (unsigned i = 0; i < p.dim; ++i)
Index: TODO
--- TODO (revision 1303)
+++ TODO (working copy)
@@ -55,14 +55,11 @@
*** type
-value::proxy to dispatch read/write + the corresponding image type
-a mean_value object { sum; count } and operator+
+...
*** other
-in Fast_Image: memcpy and memset-like methods (?)
-.offset() into GenPixel
-built-in op objects -> reverse lhs/rhs
+...
** rename
@@ -70,7 +67,7 @@
** clean-up
-select_function in fun::internal::selector_p2? etc.
+...
** processing routines
Index: mln/debug/all.hh
--- mln/debug/all.hh (revision 1303)
+++ mln/debug/all.hh (working copy)
@@ -37,14 +37,16 @@
namespace mln
{
- /*! Namespace of routines that help to debug.
- */
+ /// Namespace of routines that help to debug.
namespace debug {}
}
+# include <mln/debug/format.hh>
+# include <mln/debug/iota.hh>
# include <mln/debug/println.hh>
+# include <mln/debug/println_with_border.hh>
#endif // ! MLN_DEBUG_ALL_HH
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1303)
+++ mln/core/point.hh (working copy)
@@ -39,14 +39,20 @@
# include <mln/metal/bool.hh>
# include <mln/metal/vec.hh>
+# include <mln/metal/converts_to.hh>
# include <mln/core/h_vec.hh>
namespace mln
{
- // fwd decl
+ /// \{ Fwd decls.
template <typename M, typename C> struct dpoint_;
+ namespace literal {
+ struct zero_t;
+ struct one_t;
+ }
+ /// \}
namespace internal
@@ -102,13 +108,18 @@
/// Constructor without argument.
point_();
- /// \{ Constructors with different numbers of argument w.r.t. the
- /// dimension.
+ /// \{ Constructors with different numbers of arguments
+ /// (coordinates) w.r.t. the dimension.
point_(C ind);
point_(C row, C col);
point_(C sli, C row, C col);
/// \}
+ /// \{ Constructors with literals.
+ point_(const literal::zero_t&);
+ point_(const literal::one_t&); // Works only in 1D.
+ /// \}
+
/// Constructor; coordinates are set by function \p f.
template <typename F>
point_(const Function_i2v<F>& f);
@@ -117,7 +128,7 @@
void set_all(C c);
/// Origin point (all coordinates are 0).
- static const point_<M,C> zero;
+ static const point_<M,C> origin;
/// Shifting by \p dp.
point_<M,C>& operator+=(const dpoint& dp);
@@ -156,6 +167,8 @@
return this->coord_[i];
}
+ // Constructors.
+
template <typename M, typename C>
point_<M,C>::point_()
{
@@ -189,19 +202,33 @@
template <typename F>
point_<M,C>::point_(const Function_i2v<F>& f_)
{
+ mlc_converts_to(mln_result(F), C)::check();
const F& f = exact(f_);
for (unsigned i = 0; i < dim; ++i)
coord_[i] = f(i);
}
template <typename M, typename C>
+ point_<M,C>::point_(const literal::zero_t&)
+ {
+ coord_.set_all(0);
+ }
+
+ template <typename M, typename C>
+ point_<M,C>::point_(const literal::one_t&)
+ {
+ metal::bool_<(dim = 1)>::check();
+ coord_[0] = 1;
+ }
+
+ template <typename M, typename C>
void point_<M,C>::set_all(C c)
{
coord_.set_all(c);
}
template <typename M, typename C>
- const point_<M,C> point_<M,C>::zero = all(0);
+ const point_<M,C> point_<M,C>::origin = all(0);
template <typename M, typename C>
point_<M,C>&
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1303)
+++ mln/core/window.hh (working copy)
@@ -31,6 +31,9 @@
/*! \file mln/core/window.hh
*
* \brief Definition of the generic window class mln::window.
+ *
+ * \todo Make naming coherent: we have window (without '_') but
+ * point_, neighb_, etc.
*/
# include <mln/core/concept/window.hh>
@@ -89,6 +92,18 @@
/// Insert a delta-point \p dp.
window<D>& insert(const D& dp);
+ /// \{ Insertion of a delta-point with different numbers of
+ /// arguments (coordinates) w.r.t. the dimension.
+ window<D>& insert(const mln_coord(D)& dind); // For 1D.
+
+ window<D>& insert(const mln_coord(D)& drow,
+ const mln_coord(D)& dcol); // For 2D.
+
+ window<D>& insert(const mln_coord(D)& dsli,
+ const mln_coord(D)& drow,
+ const mln_coord(D)& dcol); // For 3D.
+ /// \}
+
/// Apply a central symmetry to the target window.
window<D>& sym();
@@ -137,6 +152,33 @@
template <typename D>
window<D>&
+ window<D>::insert(const mln_coord(D)& dind)
+ {
+ D dp(dind);
+ mln_precondition(! has(dp));
+ return this->insert(dp);
+ }
+
+ template <typename D>
+ window<D>&
+ window<D>::insert(const mln_coord(D)& drow, const mln_coord(D)& dcol)
+ {
+ D dp(drow, dcol);
+ mln_precondition(! has(dp));
+ return this->insert(dp);
+ }
+
+ template <typename D>
+ window<D>&
+ window<D>::insert(const mln_coord(D)& dsli, const mln_coord(D)& drow, const mln_coord(D)& dcol)
+ {
+ D dp(dsli, drow, dcol);
+ mln_precondition(! has(dp));
+ return this->insert(dp);
+ }
+
+ template <typename D>
+ window<D>&
window<D>::sym()
{
window<D> tmp;
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 1303)
+++ mln/core/neighb.hh (working copy)
@@ -91,7 +91,19 @@
* in the neighborhood definition; thus the client has not to
* ensure the symmetry property; that is automatic.
*/
- void insert(const D& dp);
+ neighb_<D>& insert(const D& dp);
+
+ /// \{ Insertion of a delta-point with different numbers of
+ /// arguments (coordinates) w.r.t. the dimension.
+ neighb_<D>& insert(const mln_coord(D)& dind); // For 1D.
+
+ neighb_<D>& insert(const mln_coord(D)& drow,
+ const mln_coord(D)& dcol); // For 2D.
+
+ neighb_<D>& insert(const mln_coord(D)& dsli,
+ const mln_coord(D)& drow,
+ const mln_coord(D)& dcol); // For 3D.
+ /// \}
};
@@ -103,14 +115,42 @@
}
template <typename D>
- void
+ neighb_<D>&
neighb_<D>::insert(const D& dp)
{
+ mln_precondition(! has(dp));
typedef internal::set_of_<D> super;
this->super::insert( dp);
this->super::insert(-dp);
+ return *this;
+ }
+
+ template <typename D>
+ neighb_<D>&
+ neighb_<D>::insert(const mln_coord(D)& dind)
+ {
+ D dp(dind);
+ mln_precondition(! has(dp));
+ return this->insert(dp);
+ }
+
+ template <typename D>
+ neighb_<D>&
+ neighb_<D>::insert(const mln_coord(D)& drow, const mln_coord(D)& dcol)
+ {
+ D dp(drow, dcol);
+ mln_precondition(! has(dp));
+ return this->insert(dp);
}
+ template <typename D>
+ neighb_<D>&
+ neighb_<D>::insert(const mln_coord(D)& dsli, const mln_coord(D)& drow, const mln_coord(D)& dcol)
+ {
+ D dp(dsli, drow, dcol);
+ mln_precondition(! has(dp));
+ return this->insert(dp);
+ }
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/ops.hh
--- mln/core/ops.hh (revision 1303)
+++ mln/core/ops.hh (working copy)
@@ -41,6 +41,7 @@
namespace mln
{
+
/*! \brief General definition of the "not equal to" operator.
*
* The "not equal to" operator is here defined for every milena
@@ -135,6 +136,14 @@
// FIXME: Doc!
template <typename O>
+ mln_trait_op_plus(O, unsigned)
+ operator+(unsigned lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
mln_trait_op_plus(O, float)
operator+(float lhs, const Object<O>& rhs)
{
@@ -154,6 +163,14 @@
// FIXME: Doc!
template <typename O>
+ mln_trait_op_times(O, unsigned)
+ operator*(unsigned lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) * lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
mln_trait_op_times(O, int)
operator*(int lhs, const Object<O>& rhs)
{
@@ -177,6 +194,7 @@
}
+
# ifndef MLN_INCLUDE_ONLY
template <typename O>
@@ -184,6 +202,7 @@
{
O tmp(exact(rhs)); // Copy.
++exact(rhs); // Pre-inc.
+ // FIXME: Activate: mln_postcondition(exact(rhs) = tmp + literal::one);
return tmp;
}
@@ -192,6 +211,7 @@
{
O tmp(exact(rhs)); // Copy.
--exact(rhs); // Pre-dec.
+ // FIXME: Activate: mln_postcondition(exact(rhs) = tmp - literal::one);
return tmp;
}
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1303)
+++ mln/core/dpoint.hh (working copy)
@@ -36,13 +36,20 @@
# include <mln/core/concept/dpoint.hh>
# include <mln/core/internal/coord_impl.hh>
# include <mln/fun/i2v/all.hh>
+# include <mln/metal/vec.hh>
+# include <mln/metal/converts_to.hh>
namespace mln
{
- // fwd decl
+ /// \{ Fwd decls.
template <typename M, typename C> struct point_;
+ namespace literal {
+ struct zero_t;
+ struct one_t;
+ }
+ /// \}
/*! \brief Generic delta-point class.
@@ -84,13 +91,18 @@
/// Constructor without argument.
dpoint_();
- /// \{ Constructors with different numbers of argument w.r.t. the
- /// dimension.
+ /// \{ Constructors with different numbers of arguments
+ /// (coordinates) w.r.t. the dimension.
dpoint_(C ind);
dpoint_(C row, C col);
dpoint_(C sli, C row, C col);
/// \}
+ /// \{ Constructors with literals.
+ dpoint_(const literal::zero_t&);
+ dpoint_(const literal::one_t&); // Works only in 1D.
+ /// \}
+
/// Constructor; coordinates are set by function \p f.
template <typename F>
dpoint_(const Function_i2v<F>& f);
@@ -98,19 +110,18 @@
/// Set all coordinates to the value \p c.
void set_all(C c);
- /// Null delta-point (all coordinates are 0).
+ /// Zero delta-point.
static const dpoint_<M,C> zero;
- const C* coords_() const { return coord_; }
-
- /// Type of the array of coordinates.
- typedef const C (&vec_t)[dim];
+ /// Conversion towards a metal::vec.
+ template <typename Q>
+ operator metal::vec<M::dim, Q>() const;
- /// Hook to coordinates.
- vec_t to_vec() const { return coord_; }
+ /// Explicit conversion.
+ metal::vec<M::dim, C> to_vec() const;
protected:
- C coord_[dim];
+ metal::vec<M::dim, C> coord_;
};
@@ -160,9 +171,23 @@
}
template <typename M, typename C>
+ dpoint_<M,C>::dpoint_(const literal::zero_t&)
+ {
+ coord_.set_all(0);
+ }
+
+ template <typename M, typename C>
+ dpoint_<M,C>::dpoint_(const literal::one_t&)
+ {
+ metal::bool_<(dim = 1)>::check();
+ coord_[0] = 1;
+ }
+
+ template <typename M, typename C>
template <typename F>
dpoint_<M,C>::dpoint_(const Function_i2v<F>& f_)
{
+ mlc_converts_to(mln_result(F), C)::check();
const F& f = exact(f_);
for (unsigned i = 0; i < dim; ++i)
coord_[i] = f(i);
@@ -176,7 +201,23 @@
}
template <typename M, typename C>
- const dpoint_<M,C> dpoint_<M,C>::zero = all(0);
+ const dpoint_<M,C>
+ dpoint_<M,C>::zero = all(0);
+
+ template <typename M, typename C>
+ template <typename Q>
+ dpoint_<M,C>::operator metal::vec<M::dim, Q> () const
+ {
+ return coord_;
+ }
+
+ template <typename M, typename C>
+ metal::vec<M::dim, C>
+ dpoint_<M,C>::to_vec() const
+ {
+ return coord_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1303)
+++ mln/core/concept/function.hh (working copy)
@@ -39,8 +39,19 @@
namespace mln
{
- // Fwd decl.
+ /// \{
+ /// Fwd decls.
template <typename E> struct Function;
+ template <typename E> struct Function_v2v;
+ template <typename E> struct Function_i2v;
+ template <typename E> struct Function_p2v;
+ template <typename E> struct Function_v2b;
+ template <typename E> struct Function_p2b;
+ template <typename E> struct Function_p2p;
+ template <typename E> struct Function_x2x;
+ /// \}
+
+
// Function category flag type.
template <>
@@ -71,11 +82,15 @@
// Value -> Value.
+ template <>
+ struct Function_v2v<void> { typedef Function<void> super; };
+
/// Base class for implementation of function-objects from value to
/// value.
template <typename E>
struct Function_v2v : public Function<E>
{
+ typedef Function_v2v<void> category;
protected:
Function_v2v();
Function_v2v(const Function_v2v&);
@@ -84,11 +99,15 @@
// Index -> Value.
+ template <>
+ struct Function_i2v<void> { typedef Function_v2v<void> super; };
+
/// Base class for implementation of function-objects from index to
/// value.
template <typename E>
struct Function_i2v : public Function_v2v<E>
{
+ typedef Function_i2v<void> category;
protected:
Function_i2v();
Function_i2v(const Function_i2v&);
@@ -97,11 +116,15 @@
// Point -> Value.
+ template <>
+ struct Function_p2v<void> { typedef Function_v2v<void> super; };
+
/// Base class for implementation of function-objects from point to
/// value.
template <typename E>
struct Function_p2v : public virtual Function_v2v<E>
{
+ typedef Function_p2v<void> category;
protected:
Function_p2v();
Function_p2v(const Function_p2v&);
@@ -110,11 +133,15 @@
// Value -> bool.
+ template <>
+ struct Function_v2b<void> { typedef Function_v2v<void> super; };
+
/// Base class for implementation of function-objects from value to
/// bool.
template <typename E>
struct Function_v2b : public virtual Function_v2v<E>
{
+ typedef Function_v2b<void> category;
typedef bool result;
protected:
Function_v2b();
@@ -124,12 +151,16 @@
// Point -> bool.
+ template <>
+ struct Function_p2b<void> { typedef Function_p2v<void> super; }; // FIXME
+
/// Base class for implementation of function-objects from point to
/// bool.
template <typename E>
struct Function_p2b : public Function_p2v<E>,
public Function_v2b<E>
{
+ typedef Function_p2b<void> category;
typedef bool result;
protected:
Function_p2b();
@@ -139,11 +170,15 @@
// Point -> Point.
+ template <>
+ struct Function_p2p<void> { typedef Function_p2v<void> super; }; // FIXME
+
/// Base class for implementation of function-objects from point to
/// point.
template <typename E>
struct Function_p2p : public Function_p2v<E>
{
+ typedef Function_p2p<void> category;
protected:
Function_p2p();
Function_p2p(const Function_p2p&);
@@ -152,11 +187,15 @@
// Vector -> Vector.
+ template <>
+ struct Function_x2x<void> { typedef Function_v2v<void> super; }; // FIXME
+
/// Base class for implementation of function-objects from vector to
/// vector.
template <typename E>
struct Function_x2x : public Function_v2v<E>
{
+ typedef Function_x2x<void> category;
protected:
Function_x2x();
Function_x2x(const Function_x2x&);
Index: mln/core/concept/window.hh
--- mln/core/concept/window.hh (revision 1303)
+++ mln/core/concept/window.hh (working copy)
@@ -123,8 +123,8 @@
// FIXME: Same grid!
typedef mln_point(Wl) P;
- mln_fwd_qiter(Wl) ql(exact(lhs), P::zero);
- mln_fwd_qiter(Wr) qr(exact(rhs), P::zero);
+ mln_fwd_qiter(Wl) ql(exact(lhs), P::origin);
+ mln_fwd_qiter(Wr) qr(exact(rhs), P::origin);
for (ql.start(), qr.start();
ql.is_valid() && qr.is_valid();
Index: mln/literal/ops.hh
--- mln/literal/ops.hh (revision 0)
+++ mln/literal/ops.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_LITERAL_OPS_HH
+# define MLN_LITERAL_OPS_HH
+
+/*! \file mln/literal/ops.hh
+ * \brief Definitions of some operators.
+ */
+
+# include <mln/core/concept/literal.hh>
+
+
+
+namespace mln
+{
+
+ template <typename O, typename L>
+ bool operator=(const Object<O>& lhs, const Literal<L>& rhs);
+
+ template <typename L, typename O>
+ bool operator=(const Literal<L>& lhs, const Object<O>& rhs);
+
+ template <typename L1, typename L2>
+ bool operator=(const Literal<L1>& lhs, const Literal<L2>& rhs);
+
+ template <typename L>
+ bool operator=(const Literal<L>& lhs, const Literal<L>& rhs);
+
+ // FIXME: Add other operators...
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename O, typename L>
+ bool operator=(const Object<O>& lhs, const Literal<L>& rhs)
+ {
+ return exact(lhs) = O(exact(rhs));
+ }
+
+ template <typename L, typename O>
+ bool operator=(const Literal<L>& lhs, const Object<O>& rhs)
+ {
+ return rhs = lhs;
+ }
+
+ template <typename L1, typename L2>
+ bool operator=(const Literal<L1>&, const Literal<L2>&)
+ {
+ return false;
+ }
+
+ template <typename L>
+ bool operator=(const Literal<L>&, const Literal<L>&)
+ {
+ return true;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LITERAL_OPS_HH
Index: mln/literal/one.hh
--- mln/literal/one.hh (revision 0)
+++ mln/literal/one.hh (revision 0)
@@ -0,0 +1,76 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_LITERAL_ONE_HH
+# define MLN_LITERAL_ONE_HH
+
+/*! \file mln/literal/one.hh
+ *
+ * \brief Definition of the literal of mln::one.
+ */
+
+# include <mln/core/concept/literal.hh>
+# include <mln/metal/converts_to.hh>
+
+
+namespace mln
+{
+
+ namespace literal
+ {
+
+ /// Type of literal one.
+ struct one_t : public Literal<one_t>
+ {
+ // FIXME: Cf. comments in literal/zero.hh.
+
+ template <typename T>
+ operator T () const;
+ };
+
+
+ /// Literal one.
+ static one_t one = one_t();
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ one_t::operator T () const
+ {
+ mlc_converts_to(int, T)::check();
+ return 1;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::literal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LITERAL_ONE_HH
Index: mln/literal/all.hh
--- mln/literal/all.hh (revision 0)
+++ mln/literal/all.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_LITERAL_ALL_HH
+# define MLN_LITERAL_ALL_HH
+
+/*! \file mln/literal/all.hh
+ *
+ * \brief File that includes all literals.
+ */
+
+namespace mln
+{
+
+ /// Namespace of literals.
+ namespace literal {}
+
+}
+
+
+# include <mln/literal/zero.hh>
+# include <mln/literal/one.hh>
+
+// FIXME: Add:
+// # include <mln/literal/white.hh>
+// # include <mln/literal/black.hh>
+
+// # include <mln/literal/grays.hh>
+// # include <mln/literal/colors.hh>
+
+# include <mln/literal/ops.hh>
+
+
+#endif // ! MLN_LITERAL_ALL_HH
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1303)
+++ mln/metal/vec.hh (working copy)
@@ -35,7 +35,6 @@
# include <mln/trait/all.hh>
# include <mln/value/props.hh>
# include <mln/fun/i2v/all.hh>
-# include <mln/literal/zero.hh>
# include <mln/value/concept/all.hh>
@@ -45,6 +44,10 @@
namespace mln
{
+ // Fwd decl.
+ namespace literal { struct zero_t; }
+
+
namespace metal
{
@@ -139,7 +142,7 @@
vec();
- vec(mln::literal::zero_t);
+ vec(const literal::zero_t&);
vec(const vec<n, T>& rhs);
@@ -167,6 +170,9 @@
/// Zero value.
static const vec<n, T> zero;
+
+ /// Origin value.
+ static const vec<n, T> origin;
};
} // end of namespace mln::metal
@@ -323,9 +329,9 @@
}
template <unsigned n, typename T>
- vec<n,T>::vec(mln::literal::zero_t)
+ vec<n,T>::vec(const literal::zero_t&)
{
- this->set_all( mln::literal::zero );
+ this->set_all(0);
}
template <unsigned n, typename T>
@@ -416,6 +422,9 @@
template <unsigned n, typename T>
const vec<n, T> vec<n, T>::zero = all(0);
+ template <unsigned n, typename T>
+ const vec<n, T> vec<n, T>::origin = all(0);
+
// eq
Index: mln/value/cast.hh
--- mln/value/cast.hh (revision 1303)
+++ mln/value/cast.hh (working copy)
@@ -61,7 +61,7 @@
}
template <typename T, typename S>
- typename S::equiv
+ typename S::equiv // FIXME: Is-that equiv here?
cast_(const T&, const Value<S>& src)
{
return exact(src);
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1303)
+++ mln/value/int_u.hh (working copy)
@@ -46,8 +46,10 @@
namespace mln
{
- // Fwd decl.
+ /// \{ Fwd decls.
namespace value { template <unsigned n> struct int_u; }
+ namespace literal { struct zero_t; struct one_t; }
+ /// \}
namespace trait
@@ -68,6 +70,18 @@
};
template <unsigned n>
+ struct set_precise_binary_< promote, mln::value::int_u<n>, unsigned >
+ {
+ typedef unsigned ret;
+ };
+
+ template <unsigned n>
+ struct set_precise_binary_< promote, unsigned, mln::value::int_u<n> >
+ {
+ typedef unsigned ret;
+ };
+
+ template <unsigned n>
struct set_precise_binary_< promote, mln::value::int_u<n>, float >
{
typedef float ret;
@@ -119,8 +133,18 @@
/// Constructor from an integer.
int_u(int i);
- /// Conversion to an integer.
- operator int() const;
+ /// \{ Constructors/assignments with literals.
+ int_u(const literal::zero_t&);
+ int_u& operator=(const literal::zero_t&);
+ int_u(const literal::one_t&);
+ int_u& operator=(const literal::one_t&);
+ /// \}
+
+ /// Conversion to an unsigned integer.
+ operator unsigned() const;
+
+ /// Unary operator minus.
+ int operator-() const;
/// Assignment from an integer.
int_u<n>& operator=(int i);
@@ -181,12 +205,47 @@
}
template <unsigned n>
- int_u<n>::operator int() const
+ int_u<n>::int_u(const literal::zero_t&)
+ {
+ this->v_ = 0;
+ }
+
+ template <unsigned n>
+ int_u<n>&
+ int_u<n>::operator=(const literal::zero_t&)
+ {
+ this->v_ = 0;
+ return *this;
+ }
+
+ template <unsigned n>
+ int_u<n>::int_u(const literal::one_t&)
+ {
+ this->v_ = 1;
+ }
+
+ template <unsigned n>
+ int_u<n>&
+ int_u<n>::operator=(const literal::one_t&)
+ {
+ this->v_ = 1;
+ return *this;
+ }
+
+ template <unsigned n>
+ int_u<n>::operator unsigned() const
{
return this->v_;
}
template <unsigned n>
+ int
+ int_u<n>::operator-() const
+ {
+ return - int(this->v_);
+ }
+
+ template <unsigned n>
int_u<n>&
int_u<n>::operator=(int i)
{
@@ -205,7 +264,8 @@
template <unsigned n>
std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i)
{
- return ostr << debug::format(i.to_equiv());
+ // FIXME: This code could be factored for almost every Value<*>...
+ return ostr << debug::format(i.to_equiv()); // FIXME: is to_equiv OK?
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/internal/value_like.hh
--- mln/value/internal/value_like.hh (revision 1303)
+++ mln/value/internal/value_like.hh (working copy)
@@ -123,7 +123,7 @@
N
value_like_<V,C,N,E>::to_interop() const
{
- return mln::internal::force_exact<E>(*this).operator N();
+ return static_cast<N>(mln::internal::force_exact<E>(*this));
}
template <typename V, typename C, typename N, typename E>
Index: mln/make/w_window.hh
--- mln/make/w_window.hh (revision 1303)
+++ mln/make/w_window.hh (working copy)
@@ -69,9 +69,9 @@
typedef mln_dpoint(W) D;
typedef mln_point(D) P;
mln::w_window<D, mln_result(F)> w_win;
- mln_qiter(W) q(win, P::zero);
+ mln_qiter(W) q(win, P::origin);
for_all(q)
- w_win.insert(wei(q), q - P::zero);
+ w_win.insert(wei(q), q - P::origin);
return w_win;
}
Index: mln/test/positive.hh
--- mln/test/positive.hh (revision 1303)
+++ mln/test/positive.hh (working copy)
@@ -36,6 +36,7 @@
# include <mln/test/predicate.hh>
# include <mln/pw/all.hh>
# include <mln/fun/v2v/id.hh>
+# include <mln/literal/zero.hh>
namespace mln
@@ -56,8 +57,12 @@
{
const I& input = exact(input_);
mln_precondition(input.has_data());
+ // FIXME: Below the '>=' op should properly work with signed/unsigned without
+ // FIXME: warnings; so we really need to overload ops for functions when literals
+ // FIXME: are involved.
+ mln_value(I) zero_ = literal::zero;
return test::predicate(input.domain(),
- pw::value(input) >= pw::cst(0));
+ pw::value(input) >= pw::cst(zero_));
// FIXME: test the version below.
// return test::predicate(input,
// fun::v2v::id<mln_value(I)>() >= pw::cst(0));
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 1303)
+++ mln/convert/to_image.hh (working copy)
@@ -147,7 +147,7 @@
box_<P> b = geom::bbox(win);
mln_image_from(W, bool) ima(b);
level::fill(ima, false);
- mln_qiter(W) q(win, P::zero);
+ mln_qiter(W) q(win, P::origin);
for_all(q)
ima(q) = true;
return ima;
@@ -168,7 +168,7 @@
typedef mln_point(W) P;
box_<P> b = geom::bbox(w_win);
mln_image_from(W, mln_weight(W)) ima(b);
- mln_qiter(W) q(w_win, P::zero);
+ mln_qiter(W) q(w_win, P::origin);
for_all(q)
ima(q) = q.w();
return ima;
Index: mln/convert/to_std_set.hh
--- mln/convert/to_std_set.hh (revision 1303)
+++ mln/convert/to_std_set.hh (working copy)
@@ -59,9 +59,9 @@
typedef mln_dpoint(W) D;
typedef mln_point(D) P;
std::set<D> s;
- mln_qiter(W) q(exact(win), P::zero);
+ mln_qiter(W) q(exact(win), P::origin);
for_all(q)
- s.insert(q - P::zero);
+ s.insert(q - P::origin);
return s;
}
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1303)
+++ mln/convert/to_window.hh (working copy)
@@ -79,9 +79,9 @@
typedef mln_dpoint(N) D;
typedef mln_point(D) P;
window<D> win;
- mln_niter(N) n(nbh, P::zero);
+ mln_niter(N) n(nbh, P::origin);
for_all(n)
- win.insert(n - P::zero);
+ win.insert(n - P::origin);
return win;
}
@@ -92,10 +92,10 @@
typedef mln_dpoint(N) D;
typedef mln_point(D) P;
window<D> win;
- mln_niter(N) n(nbh, P::zero);
+ mln_niter(N) n(nbh, P::origin);
for_all(n)
- if (n > P::zero)
- win.insert(n - P::zero);
+ if (n > P::origin)
+ win.insert(n - P::origin);
return win;
}
@@ -111,7 +111,7 @@
mln_piter(I) p(ima.domain());
for_all(p)
if (ima(p))
- win.insert(p - P::zero);
+ win.insert(p - P::origin);
return win;
}
Index: mln/convert/to_dpoint.hh
--- mln/convert/to_dpoint.hh (revision 1303)
+++ mln/convert/to_dpoint.hh (working copy)
@@ -57,7 +57,7 @@
for (unsigned i = 0; i < P::dim; ++i)
dp[i] = p[i];
typedef mln_point(P) P_;
- mln_postcondition(dp = p - P_::zero);
+ mln_postcondition(dp = p - P_::origin);
return dp;
}
Index: mln/convert/to_w_window.hh
--- mln/convert/to_w_window.hh (revision 1303)
+++ mln/convert/to_w_window.hh (working copy)
@@ -62,7 +62,7 @@
mln_piter(I) p(input.domain());
for_all(p)
if (input(p) != 0)
- w_win.insert(input(p), p - P::zero);
+ w_win.insert(input(p), p - P::origin);
return w_win;
}
Index: mln/geom/bbox.hh
--- mln/geom/bbox.hh (revision 1303)
+++ mln/geom/bbox.hh (working copy)
@@ -80,7 +80,7 @@
mln_precondition(! win.is_empty());
typedef mln_point(W) P;
- mln_qiter(W) q(win, P::zero);
+ mln_qiter(W) q(win, P::origin);
std::pair<P, P> pp = geom::pmin_pmax(q);
box_<P> tmp(pp.first, pp.second);
Index: mln/geom/shift.hh
--- mln/geom/shift.hh (revision 1303)
+++ mln/geom/shift.hh (working copy)
@@ -57,7 +57,7 @@
{
typedef mln_point(W) P;
window<mln_dpoint(W)> tmp;
- mln_qiter(W) q(win, P::zero);
+ mln_qiter(W) q(win, P::origin);
for_all(q)
tmp.insert(convert::to_dpoint(q) + dp);
return tmp;
Index: mln/fun/v2v/saturate.hh
--- mln/fun/v2v/saturate.hh (revision 1303)
+++ mln/fun/v2v/saturate.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/function.hh>
+# include <mln/metal/converts_to.hh>
# include <mln/value/props.hh>
@@ -86,11 +87,16 @@
V
saturate<V>::operator()(const W& w) const
{
- if (w < min_)
+ // FIXME: Below we need something more powerful that mlc_converts_to
+ // FIXME: for instance, with W=int_s<10u> and V=int_u<8u>, it does not
+ // FIXME: works cause the cast is not obvious...
+ // mlc_converts_to(W, V)::check();
+ V w_ = mln::value::cast<V>(w);
+ if (w_ < min_)
return min_;
- if (w > max_)
+ if (w_ > max_)
return max_;
- return mln::value::cast<V>(w);
+ return w_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/octagon2d.hh
--- mln/win/octagon2d.hh (revision 1303)
+++ mln/win/octagon2d.hh (working copy)
@@ -48,8 +48,9 @@
/*! \brief Octagon window defined on the 2D square grid.
*
* An octagon2d is centered and symmetrical.
- * The length l of the octagon is such as l = 6*x + 1
- * where 0 <= x.
+ *
+ * The length L of the octagon is such as L = 6 * l + 1
+ * where l >= 0.
*
* For instance: \n
* o o o \n
@@ -59,7 +60,7 @@
* o o o o o o o \n
* o o o o o \n
* o o o \n
- * is defined with length = 7 (x = 0).
+ * is defined with L = 7 (l = 1).
*/
struct octagon2d : public Window< octagon2d >,
public internal::dpoints_base_< dpoint2d, octagon2d >
@@ -144,26 +145,26 @@
const int y = length / 6;
const int x = y * 2;
const int z = y + x;
- insert(dpoint2d::zero);
+ insert(dpoint2d(0, 0));
for (int a = 1; a <= x; ++a)
for (int b = 0; b <= x; ++b)
{
- insert(make::dpoint2d(a, b));
- insert(make::dpoint2d(-b, a));
- insert(make::dpoint2d(b, -a));
- insert(make::dpoint2d(-a, -b));
+ insert(dpoint2d(a, b));
+ insert(dpoint2d(-b, a));
+ insert(dpoint2d(b, -a));
+ insert(dpoint2d(-a, -b));
}
for (int a = x + 1; a <= z; ++a)
for (int b = -2 * x + a; b <= 2 * x - a; ++b)
{
- insert(make::dpoint2d(a, b));
- insert(make::dpoint2d(a, -b));
- insert(make::dpoint2d(-a, b));
- insert(make::dpoint2d(-a, -b));
- insert(make::dpoint2d(b, a));
- insert(make::dpoint2d(b, -a));
- insert(make::dpoint2d(-b, a));
- insert(make::dpoint2d(-b, -a));
+ insert(dpoint2d(a, b));
+ insert(dpoint2d(a, -b));
+ insert(dpoint2d(-a, b));
+ insert(dpoint2d(-a, -b));
+ insert(dpoint2d(b, a));
+ insert(dpoint2d(b, -a));
+ insert(dpoint2d(-b, a));
+ insert(dpoint2d(-b, -a));
}
}
Index: mln/morpho/hit_or_miss.hh
--- mln/morpho/hit_or_miss.hh (revision 1303)
+++ mln/morpho/hit_or_miss.hh (working copy)
@@ -154,6 +154,9 @@
&& pw::value(dil_bg) < pw::value(input),
pw::value(input) - pw::value(dil_bg),
pw::cst(V::zero)));
+
+ // FIXME: Replace 'pw::cst(V::zero)' by 'pw::cst(V(literal::zero))'
+ // FIXME: and then by 'literal::zero'!
}
else if (exact(win_miss).is_centered())
{
Index: mln/norm/infty.hh
--- mln/norm/infty.hh (revision 1303)
+++ mln/norm/infty.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <cmath>
+# include <mln/metal/vec.hh>
namespace mln
@@ -42,9 +43,14 @@
namespace norm
{
- /// Infinity-norm of a vector \p vec.
+ /// Infinity-norm of a vector \p v (being a C static array).
template <unsigned n, typename C>
- C infty(const C (&vec)[n]);
+ C infty(const C (&v)[n]);
+
+ /// Infinity-norm of a vector \p v (being a metal::vec).
+ template <unsigned n, typename C>
+ C infty(const metal::vec<n,C>& v);
+
/// Infinity-norm distance between vectors \p v1 and \p v2.
template <unsigned n, typename C>
@@ -54,12 +60,23 @@
# ifndef MLN_INCLUDE_ONLY
template <unsigned n, typename C>
- C infty(const C (&vec)[n])
+ C infty(const C (&v)[n])
+ {
+ C c = 0;
+ for (unsigned i = 0; i < n; ++i)
+ if (std::abs(v[i]) > c)
+ c = std::abs(v[i]);
+ return c;
+ }
+
+ template <unsigned n, typename C>
+ C infty(const metal::vec<n,C>& v)
{
+ // FIXME: Add a ctor to metal::vec...
C c = 0;
for (unsigned i = 0; i < n; ++i)
- if (std::abs(vec[i]) > c)
- c = std::abs(vec[i]);
+ if (std::abs(v[i]) > c)
+ c = std::abs(v[i]);
return c;
}
Index: mln/norm/l2.hh
--- mln/norm/l2.hh (revision 1303)
+++ mln/norm/l2.hh (working copy)
@@ -57,6 +57,9 @@
template <unsigned n, typename C>
float l2_distance(const metal::vec<n,C>& vec1, const metal::vec<n,C>& vec2);
+ // FIXME: Replace float by mln_value_sum(C)...
+
+
# ifndef MLN_INCLUDE_ONLY
template <unsigned n, typename C>
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Update transformations.
* mln/core/concept/function.hh: Add bijective concept.
* mln/core/h_mat.hh: Add homogen matrix.
* mln/fun/internal/x2x_impl.hh,
* mln/fun/x2x/composed.hh,
* mln/fun/x2x/rotation.hh,
* mln/fun/x2x/translation.hh,
* mln/make/vec.hh,
* tests/fun_x2x_translation.cc: Update.
---
mln/core/concept/function.hh | 24 +++++++++++
mln/core/h_mat.hh | 73 +++++++++++++++++++++++++++++++++
mln/fun/internal/x2x_impl.hh | 16 ++++++-
mln/fun/x2x/composed.hh | 93 +++++++++++++++++++++----------------------
mln/fun/x2x/rotation.hh | 40 ++++++++----------
mln/fun/x2x/translation.hh | 49 ++++++++++++----------
mln/make/vec.hh | 38 +++++++++++++----
tests/fun_x2x_translation.cc | 3 -
8 files changed, 234 insertions(+), 102 deletions(-)
Index: trunk/milena/tests/fun_x2x_translation.cc
===================================================================
--- trunk/milena/tests/fun_x2x_translation.cc (revision 1302)
+++ trunk/milena/tests/fun_x2x_translation.cc (revision 1303)
@@ -33,6 +33,7 @@
#include <iostream>
#include <mln/fun/x2x/translation.hh>
+#include <mln/fun/i2v/all.hh>
@@ -46,7 +47,7 @@
c = 2.9;
metal::vec<3,float> vec1 = make::vec(a, b, c);
- fun::x2x::translation<3,float> tr1(make::vec<3,float>(1.6));
+ fun::x2x::translation<3,float> tr1(make::vec<3, float>(all(1.6)));
std::cout << vec1 << std::endl;
std::cout << tr1(vec1) << std::endl;
Index: trunk/milena/mln/core/h_mat.hh
===================================================================
--- trunk/milena/mln/core/h_mat.hh (revision 0)
+++ trunk/milena/mln/core/h_mat.hh (revision 1303)
@@ -0,0 +1,73 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_H_MAT_HH
+# define MLN_CORE_H_MAT_HH
+
+/*! \file mln/core/h_mat.hh
+ *
+ * \brief Definition of the mln::h_mat alias and of its
+ * construction routine.
+ */
+
+# include <mln/metal/mat.hh>
+
+
+namespace mln
+{
+
+
+ template <unsigned dim, typename T>
+ struct h_mat : public metal::mat<dim+1, dim+1, T>
+ {
+ h_mat();
+
+ h_mat(const metal::mat<dim+1, dim+1, T>& x);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned dim, typename T>
+ h_mat<dim,T>::h_mat()
+ : metal::mat<dim+1, dim+1, T>(metal::mat<dim+1, dim+1, T>::Id)
+ {
+ }
+
+ template <unsigned dim, typename T>
+ h_mat<dim,T>::h_mat(const metal::mat<dim+1, dim+1, T>& x)
+ : metal::mat<dim+1, dim+1, T>(x)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_H_MAT_HH
Index: trunk/milena/mln/core/concept/function.hh
===================================================================
--- trunk/milena/mln/core/concept/function.hh (revision 1302)
+++ trunk/milena/mln/core/concept/function.hh (revision 1303)
@@ -162,6 +162,22 @@
Function_x2x(const Function_x2x&);
};
+ // Vector <-> Vector.
+
+ /// Base class for implementation of bijective function-objects from
+ /// vector to vector.
+ template <typename E>
+ struct Bijection_x2x : public Function_x2x< E >
+ {
+ /*
+ typedef invert;
+ invert inv() const;
+ */
+ protected:
+ Bijection_x2x();
+ };
+
+
# ifndef MLN_INCLUDE_ONLY
@@ -256,6 +272,14 @@
{
}
+ template <typename E>
+ Bijection_x2x<E>::Bijection_x2x()
+ {
+ typedef typename E::invert invert;
+ invert (E::*m)() const = & E::inv;
+ m = 0;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/make/vec.hh
===================================================================
--- trunk/milena/mln/make/vec.hh (revision 1302)
+++ trunk/milena/mln/make/vec.hh (revision 1303)
@@ -26,7 +26,7 @@
// Public License.
#ifndef MLN_MAKE_VEC_HH
-# define MLN_METAL_VEC_HH
+# define MLN_MAKE_VEC_HH
/*! \file mln/make/vec.hh
*
@@ -34,6 +34,7 @@
*/
# include <mln/metal/vec.hh>
+# include <mln/core/concept/function.hh>
namespace mln
{
@@ -44,12 +45,21 @@
/*! \brief Create an mln::metal::vec<n,T>.
*
- * \param[in] v Value.
+ * \param[in] f Function.
*
- * \return A nD vector filled with \p v.
+ * \return A nD vector filled with the function \p f .
*/
- template <unsigned n, typename T>
- metal::vec<n, T> vec(const T& v);
+ template <unsigned n, typename T, typename F>
+ metal::vec<n, T> vec(const Function_i2v<F>& f_);
+
+ /*! \brief Create an mln::metal::vec<n,T>.
+ *
+ * \param[in] v_0 First coordinate.
+ *
+ * \return A 1D vector.
+ */
+ template <typename T>
+ metal::vec<1, T> vec(const T& v_0);
/*! \brief Create an mln::metal::vec<2,T>.
*
@@ -87,12 +97,22 @@
# ifndef MLN_INCLUDE_ONLY
- template <unsigned n, typename T>
- metal::vec<n, T> vec(const T& v)
+ template <unsigned n, typename T, typename F>
+ metal::vec<n, T> vec(const Function_i2v<F>& f_)
{
+ mlc_converts_to(mln_result(F), T)::check();
+ F f = exact(f_);
metal::vec<n, T> tmp;
- for (unsigned i = 0; i < n; ++i)
- tmp[i] = v;
+ for (unsigned i; i < n; ++i)
+ tmp[i] = f(i);
+ return tmp;
+ }
+
+ template <typename T>
+ metal::vec<1, T> vec(const T& v_0)
+ {
+ metal::vec<1, T> tmp;
+ tmp[0] = v_0;
return tmp;
}
Index: trunk/milena/mln/fun/x2x/composed.hh
===================================================================
--- trunk/milena/mln/fun/x2x/composed.hh (revision 1302)
+++ trunk/milena/mln/fun/x2x/composed.hh (revision 1303)
@@ -34,8 +34,9 @@
*/
# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/x2x_impl.hh>
# include <mln/metal/vec.hh>
-# include <mln/metal/mat.hh>
+# include <mln/core/h_mat.hh>
namespace mln
@@ -48,26 +49,26 @@
{
// Fwd decl.
- template <typename L, typename M>
+ template <typename F, typename G>
struct composed;
namespace internal
{
- template <unsigned n, typename L, unsigned m, typename M, typename E>
+ template <typename F, typename G, typename E>
struct helper_;
- template <unsigned n, typename L, typename M, typename E>
- struct helper_<n, Function_x2x<L>, n, Function_x2x<M> > : Function_x2x<E>
+ template <typename F, typename G, typename E>
+ struct helper_<Function_x2x<F>, Function_x2x<G>, E>
+ : Function_x2x<E>
{
- enum {dim = n};
};
- template <unsigned n, typename L, typename M, typename E>
- struct helper_<n, bijective_tr<L>, n, bijective_tr<M> > : bijective_tr<E>
+ template <typename F, typename G, typename E>
+ struct helper_<Bijection_x2x<F>, Bijection_x2x<G>, E >
+ : Bijection_x2x<E>
{
- enum {dim = n};
- typedef composed<M::invert,L::invert> invert;
+ typedef composed<G::invert,F::invert> invert;
invert inv() const;
};
@@ -75,78 +76,78 @@
// FIXME: Doc!
- template <typename L, typename M>
- struct composed : public internal::helper_< L::dim, L, M::dim, M, composed<L,M> >
+ template <typename F, typename G>
+ struct composed
+ : internal::x2x_impl_<F::result, composed<F,G> >,
+ public internal::helper_< F, G, composed<F,G> >,
+ private typename metal::bool<(F::dim == G::dim)>::check_t,
+ private typename metal::is<F::argument, G::result>::check_t
{
- typedef internal::helper_< L::dim, L, M::dim, M, composed<L,M> > Super
-
- enum {dim = Super::dim};
-
- typedef metal::vec<n,C> result;
+ typedef internal::x2x_impl_<F::result, composed<F,G> > super_
composed();
- composed(const L& tr_l, const M& tr_m);
+ composed(const F& f, const G& g);
- result operator()(const metal::vec<n,C>& v) const;
+ using super_:operator();
+ metal::vec<super_::dim,C> operator()(const metal::vec<super_::dim,C>& v) const;
- void set_first(const L& tr_l);
- void set_second(const M& tr_m);
+ void set_first(const F& f);
+ void set_second(const G& g);
protected:
- L tr1_;
- M tr2_;
- metal::mat<n + 1,n + 1,C> m_;
+ F f_;
+ G g_;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename L, typename M>
- composed<L,M>::composed()
+ template <typename F, typename G>
+ composed<F,G>::composed()
{
- t_ = make::vec<n,C>(0);
- m_ = metal::mat<n+1,n+1,C>::Id;
+ m_ = h_mat<n,C>::Id;
}
- template <typename L, typename M>
- composed<L,M>::composed(const L& tr_l, const M& tr_m)
- :tr1_(tr_l),
- tr2_(tr_m)
+ template <typename F, typename G>
+ composed<F,G>::composed(const F& f, const G& g)
+ :f_(f),
+ g_(g)
{
- m_ = metal::mat<n+1,n+1,C>::Id;
- m_ = tr1_ * tr2_;
+ m_ = f_.mat() * g_.mat();
}
- template <typename L, typename M>
- composed<L,M>::result
- composed<L,M>::operator()(const metal::vec<n,C>& v) const
+ template <typename F, typename G>
+ metal::vec<super_::dim,C>
+ composed<F,G>::operator()(const metal::vec<super_::dim,C>& v) const
{
return m_(v);
}
- template <typename L, typename M>
- composed<L,M>::invert
- composed<L,M>::inv() const
+ template <typename F, typename G>
+ composed<F,G>::invert
+ composed<F,G>::inv() const
{
typename composed::invert res(tr2_.inv(), tr1_.inv());
return res;
}
- template <typename L, typename M>
+ template <typename F, typename G>
void
- composed<L,M>::set_first(const L& tr_l)
+ composed<F,G>::set_first(const F& f)
{
- tr1_ = tr_l;
+ f_ = f;
+ m_ = f_.mat() * g_.mat();
}
- template <typename L, typename M>
+ template <typename F, typename G>
void
- composed<L,M>::set_second(const M& tr_m)
+ composed<F,G>::set_second(const G& g)
{
- tr2_ = tr_m;
+ g_ = g;
+ m_ = f_.mat() * g_.mat();
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/fun/x2x/translation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/translation.hh (revision 1302)
+++ trunk/milena/mln/fun/x2x/translation.hh (revision 1303)
@@ -33,10 +33,11 @@
* \brief FIXME.
*/
-# include <mln/fun/x2x/bijective_tr.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/x2x_impl.hh>
# include <mln/metal/vec.hh>
-# include <mln/metal/mat.hh>
-
+# include <mln/core/h_mat.hh>
+# include <mln/fun/i2v/all.hh>
namespace mln
{
@@ -50,26 +51,27 @@
// FIXME: Doc!
template <unsigned n, typename C>
- struct translation : public bijective_tr< translation<n,C> >
+ struct translation
+ : internal::x2x_impl_< metal::vec<n,C>, translation<n,C> >
+ , public Bijection_x2x< translation<n,C> >
{
+ typedef fun::internal::x2x_impl_< metal::vec<n,C>, translation<n,C> > super_;
- enum {dim = n};
-
- typedef metal::vec<n,C> result;
typedef translation<n,C> invert;
+ invert inv() const;
translation();
translation(const metal::vec<n,C>& t);
- result operator()(const metal::vec<n,C>& v) const;
- invert inv() const;
+ using super_::operator();
+ metal::vec<n,C> operator()(const metal::vec<n,C>& v) const;
void set_t(const metal::vec<n,C>& t);
protected:
+ void update();
metal::vec<n,C> t_;
- metal::mat<n + 1,n + 1,C> m_;
};
@@ -78,28 +80,23 @@
template <unsigned n, typename C>
translation<n,C>::translation()
{
- t_ = make::vec<n,C>(0);
- m_ = metal::mat<n+1,n+1,C>::Id;
+ t_ = make::vec<n,C>(fun::i2v::all<C>(0));
+ this->m_ = h_mat<n,C>::Id;
}
template <unsigned n, typename C>
translation<n,C>::translation(const metal::vec<n,C>& t)
:t_(t)
{
- m_ = metal::mat<n+1,n+1,C>::Id;
- for (unsigned i = 0; i < n; ++i)
- m_(i,n) = t_[i];
+ this->m_ = h_mat<n,C>::Id;
+ this->update();
}
template <unsigned n, typename C>
metal::vec<n,C>
translation<n,C>::operator()(const metal::vec<n,C>& v) const
{
- typename translation::result res;
- // FIXME: Why not "res = v + t_;"?
- for (unsigned i = 0; i < n; ++i)
- res[i] = v[i] + t_[i];
- return res;
+ return v + t_;
}
template <unsigned n, typename C>
@@ -115,11 +112,17 @@
void
translation<n,C>::set_t(const metal::vec<n,C>& t)
{
- t_ = t;
- for (unsigned i = 0; i < n; ++i)
- m_(i,n) = t_[i];
+ this->t_ = t;
+ this->update();
}
+ template <unsigned n, typename C>
+ void
+ translation<n,C>::update()
+ {
+ for (unsigned i = 0; i < n; ++i)
+ this->m_(i,n) = this->t_[i];
+ }
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/fun/x2x/rotation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/rotation.hh (revision 1302)
+++ trunk/milena/mln/fun/x2x/rotation.hh (revision 1303)
@@ -33,12 +33,12 @@
* \brief FIXME.
*/
-# include <mln/fun/x2x/bijective_tr.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/x2x_impl.hh>
# include <mln/metal/vec.hh>
# include <mln/metal/mat.hh>
# include <cmath>
-
namespace mln
{
@@ -51,30 +51,29 @@
// FIXME: Doc!
template <unsigned n, typename C>
- struct rotation : public bijective_tr< rotation<n,C> >
+ struct rotation
+ : internal::x2x_impl_< metal::vec<n,C>, rotation<n,C> >
+ , public Bijection_x2x< rotation<n,C> >
{
+ typedef fun::internal::x2x_impl_< metal::vec<n,C>, rotation<n,C> > super_;
- enum {dim = n};
-
- typedef metal::vec<n,C> result;
typedef rotation<n,C> invert;
+ invert inv() const;
rotation();
rotation(float alpha, unsigned dir = 2);
- result operator()(const metal::vec<n,C>& v) const;
- invert inv() const;
+ using super_::operator();
+ metal::vec<n,C> operator()(const metal::vec<n,C>& v) const;
void set_alpha(float alpha);
void set_dir(unsigned dir);
- void update();
-
protected:
+ void update();
float alpha_;
unsigned dir_;
- metal::mat<n + 1,n + 1,C> m_;
};
@@ -83,7 +82,9 @@
template <unsigned n, typename C>
rotation<n,C>::rotation()
{
- m_ = metal::mat<n + 1,n + 1,C>::Id;
+ alpha_ = 0;
+ dir_ = 2;
+ this->m_ = h_mat<n,C>::Id;
}
template <unsigned n, typename C>
@@ -92,6 +93,7 @@
dir_(dir)
{
mln_precondition(dir == 2 || n == 3);
+ this->m_ = h_mat<n,C>::Id;
update();
}
@@ -106,7 +108,7 @@
for (unsigned i = 0; i < n; ++i)
hmg(i,0) = v[i];
hmg(n,0) = 1;
- tmp = m_ * hmg;
+ tmp = this->m_ * hmg;
mln_assertion(tmp(n,0) == 1);
for (unsigned i = 0; i < n; ++i)
res[i] = tmp(i,0);
@@ -146,18 +148,14 @@
const float sin_a = sin(alpha_);
const metal::vec<4,float> vec = make::vec(cos_a, -sin_a, sin_a, cos_a);
- m_ = metal::mat<n + 1,n + 1,C>::Id;
unsigned k = 0;
for (unsigned i = 0; i < n; ++i)
- {
- if (i == dir_)
- continue;
for (unsigned j = 0; j < n; ++j)
{
- if (j == dir_)
- continue;
- m_(i, j) = vec[k++];
- }
+ if (j != this->dir_ && i != this->dir_)
+ this->m_(i, j) = vec[k++];
+ else
+ this->m_(i, j) = (i == j);
}
}
Index: trunk/milena/mln/fun/internal/x2x_impl.hh
===================================================================
--- trunk/milena/mln/fun/internal/x2x_impl.hh (revision 1302)
+++ trunk/milena/mln/fun/internal/x2x_impl.hh (revision 1303)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/function.hh>
-# include <mln/metal/mat.hh>
+# include <mln/core/h_mat.hh>
# include <mln/core/h_vec.hh>
@@ -55,16 +55,19 @@
typedef V argument;
typedef V result;
typedef typename V::coord coord;
+ typedef h_mat<dim, coord> matrix;
h_vec<dim, coord> operator()(const h_vec<dim, coord>& x) const
{
return m_ * x;
}
+ const matrix& mat() const;
+
protected:
x2x_impl_();
- metal::mat<dim+1, dim+1, coord> m_; // FIXME: Change mat into h_mat<dim, dim, coord>!
+ matrix m_;
};
@@ -76,6 +79,15 @@
{
}
+
+ template <typename V, typename E>
+ const typename x2x_impl_<V,E>::matrix&
+ x2x_impl_<V,E>::mat() const
+ {
+ return m_;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::fun::internal
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add int_s16 test.
* mln/value/int_s16.hh: New, signed int on 16bits.
* tests/value_int_s16.cc: New, tests.
---
mln/value/int_s16.hh | 55 ++++++++++++
tests/value_int_s16.cc | 213 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 268 insertions(+)
Index: trunk/milena/tests/value_int_s16.cc
===================================================================
--- trunk/milena/tests/value_int_s16.cc (revision 0)
+++ trunk/milena/tests/value_int_s16.cc (revision 1302)
@@ -0,0 +1,213 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/value_int_s16.cc
+ *
+ * \brief Tests on mln::value::int_s16.
+ */
+
+#include <mln/value/int_s16.hh>
+
+#define test_operator(T, OP, V1, V2) \
+ \
+{ \
+ T i = V1; \
+ T j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+#define test_interop(T1, T2, OP, V1, V2) \
+ \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+
+// test_operator
+
+int main()
+{
+ using namespace mln;
+ using value::int_s16;
+
+ int_s16 i = 3, j;
+
+ // Assignment.
+ {
+ i = 51;
+ mln_assertion(i == 51);
+
+ i = 51u;
+ mln_assertion(i == 51);
+
+ signed char c = 51;
+ i = c;
+ mln_assertion(i == 51);
+
+ j = i;
+ mln_assertion(j == 51);
+
+ i = 3;
+ mln_assertion(3.0f == i);
+ mln_assertion(i != 2.99f);
+
+ // Error at run-time as expected :-)
+ // i = 256;
+ // i = -1;
+ // i = 255, ++i;
+ }
+
+
+ // Comparaison
+ {
+ int_s16 i = 42;
+ int_s16 j = 51;
+
+ mln_assertion(i < j);
+ mln_assertion(j > i);
+ mln_assertion(i < 12345);
+ mln_assertion(12345 > i);
+
+ mln_assertion(i != j);
+ mln_assertion(i == 42);
+ mln_assertion(42 == i);
+ mln_assertion(i != 69);
+ mln_assertion(69 != i);
+
+ }
+
+ // Addition.
+ {
+ test_operator(int_s16, +, -5, 1);
+ test_interop(int_s16, int, +, 5, -1);
+ test_interop(int_s16, char, +, -4, 2);
+ test_interop(int_s16, unsigned char, +, 4, 2);
+
+ int_s16 i = 234;
+
+ i++;
+ mln_assertion(i == 235);
+
+ ++i;
+ mln_assertion(i == 236);
+
+ i = +i;
+ mln_assertion(i == 236);
+
+ }
+
+ // Soustraction
+ {
+ test_operator(int_s16, -, 100, 5);
+ test_interop(int_s16, int, -, 100, 5);
+ test_interop(int_s16, char, -, 100, 5);
+ test_interop(int_s16, unsigned char, -, 100, 5);
+
+ int_s16 c = 255;
+ c -= c;
+
+ mln_assertion(c == 0);
+
+ int_s16 i = 236;
+
+ i--;
+ mln_assertion(i == 235);
+
+ --i;
+ mln_assertion(i == 234);
+
+ mln_assertion(-i == -234);
+ }
+
+ // Multiplication
+ {
+ test_operator(int_s16, *, 5, 1);
+ test_interop(int_s16, int, *, 5, 1);
+ test_interop(int_s16, char, *, 4, 2);
+ test_interop(int_s16, unsigned char, *, 4, 2);
+
+ int_s16 c = 255;
+
+ c *= 0;
+ mln_assertion(c == 0);
+
+ i *= 2;
+ int k; k *= i;
+
+ unsigned char d = 0;
+ i *= d;
+ mln_assertion(i == 0);
+
+ // Error at run-time as expected :-)
+ // i = 128;
+ // i *= 2;
+
+ }
+
+ // Division
+ {
+ test_operator(int_s16, /, 5, 1);
+ test_interop(int_s16, int, /, 5, 1);
+ test_interop(int_s16, char, /, 4, 2);
+ test_interop(int_s16, unsigned char, /, 4, 2);
+
+ int_s16 c = 200;
+
+ c /= 1;
+ mln_assertion(c == 200);
+ c /= 2;
+ mln_assertion(c == 100);
+
+ int_s16 d = 2;
+ c /= 2;
+ mln_assertion(c == 50);
+
+ }
+
+
+ // Modulo
+ {
+ test_operator(int_s16, %, 5, 10);
+ test_interop(int_s16, int, %, 5, 10);
+ test_interop(int_s16, char, %, 4, 20);
+ test_interop(int_s16, unsigned char, %, 4, 20);
+ }
+}
Index: trunk/milena/mln/value/int_s16.hh
===================================================================
--- trunk/milena/mln/value/int_s16.hh (revision 0)
+++ trunk/milena/mln/value/int_s16.hh (revision 1302)
@@ -0,0 +1,55 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_VALUE_INT_S16_HH
+# define MLN_VALUE_INT_S16_HH
+
+/*! \file mln/value/int_s16.hh
+ *
+ * \brief Define the alias value::int_s16.
+ */
+
+# include <mln/value/int_s.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for signed 16 bit integers.
+ typedef int_s<16> int_s16;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_S16_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Finalise an exhaustive int_u8 test.
* mln/value/concept/scalar.hh: (operator %=) New.
* tests/value_int_u8.cc: Add tests.
---
mln/value/concept/scalar.hh | 12 ++++++++++
tests/value_int_u8.cc | 52 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/value_int_u8.cc
===================================================================
--- trunk/milena/tests/value_int_u8.cc (revision 1300)
+++ trunk/milena/tests/value_int_u8.cc (revision 1301)
@@ -95,12 +95,43 @@
// i = 255, ++i;
}
+
+ // Comparaison
+ {
+ int_u8 i = 42;
+ int_u8 j = 51;
+
+ mln_assertion(i < j);
+ mln_assertion(j > i);
+ mln_assertion(i < 12345);
+ mln_assertion(12345 > i);
+
+ mln_assertion(i != j);
+ mln_assertion(i == 42);
+ mln_assertion(42 == i);
+ mln_assertion(i != 69);
+ mln_assertion(69 != i);
+
+ }
+
// Addition.
{
test_operator(int_u8, +, 5, 1);
test_interop(int_u8, int, +, 5, -1);
test_interop(int_u8, char, +, 4, 2);
test_interop(int_u8, unsigned char, +, 4, 2);
+
+ int_u8 i = 234;
+
+ i++;
+ mln_assertion(i == 235);
+
+ ++i;
+ mln_assertion(i == 236);
+
+ i = +i;
+ mln_assertion(i == 236);
+
}
// Soustraction
@@ -115,6 +146,15 @@
mln_assertion(c == 0);
+ int_u8 i = 236;
+
+ i--;
+ mln_assertion(i == 235);
+
+ --i;
+ mln_assertion(i == 234);
+
+ mln_assertion(-i == -234);
}
// Multiplication
@@ -132,8 +172,8 @@
i *= 2;
int k; k *= i;
- unsigned char c = 0;
- i *= c;
+ unsigned char d = 0;
+ i *= d;
mln_assertion(i == 0);
// Error at run-time as expected :-)
@@ -162,4 +202,12 @@
}
+
+ // Modulo
+ {
+ test_operator(int_u8, %, 5, 10);
+ test_interop(int_u8, int, %, 5, 10);
+ test_interop(int_u8, char, %, 4, 20);
+ test_interop(int_u8, unsigned char, %, 4, 20);
+ }
}
Index: trunk/milena/mln/value/concept/scalar.hh
===================================================================
--- trunk/milena/mln/value/concept/scalar.hh (revision 1300)
+++ trunk/milena/mln/value/concept/scalar.hh (revision 1301)
@@ -96,6 +96,9 @@
template <typename S>
S& operator-=(value::Scalar<S>& lhs, typename S::interop i);
+ template <typename S>
+ S& operator%=(value::Scalar<S>& lhs, typename S::interop i);
+
# ifndef MLN_INCLUDE_ONLY
@@ -146,6 +149,15 @@
return lhs;
}
+
+ template <typename S>
+ S& operator%=(value::Scalar<S>& lhs_, typename S::interop i)
+ {
+ S& lhs = exact(lhs_);
+ lhs = lhs % i;
+ return lhs;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Little fix.
* tests/hexa.cc: Fix compil.
---
hexa.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: trunk/milena/tests/hexa.cc
===================================================================
--- trunk/milena/tests/hexa.cc (revision 1299)
+++ trunk/milena/tests/hexa.cc (revision 1300)
@@ -50,7 +50,7 @@
debug::iota(ima);
trait::image::print(h, std::cout);
- hexa<I>::fwd_piter p(ima.domain());
+ hexa<I>::fwd_piter p(h.domain());
for_all(p)
{
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix, doc in hexa images. Augment tests.
* mln/core/hexa.hh: Set support trait to regular.
* mln/core/image2d_h.hh: Add doc.
* tests/value_int_u8.cc: Augment.
---
mln/core/hexa.hh | 3 ++
mln/core/image2d_h.hh | 14 +++++++++++
tests/value_int_u8.cc | 60 +++++++++++++-------------------------------------
3 files changed, 33 insertions(+), 44 deletions(-)
Index: trunk/milena/tests/value_int_u8.cc
===================================================================
--- trunk/milena/tests/value_int_u8.cc (revision 1298)
+++ trunk/milena/tests/value_int_u8.cc (revision 1299)
@@ -85,6 +85,10 @@
j = i;
mln_assertion(j == 51);
+ i = 3;
+ mln_assertion(3.0f == i);
+ mln_assertion(i != 2.99f);
+
// Error at run-time as expected :-)
// i = 256;
// i = -1;
@@ -124,6 +128,18 @@
c *= 0;
mln_assertion(c == 0);
+
+ i *= 2;
+ int k; k *= i;
+
+ unsigned char c = 0;
+ i *= c;
+ mln_assertion(i == 0);
+
+ // Error at run-time as expected :-)
+ // i = 128;
+ // i *= 2;
+
}
// Division
@@ -147,47 +163,3 @@
}
}
-
-// // Multiplication.
-// {
-// i *= 2;
-// int k; k *= i;
-
-// unsigned char c = 0;
-// i *= c;
-// mln_assertion(i == 0);
-
-// // Error at run-time as expected :-)
-// // i = 128;
-// // i *= 2;
-// }
-
-
-// {
-// i = 3;
-// mln_assertion(3.0f == i);
-// mln_assertion(i != 2.99f);
-// }
-
-// {
-// int j;
-// j = -i;
-// j = +i;
-// }
-
-// {
-// i = 0;
-// i += 1;
-// }
-
- // mln_assertion(i == 2);
- // mln_assertion(i != 3);
-
- // mln_assertion(-i == -2);
- // mln_assertion(-3 * i == -6);
-
- // mln_assertion(j != i);
- // mln_assertion(j != 0);
- // mln_assertion(0 != j);
-
-//}
Index: trunk/milena/mln/core/hexa.hh
===================================================================
--- trunk/milena/mln/core/hexa.hh (revision 1298)
+++ trunk/milena/mln/core/hexa.hh (revision 1299)
@@ -76,11 +76,14 @@
typedef trait::image::category::domain_morpher category;
+
typedef mln_trait_image_border(I) border; // have a border only if I does.
typedef mln_trait_image_io_from_(I) io; // un-write when I const
typedef mln_trait_image_data_from_(I) data;
+
+ typedef trait::image::support::regular support;
// typedef mlc_if( I_data_are_linear_,
// trait::data::stored, // if linear then just stored
// I_data_ ) data; // otherwise like I
Index: trunk/milena/mln/core/image2d_h.hh
===================================================================
--- trunk/milena/mln/core/image2d_h.hh (revision 1298)
+++ trunk/milena/mln/core/image2d_h.hh (revision 1299)
@@ -54,6 +54,18 @@
/// Constructor with the numbers of rows and columns
/// border thickness.
+ ///
+ /// image2d_h(3,6) will build this hexa image :
+ ///
+ /// 1 3 5
+ /// 0 2 4
+ /// --------------
+ /// 0| x x x
+ /// |
+ /// 2| x x x
+ /// |
+ /// 4| x x x
+
image2d_h(int nrows, int ncols, unsigned bdr = border::thickness);
//using super_::init_;
@@ -65,7 +77,9 @@
template <typename V>
image2d_h<V>::image2d_h(int nrows, int ncols, unsigned bdr)
{
+ // numbers of cols can't be odd.
mln_assertion(ncols % 2 == 0);
+
image2d<V> ima(nrows,
ncols / 2,
bdr);
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Points and dpoints can be easily constructed.
* mln/core/point.hh,
* mln/core/dpoint.hh: New ctor overload with args being
coordinates.
* tests/point1d.cc,
* tests/point3d.cc,
* tests/point2d.cc: Update.
* mln/core/hexa_piter.hh: Fix ctor.
* mln/fun/x2x/translation_alt.hh: Fix.
mln/core/dpoint.hh | 31 +++++++++++++++++++++++++++++++
mln/core/hexa_piter.hh | 17 ++++-------------
mln/core/point.hh | 31 +++++++++++++++++++++++++++----
mln/fun/x2x/translation_alt.hh | 9 +++++----
tests/point1d.cc | 2 +-
tests/point2d.cc | 9 +++++++++
tests/point3d.cc | 2 +-
7 files changed, 78 insertions(+), 23 deletions(-)
Index: tests/point1d.cc
--- tests/point1d.cc (revision 1296)
+++ tests/point1d.cc (working copy)
@@ -47,7 +47,7 @@
mln_assertion(p.ind() = 5 && p[0] = 5);
// construction
- q = make::point1d(5);
+ q = 5;
mln_assertion(p = q);
q.set_all(0);
Index: tests/point3d.cc
--- tests/point3d.cc (revision 1296)
+++ tests/point3d.cc (working copy)
@@ -53,7 +53,7 @@
mln_assertion(p.col() = 3 && p[2] = 3);
// construction
- q = make::point3d(5, 9, 3);
+ q = point3d(5, 9, 3);
mln_assertion(p = q);
q.set_all(0);
Index: tests/point2d.cc
--- tests/point2d.cc (revision 1296)
+++ tests/point2d.cc (working copy)
@@ -53,6 +53,15 @@
// construction
q = make::point2d(5, 1);
mln_assertion(p = q);
+ {
+ point2d q_;
+ q_ = point2d(5, 1);
+ mln_assertion(q_ = q);
+ }
+ {
+ point2d q_(5, 1);
+ mln_assertion(q_ = q);
+ }
q.set_all(0);
for (unsigned i = 0; i < p.dim; ++i)
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1296)
+++ mln/core/point.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/internal/coord_impl.hh>
# include <mln/fun/i2v/all.hh>
+# include <mln/metal/bool.hh>
# include <mln/metal/vec.hh>
# include <mln/core/h_vec.hh>
@@ -101,8 +102,12 @@
/// Constructor without argument.
point_();
- /// Constructor with filling.
- point_(C c);
+ /// \{ Constructors with different numbers of argument w.r.t. the
+ /// dimension.
+ point_(C ind);
+ point_(C row, C col);
+ point_(C sli, C row, C col);
+ /// \}
/// Constructor; coordinates are set by function \p f.
template <typename F>
@@ -157,9 +162,27 @@
}
template <typename M, typename C>
- point_<M,C>::point_(C c)
+ point_<M,C>::point_(C ind)
{
- set_all(c);
+ metal::bool_<(dim = 1)>::check();
+ coord_[0] = ind;
+ }
+
+ template <typename M, typename C>
+ point_<M,C>::point_(C row, C col)
+ {
+ metal::bool_<(dim = 2)>::check();
+ coord_[0] = row;
+ coord_[1] = col;
+ }
+
+ template <typename M, typename C>
+ point_<M,C>::point_(C sli, C row, C col)
+ {
+ metal::bool_<(dim = 3)>::check();
+ coord_[0] = sli;
+ coord_[1] = row;
+ coord_[2] = col;
}
template <typename M, typename C>
Index: mln/core/hexa_piter.hh
--- mln/core/hexa_piter.hh (revision 1296)
+++ mln/core/hexa_piter.hh (working copy)
@@ -60,7 +60,6 @@
public:
/// Constructor from a subset of points.
- hexa_fwd_piter_(const box2d& subset);
hexa_fwd_piter_(const box2d_h& subset);
/// Start an iteration.
@@ -94,22 +93,14 @@
// hexa_fwd_piter_<I>
template <typename S>
- hexa_fwd_piter_<S>::hexa_fwd_piter_(const box2d& b)
- : super_(adaptee_(b))
- {
- }
-
- template <typename S>
hexa_fwd_piter_<S>::hexa_fwd_piter_(const box2d_h& b)
:
- box_adaptee_(make::box2d(b.pmin()[0] / 2,
- b.pmin()[1] / 2,
-
- b.pmax()[0] / 2 + b.pmax()[0] % 2,
- b.pmax()[1] / 2)),
super_(adaptee_(box_adaptee_))
-
{
+ box_adaptee_ = make::box2d(b.pmin()[0] / 2,
+ b.pmin()[1] / 2,
+ b.pmax()[0] / 2 + b.pmax()[0] % 2,
+ b.pmax()[1] / 2);
}
template <typename S>
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1296)
+++ mln/core/dpoint.hh (working copy)
@@ -84,6 +84,13 @@
/// Constructor without argument.
dpoint_();
+ /// \{ Constructors with different numbers of argument w.r.t. the
+ /// dimension.
+ dpoint_(C ind);
+ dpoint_(C row, C col);
+ dpoint_(C sli, C row, C col);
+ /// \}
+
/// Constructor; coordinates are set by function \p f.
template <typename F>
dpoint_(const Function_i2v<F>& f);
@@ -129,6 +136,30 @@
}
template <typename M, typename C>
+ dpoint_<M,C>::dpoint_(C ind)
+ {
+ metal::bool_<(dim = 1)>::check();
+ coord_[0] = ind;
+ }
+
+ template <typename M, typename C>
+ dpoint_<M,C>::dpoint_(C row, C col)
+ {
+ metal::bool_<(dim = 2)>::check();
+ coord_[0] = row;
+ coord_[1] = col;
+ }
+
+ template <typename M, typename C>
+ dpoint_<M,C>::dpoint_(C sli, C row, C col)
+ {
+ metal::bool_<(dim = 3)>::check();
+ coord_[0] = sli;
+ coord_[1] = row;
+ coord_[2] = col;
+ }
+
+ template <typename M, typename C>
template <typename F>
dpoint_<M,C>::dpoint_(const Function_i2v<F>& f_)
{
Index: mln/fun/x2x/translation_alt.hh
--- mln/fun/x2x/translation_alt.hh (revision 1296)
+++ mln/fun/x2x/translation_alt.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/fun/x2x/bijective_tr.hh>
-# include <mln/fun/internal/x2x_base.hh>
+# include <mln/fun/internal/x2x_impl.hh>
namespace mln
@@ -52,13 +52,14 @@
struct translation_alt
:
- fun::internal::x2x_base_< metal::vec<n,C>, translation_alt<n,C> >
+ fun::internal::x2x_impl_< metal::vec<n,C>, translation_alt<n,C> >
,
- Function_x2x< translation_alt<n,C> >
+ Bijection_x2x< translation_alt<n,C> >
// FIXME: Activate public bijective_tr< translation_alt<n,C> >
{
typedef fun::internal::x2x_base_< metal::vec<n,C>, translation_alt<n,C> > super_;
+
// typedef translation_alt<n,C> invert;
// invert inv() const;
@@ -66,7 +67,7 @@
translation_alt(const metal::vec<n,C>& t);
using super_::operator();
- result operator()(const metal::vec<n,C>& v) const;
+ metal::vec<n,C> operator()(const metal::vec<n,C>& v) const;
void set_t(const metal::vec<n,C>& t);
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Augment tests on int_u8.
* tests/value_int_u8.cc: Update.
---
value_int_u8.cc | 126 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 102 insertions(+), 24 deletions(-)
Index: trunk/milena/tests/value_int_u8.cc
===================================================================
--- trunk/milena/tests/value_int_u8.cc (revision 1297)
+++ trunk/milena/tests/value_int_u8.cc (revision 1298)
@@ -31,44 +31,122 @@
*/
#include <mln/value/int_u8.hh>
-#include <mln/value/int_u16.hh>
-#include <mln/value/float01_8.hh>
+
+#define test_operator(T, OP, V1, V2) \
+ \
+{ \
+ T i = V1; \
+ T j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+#define test_interop(T1, T2, OP, V1, V2) \
+ \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+
+// test_operator
int main()
{
using namespace mln;
using value::int_u8;
- using value::float01_8;
int_u8 i = 3, j;
+ // Assignment.
{
-// int k = 1;
-// i *= k;
- i *= i;
- mln_assertion(i == 9);
+ i = 51;
+ mln_assertion(i == 51);
+
+ i = 51u;
+ mln_assertion(i == 51);
+
+ signed char c = 51;
+ i = c;
+ mln_assertion(i == 51);
+
+ j = i;
+ mln_assertion(j == 51);
+
+ // Error at run-time as expected :-)
+ // i = 256;
+ // i = -1;
+ // i = 255, ++i;
}
-// // Assignment.
-// {
-// i = 51;
-// mln_assertion(i == 51);
+ // Addition.
+ {
+ test_operator(int_u8, +, 5, 1);
+ test_interop(int_u8, int, +, 5, -1);
+ test_interop(int_u8, char, +, 4, 2);
+ test_interop(int_u8, unsigned char, +, 4, 2);
+ }
-// i = 51u;
-// mln_assertion(i == 51);
+ // Soustraction
+ {
+ test_operator(int_u8, -, 100, 5);
+ test_interop(int_u8, int, -, 100, 5);
+ test_interop(int_u8, char, -, 100, 5);
+ test_interop(int_u8, unsigned char, -, 100, 5);
-// signed char c = 51;
-// i = c;
-// mln_assertion(i == 51);
+ int_u8 c = 255;
+ c -= c;
-// j = i;
-// mln_assertion(j == 51);
+ mln_assertion(c == 0);
-// // Error at run-time as expected :-)
-// // i = 256;
-// // i = -1;
-// // i = 255, ++i;
-// }
+ }
+
+ // Multiplication
+ {
+ test_operator(int_u8, *, 5, 1);
+ test_interop(int_u8, int, *, 5, 1);
+ test_interop(int_u8, char, *, 4, 2);
+ test_interop(int_u8, unsigned char, *, 4, 2);
+
+ int_u8 c = 255;
+
+ c *= 0;
+ mln_assertion(c == 0);
+ }
+
+ // Division
+ {
+ test_operator(int_u8, /, 5, 1);
+ test_interop(int_u8, int, /, 5, 1);
+ test_interop(int_u8, char, /, 4, 2);
+ test_interop(int_u8, unsigned char, /, 4, 2);
+
+ int_u8 c = 200;
+
+ c /= 1;
+ mln_assertion(c == 200);
+ c /= 2;
+ mln_assertion(c == 100);
+
+ int_u8 d = 2;
+ c /= 2;
+ mln_assertion(c == 50);
+
+ }
+
+}
// // Multiplication.
// {
@@ -112,4 +190,4 @@
// mln_assertion(j != 0);
// mln_assertion(0 != j);
-}
+//}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add comments for translate image.
* translate_image.hh: Add comments.
* h_vec.hh: Fix.
---
h_vec.hh | 2 +-
translate_image.hh | 9 ++++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
Index: trunk/milena/mln/core/translate_image.hh
===================================================================
--- trunk/milena/mln/core/translate_image.hh (revision 1295)
+++ trunk/milena/mln/core/translate_image.hh (revision 1296)
@@ -54,7 +54,11 @@
data_(I& ima, const mln_dpoint(I) dp);
I ima_;
+
+ /// Real domain.
box2d bb_;
+
+ /// Delta point of translation.
const mln_dpoint(I) dp_;
};
@@ -82,7 +86,10 @@
- /*! \brief FIXME
+ /*! \brief Translate image class.
+ *
+ * The parameter \c I is the type of image. This image class
+ * makes a translation of a delta point.
*
*/
template <typename I>
Index: trunk/milena/mln/core/h_vec.hh
===================================================================
--- trunk/milena/mln/core/h_vec.hh (revision 1295)
+++ trunk/milena/mln/core/h_vec.hh (revision 1296)
@@ -81,7 +81,7 @@
mln_assertion(w != 0);
metal::vec<d,C> tmp;
- for (unsigned i = 0; i < n; ++i)
+ for (unsigned i = 0; i < d; ++i)
tmp[i] = this->data_[i] / w;
return tmp;
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add convert/to_tiles.hh.
* to_tiles.hh: Create an image from vector of image.
---
to_tiles.hh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
Index: trunk/milena/mln/convert/to_tiles.hh
===================================================================
--- trunk/milena/mln/convert/to_tiles.hh (revision 0)
+++ trunk/milena/mln/convert/to_tiles.hh (revision 1295)
@@ -0,0 +1,97 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CONVERT_TO_TILES_HH
+# define MLN_CONVERT_TO_TILES_HH
+
+/*! \file mln/convert/to_tiles.hh
+ *
+ * \brief Conversion of a vector of image2d into a tiled image with ratio.
+ */
+
+# include <mln/core/translate_image.hh>
+# include <mln/level/paste.hh>
+# include <mln/geom/nrows.hh>
+# include <mln/geom/ncols.hh>
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// FIXME : Run only for image2d
+ /// Convert a vector of image2d into a tiled image with ratio.
+ template <typename I>
+ I to_tiles (std::vector<I>& vec, float ratio);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ I
+ to_tiles (std::vector<I>& vec, float ratio)
+ {
+ /// Test if vec is not empty.
+ mln_precondition(!vec.empty ());
+
+ unsigned size = vec.size ();
+ unsigned nrows = geom::nrows(vec[0]);
+ unsigned ncols = geom::ncols(vec[0]);
+
+ /// Compute output size.
+ int size_c = (int) ceil(sqrt(size * ratio));
+ int size_r = (int) ceil(sqrt(size / ratio));
+
+ I output (size_r * nrows, size_c * ncols);
+
+ for (unsigned i = 0; i < size; ++i)
+ {
+ /// Check if current image has good dimension.
+ mln_precondition(geom::nrows(vec[i]) == nrows);
+ mln_precondition(geom::ncols(vec[i]) == ncols);
+
+ /// Compute the delta point of translation.
+ dpoint2d dp = make::dpoint2d(i / size_c * nrows, i % size_c * ncols);
+
+ /// Convert current image in translate image with its delta point.
+ translate_image<I> tr_ima (vec[i], dp);
+
+ /// Paste translated image into output.
+ level::paste (tr_ima, output);
+ }
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_TILES_HH
1
0