* mln/core/image/graph_window_piter.hh,
* mln/core/internal/neighb_niter_impl.hh,
* mln/core/site_set/p_graph_piter.hh: add id().
* tests/core/image/graph_image.cc,
* tests/core/image/line_graph_image.cc: use id() instead of
element().id().
---
milena/ChangeLog | 12 ++++
milena/mln/core/image/graph_window_piter.hh | 37 +++++++++---
milena/mln/core/internal/neighb_niter_impl.hh | 10 +++
milena/mln/core/site_set/p_graph_piter.hh | 11 +++
milena/tests/core/image/graph_image.cc | 84 ++++++++++++------------
milena/tests/core/image/line_graph_image.cc | 80 ++++++++++++------------
6 files changed, 144 insertions(+), 90 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 60a03d4..75ed693 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2008-12-12 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add missing id() member in graph related piters.
+
+ * mln/core/image/graph_window_piter.hh,
+ * mln/core/internal/neighb_niter_impl.hh,
+ * mln/core/site_set/p_graph_piter.hh: add id().
+
+ * tests/core/image/graph_image.cc,
+ * tests/core/image/line_graph_image.cc: use id() instead of
+ element().id().
+
+2008-12-12 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add new macros mln_*ITER() to declare iterators.
* tests/core/other/category.cc,
diff --git a/milena/mln/core/image/graph_window_piter.hh
b/milena/mln/core/image/graph_window_piter.hh
index e4186f3..86abb4d 100644
--- a/milena/mln/core/image/graph_window_piter.hh
+++ b/milena/mln/core/image/graph_window_piter.hh
@@ -91,6 +91,12 @@ namespace mln
/// Compute the current psite.
mln_psite(W) compute_p_() const;
+
+ /// Convert towards the graph element id.
+ operator unsigned() const;
+
+ /// Return the graph element id.
+ unsigned id() const;
/// \}
private:
@@ -151,14 +157,6 @@ namespace mln
}
template <typename S, typename W, typename I>
- inline
- mln_psite(W)
- graph_window_piter<S,W,I>::compute_p_() const
- {
- return mln_psite(S)(this->center().site_set(), iter_.id());
- }
-
- template <typename S, typename W, typename I>
template <typename Pref>
inline
void
@@ -170,12 +168,35 @@ namespace mln
template <typename S, typename W, typename I>
inline
+ mln_psite(W)
+ graph_window_piter<S,W,I>::compute_p_() const
+ {
+ return mln_psite(S)(this->center().site_set(), iter_.id());
+ }
+
+ template <typename S, typename W, typename I>
+ inline
const mln_graph_element(S)&
graph_window_piter<S, W, I>::element() const
{
return iter_;
}
+ template <typename S, typename W, typename I>
+ inline
+ graph_window_piter<S, W, I>::operator unsigned() const
+ {
+ return iter_.id();
+ }
+
+ template <typename S, typename W, typename I>
+ inline
+ unsigned
+ graph_window_piter<S, W, I>::id() const
+ {
+ return iter_.id();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
diff --git a/milena/mln/core/internal/neighb_niter_impl.hh
b/milena/mln/core/internal/neighb_niter_impl.hh
index aa0965d..d80789f 100644
--- a/milena/mln/core/internal/neighb_niter_impl.hh
+++ b/milena/mln/core/internal/neighb_niter_impl.hh
@@ -67,6 +67,16 @@ namespace mln
return internal::force_exact<E>(*this).compute_p_().element();
}
+ unsigned id() const
+ {
+ return internal::force_exact<E>(*this).compute_p_().id();
+ }
+
+ operator unsigned() const
+ {
+ return internal::force_exact<E>(*this).compute_p_().id();
+ }
+
};
diff --git a/milena/mln/core/site_set/p_graph_piter.hh
b/milena/mln/core/site_set/p_graph_piter.hh
index d91a2cb..e6f4ce8 100644
--- a/milena/mln/core/site_set/p_graph_piter.hh
+++ b/milena/mln/core/site_set/p_graph_piter.hh
@@ -91,6 +91,9 @@ namespace mln
/// Convert towards the graph element id.
operator unsigned() const;
+ /// Return the graph element id.
+ unsigned id() const;
+
private:
/// Update the psite corresponding to this iterator.
@@ -199,6 +202,14 @@ namespace mln
template <typename S, typename I>
inline
+ unsigned
+ p_graph_piter<S,I>::id() const
+ {
+ return iter_.id();
+ }
+
+ template <typename S, typename I>
+ inline
void
p_graph_piter<S,I>::update_()
{
diff --git a/milena/tests/core/image/graph_image.cc
b/milena/tests/core/image/graph_image.cc
index 2094a24..20e0961 100644
--- a/milena/tests/core/image/graph_image.cc
+++ b/milena/tests/core/image/graph_image.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright(C) 2007, 2008 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
@@ -46,20 +46,33 @@
#include <mln/debug/draw_graph.hh>
#include <mln/debug/println.hh>
+/* The graph is as follows:
+
+ 0 1 2 3 4
+ .-----------
+ |
+ 0 | 0 2
+ 1 | \ / |
+ 2 | 1 |
+ 3 | \ |
+ 4 | 3-4
+
+*/
// Expected neighbors for forward and backward iteration.
-static unsigned fwd[5][3] = { { 1, -1, -1 },
- { 0, 2, 3 },
- { 1, 4, -1 },
- { 1, 4, -1 },
- { 3, 2, -1 } };
+// -1 is an invalid id.
+static unsigned expected_fwd_nb[5][3] = { { 1, -1, -1 },
+ { 0, 2, 3 },
+ { 1, 4, -1 },
+ { 1, 4, -1 },
+ { 3, 2, -1 } };
-static unsigned bkd[5][3] = { { 1, -1, -1 },
- { 3, 2, 0 },
- { 4, 1, -1 },
- { 4, 1, -1 },
- { 2, 3, -1 } };
+static unsigned expected_bkd_nb[5][3] = { { 1, -1, -1 },
+ { 3, 2, 0 },
+ { 4, 1, -1 },
+ { 4, 1, -1 },
+ { 2, 3, -1 } };
int main()
@@ -70,19 +83,6 @@ int main()
| Graph. |
`--------*/
- /* The graph is as follows:
-
- 0 1 2 3 4
- .-----------
- |
- 0 | 0 2
- 1 | \ / |
- 2 | 1 |
- 3 | \ |
- 4 | 3-4
-
- */
-
// Points associated to vertices.
typedef fun::i2v::array<point2d> fsite_t;
fsite_t sites(5);
@@ -95,7 +95,7 @@ int main()
// Edges.
util::graph g;
// Populate the graph with vertices.
- for (unsigned i = 0; i < sites.size(); ++i)
+ for(unsigned i = 0; i < sites.size(); ++i)
g.add_vertex();
// Populate the graph with edges.
g.add_edge(0, 1);
@@ -120,11 +120,11 @@ int main()
// Graph values.
typedef fun::i2v::array<unsigned> viota_t;
viota_t iota(pv.nsites());
- for (unsigned i = 0; i < iota.size(); ++i)
+ for(unsigned i = 0; i < iota.size(); ++i)
iota(i) = 10 + i;
// Create graph image.
- mln_const_VAR(ima, (iota | pv));
+ mln_const_VAR(ima,(iota | pv));
{
// FIXME: Move this part to a special test case.
@@ -139,13 +139,13 @@ int main()
// Print the image.
/* FIXME: Unfortunately, displaying graph images is not easy right
- now (2008-02-05). We could use
+ 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).
+ interface of graph_image to work with points(not psites).
Moreover, this implementation only shows *values*, not the graph
itslef.
@@ -169,7 +169,7 @@ int main()
// iteration over the domain of IMA.
mln_piter_(ima_t) p(ima.domain());
unsigned i = 10;
- for_all (p)
+ for_all(p)
mln_assertion(ima(p) == i++);
typedef graph_elt_window<util::graph, fsite_t> win_t;
@@ -178,12 +178,12 @@ int main()
{
// Window - Forward iteration
mln_qiter_(win_t) q(win, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (q)
+ for_all(q)
{
- mln_assertion(fwd[p.element().id()][i] == q.element().id());
+ mln_assertion(expected_fwd_nb[p.id()][i] == q.id());
++i;
}
}
@@ -192,12 +192,12 @@ int main()
{
// Window - Backward iteration
mln_bkd_qiter_(win_t) q(win, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (q)
+ for_all(q)
{
- mln_assertion(bkd[p.element().id()][i] == q.element().id());
+ mln_assertion(expected_bkd_nb[p.id()][i] == q.id());
++i;
}
}
@@ -209,12 +209,12 @@ int main()
// Neighborhood - Forward iteration
mln_niter_(neighb_t) n(neigh, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (n)
+ for_all(n)
{
- mln_assertion(fwd[p.element().id()][i] == n.element().id());
+ mln_assertion(expected_fwd_nb[p.id()][i] == n.id());
++i;
}
}
@@ -223,12 +223,12 @@ int main()
{
// Neighborhood - Backward iteration
mln_bkd_niter_(neighb_t) n(neigh, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (n)
+ for_all(n)
{
- mln_assertion(bkd[p.element().id()][i] == n.element().id());
+ mln_assertion(expected_bkd_nb[p.id()][i] == n.id());
++i;
}
}
diff --git a/milena/tests/core/image/line_graph_image.cc
b/milena/tests/core/image/line_graph_image.cc
index 36a836f..e7008e7 100644
--- a/milena/tests/core/image/line_graph_image.cc
+++ b/milena/tests/core/image/line_graph_image.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright(C) 2007, 2008 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
@@ -44,19 +44,32 @@
#include <mln/core/var.hh>
+/* The graph and its corresponding line graph are as follows:
+
+ 0 1 2 3 4 0 1 2 3 4
+ .----------- .-----------
+ | |
+ 0 | 0 2 0 | * *
+ 1 | \ / | 1 | 0 1 |
+ 2 | 1 | 2 | * 4
+ 3 | \ | 3 | 2 |
+ 4 | 3-4 4 | *3*
+
+*/
+
// Expected neighbors for forward and backward iteration.
-static unsigned fwd[5][3] = { { 1, 2, -1 },
- { 0, 2, 4 },
- { 0, 1, 3 },
- { 2, 4, -1 },
- { 1, 3, -1 } };
+static unsigned expected_fwd_nbh[5][3] = { { 1, 2, -1 },
+ { 0, 2, 4 },
+ { 0, 1, 3 },
+ { 2, 4, -1 },
+ { 1, 3, -1 } };
-static unsigned bkd[5][3] = { { 2, 1, -1 },
- { 4, 2, 0 },
- { 3, 1, 0 },
- { 4, 2, -1 },
- { 3, 1, -1 } };
+static unsigned expected_bkd_nbh[5][3] = { { 2, 1, -1 },
+ { 4, 2, 0 },
+ { 3, 1, 0 },
+ { 4, 2, -1 },
+ { 3, 1, -1 } };
int main()
@@ -67,19 +80,6 @@ int main()
| Graph. |
`--------*/
- /* The graph and its corresponding line graph are as follows:
-
- 0 1 2 3 4 0 1 2 3 4
- .----------- .-----------
- | |
- 0 | 0 2 0 | * *
- 1 | \ / | 1 | 0 1 |
- 2 | 1 | 2 | * 4
- 3 | \ | 3 | 2 |
- 4 | 3-4 4 | *3*
-
- */
-
// Sites associated to edges.
typedef fun::i2v::array<point2d> fsite_t;
fsite_t sites(5);
@@ -91,7 +91,7 @@ int main()
util::graph g;
// Populate the graph with vertices.
- for (unsigned i = 0; i < sites.size(); ++i)
+ for(unsigned i = 0; i < sites.size(); ++i)
g.add_vertex();
// Populate the graph with edges.
g.add_edge(0, 1);
@@ -114,11 +114,11 @@ int main()
// Graph values.
typedef fun::i2v::array<unsigned> viota_t;
viota_t iota(pe.nsites());
- for (unsigned i = 0; i < iota.size(); ++i)
+ for(unsigned i = 0; i < iota.size(); ++i)
iota(i) = 10 + i;
// Create line graph image.
- mln_const_VAR(ima, (iota | pe));
+ mln_const_VAR(ima,(iota | pe));
/*------------.
| Iterators. |
@@ -130,7 +130,7 @@ int main()
// Manual iteration over the domain of IMA.
mln_piter_(ima_t) p(ima.domain());
unsigned i = 10;
- for_all (p)
+ for_all(p)
mln_assertion(ima(p) == i++);
typedef line_graph_elt_window<util::graph, fsite_t> win_t;
@@ -139,12 +139,12 @@ int main()
{
// Window - Forward iteration
mln_fwd_qiter_(win_t) q(win, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (q)
+ for_all(q)
{
- mln_assertion(fwd[p.element().id()][i] == q.element().id());
+ mln_assertion(expected_fwd_nbh[p.id()][i] == q.id());
++i;
}
}
@@ -153,12 +153,12 @@ int main()
{
// Window - Backward iteration
mln_bkd_qiter_(win_t) q(win, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (q)
+ for_all(q)
{
- mln_assertion(bkd[p.element().id()][i] == q.element().id());
+ mln_assertion(expected_bkd_nbh[p.id()][i] == q.id());
++i;
}
}
@@ -171,12 +171,12 @@ int main()
{
// Neighborhood - Forward iteration
mln_fwd_niter_(neighb_t) n(neigh, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (n)
+ for_all(n)
{
- mln_assertion(fwd[p.element().id()][i] == n.element().id());
+ mln_assertion(expected_fwd_nbh[p.id()][i] == n.id());
++i;
}
}
@@ -185,12 +185,12 @@ int main()
{
// Neighborhood - Backward iteration
mln_bkd_niter_(neighb_t) n(neigh, p);
- for_all (p)
+ for_all(p)
{
i = 0;
- for_all (n)
+ for_all(n)
{
- mln_assertion(bkd[p.element().id()][i] == n.element().id());
+ mln_assertion(expected_bkd_nbh[p.id()][i] == n.id());
++i;
}
}
--
1.5.6.5