https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment tutorial example for Z.
* milena/doc/tutorial/examples/for_Z.cc: Augment.
* milena/mln/debug/println.spe.hh (has): Replace ima.has by
ima.domain.has so that we do not print the domain extension.
* milena/mln/core/site_set/p_if.hh (pset, pset_): Rename as...
(s, s_): ...these; more consistent with the other code.
* milena/mln/core/image/image_if.hh (todo): Fix typo.
* milena/mln/core/internal/image_domain_morpher.hh
(operator()): Fix missing preconditions.
* milena/mln/value/rgb.hh (operator<<): Remove spaces.
* milena/mln/geom/bbox.hh (bbox): Add overload for images.
doc/tutorial/examples/for_Z.cc | 120 +++++++++++++++++++++++++++++-
mln/core/image/image_if.hh | 2
mln/core/internal/image_domain_morpher.hh | 6 +
mln/core/site_set/p_if.hh | 34 ++++----
mln/debug/println.spe.hh | 4 -
mln/geom/bbox.hh | 13 +++
mln/value/rgb.hh | 10 +-
7 files changed, 161 insertions(+), 28 deletions(-)
Index: milena/doc/tutorial/examples/for_Z.cc
--- milena/doc/tutorial/examples/for_Z.cc (revision 2183)
+++ milena/doc/tutorial/examples/for_Z.cc (working copy)
@@ -1,12 +1,24 @@
# include <mln/core/image/image2d.hh>
+
# include <mln/core/image/image_if.hh>
+# include <mln/core/image/sub_image.hh>
+
+# include <mln/core/site_set/p_vaccess.hh>
+# include <mln/convert/from_to.hh>
+# include <mln/core/alias/p_runs2d.hh>
+
# include <mln/core/alias/neighb2d.hh>
+# include <mln/core/var.hh>
# include <mln/value/int_u8.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/literal/colors.hh>
# include <mln/pw/all.hh>
# include <mln/convert/to_fun.hh>
# include <mln/debug/println.hh>
# include <mln/labeling/blobs.hh>
+# include <mln/level/fill.hh>
+# include <mln/geom/bbox.hh>
namespace mln
@@ -82,10 +94,37 @@
}
+
+namespace my
+{
+
+ template <typename I>
+ void fill(I& ima, mln_value(I) v)
+ {
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ ima(p) = v;
+ }
+
+ template <typename I, typename J>
+ void paste(const I& data, J& dest)
+ {
+ mln_piter(I) p(data.domain());
+ for_all(p)
+ dest(p) = data(p);
+ }
+
+} // end of namespace my
+
+
+
+
+
int main()
{
using namespace mln;
using value::int_u8;
+ using value::rgb8;
bool vals[6][5] = {
@@ -103,6 +142,83 @@
image2d<int_u8> lab = labeling::blobs(ima, c4(), nlabels);
debug::println(lab);
- debug::println(lab | (pw::value(lab) != 0u));
- debug::println(lab | row_oddity);
+
+ mln_VAR(lab_0, lab | (pw::value(lab) != 0u));
+ debug::println(lab_0);
+
+
+// box2d b3 = geom::bbox(lab | (pw::value(lab) == 3u));
+// std::cout << b3 << std::endl
+// << std::endl;
+
+// // mln_VAR(lab3, lab | b3);
+// // debug::println(lab3);
+// // std::cout << lab3.domain() << std::endl
+// // << std::endl;
+
+
+// {
+// std::cout << "(ima | sub_D) | pred" << std::endl <<
std::endl;
+
+// mln_VAR(pred, pw::value(lab) == 3u);
+
+// std::cout << (lab | b3).domain() << std::endl;
+// debug::println(lab | b3);
+
+// std::cout << ((lab | b3) | pred).domain() << std::endl;
+// debug::println((lab | b3) | pred);
+// }
+
+
+// // il existe une difference entre:
+// //
+// // - ima | sub_D ou le sub_D DOIT etre inclus dans ima.domain
+// // et
+// // - ima / sub_D qui reste a ecrire...
+// // ou dans ce cas, on aurait (ima / sub_D).domain() == sub_D | f:p->b =
ima.domain().has(p)
+
+
+// {
+// std::cout << "(ima | pred) | sub_D" << std::endl <<
std::endl;
+
+// mln_VAR(pred, pw::value(lab) == 3u);
+
+// // OK :-)
+// std::cout << (lab | pred).domain() << std::endl;
+// debug::println(lab | pred);
+
+// // KO :-)
+// // Cf. commentaire plus haut
+// // ici l'erreur est que b3 n'est pas un sous-domaine de celui de "lab
| pred"...
+// /*
+// std::cout << ((lab | pred) | b3).domain() << std::endl;
+// debug::println((lab | pred) | b3);
+// */
+// }
+
+
+// debug::println(lab | row_oddity);
+
+// my::fill(lab_0, 9);
+// debug::println(lab_0);
+// debug::println(lab);
+
+
+// image2d<rgb8> cool(ima.domain());
+// level::fill(cool, literal::black);
+
+// level::fill( inplace(cool | (pw::value(lab) == 1u)),
+// literal::red );
+
+// debug::println(cool);
+
+
+ {
+ p_vaccess< int_u8, p_runs2d > s;
+ convert::from_to(lab_0, s);
+ std::cout << s << std::endl;
+ std::cout << s(3) << std::endl;
+ std::cout << s(3).bbox() << std::endl;
+ }
+
}
Index: milena/mln/debug/println.spe.hh
--- milena/mln/debug/println.spe.hh (revision 2183)
+++ milena/mln/debug/println.spe.hh (working copy)
@@ -129,7 +129,7 @@
for_all(p)
{
- if (input.has(p))
+ if (input.domain().has(p))
std::cout << format(input(p)) << " ";
else
std::cout << " ";
@@ -173,7 +173,7 @@
for (int i = max_row; i >= row; --i)
std::cout << ' ';
for (col = b.min_col(); col <= max_col; ++col)
- if (input.has(p))
+ if (input.domain().has(p))
std::cout << format(input(p)) << ' ';
else
std::cout << " ";
Index: milena/mln/core/site_set/p_if.hh
--- milena/mln/core/site_set/p_if.hh (revision 2183)
+++ milena/mln/core/site_set/p_if.hh (working copy)
@@ -30,9 +30,9 @@
/*! \file mln/core/site_set/p_if.hh
*
- * \brief Definition of the restriction of a point set w.r.t. a predicate.
+ * \brief Definition of the restriction of a site set w.r.t. a predicate.
*
- * \todo Change pset_ attribute type to S*.
+ * \todo Change s_ attribute type to S*.
*/
# include <mln/core/internal/site_set_base.hh>
@@ -62,21 +62,21 @@
} // end of namespace trait
- /*! \brief Restrict a point set \p pset to points that verify \p f.
+ /*! \brief Restrict a site set \p s to points that verify \p f.
*
- * \param[in] pset A point set.
+ * \param[in] s A site set.
* \param[in] f A function from point to Boolean.
* \return A subset of points.
*/
template <typename S, typename F>
p_if<S, F>
- operator | (const Site_Set<S>& pset, const Function_p2b<F>& f);
+ operator | (const Site_Set<S>& s, const Function_p2b<F>& f);
/*! \brief Generic subset class.
*
- * Parameter \c S is a point set type; parameter F is a function
+ * Parameter \c S is a site set type; parameter F is a function
* from point to Boolean.
*/
template <typename S, typename F>
@@ -103,8 +103,8 @@
typedef fwd_piter piter;
- /// Constructor with a point set \p pset and a predicate \p f.
- p_if(const S& pset, const F& f);
+ /// Constructor with a site set \p s and a predicate \p f.
+ p_if(const S& s, const F& f);
/// Constructor without argument.
p_if();
@@ -132,7 +132,7 @@
protected:
- S pset_;
+ S s_;
F f_;
};
@@ -144,9 +144,9 @@
template <typename S, typename F>
inline
p_if<S, F>
- operator | (const Site_Set<S>& pset, const Function_p2b<F>& f)
+ operator | (const Site_Set<S>& s, const Function_p2b<F>& f)
{
- p_if<S, F> tmp(exact(pset), exact(f));
+ p_if<S, F> tmp(exact(s), exact(f));
return tmp;
}
@@ -158,7 +158,7 @@
bool
p_if<S,F>::has(const psite& p) const
{
- return pset_.has(p) && f_(p);
+ return s_.has(p) && f_(p) == true;
}
template <typename S, typename F>
@@ -166,7 +166,7 @@
bool
p_if<S,F>::is_valid() const
{
- return pset_.is_valid();
+ return s_.is_valid();
}
template <typename S, typename F>
@@ -174,7 +174,7 @@
const S&
p_if<S,F>::overset() const
{
- return pset_;
+ return s_;
}
template <typename S, typename F>
@@ -187,8 +187,8 @@
template <typename S, typename F>
inline
- p_if<S,F>::p_if(const S& pset, const F& f)
- : pset_(pset),
+ p_if<S,F>::p_if(const S& s, const F& f)
+ : s_(s),
f_(f)
{
}
@@ -212,7 +212,7 @@
std::size_t
p_if<S,F>::memory_size() const
{
- return pset_.memory_size() + sizeof(f_);
+ return s_.memory_size() + sizeof(f_);
}
# endif // ! MLN_INCLUDE_ONLY
Index: milena/mln/core/image/image_if.hh
--- milena/mln/core/image/image_if.hh (revision 2183)
+++ milena/mln/core/image/image_if.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Definition of a image which domain is restricted by a
* function.
*
- * \todo Relax Function_p2v into Function_v2v.
+ * \todo Relax Function_p2b into Function_v2b.
*/
# include <mln/core/internal/image_domain_morpher.hh>
Index: milena/mln/core/internal/image_domain_morpher.hh
--- milena/mln/core/internal/image_domain_morpher.hh (revision 2183)
+++ milena/mln/core/internal/image_domain_morpher.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -102,6 +102,8 @@
image_domain_morpher<I,S,E>::operator()(const mln_psite(S)& p) const
{
mln_precondition(this->delegatee_() != 0);
+ mln_precondition(exact(this)->has(p));
+ mln_precondition(this->delegatee_()->has(p));
return this->delegatee_()->operator()(p);
}
@@ -111,6 +113,8 @@
image_domain_morpher<I,S,E>::operator()(const mln_psite(S)& p)
{
mln_precondition(this->delegatee_() != 0);
+ mln_precondition(exact(this)->has(p));
+ mln_precondition(this->delegatee_()->has(p));
return this->delegatee_()->operator()(p);
}
Index: milena/mln/value/rgb.hh
--- milena/mln/value/rgb.hh (revision 2183)
+++ milena/mln/value/rgb.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -479,10 +479,10 @@
inline
std::ostream& operator<<(std::ostream& ostr, const rgb<n>&
v)
{
- return ostr << "(" << debug::format(v.red())
- << ", " << debug::format(v.green())
- << ", " << debug::format(v.blue())
- << ")";
+ return ostr << '(' << debug::format(v.red())
+ << ',' << debug::format(v.green())
+ << ',' << debug::format(v.blue())
+ << ')';
}
template <unsigned n>
Index: milena/mln/geom/bbox.hh
--- milena/mln/geom/bbox.hh (revision 2183)
+++ milena/mln/geom/bbox.hh (working copy)
@@ -53,6 +53,11 @@
box<mln_site(S)> bbox(const Site_Set<S>& pset);
+ /// Compute the precise bounding box of a point set \p pset.
+ template <typename I>
+ box<mln_site(I)> bbox(const Image<I>& ima);
+
+
# ifndef MLN_INCLUDE_ONLY
namespace impl
@@ -110,6 +115,14 @@
return b;
}
+ template <typename I>
+ box<mln_site(I)> bbox(const Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ return geom::bbox(ima.domain());
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::geom