URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Update fllt.
* mln/util/branch_iter.hh: (deepness) New.
* sandbox/garrigues/fllt.hh: More output. FIXME : optimize.
---
mln/util/branch_iter.hh | 35 ++++++++++++++-
sandbox/garrigues/fllt.hh | 102 +++++++++++++++++++++++++++++++++++++---------
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;
private:
util::branch<T> branch_;
@@ -74,6 +75,8 @@
std::stack< iter_pair > s_;
util::node<T>* n_;
+ unsigned deepness_;
+ unsigned futur_deepness_;
};
@@ -103,6 +106,24 @@
}
template <typename T>
+ unsigned
+ branch_iter<T>::deepness() const
+ {
+ mln_assertion(is_valid());
+ //return s_.size();
+
+ unsigned i = 0;
+ node<T>* p = n_;
+ while (p)
+ {
+ p = p->parent();
+ i++;
+ }
+ return i;
+ // return deepness_;
+ }
+
+ template <typename T>
bool
branch_iter<T>::is_valid() const
{
@@ -121,6 +142,7 @@
void
branch_iter<T>::start()
{
+ deepness_ = 0;
s_.push(iter_pair(branch_.apex().children().begin(),
branch_.apex().children().end()));
n_ = &branch_.apex();
@@ -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;
s_.pop();
next();
return;
}
else
{
+ deepness_ = futur_deepness_;
+// std::cout << "st :" << deepness_ << std::endl;
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;
next();
return;
}
mln_assertion(n_);
if (n_->children().size() > 0)
+ {
+ futur_deepness_ = deepness_ + 1;
s_.push(iter_pair(n_->children().begin(),
n_->children().end()));
+ }
return;
}
}
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.
- 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());
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);
if (output != ima)
{
@@ -625,6 +624,54 @@
// }
}
+
+ 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;
+ 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;
+ if (is_border)
+ output(q) = 0;
+ }
+ }
+ }
+ }
+
template <typename V>
// Fixme : return type
void
@@ -637,12 +684,16 @@
image2d<fllt_node(P, V)*> low_reg(ima.domain());
image2d<fllt_node(P, V)*> upp_reg(ima.domain());
+ std::cout << "1/ Compute the lower level set." << std::endl;
lower_tree = compute_level_set<V, lower<V> >(ima, low_reg);
+ std::cout << "2/ Compute the upper level set." << std::endl;
upper_tree = compute_level_set<V, upper<V> >(ima, upp_reg);
+ std::cout << "3/ Merge the two trees." << std::endl;
merge_trees(lower_tree, upper_tree, low_reg, upp_reg);
+ std::cout << "4/ Generate outputs." << std::endl;
image2d<value::int_u8> output (ima.domain ());
util::tree_to_image (lower_tree, output);
@@ -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");
}
} // end of namespace mln::fllt