* tests/make/Makefile.am,
* tests/core/image/vertex_image.cc,
* tests/make/dummy_p_edges.cc,
* tests/make/dummy_p_vertices.cc,
* tests/make/p_edges_with_mass_centers.cc,
* tests/make/p_vertices_with_mass_centers.cc: new test for the newly
added routines.
---
milena/ChangeLog | 12 +
milena/tests/core/image/vertex_image.cc | 231 ++++++++++++++-------
milena/tests/make/Makefile.am | 8 +
milena/tests/make/dummy_p_edges.cc | 75 +++++++
milena/tests/make/dummy_p_vertices.cc | 75 +++++++
milena/tests/make/p_edges_with_mass_centers.cc | 86 ++++++++
milena/tests/make/p_vertices_with_mass_centers.cc | 84 ++++++++
7 files changed, 499 insertions(+), 72 deletions(-)
create mode 100644 milena/tests/make/dummy_p_edges.cc
create mode 100644 milena/tests/make/dummy_p_vertices.cc
create mode 100644 milena/tests/make/p_edges_with_mass_centers.cc
create mode 100644 milena/tests/make/p_vertices_with_mass_centers.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0b743d3..0e13e64 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2009-04-14 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new tests.
+
+ * tests/make/Makefile.am,
+ * tests/core/image/vertex_image.cc,
+ * tests/make/dummy_p_edges.cc,
+ * tests/make/dummy_p_vertices.cc,
+ * tests/make/p_edges_with_mass_centers.cc,
+ * tests/make/p_vertices_with_mass_centers.cc: new test for the newly
+ added routines.
+
+2009-04-14 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add small routines to help while constructing graph images.
* mln/make/dummy_p_edges.hh,
diff --git a/milena/tests/core/image/vertex_image.cc b/milena/tests/core/image/vertex_image.cc
index 3531420..8dcd980 100644
--- a/milena/tests/core/image/vertex_image.cc
+++ b/milena/tests/core/image/vertex_image.cc
@@ -32,6 +32,7 @@
#include <vector>
#include <mln/core/image/vertex_image.hh>
+#include <mln/make/vertex_image.hh>
#include <mln/core/image/image2d.hh>
#include <mln/accu/bbox.hh>
@@ -113,113 +114,199 @@ int main()
for (unsigned i = 0; i < iota.size(); ++i)
iota(i) = 10 + i;
- typedef vertex_image<point2d,unsigned> ima_t;
- ima_t ima(g, sites, iota);
+
+
+ /// Vertices are associated to image sites.
{
- // FIXME: Move this part to a special test case.
+ typedef vertex_image<point2d,unsigned> ima_t;
+ ima_t ima = make::vertex_image(g, sites, iota);
+
+ {
+ // FIXME: Move this part to a special test case.
+
+ // Compute the bounding box of 'ima'.
+ accu::bbox<point2d> a;
+ mln_piter_(ima_t) p(ima.domain());
+ for_all(p)
+ a.take(p);
+ box2d bbox = a.to_result();
+ mln_assertion(bbox == make::box2d(5, 5));
+
+ // Print the image.
+ /* FIXME: Unfortunately, displaying graph images is not easy right
+ now(2008-02-05). We could use
+
+ debug::println(ima);
+
+ but there's not specialization working for graph_image; the one
+ selected by the compiler is based on a 2-D bbox, and expects the
+ interface of graph_image to work with points(not psites).
+ Moreover, this implementation only shows *values*, not the graph
+ itslef.
+
+ An alternative is to use debug::graph,
+ but it doesn't show the values, only the vertices and edges of the
+ graph.
+
+ The current solution is a mix between debug::graph and hand-made
+ iterations. */
+ image2d<int> ima_rep(bbox);
+
+ // We use the value 9 in debug::graph to represent edges to distinguish it
+ // from vertices holding a value of 1.
+ debug::draw_graph(ima_rep, ima.domain(), 1, 9);
+ }
- // Compute the bounding box of 'ima'.
- accu::bbox<point2d> a;
+ /*------------.
+ | Iterators. |
+ `------------*/
+
+ // iteration over the domain of IMA.
mln_piter_(ima_t) p(ima.domain());
+ unsigned i = 10;
for_all(p)
- a.take(p);
- box2d bbox = a.to_result();
- mln_assertion(bbox == make::box2d(5, 5));
+ mln_assertion(ima(p) == i++);
- // Print the image.
- /* FIXME: Unfortunately, displaying graph images is not easy right
- now(2008-02-05). We could use
+ typedef ima_t::win_t win_t;
+ win_t win;
- debug::println(ima);
+ {
+ // Window - Forward iteration
+ mln_qiter_(win_t) q(win, p);
+ for_all(p)
+ {
+ i = 0;
+ for_all(q)
+ {
+ mln_assertion(expected_fwd_nb[p.id()][i] == q.id());
+ ++i;
+ }
+ }
+ }
- but there's not specialization working for graph_image; the one
- selected by the compiler is based on a 2-D bbox, and expects the
- interface of graph_image to work with points(not psites).
- Moreover, this implementation only shows *values*, not the graph
- itslef.
+ {
+ // Window - Backward iteration
+ mln_bkd_qiter_(win_t) q(win, p);
+ for_all(p)
+ {
+ i = 0;
+ for_all(q)
+ {
+ mln_assertion(expected_bkd_nb[p.id()][i] == q.id());
+ ++i;
+ }
+ }
+ }
- An alternative is to use debug::graph,
- but it doesn't show the values, only the vertices and edges of the
- graph.
+ typedef ima_t::nbh_t nbh_t;
+ nbh_t neigh;
+ {
+ // Neighborhood - Forward iteration
+ mln_niter_(nbh_t) n(neigh, p);
- The current solution is a mix between debug::graph and hand-made
- iterations. */
- image2d<int> ima_rep(bbox);
+ for_all(p)
+ {
+ i = 0;
+ for_all(n)
+ {
+ mln_assertion(expected_fwd_nb[p.id()][i] == n.id());
+ ++i;
+ }
+ }
+ }
- // We use the value 9 in debug::graph to represent edges to distinguish it
- // from vertices holding a value of 1.
- debug::draw_graph(ima_rep, ima.domain(), 1, 9);
+ {
+ // Neighborhood - Backward iteration
+ mln_bkd_niter_(nbh_t) n(neigh, p);
+ for_all(p)
+ {
+ i = 0;
+ for_all(n)
+ {
+ mln_assertion(expected_bkd_nb[p.id()][i] == n.id());
+ ++i;
+ }
+ }
+ }
}
- /*------------.
- | Iterators. |
- `------------*/
- // iteration over the domain of IMA.
- mln_piter_(ima_t) p(ima.domain());
- unsigned i = 10;
- for_all(p)
- mln_assertion(ima(p) == i++);
- typedef ima_t::win_t win_t;
- win_t win;
+ /// Vertices do not have image site information.
+ /// The associated sites are the vertex themselves.
{
- // Window - Forward iteration
- mln_qiter_(win_t) q(win, p);
+ typedef vertex_image<void,unsigned> ima_void_t;
+ ima_void_t ima_void(g, iota);
+
+ // iteration over the domain of IMA.
+ mln_piter_(ima_void_t) p(ima_void.domain());
+ unsigned i = 10;
for_all(p)
+ mln_assertion(ima_void(p) == i++);
+
+ typedef ima_void_t::win_t win_t;
+ win_t win;
+
{
- i = 0;
- for_all(q)
+ // Window - Forward iteration
+ mln_qiter_(win_t) q(win, p);
+ for_all(p)
{
- mln_assertion(expected_fwd_nb[p.id()][i] == q.id());
- ++i;
+ i = 0;
+ for_all(q)
+ {
+ mln_assertion(expected_fwd_nb[p.id()][i] == q.id());
+ ++i;
+ }
}
}
- }
- {
- // Window - Backward iteration
- mln_bkd_qiter_(win_t) q(win, p);
- for_all(p)
{
- i = 0;
- for_all(q)
+ // Window - Backward iteration
+ mln_bkd_qiter_(win_t) q(win, p);
+ for_all(p)
{
- mln_assertion(expected_bkd_nb[p.id()][i] == q.id());
- ++i;
+ i = 0;
+ for_all(q)
+ {
+ mln_assertion(expected_bkd_nb[p.id()][i] == q.id());
+ ++i;
+ }
}
}
- }
- typedef ima_t::nbh_t nbh_t;
- nbh_t neigh;
- {
- // Neighborhood - Forward iteration
- mln_niter_(nbh_t) n(neigh, p);
-
- for_all(p)
+ typedef ima_void_t::nbh_t nbh_t;
+ nbh_t neigh;
{
- i = 0;
- for_all(n)
+ // Neighborhood - Forward iteration
+ mln_niter_(nbh_t) n(neigh, p);
+
+ for_all(p)
{
- mln_assertion(expected_fwd_nb[p.id()][i] == n.id());
- ++i;
+ i = 0;
+ for_all(n)
+ {
+ //FIXME: Ambiguities with n.id()!!!!
+ mln_assertion(expected_fwd_nb[p.id()][i] == n.element().id());
+ ++i;
+ }
}
}
- }
- {
- // Neighborhood - Backward iteration
- mln_bkd_niter_(nbh_t) n(neigh, p);
- for_all(p)
{
- i = 0;
- for_all(n)
+ // Neighborhood - Backward iteration
+ mln_bkd_niter_(nbh_t) n(neigh, p);
+ for_all(p)
{
- mln_assertion(expected_bkd_nb[p.id()][i] == n.id());
- ++i;
+ i = 0;
+ for_all(n)
+ {
+ //FIXME: Ambiguities with n.id()!!!!
+ mln_assertion(expected_bkd_nb[p.id()][i] == n.element().id());
+ ++i;
+ }
}
}
}
diff --git a/milena/tests/make/Makefile.am b/milena/tests/make/Makefile.am
index 7e4c12b..ba517cd 100644
--- a/milena/tests/make/Makefile.am
+++ b/milena/tests/make/Makefile.am
@@ -4,22 +4,30 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
dual_neighb \
+ dummy_p_edges \
+ dummy_p_vertices \
graph \
h_mat \
image2d \
image3d \
mat \
+ p_edges_with_mass_centers \
+ p_vertices_with_mass_centers \
region_adjacency_graph \
rag_and_labeled_wsl \
w_window \
w_window_directional
dual_neighb_SOURCES = dual_neighb.cc
+dummy_p_edges_SOURCES = dummy_p_edges.cc
+dummy_p_vertices_SOURCES = dummy_p_vertices.cc
graph_SOURCES = graph.cc
h_mat_SOURCES = h_mat.cc
image2d_SOURCES = image2d.cc
image3d_SOURCES = image3d.cc
mat_SOURCES = mat.cc
+p_edges_with_mass_centers_SOURCES = p_edges_with_mass_centers.cc
+p_vertices_with_mass_centers_SOURCES = p_vertices_with_mass_centers.cc
region_adjacency_graph_SOURCES = region_adjacency_graph.cc
rag_and_labeled_wsl_SOURCES = rag_and_labeled_wsl.cc
w_window_SOURCES = w_window.cc
diff --git a/milena/tests/make/dummy_p_edges.cc b/milena/tests/make/dummy_p_edges.cc
new file mode 100644
index 0000000..b04e6d4
--- /dev/null
+++ b/milena/tests/make/dummy_p_edges.cc
@@ -0,0 +1,75 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/make/dummy_p_edges.cc
+///
+/// Tests on mln::make::dummy_p_edges.
+
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/util/graph.hh>
+
+#include <mln/value/label_8.hh>
+
+#include <mln/make/dummy_p_edges.hh>
+
+int main()
+{
+ using namespace mln;
+
+ typedef util::graph G;
+ G g;
+ g.add_vertices(5);
+ g.add_edge(1,2);
+ g.add_edge(1,3);
+ g.add_edge(4,3);
+ g.add_edge(4,2);
+
+ {
+ typedef p_edges<G, pw::cst_<int> > pe_t;
+ pe_t pe = make::dummy_p_edges(g);
+
+ mln_assertion(pe.nsites() == 4);
+ mln_piter_(pe_t) p(pe);
+ for_all(p)
+ mln_assertion(p == 0);
+ }
+
+ {
+ typedef p_edges<G, pw::cst_<point2d> > pe_t;
+ pe_t pe = make::dummy_p_edges(g, point2d::plus_infty());
+
+ mln_assertion(pe.nsites() == 4);
+ mln_piter_(pe_t) p(pe);
+ for_all(p)
+ mln_assertion(p == point2d::plus_infty());
+ }
+
+}
+
diff --git a/milena/tests/make/dummy_p_vertices.cc b/milena/tests/make/dummy_p_vertices.cc
new file mode 100644
index 0000000..6cfa2b8
--- /dev/null
+++ b/milena/tests/make/dummy_p_vertices.cc
@@ -0,0 +1,75 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/make/dummy_p_vertices.cc
+///
+/// Tests on mln::make::dummy_p_vertices.
+
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/util/graph.hh>
+
+#include <mln/value/label_8.hh>
+
+#include <mln/make/dummy_p_vertices.hh>
+
+int main()
+{
+ using namespace mln;
+
+ typedef util::graph G;
+ G g;
+ g.add_vertices(5);
+ g.add_edge(1,2);
+ g.add_edge(1,3);
+ g.add_edge(4,3);
+ g.add_edge(4,2);
+
+ {
+ typedef p_vertices<G, pw::cst_<int> > pe_t;
+ pe_t pe = make::dummy_p_vertices(g);
+
+ mln_assertion(pe.nsites() == 4);
+ mln_piter_(pe_t) p(pe);
+ for_all(p)
+ mln_assertion(p == 0);
+ }
+
+ {
+ typedef p_vertices<G, pw::cst_<point2d> > pe_t;
+ pe_t pe = make::dummy_p_vertices(g, point2d::plus_infty());
+
+ mln_assertion(pe.nsites() == 4);
+ mln_piter_(pe_t) p(pe);
+ for_all(p)
+ mln_assertion(p == point2d::plus_infty());
+ }
+
+}
+
diff --git a/milena/tests/make/p_edges_with_mass_centers.cc b/milena/tests/make/p_edges_with_mass_centers.cc
new file mode 100644
index 0000000..967320c
--- /dev/null
+++ b/milena/tests/make/p_edges_with_mass_centers.cc
@@ -0,0 +1,86 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/make/p_edges_with_mass_centers.cc
+///
+/// Tests on mln::make::p_edges_with_mass_centers.
+
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/util/graph.hh>
+
+#include <mln/value/label_8.hh>
+
+#include <mln/make/p_edges_with_mass_centers.hh>
+
+#include <mln/util/site_pair.hh>
+
+int main()
+{
+ using namespace mln;
+
+ typedef value::label_8 L;
+
+ L data[] = {
+ 1, 1, 1, 0, 2, 2, 2,
+ 1, 1, 1, 0, 2, 2, 2,
+ 1, 1, 1, 0, 2, 2, 2,
+ 0, 0, 0, 0, 0, 0, 0,
+ 3, 3, 3, 0, 4, 4, 4,
+ 3, 3, 3, 0, 4, 4, 4,
+ 3, 3, 3, 0, 4, 4, 4
+ };
+
+ image2d<L> wst = make::image2d(data);
+ typedef util::graph G;
+ G g;
+ g.add_vertices(5);
+ g.add_edge(1,2);
+ g.add_edge(1,3);
+ g.add_edge(4,3);
+ g.add_edge(4,2);
+
+ L nbasins = 4;
+ typedef p_edges<G,fun::i2v::array<util::site_pair<point2d> > > pe_t;
+ pe_t pe = make::p_edges_with_mass_centers(wst, nbasins, g);
+
+ typedef util::site_pair<point2d> P;
+ typedef p_array<P> arr_t;
+ arr_t arr;
+ arr.insert(P(point2d(1,1), point2d(1,5)));
+ arr.insert(P(point2d(1,1), point2d(5,1)));
+ arr.insert(P(point2d(5,1), point2d(5,5)));
+ arr.insert(P(point2d(1,5), point2d(5,5)));
+
+ mln_piter_(pe_t) p1(pe);
+ mln_piter_(arr_t) p2(arr);
+ for_all_2(p1,p2)
+ mln_assertion(p1 == p2);
+}
+
diff --git a/milena/tests/make/p_vertices_with_mass_centers.cc b/milena/tests/make/p_vertices_with_mass_centers.cc
new file mode 100644
index 0000000..2d103df
--- /dev/null
+++ b/milena/tests/make/p_vertices_with_mass_centers.cc
@@ -0,0 +1,84 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/make/p_vertices_with_mass_centers.cc
+///
+/// Tests on mln::make::p_vertices_with_mass_centers.
+
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/util/graph.hh>
+
+#include <mln/value/label_8.hh>
+
+#include <mln/make/p_vertices_with_mass_centers.hh>
+
+int main()
+{
+ using namespace mln;
+
+ typedef value::label_8 L;
+
+ L data[] = {
+ 1, 1, 1, 0, 2, 2, 2,
+ 1, 1, 1, 0, 2, 2, 2,
+ 1, 1, 1, 0, 2, 2, 2,
+ 0, 0, 0, 0, 0, 0, 0,
+ 3, 3, 3, 0, 4, 4, 4,
+ 3, 3, 3, 0, 4, 4, 4,
+ 3, 3, 3, 0, 4, 4, 4
+ };
+
+ image2d<L> wst = make::image2d(data);
+ typedef util::graph G;
+ G g;
+ g.add_vertices(5);
+ g.add_edge(1,2);
+ g.add_edge(1,3);
+ g.add_edge(4,3);
+ g.add_edge(4,2);
+
+ L nbasins = 4;
+ typedef p_vertices<G,fun::i2v::array<point2d> > pv_t;
+ pv_t pv = make::p_vertices_with_mass_centers(wst, nbasins, g);
+
+ typedef p_array<point2d> arr_t;
+ arr_t arr;
+ arr.insert(point2d(3,3));
+ arr.insert(point2d(1,1));
+ arr.insert(point2d(1,5));
+ arr.insert(point2d(5,1));
+ arr.insert(point2d(5,5));
+
+ mln_piter_(pv_t) p1(pv);
+ mln_piter_(arr_t) p2(arr);
+ for_all_2(p1,p2)
+ mln_assertion(p1 == p2);
+}
+
--
1.5.6.5
* mln/make/dummy_p_edges.hh,
* mln/make/dummy_p_vertices.hh: create graph site sets without
localization.
* mln/make/all.hh: update includes.
* mln/make/graph.hh: rename as...
* mln/make/influence_zone_adjacency_graph.hh: ...this.
* mln/make/p_edges_with_mass_centers.hh,
* mln/make/p_vertices_with_mass_centers.hh: new routines to construct
common graph site sets.
---
milena/ChangeLog | 17 +++
milena/mln/make/all.hh | 5 +-
milena/mln/make/dummy_p_edges.hh | 107 +++++++++++++++++
milena/mln/make/dummy_p_vertices.hh | 107 +++++++++++++++++
...{graph.hh => influence_zone_adjacency_graph.hh} | 0
milena/mln/make/p_edges_with_mass_centers.hh | 121 ++++++++++++++++++++
milena/mln/make/p_vertices_with_mass_centers.hh | 111 ++++++++++++++++++
7 files changed, 467 insertions(+), 1 deletions(-)
create mode 100644 milena/mln/make/dummy_p_edges.hh
create mode 100644 milena/mln/make/dummy_p_vertices.hh
rename milena/mln/make/{graph.hh => influence_zone_adjacency_graph.hh} (100%)
create mode 100644 milena/mln/make/p_edges_with_mass_centers.hh
create mode 100644 milena/mln/make/p_vertices_with_mass_centers.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 7f69bb3..0b743d3 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,20 @@
+2009-04-14 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add small routines to help while constructing graph images.
+
+ * mln/make/dummy_p_edges.hh,
+ * mln/make/dummy_p_vertices.hh: create graph site sets without
+ localization.
+
+ * mln/make/all.hh: update includes.
+
+ * mln/make/graph.hh: rename as...
+ * mln/make/influence_zone_adjacency_graph.hh: ...this.
+
+ * mln/make/p_edges_with_mass_centers.hh,
+ * mln/make/p_vertices_with_mass_centers.hh: new routines to construct
+ common graph site sets.
+
2009-04-09 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
Make util::array a Function_i2v.
diff --git a/milena/mln/make/all.hh b/milena/mln/make/all.hh
index 9665f14..52571ca 100644
--- a/milena/mln/make/all.hh
+++ b/milena/mln/make/all.hh
@@ -48,7 +48,6 @@ namespace mln
# include <mln/make/box3d.hh>
# include <mln/make/dpoint2d_h.hh>
# include <mln/make/dual_neighb.hh>
-# include <mln/make/graph.hh>
# include <mln/make/image.hh>
# include <mln/make/image2d.hh>
# include <mln/make/image3d.hh>
@@ -68,4 +67,8 @@ namespace mln
# include <mln/make/w_window_directional.hh>
# include <mln/make/win_chamfer.hh>
+# include <mln/make/influence_zone_adjacency_graph.hh>
+# include <mln/make/region_adjacency_graph.hh>
+# include <mln/make/rag_and_labeled_wsl.hh>
+
#endif // ! MLN_MAKE_ALL_HH
diff --git a/milena/mln/make/dummy_p_edges.hh b/milena/mln/make/dummy_p_edges.hh
new file mode 100644
index 0000000..927d0d8
--- /dev/null
+++ b/milena/mln/make/dummy_p_edges.hh
@@ -0,0 +1,107 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_DUMMY_P_EDGES_HH
+# define MLN_MAKE_DUMMY_P_EDGES_HH
+
+/// \file mln/make/dummy_p_edges.hh
+///
+/// Create a p_edges which associate a graph element to a constant site.
+///
+/// \sa edge_image, p_edges
+
+
+# include <mln/core/concept/graph.hh>
+# include <mln/core/site_set/p_edges.hh>
+# include <mln/pw/cst.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+
+ /// Create a p_edges which associate a graph element to a constant site.
+ ///
+ /// \param[in] g_ A graph.
+ /// \param[in] dummy_site The dummy site mapped to graph edges.
+ ///
+ /// \return A p_edges.
+ //
+ template <typename G, typename P>
+ p_edges< G, pw::cst_<P> >
+ dummy_p_edges(const Graph<G>& g_, const P& dummy_site);
+
+
+ /// Create a p_edges which associate a graph element to a constant site.
+ /// \c 0 (int) is used as dummy site.
+ ///
+ /// \param[in] g_ A graph.
+ ///
+ /// \return A p_edges.
+ //
+ template <typename G>
+ p_edges< G, pw::cst_<int> >
+ dummy_p_edges(const Graph<G>& g);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename G, typename P>
+ p_edges<G,pw::cst_<P> >
+ dummy_p_edges(const Graph<G>& g_, const P& dummy_site)
+ {
+ trace::entering("dummy_p_edges");
+
+ const G& g = exact(g_);
+ mln_precondition(g.is_valid());
+
+ p_edges< G, pw::cst_<P> > pe(g, pw::cst(dummy_site));
+
+ trace::exiting("dummy_p_edges");
+ return pe;
+ }
+
+
+ template <typename G>
+ p_edges< G, pw::cst_<int> >
+ dummy_p_edges(const Graph<G>& g)
+ {
+ return dummy_p_edges(g, 0);
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+#endif // ! MLN_MAKE_DUMMY_P_EDGES_HH
diff --git a/milena/mln/make/dummy_p_vertices.hh b/milena/mln/make/dummy_p_vertices.hh
new file mode 100644
index 0000000..910d02e
--- /dev/null
+++ b/milena/mln/make/dummy_p_vertices.hh
@@ -0,0 +1,107 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_DUMMY_P_VERTICES_HH
+# define MLN_MAKE_DUMMY_P_VERTICES_HH
+
+/// \file mln/make/dummy_p_vertices.hh
+///
+/// Create a p_vertices which associate a graph element to a constant site.
+///
+/// \sa edge_image, p_vertices
+
+
+# include <mln/core/concept/graph.hh>
+# include <mln/core/site_set/p_vertices.hh>
+# include <mln/pw/cst.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+
+ /// Create a p_vertices which associate a graph element to a constant site.
+ ///
+ /// \param[in] g_ A graph.
+ /// \param[in] dummy_site The dummy site mapped to graph vertices.
+ ///
+ /// \return A p_vertices.
+ //
+ template <typename G, typename P>
+ p_vertices< G, pw::cst_<P> >
+ dummy_p_vertices(const Graph<G>& g_, const P& dummy_site);
+
+
+ /// Create a p_vertices which associate a graph element to a constant site.
+ /// \c 0 (int) is used as dummy site.
+ ///
+ /// \param[in] g_ A graph.
+ ///
+ /// \return A p_vertices.
+ //
+ template <typename G>
+ p_vertices< G, pw::cst_<int> >
+ dummy_p_vertices(const Graph<G>& g);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename G, typename P>
+ p_vertices<G,pw::cst_<P> >
+ dummy_p_vertices(const Graph<G>& g_, const P& dummy_site)
+ {
+ trace::entering("dummy_p_vertices");
+
+ const G& g = exact(g_);
+ mln_precondition(g.is_valid());
+
+ p_vertices< G, pw::cst_<P> > pe(g, pw::cst(dummy_site));
+
+ trace::exiting("dummy_p_vertices");
+ return pe;
+ }
+
+
+ template <typename G>
+ p_vertices< G, pw::cst_<int> >
+ dummy_p_vertices(const Graph<G>& g)
+ {
+ return dummy_p_vertices(g, 0);
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+#endif // ! MLN_MAKE_DUMMY_P_VERTICES_HH
diff --git a/milena/mln/make/graph.hh b/milena/mln/make/influence_zone_adjacency_graph.hh
similarity index 100%
rename from milena/mln/make/graph.hh
rename to milena/mln/make/influence_zone_adjacency_graph.hh
diff --git a/milena/mln/make/p_edges_with_mass_centers.hh b/milena/mln/make/p_edges_with_mass_centers.hh
new file mode 100644
index 0000000..06a2376
--- /dev/null
+++ b/milena/mln/make/p_edges_with_mass_centers.hh
@@ -0,0 +1,121 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
+# define MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
+
+/// \file mln/make/p_edges_with_mass_centers.hh
+///
+/// Construct a p_edges from a watershed image and a region adjacency
+/// graph (RAG). Map each graph edge to a pair of mass centers of two
+/// adjacent regions.
+///
+/// \sa edge_image, p_edges
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/graph.hh>
+# include <mln/core/site_set/p_edges.hh>
+
+# include <mln/labeling/compute.hh>
+
+# include <mln/accu/center.hh>
+
+# include <mln/fun/i2v/array.hh>
+
+# include <mln/util/site_pair.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /// Construct a p_edges from a watershed image and a region adjacency
+ /// graph (RAG). Map each graph edge to a pair of mass centers of two
+ /// adjacent regions.
+ ///
+ /// \param wst_ A watershed image.
+ /// \param nbasins The number of basins.
+ /// \param g_ A region adjacency graph.
+ ///
+ /// \return A p_edges.
+ ///
+ /// \sa edge_image, p_edges, make::region_adjacency_graph
+ //
+ template <typename W, typename G>
+ inline
+ p_edges<G, fun::i2v::array<util::site_pair<mln_site(W)> > >
+ p_edges_with_mass_centers(const Image<W>& wst_,
+ const mln_value(W)& nbasins,
+ const Graph<G>& g_);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename W, typename G>
+ inline
+ p_edges<G, fun::i2v::array<util::site_pair<mln_site(W)> > >
+ p_edges_with_mass_centers(const Image<W>& wst_,
+ const mln_value(W)& nbasins,
+ const Graph<G>& g_)
+ {
+ trace::entering("make::p_edges_with_mass_centers");
+
+ const W& wst = exact(wst_);
+ const G& g = exact(g_);
+ mln_precondition(wst.is_valid());
+ mln_precondition(g.is_valid());
+
+ typedef mln_site(W) P;
+
+ util::array<mln_vec(P)>
+ mass_centers = labeling::compute(accu::center<P>(), wst, nbasins);
+
+ typedef fun::i2v::array< util::site_pair<P> > edge_sites_t;
+ edge_sites_t edge_sites(g.e_nmax());
+
+ mln_edge_iter(G) e(g);
+ for_all(e)
+ edge_sites(e.id()) = util::site_pair<P>(mass_centers[e.v1()],
+ mass_centers[e.v2()]);
+
+ p_edges<G, edge_sites_t> pe(g, edge_sites);
+
+ trace::exiting("make::p_edges_with_mass_centers");
+ return pe;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+#endif // ! MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
diff --git a/milena/mln/make/p_vertices_with_mass_centers.hh b/milena/mln/make/p_vertices_with_mass_centers.hh
new file mode 100644
index 0000000..064cdbc
--- /dev/null
+++ b/milena/mln/make/p_vertices_with_mass_centers.hh
@@ -0,0 +1,111 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
+# define MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
+
+/// \file mln/make/p_vertices_with_mass_centers.hh
+///
+/// Create a p_vertices using region mass centers as vertex site.
+///
+/// \sa vertex_image, p_vertices
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/graph.hh>
+# include <mln/core/site_set/p_vertices.hh>
+
+# include <mln/labeling/compute.hh>
+
+# include <mln/accu/center.hh>
+
+# include <mln/fun/i2v/array.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /// Construct a p_vertices from a watershed image and a region adjacency
+ /// graph (RAG). Map each graph vertex to the mass center of its
+ /// corresponding region.
+ ///
+ /// \param wst_ A watershed image.
+ /// \param nbasins The number of basins.
+ /// \param g_ A region adjacency graph.
+ ///
+ /// \return A p_vertices.
+ ///
+ /// \sa edge_image, vertex_image, p_vertices, p_edges, make::region_adjacency_graph
+ //
+ template <typename W, typename G>
+ inline
+ p_vertices<G, fun::i2v::array<mln_site(W)> >
+ p_vertices_with_mass_centers(const Image<W>& wst_,
+ const mln_value(W)& nbasins,
+ const Graph<G>& g_);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename W, typename G>
+ inline
+ p_vertices<G, fun::i2v::array<mln_site(W)> >
+ p_vertices_with_mass_centers(const Image<W>& wst_,
+ const mln_value(W)& nbasins,
+ const Graph<G>& g_)
+ {
+ trace::entering("make::p_vertices_with_mass_centers");
+
+ const W& wst = exact(wst_);
+ const G& g = exact(g_);
+ mln_precondition(wst.is_valid());
+ mln_precondition(g.is_valid());
+
+ typedef mln_site(W) P;
+ typedef fun::i2v::array<P> vertex_sites_t;
+
+ vertex_sites_t vertex_sites;
+ convert::from_to(labeling::compute(accu::center<P>(), wst, nbasins),
+ vertex_sites);
+
+ p_vertices<G, vertex_sites_t> pv(g, vertex_sites);
+
+ trace::exiting("make::p_vertices_with_mass_centers");
+ return pv;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+#endif // ! MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
--
1.5.6.5
* mln/labeling/all.hh: include new header.
* mln/labeling/relabel.hh: move an overload...
* mln/labeling/pack.hh: ... in this new routine.
* tests/labeling/Makefile.am,
* tests/labeling/pack.cc: add a new test.
---
milena/ChangeLog | 14 ++-
milena/mln/labeling/all.hh | 1 +
milena/mln/labeling/pack.hh | 151 ++++++++++++++++++++
milena/mln/labeling/relabel.hh | 78 ++---------
milena/tests/labeling/Makefile.am | 2 +
.../labeling/all.hh => tests/labeling/pack.cc} | 68 +++++-----
6 files changed, 214 insertions(+), 100 deletions(-)
create mode 100644 milena/mln/labeling/pack.hh
copy milena/{mln/labeling/all.hh => tests/labeling/pack.cc} (56%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 76e2c32..a52c977 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,4 +1,16 @@
-2009-04-08 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+2009-04-09 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add labeling::pack.
+
+ * mln/labeling/all.hh: include new header.
+
+ * mln/labeling/relabel.hh: move an overload...
+ * mln/labeling/pack.hh: ... in this new routine.
+
+ * tests/labeling/Makefile.am,
+ * tests/labeling/pack.cc: add a new test.
+
+2009-04-09 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
Small fixes.
diff --git a/milena/mln/labeling/all.hh b/milena/mln/labeling/all.hh
index 798ee02..2931427 100644
--- a/milena/mln/labeling/all.hh
+++ b/milena/mln/labeling/all.hh
@@ -61,6 +61,7 @@ namespace mln
# include <mln/labeling/foreground.hh>
# include <mln/labeling/level.hh>
# include <mln/labeling/n_max.hh>
+# include <mln/labeling/pack.hh>
# include <mln/labeling/regional_maxima.hh>
# include <mln/labeling/regional_minima.hh>
diff --git a/milena/mln/labeling/pack.hh b/milena/mln/labeling/pack.hh
new file mode 100644
index 0000000..45a08e3
--- /dev/null
+++ b/milena/mln/labeling/pack.hh
@@ -0,0 +1,151 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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_LABELING_PACK_HH
+# define MLN_LABELING_PACK_HH
+
+/// \file mln/labeling/pack.hh
+///
+/// Remove components and relabel a labeled image in order to have a
+/// contiguous labeling.
+
+
+# include <mln/core/concept/image.hh>
+
+# include <mln/make/relabelfun.hh>
+
+# include <mln/level/compute.hh>
+# include <mln/level/transform.hh>
+
+# include <mln/accu/label_used.hh>
+
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /// Relabel a labeled image in order to have a contiguous labeling.
+ /// \input[in] label The labeled image.
+ /// \input[out] new_nlabels The number of labels after relabeling.
+ ///
+ /// \return The relabeled image.
+ //
+ template <typename I>
+ mln_concrete(I)
+ pack(const Image<I>& label, mln_value(I)& new_nlabels);
+
+
+
+ /// Relabel inplace a labeled image in order to have a contiguous
+ /// labeling.
+ /// \input[in] label The labeled image.
+ /// \input[out] new_nlabels The number of labels after relabeling.
+ //
+ template <typename I>
+ void
+ relabel_inplace(Image<I>& label, mln_value(I)& new_nlabels);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I>
+ void
+ pack_tests(const Image<I>& label, mln_value(I)& new_nlabels)
+ {
+ // FIXME: we may want to check that it is exactly a label.
+ mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
+ mln_precondition(exact(label).is_valid());
+ (void) label;
+ (void) new_nlabels;
+ }
+
+ } // end of mln::labeling::internal
+
+
+
+ template <typename I>
+ mln_concrete(I)
+ pack(const Image<I>& label, mln_value(I)& new_nlabels)
+ {
+ trace::entering("labeling::pack");
+
+ internal::pack_tests(label, new_nlabels);
+
+ fun::i2v::array<bool>
+ fv2b = level::compute(accu::meta::label_used(), label);
+
+ mln_value(I) tmp_nlabels = fv2b.size() - 1;
+ mln_concrete(I)
+ output = level::transform(label,
+ make::relabelfun(fv2b,
+ tmp_nlabels,
+ new_nlabels));
+
+ trace::exiting("labeling::pack");
+ return output;
+ }
+
+
+
+ template <typename I>
+ void
+ pack_inplace(Image<I>& label, mln_value(I)& new_nlabels)
+ {
+ trace::entering("labeling::pack_inplace");
+
+ internal::pack_tests(label, new_nlabels);
+
+ fun::i2v::array<bool>
+ fv2b = level::compute(accu::meta::label_used(), label);
+
+ mln_value(I) tmp_nlabels = fv2b.size() - 1;
+ exact(label) = level::transform(label,
+ make::relabelfun(fv2b,
+ tmp_nlabels,
+ new_nlabels));
+
+ trace::exiting("labeling::pack_inplace");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_PACK_HH
diff --git a/milena/mln/labeling/relabel.hh b/milena/mln/labeling/relabel.hh
index c24c0dd..e811db1 100644
--- a/milena/mln/labeling/relabel.hh
+++ b/milena/mln/labeling/relabel.hh
@@ -33,28 +33,23 @@
///
/// Remove components and relabel a labeled image.
+
# include <mln/core/concept/image.hh>
+
# include <mln/make/relabelfun.hh>
-# include <mln/level/compute.hh>
+
# include <mln/level/transform.hh>
# include <mln/level/transform_inplace.hh>
+
# include <mln/value/label.hh>
-# include <mln/accu/label_used.hh>
+
+
namespace mln
{
namespace labeling
{
- /// Relabel a labeled image in order to have a contiguous labeling.
- /// \input[in] label The labeled image.
- /// \input[out] new_nlabels The number of labels after relabeling.
- ///
- /// \return The relabeled image.
- template <typename I>
- mln_concrete(I)
- relabel(const Image<I>& label,
- mln_value(I)& new_nlabels);
/// Remove components and relabel a labeled image.
/// \input[in] label the labeled image.
@@ -64,6 +59,7 @@ namespace mln
/// by the background.
///
/// \return the relabeled image.
+ //
template <typename I, typename F>
mln_concrete(I)
relabel(const Image<I>& label,
@@ -71,6 +67,7 @@ namespace mln
mln_value(I)& new_nlabels,
const Function_v2b<F>& fv2b);
+
/// Remove components and relabel a labeled image.
/// \input[in] label the labeled image.
/// \input[in] nlabels the number of labels in \p label.
@@ -78,39 +75,33 @@ namespace mln
/// value.
///
/// \return the relabeled image.
+ //
template <typename I, typename F>
mln_concrete(I)
relabel(const Image<I>& label,
const mln_value(I)& nlabels,
const Function_v2v<F>& fv2v);
- /// Relabel inplace a labeled image in order to have a contiguous
- /// labeling.
- /// \input[in] label The labeled image.
- /// \input[out] new_nlabels The number of labels after relabeling.
- template <typename I>
- void
- relabel_inplace(Image<I>& label,
- mln_value(I)& new_nlabels);
/// Remove components and relabel a labeled image inplace.
/// \input[in, out] label the labeled image.
/// \input[in, out] nlabels the number of labels in \p label.
/// \input[in] f function returning whether a label must be replaced
/// by the background.
- ///
+ //
template <typename I, typename F>
void
relabel_inplace(Image<I>& label,
mln_value(I)& nlabels,
const Function_v2b<F>& fv2b);
+
/// Remove components and relabel a labeled image inplace.
/// \input[in, out] label the labeled image.
/// \input[in, out] nlabels the number of labels in \p label.
/// \input[in] f function returning the new component id for each
/// pixel value.
- ///
+ //
template <typename I, typename F>
void
relabel_inplace(Image<I>& label,
@@ -185,29 +176,6 @@ namespace mln
} // end of namespace mln::labeling::internal
- template <typename I>
- mln_concrete(I)
- relabel(const Image<I>& label,
- mln_value(I)& new_nlabels)
- {
- trace::entering("labeling::relabel");
-
- internal::relabel_tests(label, new_nlabels);
-
- fun::i2v::array<bool>
- fv2b = level::compute(accu::meta::label_used(), label);
-
- mln_value(I) tmp_nlabels = fv2b.size() - 1;
- mln_concrete(I)
- output = level::transform(label,
- make::relabelfun(fv2b,
- tmp_nlabels,
- new_nlabels));
-
- trace::exiting("labeling::relabel");
- return output;
- }
-
template <typename I, typename F>
inline
@@ -249,28 +217,6 @@ namespace mln
}
- template <typename I>
- void
- relabel_inplace(Image<I>& label,
- mln_value(I)& new_nlabels)
- {
- trace::entering("labeling::relabel_inplace");
-
- internal::relabel_tests(label, new_nlabels);
-
- fun::i2v::array<bool>
- fv2b = level::compute(accu::meta::label_used(), label);
-
- mln_value(I) tmp_nlabels = fv2b.size() - 1;
- exact(label) = level::transform(label,
- make::relabelfun(fv2b,
- tmp_nlabels,
- new_nlabels));
-
- trace::exiting("labeling::relabel_inplace");
- }
-
-
template <typename I, typename F>
inline
void
diff --git a/milena/tests/labeling/Makefile.am b/milena/tests/labeling/Makefile.am
index f436f63..411674e 100644
--- a/milena/tests/labeling/Makefile.am
+++ b/milena/tests/labeling/Makefile.am
@@ -12,6 +12,7 @@ check_PROGRAMS = \
level \
mean_values \
n_max \
+ pack \
regional_maxima \
regional_minima \
relabel \
@@ -26,6 +27,7 @@ foreground_SOURCES = foreground.cc
level_SOURCES = level.cc
mean_values_SOURCES = mean_values.cc
n_max_SOURCES = n_max.cc
+pack_SOURCES = pack.cc
regional_maxima_SOURCES = regional_maxima.cc
regional_minima_SOURCES = regional_minima.cc
relabel_SOURCES = relabel.cc
diff --git a/milena/mln/labeling/all.hh b/milena/tests/labeling/pack.cc
similarity index 56%
copy from milena/mln/labeling/all.hh
copy to milena/tests/labeling/pack.cc
index 798ee02..b839d64 100644
--- a/milena/mln/labeling/all.hh
+++ b/milena/tests/labeling/pack.cc
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -26,43 +26,45 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_LABELING_ALL_HH
-# define MLN_LABELING_ALL_HH
-
-/// \file mln/labeling/all.hh
-///
-/// File that includes all labeling routines.
+/// \file tests/labeling/pack.cc
///
-/// \todo Many files in this directory have to be updated with the
-/// test and dispatch mechanisms.
+/// Tests on mln::labeling::pack.
-namespace mln
-{
+#include <mln/core/image/image2d.hh>
+#include <mln/labeling/pack.hh>
+#include <mln/level/compare.hh>
+#include <mln/value/label_16.hh>
+#include <mln/debug/println.hh>
- /// Namespace of labeling routines.
- namespace labeling
- {
- /// Implementation namespace of labeling namespace.
- namespace impl {
+int main()
+{
+ using namespace mln;
+ using value::label_16;
- /// Generic implementation namespace of labeling namespace.
- namespace generic {}
+ label_16 vals2[6][5] = {
+ { 0, 10, 10, 0, 0},
+ { 0, 10, 10, 4, 0},
+ { 0, 0, 0, 0, 0},
+ {12, 12, 0, 3, 0},
+ {12, 50, 3, 3, 3},
+ {12, 50, 50, 0, 0}
+ };
- }
- }
-}
+ label_16 vals_ref[6][5] = {
+ { 0, 3, 3, 0, 0},
+ { 0, 3, 3, 2, 0},
+ { 0, 0, 0, 0, 0},
+ { 4, 4, 0, 1, 0},
+ { 4, 5, 1, 1, 1},
+ { 4, 5, 5, 0, 0}
+ };
-# include <mln/labeling/background.hh>
-# include <mln/labeling/blobs.hh>
-# include <mln/labeling/compute.hh>
-# include <mln/labeling/fill_holes.hh>
-# include <mln/labeling/flat_zones.hh>
-# include <mln/labeling/foreground.hh>
-# include <mln/labeling/level.hh>
-# include <mln/labeling/n_max.hh>
-# include <mln/labeling/regional_maxima.hh>
-# include <mln/labeling/regional_minima.hh>
+ image2d<label_16> lbl2 = make::image(vals2);
+ image2d<label_16> lbl_ref = make::image(vals_ref);
+ label_16 nlabels;
+ image2d<label_16> relbl = labeling::pack(lbl2, nlabels);
-#endif // ! MLN_LABELING_ALL_HH
+ mln_assertion(lbl_ref == relbl);
+}
--
1.5.6.5
* mln/core/internal/image_morpher.hh: remove operator I().
---
milena/ChangeLog | 7 ++++++
milena/mln/core/internal/image_morpher.hh | 31 ++++++++--------------------
2 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4a24f51..7e6190d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2009-04-08 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Remove an invalid conversion operator from a morpher to a concrete
+ image.
+
+ * mln/core/internal/image_morpher.hh: remove operator I().
+
+2009-04-08 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Introduce edge_image and vertex_image types.
* mln/core/site_set/p_graph_piter.hh,
diff --git a/milena/mln/core/internal/image_morpher.hh b/milena/mln/core/internal/image_morpher.hh
index ab50ea8..fd170ea 100644
--- a/milena/mln/core/internal/image_morpher.hh
+++ b/milena/mln/core/internal/image_morpher.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,12 +29,11 @@
#ifndef MLN_CORE_INTERNAL_IMAGE_MORPHER_HH
# define MLN_CORE_INTERNAL_IMAGE_MORPHER_HH
-/*! \file mln/core/internal/image_morpher.hh
- *
- * \brief Definition of a base class for image morphers.
- *
- * \todo Add the appropriate checks in .rw().
- */
+/// \file mln/core/internal/image_morpher.hh
+///
+/// Definition of a base class for image morphers.
+///
+/// \todo Add the appropriate checks in .rw().
# include <mln/core/internal/image_base.hh>
# include <mln/metal/const.hh>
@@ -47,9 +47,8 @@ namespace mln
namespace internal
{
- /*! A base class for images that are morphers. Parameter
- * \c I is the underlying-morphed image type.
- */
+ /// A base class for images that are morphers. Parameter
+ /// \c I is the underlying-morphed image type.
template <typename I, typename T, typename S, typename E>
class image_morpher : public image_base<T, S, E>
{
@@ -80,9 +79,6 @@ namespace mln
*/
bool is_valid() const;
- /// Conversion to the underlying (morphed) image.
- operator I() const; // FIXME: Very dangerous? Remove?
-
/// State that the morpher is writable. This allows for C++ to
/// use it as a mutable object even if it is a temporary object.
@@ -165,15 +161,6 @@ namespace mln
return *ptr;
}
-
- template <typename I, typename T, typename S, typename E>
- inline
- image_morpher<I, T, S, E>::operator I() const
- {
- mln_precondition(exact(this)->is_valid());
- return * this->delegatee_();
- }
-
template <typename I, typename T, typename S, typename E>
inline
bool
--
1.5.6.5