Matthieu Garrigues <garrigues(a)lrde.epita.fr> writes:
URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Update fllt.
s/fllt/FLLT/
* mln/util/branch_iter.hh: (deepness) New.
* sandbox/garrigues/fllt.hh: More output. FIXME : optimize.
No FIXME in ChangeLog, please.
Besides, this entry does not tells a lot about the changes.
2 files changed, 116 insertions(+), 21 deletions(-)
Index: trunk/milena/mln/util/branch_iter.hh
===================================================================
--- trunk/milena/mln/util/branch_iter.hh (revision 1399)
+++ trunk/milena/mln/util/branch_iter.hh (revision 1400)
@@ -64,7 +64,8 @@
/// Go to the next point.
void next();
-
+ /// Give how deep is the iterator in the branch.
+ unsigned deepness() const;
s/deepness/depth/
private:
util::branch<T> branch_;
@@ -74,6 +75,8 @@
std::stack< iter_pair > s_;
util::node<T>* n_;
+ unsigned deepness_;
+ unsigned futur_deepness_;
};
s/futur_deepness/future_deepness/
(To be changed wherever deepness occurs.)
It would be nice to comment attributes, too. For instance, what does
futur(e)_deepness_ means.
@@ -103,6 +106,24 @@
}
template <typename T>
+ unsigned
+ branch_iter<T>::deepness() const
+ {
+ mln_assertion(is_valid());
+ //return s_.size();
Please, don't leave dead code in your commits, unless you know that
you're gonna need it later.
The rule I apply is: whenever you leave dead code in a patch -- and
you should try to avoid this as much as possible --, add a FIXME to
mark this code as dead (and to be removed later).
+
+ unsigned i = 0;
+ node<T>* p = n_;
+ while (p)
+ {
+ p = p->parent();
+ i++;
Try to use `++i' instead of `i++' as an habit. Here, it won't change
anything, but when dealing with objects, the pre-increment operator is
more efficient than the post-increment one. So, prefer the former
over the latter, except you really want the behavior or a
post-incrementation.
+ }
+ return i;
+ // return deepness_;
Likewise w.r.t. dead code.
[...]
@@ -140,26 +162,35 @@
if (s_.top().first == s_.top().second)
//if (*(s_.top().first) == 0)
{
+ deepness_ = futur_deepness_;
+ //deepness_--;
+ futur_deepness_ = deepness_;
+// std::cout << "dec :" << deepness_ << std::endl;
Dead (debug) code.
s_.pop();
next();
return;
}
else
{
+ deepness_ = futur_deepness_;
+// std::cout << "st :" << deepness_ << std::endl;
Likewise.
n_ = *(s_.top().first);
s_.top().first++;
if (!n_)
{
- std::cout << "browsing warning : nul pointer" << std::endl;
+// std::cout << "browsing warning : nul pointer" <<
std::endl;
Ditto.
[...]
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1399)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1400)
@@ -266,8 +266,8 @@
// Count the number of conected components of the border of R.
s/conected/connected/
s/of/on/
- image2d<int>
tmp(u.domain().to_larger(1));
- image2d<bool> border_ima(tmp.domain());
+ static image2d<int> tmp(u.domain().to_larger(1));
+ static image2d<bool> border_ima(tmp.domain());
Why these images are static now? A comment would be useful.
level::fill(border_ima, false);
level::fill(inplace(border_ima | N), true);
unsigned n;
@@ -401,7 +401,6 @@
level::fill(regions, 0);
level::fill(tagged, false);
- level::fill(min_locals, 0);
// Get the locals extremums
unsigned nlabels;
@@ -461,9 +460,9 @@
util::tree_to_image (tree, output);
- debug::println(output);
- std::cout << std::endl;
- debug::println(ima);
+// debug::println(output);
+// std::cout << std::endl;
+// debug::println(ima);
Dead code.
[...]
The following two functions are new, and they're not mentioned in the
ChangeLog entry!
+ template <typename P, typename V>
+ void
+ visualize_deepness(image2d<value::int_u8>& output,
+ fllt_tree(P, V)& tree)
+ {
+ fllt_branch_iter(P, V) p(tree.main_branch());
+ level::fill(output, 0);
+ for_all(p)
+ {
+ //std::cout << (&*p) << ":" << p.deepness() <<
std::endl;
Dead code.
+ mln_piter(set_p<point2d>)
q((*p).elt().points);
+ for_all(q)
+ {
+ if (output(q) < p.deepness())
+ output(q) = p.deepness();
+ }
+ }
+ }
+
+
+ template <typename P, typename V>
+ void
+ visualize_bounds(image2d<value::int_u8>& output,
+ fllt_tree(P, V)& tree,
+ unsigned limit)
+ {
+ fllt_branch_iter(P, V) p(tree.main_branch());
+ level::fill(output, 255);
+ for_all(p)
+ {
+ if ((*p).elt().points.npoints() > limit)
+ {
+ mln_piter(set_p<point2d>) q((*p).elt().points);
+ for_all(q)
+ {
+ mln_niter(neighb2d) n(c4(), q);
+ bool is_border = false;
+ for_all (n)
+ if (!((*p).elt().points).has (n))
+ is_border = true;
This is not efficient: you could break out of the loop as soon as the
condition is true for a given `n', instead of iterating over the
remaining elements.
+ if (is_border)
+ output(q) = 0;
+ }
+ }
+ }
+ }
+
template <typename V>
// Fixme : return type
void
s/fixme/FIXME/
[...]
@@ -653,22 +704,35 @@
abort();
}
- io::pgm::save(output, "out_final.pgm");
- std::cout << "out_final.pgm generate"
- << std::endl;
+// io::pgm::save(output, "out_final.pgm");
+// std::cout << "out_final.pgm generate"
+// << std::endl;
- fllt_branch_iter(P, V) p(lower_tree.main_branch());
- for_all(p)
- {
- std::cout << "region mere : " << (*p).parent() <<
std::endl;
- std::cout << " ^" << std::endl;
- std::cout << " |" << std::endl;
- std::cout << "region : " << &*p << std::endl;
+// fllt_branch_iter(P, V) p(lower_tree.main_branch());
+// for_all(p)
+// {
+// std::cout << "region mere : " << (*p).parent() <<
std::endl;
+// std::cout << " ^" << std::endl;
+// std::cout << " |" << std::endl;
+// std::cout << "region : " << &*p << std::endl;
- debug::println(ima | (*p).elt().points);
- std::cout << std::endl;
- }
+// debug::println(ima | (*p).elt().points);
+// std::cout << std::endl;
+// }
+
+// image2d<value::int_u8> viz(ima.domain());
+// image2d<value::int_u8> viz2(ima.domain());
+
+// visualize_deepness(viz, lower_tree);
+// level::stretch(viz, viz2);
+// debug::println(viz);
+// debug::println(viz2);
+// io::pgm::save(viz2, "fllt.pgm");
+
+// visualize_bounds(viz, lower_tree, 2000);
+// debug::println(viz);
+// io::pgm::save(viz, "fllt_bounds.pgm");
}
Dead code.