URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-23 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Rename abr into tree.
* mln/util/abr.hh: Remove.
* mln/util/abr_to_image.hh: Remove.
* mln/util/tree.hh: New.
* mln/util/tree_to_image.hh: New.
* sandbox/garrigues/fllt.hh: .
* tests/abr.cc: Remove.
* tests/abr_to_image.cc: Remove.
* tests/tree.cc: New.
* tests/tree_to_image.cc: New.
---
mln/util/tree.hh | 164 ++++++++++++++++++++++++++++++++++++++++++++++
mln/util/tree_to_image.hh | 90 +++++++++++++++++++++++++
sandbox/garrigues/fllt.hh | 4 -
tests/tree.cc | 59 ++++++++++++++++
tests/tree_to_image.cc | 110 ++++++++++++++++++++++++++++++
5 files changed, 425 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/abr.cc (deleted)
===================================================================
Index: trunk/milena/tests/abr_to_image.cc (deleted)
===================================================================
Index: trunk/milena/tests/tree.cc
===================================================================
--- trunk/milena/tests/tree.cc (revision 0)
+++ trunk/milena/tests/tree.cc (revision 1381)
@@ -0,0 +1,59 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*!
+ * \file tests/tree.cc
+ *
+ * \brief test of mln::util::tree
+ *
+ */
+
+#include <mln/util/tree.hh>
+#include <mln/core/contract.hh>
+
+int main (void)
+{
+ using namespace mln;
+
+ unsigned elt1 = 1;
+ unsigned elt2 = 2;
+ unsigned elt3 = 3;
+ unsigned elt4 = 4;
+ unsigned elt5 = 5;
+
+ util::tree<unsigned> tree(elt1);
+ tree.add_child(elt2);
+ tree.add_child(elt3);
+ util::tree<unsigned>* tree2 = tree.search(elt2);
+ mln_assertion(tree2);
+ tree2->add_child(elt4);
+ tree2->add_child(elt5);
+ util::tree<unsigned>* tree3 = tree.search(elt4);
+ mln_assertion(tree3);
+ tree3 = tree2->search(elt1);
+ mln_assertion(!tree3);
+}
Index: trunk/milena/tests/tree_to_image.cc
===================================================================
--- trunk/milena/tests/tree_to_image.cc (revision 0)
+++ trunk/milena/tests/tree_to_image.cc (revision 1381)
@@ -0,0 +1,110 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*!
+ * \file tests/tree_to_image.cc
+ *
+ * \brief test of mln::util::tree_to_image
+ *
+ */
+
+#include <mln/util/tree.hh>
+#include <mln/core/contract.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/set_p.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/stretch.hh>
+#include <mln/io/pgm/save.hh>
+#include <vector>
+#include <mln/util/tree_to_image.hh>
+
+int main (void)
+{
+ using namespace mln;
+ using value::int_u8;
+
+ typedef set_p<point2d > I;
+
+ image2d<int_u8> output (300, 300);
+
+ I s1;
+ I s2;
+ I s3;
+ I s4;
+ I s5;
+ I s6;
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s1.insert(point2d(i, j));
+
+ for (int i = 200; i < 300; ++i)
+ for (int j = 0; j < 100; ++j)
+ s2.insert(point2d(i, j));
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s3.insert(point2d(i, j));
+
+ for (int i = 260; i < 290; ++i)
+ for (int j = 0; j < 50; ++j)
+ s4.insert(point2d(i, j));
+
+ for (int i = 200; i < 210; ++i)
+ for (int j = 0; j < 50; ++j)
+ s5.insert(point2d(i, j));
+
+ for (int i = 270; i < 280; ++i)
+ for (int j = 50; j < 60; ++j)
+ s6.insert(point2d(i, j));
+
+ util::tree<I> tree(s1);
+ tree.add_child(s2);
+ tree.add_child(s3);
+
+ util::tree<I>* tree2 = tree.search(s2);
+ mln_assertion(tree2);
+ tree2->add_child(s4);
+ tree2->add_child(s5);
+ util::tree<I>* tree3 = tree.search(s4);
+ mln_assertion(tree3);
+ tree3->add_child(s6);
+
+ util::tree_to_image(tree, output);
+
+ image2d<int_u8> out(output.domain());
+
+ level::stretch (output, out);
+
+ io::pgm::save(out, "out.pgm");
+
+ std::cout << "out.pgm generate"
+ << std::endl;
+
+// tree3 = tree2->search(s1);
+// mln_assertion(!tree3);
+}
Index: trunk/milena/mln/util/abr.hh (deleted)
===================================================================
Index: trunk/milena/mln/util/abr_to_image.hh (deleted)
===================================================================
Index: trunk/milena/mln/util/tree_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_to_image.hh (revision 0)
+++ trunk/milena/mln/util/tree_to_image.hh (revision 1381)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_TREE_TO_IMAGE_HH
+# define MLN_UTIL_TREE_TO_IMAGE_HH
+
+/*!
+ * \file mln/util/tree_to_image.hh
+ *
+ * \brief Definition of function which transform a tree into an
+ * image.
+ *
+ */
+
+#include <mln/util/tree.hh>
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T, typename I>
+ void
+ tree_to_image_rec(tree<T>& tree, Image<I>& output_, const mln_value(I) lvl);
+
+ template <typename T, typename I>
+ void
+ tree_to_image (tree<T>& tree, Image<I>& output_);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename I>
+ void
+ tree_to_image_rec(tree<T>& tree, Image<I>& output_, const mln_value(I) lvl)
+ {
+ I& output = exact(output_);
+
+ mln_piter(T) p(tree.elt_);
+
+ for_all(p)
+ output(p) = lvl;
+
+ typename std::vector< util::tree<T>* >::const_iterator it = tree.child_.begin();
+ for (;
+ it != tree.child_.end();
+ ++it)
+ tree_to_image_rec((**it), output, lvl + 1);
+ }
+
+
+ template <typename T, typename I>
+ void
+ tree_to_image (tree<T>& tree, Image<I>& output_)
+ {
+ I& output = exact(output_);
+ tree_to_image_rec(tree, output, 1);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // !MLN_UTIL_TREE_TO_IMAGE_HH
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 0)
+++ trunk/milena/mln/util/tree.hh (revision 1381)
@@ -0,0 +1,164 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_TREE_HH
+# define MLN_UTIL_TREE_HH
+
+# include <vector>
+
+/*!
+ * \file mln/util/tree.hh
+ *
+ * \brief Definition of a generic general tree.
+ *
+ */
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T>
+ struct tree
+ {
+ tree();
+ tree(T& elt);
+
+ T& content();
+ const T& content() const;
+ void add_child(T& elt);
+ void set_parent(tree<T>* parent);
+ tree<T>* get_parent();
+ void print_rec(int n) const;
+ void print(void) const;
+ int search_rec(tree<T>** res, T& elt);
+ tree<T>* search(T& elt);
+
+ T elt_;
+ tree<T>* parent_;
+ std::vector< tree<T>* > child_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ tree<T>::tree()
+ : parent_ (0)
+ {
+ }
+
+ template <typename T>
+ tree<T>::tree(T& elt)
+ : elt_ (elt),
+ parent_ (0)
+ {
+ }
+
+ template <typename T>
+ const T&
+ tree<T>::content() const
+ {
+ return elt_;
+ }
+
+ template <typename T>
+ T&
+ tree<T>::content()
+ {
+ return elt_;
+ }
+
+ template <typename T>
+ void
+ tree<T>::add_child(T& elt)
+ {
+ tree<T>* s = new tree<T>(elt);
+
+ s->parent_ = this;
+ this->child_.push_back(s);
+ }
+
+ template <typename T>
+ void
+ tree<T>::set_parent(tree<T>* parent)
+ {
+ mln_assertion(parent != 0);
+ parent_ = parent;
+ parent->child_.push_back(this);
+ }
+
+
+ template <typename T>
+ tree<T>*
+ tree<T>::get_parent()
+ {
+ return parent_;
+ }
+
+ template <typename T>
+ int
+ tree<T>::search_rec(tree<T>** res, T& elt)
+ {
+ if (elt == this->elt_)
+ {
+ *res = this;
+ return 1;
+ }
+ else
+ {
+ for (typename std::vector<tree<T>* >::iterator it = this->child_.begin();
+ it != this->child_.end(); ++it)
+ {
+ if ((**it).search_rec(res, elt))
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ template <typename T>
+ tree<T>*
+ tree<T>::search(T& elt)
+ {
+ tree<T>* res = 0;
+
+ if (search_rec(&res, elt))
+ return res;
+ return 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+
+} // end of namespace mln
+
+
+#endif // !MLN_UTIL_TREE_HH
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1380)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1381)
@@ -57,7 +57,7 @@
# include <mln/set/diff.hh>
# include <mln/set/inter.hh>
-# include <mln/util/abr.hh>
+# include <mln/util/tree.hh>
# include <mln/labeling/regional_minima.hh>
# include <mln/labeling/level.hh>
@@ -78,7 +78,7 @@
set_p<P> holes;
};
- # define fllt_node(P) util::abr< fllt_node<P> >
+ # define fllt_node(P) util::tree< fllt_node<P> >
// LOWER LEVEL SET : region = c4, border = c8
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-23 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Update fllt.
* mln/core/a_point_of.hh: New, give a point of an image
* mln/util/abr.hh: (abr::set_parent) New,
(abr::get_parent) New,
(abr::content) New.
* sandbox/garrigues/fllt.hh: Update fllt.
* sandbox/garrigues/test_fllt.cc: Update.
---
mln/core/a_point_of.hh | 63 +++++++++++++++++++++++
mln/util/abr.hh | 40 +++++++++++++-
sandbox/garrigues/fllt.hh | 110 ++++++++++++++++++++++++++++++++++++-----
sandbox/garrigues/test_fllt.cc | 8 +-
4 files changed, 201 insertions(+), 20 deletions(-)
Index: trunk/milena/mln/core/a_point_of.hh
===================================================================
--- trunk/milena/mln/core/a_point_of.hh (revision 0)
+++ trunk/milena/mln/core/a_point_of.hh (revision 1380)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_A_POINT_OF_HH
+# define MLN_CORE_A_POINT_OF_HH
+
+/*! \file mln/core/a_point_oft.hh
+ *
+ * \brief Give a point of an image.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/exact.hh>
+
+namespace mln
+{
+
+ /// Give a point of an image.
+ template <typename I>
+ mln_point(I) a_point_of(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_point(I) a_point_of(const Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_piter(I) p(ima.domain());
+ p.start();
+ return p;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_A_POINT_OF_HH
Index: trunk/milena/mln/util/abr.hh
===================================================================
--- trunk/milena/mln/util/abr.hh (revision 1379)
+++ trunk/milena/mln/util/abr.hh (revision 1380)
@@ -49,13 +49,17 @@
abr();
abr(T& elt);
+ T& content();
+ const T& content() const;
void add_child(T& elt);
+ void set_parent(abr<T>* parent);
+ abr<T>* get_parent();
void print_rec(int n) const;
void print(void) const;
int search_rec(abr<T>** res, T& elt);
abr<T>* search(T& elt);
- T& elt_;
+ T elt_;
abr<T>* parent_;
std::vector< abr<T>* > child_;
};
@@ -65,8 +69,7 @@
template <typename T>
abr<T>::abr()
- : elt_ (0),
- parent_ (0)
+ : parent_ (0)
{
}
@@ -78,6 +81,20 @@
}
template <typename T>
+ const T&
+ abr<T>::content() const
+ {
+ return elt_;
+ }
+
+ template <typename T>
+ T&
+ abr<T>::content()
+ {
+ return elt_;
+ }
+
+ template <typename T>
void
abr<T>::add_child(T& elt)
{
@@ -88,6 +105,23 @@
}
template <typename T>
+ void
+ abr<T>::set_parent(abr<T>* parent)
+ {
+ mln_assertion(parent != 0);
+ parent_ = parent;
+ parent->child_.push_back(this);
+ }
+
+
+ template <typename T>
+ abr<T>*
+ abr<T>::get_parent()
+ {
+ return parent_;
+ }
+
+ template <typename T>
int
abr<T>::search_rec(abr<T>** res, T& elt)
{
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1379)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1380)
@@ -44,6 +44,7 @@
# include <mln/core/sub_image.hh>
# include <mln/core/image_if.hh>
# include <mln/core/clone.hh>
+# include <mln/core/a_point_of.hh>
# include <mln/debug/println.hh>
# include <mln/convert/to_image.hh>
@@ -56,6 +57,8 @@
# include <mln/set/diff.hh>
# include <mln/set/inter.hh>
+# include <mln/util/abr.hh>
+
# include <mln/labeling/regional_minima.hh>
# include <mln/labeling/level.hh>
@@ -65,6 +68,19 @@
namespace mln
{
+ namespace fllt
+ {
+
+ template <typename P>
+ struct fllt_node
+ {
+ set_p<P> points;
+ set_p<P> holes;
+ };
+
+ # define fllt_node(P) util::abr< fllt_node<P> >
+
+
// LOWER LEVEL SET : region = c4, border = c8
// UPPER LEVEL SET : region = c8, border = c4
@@ -145,7 +161,13 @@
set_p<P>& N,
V& gn)
{
+ static bool finished = false;
std::cout << "entering step 3" << std::endl;
+
+ // Stop the algorithm.
+ if (finished)
+ { gn = 0; return; }
+
// N <- N union {x neighbor of a pixel in a\R}
mln_piter(set_p<P>) qa(A);
for_all(qa)
@@ -167,8 +189,13 @@
debug::println(u | R);
// gn <- min u(x) x belongs to N.
+ if ((u | set::inter(N, u.domain())).npoints() > 0)
gn = level::compute<accu::min>(u | set::inter(N, u.domain()));
-
+ else
+ {
+ finished = true;
+ gn++;
+ }
std::cout << std::endl << "gN = " << gn << std::endl;
// R <- R union A
// tag the pixels of A.
@@ -186,12 +213,36 @@
template <typename V, typename P>
void step4_1 (image2d<V>& u,
set_p<P>& A,
-// set_p<P>& R,
+ set_p<P>& R,
set_p<P>& N,
V& g,
- V& gn)
+ V& gn,
+ fllt_node(P)* current_region,
+ image2d<fllt_node(P)*>& regions
+ )
{
std::cout << "entering step 4_1" << std::endl;
+
+ // Create a new conected component.
+ // FIXME : we can make it faster.
+ //mln_piter(S) p(set::inter(N, u.domain()) | pw::value(u) == pw::cst(g));
+ mln_piter(set_p<P>) p(R);
+ current_region = new fllt_node(P)();
+ for_all(p)
+ {
+ if (regions(p) == 0)
+ {
+ current_region->content().points.insert(p);
+ regions(p) = current_region;
+ }
+ else
+ {
+ if (regions(p)->get_parent() == 0)
+ regions(p)->set_parent(current_region);
+ }
+ }
+
+
// Count the number of conected components of the border of R.
image2d<int> tmp(u.domain().to_larger(1));
image2d<bool> border_ima(u.domain().to_larger(1));
@@ -208,13 +259,18 @@
{
// IF number of conected components of the border > 1
-
+ for (int i = 2; i < n; i++)
+ {
// follow each border to find which is the exterior border
// and which are the holes. Keep one pixel of each holes.
-// Remove from N border of holes???.
+ // WARNING : We trust labeling::level to label the exterior border with 1.
+ current_region->content().holes.insert(a_point_of(tmp | pw::value(tmp) == pw::cst(n)));
+
+ // FIXME : [optimisation] Remove from N border of holes???.
// Recompute gn <- min u(x) x belongs to A
}
+ }
g = gn;
// A <- {x belongs to N / u(x) == g}
@@ -239,7 +295,10 @@
void step4_2 (const image2d<V>& u,
set_p<P>& A,
set_p<P>& N,
- V& g)
+ V& g,
+ fllt_node(P)* current_region,
+ image2d<fllt_node(P)*>& regions
+ )
{
std::cout << "entering step 4_2" << std::endl;
@@ -248,6 +307,21 @@
// N <- N\{x belongs to N / u(x) == g}
N = set::diff(N, N | pw::value(u) == pw::cst(g));
+// // FIXME
+// typedef mln::pset_if<
+// mln::set_p<mln::point_<mln::grid::square, int> >,
+// mln::fun::eq_p2b_expr_<mln::pw::value_<mln::image2d<int> >,
+// mln::pw::cst_<int> > > S;
+
+// // Update the current region
+// //mln_piter(S) p(set::inter(N, u.domain()) | pw::value(u) == pw::cst(g));
+// mln_piter(set_p<P>) p(A);
+// for_all(p)
+// {
+// if (regions(p) == 0)
+// regions(p) = current_region;
+// }
+
std::cout << "A :" << std::endl;
if (A.npoints())
debug::println(u | A);
@@ -280,14 +354,12 @@
}
-
-
-
template <typename V>
void compute_level_set(const image2d<V>& ima)
{
typedef point2d P;
typedef image2d<V> I;
+ // FIXME
typedef mln::image_if<
mln::image2d<V>,
mln::fun::greater_p2b_expr_<mln::pw::value_<mln::image2d<V> >,
@@ -302,6 +374,10 @@
image2d<V> u = clone(ima);
image2d<bool> tagged(ima.domain());
+ fllt_node(P)* current_region;
+ image2d<fllt_node(P)*> regions(ima.domain());
+ level::fill(regions, 0);
+
unsigned nlabels;
labeling::regional_minima(ima, c4(), min_locals, nlabels);
@@ -329,7 +405,7 @@
/// step4.
if (g < gn)
{
- step4_1(u, A, N, g, gn);
+ step4_1(u, A, R, N, g, gn, current_region, regions);
// GO TO 3)
continue;
}
@@ -337,7 +413,7 @@
if (g == gn)
{
- step4_2(u, A, N, g);
+ step4_2(u, A, N, g, current_region, regions);
// GO TO 3)
continue;
}
@@ -351,8 +427,16 @@
}
}
}
- }
- }
+ } // end of Algorithm
+ std::cout << "END OF ALGORITHM" << std::endl;
+
+
+ debug::println(regions);
+ debug::println(ima | regions(make::point2d(-4,-1))->content().points);
+
+ } // end of compute_level_set
+
+ } // end of namespace mln::fllt
} // end of namespace mln
Index: trunk/milena/sandbox/garrigues/test_fllt.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1379)
+++ trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1380)
@@ -14,9 +14,9 @@
2,1,3,4,4,4,4,5,5,
2,3,4,2,3,3,2,4,4,
1,4,2,1,1,2,1,2,2,
- 1,2,4,2,1,2,1,1,1,
- 1,3,3,4,2,3,2,1,1,
- 1,3,3,4,2,3,2,1,1,
+ 1,2,4,2,1,2,1,9,1,
+ 1,3,3,4,2,3,2,9,1,
+ 1,3,3,4,2,3,2,9,1,
1,3,3,4,2,3,2,1,1,
1,3,3,4,2,3,2,1,1};
@@ -25,5 +25,5 @@
image2d<int> ima = convert::to_image(w_win);
debug::println(ima);
- compute_level_set(ima);
+ fllt::compute_level_set(ima);
}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-23 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add abr_to_image which transform an util::abr in image.
* mln/util/abr_to_image.hh: New function.
* tests/abr_to_image.cc: New test.
---
mln/util/abr_to_image.hh | 90 ++++++++++++++++++++++++++++++++++++++
tests/abr_to_image.cc | 110 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 200 insertions(+)
Index: trunk/milena/tests/abr_to_image.cc
===================================================================
--- trunk/milena/tests/abr_to_image.cc (revision 0)
+++ trunk/milena/tests/abr_to_image.cc (revision 1379)
@@ -0,0 +1,110 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*!
+ * \file tests/abr_to_image.cc
+ *
+ * \brief test of mln::util::abr_to_image
+ *
+ */
+
+#include <mln/util/abr.hh>
+#include <mln/core/contract.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/set_p.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/stretch.hh>
+#include <mln/io/pgm/save.hh>
+#include <vector>
+#include <mln/util/abr_to_image.hh>
+
+int main (void)
+{
+ using namespace mln;
+ using value::int_u8;
+
+ typedef set_p<point2d > I;
+
+ image2d<int_u8> output (300, 300);
+
+ I s1;
+ I s2;
+ I s3;
+ I s4;
+ I s5;
+ I s6;
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s1.insert(point2d(i, j));
+
+ for (int i = 200; i < 300; ++i)
+ for (int j = 0; j < 100; ++j)
+ s2.insert(point2d(i, j));
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s3.insert(point2d(i, j));
+
+ for (int i = 260; i < 290; ++i)
+ for (int j = 0; j < 50; ++j)
+ s4.insert(point2d(i, j));
+
+ for (int i = 200; i < 210; ++i)
+ for (int j = 0; j < 50; ++j)
+ s5.insert(point2d(i, j));
+
+ for (int i = 270; i < 280; ++i)
+ for (int j = 50; j < 60; ++j)
+ s6.insert(point2d(i, j));
+
+ util::abr<I> abr(s1);
+ abr.add_child(s2);
+ abr.add_child(s3);
+
+ util::abr<I>* abr2 = abr.search(s2);
+ mln_assertion(abr2);
+ abr2->add_child(s4);
+ abr2->add_child(s5);
+ util::abr<I>* abr3 = abr.search(s4);
+ mln_assertion(abr3);
+ abr3->add_child(s6);
+
+ util::abr_to_image(abr, output);
+
+ image2d<int_u8> out(output.domain());
+
+ level::stretch (output, out);
+
+ io::pgm::save(out, "out.pgm");
+
+ std::cout << "out.pgm generate"
+ << std::endl;
+
+// abr3 = abr2->search(s1);
+// mln_assertion(!abr3);
+}
Index: trunk/milena/mln/util/abr_to_image.hh
===================================================================
--- trunk/milena/mln/util/abr_to_image.hh (revision 0)
+++ trunk/milena/mln/util/abr_to_image.hh (revision 1379)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_ABR_TO_IMAGE_HH
+# define MLN_UTIL_ABR_TO_IMAGE_HH
+
+/*!
+ * \file mln/util/abr_to_image.hh
+ *
+ * \brief Definition of function which transform a tree into an
+ * image.
+ *
+ */
+
+#include <mln/util/abr.hh>
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T, typename I>
+ void
+ abr_to_image_rec(abr<T>& abr, Image<I>& output_, const mln_value(I) lvl);
+
+ template <typename T, typename I>
+ void
+ abr_to_image (abr<T>& abr, Image<I>& output_);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename I>
+ void
+ abr_to_image_rec(abr<T>& abr, Image<I>& output_, const mln_value(I) lvl)
+ {
+ I& output = exact(output_);
+
+ mln_piter(T) p(abr.elt_);
+
+ for_all(p)
+ output(p) = lvl;
+
+ typename std::vector< util::abr<T>* >::const_iterator it = abr.child_.begin();
+ for (;
+ it != abr.child_.end();
+ ++it)
+ abr_to_image_rec((**it), output, lvl + 1);
+ }
+
+
+ template <typename T, typename I>
+ void
+ abr_to_image (abr<T>& abr, Image<I>& output_)
+ {
+ I& output = exact(output_);
+ abr_to_image_rec(abr, output, 1);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // !MLN_UTIL_ABR_TO_IMAGE_HH
URL: https://svn.lrde.org/svn/oln/trunk/milena
ChangeLog:
2007-10-23 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Fix convert_to_set_p and add tests.
* mln/convert/to_set_p.hh: Fix.
* tests/convert_to_set_p.cc: New.
* tests/convert_to_window.cc: New.
---
mln/convert/to_set_p.hh | 21 +++++----
tests/convert_to_set_p.cc | 96 +++++++++++++++++++++++++++++++++++++++++++
tests/convert_to_window.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 206 insertions(+), 10 deletions(-)
Index: trunk/milena/tests/convert_to_set_p.cc
===================================================================
--- trunk/milena/tests/convert_to_set_p.cc (revision 0)
+++ trunk/milena/tests/convert_to_set_p.cc (revision 1378)
@@ -0,0 +1,96 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/convert_to_set_p.cc
+ *
+ * \brief Tests on mln::convert::to_set_p.
+ */
+
+#include <mln/core/point2d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/box2d.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/level/fill.hh>
+
+#include <mln/convert/to_set_p.hh>
+
+using namespace mln;
+
+ void test(set_p<point2d> ref, set_p<point2d> cmp)
+ {
+ mln_assertion(ref.npoints() == cmp.npoints());
+ for (unsigned i = 0; i < ref.npoints(); ++i)
+ mln_assertion(ref[i] == cmp[i]);
+ }
+
+int main()
+{
+ point2d
+ a(1, 0),
+ b(0, 1),
+ c(-1,0),
+ d(0,-1);
+
+ set_p<point2d> ref;
+ ref.insert(a).insert(b).insert(c).insert(d);
+ // Reference constructed.
+
+ // Nbh :
+ neighb2d nbh = c4();
+ set_p<point2d> test_nbh = convert::to_set_p(nbh);
+ test(ref, test_nbh);
+
+ // Image :
+ image2d<bool> ima(make::box2d(-6, -6, 6, 6));
+ level::fill(ima, false);
+ level::fill(inplace(ima | ref), true);
+ set_p<point2d> test_ima = convert::to_set_p(ima);
+ test(ref, test_ima);
+
+ // Window :
+ window2d win;
+ win
+ .insert(a - point2d::origin)
+ .insert(b - point2d::origin)
+ .insert(c - point2d::origin)
+ .insert(d - point2d::origin);
+ set_p<point2d> test_win = convert::to_set_p(win);
+ test(ref, test_win);
+
+ // std::set :
+ std::set<point2d> set;
+ set.insert(a);
+ set.insert(b);
+ set.insert(c);
+ set.insert(d);
+ set_p<point2d> test_set = convert::to_set_p(set);
+ test(ref, test_set);
+}
Index: trunk/milena/tests/convert_to_window.cc
===================================================================
--- trunk/milena/tests/convert_to_window.cc (revision 0)
+++ trunk/milena/tests/convert_to_window.cc (revision 1378)
@@ -0,0 +1,99 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/convert_to_window.cc
+ *
+ * \brief Tests on mln::convert::to_window.
+ */
+
+#include <mln/core/dpoint2d.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/box2d.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/level/fill.hh>
+
+#include <mln/convert/to_window.hh>
+#include <mln/convert/to_set_p.hh>
+
+using namespace mln;
+
+ void test(window2d ref, window2d cmp)
+ {
+ mln_assertion(ref.ndpoints() == cmp.ndpoints());
+ for (unsigned i = 0; i < ref.ndpoints(); ++i)
+ mln_assertion(ref.dp(i) == cmp.dp(i));
+ }
+
+int main()
+{
+ dpoint2d
+ a(1, 0),
+ b(0, 1),
+ c(-1,0),
+ d(0,-1);
+
+ window2d ref;
+ ref.insert(a).insert(b).insert(c).insert(d);
+ // Reference constructed.
+
+ // Nbh :
+ neighb2d nbh = c4();
+ window2d test_nbh = convert::to_window(nbh);
+ test(ref, test_nbh);
+
+ // Image :
+ image2d<bool> ima(make::box2d(-6, -6, 6, 6));
+ level::fill(ima, false);
+ level::fill(inplace(ima | convert::to_set_p(ref)), true);
+ window2d test_ima = convert::to_window(ima);
+ test(ref, test_ima);
+
+ // Window :
+ set_p<point2d> setp;
+ setp
+ .insert(point2d::origin + a)
+ .insert(point2d::origin + b)
+ .insert(point2d::origin + c)
+ .insert(point2d::origin + d);
+ window2d test_setp = convert::to_window(setp);
+ test(ref, test_setp);
+
+ // std::set :
+ std::set<dpoint2d> set;
+ set.insert(a);
+ set.insert(b);
+ set.insert(c);
+ set.insert(d);
+ window2d test_set = convert::to_window(set);
+ test(ref, test_set);
+
+ // FIXME: To upper window.
+}
Index: trunk/milena/mln/convert/to_set_p.hh
===================================================================
--- trunk/milena/mln/convert/to_set_p.hh (revision 1377)
+++ trunk/milena/mln/convert/to_set_p.hh (revision 1378)
@@ -51,15 +51,15 @@
/// Convert a neighborhood \p nbh into a point set.
template <typename N>
- set_p<mln_point(N)> to_window(const Neighborhood<N>& nbh);
+ set_p<mln_point(N)> to_set_p(const Neighborhood<N>& nbh);
/// Convert a binary image \p ima into a point set.
template <typename I>
set_p<mln_point(I)> to_set_p(const Image<I>& ima);
/// Convert a Window \p win into a point set.
- template <typename P>
- set_p<P> to_set_p(const Window<mln_dpoint(P)> win);
+ template <typename W>
+ set_p<mln_point(W)> to_set_p(const Window<W>& win);
/// Convert an std::set \p s of points into a point set.
template <typename D>
@@ -77,7 +77,7 @@
set_p<P> pset;
mln_niter(N) n(nbh, P::origin);
for_all(n)
- pset.insert(n - P::origin);
+ pset.insert(n);
return pset;
}
@@ -93,18 +93,19 @@
mln_piter(I) p(ima.domain());
for_all(p)
if (ima(p))
- pset.insert(p - P::origin);
+ pset.insert(p);
return pset;
}
- template <typename P>
- set_p<P> to_set_p(const Window<mln_dpoint(P)>& win)
+ template <typename W>
+ set_p<mln_point(W)> to_set_p(const Window<W>& win)
{
- typedef mln_dpoint(P) D;
+ typedef mln_dpoint(W) D;
+ typedef mln_point(W) P;
set_p<P> pset;
- mln_qiter(D) q(exact(win), P::origin);
+ mln_qiter(W) q(exact(win), P::origin);
for_all(q)
- pset.insert(q - P::origin);
+ pset.insert(q);
return pset;
}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-23 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add a function which transform a tree into an image in sandbox.
* abr_to_image.cc: New function abr_to_image.
---
abr_to_image.cc | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 147 insertions(+)
Index: trunk/milena/sandbox/duhamel/abr_to_image.cc
===================================================================
--- trunk/milena/sandbox/duhamel/abr_to_image.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/abr_to_image.cc (revision 1377)
@@ -0,0 +1,147 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*!
+ * \file tests/abr.cc
+ *
+ * \brief test of mln::util::abr
+ *
+ */
+
+#include <mln/util/abr.hh>
+#include <mln/core/contract.hh>
+#include <mln/core/image2d.hh>
+#include <mln/core/set_p.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/stretch.hh>
+#include <mln/io/pgm/save.hh>
+#include <vector>
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T, typename I>
+ void
+ abr_to_image_rec(abr<T>& abr, Image<I>& output_, const mln_value(I) lvl)
+ {
+ I& output = exact(output_);
+
+ mln_piter(T) p(abr.elt_);
+
+ for_all(p)
+ output(p) = lvl;
+
+ typename std::vector< util::abr<T>* >::const_iterator it = abr.child_.begin();
+ for (;
+ it != abr.child_.end();
+ ++it)
+ abr_to_image_rec((**it), output, lvl + 1);
+ }
+
+
+ template <typename T, typename I>
+ void
+ abr_to_image (abr<T>& abr, Image<I>& output_)
+ {
+ I& output = exact(output_);
+ abr_to_image_rec(abr, output, 1);
+ }
+
+ } // end of namespace mln::util
+
+
+} // end of namespace mln
+
+int main (void)
+{
+ using namespace mln;
+ using value::int_u8;
+
+ typedef set_p<point2d > I;
+
+ image2d<int_u8> output (300, 300);
+
+ I s1;
+ I s2;
+ I s3;
+ I s4;
+ I s5;
+ I s6;
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s1.insert(point2d(i, j));
+
+ for (int i = 200; i < 300; ++i)
+ for (int j = 0; j < 100; ++j)
+ s2.insert(point2d(i, j));
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ s3.insert(point2d(i, j));
+
+ for (int i = 260; i < 290; ++i)
+ for (int j = 0; j < 50; ++j)
+ s4.insert(point2d(i, j));
+
+ for (int i = 200; i < 210; ++i)
+ for (int j = 0; j < 50; ++j)
+ s5.insert(point2d(i, j));
+
+ for (int i = 270; i < 280; ++i)
+ for (int j = 50; j < 60; ++j)
+ s6.insert(point2d(i, j));
+
+ util::abr<I> abr(s1);
+ abr.add_child(s2);
+ abr.add_child(s3);
+
+ util::abr<I>* abr2 = abr.search(s2);
+ mln_assertion(abr2);
+ abr2->add_child(s4);
+ abr2->add_child(s5);
+ util::abr<I>* abr3 = abr.search(s4);
+ mln_assertion(abr3);
+ abr3->add_child(s6);
+
+ util::abr_to_image(abr, output);
+
+ image2d<int_u8> out(output.domain());
+
+ level::stretch (output, out);
+
+ io::pgm::save(out, "out.pgm");
+
+ std::cout << "out.pgm generate"
+ << std::endl;
+
+// abr3 = abr2->search(s1);
+// mln_assertion(!abr3);
+}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-23 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Fix display show and add color_pretty version for fllt.
* mln/display/remove.hh: New function which removes all
created file from display::save.
* mln/display/show.hh: Update for previous function.
* tests/show.cc: Update test for display::remove.
* mln/display/color_pretty.hh: Add display::color_pretty_rgb for fllt,
this function take three v_set and color a new image by these point_set.
* tests/color_pretty.cc: Update test for display::color_pretty_rgb.
* mln/util/abr.hh,
* tests/abr.cc: Update typo.
---
mln/display/color_pretty.hh | 57 +++++++++++++++++++++++++++-
mln/display/remove.hh | 87 ++++++++++++++++++++++++++++++++++++++++++++
mln/display/show.hh | 2 +
mln/util/abr.hh | 2 -
tests/abr.cc | 2 -
tests/color_pretty.cc | 44 +++++++++++++++++++++-
tests/show.cc | 2 +
7 files changed, 190 insertions(+), 6 deletions(-)
Index: trunk/milena/tests/abr.cc
===================================================================
--- trunk/milena/tests/abr.cc (revision 1375)
+++ trunk/milena/tests/abr.cc (revision 1376)
@@ -21,7 +21,7 @@
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
-// License.
+// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
Index: trunk/milena/tests/show.cc
===================================================================
--- trunk/milena/tests/show.cc (revision 1375)
+++ trunk/milena/tests/show.cc (revision 1376)
@@ -41,6 +41,7 @@
# include <mln/core/w_window2d_int.hh>
# include <mln/display/show.hh>
# include <mln/display/save.hh>
+# include <mln/display/remove.hh>
# include <mln/display/color_pretty.hh>
# include <mln/io/ppm/save.hh>
@@ -70,4 +71,5 @@
display::save (t);
display::show (t, "xv");
}
+ display::remove ();
}
Index: trunk/milena/tests/color_pretty.cc
===================================================================
--- trunk/milena/tests/color_pretty.cc (revision 1375)
+++ trunk/milena/tests/color_pretty.cc (revision 1376)
@@ -41,6 +41,7 @@
# include <mln/core/w_window2d_int.hh>
# include <mln/display/color_pretty.hh>
# include <mln/io/ppm/save.hh>
+# include <mln/core/set_p.hh>
int main()
@@ -61,8 +62,49 @@
// Call chamfer for a distance image.
image2d<unsigned> tmp = geom::chamfer(input, w_win, max);
+ set_p<point2d > s1;
+ set_p<point2d > s2;
+ set_p<point2d > s3;
+
+
+// typedef image_if_value<image2d<unsigned> > I;
+// {
+// I t = inplace (tmp | 4);
+// mln_piter(image_if_value<image2d<unsigned> >) p (t.domain ());
+// for_all (p)
+// s1.insert (p);
+// }
+
+// {
+// I tmp = inplace (tmp | 6);
+// mln_point(I) p (tmp.domain ());
+// for_all (p)
+// s2.insert (p);
+// }
+
+// {
+// I tmp = inplace (tmp | 8);
+// mln_point(I) p (tmp.domain ());
+// for_all (p)
+// s3.insert (p);
+// }
+
+// for (int i = 0; i < 100; ++i)
+// for (int j = 0; j < 100; ++j)
+// s1.insert(point2d(i, j));
+
+ for (int i = 200; i < 300; ++i)
+ for (int j = 0; j < 100; ++j)
+ s2.insert(point2d(i, j));
+
+ for (int i = 0; i < 100; ++i)
+ for (int j = 200; j < 300; ++j)
+ s3.insert(point2d(i, j));
+
+
+
// Call color_pretty for sub_image.
- image2d<value::rgb8> out = display::color_pretty(inplace (tmp | 4));
+ image2d<value::rgb8> out = display::color_pretty_rgb(tmp, s1, s2, s3);
// Save output image from color in out.ppm.
io::ppm::save(out, "out.ppm");
Index: trunk/milena/mln/display/color_pretty.hh
===================================================================
--- trunk/milena/mln/display/color_pretty.hh (revision 1375)
+++ trunk/milena/mln/display/color_pretty.hh (revision 1376)
@@ -40,7 +40,7 @@
# include <mln/value/rgb8.hh>
# include <mln/level/fill.hh>
# include <mln/level/paste.hh>
-
+# include <mln/core/set_p.hh>
namespace mln
{
@@ -52,6 +52,13 @@
typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret
color_pretty(const Image<I>& input_);
+ template <typename I>
+ typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret
+ color_pretty_rgb(const Image<I>& input_,
+ const set_p<mln_point(I) >& s1_,
+ const set_p<mln_point(I) >& s2_,
+ const set_p<mln_point(I) >& s3_);
+
# ifndef MLN_INCLUDE_ONLY
namespace impl
@@ -88,8 +95,6 @@
image2d<value::rgb8> output(input.domain().bbox());
level::fill(output, value::rgb8(255, 0, 0));
-// /// FIXME by :
-// level::paste(input, output);
{
mln_piter(I) p(input.domain());
@@ -99,6 +104,42 @@
return output;
}
+ template <typename I>
+ typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret
+ color_pretty_rgb(const Image<I>& input_,
+ const set_p<mln_point(I) >& s1_,
+ const set_p<mln_point(I) >& s2_,
+ const set_p<mln_point(I) >& s3_)
+ {
+ const I& input = exact (input_);
+
+ image2d<value::rgb8> output(input.domain().bbox());
+ level::fill(output, value::rgb8(0, 0, 0));
+
+ {
+ mln_piter(set_p<mln_point(I) >) p(s1_);
+
+ for_all(p)
+ output(p).red() = 255;
+ }
+
+ {
+ mln_piter(set_p<mln_point(I) >) p(s2_);
+
+ for_all(p)
+ output(p).green() = 255;
+ }
+
+ {
+ mln_piter(set_p<mln_point(I) >) p(s3_);
+
+ for_all(p)
+ output(p).blue() = 255;
+ }
+ return output;
+ }
+
+
} // end of namespace mln::display::impl
/// Facade.
@@ -109,6 +150,16 @@
return impl::color_pretty(input_);
}
+ template <typename I>
+ typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret
+ color_pretty_rgb(const Image<I>& input_,
+ const set_p<mln_point(I) >& s1_,
+ const set_p<mln_point(I) >& s2_,
+ const set_p<mln_point(I) >& s3_)
+ {
+ return impl::color_pretty_rgb(input_, s1_, s2_, s3_);
+ }
+
# endif // !MLN_INCLUDE_ONLY
} // end of namespace mln::display
Index: trunk/milena/mln/display/remove.hh
===================================================================
--- trunk/milena/mln/display/remove.hh (revision 0)
+++ trunk/milena/mln/display/remove.hh (revision 1376)
@@ -0,0 +1,87 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DISPLAY_REMOVE_HH
+# define MLN_DISPLAY_REMOVE_HH
+
+/*! \file mln/display/remove.hh
+ *
+ * \brief Remove all temporary files creat by display::save.
+ *
+ */
+
+# include <mln/trait/image_from_mesh.hh>
+# include <mln/core/image_if_value.hh>
+# include <mln/core/image2d.hh>
+# include <mln/display/save.hh>
+
+# include <map>
+
+namespace mln
+{
+
+ namespace display
+ {
+
+ void
+ remove();
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ void
+ remove()
+ {
+
+ for (std::map<void*, std::string>::const_iterator it = map_saved_image_tmp_.begin ();
+ it != map_saved_image_tmp_.end ();
+ ++it)
+ {
+ std::string s = "rm -f " + (*it).second;
+ system (s.c_str ());
+ }
+ }
+
+ } // end of namespace mln::display::impl
+
+ /// Facade.
+ void
+ remove()
+ {
+ return impl::remove();
+ }
+
+# endif // !MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::display
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DISPLAY_REMOVE_HH
Index: trunk/milena/mln/display/show.hh
===================================================================
--- trunk/milena/mln/display/show.hh (revision 1375)
+++ trunk/milena/mln/display/show.hh (revision 1376)
@@ -64,6 +64,8 @@
std::string s = cmd + " " + map_saved_image_tmp_[(void*)input.id_ ()] + " &";
system (s.c_str ());
+ s = "sleep 3 && pkill " + cmd;
+ system (s.c_str ());
}
} // end of namespace mln::display::impl
Index: trunk/milena/mln/util/abr.hh
===================================================================
--- trunk/milena/mln/util/abr.hh (revision 1375)
+++ trunk/milena/mln/util/abr.hh (revision 1376)
@@ -21,7 +21,7 @@
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
-// License.
+// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-22 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add a structure of tree in sandbox.
* abr.cc: New test file for mln::util::abr.
* abr.hh: New structure for tree.
---
abr.cc | 49 ++++++++++++++++++++
abr.hh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 207 insertions(+)
Index: trunk/milena/sandbox/duhamel/abr.hh
===================================================================
--- trunk/milena/sandbox/duhamel/abr.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/abr.hh (revision 1362)
@@ -0,0 +1,158 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_ABR_HH
+# define MLN_UTIL_ABR_HH
+
+# include <list>
+# include <iostream>
+
+/*!
+ * \file mln/util/abr.hh
+ *
+ * \brief Definition of a generic general tree.
+ *
+ *
+ */
+
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename T>
+ struct s_abr
+ {
+ s_abr ();
+ s_abr (const T& elt);
+
+ void add_son (const T& elt);
+ void print_rec (int n) const;
+ void print (void) const;
+ int search_rec(s_abr<T>** res, const T& elt);
+ s_abr<T>* search(const T& elt);
+
+ const T& elt_;
+ s_abr<T>* father_;
+ std::list< s_abr<T>* > sons_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ s_abr<T>::s_abr ()
+ : elt_ (0),
+ father_ (0)
+ {
+ }
+
+ template <typename T>
+ s_abr<T>::s_abr (const T& elt)
+ : elt_ (elt),
+ father_ (0)
+ {
+ }
+
+
+ template <typename T>
+ void
+ s_abr<T>::add_son (const T& elt)
+ {
+
+ s_abr<T>* s = new s_abr<T> (elt);
+
+ s->father_ = this;
+ this->sons_.push_back (s);
+ }
+
+ template <typename T>
+ void
+ s_abr<T>::print_rec (int n) const
+ {
+ std::cout << this->elt_ << std::endl;
+ typename std::list<s_abr<T>* >::const_iterator it = this->sons_.begin ();
+ for (; it != this->sons_.end (); ++it)
+ {
+ for (int i = 0; i < n; ++i)
+ std::cout << " ";
+ (**it).print_rec (n + 1);
+ }
+ }
+
+ template <typename T>
+ void
+ s_abr<T>::print (void) const
+ {
+ this->print_rec(1);
+ }
+
+
+ template <typename T>
+ int
+ s_abr<T>::search_rec(s_abr<T>** res, const T& elt)
+ {
+ if (elt == this->elt_)
+ {
+ *res = this;
+ return 1;
+ }
+ else
+ {
+ typename std::list<s_abr<T>* >::iterator it = this->sons_.begin ();
+ for (; it != this->sons_.end (); ++it)
+ {
+ if ((**it).search_rec (res, elt))
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ template <typename T>
+ s_abr<T>*
+ s_abr<T>::search(const T& elt)
+ {
+ s_abr<T>* res = 0;
+
+ if (search_rec (&res, elt))
+ return res;
+ std::cerr << elt << " not found" << std::endl;
+ return 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+
+} // end of namespace mln
+
+
+#endif // !MLN_UTIL_ABR_HH
Index: trunk/milena/sandbox/duhamel/abr.cc
===================================================================
--- trunk/milena/sandbox/duhamel/abr.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/abr.cc (revision 1362)
@@ -0,0 +1,49 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*!
+ * \file tests/abr.cc
+ *
+ * \brief test of mln::util::abr
+ *
+ */
+
+#include "abr.hh"
+
+int main (void)
+{
+ using namespace mln;
+ util::s_abr<unsigned> abr (1);
+
+ abr.add_son (2);
+ abr.add_son (3);
+ abr.print ();
+ util::s_abr<unsigned>* abr2 = abr.search (2);
+ abr2->add_son (4);
+ abr2->add_son (5);
+ abr.print ();
+}
>>> "Matthieu" == Matthieu Garrigues <garrigues(a)lrde.epita.fr> writes:
[...]
Matthieu> + /*! \brief Remove an element \p elt into the set.
Matthieu> + *
Matthieu> + * \param[in] elt The element to be inserted.
Matthieu> + *
Remove ... from
to be removed
Matthieu> + * If \p elt is already in the set, this method is a no-op.
is not in
--
Alexandre Duret-Lutz