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