https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make pixels convertible to offsets.
* mln/core/concept/generalized_pixel.hh
(operator unsigned): New.
* tests/pixel.cc: Update.
* sandbox/duhamel/canvas_labeling.hh
(labeling_fast_try2): New.
mln/core/concept/generalized_pixel.hh | 7 +
sandbox/duhamel/canvas_labeling.hh | 126 ++++++++++++++++++++++++++++++++++
tests/pixel.cc | 4 +
3 files changed, 137 insertions(+)
Index: tests/pixel.cc
--- tests/pixel.cc (revision 1125)
+++ tests/pixel.cc (working copy)
@@ -40,6 +40,8 @@
using namespace mln;
typedef image2d_b<int> I;
+
+ border::thickness = 0;
I ima(3, 3);
{
@@ -51,8 +53,10 @@
{
pixel<const I> pxl(ima, make::point2d(1, 1));
ima.at(1, 1) = 51;
+ mln_assertion(unsigned(pxl) = 4);
mln_assertion(pxl.val() = 51);
+
// hopefully the code below does not compile:
// pxl.val() = 0;
// assignment of read-only location
Index: mln/core/concept/generalized_pixel.hh
--- mln/core/concept/generalized_pixel.hh (revision 1125)
+++ mln/core/concept/generalized_pixel.hh (working copy)
@@ -64,6 +64,13 @@
image& ima() const;
mln_qlf_value(image)** address_() const;
*/
+
+ operator unsigned() const // FIXME: Change to std::size_t
+ {
+ const E& it_ = internal::force_exact<E>(*this);
+ return & it_.val() - & it_.ima()[0];
+ }
+
protected:
Generalized_Pixel();
};
Index: sandbox/duhamel/canvas_labeling.hh
--- sandbox/duhamel/canvas_labeling.hh (revision 1125)
+++ sandbox/duhamel/canvas_labeling.hh (working copy)
@@ -45,6 +45,117 @@
namespace canvas
{
+ // Fast version (version 2).
+
+ template <typename F>
+ struct labeling_fast_try2
+ {
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::O O;
+ typedef typename F::S S;
+
+ // aux:
+ mln_ch_value(O, unsigned) parent;
+
+ labeling(F& f)
+ : f(f),
+ parent(f.output.domain())
+ {
+ run();
+ }
+
+ void run()
+ {
+ // init
+ {
+ f.nlabels = 0;
+ f.init();
+ }
+ // first pass
+ {
+ mln_fwd_pixter(const I) p(f.input); // p is a pixel
+
+ W win = convert::to_window(f.nbh);
+ mln_qixter(const I, W) q(f.input, win, p);
+
+ for_all(p) // if (f.handles(p))
+ {
+ make_set(p);
+ for_all(q)
+ if (f.equiv(n, p))
+ do_union(n, p);
+ else
+ f.do_no_union(n, p);
+ }
+ }
+
+// // second pass
+// {
+// mln_bkd_piter(S) p(f.s);
+// for_all(p) if (f.handles(p))
+// {
+// if (is_root(p))
+// {
+// if (f.labels(p))
+// {
+// if (f.nlabels = mln_max(mln_value(O)))
+// {
+// f.status = false;
+// return;
+// }
+// f.output(p) = ++f.nlabels;
+// }
+// }
+// else
+// f.output(p) = f.output(parent[p]);
+// }
+// f.status = true;
+// }
+
+ } // end of run()
+
+ void make_set(const unsigned& p)
+ {
+ parent[p] = p;
+ f.init_attr(p);
+ }
+
+ bool is_root(const unsigned& p) const
+ {
+ return parent[p] = p;
+ }
+
+ point find_root(const unsigned& x)
+ {
+ if (parent[x] = x)
+ return x;
+ else
+ return parent[x] = find_root(parent[x]);
+ }
+
+ void do_union(const unsigned& n, const unsigned& p)
+ {
+ point r = find_root(n);
+ if (r != p)
+ {
+ parent[r] = p;
+ f.merge_attr(r, p);
+ }
+ }
+
+ };
+
+
+
+
+
+
+
+
+
// General version.
template <typename F>
@@ -152,6 +263,21 @@
};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// FIXME: Fast version.
// FIXME (ADD)