Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
October 2007
- 8 participants
- 229 discussions
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
* milena/mln/labeling: Rename as...
* milena/mln/labeling: ...this.
According to the Robert & Collins dictionary, `labelling' is
spelled with two l's.
0 files changed
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add iterator for branches.
* mln/util/branch_iter.hh: To iterate on branch.
* mln/util/tree.hh: Add branch class, fix tree.
* mln/util/tree_to_image.hh: Fix.
* mln/value/concept/built_in.hh: Add a forward declaration.
* sandbox/garrigues/fllt.hh: Update.
* tests/branch_iter.cc: Test for branch_iter.
---
mln/util/branch_iter.hh | 161 ++++++++++++++++++++++++++++++++++++++++++
mln/util/tree.hh | 98 ++++++++++++++++++++++---
mln/util/tree_to_image.hh | 3
mln/value/concept/built_in.hh | 1
sandbox/garrigues/fllt.hh | 43 +++++++++--
tests/branch_iter.cc | 68 +++++++++++++++++
6 files changed, 354 insertions(+), 20 deletions(-)
Index: trunk/milena/tests/branch_iter.cc
===================================================================
--- trunk/milena/tests/branch_iter.cc (revision 0)
+++ trunk/milena/tests/branch_iter.cc (revision 1393)
@@ -0,0 +1,68 @@
+// 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/branch_iter.cc
+ *
+ * \brief test of mln::util::branch_iter
+ *
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/util/tree.hh>
+#include <mln/util/branch_iter.hh>
+
+int main()
+{
+ using namespace mln;
+
+ util::node<int> n(11);
+
+ util::tree<int> t(&n);
+
+ util::node<int>* f = n.add_child(42);
+
+ util::node<int>* g = f->add_child(421);
+ util::node<int>* h = f->add_child(422);
+
+ g->add_child(4211)->add_child(51)->add_child(52)->add_child(53)->add_child(54)->add_child(55);
+ g->add_child(4212);
+
+ f->add_child(4221);
+ f->add_child(4222);
+
+ n.add_child(43);
+
+ util::branch<int> b(t, n);
+
+ std::vector< util::node<int>* >::iterator it;
+ util::branch_iter<int> p(b);
+ for_all(p)
+ {
+ std::cout << "parcour : " << util::node<int>(p).elt() << std::endl;
+ }
+}
Index: trunk/milena/mln/value/concept/built_in.hh
===================================================================
--- trunk/milena/mln/value/concept/built_in.hh (revision 1392)
+++ trunk/milena/mln/value/concept/built_in.hh (revision 1393)
@@ -42,6 +42,7 @@
namespace value
{
+ template <typename B> struct Built_In;
// Category flag type.
template <>
struct Built_In<void> // No inheritance here since this category is special (on the side).
Index: trunk/milena/mln/util/tree_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_to_image.hh (revision 1392)
+++ trunk/milena/mln/util/tree_to_image.hh (revision 1393)
@@ -65,9 +65,8 @@
mln_piter(set_p<point2d>) p(node->elt_.points);
for_all(p)
- {
output(p) = node->elt_.value;
- }
+
typename std::vector< util::node<T>* >::const_iterator it = node->child_.begin();
for (int i = 0;
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1392)
+++ trunk/milena/mln/util/tree.hh (revision 1393)
@@ -45,15 +45,34 @@
namespace util
{
+ /// Fwd declarations.
+ template <typename T> class node;
+ template <typename T> class tree;
+ template <typename T> class branch;
+
template <typename T>
- struct node
+ class node
{
+ public:
+
+ /// \{ Constructors
node();
- node(T& elt);
+ node(T elt);
+ /// \}
+
+ /// \{ Acccess to the element.
+ T& elt();
+ const T& elt() const;
+ /// \}
+
+ /// Access to the children
+ const std::vector< node<T>* >& children() const;
+ std::vector< node<T>* >& children();
- T& content();
- const T& content() const;
- node<T>* add_child(T& elt);
+ /// Access to the parent node.
+ const node<T>* parent() const;
+
+ node<T>* add_child(T elt);
void set_parent(node<T>* parent);
node<T>* get_parent();
void print_rec(int n) const;
@@ -61,14 +80,17 @@
int search_rec(node<T>** res, T& elt);
node<T>* search(T& elt);
+ private:
+ //FIXME tree<T>& tree_;
T elt_;
node<T>* parent_;
std::vector< node<T>* > child_;
};
template <typename T>
- struct tree
+ class tree
{
+ public:
typedef node<T> node_t;
tree();
tree(node<T>* root);
@@ -77,9 +99,26 @@
void add_tree_up (T& elt);
void add_tree_down (T& elt);
+ private:
node<T>* root_;
};
+
+ template <typename T>
+ class branch
+ {
+ public:
+ branch(tree<T>& tree, node<T>& apex);
+
+ node<T>& apex();
+ tree<T>& tree();
+
+ private:
+ node<T>& apex_;
+ util::tree<T>& tree_;
+ };
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename T>
@@ -131,7 +170,7 @@
}
template <typename T>
- node<T>::node(T& elt)
+ node<T>::node(T elt)
: elt_ (elt),
parent_ (0)
{
@@ -139,21 +178,36 @@
template <typename T>
const T&
- node<T>::content() const
+ node<T>::elt() const
{
return elt_;
}
template <typename T>
T&
- node<T>::content()
+ node<T>::elt()
{
return elt_;
}
+
+ template <typename T>
+ std::vector< node<T>* >&
+ node<T>::children()
+ {
+ return child_;
+ }
+
+ template <typename T>
+ const std::vector< node<T>* >&
+ node<T>::children() const
+ {
+ return child_;
+ }
+
template <typename T>
node<T>*
- node<T>::add_child(T& elt)
+ node<T>::add_child(T elt)
{
node<T>* s = new node<T>(elt);
@@ -211,6 +265,30 @@
return 0;
}
+ // Branch methods
+ template <typename T>
+ branch<T>::branch(util::tree<T>& tree,
+ util::node<T>& apex)
+ : tree_(tree),
+ apex_(apex)
+ {
+ }
+
+
+ template <typename T>
+ util::node<T>&
+ branch<T>::apex()
+ {
+ return apex_;
+ }
+
+ template <typename T>
+ util::tree<T>&
+ branch<T>::tree()
+ {
+ return tree_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::util
Index: trunk/milena/mln/util/branch_iter.hh
===================================================================
--- trunk/milena/mln/util/branch_iter.hh (revision 0)
+++ trunk/milena/mln/util/branch_iter.hh (revision 1393)
@@ -0,0 +1,161 @@
+// 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_BRANCH_ITER_HH
+# define MLN_UTIL_BRANCH_ITER_HH
+
+# include <stack>
+# include <mln/util/tree.hh>
+/*!
+ * \file mln/util/branch.hh
+ *
+ * \brief Definition of a iterator on branch.
+ *
+ */
+
+namespace mln
+{
+
+ namespace util
+ {
+ template <typename T>
+ class branch_iter
+ {
+ public:
+ branch_iter(branch<T> branch);
+
+ /// Convertion to node.
+ operator node<T>&() const;
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next();
+
+
+ private:
+ util::branch<T> branch_;
+
+ typedef typename std::vector< util::node<T>* >::iterator child_iter;
+ typedef std::pair<child_iter, child_iter> iter_pair;
+ /// Store child().begin() and child().end().
+ std::stack< iter_pair > s_;
+
+ util::node<T>* n_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename T>
+ branch_iter<T>::branch_iter(branch<T> branch)
+ : branch_(branch)
+ {
+ invalidate();
+ }
+
+ template <typename T>
+ branch_iter<T>::operator node<T>&() const
+ {
+ mln_assertion(n_);
+ return *n_;
+ }
+
+ template <typename T>
+ bool
+ branch_iter<T>::is_valid() const
+ {
+ return n_ != 0;
+ }
+
+ template <typename T>
+ void
+ branch_iter<T>::invalidate()
+ {
+ n_ = 0;
+ }
+
+
+ template <typename T>
+ void
+ branch_iter<T>::start()
+ {
+ s_.push(iter_pair(branch_.apex().children().begin(),
+ branch_.apex().children().end()));
+ n_ = &branch_.apex();
+
+ //n_ = *(s_.top().first);
+ //s_.top().first++;
+ }
+
+ template <typename T>
+ void
+ branch_iter<T>::next()
+ {
+ if (s_.size() == 0)
+ invalidate();
+ else
+ {
+ if (s_.top().first == s_.top().second)
+ //if (*(s_.top().first) == 0)
+ {
+ mln_assertion(n_);
+ s_.pop();
+ next();
+ return;
+ }
+ else
+ {
+ n_ = *(s_.top().first);
+ s_.top().first++;
+
+ mln_assertion(n_);
+ if (n_->children().size() > 0)
+ s_.push(iter_pair(n_->children().begin(),
+ n_->children().end()));
+ return;
+ }
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ }
+
+} // end of namespace mln
+
+
+#endif // !MLN_UTIL_BRANCH_HH
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1392)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1393)
@@ -246,10 +246,10 @@
// FIXME : we can make it faster.
mln_piter(set_p<P>) p(R);
current_region = new fllt_node(P, V)();
- current_region->content().value = g;
+ current_region->elt().value = g;
for_all(p)
{
- current_region->content().points.insert(p);
+ current_region->elt().points.insert(p);
if (regions(p) == 0)
regions(p) = current_region;
else
@@ -281,7 +281,7 @@
// and which are the holes. Keep one pixel of each 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)));
+ current_region->elt().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
@@ -469,7 +469,7 @@
// debug::println(regions);
- //debug::println(ima | regions(make:defined reference to `mln::fllt::lower<mln::value::int_u<8u> >::inc':point2d(-4,-1))->content().points);
+ //debug::println(ima | regions(make:defined reference to `mln::fllt::lower<mln::value::int_u<8u> >::inc':point2d(-4,-1))->elt().points);
return (&tree);
@@ -530,10 +530,38 @@
static const neighb2d& reg_nbh() { return c8(); }
};
+
+// template <>
+// void find_shape_of_holes(fllt_node(P, V)* lower,
+// fllt_node(P, V)* upper)
+// {
+// }
+
template <typename P, typename V>
- void find_shapes_of_holes(fllt_node(P, V)* lower,
+ void merge_trees(fllt_node(P, V)* lower,
fllt_node(P, V)* upper)
{
+
+ // In order to merge the trees, we only have to find for each shape S
+ // with a hole H in it whether one of its children has a hole HŽ
+ // containing H. If it is the case, we do nothing. Otherwise, we
+ // put the shape of the hole H (and all its descendants) as child of
+ // the shape .
+
+ fllt_node(P, V)* it = lower;
+
+ if (lower->elt().holes.size() > 0)
+ {
+
+ }
+ // FIXME : add an method to tree to get the childen.
+ // FIXME : add an iterator to browse a tree.
+
+ mln_piter(set_p<P>) p(lower->child_);
+ for_all(p)
+ {
+ merge_trees(lower, upper);
+ }
}
template <typename V>
@@ -546,10 +574,9 @@
fllt_tree(P, V)* lower_tree;
lower_tree = compute_level_set<V, lower<V> >(ima);
+ upper_tree = compute_level_set<V, upper<V> >(ima);
- // upper_tree = compute_level_set<V, upper<V> >(ima);
-
- //find_shapes_of_holes(lower_tree, upper_tree);
+ merge_trees(lower_tree, upper_tree);
}
} // end of namespace mln::fllt
2
1
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix use of tree.
* mln/util/tree.hh,
* mln/util/tree_to_image.hh,
* sandbox/garrigues/fllt.hh: Fix.
---
mln/util/tree.hh | 11 ++++-------
mln/util/tree_to_image.hh | 10 +++++-----
sandbox/garrigues/fllt.hh | 2 +-
3 files changed, 10 insertions(+), 13 deletions(-)
Index: trunk/milena/mln/util/tree_to_image.hh
===================================================================
--- trunk/milena/mln/util/tree_to_image.hh (revision 1393)
+++ trunk/milena/mln/util/tree_to_image.hh (revision 1394)
@@ -62,15 +62,15 @@
I& output = exact(output_);
- mln_piter(set_p<point2d>) p(node->elt_.points);
+ mln_piter(set_p<point2d>) p(node->elt().points);
for_all(p)
- output(p) = node->elt_.value;
+ output(p) = node->elt().value;
- typename std::vector< util::node<T>* >::const_iterator it = node->child_.begin();
+ typename std::vector< util::node<T>* >::const_iterator it = node->children().begin();
for (int i = 0;
- it != node->child_.end();
+ it != node->children().end();
++it, ++i)
{
if (*it)
@@ -84,7 +84,7 @@
tree_to_image (tree<T>& tree, Image<I>& output_)
{
I& output = exact(output_);
- tree_to_image_rec(tree.root_, output);
+ tree_to_image_rec(tree.root(), output);
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1393)
+++ trunk/milena/mln/util/tree.hh (revision 1394)
@@ -95,7 +95,7 @@
tree();
tree(node<T>* root);
- tree<T>* tree_get(T& elt);
+ node<T>* root();
void add_tree_up (T& elt);
void add_tree_down (T& elt);
@@ -135,13 +135,10 @@
}
template <typename T>
- tree<T>*
- tree<T>::tree_get(T& elt)
+ node<T>*
+ tree<T>::root()
{
- node<T>* n = root_->search(elt);
- tree<T>* res = new tree (n);
-
- return res;
+ return root_;
}
template <typename T>
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1393)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1394)
@@ -576,7 +576,7 @@
lower_tree = compute_level_set<V, lower<V> >(ima);
upper_tree = compute_level_set<V, upper<V> >(ima);
- merge_trees(lower_tree, upper_tree);
+ //merge_trees(lower_tree, upper_tree);
}
} // end of namespace mln::fllt
2
1
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix tree.
* mln/util/branch_iter.hh,
* mln/util/tree.hh,
* tests/tree.cc: Fix.
---
mln/util/branch_iter.hh | 2 +-
mln/util/tree.hh | 31 +++++++++++++++++++++++--------
tests/tree.cc | 2 --
3 files changed, 24 insertions(+), 11 deletions(-)
Index: trunk/milena/tests/tree.cc
===================================================================
--- trunk/milena/tests/tree.cc (revision 1394)
+++ trunk/milena/tests/tree.cc (revision 1395)
@@ -60,6 +60,4 @@
util::tree<unsigned>* tre = new util::tree<unsigned>(&node);
mln_assertion(tre);
tre->add_tree_up(elt6);
- util::tree<unsigned>* trees = tre->tree_get(elt5);
- mln_assertion(trees);
}
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1394)
+++ trunk/milena/mln/util/tree.hh (revision 1395)
@@ -55,6 +55,7 @@
{
public:
+ typedef std::vector< node<T>* > children_t;
/// \{ Constructors
node();
node(T elt);
@@ -66,15 +67,15 @@
/// \}
/// Access to the children
- const std::vector< node<T>* >& children() const;
- std::vector< node<T>* >& children();
+ const children_t& children() const;
+ children_t& children();
/// Access to the parent node.
+ //node<T>*& parent();
const node<T>* parent() const;
node<T>* add_child(T elt);
void set_parent(node<T>* parent);
- node<T>* get_parent();
void print_rec(int n) const;
void print() const;
int search_rec(node<T>** res, T& elt);
@@ -96,6 +97,7 @@
tree(node<T>* root);
node<T>* root();
+ branch<T> main_branch();
void add_tree_up (T& elt);
void add_tree_down (T& elt);
@@ -142,12 +144,19 @@
}
template <typename T>
+ branch<T>
+ tree<T>::main_branch()
+ {
+ return branch<T>(*this, root());
+ }
+
+ template <typename T>
void
tree<T>::add_tree_up(T& elt)
{
node<T>* n = new node<T> (elt);
- root_->parent_ = n;
- n->child_.push_back (root_);
+ root_->set_parent(n);
+ n->children().push_back (root_);
root_ = n;
}
@@ -222,14 +231,20 @@
parent->child_.push_back(this);
}
-
template <typename T>
- node<T>*
- node<T>::get_parent()
+ const node<T>*
+ node<T>::parent() const
{
return parent_;
}
+// template <typename T>
+// node<T>*&
+// node<T>::parent()
+// {
+// return parent_;
+// }
+
template <typename T>
int
node<T>::search_rec(node<T>** res, T& elt)
Index: trunk/milena/mln/util/branch_iter.hh
===================================================================
--- trunk/milena/mln/util/branch_iter.hh (revision 1394)
+++ trunk/milena/mln/util/branch_iter.hh (revision 1395)
@@ -49,7 +49,7 @@
branch_iter(branch<T> branch);
/// Convertion to node.
- operator node<T>&() const;
+ operator util::node<T>&() const;
/// Test the iterator validity.
bool is_valid() const;
2
1
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix warnings in some tests.
* tests/border_resize_sub_image.cc,
* tests/branch_iter.cc: Fix.
---
border_resize_sub_image.cc | 2 +-
branch_iter.cc | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/border_resize_sub_image.cc
===================================================================
--- trunk/milena/tests/border_resize_sub_image.cc (revision 1395)
+++ trunk/milena/tests/border_resize_sub_image.cc (revision 1396)
@@ -60,7 +60,7 @@
typedef image2d<int> I;
unsigned border = 42;
- unsigned new_border = 51;
+ //unsigned new_border = 51;
box2d b(literal::origin, point2d(1,1));
I ima(3,3, border);
Index: trunk/milena/tests/branch_iter.cc
===================================================================
--- trunk/milena/tests/branch_iter.cc (revision 1395)
+++ trunk/milena/tests/branch_iter.cc (revision 1396)
@@ -47,7 +47,7 @@
util::node<int>* f = n.add_child(42);
util::node<int>* g = f->add_child(421);
- util::node<int>* h = f->add_child(422);
+ f->add_child(422);
g->add_child(4211)->add_child(51)->add_child(52)->add_child(53)->add_child(54)->add_child(55);
g->add_child(4212);
2
1
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix warnings.
* mln/util/tree.hh: Fix
---
tree.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1396)
+++ trunk/milena/mln/util/tree.hh (revision 1397)
@@ -116,8 +116,8 @@
tree<T>& tree();
private:
- node<T>& apex_;
util::tree<T>& tree_;
+ node<T>& apex_;
};
2
1
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Improve fllt. Add more tests.
* mln/set/is_subset_of.hh: New, Test if a point set is a subset of
another.
* mln/util/branch_iter.hh: Update
* mln/util/tree.hh: (tree<T>::add_child(node<T>*)) New,
(tree<T>::main_branch()) New.
* sandbox/garrigues/fllt.hh: Improve fllt.
* sandbox/garrigues/test_fllt.cc: Update
* sandbox/garrigues/test_fllt2.cc,
* sandbox/garrigues/test_fllt3.cc,
* sandbox/garrigues/test_fllt4.cc,
* sandbox/garrigues/test_fllt5.cc,
* sandbox/garrigues/test_fllt_tiny.cc: New, differents cases of tests
for fllt.
---
mln/set/is_subset_of.hh | 75 +++++++++++++++++
mln/util/branch_iter.hh | 17 +++
mln/util/tree.hh | 22 ++++-
sandbox/garrigues/fllt.hh | 156 ++++++++++++++++++++++++++++--------
sandbox/garrigues/test_fllt.cc | 44 +++++-----
sandbox/garrigues/test_fllt2.cc | 40 +++++++++
sandbox/garrigues/test_fllt3.cc | 40 +++++++++
sandbox/garrigues/test_fllt4.cc | 40 +++++++++
sandbox/garrigues/test_fllt5.cc | 40 +++++++++
sandbox/garrigues/test_fllt_tiny.cc | 24 +++++
10 files changed, 439 insertions(+), 59 deletions(-)
Index: trunk/milena/mln/set/is_subset_of.hh
===================================================================
--- trunk/milena/mln/set/is_subset_of.hh (revision 0)
+++ trunk/milena/mln/set/is_subset_of.hh (revision 1399)
@@ -0,0 +1,75 @@
+// 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_SET_IS_SUBSET_OF_HH
+# define MLN_SET_IS_SUBSET_OF_HH
+
+# include <mln/core/concept/point_set.hh>
+
+namespace mln
+{
+
+ namespace set
+ {
+ /*! \brief Test if a point set is a subset of another point set.
+ *
+ * \relates mln::Point_Set
+ */
+ template <typename Pl, typename Pr>
+ bool
+ is_subset_of(const Point_Set<Pl>& lhs, const Point_Set<Pr>& rhs);
+
+# ifndef MLN_INCLUDE_ONL
+
+ template <typename Pl, typename Pr>
+ bool
+ is_subset_of(const Point_Set<Pl>& lhs_, const Point_Set<Pr>& rhs_)
+ {
+ Pl lhs = exact(lhs_);
+ Pr rhs = exact(rhs_);
+
+ if (lhs.npoints() > rhs.npoints())
+ return false;
+
+ mln_piter(Pl) p(lhs);
+ for_all(p)
+ {
+ if (!rhs.has(p))
+ return false;
+ }
+ return true;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::set
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SET_SUBSET_HH
Index: trunk/milena/mln/util/tree.hh
===================================================================
--- trunk/milena/mln/util/tree.hh (revision 1398)
+++ trunk/milena/mln/util/tree.hh (revision 1399)
@@ -71,10 +71,14 @@
children_t& children();
/// Access to the parent node.
+ node<T>* parent();
//node<T>*& parent();
- const node<T>* parent() const;
+ /// \{ Add a child to the node
node<T>* add_child(T elt);
+ node<T>* add_child(node<T>* node);
+ /// \}
+
void set_parent(node<T>* parent);
void print_rec(int n) const;
void print() const;
@@ -147,7 +151,7 @@
branch<T>
tree<T>::main_branch()
{
- return branch<T>(*this, root());
+ return branch<T>(*this, *root());
}
template <typename T>
@@ -222,6 +226,16 @@
return s;
}
+
+ template <typename T>
+ node<T>*
+ node<T>::add_child(node<T>* node)
+ {
+ node->parent_ = this;
+ this->children().push_back(node);
+ return node;
+ }
+
template <typename T>
void
node<T>::set_parent(node<T>* parent)
@@ -232,8 +246,8 @@
}
template <typename T>
- const node<T>*
- node<T>::parent() const
+ node<T>*
+ node<T>::parent()
{
return parent_;
}
Index: trunk/milena/mln/util/branch_iter.hh
===================================================================
--- trunk/milena/mln/util/branch_iter.hh (revision 1398)
+++ trunk/milena/mln/util/branch_iter.hh (revision 1399)
@@ -50,6 +50,7 @@
/// Convertion to node.
operator util::node<T>&() const;
+ util::node<T>& operator *();
/// Test the iterator validity.
bool is_valid() const;
@@ -94,6 +95,14 @@
}
template <typename T>
+ util::node<T>&
+ branch_iter<T>::operator*()
+ {
+ mln_assertion(n_);
+ return *n_;
+ }
+
+ template <typename T>
bool
branch_iter<T>::is_valid() const
{
@@ -131,7 +140,6 @@
if (s_.top().first == s_.top().second)
//if (*(s_.top().first) == 0)
{
- mln_assertion(n_);
s_.pop();
next();
return;
@@ -141,6 +149,13 @@
n_ = *(s_.top().first);
s_.top().first++;
+ if (!n_)
+ {
+ std::cout << "browsing warning : nul pointer" << std::endl;
+ next();
+ return;
+ }
+
mln_assertion(n_);
if (n_->children().size() > 0)
s_.push(iter_pair(n_->children().begin(),
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1398)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1399)
@@ -61,8 +61,10 @@
# include <mln/set/uni.hh>
# include <mln/set/diff.hh>
# include <mln/set/inter.hh>
+# include <mln/set/is_subset_of.hh>
# include <mln/util/tree.hh>
+# include <mln/util/branch_iter.hh>
# include <mln/labeling/regional_minima.hh>
# include <mln/labeling/regional_maxima.hh>
@@ -84,15 +86,18 @@
{
template <typename P, typename V>
- struct fllt_node
+ struct fllt_node_elt
{
V value;
set_p<P> points;
set_p<P> holes;
};
- # define fllt_tree(P, V) util::tree< fllt_node<P, V> >
- # define fllt_node(P, V) util::node< fllt_node<P, V> >
+ # define fllt_tree(P, V) util::tree< fllt_node_elt<P, V> >
+ # define fllt_node(P, V) util::node< fllt_node_elt<P, V> >
+ # define fllt_branch(P, V) util::branch< fllt_node_elt<P, V> >
+ # define fllt_branch_iter(P, V) util::branch_iter< fllt_node_elt<P, V> >
+
// # define fllt_node(P, V) typename fllt_tree(P, V)::node_t
@@ -254,7 +259,7 @@
regions(p) = current_region;
else
{
- if (regions(p)->get_parent() == 0)
+ if (regions(p)->parent() == 0)
regions(p)->set_parent(current_region);
}
}
@@ -356,8 +361,9 @@
template <typename V, typename F>
- fllt_tree(point2d, V)*
- compute_level_set(const image2d<V>& ima)
+ fllt_tree(point2d, V)&
+ compute_level_set(const image2d<V>& ima,
+ image2d< fllt_node(point2d, V)* >& regions)
{
typedef point2d P;
typedef image2d<V> I;
@@ -369,6 +375,9 @@
mln::pw::cst_<int> >
> I_IF;
+ // Check
+ mln_assertion(ima.domain() == regions.domain());
+
// Declarations.
set_p<P> R, N, A;
V g, gn;
@@ -381,7 +390,6 @@
// debug::println_with_border(u);
image2d<bool> tagged(ima.domain());
fllt_node(P, V)* current_region;
- image2d<fllt_node(P, V)*> regions(ima.domain());
// INIT
R.clear();
@@ -471,7 +479,7 @@
// debug::println(regions);
//debug::println(ima | regions(make:defined reference to `mln::fllt::lower<mln::value::int_u<8u> >::inc':point2d(-4,-1))->elt().points);
- return (&tree);
+ return (tree);
} // end of compute_level_set
@@ -530,16 +538,71 @@
static const neighb2d& reg_nbh() { return c8(); }
};
+ template <typename P, typename V>
+ void
+ move_shape(fllt_node(P, V)& node,
+ fllt_node(P, V)& hole,
+ fllt_tree(P, V)& tree,
+ const image2d<fllt_node(P, V)*>& other_reg)
+ {
+ fill_a_shape(hole, tree, other_reg);
+ node.elt().points = set::uni(hole.elt().points, node.elt().points);
+ node.add_child(&hole);
+ }
-// template <>
-// void find_shape_of_holes(fllt_node(P, V)* lower,
-// fllt_node(P, V)* upper)
-// {
-// }
+ template <typename P, typename V>
+ fllt_node(P, V)*
+ find_the_hole(fllt_node(P, V)& node,
+ const P p,
+ const image2d<fllt_node(P, V)*>& other_reg)
+ {
+ fllt_node(P, V)* s = other_reg(p);
+
+ mln_assertion(s);
+ while (s->parent() && (s->parent()->elt().value < node.elt().value))
+ {
+ mln_assertion(s);
+ s = s->parent();
+ mln_assertion(s);
+ }
+ return s;
+ }
+
+ template <typename P, typename V>
+ void
+ fill_a_shape(fllt_node(P, V)& node,
+ fllt_tree(P, V)& tree,
+ const image2d<fllt_node(P, V)*>& other_reg)
+ {
+ mln_piter(set_p<P>) p(node.elt().holes);
+ for_all(p)
+ {
+ bool h = true;
+ fllt_node(P, V)* hole = find_the_hole(node, point2d(p), other_reg);
+ typename fllt_node(P, V)::children_t::iterator it;
+ for (it = node.children().begin();
+ it != node.children().end();
+ it++)
+ {
+ if (set::is_subset_of(hole->elt().points,
+ (*it)->elt().points))
+ {
+ h = false;
+ break;
+ }
+ }
+ if (h)
+ move_shape(node, *hole, tree, other_reg);
+
+ }
+ }
template <typename P, typename V>
- void merge_trees(fllt_node(P, V)* lower,
- fllt_node(P, V)* upper)
+ void
+ merge_trees(fllt_tree(P, V)& lower,
+ fllt_tree(P, V)& upper,
+ const image2d<fllt_node(P, V)*>& low_reg,
+ const image2d<fllt_node(P, V)*>& upp_reg)
{
// In order to merge the trees, we only have to find for each shape S
@@ -548,35 +611,64 @@
// put the shape of the hole H (and all its descendants) as child of
// the shape .
- fllt_node(P, V)* it = lower;
-
- if (lower->elt().holes.size() > 0)
- {
-
- }
- // FIXME : add an method to tree to get the childen.
- // FIXME : add an iterator to browse a tree.
-
- mln_piter(set_p<P>) p(lower->child_);
+ fllt_branch_iter(P, V) p(lower.main_branch());
for_all(p)
{
- merge_trees(lower, upper);
+ fllt_node(P, V)& n(p);
+ fill_a_shape(n, lower, upp_reg);
}
+// fllt_branch_iter(P, V) q(upper.main_branch());
+// for_all(q)
+// {
+// fllt_node(P, V)& n(p);
+// fill_a_shape(n, upper, low_reg);
+// }
}
template <typename V>
// Fixme : return type
- void fllt(const image2d<V>& ima)
+ void
+ fllt(const image2d<V>& ima)
{
typedef point2d P;
- fllt_tree(P, V)* upper_tree;
- fllt_tree(P, V)* lower_tree;
+ fllt_tree(P, V) upper_tree;
+ fllt_tree(P, V) lower_tree;
+ image2d<fllt_node(P, V)*> low_reg(ima.domain());
+ image2d<fllt_node(P, V)*> upp_reg(ima.domain());
+
+ lower_tree = compute_level_set<V, lower<V> >(ima, low_reg);
+ upper_tree = compute_level_set<V, upper<V> >(ima, upp_reg);
- lower_tree = compute_level_set<V, lower<V> >(ima);
- upper_tree = compute_level_set<V, upper<V> >(ima);
+ merge_trees(lower_tree, upper_tree, low_reg, upp_reg);
- //merge_trees(lower_tree, upper_tree);
+
+
+ image2d<value::int_u8> output (ima.domain ());
+ util::tree_to_image (lower_tree, output);
+
+ if (output != ima)
+ {
+ std::cerr << "BUG!!!" << std::endl;
+ abort();
+ }
+
+ io::pgm::save(output, "out_final.pgm");
+ std::cout << "out_final.pgm generate"
+ << std::endl;
+
+
+ fllt_branch_iter(P, V) p(lower_tree.main_branch());
+ for_all(p)
+ {
+ std::cout << "region mere : " << (*p).parent() << std::endl;
+ std::cout << " ^" << std::endl;
+ std::cout << " |" << std::endl;
+ std::cout << "region : " << &*p << std::endl;
+
+ debug::println(ima | (*p).elt().points);
+ std::cout << std::endl;
+ }
}
} // end of namespace mln::fllt
Index: trunk/milena/sandbox/garrigues/test_fllt.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1398)
+++ trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1399)
@@ -15,26 +15,26 @@
using namespace mln;
-// int ws[81] = {3,2,3,3,5,5,5,5,5,
-// 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,3,4,3,2,5,1,
-// 1,3,4,3,4,3,2,5,1,
-// 1,3,3,3,4,3,2,5,1,
-// 1,3,3,4,2,3,2,1,1};
-
-// w_window2d_int w_win = make::w_window2d(ws);
-// image2d<int> ima = convert::to_image(w_win);
-//fllt::fllt(ima);
-
-
- image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
-
- image2d<int> ima_int(ima.domain());
-
-level::fill(ima_int, ima);
- debug::println(ima);
- fllt::fllt(ima_int);
+ int ws[81] = {3,2,3,3,5,5,5,5,5,
+ 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,3,4,3,2,5,1,
+ 1,3,4,3,4,3,2,5,1,
+ 1,3,3,3,4,3,2,5,1,
+ 1,3,3,4,2,3,2,1,1};
+
+ w_window2d_int w_win = make::w_window2d(ws);
+ image2d<int> ima = convert::to_image(w_win);
+fllt::fllt(ima);
+
+
+// image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
+
+// image2d<int> ima_int(ima.domain());
+
+// level::fill(ima_int, ima);
+// debug::println(ima);
+// fllt::fllt(ima_int);
}
Index: trunk/milena/sandbox/garrigues/test_fllt2.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt2.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/test_fllt2.cc (revision 1399)
@@ -0,0 +1,40 @@
+# include "fllt.hh"
+# include <mln/core/image2d.hh>
+# include <mln/core/clone.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/debug/println.hh>
+# include <mln/convert/to_w_window.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/convert/to_image.hh>
+# include <mln/level/fill.hh>
+# include <mln/io/pgm/load.hh>
+# include <mln/io/pbm/load.hh>
+
+int main()
+{
+
+ using namespace mln;
+
+ int ws[81] = {5,5,5,5,5,5,5,5,5,
+ 5,5,5,5,5,5,5,5,5,
+ 5,5,5,5,5,5,8,8,5,
+ 5,5,1,1,1,5,8,8,5,
+ 5,5,1,1,1,5,8,8,5,
+ 5,5,1,1,1,5,8,8,5,
+ 5,5,5,5,5,5,8,8,5,
+ 5,5,5,5,5,5,5,5,5,
+ 5,5,5,5,5,5,5,5,5};
+
+ w_window2d_int w_win = make::w_window2d(ws);
+ image2d<int> ima = convert::to_image(w_win);
+fllt::fllt(ima);
+
+
+// image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
+
+// image2d<int> ima_int(ima.domain());
+
+// level::fill(ima_int, ima);
+// debug::println(ima);
+// fllt::fllt(ima_int);
+}
Index: trunk/milena/sandbox/garrigues/test_fllt3.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt3.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/test_fllt3.cc (revision 1399)
@@ -0,0 +1,40 @@
+# include "fllt.hh"
+# include <mln/core/image2d.hh>
+# include <mln/core/clone.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/debug/println.hh>
+# include <mln/convert/to_w_window.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/convert/to_image.hh>
+# include <mln/level/fill.hh>
+# include <mln/io/pgm/load.hh>
+# include <mln/io/pbm/load.hh>
+
+int main()
+{
+
+ using namespace mln;
+
+ int ws[81] = {2,2,2,2,2,2,2,2,2,
+ 2,2,2,2,2,2,2,2,2,
+ 2,1,1,1,1,1,1,1,2,
+ 2,1,2,2,1,0,0,1,2,
+ 2,1,2,2,1,0,0,1,2,
+ 2,1,2,2,1,0,0,1,2,
+ 2,1,1,1,1,1,1,1,2,
+ 2,1,1,1,1,1,1,1,2,
+ 2,2,2,2,2,2,2,2,2};
+
+ w_window2d_int w_win = make::w_window2d(ws);
+ image2d<int> ima = convert::to_image(w_win);
+fllt::fllt(ima);
+
+
+// image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
+
+// image2d<int> ima_int(ima.domain());
+
+// level::fill(ima_int, ima);
+// debug::println(ima);
+// fllt::fllt(ima_int);
+}
Index: trunk/milena/sandbox/garrigues/test_fllt_tiny.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt_tiny.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/test_fllt_tiny.cc (revision 1399)
@@ -0,0 +1,24 @@
+# include "fllt.hh"
+# include <mln/core/image2d.hh>
+# include <mln/core/clone.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/debug/println.hh>
+# include <mln/convert/to_w_window.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/convert/to_image.hh>
+# include <mln/level/fill.hh>
+# include <mln/io/pgm/load.hh>
+# include <mln/io/pbm/load.hh>
+
+int main()
+{
+
+ using namespace mln;
+
+ image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
+
+ image2d<int> ima_int(ima.domain());
+
+ level::fill(ima_int, ima);
+ fllt::fllt(ima_int);
+}
Index: trunk/milena/sandbox/garrigues/test_fllt4.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt4.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/test_fllt4.cc (revision 1399)
@@ -0,0 +1,40 @@
+# include "fllt.hh"
+# include <mln/core/image2d.hh>
+# include <mln/core/clone.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/debug/println.hh>
+# include <mln/convert/to_w_window.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/convert/to_image.hh>
+# include <mln/level/fill.hh>
+# include <mln/io/pgm/load.hh>
+# include <mln/io/pbm/load.hh>
+
+int main()
+{
+
+ using namespace mln;
+
+ int ws[81] = {5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1,
+ 5,5,5,5,5,1,1,1,1};
+
+ w_window2d_int w_win = make::w_window2d(ws);
+ image2d<int> ima = convert::to_image(w_win);
+fllt::fllt(ima);
+
+
+// image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
+
+// image2d<int> ima_int(ima.domain());
+
+// level::fill(ima_int, ima);
+// debug::println(ima);
+// fllt::fllt(ima_int);
+}
Index: trunk/milena/sandbox/garrigues/test_fllt5.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt5.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/test_fllt5.cc (revision 1399)
@@ -0,0 +1,40 @@
+# include "fllt.hh"
+# include <mln/core/image2d.hh>
+# include <mln/core/clone.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/debug/println.hh>
+# include <mln/convert/to_w_window.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/convert/to_image.hh>
+# include <mln/level/fill.hh>
+# include <mln/io/pgm/load.hh>
+# include <mln/io/pbm/load.hh>
+
+int main()
+{
+
+ using namespace mln;
+
+ int ws[81] = {5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1,
+ 5,5,5,2,2,2,1,1,1};
+
+ w_window2d_int w_win = make::w_window2d(ws);
+ image2d<int> ima = convert::to_image(w_win);
+fllt::fllt(ima);
+
+
+// image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
+
+// image2d<int> ima_int(ima.domain());
+
+// level::fill(ima_int, ima);
+// debug::println(ima);
+// fllt::fllt(ima_int);
+}
2
1
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-26 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Update fllt.
* mln/util/branch_iter.hh: (deepness) New.
* sandbox/garrigues/fllt.hh: More output. FIXME : optimize.
---
mln/util/branch_iter.hh | 35 ++++++++++++++-
sandbox/garrigues/fllt.hh | 102 +++++++++++++++++++++++++++++++++++++---------
2 files changed, 116 insertions(+), 21 deletions(-)
Index: trunk/milena/mln/util/branch_iter.hh
===================================================================
--- trunk/milena/mln/util/branch_iter.hh (revision 1399)
+++ trunk/milena/mln/util/branch_iter.hh (revision 1400)
@@ -64,7 +64,8 @@
/// Go to the next point.
void next();
-
+ /// Give how deep is the iterator in the branch.
+ unsigned deepness() const;
private:
util::branch<T> branch_;
@@ -74,6 +75,8 @@
std::stack< iter_pair > s_;
util::node<T>* n_;
+ unsigned deepness_;
+ unsigned futur_deepness_;
};
@@ -103,6 +106,24 @@
}
template <typename T>
+ unsigned
+ branch_iter<T>::deepness() const
+ {
+ mln_assertion(is_valid());
+ //return s_.size();
+
+ unsigned i = 0;
+ node<T>* p = n_;
+ while (p)
+ {
+ p = p->parent();
+ i++;
+ }
+ return i;
+ // return deepness_;
+ }
+
+ template <typename T>
bool
branch_iter<T>::is_valid() const
{
@@ -121,6 +142,7 @@
void
branch_iter<T>::start()
{
+ deepness_ = 0;
s_.push(iter_pair(branch_.apex().children().begin(),
branch_.apex().children().end()));
n_ = &branch_.apex();
@@ -140,26 +162,35 @@
if (s_.top().first == s_.top().second)
//if (*(s_.top().first) == 0)
{
+ deepness_ = futur_deepness_;
+ //deepness_--;
+ futur_deepness_ = deepness_;
+// std::cout << "dec :" << deepness_ << std::endl;
s_.pop();
next();
return;
}
else
{
+ deepness_ = futur_deepness_;
+// std::cout << "st :" << deepness_ << std::endl;
n_ = *(s_.top().first);
s_.top().first++;
if (!n_)
{
- std::cout << "browsing warning : nul pointer" << std::endl;
+// std::cout << "browsing warning : nul pointer" << std::endl;
next();
return;
}
mln_assertion(n_);
if (n_->children().size() > 0)
+ {
+ futur_deepness_ = deepness_ + 1;
s_.push(iter_pair(n_->children().begin(),
n_->children().end()));
+ }
return;
}
}
Index: trunk/milena/sandbox/garrigues/fllt.hh
===================================================================
--- trunk/milena/sandbox/garrigues/fllt.hh (revision 1399)
+++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1400)
@@ -266,8 +266,8 @@
// Count the number of conected components of the border of R.
- image2d<int> tmp(u.domain().to_larger(1));
- image2d<bool> border_ima(tmp.domain());
+ static image2d<int> tmp(u.domain().to_larger(1));
+ static image2d<bool> border_ima(tmp.domain());
level::fill(border_ima, false);
level::fill(inplace(border_ima | N), true);
unsigned n;
@@ -401,7 +401,6 @@
level::fill(regions, 0);
level::fill(tagged, false);
- level::fill(min_locals, 0);
// Get the locals extremums
unsigned nlabels;
@@ -461,9 +460,9 @@
util::tree_to_image (tree, output);
- debug::println(output);
- std::cout << std::endl;
- debug::println(ima);
+// debug::println(output);
+// std::cout << std::endl;
+// debug::println(ima);
if (output != ima)
{
@@ -625,6 +624,54 @@
// }
}
+
+ template <typename P, typename V>
+ void
+ visualize_deepness(image2d<value::int_u8>& output,
+ fllt_tree(P, V)& tree)
+ {
+ fllt_branch_iter(P, V) p(tree.main_branch());
+ level::fill(output, 0);
+ for_all(p)
+ {
+ //std::cout << (&*p) << ":" << p.deepness() << std::endl;
+ mln_piter(set_p<point2d>) q((*p).elt().points);
+ for_all(q)
+ {
+ if (output(q) < p.deepness())
+ output(q) = p.deepness();
+ }
+ }
+ }
+
+
+ template <typename P, typename V>
+ void
+ visualize_bounds(image2d<value::int_u8>& output,
+ fllt_tree(P, V)& tree,
+ unsigned limit)
+ {
+ fllt_branch_iter(P, V) p(tree.main_branch());
+ level::fill(output, 255);
+ for_all(p)
+ {
+ if ((*p).elt().points.npoints() > limit)
+ {
+ mln_piter(set_p<point2d>) q((*p).elt().points);
+ for_all(q)
+ {
+ mln_niter(neighb2d) n(c4(), q);
+ bool is_border = false;
+ for_all (n)
+ if (!((*p).elt().points).has (n))
+ is_border = true;
+ if (is_border)
+ output(q) = 0;
+ }
+ }
+ }
+ }
+
template <typename V>
// Fixme : return type
void
@@ -637,12 +684,16 @@
image2d<fllt_node(P, V)*> low_reg(ima.domain());
image2d<fllt_node(P, V)*> upp_reg(ima.domain());
+ std::cout << "1/ Compute the lower level set." << std::endl;
lower_tree = compute_level_set<V, lower<V> >(ima, low_reg);
+ std::cout << "2/ Compute the upper level set." << std::endl;
upper_tree = compute_level_set<V, upper<V> >(ima, upp_reg);
+ std::cout << "3/ Merge the two trees." << std::endl;
merge_trees(lower_tree, upper_tree, low_reg, upp_reg);
+ std::cout << "4/ Generate outputs." << std::endl;
image2d<value::int_u8> output (ima.domain ());
util::tree_to_image (lower_tree, output);
@@ -653,22 +704,35 @@
abort();
}
- io::pgm::save(output, "out_final.pgm");
- std::cout << "out_final.pgm generate"
- << std::endl;
+// io::pgm::save(output, "out_final.pgm");
+// std::cout << "out_final.pgm generate"
+// << std::endl;
- fllt_branch_iter(P, V) p(lower_tree.main_branch());
- for_all(p)
- {
- std::cout << "region mere : " << (*p).parent() << std::endl;
- std::cout << " ^" << std::endl;
- std::cout << " |" << std::endl;
- std::cout << "region : " << &*p << std::endl;
+// fllt_branch_iter(P, V) p(lower_tree.main_branch());
+// for_all(p)
+// {
+// std::cout << "region mere : " << (*p).parent() << std::endl;
+// std::cout << " ^" << std::endl;
+// std::cout << " |" << std::endl;
+// std::cout << "region : " << &*p << std::endl;
- debug::println(ima | (*p).elt().points);
- std::cout << std::endl;
- }
+// debug::println(ima | (*p).elt().points);
+// std::cout << std::endl;
+// }
+
+// image2d<value::int_u8> viz(ima.domain());
+// image2d<value::int_u8> viz2(ima.domain());
+
+// visualize_deepness(viz, lower_tree);
+// level::stretch(viz, viz2);
+// debug::println(viz);
+// debug::println(viz2);
+// io::pgm::save(viz2, "fllt.pgm");
+
+// visualize_bounds(viz, lower_tree, 2000);
+// debug::println(viz);
+// io::pgm::save(viz, "fllt_bounds.pgm");
}
} // end of namespace mln::fllt
2
1
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-29 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update test for fllt.
* test_fllt.cc: Update.
---
test_fllt.cc | 52 ++++++++++++++++++++++++++++++----------------------
1 file changed, 30 insertions(+), 22 deletions(-)
Index: trunk/milena/sandbox/garrigues/test_fllt.cc
===================================================================
--- trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1400)
+++ trunk/milena/sandbox/garrigues/test_fllt.cc (revision 1401)
@@ -9,32 +9,40 @@
# include <mln/level/fill.hh>
# include <mln/io/pgm/load.hh>
# include <mln/io/pbm/load.hh>
+# include <sstream>
+
int main()
{
using namespace mln;
- int ws[81] = {3,2,3,3,5,5,5,5,5,
- 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,3,4,3,2,5,1,
- 1,3,4,3,4,3,2,5,1,
- 1,3,3,3,4,3,2,5,1,
- 1,3,3,4,2,3,2,1,1};
-
- w_window2d_int w_win = make::w_window2d(ws);
- image2d<int> ima = convert::to_image(w_win);
-fllt::fllt(ima);
-
-
-// image2d<value::int_u8> ima = io::pgm::load("../../img/tiny.pgm");
-
-// image2d<int> ima_int(ima.domain());
-
-// level::fill(ima_int, ima);
-// debug::println(ima);
-// fllt::fllt(ima_int);
+// int ws[81] = {3,2,3,3,5,5,5,5,5,
+// 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,3,4,3,2,5,1,
+// 1,3,4,3,4,3,2,5,1,
+// 1,3,3,3,4,3,2,5,1,
+// 1,3,3,4,2,3,2,1,1};
+
+// w_window2d_int w_win = make::w_window2d(ws);
+// image2d<int> ima = convert::to_image(w_win);
+// fllt::fllt(ima);
+
+
+ for (int i = 1; i < 16; ++i)
+ for (int j = 1; j < 16; ++j)
+ {
+ std::stringstream path;
+ path << "/lrde/tegucigalpa/theo/pub/mln_docs/lena_tiles/lena_" << i << "_" << j << ".pgm";
+ std::cout << path.str () << std::endl;
+ image2d<value::int_u8> ima = io::pgm::load(path.str());
+ image2d<int> ima_int(ima.domain());
+ level::fill(ima_int, ima);
+ debug::println(ima_int);
+ fllt::fllt(ima_int);
+ }
+
}
2
1
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Get rid of Generalized_Point, replaced by Point_Site.
* mln/core/concept/point_iterator.hh: Change inheritance
from Iterator to Point_Site.
* mln/core/concept/doc/generalized_point.hh: Rename as...
* mln/core/concept/doc/point_site.hh: ...this; update.
Then update.
* tests/rle_image.cc: Add todo.
* mln/core/internal/point_iterator_base.hh
(operator[]): New.
* mln/core/rle_image.hh: Conform to style.
* mln/core/concept/generalized_point.hh: Remove.
* mln/core/concept/delta_point_site.hh: New.
* mln/core/concept/point.hh (Point<void>): New.
* mln/core/concept/dpoint.hh (Dpoint<void>): New.
(operator): Remove all; obsolete.
* mln/value/concept/built_in.hh: Add comment.
* mln/core/dpoints_piter.hh,
* mln/core/mesh_psite.hh,
* mln/core/window.hh,
* mln/core/dpoints_pixter.hh,
* mln/core/mesh_p.hh,
* mln/core/internal/piter_adaptor.hh,
* mln/core/internal/run_pset.hh,
* mln/core/internal/run_psite.hh,
* mln/core/internal/check/image_fastest.hh,
* mln/core/mesh_p_piter.hh,
* mln/core/line_piter.hh,
* mln/core/vec_p_piter.hh,
* mln/core/box_piter.hh,
* mln/core/concept/dpoint.hh,
* mln/core/concept/value_iterator.hh,
* mln/core/concept/point.hh,
* mln/core/concept/point_set.hh,
* mln/core/concept/point_site.hh,
* mln/linear/local/convolve.hh,
* mln/convert/to_window.hh,
* mln/convert/to_set_p.hh,
* mln/convert/to_dpoint.hh: Update.
mln/convert/to_dpoint.hh | 12 -
mln/convert/to_set_p.hh | 4
mln/convert/to_window.hh | 5
mln/core/box_piter.hh | 20 +-
mln/core/concept/delta_point_site.hh | 218 +++++++++++++++++++++++
mln/core/concept/doc/point_site.hh | 32 +--
mln/core/concept/dpoint.hh | 151 +---------------
mln/core/concept/point.hh | 80 +++++---
mln/core/concept/point_iterator.hh | 40 +++-
mln/core/concept/point_set.hh | 2
mln/core/concept/point_site.hh | 286 ++++++++++++++++++++++++++++---
mln/core/concept/value_iterator.hh | 2
mln/core/dpoints_piter.hh | 20 +-
mln/core/dpoints_pixter.hh | 10 -
mln/core/internal/check/image_fastest.hh | 7
mln/core/internal/piter_adaptor.hh | 10 -
mln/core/internal/point_iterator_base.hh | 11 +
mln/core/internal/run_pset.hh | 39 +++-
mln/core/internal/run_psite.hh | 15 +
mln/core/line_piter.hh | 10 -
mln/core/mesh_p.hh | 2
mln/core/mesh_p_piter.hh | 19 --
mln/core/mesh_psite.hh | 26 +-
mln/core/rle_image.hh | 3
mln/core/vec_p_piter.hh | 20 +-
mln/core/window.hh | 5
mln/linear/local/convolve.hh | 14 -
mln/value/concept/built_in.hh | 3
tests/rle_image.cc | 2
29 files changed, 750 insertions(+), 318 deletions(-)
Index: tests/rle_image.cc
--- tests/rle_image.cc (revision 1397)
+++ tests/rle_image.cc (working copy)
@@ -28,6 +28,8 @@
/*! \file tests/rle_image.cc
*
* \brief Tests on mln::rle_image.
+ *
+ * \todo Trouble with ctor/init since there is no ctor with arg!
*/
#include <mln/core/image2d.hh>
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1397)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -35,7 +35,7 @@
*/
# include <mln/core/internal/point_iterator_base.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
namespace mln
@@ -58,13 +58,13 @@
*/
template <typename Dps, typename Pref>
dpoints_fwd_piter(const Dps& dps, // FIXME: explicitly set_of_<D>?
- const Generalized_Point<Pref>& p_ref);
+ const Point_Site<Pref>& p_ref);
/// Convertion to point.
operator mln_point(D) () const;
- /// Address of the point this iterator designates.
- const mln_point(D)* pointer_() const;
+ /// Reference to the corresponding point.
+ const mln_point(D)& to_point() const;
/// Test the iterator validity.
bool is_valid() const;
@@ -95,7 +95,7 @@
unsigned i_;
mln_point(D) p_; // location of this iterator; p_ makes this iterator be
- // itself a potential center point (Cf. the pointer_() method).
+ // itself a potential center point.
};
@@ -110,9 +110,9 @@
template <typename D>
template <typename Dps, typename Pref>
dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps,
- const Generalized_Point<Pref>& p_ref)
+ const Point_Site<Pref>& p_ref)
: dps_(exact(dps).vect()),
- p_ref_(* internal::force_exact<Pref>(p_ref).pointer_())
+ p_ref_(exact(p_ref).to_point())
{
invalidate();
}
@@ -125,10 +125,10 @@
}
template <typename D>
- const mln_point(D)*
- dpoints_fwd_piter<D>::pointer_() const
+ const mln_point(D)&
+ dpoints_fwd_piter<D>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename D>
Index: mln/core/mesh_psite.hh
--- mln/core/mesh_psite.hh (revision 1397)
+++ mln/core/mesh_psite.hh (working copy)
@@ -31,13 +31,19 @@
/*! \file mln/core/mesh_p.hh
*
* \brief Definition of a graph-based point site.
+ *
+ * \todo Clean-up!
*/
+
namespace mln
{
+ // Fwd decl.
template<typename P> class mesh_p;
+
+ // FIXME: Doc!
template<typename P>
struct mesh_psite : public Point_Site< mesh_psite<P> >
{
@@ -48,12 +54,15 @@
typedef mln_coord(P) coord;
mesh_psite(unsigned i, mesh_p<P>* m_ptr);
- P to_point() const;
+
operator P() const;
- const point* pointer_() const;
+
+ const point& to_point() const;
+
coord operator[](unsigned i) const;
unsigned i_;
+
mesh_p<P>* m_ptr_;
};
@@ -67,23 +76,16 @@
}
template<typename P>
- P
- mesh_psite<P>::to_point() const
- {
- return m_ptr_->loc_[i_];
- }
-
- template<typename P>
mesh_psite<P>::operator P() const
{
return m_ptr_->loc_[i_];
}
template<typename P>
- const P*
- mesh_psite<P>::pointer_() const
+ const P&
+ mesh_psite<P>::to_point() const
{
- return 0;
+ return m_ptr_->loc_[i_];
}
template<typename P>
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1397)
+++ mln/core/window.hh (working copy)
@@ -37,7 +37,7 @@
*/
# include <mln/core/concept/window.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint.hh>
# include <mln/core/box.hh>
@@ -132,7 +132,8 @@
template <typename D>
window<D>::window()
{
- mln::metal::is_a<D, Dpoint>::check();
+ // FIXME HERE: Was: mln::metal::is_a<D, Dpoint>::check();
+ mln::metal::is_a<D, Delta_Point_Site>::check();
}
template <typename D>
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 1397)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -38,7 +38,7 @@
# include <vector>
# include <mln/core/concept/pixel_iterator.hh>
-# include <mln/core/concept/generalized_pixel.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/internal/pixel_impl.hh>
@@ -62,12 +62,12 @@
*
* \param[in] image Image subject to iteration.
* \param[in] dps Object that can provide a set of delta-points.
- * \param[in] p_ref Center (generalized) point to iterate around.
+ * \param[in] p_ref Center point to iterate around.
*/
template <typename Dps, typename Pref>
dpoints_fwd_pixter(I& image,
const Dps& dps,
- const Generalized_Point<Pref>& p_ref);
+ const Point_Site<Pref>& p_ref);
/*! \brief Constructor.
*
@@ -129,11 +129,11 @@
template <typename Dps, typename Pref>
dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
const Dps& dps,
- const Generalized_Point<Pref>& p_ref)
+ const Point_Site<Pref>& p_ref)
: super_(image)
{
mln_precondition(image.has_data());
- p_ref_ = internal::force_exact<Pref>(p_ref).pointer_();
+ p_ref_ = & exact(p_ref).to_point();
value_ref_ = 0;
init_(dps);
}
Index: mln/core/mesh_p.hh
--- mln/core/mesh_p.hh (revision 1397)
+++ mln/core/mesh_p.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_MESH_P_HH
# define MLN_MESH_P_HH
-# include <mln/core/concept/point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/internal/point_set_base.hh>
# include <mln/accu/bbox.hh>
# include <mln/util/graph.hh>
Index: mln/core/internal/point_iterator_base.hh
--- mln/core/internal/point_iterator_base.hh (revision 1397)
+++ mln/core/internal/point_iterator_base.hh (working copy)
@@ -71,6 +71,9 @@
/// Coord associated type.
typedef mln_coord(point) coord;
+ // Access to the i-th coordinate.
+ coord operator[](unsigned i) const;
+
protected:
/// Constructor.
point_iterator_base_();
@@ -85,6 +88,14 @@
mln::metal::is_a<P, Point_Site>::check();
}
+ template <typename P, typename E>
+ typename point_iterator_base_<P, E>::coord
+ point_iterator_base_<P, E>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ return exact(*this).to_point()[i];
+ }
+
#endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
Index: mln/core/internal/piter_adaptor.hh
--- mln/core/internal/piter_adaptor.hh (revision 1397)
+++ mln/core/internal/piter_adaptor.hh (working copy)
@@ -63,8 +63,8 @@
/// Convertion to point.
operator mln_point(Pi) () const;
- /// Address of the point.
- const mln_point(Pi)* pointer_() const;
+ /// Reference to the corresponding point.
+ const mln_point(Pi)& to_point() const;
/// Give the i-th coordinate.
mln_coord(Pi) operator[](unsigned i) const;
@@ -105,10 +105,10 @@
}
template <typename Pi, typename E>
- const mln_point(Pi)*
- piter_adaptor_<Pi,E>::pointer_() const
+ const mln_point(Pi)&
+ piter_adaptor_<Pi,E>::to_point() const
{
- return piter_.pointer_();
+ return piter_.to_point();
}
template <typename Pi, typename E>
Index: mln/core/internal/run_pset.hh
--- mln/core/internal/run_pset.hh (revision 1397)
+++ mln/core/internal/run_pset.hh (working copy)
@@ -69,15 +69,19 @@
run_pset_();
+
/// Test is \p p belongs to this point set.
bool has(const run_psite<P>& p) const;
+
/// Give the exact bounding box.
const box_<P>& bbox() const;
+
/// Give the number of points.
typename std::size_t npoints() const;
/// Insert a range, start at point \p p wit len \p len.
void insert(const P& p, unsigned len);
+
/// Return the len of the range starting at point \p p.
unsigned range_len_(const P& p) const;
@@ -85,10 +89,13 @@
const std_container& con() const;
protected:
+
/// Number of points.
typename std::size_t npoints_;
+
/// Points container
std_container con_;
+
/// Exact bounding box.
accu::bbox<P> fb_;
};
@@ -182,18 +189,24 @@
/// Convertion into a point-site.
operator internal::run_psite<P> () const;
+
/// Convertion into a point.
operator P () const;
- /// Return a pointer of the current point.
- const P* pointer_() const;
+
+ /// Reference to the corresponding point.
+ const P& to_point() const;
+
/// Access to the current point coordinates.
mln_coord(P) operator[](unsigned i) const;
protected:
+
/// Current point.
P p_;
+
/// Current site.
internal::run_psite<P> site_;
+
/// Point set container.
const std_container& con_;
@@ -222,11 +235,11 @@
}
template <typename P, typename E>
- const P*
- run_piter_<P, E>::pointer_() const
+ const P&
+ run_piter_<P, E>::to_point() const
{
mln_precondition(exact(this)->is_valid());
- return &p_;
+ return p_;
}
template <typename P, typename E>
@@ -236,6 +249,7 @@
mln_precondition(exact(this)->is_valid());
return p_[i];
}
+
# endif // ! MLN_INCLUDE_ONLY
@@ -253,17 +267,24 @@
/// Test the iterator validity.
bool is_valid() const;
+
/// Invalidate the iterator.
void invalidate();
+
/// Start an iteration.
void start();
+
/// Go to the next point.
void next_();
+
protected:
typename super::std_container::const_iterator it_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename P>
run_fwd_piter_<P>::run_fwd_piter_(const run_pset_<P>& pset) :
super(pset)
@@ -318,6 +339,7 @@
# endif // ! MLN_INCLUDE_ONLY
+
/*! \brief Backward iterator on run_pset_ point set.
*
* Parameter \c P is the type of the point used in the point set.
@@ -332,17 +354,24 @@
/// Test the iterator validity.
bool is_valid() const;
+
/// Invalidate the iterator.
void invalidate();
+
/// Start an iteration.
void start();
+
/// Go to the next point.
void next_();
+
protected:
typename super::std_container::const_reverse_iterator it_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename P>
run_bkd_piter_<P>::run_bkd_piter_(const run_pset_<P>& pset) :
super(pset)
Index: mln/core/internal/run_psite.hh
--- mln/core/internal/run_psite.hh (revision 1397)
+++ mln/core/internal/run_psite.hh (working copy)
@@ -80,13 +80,16 @@
/// Return the position of this psite in the current range.
unsigned& index_();
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
+
+ /// Give the i-th coordinate of the corresponding point.
mln_coord(P) operator[](unsigned i) const;
protected:
/// Start of the psite range.
- P point_;
+ P point_; // FIXME: Rename as p_ (like everywhere else!)
/// Position in the psite range.
unsigned range_index_;
@@ -95,7 +98,9 @@
unsigned pset_position_;
};
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename P>
run_psite<P>::run_psite()
{
@@ -160,10 +165,10 @@
}
template <typename P>
- const P*
- run_psite<P>::pointer_() const
+ const P&
+ run_psite<P>::to_point() const
{
- return & point_;
+ return point_;
}
template <typename P>
Index: mln/core/internal/check/image_fastest.hh
--- mln/core/internal/check/image_fastest.hh (revision 1397)
+++ mln/core/internal/check/image_fastest.hh (working copy)
@@ -34,6 +34,7 @@
* images.
*/
+# include <mln/core/internal/force_exact.hh>
namespace mln
@@ -62,7 +63,7 @@
*/
template <typename P>
unsigned
- offset_at(const Generalized_Point<P>& p) const;
+ offset_at(const Point_Site<P>& p) const;
protected:
image_fastest_();
@@ -118,11 +119,11 @@
template <typename E, typename B>
template <typename P>
unsigned // FIXME: std::size_t?
- image_fastest_<E,B>::offset_at(const Generalized_Point<P>& p_) const
+ image_fastest_<E,B>::offset_at(const Point_Site<P>& p_) const
{
// FIXME: check that P is mln_point(E)
const E* this_ = & internal::force_exact<E>(*this);
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
mln_precondition(this_->has_data());
mln_precondition(this_->owns_(p));
Index: mln/core/mesh_p_piter.hh
--- mln/core/mesh_p_piter.hh (revision 1397)
+++ mln/core/mesh_p_piter.hh (working copy)
@@ -54,8 +54,8 @@
mesh_p_piter_(const mesh_p<P>& s);
- /// Give a hook to the point address.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -81,6 +81,8 @@
P p_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
template<typename P>
@@ -90,15 +92,13 @@
invalidate();
}
-
template<typename P>
- const P*
- mesh_p_piter_<P>::pointer_() const
+ const P&
+ mesh_p_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
-
template<typename P>
mln_coord(P)
mesh_p_piter_<P>::operator[](unsigned i) const
@@ -106,7 +106,6 @@
return p_[i];
}
-
template<typename P>
bool
mesh_p_piter_<P>::is_valid() const
@@ -114,7 +113,6 @@
return i_ != loc_.size();
}
-
template<typename P>
void
mesh_p_piter_<P>::invalidate()
@@ -122,7 +120,6 @@
i_ = loc_.size();
}
-
template<typename P>
void
mesh_p_piter_<P>::start()
@@ -132,7 +129,6 @@
p_ = loc_[i_];
}
-
template<typename P>
void
mesh_p_piter_<P>::next_()
@@ -142,7 +138,6 @@
p_ = loc_[i_];
}
-
template<typename P>
mesh_p_piter_<P>::operator P() const
{
Index: mln/core/rle_image.hh
--- mln/core/rle_image.hh (revision 1397)
+++ mln/core/rle_image.hh (working copy)
@@ -45,6 +45,7 @@
// Fwd decl.
template <typename P, typename T> struct rle_image;
+
namespace internal
{
@@ -62,6 +63,8 @@
} // end of namespace mln::internal
+
+
/*! \brief RLE image.
*
*
Index: mln/core/line_piter.hh
--- mln/core/line_piter.hh (revision 1397)
+++ mln/core/line_piter.hh (working copy)
@@ -64,8 +64,8 @@
/// Convertion to point.
operator P() const;
- /// Address of the point.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Give the i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -115,10 +115,10 @@
}
template <typename P>
- const P*
- line_piter_<P>::pointer_() const
+ const P&
+ line_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1397)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -56,8 +56,8 @@
template <typename S>
vec_p_fwd_piter_(const Point_Set<S>& s);
- /// Give a hook to the point address.
- const P* pointer_() const;
+ /// Reference of the corresponding point.
+ const P& to_point() const;
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -102,8 +102,8 @@
template <typename S>
vec_p_bkd_piter_(const Point_Set<S>& s);
- /// Give a hook to the point address.
- const P* pointer_() const;
+ /// Reference of the corresponding point.
+ const P& to_point() const;
/// Read-only access to the \p i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -144,10 +144,10 @@
}
template <typename P>
- const P*
- vec_p_fwd_piter_<P>::pointer_() const
+ const P&
+ vec_p_fwd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
@@ -210,10 +210,10 @@
}
template <typename P>
- const P*
- vec_p_bkd_piter_<P>::pointer_() const
+ const P&
+ vec_p_bkd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
Index: mln/core/box_piter.hh
--- mln/core/box_piter.hh (revision 1397)
+++ mln/core/box_piter.hh (working copy)
@@ -65,8 +65,8 @@
/// Convertion to point.
operator P() const;
- /// Address of the point.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Give the i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -115,8 +115,8 @@
/// Convertion to point.
operator P() const;
- /// Address of the point.
- const P* pointer_() const;
+ /// Reference to the corresponding point.
+ const P& to_point() const;
/// Give the i-th coordinate.
mln_coord(P) operator[](unsigned i) const;
@@ -162,10 +162,10 @@
}
template <typename P>
- const P*
- box_fwd_piter_<P>::pointer_() const
+ const P&
+ box_fwd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
@@ -233,10 +233,10 @@
template <typename P>
- const P*
- box_bkd_piter_<P>::pointer_() const
+ const P&
+ box_bkd_piter_<P>::to_point() const
{
- return & p_;
+ return p_;
}
template <typename P>
Index: mln/core/concept/value_iterator.hh
--- mln/core/concept/value_iterator.hh (revision 1397)
+++ mln/core/concept/value_iterator.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/iterator.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
namespace mln
Index: mln/core/concept/delta_point_site.hh
--- mln/core/concept/delta_point_site.hh (revision 0)
+++ mln/core/concept/delta_point_site.hh (revision 0)
@@ -0,0 +1,218 @@
+// 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_CONCEPT_DELTA_POINT_SITE_HH
+# define MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH
+
+/*! \file mln/core/concept/delta_point_site.hh
+ *
+ * \brief Definition of the concept of mln::Delta_Point_Site.
+ */
+
+# include <mln/core/concept/object.hh>
+# include <mln/core/grids.hh>
+# include <mln/trait/all.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename E> struct Delta_Point_Site;
+
+
+
+ namespace trait
+ {
+
+ template < typename L, typename R >
+ struct set_binary_< op::plus,
+ mln::Delta_Point_Site, L, mln::Delta_Point_Site, R >
+ {
+ typedef mln_dpoint(L) ret;
+ };
+
+ template < typename L, typename R >
+ struct set_binary_< op::minus,
+ mln::Delta_Point_Site, L, mln::Delta_Point_Site, R >
+ {
+ typedef mln_dpoint(L) ret;
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ /// Delta point site category flag type.
+ template <>
+ struct Delta_Point_Site<void>
+ {
+ typedef Object<void> super;
+ };
+
+
+ /*! \brief FIXME: Doc!
+ */
+ template <typename E>
+ struct Delta_Point_Site : public Object<E>
+ {
+ typedef Delta_Point_Site<void> category;
+
+ /*
+ enum { dim };
+ typedef mesh;
+
+ typedef point;
+ typedef dpoint;
+ typedef coord;
+
+ const dpoint& to_dpoint() const;
+ coord operator[](unsigned i) const;
+ */
+
+ protected:
+ Delta_Point_Site();
+ };
+
+
+
+ // Operators.
+
+ template <typename D>
+ std::ostream&
+ operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp);
+
+
+ template <typename L, typename R>
+ bool
+ operator=(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+ template <typename L, typename R>
+ bool
+ operator<(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator+(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator-(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Delta_Point_Site<E>::Delta_Point_Site()
+ {
+ int dim = E::dim;
+ mln_invariant(dim > 0);
+ dim = 0;
+ typedef mln_mesh(E) mesh;
+ typedef mln_point(E) point;
+ typedef mln_dpoint(E) dpoint;
+ typedef mln_coord(E) coord;
+ const dpoint& (E::*m1)() const = & E::to_dpoint;
+ m1 = 0;
+ coord (E::*m2)(unsigned i) const = & E::operator[];
+ m2 = 0;
+ }
+
+
+ template <typename D>
+ std::ostream& operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp_)
+ {
+ const D& dp = exact(dp_);
+ ostr << '(';
+ for (unsigned i = 0; i < D::dim; ++i)
+ ostr << dp[i] << (i = D::dim - 1 ? ')' : ',');
+ return ostr;
+ }
+
+
+ template <typename L, typename R>
+ bool operator=(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
+ template <typename L, typename R>
+ bool operator<(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ {
+ if (lhs[i] = rhs[i])
+ continue;
+ return lhs[i] < rhs[i];
+ }
+ return false;
+ }
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator+(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_dpoint(L) tmp;
+ for (unsigned i = 0; i < L::dim; ++i)
+ tmp[i] = lhs[i] + rhs[i];
+ return tmp;
+ }
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator-(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_dpoint(L) tmp;
+ for (unsigned i = 0; i < L::dim; ++i)
+ tmp[i] = lhs[i] - rhs[i];
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH
Index: mln/core/concept/point.hh
--- mln/core/concept/point.hh (revision 1397)
+++ mln/core/concept/point.hh (working copy)
@@ -34,11 +34,24 @@
*/
# include <mln/core/concept/point_site.hh>
+# include <mln/core/concept/dpoint.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Point;
+
+
+ // Point category flag type.
+ template <>
+ struct Point<void>
+ {
+ typedef Point_Site<void> super;
+ };
+
+
/*! \brief Base class for implementation of point classes.
*
* A point is an element of a space.
@@ -53,47 +66,43 @@
*/
typedef P point;
- /*! \brief The pointer is this point address.
+ /*! \brief It is a Point so it returns itself.
*/
- const P* pointer_() const;
+ const P& to_point() const;
protected:
Point();
};
- /*! \brief Add a delta-point \p rhs to a point \p lhs.
+ /*! \brief Shift a point \p by a delta-point \p dp.
*
- * \param[in,out] lhs The targeted point.
- * \param[in] rhs A delta-point.
+ * \param[in,out] p The targeted point.
+ * \param[in] dp A delta-point.
+ * \return A reference to the point \p p once translated by \p dp.
*
- * \pre The type of \p rhs has to be the Dpoint type associated with
- * the type of \p lhs; otherwise this test does not compile.
- *
- * \return A reference to the point \p lhs once translated by \p
- * rhs.
+ * \pre The type of \p dp has to be compatible with the type of \p
+ * p.
*
* \relates mln::Point
*/
- template <typename P>
- P& operator+=(Point<P>& lhs, const mln_dpoint(P)& rhs);
+ template <typename P, typename D>
+ P& operator+=(Point<P>& p, const Dpoint<D>& dp);
- /*! \brief Remove a delta-point \p rhs to a point \p lhs.
- *
- * \param[in,out] lhs The targeted point.
- * \param[in] rhs A delta-point.
+ /*! \brief Shift a point \p by the negate of a delta-point \p dp.
*
- * \pre The type of \p rhs has to be the Dpoint type associated with
- * the type of \p lhs; otherwise this test does not compile.
+ * \param[in,out] p The targeted point.
+ * \param[in] dp A delta-point.
+ * \return A reference to the point \p p once translated by - \p dp.
*
- * \return A reference to the point \p lhs once translated by - \p
- * rhs.
+ * \pre The type of \p dp has to be compatible with the type of \p
+ * p.
*
* \relates mln::Point
*/
- template <typename P>
- P& operator-=(Point<P>& lhs, const mln_dpoint(P)& rhs);
+ template <typename P, typename D>
+ P& operator-=(Point<P>& p, const Dpoint<D>& dp);
@@ -105,25 +114,32 @@
}
template <typename P>
- const P* Point<P>::pointer_() const
+ const P&
+ Point<P>::to_point() const
{
- return exact(this);
+ return exact(*this);
}
- template <typename P>
- P& operator+=(Point<P>& lhs, const mln_dpoint(P)& rhs)
+ template <typename P, typename D>
+ P& operator+=(Point<P>& p_, const Dpoint<D>& dp_)
{
+ P& p = exact(p_);
+ const D& dp = exact(dp_);
+ // FIXME: Use to_vec()!
for (unsigned i = 0; i < P::dim; ++i)
- exact(lhs)[i] += rhs[i];
- return lhs;
+ p[i] += dp[i];
+ return p;
}
- template <typename P>
- P& operator-=(Point<P>& lhs, const mln_dpoint(P)& rhs)
+ template <typename P, typename D>
+ P& operator-=(Point<P>& p_, const Dpoint<D>& dp_)
{
+ P& p = exact(p_);
+ const D& dp = exact(dp_);
+ // FIXME: Use to_vec()!
for (unsigned i = 0; i < P::dim; ++i)
- exact(lhs)[i] -= rhs[i];
- return lhs;
+ p[i] -= dp[i];
+ return p;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/dpoint.hh
--- mln/core/concept/dpoint.hh (revision 1397)
+++ mln/core/concept/dpoint.hh (working copy)
@@ -32,7 +32,7 @@
* \brief Definition of the concept of mln::Dpoint.
*/
-# include <mln/core/concept/object.hh>
+# include <mln/core/concept/delta_point_site.hh>
# include <mln/core/grids.hh>
@@ -42,11 +42,12 @@
// Fwd decl.
template <typename E> struct Dpoint;
+
// Dpoint category flag type.
template <>
struct Dpoint<void>
{
- typedef Object<void> super;
+ typedef Delta_Point_Site<void> super;
};
@@ -61,160 +62,32 @@
* contents.
*/
template <typename E>
- struct Dpoint : public Object<E>
+ struct Dpoint : public Delta_Point_Site<E>
{
typedef Dpoint<void> category;
- /*
- typedef point;
- typedef coord;
- enum { dim };
- coord operator[](unsigned i) const;
- */
+ typedef E dpoint;
+
+ /// It is a Dpoint so it returns itself.
+ const E& to_dpoint() const;
protected:
Dpoint();
};
- /*! \brief Give the negate of the delta-point \p rhs.
- *
- * \param[in] rhs The targeted delta-point.
- *
- * \invariant For all delta-point dp, we have: -(-dp) = dp.
- *
- * \return A delta-point (temporary object).
- *
- * \relates mln::Dpoint
- */
- template <typename D>
- D operator-(const Dpoint<D>& rhs);
-
-
- /*! \brief Add the couple of delta-points \p lhs and \p rhs.
- *
- * \param[in] lhs A delta-point.
- * \param[in] rhs Another delta-point.
- *
- * \return A delta-point (temporary object).
- *
- * \relates mln::Dpoint
- */
- template <typename D>
- D operator+(const Dpoint<D>& lhs, const Dpoint<D>& rhs);
-
-
- /*! \brief Equality comparison between a couple of delta-point \p lhs
- * and \p rhs.
- *
- * \param[in] lhs A first delta-point.
- * \param[in] rhs A second delta-point.
- *
- * \pre Both \p lhs and \p rhs have to be defined on the same
- * topology; otherwise this test does not compile.
- *
- * \return True if both delta-points have the same coordinates,
- * otherwise false.
- *
- * \relates mln::Dpoint
- */
- template <typename Dl, typename Dr>
- bool operator=(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs);
-
-
- /*! \brief Ordering "less than" comparison between a couple of
- * delta-points \p lhs and \p rhs.
- *
- * \param[in] lhs A first delta-point.
- * \param[in] rhs A second delta-point.
- *
- * \pre Both \p lhs and \p rhs have to be defined on the same
- * topology; otherwise this test does not compile.
- *
- * \return True if both delta-points have the same coordinates,
- * otherwise false.
- *
- * \relates mln::Dpoint
- */
- template <typename Dl, typename Dr>
- bool operator<(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs);
-
-
- /*! \brief Print a delta-point \p p into the output stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] dp A delta-point.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::Dpoint
- */
- template <typename D>
- std::ostream& operator<<(std::ostream& ostr, const Dpoint<D>& dp);
-
-
-
# ifndef MLN_INCLUDE_ONLY
template <typename E>
Dpoint<E>::Dpoint()
{
- typedef mln_point(E) point;
- typedef mln_coord(E) coord;
- enum { dim = E::dim };
- coord (E::*m)(unsigned i) const = & E::operator[];
- m = 0;
}
- template <typename D>
- D operator-(const Dpoint<D>& rhs)
- {
- D tmp;
- for (unsigned i = 0; i < D::dim; ++i)
- tmp[i] = - exact(rhs)[i];
- return tmp;
- }
-
- template <typename D>
- D operator+(const Dpoint<D>& lhs, const Dpoint<D>& rhs)
- {
- D tmp;
- for (unsigned i = 0; i < D::dim; ++i)
- tmp[i] = exact(lhs)[i] + exact(rhs)[i];
- return tmp;
- }
-
- template <typename Dl, typename Dr>
- bool operator=(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs)
- {
- for (unsigned i = 0; i < Dl::dim; ++i)
- if (exact(lhs)[i] != exact(rhs)[i])
- return false;
- return true;
- }
-
- template <typename Dl, typename Dr>
- bool operator<(const Dpoint<Dl>& lhs, const Dpoint<Dr>& rhs)
- {
- for (unsigned i = 0; i < Dl::dim; ++i)
- {
- if (exact(lhs)[i] = exact(rhs)[i])
- continue;
- return exact(lhs)[i] < exact(rhs)[i];
- }
- return false;
- }
-
- template <typename D>
- std::ostream& operator<<(std::ostream& ostr, const Dpoint<D>& dp)
- {
- ostr << '(';
- for (unsigned i = 0; i < D::dim; ++i)
+ template <typename E>
+ const E&
+ Dpoint<E>::to_dpoint() const
{
- ostr << exact(dp)[i]
- << (i = D::dim - 1 ? ')' : ',');
- }
- return ostr;
+ return exact(*this);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/point_iterator.hh
--- mln/core/concept/point_iterator.hh (revision 1397)
+++ mln/core/concept/point_iterator.hh (working copy)
@@ -31,11 +31,12 @@
/*! \file mln/core/concept/point_iterator.hh
*
* \brief Definition of the concept of mln::Point_Iterator.
+ *
+ * \todo Fix mln/core/concept/doc/point_iterator.hh
*/
-# include <mln/core/concept/iterator.hh>
-# include <mln/core/concept/generalized_point.hh>
# include <mln/core/concept/point_site.hh>
+# include <mln/core/concept/iterator.hh> // To fetch the macros.
namespace mln
@@ -51,22 +52,44 @@
* contents.
*/
template <typename E>
- struct Point_Iterator : public Iterator<E>,
- public Generalized_Point<E>
+ struct Point_Iterator : public Point_Site<E>
{
/*
typedef psite;
+ bool is_valid() const;
+ void invalidate();
+ void start();
+ void next_();
operator psite() const;
*/
+ /*! \brief Go to the next element.
+ *
+ * \warning This is a final method; iterator classes should not
+ * re-defined this method. The actual "next" operation has to be
+ * defined through the \em next_ method.
+ *
+ * \pre The iterator is valid.
+ */
+ void next(); // final
+
protected:
Point_Iterator();
};
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
+ void
+ Point_Iterator<E>::next() // final
+ {
+ assert(exact(this)->is_valid());
+ exact(this)->next_();
+ }
+
+ template <typename E>
Point_Iterator<E>::Point_Iterator()
{
typedef mln_psite(E) psite;
@@ -74,6 +97,15 @@
psite (E::*m)() const = & E::operator psite;
m = 0;
+
+ bool (E::*m1)() const = & E::is_valid;
+ m1 = 0;
+ void (E::*m2)() = & E::invalidate;
+ m2 = 0;
+ void (E::*m3)() = & E::start;
+ m3 = 0;
+ void (E::*m4)() = & E::next_;
+ m4 = 0;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/point_set.hh
--- mln/core/concept/point_set.hh (revision 1397)
+++ mln/core/concept/point_set.hh (working copy)
@@ -38,7 +38,7 @@
* \todo Move out the ops.
*/
-# include <mln/core/concept/point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/concept/point_iterator.hh>
Index: mln/core/concept/doc/point_site.hh
--- mln/core/concept/doc/point_site.hh (revision 1395)
+++ mln/core/concept/doc/point_site.hh (working copy)
@@ -25,8 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file mln/core/concept/doc/generalized_point.hh
- * \brief This file documents the concept of mln::Generalized_Point.
+/*! \file mln/core/concept/doc/point_site.hh
+ *
+ * \brief This file documents the concept of mln::Point_Site.
*/
namespace mln
@@ -35,12 +36,12 @@
namespace doc
{
- /*! \brief Documentation class for mln::Generalized_Point.
+ /*! \brief Documentation class for mln::Point_Site.
*
- * \see mln::Generalized_Point
+ * \see mln::Point_Site
*/
template <typename E>
- struct Generalized_Point
+ struct Point_Site
{
/*! \var dim
* \brief Dimension of the space.
@@ -48,6 +49,11 @@
*/
enum { dim };
+ /*! \brief Mesh associated type.
+ * \invariant This type has to derive from mln::Mesh.
+ */
+ typedef void mesh;
+
/*! \brief Point associated type.
* \invariant This type has to derive from mln::Point.
*/
@@ -63,23 +69,13 @@
typedef void coord;
- // FIXME: typedef void topo;
-
-
- /*! \brief Either \c E is a point or an convertion operator into
- * a point is defined.
- *
- * \return A point.
- */
- operator point() const;
-
- /*! \brief Give a hook to the point address.
+ /*! \brief Give a reference to the corresponding point.
*
* This method allows for iterators to refer to a point.
*
- * \return A point address.
+ * \return A point constant reference.
*/
- const point* pointer_() const;
+ const point& to_point() const;
/*! \brief Read-only access to the \p i-th coordinate value.
*
Index: mln/core/concept/point_site.hh
--- mln/core/concept/point_site.hh (revision 1397)
+++ mln/core/concept/point_site.hh (working copy)
@@ -25,29 +25,61 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_CONCEPT_PSITE_HH
-# define MLN_CORE_CONCEPT_PSITE_HH
+#ifndef MLN_CORE_CONCEPT_POINT_SITE_HH
+# define MLN_CORE_CONCEPT_POINT_SITE_HH
/*! \file mln/core/concept/point_site.hh
+ *
* \brief Definition of the concept of mln::Point_Site.
*/
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/object.hh>
+# include <mln/core/concept/delta_point_site.hh>
+# include <mln/core/grids.hh>
+# include <mln/trait/all.hh>
+
namespace mln
{
- // FIXME: Hack is "Point" instead of "Points_Site"; change it!
+ // Fwd decls.
+ template <typename E> struct Point_Site;
+
+
+
+ namespace trait
+ {
+ template < typename P, typename D >
+ struct set_binary_< op::plus,
+ mln::Point_Site, P, mln::Delta_Point_Site, D >
+ {
+ typedef mln_point(P) ret;
+ };
- // Fwd decl.
- template <typename E> struct Point;
+ template < typename P, typename D >
+ struct set_binary_< op::minus,
+ mln::Point_Site, P, mln::Delta_Point_Site, D >
+ {
+ typedef mln_point(P) ret;
+ };
+ template < typename L, typename R >
+ struct set_binary_< op::minus,
+ mln::Point_Site, L, mln::Point_Site, R >
+ {
+ typedef mln_dpoint(L) ret;
+ };
- /// Point_Site category flag type.
+ } // end of namespace mln::trait
+
+
+
+
+ /// Point site category flag type.
template <>
- struct Point<void>
+ struct Point_Site<void>
{
typedef Object<void> super;
};
@@ -58,13 +90,10 @@
*
* A point site ("psite" for short) is an object that allows an
* efficient access to data associated with a point. A point site
- * is either a point or designates a point: regular points, deriving
- * from mln::Point, are point sites, yet some point sites are not
- * points.) A point site has the behavior expected from every
- * point; see mln::Generalized_Point.
+ * is either a point or designates a point.
*
- * When a point site is not a point, it is automatically convertible
- * to the point it designates.
+ * When a point site is not really a point, it is automatically
+ * convertible to the point it designates.
*
*
* Let us take the example of a 2D image encoded as an array of runs
@@ -76,16 +105,21 @@
* proper point site is a pair (index of run, index within the run).
*/
template <typename E>
- struct Point_Site : public Object<E>,
- public Generalized_Point<E>
+ struct Point_Site : public Object<E>
{
- typedef Point<void> category; // FIXME: This is a hack! Change the hierarchy...
+ typedef Point_Site<void> category;
/*
- const point* pointer_() const
- {
- return & (exact(this)->operator point());
- }
+ enum { dim };
+ typedef mesh;
+
+ typedef point;
+ typedef dpoint;
+ typedef coord;
+
+ const point& to_point() const;
+
+ coord operator[](unsigned i) const;
*/
protected:
@@ -93,11 +127,219 @@
};
+ /*! \brief Equality comparison between a couple of point site \p lhs
+ * and \p rhs.
+ *
+ * \param[in] lhs A first point site.
+ * \param[in] rhs A second point site.
+ *
+ * \pre Both \p lhs and \p rhs have to be defined on the same
+ * topology; otherwise this test does not compile.
+ *
+ * \return True if both point sites have the same
+ * coordinates, otherwise false.
+ *
+ * \relates mln::Point_Site
+ */
+ template <typename L, typename R>
+ bool operator=(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
+
+
+ /*! \brief Ordering "less than" comparison between a couple of
+ * point sites \p lhs and \p rhs.
+ *
+ * \param[in] lhs A first point site.
+ * \param[in] rhs A second point site.
+ *
+ * This test is based on a lexicographical ordering over coordinates.
+ *
+ * \warning In the general case this ordering relationship is \em
+ * not bound to the way of browsing a domain with a forward point
+ * iterator.
+ *
+ * \pre Both \p lhs and \p rhs have to be defined on the same
+ * topology; otherwise this test does not compile.
+ *
+ * \return True if \p lhs is before \p rhs in the sense of the
+ * coordinates lexicographic comparison, otherwise false.
+ *
+ * \relates mln::Point_Site
+ */
+ template <typename L, typename R>
+ bool operator<(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
+
+
+ /*! \brief Difference between a couple of point site \p lhs and \p
+ * rhs.
+ *
+ * \param[in] lhs A first point site.
+ * \param[in] rhs A second point site.
+ *
+ * \warning There is no type promotion in milena so the client
+ * has to make sure that both points are defined with the same
+ * type of coordinates.
+ *
+ * \pre Both \p lhs and \p rhs have to be defined on the same
+ * topology and with the same type of coordinates; otherwise this
+ * test does not compile.
+ *
+ * \post The result, \p dp, is such as \p lhs = \p rhs + \p dp.
+ *
+ * \return A delta point (temporary object).
+ *
+ * \relates mln::Point_Site
+ * \see mln::Delta_Point_Site
+ */
+ template <typename L, typename R>
+ mln_dpoint(L)
+ operator-(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
+
+
+ /*! \brief Add a delta-point \p rhs to a point site \p lhs.
+ *
+ * \param[in] p A point site.
+ * \param[in] dp A delta-point.
+ *
+ * The type of \p dp has to compatible with the type of \p p.
+ *
+ * \return A point (temporary object).
+ *
+ * \relates mln::Point_Site
+ * \see mln::Delta_Point_Site
+ */
+ template <typename P, typename D>
+ mln_point(P)
+ operator+(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
+
+
+ /*! \brief Substract a delta-point \p rhs to a point site \p lhs.
+ *
+ * \param[in] p A point site.
+ * \param[in] dp A delta-point.
+ *
+ * The type of \p dp has to compatible with the type of \p p.
+ *
+ * \return A point (temporary object).
+ *
+ * \see mln::Dpoint
+ * \see mln::Delta_Point_Site
+ */
+ template <typename P, typename D>
+ mln_point(P)
+ operator-(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
+
+
+ /*! \brief Print a point site \p p into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] p A point site.
+ *
+ * \return The modified output stream \p ostr.
+ *
+ * \relates mln::Point_Site
+ */
+ template <typename P>
+ std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p);
+
+
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
Point_Site<E>::Point_Site()
{
+ int dim = E::dim;
+ mln_invariant(dim > 0);
+ dim = 0;
+ typedef mln_mesh(E) mesh;
+ typedef mln_point(E) point;
+ typedef mln_dpoint(E) dpoint;
+ typedef mln_coord(E) coord;
+ const point& (E::*m1)() const = & E::to_point;
+ m1 = 0;
+ coord (E::*m2)(unsigned i) const = & E::operator[];
+ m2 = 0;
+ }
+
+
+ // Operators.
+
+ template <typename L, typename R>
+ bool operator=(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
+ template <typename L, typename R>
+ bool operator<(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ for (unsigned i = 0; i < L::dim; ++i)
+ {
+ if (lhs[i] = rhs[i])
+ continue;
+ return lhs[i] < rhs[i];
+ }
+ return false;
+ }
+
+ template <typename L, typename R>
+ mln_dpoint(L) // FIXME: promote!
+ operator-(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
+ {
+ mln::metal::bool_<(int(L::dim) = int(R::dim))>::check();
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_dpoint(L) tmp;
+ for (unsigned i = 0; i < L::dim; ++i)
+ tmp[i] = lhs[i] - rhs[i];
+ mln_postcondition(rhs_ + tmp = lhs_);
+ return tmp;
+ }
+
+ template <typename P, typename D>
+ mln_point(P) // FIXME: promote!
+ operator+(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
+ {
+ mln::metal::bool_<(int(P::dim) = int(D::dim))>::check();
+ const P& p = exact(p_);
+ const D& dp = exact(dp_);
+ mln_point(P) tmp;
+ for (unsigned i = 0; i < P::dim; ++i)
+ tmp[i] = p[i] + dp[i];
+ return tmp;
+ }
+
+ template <typename P, typename D>
+ mln_point(P) // FIXME: promote!
+ operator-(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
+ {
+ mln::metal::bool_<(int(P::dim) = int(D::dim))>::check();
+ const P& p = exact(p_);
+ const D& dp = exact(dp_);
+ mln_point(P) tmp;
+ for (unsigned i = 0; i < P::dim; ++i)
+ tmp[i] = p[i] - dp[i];
+ return tmp;
+ }
+
+ template <typename P>
+ std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p_)
+ {
+ const P& p = exact(p_);
+ ostr << '(';
+ for (unsigned i = 0; i < P::dim; ++i)
+ ostr << p[i] << (i = P::dim - 1 ? ')' : ',');
+ return ostr;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -105,4 +347,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_CONCEPT_PSITE_HH
+#endif // ! MLN_CORE_CONCEPT_POINT_SITE_HH
Index: mln/linear/local/convolve.hh
--- mln/linear/local/convolve.hh (revision 1397)
+++ mln/linear/local/convolve.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/concept/generalized_pixel.hh>
# include <mln/core/concept/weighted_window.hh>
# include <mln/metal/const.hh>
@@ -61,7 +61,7 @@
*/
template <typename I, typename P, typename W, typename R>
void convolve(const Image<I>& input,
- const Generalized_Point<P>& p,
+ const Point_Site<P>& p,
const Weighted_Window<W>& w_win,
R& result);
@@ -88,11 +88,11 @@
template <typename I, typename P, typename W, typename R>
void convolve(trait::image::speed::any, const I& input,
- const Generalized_Point<P>& p_,
+ const Point_Site<P>& p_,
const W& w_win,
R& result)
{
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
R tmp = 0; // FIXME: zero?
mln_qiter(W) q(w_win, p);
@@ -103,11 +103,11 @@
template <typename I, typename P, typename W, typename R>
void convolve(trait::image::speed::fastest, const I& input,
- const Generalized_Point<P>& p_,
+ const Point_Site<P>& p_,
const W& w_win,
R& result)
{
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
mln_precondition(input.border() >= w_win.delta());
@@ -144,7 +144,7 @@
template <typename I, typename P, typename W, typename R>
void convolve(const Image<I>& input,
- const Generalized_Point<P>& p,
+ const Point_Site<P>& p,
const Weighted_Window<W>& w_win,
R& result)
{
Index: mln/value/concept/built_in.hh
--- mln/value/concept/built_in.hh (revision 1397)
+++ mln/value/concept/built_in.hh (working copy)
@@ -42,7 +42,10 @@
namespace value
{
+ // Fwd decl.
template <typename B> struct Built_In;
+
+
// Category flag type.
template <>
struct Built_In<void> // No inheritance here since this category is special (on the side).
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1397)
+++ mln/convert/to_window.hh (working copy)
@@ -35,7 +35,7 @@
# include <set>
-# include <mln/core/concept/dpoint.hh>
+# include <mln/core/concept/delta_point_site.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
# include <mln/pw/image.hh>
@@ -124,7 +124,8 @@
template <typename D>
window<D> to_window(const std::set<D>& s)
{
- mln::metal::is_a<D, Dpoint>::check();
+ // FIXME: Was: mln::metal::is_a<D, Dpoint>::check();
+ mln::metal::is_a<D, Delta_Point_Site>::check();
window<D> win;
for (typename std::set<D>::const_iterator i = s.begin();
i != s.end(); ++i)
Index: mln/convert/to_set_p.hh
--- mln/convert/to_set_p.hh (revision 1397)
+++ mln/convert/to_set_p.hh (working copy)
@@ -35,8 +35,8 @@
# include <set>
-# include <mln/core/concept/dpoint.hh>
# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/point_site.hh>
# include <mln/core/set_p.hh>
# include <mln/pw/image.hh>
# include <mln/pw/cst.hh>
@@ -112,7 +112,7 @@
template <typename P>
set_p<P> to_set_p(const std::set<P>& s)
{
- mln::metal::is_a<P, Point>::check();
+ mln::metal::is_a<P, Point_Site>::check();
set_p<P> pset;
for (typename std::set<P>::const_iterator i = s.begin();
i != s.end(); ++i)
Index: mln/convert/to_dpoint.hh
--- mln/convert/to_dpoint.hh (revision 1397)
+++ mln/convert/to_dpoint.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Conversions to mln::Dpoint.
*/
-# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
namespace mln
@@ -42,17 +42,19 @@
namespace convert
{
- /// Convert a generalized point \p p into a delta-point.
+ /// Convert a point site \p p into a delta-point.
template <typename P>
- mln_dpoint(P) to_dpoint(const Generalized_Point<P>& p);
+ mln_dpoint(P) to_dpoint(const Point_Site<P>& p);
# ifndef MLN_INCLUDE_ONLY
template <typename P>
- mln_dpoint(P) to_dpoint(const Generalized_Point<P>& p_)
+ mln_dpoint(P) to_dpoint(const Point_Site<P>& p_)
{
- const P& p = internal::force_exact<P>(p_);
+ const P& p = exact(p_);
+ // FIXME HERE: Add ctors from vec in point_ and dpoint_.
+ // FIXME HERE: Then change to "return mln_dpoint(P)(p.to_vec());"
mln_dpoint(P) dp;
for (unsigned i = 0; i < P::dim; ++i)
dp[i] = p[i];
1
0