URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-26 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Review util subdirectory.
* mln/util/branch_iter.hh,
* mln/util/branch_iter_ind.hh,
* mln/util/eat.hh,
* mln/util/graph.hh,
* mln/util/ignore.hh,
* mln/util/nil.hh,
* mln/util/pix.hh,
* mln/util/tree.hh,
* mln/util/tree_fast.hh,
* mln/util/tree_fast_to_image.hh,
* mln/util/tree_to_image.hh: Add doc, tracing, fix typo.
Tests
* tests/util/Makefile.am: Update tests.
* tests/util/tree_fast_to_image.cc: Fix this test.
* tests/util/graph.cc,
* tests/util/tree.cc,
* tests/util/tree_to_image.cc: Update.
---
mln/util/branch_iter.hh | 3
mln/util/branch_iter_ind.hh | 6 -
mln/util/eat.hh | 4
mln/util/graph.hh | 81 ++++++++++++++---
mln/util/ignore.hh | 4
mln/util/nil.hh | 4
mln/util/pix.hh | 40 ++++++++
mln/util/tree.hh | 184 +++++++++++++++++++++++++++++++++++----
mln/util/tree_fast.hh | 57 +++++++++++-
mln/util/tree_fast_to_image.hh | 28 +++++
mln/util/tree_to_image.hh | 132 +++++++++++++++++++--------
tests/util/Makefile.am | 4
tests/util/graph.cc | 1
tests/util/tree_fast_to_image.cc | 128 ++++++++++++---------------
tests/util/tree_to_image.cc | 17 +--
15 files changed, 535 insertions(+), 158 deletions(-)
Index: trunk/milena/tests/util/tree.cc
===================================================================
Index: trunk/milena/tests/util/tree_fast_to_image.cc
===================================================================
--- trunk/milena/tests/util/tree_fast_to_image.cc (revision 1539)
+++ trunk/milena/tests/util/tree_fast_to_image.cc (revision 1540)
@@ -26,21 +26,24 @@
// Public License.
/*!
- * \file tests/tree_fast_to_image.cc
+ * \file tests/util/tree_fast_to_image.cc
*
* \brief test of mln::util::tree_fast_to_image
*
*/
+#include <mln/util/tree_fast.hh>
#include <mln/core/contract.hh>
#include <mln/core/image2d.hh>
#include <mln/core/p_set.hh>
#include <mln/value/int_u8.hh>
#include <mln/level/stretch.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/compare.hh>
#include <mln/io/pgm/save.hh>
#include <vector>
#include <mln/util/tree_fast_to_image.hh>
-#include <mln/util/tree_fast.hh>
+#include <mln/debug/println.hh>
template <typename P, typename V>
struct fllt_node
@@ -51,92 +54,83 @@
};
-template <typename P, typename V>
-bool operator==(const mln::p_set<P>& lhs, const mln::p_set<P>& rhs)
-{
- std::size_t n = lhs.npoints ();
- mln::p_set<P> tmp;
-
- if (n != rhs.npoints ())
- return false;
-
-// for (std::size_t i = 0; i < n; ++i)
-// if ()
-
-}
-
-template <typename P, typename V>
-bool operator==(const struct fllt_node<P,V>& lhs, const struct
fllt_node<P,V>& rhs)
-{
- if (lhs.value != rhs.value)
- return false;
-
- /// FIXME
-
- if (!(lhs.points == rhs.points))
- return false;
-
- if (!(lhs.holes == rhs.holes))
- return false;
-
- return true;
-}
-
int main (void)
{
using namespace mln;
using value::int_u8;
- typedef p_set<point2d > I;
- typedef fllt_node<point2d, int_u8> T;
+ typedef fllt_node<point2d , int_u8> I;
+
- T s1;
- T s2;
- T s3;
- T s4;
- T s5;
- T s6;
- T s7;
+ I s1;
+ I s2;
+ I s3;
+ I s4;
+ I s5;
+ I s6;
+ I s7;
- for (int i = 0; i < 100; ++i)
- for (int j = 0; j < 100; ++j)
+ for (int i = 0; i < 4; ++i)
+ for (int j = 0; j < 4; ++j)
s1.points.insert(point2d(i, j));
s1.value = 60;
- for (int i = 200; i < 300; ++i)
- for (int j = 0; j < 100; ++j)
+ for (int i = 8; i < 16; ++i)
+ for (int j = 0; j < 4; ++j)
s2.points.insert(point2d(i, j));
- s2.value = 100;
- for (int i = 0; i < 100; ++i)
- for (int j = 0; j < 100; ++j)
+ s1.value = 100;
+ for (int i = 0; i < 4; ++i)
+ for (int j = 0; j < 4; ++j)
s3.points.insert(point2d(i, j));
s3.value = 110;
- for (int i = 260; i < 290; ++i)
- for (int j = 0; j < 50; ++j)
+ for (int i = 10; i < 12; ++i)
+ for (int j = 0; j < 2; ++j)
s4.points.insert(point2d(i, j));
s4.value = 170;
- for (int i = 200; i < 210; ++i)
- for (int j = 0; j < 50; ++j)
+ for (int i = 8; i < 16; ++i)
+ for (int j = 0; j < 2; ++j)
s5.points.insert(point2d(i, j));
s5.value = 180;
- for (int i = 270; i < 280; ++i)
- for (int j = 50; j < 60; ++j)
+ for (int i = 8; i < 16; ++i)
+ for (int j = 2; j < 4; ++j)
s6.points.insert(point2d(i, j));
s6.value = 210;
- for (int i = 0; i < 300; ++i)
- for (int j = 0; j < 200; ++j)
+ for (int i = 0; i < 16; ++i)
+ for (int j = 0; j < 8; ++j)
s7.points.insert(point2d(i, j));
s7.value = 10;
- util::tree_fast<T> tree(s1);
+ util::tree_fast<I> tree(s1);
tree.add_child(tree.root_, s2);
- tree.add_child(tree.search(s1), s3);
- tree.add_child(tree.search(s2), s4);
- tree.add_child(tree.search(s2), s5);
- tree.add_child(tree.search(s4), s6);
+ tree.add_child(tree.root_, s3);
+ tree.add_child(tree.root_, s4);
+ tree.add_child(tree.root_, s5);
+ tree.add_child(tree.root_, s6);
tree.add_parent(s7);
- image2d<int_u8> out (300,300);
- util::tree_fast_to_image(tree, out);
- io::pgm::save(out, "out.pgm");
- std::cout << "out.pgm generate"
- << std::endl;
+ image2d<int_u8> output (16, 16);
+ level::fill(output, 0);
+ util::tree_fast_to_image(tree, output);
+
+ int_u8 vs[16][16] = {
+
+ {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {110, 110, 110, 110, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ { 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0}
+
+ };
+
+ image2d<int_u8> ref (make::image2d(vs));
+ mln_assertion(ref == output);
}
Index: trunk/milena/tests/util/graph.cc
===================================================================
--- trunk/milena/tests/util/graph.cc (revision 1539)
+++ trunk/milena/tests/util/graph.cc (revision 1540)
@@ -33,6 +33,7 @@
*/
#include <mln/util/graph.hh>
+#include <iostream>
int main ()
{
Index: trunk/milena/tests/util/tree_to_image.cc
===================================================================
--- trunk/milena/tests/util/tree_to_image.cc (revision 1539)
+++ trunk/milena/tests/util/tree_to_image.cc (revision 1540)
@@ -26,7 +26,7 @@
// Public License.
/*!
- * \file tests/tree_to_image.cc
+ * \file tests/util/tree_to_image.cc
*
* \brief test of mln::util::tree_to_image
*
@@ -62,6 +62,7 @@
typedef fllt_node<point2d , int_u8> I;
image2d<int_u8> output (16, 16);
+ level::fill(output, 0);
I s1;
I s2;
@@ -120,14 +121,14 @@
{ 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
{ 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
{ 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
- {180, 180, 16, 16, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
- {180, 180, 16, 16, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
- {180, 180, 16, 16, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
- {180, 180, 16, 16, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
- {180, 180, 16, 16, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 0, 0, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 0, 0, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 0, 0, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 0, 0, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ {180, 180, 0, 0, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
{180, 180, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
- { 16, 16, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
- { 16, 16, 16, 16, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0}
+ { 0, 0, 210, 210, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0}
};
Index: trunk/milena/tests/util/Makefile.am
===================================================================
--- trunk/milena/tests/util/Makefile.am (revision 1539)
+++ trunk/milena/tests/util/Makefile.am (revision 1540)
@@ -9,7 +9,8 @@
tree \
tree_fast \
tree_fast_to_image \
-tree_to_image
+tree_to_image \
+tree_fast_to_image
branch_iter_SOURCES = branch_iter.cc
@@ -21,6 +22,7 @@
tree_fast_SOURCES = tree_fast.cc
tree_fast_to_image_SOURCES = tree_to_image.cc
tree_to_image_SOURCES = tree_to_image.cc
+tree_fast_to_image_SOURCES = tree_fast_to_image.cc
TESTS = $(check_PROGRAMS)
Index: trunk/milena/mln/util/graph.hh
===================================================================
--- trunk/milena/mln/util/graph.hh (revision 1539)
+++ trunk/milena/mln/util/graph.hh (revision 1540)
@@ -30,7 +30,7 @@
# include <mln/core/concept/object.hh>
# include <cstddef>
-# include <iostream>
+# include <ostream>
# include <vector>
# include <list>
# include <algorithm>
@@ -46,6 +46,9 @@
namespace util
{
+ /*! \brief Structure of generic node.
+ *
+ */
template<typename T>
struct s_node
{
@@ -53,12 +56,20 @@
std::vector<unsigned> links;
};
+
+ /*! \brief Structure of node with void parameter.
+ *
+ */
template<>
struct s_node<void>
{
std::list<unsigned> links;
};
+
+ /*! \brief Structure of generic edge.
+ *
+ */
template<typename T>
struct s_edge
{
@@ -67,6 +78,9 @@
unsigned node2;
};
+ /*! \brief Structure of edge with void parameter.
+ *
+ */
template<>
struct s_edge <void>
{
@@ -74,18 +88,65 @@
unsigned node2;
};
+ /*! \brief Generic graph using s_node and s_edge.
+ *
+ */
template<typename N, typename E = void>
struct graph
{
+ /*! \brief Constructor.
+ *
+ */
graph ();
+ /*! \brief Add a void node.
+ *
+ */
void add_node (void);
+
+
+ /*! \brief Add a void edge between \p n1 and \p n2.
+ *
+ * \param[in] n1 The first node to link.
+ * \param[in] n2 The second node to link.
+ *
+ * \pre n1 < nb_node_.
+ * \pre n2 < nb_node_.
+ *
+ */
void add_edge (unsigned n1, unsigned n2);
+
+
+ /*! \brief Check the consistency of the graph.
+ *
+ * Check if all edge have their node in the graph.
+ *
+ * \pre nodes_.size () == nb_node_.
+ * \pre links_.size () == nb_link_.
+ *
+ */
void consistency () const;
- void print_debug () const;
+
+
+ /*! \brief Print on \p ostr the graph.
+ *
+ * \param[in] ostr The output stream.
+ *
+ */
+ void print_debug (std::ostream& ostr) const;
+
+
+
+ /// The nuber of nodes.
unsigned nb_node_;
+
+ /// The nuber of links.
unsigned nb_link_;
+
+ /// The vector where is stocked the pointers of nodes.
std::vector<struct s_node<N>*> nodes_;
+
+ /// The vector where is stocked the pointers of links.
std::vector<struct s_edge<E>*> links_;
};
@@ -151,27 +212,23 @@
template<typename N, typename E>
void
- graph<N, E>::print_debug () const
+ graph<N, E>::print_debug (std::ostream& ostr) const
{
- std::cout << "nodes :"
- << std::endl;
+ ostr << "nodes :" << std::endl;
typename std::vector<struct s_node<N>*>::const_iterator it =
nodes_.begin ();
int i = 0;
for (; it != nodes_.end (); ++it, ++i)
{
- std::cout << "node number = "
- << i
- << " nbh : ";
+ ostr << "node number = " << i << " nbh : ";
typename std::list<unsigned>::const_iterator it2 = (*it)->links.begin ();
for (; it2 != (*it)->links.end (); ++it2)
{
- std::cout << (*it2)
- << " ";
+ ostr << (*it2) << " ";
}
- std::cout << std::endl;
+ ostr << std::endl;
}
- std::cout << std::endl;
+ ostr << std::endl;
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/util/nil.hh
===================================================================
--- trunk/milena/mln/util/nil.hh (revision 1539)
+++ trunk/milena/mln/util/nil.hh (revision 1540)
@@ -42,7 +42,9 @@
namespace util
{
- /// Nil structure.
+ /*! \brief Nil structure.
+ *
+ */
struct nil : public Object< nil >
{
nil();
Index: trunk/milena/mln/util/ignore.hh
===================================================================
--- trunk/milena/mln/util/ignore.hh (revision 1539)
+++ trunk/milena/mln/util/ignore.hh (revision 1540)
@@ -42,7 +42,9 @@
namespace util
{
- /// Ignore structure.
+ /*! \brief Ignore structure.
+ *
+ */
struct ignore : public Object< ignore >
{
ignore();
Index: trunk/milena/mln/util/tree_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_to_image.hh (revision 1539)
+++ trunk/milena/mln/util/tree_to_image.hh (revision 1540)
@@ -45,28 +45,48 @@
namespace util
{
+ /*! Convert a tree into an image.
+ *
+ * \param[in] tree The tree to convert.
+ * \param[out] output_ The image containing tree informations.
+ *
+ */
template <typename T, typename I>
void
tree_to_image (tree<T>& tree, Image<I>& output_);
- template <typename P, typename J>
- void
- display_set(const Image<J>& ima_, p_set<P>& s);
-
+ /*! Display a tree.
+ *
+ * \param[in] ima The domain of output image.
+ * \param[in] tree The tree to display.
+ *
+ */
template <typename I, typename J>
void
display_tree(const Image<J>& ima_, tree<I>& tree);
+
+ /*! Display an arborescence from \p node.
+ *
+ * \param[in] ima The domain of output image.
+ * \param[in] node The root node to display.
+ *
+ */
template <typename I, typename J>
void
display_branch(const Image<J>& ima_, node<I>* node);
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename T, typename I>
void
tree_to_image_rec(node<T>* node, Image<I>& output_)
{
+ trace::entering("util::impl::tree_to_image_rec");
+
I& output = exact(output_);
mln_piter(p_set<point2d>) p(node->elt().points);
@@ -83,14 +103,44 @@
if (*it)
tree_to_image_rec((*it), output);
}
+ trace::exiting("util::impl::tree_to_image_rec");
}
- template <typename T, typename I>
+ template <typename T, typename J>
void
- tree_to_image (tree<T>& tree, Image<I>& output_)
+ display_tree_rec(const Image<J>& ima_, node<T>* node, int level)
{
- I& output = exact(output_);
- tree_to_image_rec(tree.root(), output);
+ trace::entering("util::impl::display_tree_rec");
+
+ const J& ima = exact(ima_);
+ display_set(ima, node->elt().points);
+ typename mln::util::node<T>::children_t::iterator it =
node->children().begin();
+ for (;
+ it != node->children().end(); ++it)
+ display_tree_rec(ima, (*it), level + 1);
+
+ trace::exiting("util::impl::display_tree_rec");
+ }
+
+
+ template <typename T, typename J, typename K>
+ void
+ display_branch_rec(const Image<J>& ima_, node<T>* node,
Image<K>& output_)
+ {
+ trace::entering("util::impl::display_branch_rec");
+
+ K& output = exact(output_);
+ const J& ima = exact(ima_);
+
+ mln_piter(p_set<point2d>) p(node->elt().points);
+ for_all (p)
+ output(p) = true;
+ typename mln::util::node<T>::children_t::iterator it =
node->children().begin();
+ for (;
+ it != node->children().end(); ++it)
+ display_branch_rec(ima, (*it), output);
+
+ trace::exiting("util::impl::display_branch_rec");
}
@@ -98,6 +148,8 @@
void
display_set(const Image<J>& ima_, p_set<P>& s)
{
+ trace::entering("util::impl::display_set");
+
const J& ima = exact(ima_);
image2d<bool> out (ima.bbox ());
@@ -105,64 +157,60 @@
mln_piter(p_set<P>) p (s);
for_all (p)
out(p) = true;
+
+ trace::exiting("util::impl::display_set");
}
- template <typename T, typename J>
+ } // end of namespace mln::util::impl
+
+
+
+ template <typename T, typename I>
void
- display_tree_rec(const Image<J>& ima_, node<T>* node, int level)
+ tree_to_image (tree<T>& tree, Image<I>& output_)
{
- const J& ima = exact(ima_);
- std::cout << level << std::endl;
- std::cout << std::endl;
- display_set(ima, node->elt().points);
- typename mln::util::node<T>::children_t::iterator it =
node->children().begin();
- for (;
- it != node->children().end(); ++it)
- display_tree_rec(ima, (*it), level + 1);
- std::cout << std::endl;
- std::cout << std::endl;
- std::cout << std::endl;
- std::cout << std::endl;
+ trace::entering("util::tree_to_image");
+
+ I& output = exact(output_);
+ impl::tree_to_image_rec(tree.root(), output);
+
+ trace::exiting("util::tree_to_image");
}
+
template <typename I, typename J>
void
display_tree(const Image<J>& ima_, tree<I>& tree)
{
- const J& ima = exact(ima_);
- int level = 0;
+ trace::entering("util::display_tree");
- mln_assertion(tree.root());
- display_tree_rec(ima, tree.root(), level);
- }
+ mln_precondition(tree.root());
- template <typename T, typename J, typename K>
- void
- display_branch_rec(const Image<J>& ima_, node<T>* node,
Image<K>& output_)
- {
- K& output = exact(output_);
const J& ima = exact(ima_);
+ int level = 0;
- mln_piter(p_set<point2d>) p(node->elt().points);
- for_all (p)
- output(p) = true;
- typename mln::util::node<T>::children_t::iterator it =
node->children().begin();
- for (;
- it != node->children().end(); ++it)
- display_branch_rec(ima, (*it), output);
+ impl::display_tree_rec(ima, tree.root(), level);
+
+ trace::exiting("util::display_tree");
}
+
template <typename I, typename J>
void
display_branch(const Image<J>& ima_, node<I>* node)
{
+ trace::entering("util::display_branch");
+
+ mln_assertion(node);
+
const J& ima = exact(ima_);
- image2d<bool> output (ima.domain ());
+ image2d<bool> output (ima.domain ());
level::fill(output, false);
- mln_assertion(node);
- display_branch_rec(ima, node, output);
+ impl::display_branch_rec(ima, node, output);
+
+ trace::exiting("util::display_branch");
}
Index: trunk/milena/mln/util/eat.hh
===================================================================
--- trunk/milena/mln/util/eat.hh (revision 1539)
+++ trunk/milena/mln/util/eat.hh (revision 1540)
@@ -42,7 +42,9 @@
namespace util
{
- /// Eat structure.
+ /*! \brief Eat structure.
+ *
+ */
struct eat : public Object< eat >
{
eat();
Index: trunk/milena/mln/util/branch_iter_ind.hh
===================================================================
--- trunk/milena/mln/util/branch_iter_ind.hh (revision 1539)
+++ trunk/milena/mln/util/branch_iter_ind.hh (revision 1540)
@@ -60,8 +60,9 @@
/*! \brief Basic 2D image class.
*
- * The parameter \c T is the type of node's data. branch_iter_ind is used to
pre-order walk a branch.
-
+ * The parameter \c T is the type of node's data. branch_iter_ind
+ * is used to pre-order walk a branch.
+ *
*/
template <typename T>
class branch_iter_ind
@@ -87,6 +88,7 @@
/// Give how deep is the iterator in the branch.
unsigned deepness() const;
+
private:
/// The branch to iter.
util::branch<T> branch_;
Index: trunk/milena/mln/util/tree_fast.hh
===================================================================
--- trunk/milena/mln/util/tree_fast.hh (revision 1539)
+++ trunk/milena/mln/util/tree_fast.hh (revision 1540)
@@ -29,7 +29,6 @@
# define MLN_UTIL_TREE_FAST_HH
# include <vector>
-# include <iostream>
# include <mln/core/contract.hh>
@@ -49,19 +48,70 @@
template <typename T>
struct tree_fast
{
+ /*! \brief Constructor.
+ *
+ */
tree_fast();
+
+ /*! \brief Constructor.
+ *
+ * \param[in] elt The value of the root of the tree.
+ */
tree_fast(T& elt);
+ /*! \brief Return the size of the tree.
+ *
+ * \return the number of node of the tree.
+ */
const unsigned size() const;
+
+
+ /*! \brief Check if the tree has \p elt.
+ *
+ * \return true if it has it else false.
+ */
bool has (T& elt) const;
+
+
+ /*! \brief Search the position of the node with \p elt.
+ *
+ * \param[in] elt The value of the searched node.
+ *
+ * \return the position of the node if it's found else UINT_MAX.
+ */
unsigned search (T& elt) const;
+
+
+ /*! \brief Check if the node at position \p i is the root node.
+ *
+ * \return true if it's the node root it else false.
+ */
bool is_root (unsigned i) const;
+
+
+ /*! \brief Add a child with value \p elt to the \p i th node.
+ *
+ * \return The position of the add child.
+ */
unsigned add_child (unsigned i, T& elt);
+
+
+ /*! \brief Add a parent with value \p elt to this tree.
+ *
+ * \return The position of the new root of this tree.
+ */
unsigned add_parent (T& elt);
+ /// The vector of the value of all node of the tree.
std::vector<T> data_;
+
+ /// The vector of the parent's position of all node of the tree.
std::vector<unsigned> parent_;
+
+ /// The vector of the vector children position of all node of the tree.
std::vector<std::vector<unsigned> > child_;
+
+ /// The position of the root in data_.
unsigned root_;
};
@@ -108,8 +158,9 @@
for (unsigned i = 0; i < data_.size (); ++i)
if (data_[i] == elt)
return i;
- std::cerr << "BUGG !!!!"
- << std::endl;
+
+ /// Bug the search failed.
+ mln_assertion (false);
return (unsigned)(-1);
}
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1539)
+++ trunk/milena/mln/util/tree.hh (revision 1540)
@@ -30,7 +30,7 @@
# include <vector>
# include <algorithm>
-# include <iostream>
+# include <ostream>
# include <algorithm>
# include <mln/core/contract.hh>
@@ -52,79 +52,229 @@
template <typename T> class tree;
template <typename T> class branch;
+
+ /*! \brief Class of generic node for tree.
+ *
+ */
template <typename T>
class node
{
public:
typedef std::vector< node<T>* > children_t;
- /// \{ Constructors
+
+ /*! \brief Constructor.
+ *
+ */
node();
+
+ /*! \brief Constructor.
+ *
+ * \param[in] elt The element of node.
+ */
node(T elt);
- /// \}
- /// \{ Acccess to the element.
+
+ /*! \brief The getter of the element.
+ *
+ * \return The element of the node.
+ */
T& elt();
+
+ /*! \brief The const getter of the element.
+ *
+ * \return The element of the node in const.
+ */
const T& elt() const;
- /// \}
- /// Access to the children
- const children_t& children() const;
+
+ /*! \brief The getter of the children.
+ *
+ * \return The children of the node.
+ */
children_t& children();
- /// Access to the parent node.
+
+ /*! \brief The getter of the children.
+ *
+ * \return The children of the node in const.
+ */
+ const children_t& children() const;
+
+
+ /*! \brief The getter of the parent.
+ *
+ * \return The parent of the node.
+ */
node<T>* parent();
- //node<T>*& parent();
- /// \{ Add a child to the node
+
+ /*! \brief Create a node with \p elt which become the child of
+ * the current node.
+ *
+ * \param[in] elt The element of the new child to add.
+ *
+ * \return The new node created.
+ */
node<T>* add_child(T elt);
+
+ /*! \brief Bind \p node to the current node and become its
+ * child.
+ *
+ * \param[in] node The new child node.
+ *
+ * \return The child node.
+ */
node<T>* add_child(node<T>* node);
- /// \}
+ /*! \brief Bind \p node to the current node and become its
+ * parent.
+ *
+ * \param[in] node The new parent node.
+ *
+ */
void set_parent(node<T>* parent);
+
+ /*! \brief Delete the current node.
+ *
+ */
node<T>* delete_node();
- void print(int level);
+
+ /*! \brief Print on \p ostr the arborescence with the current
+ * node as root.
+ *
+ * \param[in] ostr The output stream.
+ *
+ */
+ void print(std::ostream& ostr, int level = 0);
+
+ /*! \brief Check the consistency of the node.
+ *
+ * \return true if no error, else false.
+ */
bool check_consistency();
- int search_rec(node<T>** res, T& elt);
+
+
+ /*! \brief Search the node with value \p elt in the arborescence
+ * of the current node.
+ *
+ * \param[in] elt The value of the searched node.
+ *
+ * \return If not found 0 else the node with \p elt value.
+ */
node<T>* search(T& elt);
+ /// The using method for method search.
+ int search_rec(node<T>** res, T& elt);
+
private:
- //FIXME tree<T>& tree_;
+
+ /// The value.
T elt_;
+
+ /// The node parent.
node<T>* parent_;
+
+ /// The children.
std::vector< node<T>* > child_;
};
+
+
+ /*! \brief Class of generic tree.
+ *
+ */
template <typename T>
class tree
{
public:
+
typedef node<T> node_t;
+
+ /*! \brief Constructor.
+ *
+ */
tree();
+
+ /*! \brief Constructor.
+ *
+ * \param[in] root The root of the tree.
+ */
tree(node<T>* root);
+
+ /*! \brief The getter of the root.
+ *
+ * \return The root's node of the the current tree.
+ */
node<T>* root();
+
+ /*! \brief Convert the tree into brach.
+ *
+ * \return The root's node of the the current tree.
+ */
branch<T> main_branch();
+
+ /*! \brief Check the consistency of the tree.
+ *
+ * \return true if no error, else false.
+ */
bool check_consistency();
+
+
+ /*! \brief Bind a new tree upper the current.
+ *
+ * \param[in] elt The new value of the new node of the new tree
+ * add upper the current.
+ */
void add_tree_up (T& elt);
+
+ /*! \brief Bind a new tree downer the current.
+ *
+ * \param[in] elt The new value of the new node of the new tree
+ * add downer the current.
+ */
void add_tree_down (T& elt);
private:
+
+ /// The root's node.
node<T>* root_;
};
+ /*! \brief Class of generic branch.
+ *
+ */
template <typename T>
class branch
{
public:
+
+ /*! \brief Constructor.
+ *
+ * \param[in] tree The tree of the branch.
+ * \param[in] apex The apex of the branch.
+ */
branch(tree<T>& tree, node<T>& apex);
+ /*! \brief The getter of the appex.
+ *
+ * \return The node appex of the current branch.
+ */
node<T>& apex();
+
+ /*! \brief The getter of the tree.
+ *
+ * \return The tree of the current branch.
+ */
tree<T>& tree();
private:
+ /// The tree of this branch.
util::tree<T>& tree_;
+
+ /// The node apex of this branch.
node<T>& apex_;
};
@@ -280,11 +430,11 @@
template <typename T>
void
- node<T>::print(int level)
+ node<T>::print(std::ostream& ostr, int level)
{
- std::cout << level << std::endl;
+ ostr << level << std::endl;
- std::cout << " elt " << this->elt() << std::endl;
+ ostr << " elt " << this->elt() << std::endl;
for (typename std::vector<node<T>* >::iterator it =
this->child_.begin();
Index: trunk/milena/mln/util/pix.hh
===================================================================
--- trunk/milena/mln/util/pix.hh (revision 1539)
+++ trunk/milena/mln/util/pix.hh (revision 1540)
@@ -39,10 +39,12 @@
namespace mln
{
- /// FIXME : doc
namespace select
{
+ /*! \brief Structure p_of.
+ *
+ */
template <typename P>
struct p_of : P
{
@@ -57,19 +59,53 @@
namespace util
{
- /// Pix structure.
+ /*! \brief Structure pix.
+ *
+ */
template <typename I>
struct pix
{
+
+ /// Point_Site associated type.
typedef mln_psite(I) psite;
+
+ /// Value associated type.
typedef mln_value(I) value;
+ /*! \brief Constructor.
+ *
+ * \param[in] ima The image.
+ * \param[in] p The p_site.
+ */
pix(const Image<I>& ima, const mln_psite(I)& p);
+
+ /*! \brief The getter of the image associate to pix structure.
+ *
+ * \return The image ima_.
+ *
+ */
const I& ima() const;
+
+ /*! \brief The getter of psite associate to pix structure.
+ *
+ * \return The psite p_.
+ *
+ */
const mln_psite(I)& p() const;
+
+ /*! \brief The getter of value associate to pix structure.
+ *
+ * \return The value of pix.
+ *
+ */
mln_rvalue(I) v() const;
+
private:
+
+ /// The image associate to pix.
const I& ima_;
+
+ /// The psite associate to pix.
const mln_psite(I)& p_;
};
Index: trunk/milena/mln/util/tree_fast_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_fast_to_image.hh (revision 1539)
+++ trunk/milena/mln/util/tree_fast_to_image.hh (revision 1540)
@@ -46,16 +46,27 @@
namespace util
{
+ /*! Convert a tree_fast into an image.
+ *
+ * \param[in] tree The tree to convert.
+ * \param[out] output_ The image containing tree informations.
+ *
+ */
template <typename T, typename I>
void
tree_fast_to_image(tree_fast<T>& tree, Image<I>& output_);
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename T, typename I>
void
tree_fast_to_image(tree_fast<T>& tree, Image<I>& output_)
{
+ trace::entering("util::impl::tree_fast_to_image");
+
I& output = exact(output_);
std::list<unsigned> l;
@@ -74,6 +85,23 @@
}
l.pop_front();
}
+
+ trace::exiting("util::impl::tree_fast_to_image");
+ }
+
+ } // end of mln::util::impl
+
+
+
+ template <typename T, typename I>
+ void
+ tree_fast_to_image(tree_fast<T>& tree, Image<I>& output_)
+ {
+ trace::entering("util::tree_fast_to_image");
+
+ impl::tree_fast_to_image(tree, output_);
+
+ trace::exiting("util::tree_fast_to_image");
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/util/branch_iter.hh
===================================================================
--- trunk/milena/mln/util/branch_iter.hh (revision 1539)
+++ trunk/milena/mln/util/branch_iter.hh (revision 1540)
@@ -46,7 +46,8 @@
/*! \brief Basic 2D image class.
*
- * The parameter \c T is the type of node's data. branch_iter is used to
pre-order walk a branch.
+ * The parameter \c T is the type of node's data. branch_iter is
+ * used to pre-order walk a branch.
*
*/
template <typename T>