https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a tutorial example for Z.
* doc/tutorial/examples/for_Z.cc: New.
* mln/trait/op/lor.hh: New.
* mln/trait/op/all.hh: Update.
* mln/value/ops.hh: Add some doc.
* mln/value/builtin/ops.hh: Make op== and op!= commute when a
builtin is involved: "bi == obj" is rewritten into
"obj == scalar(bi)".
doc/tutorial/examples/for_Z.cc | 108 +++++++++++++++++++++++++++++++++++++++++
mln/trait/op/all.hh | 2
mln/trait/op/lor.hh | 18 +++---
mln/value/builtin/ops.hh | 6 +-
mln/value/ops.hh | 3 +
5 files changed, 126 insertions(+), 11 deletions(-)
Index: doc/tutorial/examples/for_Z.cc
--- doc/tutorial/examples/for_Z.cc (revision 0)
+++ doc/tutorial/examples/for_Z.cc (revision 0)
@@ -0,0 +1,108 @@
+# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image_if.hh>
+# include <mln/core/alias/neighb2d.hh>
+# include <mln/value/int_u8.hh>
+
+# include <mln/pw/all.hh>
+# include <mln/convert/to_fun.hh>
+# include <mln/debug/println.hh>
+# include <mln/labeling/blobs.hh>
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+// template <template <class, class> class Op,
+// typename F, typename S>
+// struct set_binary_< Op, mln::Function_v2v, F, mln::value::Scalar, S >
+// {
+// typedef Op< F, pw::cst_<mln_value_equiv(S)> > Op_;
+// typedef typename Op_::ret ret;
+// };
+
+ template <template <class, class> class Op,
+ typename F,
+ typename R, typename A>
+ struct set_precise_binary_< Op, F, R (*)(A) >
+ {
+ typedef Op< F, fun::C<R (*)(A)> > Op_;
+ typedef typename Op_::ret ret;
+ };
+
+ template <typename F, typename S>
+ struct set_binary_< op::eq, mln::Function_v2v, F, mln::value::Scalar, S >
+ {
+ typedef mln_trait_op_eq(F, pw::cst_<mln_value_equiv(S)>) ret;
+ };
+
+
+ // const Image | Function_v2v
+
+// template <typename I, typename F>
+// struct set_binary_< op::lor, mln::Image, /* FIXME: const */ I,
mln::Function_v2v, F >
+// {
+// typedef image_if<const I, F> ret;
+// };
+
+ } // end of namespace mln::trait
+
+
+ template <typename F, typename S>
+ mln_trait_op_eq(F,S)
+ operator == (const Function_v2v<F>& fun, const value::Scalar<S>&
s)
+ {
+ return exact(fun) == pw::cst( value::equiv(s) );
+ }
+
+
+ template <typename I, typename R, typename A>
+ image_if< const I, fun::C<R(*)(A)> >
+ operator | (const Image<I>& ima, R (*f)(A) )
+ {
+ return exact(ima) | convert::to_fun(f);
+ }
+
+
+// template <typename O, typename R, typename A>
+// mln_trait_op_lor(const O, fun::C<R(*)(A)>)
+// operator | (const Object<O>& lhs, R (*rhs)(A) )
+// {
+// return exact(lhs) | convert::to_fun(rhs);
+// }
+
+} // end of namespace mln
+
+
+bool row_oddity(mln::point2d p)
+{
+ return p.row() % 2;
+}
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+
+ bool vals[6][5] = {
+ {0, 1, 1, 0, 0},
+ {0, 1, 1, 0, 0},
+ {0, 0, 0, 0, 0},
+ {1, 1, 0, 1, 0},
+ {1, 0, 1, 1, 1},
+ {1, 0, 0, 0, 0}
+ };
+ image2d<bool> ima = make::image2d(vals);
+ debug::println(ima);
+
+ int_u8 nlabels;
+ image2d<int_u8> lab = labeling::blobs(ima, c4(), nlabels);
+ debug::println(lab);
+
+ debug::println(lab | (pw::value(lab) != 0u));
+ debug::println(lab | row_oddity);
+}
Index: mln/trait/op/lor.hh
--- mln/trait/op/lor.hh (revision 2182)
+++ mln/trait/op/lor.hh (working copy)
@@ -25,19 +25,21 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_TRAIT_OP_OR_HH
-# define MLN_TRAIT_OP_OR_HH
+#ifndef MLN_TRAIT_OP_LOR_HH
+# define MLN_TRAIT_OP_LOR_HH
-/*! \file mln/trait/op/or.hh
+/*! \file mln/trait/op/lor.hh
*
- * \brief Declaration of the "binary or" operator trait.
+ * \brief Declaration of the "binary logical or" operator trait.
+ *
+ * \todo Add land (for logical and).
*/
# include <mln/trait/op/decl.hh>
-# define mln_trait_op_or(L, R) typename mln::trait::op::or_< L , R >::ret
-# define mln_trait_op_or_(L, R) mln::trait::op::or_< L , R >::ret
+# define mln_trait_op_lor(L, R) typename mln::trait::op::lor< L , R >::ret
+# define mln_trait_op_lor_(L, R) mln::trait::op::lor< L , R >::ret
@@ -51,7 +53,7 @@
{
template <typename L, typename R>
- struct or_ : public solve_binary<or_, L, R>
+ struct lor : public solve_binary<lor, L, R>
{
};
@@ -65,4 +67,4 @@
# include <mln/trait/solve.hh>
-#endif // ! MLN_TRAIT_OP_OR_HH
+#endif // ! MLN_TRAIT_OP_LOR_HH
Index: mln/trait/op/all.hh
--- mln/trait/op/all.hh (revision 2182)
+++ mln/trait/op/all.hh (working copy)
@@ -74,6 +74,8 @@
# include <mln/trait/op/or.hh>
# include <mln/trait/op/xor.hh>
+# include <mln/trait/op/lor.hh>
+
# include <mln/trait/op/not.hh>
// Ordering.
Index: mln/value/ops.hh
--- mln/value/ops.hh (revision 2182)
+++ mln/value/ops.hh (working copy)
@@ -157,6 +157,9 @@
operator % (const value::Scalar<Vl>& lhs, const
value::Scalar<Vr>& rhs);
+ // Swap arguments so that "scalar_ OP Object" is "Object OP
+ // scalar_". As a consequence, the user only has to define what
+ // happens with a scalar as a rhs.
template <typename S, typename O>
mln_trait_op_plus(O, value::scalar_<S>)
Index: mln/value/builtin/ops.hh
--- mln/value/builtin/ops.hh (revision 2182)
+++ mln/value/builtin/ops.hh (working copy)
@@ -121,7 +121,7 @@
operator Symb (const Object<O>& lhs, const Builtin & rhs); \
\
template <typename O> \
- mln_trait_op_##Name (value::scalar_< Builtin >, O) \
+ mln_trait_op_##Name (O, value::scalar_< Builtin >) \
operator Symb (const Builtin & lhs, const Object<O>& rhs); \
\
struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
@@ -136,10 +136,10 @@
} \
\
template <typename O> \
- mln_trait_op_##Name (value::scalar_< Builtin >, O) \
+ mln_trait_op_##Name (O, value::scalar_< Builtin >) \
operator Symb (const Builtin & lhs, const Object<O>& rhs) \
{ \
- return value::scalar(lhs) Symb exact(rhs); \
+ return exact(rhs) Symb value::scalar(lhs); \
} \
\
struct m_a_c_r_o__e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n