
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-26 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Update tree for tests. * mln/util/tree.hh, * mln/util/tree_fast.hh, * mln/util/tree_to_image.hh, * tests/tree.cc, * tests/tree_fast_to_image.cc, * tests/tree_to_image.cc: Update. --- mln/util/tree.hh | 5 ++-- mln/util/tree_fast.hh | 24 ++++++++++--------- mln/util/tree_to_image.hh | 2 - tests/tree.cc | 4 +-- tests/tree_fast_to_image.cc | 25 ++++++++++++++++---- tests/tree_to_image.cc | 55 ++++++++++++++++++++++++-------------------- 6 files changed, 69 insertions(+), 46 deletions(-) Index: trunk/milena/tests/tree.cc =================================================================== --- trunk/milena/tests/tree.cc (revision 1391) +++ trunk/milena/tests/tree.cc (revision 1392) @@ -47,9 +47,9 @@ unsigned elt6= 42; util::node<unsigned> node(elt1); - node.add_child(elt2); + util::node<unsigned>* node2 = node.add_child(elt2); node.add_child(elt3); - util::node<unsigned>* node2 = node.search(elt2); +// util::node<unsigned>* node2 = node.search(elt2); mln_assertion(node2); node2->add_child(elt4); node2->add_child(elt5); Index: trunk/milena/tests/tree_fast_to_image.cc =================================================================== --- trunk/milena/tests/tree_fast_to_image.cc (revision 1391) +++ trunk/milena/tests/tree_fast_to_image.cc (revision 1392) @@ -50,6 +50,21 @@ mln::set_p<P> holes; }; + +template <typename P, typename V> +bool operator==(const mln::set_p<P>& lhs, const mln::set_p<P>& rhs) +{ + std::size_t n = lhs.npoints (); + mln::set_p<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) { @@ -58,11 +73,11 @@ /// FIXME -// if (lhs.points != rhs.points) -// return false; + if (!(lhs.points == rhs.points)) + return false; -// if (lhs.holes != rhs.holes) -// return false; + if (!(lhs.holes == rhs.holes)) + return false; return true; } @@ -113,7 +128,7 @@ s7.value = 10; util::tree_fast<T> tree(s1); - tree.add_child(tree.search(s1), s2); + 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); Index: trunk/milena/tests/tree_to_image.cc =================================================================== --- trunk/milena/tests/tree_to_image.cc (revision 1391) +++ trunk/milena/tests/tree_to_image.cc (revision 1392) @@ -42,12 +42,21 @@ #include <vector> #include <mln/util/tree_to_image.hh> +template <typename P, typename V> +struct fllt_node +{ + V value; + mln::set_p<P> points; + mln::set_p<P> holes; +}; + + int main (void) { using namespace mln; using value::int_u8; - typedef set_p<point2d > I; + typedef fllt_node<point2d , int_u8> I; image2d<int_u8> output (300, 300); @@ -61,43 +70,44 @@ for (int i = 0; i < 100; ++i) for (int j = 0; j < 100; ++j) - s1.insert(point2d(i, j)); - + s1.points.insert(point2d(i, j)); + s1.value = 60; for (int i = 200; i < 300; ++i) for (int j = 0; j < 100; ++j) - s2.insert(point2d(i, j)); - + s2.points.insert(point2d(i, j)); + s1.value = 100; for (int i = 0; i < 100; ++i) for (int j = 0; j < 100; ++j) - s3.insert(point2d(i, j)); - + s3.points.insert(point2d(i, j)); + s3.value = 110; for (int i = 260; i < 290; ++i) for (int j = 0; j < 50; ++j) - s4.insert(point2d(i, j)); - + s4.points.insert(point2d(i, j)); + s4.value = 170; for (int i = 200; i < 210; ++i) for (int j = 0; j < 50; ++j) - s5.insert(point2d(i, j)); - + s5.points.insert(point2d(i, j)); + s5.value = 180; for (int i = 270; i < 280; ++i) for (int j = 50; j < 60; ++j) - s6.insert(point2d(i, j)); - + s6.points.insert(point2d(i, j)); + s6.value = 210; for (int i = 0; i < 300; ++i) for (int j = 0; j < 200; ++j) - s7.insert(point2d(i, j)); + s7.points.insert(point2d(i, j)); + s7.value = 10; util::node<I> node(s1); node.add_child(s2); node.add_child(s3); - util::node<I>* node2 = node.search(s2); - mln_assertion(node2); - node2->add_child(s4); - node2->add_child(s5); - util::node<I>* node3 = node.search(s4); - mln_assertion(node3); - node3->add_child(s6); +// util::node<I>* node2 = node.search(s2); +// mln_assertion(node2); + node.add_child(s4); + node.add_child(s5); +// util::node<I>* node3 = node.search(s4); +// mln_assertion(node3); + node.add_child(s6); util::tree<I> tree (&node); @@ -113,7 +123,4 @@ std::cout << "out.pgm generate" << std::endl; - -// tree3 = tree2->search(s1); -// mln_assertion(!tree3); } Index: trunk/milena/mln/util/tree_to_image.hh =================================================================== --- trunk/milena/mln/util/tree_to_image.hh (revision 1391) +++ trunk/milena/mln/util/tree_to_image.hh (revision 1392) @@ -66,8 +66,6 @@ for_all(p) { - std::cout << p - << std::endl; output(p) = node->elt_.value; } typename std::vector< util::node<T>* >::const_iterator it = node->child_.begin(); Index: trunk/milena/mln/util/tree_fast.hh =================================================================== --- trunk/milena/mln/util/tree_fast.hh (revision 1391) +++ trunk/milena/mln/util/tree_fast.hh (revision 1392) @@ -49,15 +49,15 @@ template <typename T> struct tree_fast { -// tree_fast(); + tree_fast(); tree_fast(T& elt); const unsigned size() const; bool has (T& elt) const; unsigned search (T& elt) const; bool is_root (unsigned i) const; - void add_child (unsigned i, T& elt); - void add_parent (T& elt); + unsigned add_child (unsigned i, T& elt); + unsigned add_parent (T& elt); std::vector<T> data_; std::vector<unsigned> parent_; @@ -67,10 +67,10 @@ # ifndef MLN_INCLUDE_ONLY -// template <typename T> -// tree_fast<T>::tree_fast() -// { -// } + template <typename T> + tree_fast<T>::tree_fast() + { + } template <typename T> tree_fast<T>::tree_fast(T& elt) @@ -121,7 +121,7 @@ } template <typename T> - void + unsigned tree_fast<T>::add_child (unsigned i, T& elt) { mln_assertion (i < data_.size ()); @@ -130,19 +130,21 @@ parent_.push_back(i); child_.push_back(v); child_[i].push_back(data_.size () - 1); + return (data_.size () - 1); } template <typename T> - void + unsigned tree_fast<T>::add_parent (T& elt) { - std::vector<unsigned> v; data_.push_back(elt); parent_.push_back(data_.size () - 1); + std::vector<unsigned> v; + v.push_back (root_); child_.push_back(v); - child_[data_.size () - 1].push_back(root_); parent_[root_] = data_.size () - 1; root_ = data_.size () - 1; + return (data_.size () - 1); } Index: trunk/milena/mln/util/tree.hh =================================================================== --- trunk/milena/mln/util/tree.hh (revision 1391) +++ trunk/milena/mln/util/tree.hh (revision 1392) @@ -53,7 +53,7 @@ T& content(); const T& content() const; - void add_child(T& elt); + node<T>* add_child(T& elt); void set_parent(node<T>* parent); node<T>* get_parent(); void print_rec(int n) const; @@ -152,13 +152,14 @@ } template <typename T> - void + node<T>* node<T>::add_child(T& elt) { node<T>* s = new node<T>(elt); s->parent_ = this; this->child_.push_back(s); + return s; } template <typename T>