* mln/debug/graph.hh: update in order to support p_vertices.
* tests/core/image/graph_image.cc: Add assertions.
* tests/core/site_set/p_vertices.cc: use fun::i2v::array.
---
milena/ChangeLog | 10 ++++++
milena/mln/debug/graph.hh | 45 +++++++++++++++--------------
milena/tests/core/image/graph_image.cc | 7 ++--
milena/tests/core/site_set/p_vertices.cc | 25 ++++++----------
4 files changed, 46 insertions(+), 41 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 7d6da48..0bdb17c 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,15 @@
2008-11-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Fix graph related files.
+
+ * mln/debug/graph.hh: update in order to support p_vertices.
+
+ * tests/core/image/graph_image.cc: Add assertions.
+
+ * tests/core/site_set/p_vertices.cc: use fun::i2v::array.
+
+2008-11-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Make all_headers and essential_headers compile.
* mln/core/image/all.hh,
diff --git a/milena/mln/debug/graph.hh b/milena/mln/debug/graph.hh
index ef52e0b..7485d7e 100644
--- a/milena/mln/debug/graph.hh
+++ b/milena/mln/debug/graph.hh
@@ -34,8 +34,7 @@
# include <mln/pw/image.hh>
# include <mln/level/fill.hh>
# include <mln/draw/line.hh>
-# include <mln/core/site_set/p_graph.hh>
-# include <mln/core/image/graph_image.hh>
+# include <mln/core/site_set/p_vertices.hh>
namespace mln
{
@@ -48,16 +47,15 @@ namespace mln
* the background.
*
* \param[in,out] ima The image to be drawn.
- * \param[in] pg The p_graph which contains vertices and edges
- * positions.
+ * \param[in] pv The p_vertices which contains vertices positions.
* \param[in] vertex_v The value to assign to pixels which contains
* vertices.
* \param[in] edge_v The value to assign to pixels which contains
* edges.
*/
- template <typename I, typename P>
+ template <typename I, typename G, typename F>
void
- draw_graph(Image<I>& ima, const p_graph<P>& pg,
+ draw_graph(Image<I>& ima, const p_vertices<G, F>& pv,
mln_value(I) vertex_v, mln_value(I) edge_v);
/*! \brief Draw an image \p ima from a mln::graph_image \p gi.
@@ -72,37 +70,39 @@ namespace mln
*/
// FIXME: The type of the last argument cannot always been
// constructed from `int'! We should remove this last argument.
- template <typename I, typename P, typename V>
- void
- draw_graph(Image<I>& ima, const graph_image<P, V>& gi,
- mln_value(I) edge_v = 1);
+// template <typename I, typename P, typename V>
+// void
+// draw_graph(Image<I>& ima, const graph_image<P, V>& gi,
+// mln_value(I) edge_v = 1);
# ifndef MLN_INCLUDE_ONLY
// FIXME: Add assertions on the size of the image: it must be large
// enough to hold the representation of the graph/graph_image.
- template <typename I, typename P>
+ template <typename I, typename G, typename F>
inline
void
- draw_graph(Image<I>& ima, const p_graph<P>& pg,
+ draw_graph(Image<I>& ima, const p_vertices<G, F>& pv,
mln_value(I) vertex_v, mln_value(I) edge_v)
{
// Debug the background.
level::fill(ima, 0);
+
// Debug the lines (edges).
- for (unsigned l = 0; l < pg.nedges(); ++l)
- line (exact(ima),
- // FIXME: Too low-level. See similar remarks
- // in mln/core/image/graph_image.hh
- pg.gr_->vertex_data(pg.gr_->edge(l).v1()),
- pg.gr_->vertex_data(pg.gr_->edge(l).v2()),
- edge_v);
+ const G& g = pv.graph();
+ typedef p_vertices<G, F> pv_t;
+ mln_edge_iter(G) ei(g);
+ for_all(ei)
+ draw::line(exact(ima), pv(ei.v1()), pv(ei.v2()), edge_v);
+
// Debug the points (vertices).
- for (unsigned p = 0; p < pg.nsites(); ++p)
- exact(ima)(pg.gr_->vertex_data(p)) = vertex_v;
+ mln_piter(pv_t) p(pv);
+ for_all(p)
+ exact(ima)(p) = vertex_v;
}
+/*
template <typename I, typename P, typename V>
inline
void
@@ -116,8 +116,9 @@ namespace mln
line (exact(ima), gi.vertex1(l), gi.vertex2(l), edge_v);
// Debug the points (vertices).
for (unsigned p = 0; p < gi.domain().nvertices(); ++p)
- exact(ima)(gi.domain().point_from_id(p)) = gi.vertex_values()[p];
+ exact(ima)(gi.domain().point_from_id(p)) = gi.vertex_values()[p];
}
+*/
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/tests/core/image/graph_image.cc
b/milena/tests/core/image/graph_image.cc
index 34faf3a..4c3f09a 100644
--- a/milena/tests/core/image/graph_image.cc
+++ b/milena/tests/core/image/graph_image.cc
@@ -121,7 +121,7 @@ int main()
g.add_edge(3, 4);
g.add_edge(4, 2);
- g.print_debug(std::cout);
+ //g.print_debug(std::cout);
/*----------------------.
| Graph image support. |
@@ -171,7 +171,7 @@ int main()
// We use the value 9 in debug::graph to represent edges to distinguish it
// from vertices holding a value of 1.
- debug::graph(ima_rep, pv, 1, 9);
+ debug::draw_graph(ima_rep, pv, 1, 9);
debug::println(ima_rep);
}
@@ -181,8 +181,9 @@ int main()
// iteration over the domain of IMA.
mln_piter_(ima_t) p(ima.domain());
+ unsigned i = 10;
for_all (p)
- std::cout << "ima (" << p << ") = " <<
ima(p) << std::endl;
+ mln_assertion(ima(p) == i++);
{
// Window - Forward iteration
diff --git a/milena/tests/core/site_set/p_vertices.cc
b/milena/tests/core/site_set/p_vertices.cc
index cdee10b..b2c600d 100644
--- a/milena/tests/core/site_set/p_vertices.cc
+++ b/milena/tests/core/site_set/p_vertices.cc
@@ -33,20 +33,7 @@
#include <mln/util/graph.hh>
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_vertices.hh>
-
-template <typename G>
-struct my_fun
-{
- typedef mln::point2d result;
-
- const result& operator()(const mln::util::vertex<G>& v) const
- {
- static mln::point2d res(0, 0);
- res.row() = v.id();
- return res;
- }
-
-};
+#include <mln/fun/i2v/array.hh>
int main()
{
@@ -68,8 +55,14 @@ int main()
g.add_edge (5, 3);
g.add_edge (2, 1);
- typedef p_vertices<util::graph, my_fun<util::graph> > p_vertices;
- p_vertices pv(g, my_fun<util::graph>());
+ // Map vertices to sites.
+ typedef fun::i2v::array<point2d> F;
+ F f(5);
+ for (unsigned i = 0; i < 5; ++i)
+ f(i) = point2d(i, 0);
+
+ typedef p_vertices<util::graph, F> p_vertices;
+ p_vertices pv(g, f);
{
mln_fwd_piter_(p_vertices) p(pv);
--
1.5.6.5