https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix a couple of bugs and augment tutorial examples.
* doc/tutorial/examples/p_array.cc: Augment with a test on p_array
update.
* doc/tutorial/examples/p_array.2.cc: Augment with index
manipulation.
* doc/tutorial/examples/p_vaccess.cc: Augment with extra output.
* mln/trait/site_set/status.txt (pset_array): Fix status.
* mln/core/p_vaccess.hh (set_1_): Fix return type.
* mln/core/p_double.hh (super): Rename that private typedef as...
(super_): ...this.
(change_target): New overriding in p_double_piter. That fixes a
bug since such iterators have to perform some extra
code (w.r.t. the inherited method) when setting the site set.
doc/tutorial/examples/p_array.2.cc | 9 +++
doc/tutorial/examples/p_array.cc | 9 +++
doc/tutorial/examples/p_vaccess.cc | 85 +++++++++++++++++++++++++++++++------
mln/core/p_double.hh | 19 ++++++--
mln/core/p_vaccess.hh | 4 -
mln/trait/site_set/status.txt | 3 -
6 files changed, 110 insertions(+), 19 deletions(-)
Index: doc/tutorial/examples/p_array.cc
--- doc/tutorial/examples/p_array.cc (revision 2157)
+++ doc/tutorial/examples/p_array.cc (working copy)
@@ -75,6 +75,7 @@
<< index_of_in(p, arr2) << " in arr2, #"
<< index_of_in(p, arr1) << " in arr1" << std::endl;
}
+ std::cout << std::endl;
}
mln_invariant(arr2 < arr1);
@@ -89,6 +90,14 @@
}
}
+ {
+ // Fun stuff:
+
+ arr1[0] = point2d(0,0);
+ picture(arr1);
+ picture(arr2);
+ }
+
}
}
Index: doc/tutorial/examples/p_array.2.cc
--- doc/tutorial/examples/p_array.2.cc (revision 2157)
+++ doc/tutorial/examples/p_array.2.cc (working copy)
@@ -81,4 +81,13 @@
// FIXME: j does NOT convert to int because index is NOT a proxy
// NOTA: make index be a proxy, so equip it with every op it needs.
+
+ for (i = 0; i < n; i = i + 1)
+ {
+ std::cout << "i=" << i << ": ";
+ for_all(j)
+ std::cout << arr[(int(j.to_site()) + n) % n] << ' ';
+ std::cout << std::endl;
+ }
+
}
Index: doc/tutorial/examples/p_vaccess.cc
--- doc/tutorial/examples/p_vaccess.cc (revision 2157)
+++ doc/tutorial/examples/p_vaccess.cc (working copy)
@@ -3,6 +3,7 @@
# include <mln/value/int_u8.hh>
# include <mln/level/fill.hh>
+# include <mln/level/paste.hh>
# include <mln/debug/println.hh>
# include <mln/util/timer.hh>
# include <mln/labeling/blobs.hh>
@@ -13,6 +14,8 @@
# include <mln/pw/all.hh>
# include <mln/convert/from_to.hh>
+# include <mln/core/var.hh>
+
template <typename I, typename S>
@@ -64,9 +67,49 @@
mlc_equal(Arr::element, p_run2d)::check();
Arr arr;
- convert::from_to(lab | (pw::value(lab) != pw::cst(0u)), arr);
+ mln_VAR(sub, lab | (pw::value(lab) != pw::cst(0u)));
+ debug::println(sub);
+
+ convert::from_to(sub, arr);
mln_assertion(arr.nsites() == n);
+ {
+ std::cout << "arr = ";
+ mln_piter_(Arr) p(arr);
+ for_all(p)
+ std::cout << p << ' ';
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ {
+ for (unsigned l = 0; l <= nlabels; ++l)
+ {
+ std::cout << "arr(" << l << ") = ";
+ mln_piter_(p_runs2d) p(arr(l));
+ for_all(p)
+ std::cout << p << ' ';
+ std::cout << std::endl;
+ }
+ }
+
+ std::cout << std::endl;
+
+ {
+ for (unsigned l = 0; l <= nlabels; ++l)
+ {
+ std::cout << "arr(" << l << ") = ";
+ mln_iter_(util::set<p_run2d>) r(arr(l).set_hook_());
+ for_all(r)
+ std::cout << r << ' ';
+ std::cout << std::endl;
+ }
+ }
+
+ std::cout << std::endl;
+
+ std::cout << "arr in " << arr.bbox() << std::endl;
for (unsigned l = 0; l <= nlabels; ++l)
{
std::cout << l << ": #" << arr(l).nsites();
@@ -75,22 +118,40 @@
std::cout << std::endl;
}
std::cout << std::endl;
- }
{
- p_runs2d rs;
- convert::from_to(ima, rs);
- mln_assertion(rs.bbox() == ima.bbox());
-
- image2d<int_u8> ima_(ima.domain());
+ image2d<int> ima_(arr.bbox());
level::fill(ima_, 0);
- for (unsigned r = 0; r < rs.nelements(); ++r)
- {
- mln_piter_(p_run2d) p(rs[r]);
- for_all(p)
- ima_(p) = r + 1;
+ for (unsigned l = 1; l <= nlabels; ++l)
+ for (unsigned r = 0; r < arr(l).nelements(); ++r)
+ level::paste(pw::cst(10 * l + r) | arr(l)[r], ima_);
+ debug::println(ima_);
}
+
+ {
+ image2d<int> ima_(arr.bbox());
+ level::fill(ima_, 0);
+ for (unsigned l = 1; l <= nlabels; ++l)
+ if (arr(l).nsites() > 1)
+ level::paste(pw::cst(l) | arr(l), ima_);
debug::println(ima_);
}
+ }
+
+// {
+// p_runs2d rs;
+// convert::from_to(ima, rs);
+// mln_assertion(rs.bbox() == ima.bbox());
+
+// image2d<int_u8> ima_(ima.domain());
+// level::fill(ima_, 0);
+// for (unsigned r = 0; r < rs.nelements(); ++r)
+// {
+// mln_piter_(p_run2d) p(rs[r]);
+// for_all(p)
+// ima_(p) = r + 1;
+// }
+// debug::println(ima_);
+// }
}
Index: mln/trait/site_set/status.txt
--- mln/trait/site_set/status.txt (revision 2157)
+++ mln/trait/site_set/status.txt (working copy)
@@ -43,7 +43,8 @@
ok p_vaccess
ok line2d
+rm pset_array.hh
+
?? pset_if
KO p_array_bb
-KO pset_array.hh
Index: mln/core/p_vaccess.hh
--- mln/core/p_vaccess.hh (revision 2157)
+++ mln/core/p_vaccess.hh (working copy)
@@ -140,7 +140,7 @@
std::size_t memory_size() const;
// Required by p_double-related classes.
- const V& set_1_() const;
+ const mln::value::set<V>& set_1_() const;
const S& set_2_(const V& v) const;
protected:
@@ -257,7 +257,7 @@
template <typename V, typename S>
inline
- const V&
+ const mln::value::set<V>&
p_vaccess<V,S>::set_1_() const
{
return vs_;
Index: mln/core/p_double.hh
--- mln/core/p_double.hh (revision 2157)
+++ mln/core/p_double.hh (working copy)
@@ -94,7 +94,7 @@
p_double_piter<S,I1,I2> >
{
typedef p_double_piter<S,I1,I2> self_;
- typedef internal::site_set_iterator_base<S,self_> super;
+ typedef internal::site_set_iterator_base<S,self_> super_;
public:
/// Constructor with no argument.
@@ -103,6 +103,9 @@
/// Constructor.
p_double_piter(const S& s);
+ /// Change the site set targeted by this iterator.
+ void change_target(const S& newtarget);
+
/// Test if the iterator is valid.
bool is_valid_() const;
@@ -116,8 +119,8 @@
void next_();
protected:
- using super::p_;
- using super::s_;
+ using super_::p_;
+ using super_::s_;
private:
I1 i1_;
@@ -219,7 +222,15 @@
p_double_piter<S,I1,I2>::p_double_piter(const S& s)
{
this->change_target(s);
- i1_.change_target(s.set_1_());
+ }
+
+ template <typename S, typename I1, typename I2>
+ inline
+ void
+ p_double_piter<S,I1,I2>::change_target(const S& newtarget)
+ {
+ this->super_::change_target(newtarget);
+ i1_.change_target(newtarget.set_1_());
invalidate_();
}