* doc/tutorial/samples/graph-add-edges.tex
* doc/tutorial/samples/graph-add-vertex.tex
* doc/tutorial/samples/graph-data.tex
* doc/tutorial/samples/graph-i2v-vertex.tex
* doc/tutorial/samples/graph-iter-edge-nbh-edge.tex
* doc/tutorial/samples/graph-iter-vertex-nbh-vertex.tex
* doc/tutorial/samples/graph-iter-vertex.tex
* doc/tutorial/samples/graph-iter.tex
* doc/tutorial/samples/graph-p-vertices.tex
* doc/tutorial/samples/ima2d-2.tex
* doc/tutorial/samples/ima2d-7.tex
* doc/tutorial/samples/mln_var-3.tex:
New. Add sample code.
* doc/tutorial/tutorial.tex: rewrite graph section.
---
milena/ChangeLog | 20 +++
milena/doc/tutorial/samples/graph-add-edges.tex | 5 +
milena/doc/tutorial/samples/graph-add-vertex.tex | 4 +
milena/doc/tutorial/samples/graph-data.tex | 36 +++++
milena/doc/tutorial/samples/graph-i2v-vertex.tex | 7 +
.../tutorial/samples/graph-iter-edge-nbh-edge.tex | 15 ++
.../samples/graph-iter-vertex-nbh-vertex.tex | 15 ++
milena/doc/tutorial/samples/graph-iter-vertex.tex | 15 ++
milena/doc/tutorial/samples/graph-iter.tex | 11 ++
milena/doc/tutorial/samples/graph-p-vertices.tex | 1 +
milena/doc/tutorial/samples/ima2d-2.tex | 8 +-
milena/doc/tutorial/samples/ima2d-7.tex | 5 +
milena/doc/tutorial/samples/mln_var-3.tex | 3 +-
milena/doc/tutorial/tutorial.tex | 137 ++++----------------
14 files changed, 167 insertions(+), 115 deletions(-)
create mode 100644 milena/doc/tutorial/samples/graph-add-edges.tex
create mode 100644 milena/doc/tutorial/samples/graph-add-vertex.tex
create mode 100644 milena/doc/tutorial/samples/graph-data.tex
create mode 100644 milena/doc/tutorial/samples/graph-i2v-vertex.tex
create mode 100644 milena/doc/tutorial/samples/graph-iter-edge-nbh-edge.tex
create mode 100644 milena/doc/tutorial/samples/graph-iter-vertex-nbh-vertex.tex
create mode 100644 milena/doc/tutorial/samples/graph-iter-vertex.tex
create mode 100644 milena/doc/tutorial/samples/graph-iter.tex
create mode 100644 milena/doc/tutorial/samples/graph-p-vertices.tex
create mode 100644 milena/doc/tutorial/samples/ima2d-7.tex
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0bdb17c..ef591fd 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,25 @@
2008-11-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Update graph section in tutorial.
+
+ * doc/tutorial/samples/graph-add-edges.tex
+ * doc/tutorial/samples/graph-add-vertex.tex
+ * doc/tutorial/samples/graph-data.tex
+ * doc/tutorial/samples/graph-i2v-vertex.tex
+ * doc/tutorial/samples/graph-iter-edge-nbh-edge.tex
+ * doc/tutorial/samples/graph-iter-vertex-nbh-vertex.tex
+ * doc/tutorial/samples/graph-iter-vertex.tex
+ * doc/tutorial/samples/graph-iter.tex
+ * doc/tutorial/samples/graph-p-vertices.tex
+ * doc/tutorial/samples/ima2d-2.tex
+ * doc/tutorial/samples/ima2d-7.tex
+ * doc/tutorial/samples/mln_var-3.tex:
+ New. Add sample code.
+
+ * doc/tutorial/tutorial.tex: rewrite graph section.
+
+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.
diff --git a/milena/doc/tutorial/samples/graph-add-edges.tex
b/milena/doc/tutorial/samples/graph-add-edges.tex
new file mode 100644
index 0000000..be04c8a
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-add-edges.tex
@@ -0,0 +1,5 @@
+g.add_edge(0, 1); // Associated to edge 0.
+g.add_edge(1, 2); // Associated to edge 1.
+g.add_edge(1, 3); // Associated to edge 2.
+g.add_edge(3, 4); // Associated to edge 3.
+g.add_edge(4, 2); // Associated to edge 4.
diff --git a/milena/doc/tutorial/samples/graph-add-vertex.tex
b/milena/doc/tutorial/samples/graph-add-vertex.tex
new file mode 100644
index 0000000..48eca70
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-add-vertex.tex
@@ -0,0 +1,4 @@
+util::graph g;
+
+for (unsigned i = 0; i < 5; ++i)
+ g.add_vertex () // Add vertex 'i';
diff --git a/milena/doc/tutorial/samples/graph-data.tex
b/milena/doc/tutorial/samples/graph-data.tex
new file mode 100644
index 0000000..b2a3f06
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-data.tex
@@ -0,0 +1,36 @@
+template <typename S>
+struct viota_t : public mln::Function_p2v< viota_t<S> >
+{
+ typedef unsigned result;
+
+ viota_t(unsigned size)
+ {
+ v_.resize(size);
+ for (unsigned i = 0; i < size; ++i)
+ v_[i] = 10 + i;
+ }
+
+ unsigned
+ operator()(const mln_psite(S)& p) const
+ {
+ return v_[p.v().id()];
+ }
+
+ protected:
+ std::vector<result> v_;
+};
+
+void my_fun()
+{
+ ...
+ // Constructs an image
+ mln_VAR(graph_vertices_ima, viota_t<pv_t>() | pv);
+
+ //Prints each vertex and its associated data.
+ mln_piter(graph_vertices_ima_t) p(graph_vertices_ima);
+ for_all(p)
+ std::Cout << "ima(" << p << ") = "
+ << ima(p) << std::endl;
+ ...
+}
+
diff --git a/milena/doc/tutorial/samples/graph-i2v-vertex.tex
b/milena/doc/tutorial/samples/graph-i2v-vertex.tex
new file mode 100644
index 0000000..4de430f
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-i2v-vertex.tex
@@ -0,0 +1,7 @@
+typedef fun::i2v::array<point2d> F;
+F f(5); // We need to map 5 vertices.
+f(0) = point2d(0, 0);
+f(1) = point2d(2, 2);
+f(2) = point2d(0, 4);
+f(3) = point2d(4, 3);
+f(4) = point2d(4, 4);
diff --git a/milena/doc/tutorial/samples/graph-iter-edge-nbh-edge.tex
b/milena/doc/tutorial/samples/graph-iter-edge-nbh-edge.tex
new file mode 100644
index 0000000..9d2e8f0
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-iter-edge-nbh-edge.tex
@@ -0,0 +1,15 @@
+// Iterator on edges.
+mln_edge_iter(util::graph) e(g);
+
+// Iterator on edges adjacent to e.
+mln_edge_nbh_edge_iter ne(g, e);
+
+// Prints the graph
+// List all adjacent edges for each edge.
+for_all(e)
+{
+ std::cout << e << " : ";
+ for_all(ne)
+ std::cout << ne << " ";
+ std::cout << std::endl;
+}
diff --git a/milena/doc/tutorial/samples/graph-iter-vertex-nbh-vertex.tex
b/milena/doc/tutorial/samples/graph-iter-vertex-nbh-vertex.tex
new file mode 100644
index 0000000..75fcea7
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-iter-vertex-nbh-vertex.tex
@@ -0,0 +1,15 @@
+// Iterator on vertices.
+mln_vertex_iter(util::graph) v(g);
+
+// Iterator on vertices adjacent to v.
+mln_vertex_nbh_vertex_iter nv(g, v);
+
+// Prints the graph
+// List all adjacent edges for each edge.
+for_all(v)
+{
+ std::cout << v << " : ";
+ for_all(nv)
+ std::cout << nv << " ";
+ std::cout << std::endl;
+}
diff --git a/milena/doc/tutorial/samples/graph-iter-vertex.tex
b/milena/doc/tutorial/samples/graph-iter-vertex.tex
new file mode 100644
index 0000000..aa0ee74
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-iter-vertex.tex
@@ -0,0 +1,15 @@
+// Iterator on vertices.
+mln_vertex_iter(util::graph) v(g);
+
+// Iterator on v's edges.
+mln_vertex_nbh_edge_iter(util::graph) e(g, v);
+
+// Prints the graph
+// List all edges for each vertex.
+for_all(v)
+{
+ std::cout << v << " : ";
+ for_all(e)
+ std::cout << e << " ";
+ std::cout << std::endl;
+}
diff --git a/milena/doc/tutorial/samples/graph-iter.tex
b/milena/doc/tutorial/samples/graph-iter.tex
new file mode 100644
index 0000000..1c0f403
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-iter.tex
@@ -0,0 +1,11 @@
+// Function which maps sites to data.
+viota_t viota;
+
+// Iterator on vertices.
+mln_vertex_iter(util::graph) v(g);
+
+// Prints each vertex and its associated value.
+for_all(v)
+{
+ std::cout << v << " : " << viota(v) << std::endl;
+}
diff --git a/milena/doc/tutorial/samples/graph-p-vertices.tex
b/milena/doc/tutorial/samples/graph-p-vertices.tex
new file mode 100644
index 0000000..3b6869e
--- /dev/null
+++ b/milena/doc/tutorial/samples/graph-p-vertices.tex
@@ -0,0 +1 @@
+p_vertices<util::graph, F> pv(g, f);
diff --git a/milena/doc/tutorial/samples/ima2d-2.tex
b/milena/doc/tutorial/samples/ima2d-2.tex
index 41ead50..1caf397 100644
--- a/milena/doc/tutorial/samples/ima2d-2.tex
+++ b/milena/doc/tutorial/samples/ima2d-2.tex
@@ -1,4 +1,8 @@
-// which builds an empty image;
+// Build an empty image;
image2d<int> img1a;
-// which builds an image with 6 sites
+
+// Build an image with 2 rows
+// and 3 columns sites
image2d<int> img1b(box2d(2, 3));
+image2d<int> img1c(2, 3);
+
diff --git a/milena/doc/tutorial/samples/ima2d-7.tex
b/milena/doc/tutorial/samples/ima2d-7.tex
new file mode 100644
index 0000000..ae7ef8f
--- /dev/null
+++ b/milena/doc/tutorial/samples/ima2d-7.tex
@@ -0,0 +1,5 @@
+image2d<int> img2a(2, 3);
+image2d<int> img2b;
+
+initialize(img2b, img2a);
+level::fill(img2b, img2a);
diff --git a/milena/doc/tutorial/samples/mln_var-3.tex
b/milena/doc/tutorial/samples/mln_var-3.tex
index 240be1f..d62891a 100644
--- a/milena/doc/tutorial/samples/mln_var-3.tex
+++ b/milena/doc/tutorial/samples/mln_var-3.tex
@@ -2,7 +2,8 @@ box2d b2(0,0, 1, 1);
mln_VAR(imad, imab1 / b2);
+debug::prinln(imad);
// Print
// 1
// 1 1
-debug::prinln(imad);
+
diff --git a/milena/doc/tutorial/tutorial.tex b/milena/doc/tutorial/tutorial.tex
index 25e9862..4c0c052 100644
--- a/milena/doc/tutorial/tutorial.tex
+++ b/milena/doc/tutorial/tutorial.tex
@@ -795,6 +795,13 @@ processing, or another image. Trying to access the site value from an
empty
image leads to an error at run-time.
Img1b is defined on a domain but does not have data yet.\\
+Sometimes, you may want to initialize an image from another one:
+\doxycode{ima2d-7}
+\var{img2b} is declared without specifying a domain. Its border size is set to
+the default one, e.g 0. By using \code{initialize} \var{img2b} is initialized
+ with the same domain and border/extension as \var{img2a}. The data is not
+ copied though. Other routines like \code{level::fill} can be called in order to
+ do so (See also \ref{fillop}).
%================================================
@@ -1601,144 +1608,50 @@ First, create a graph which looks like the following:
First we need to add vertices:
-\begin{lstlisting}
-util::graph g;
-
-for (unsigned i = 0; i < 5; ++i)
- g.add_vertex () // Associated to vertex 'i';
-\end{lstlisting}
+\doxycode{graph-add-vertex}
Finally, populate the graph with edges:
-\begin{lstlisting}
-g.add_edge(0, 1); // Associated to edge 0.
-g.add_edge(1, 2); // Associated to edge 1.
-g.add_edge(1, 3); // Associated to edge 2.
-g.add_edge(3, 4); // Associated to edge 3.
-g.add_edge(4, 2); // Associated to edge 4.
-\end{lstlisting}
+\doxycode{graph-add-edges}
Now there is a graph topology and we want to associate elements of this graph
to a site in the image.
The idea is to use specific site sets such as \type{p\_vertices} and
\type{p\_edges}.
-Let's associate the vertices with sites. To do so we need to create a functor
-which for a given vertex returns a site.
-
-\begin{lstlisting}[frame=single]
-struct assoc_fun : public Function_v2v< assoc_fun >
-{
- typedef const point2d& result;
-
- inline
- const point2d& operator()(const vertex<graph::util>& v) const
- {
- ...
- }
-
-};
-\end{lstlisting}
+Let's associate the vertices with sites. To do so we need a function which maps
+a vertex id to a site, e.g. a \type{point2d} here.
+\doxycode{graph-i2v-vertex}
Then declare a \type{p\_vertices}:
-\begin{lstlisting}[frame=single]
-p_vertices<util::graph, assoc_fun> pv(g, assoc_fun());
-\end{lstlisting}
+\doxycode{graph-p-vertices}
Thanks to the \type{p\_vertices} there is now a mapping between vertices and sites.
-We may like to map data to it. The idea is to provide a function which returns the
associated data
-according to the site given as parameter. Combining this function and the
-\type{p\_vertices}, we get an image. Since this is an image, you can use it with
+We may like to map data to it. The idea is to provide a function which returns
+the associated data according to the site given as parameter. Combining this
+function and the \type{p\_vertices}, we get an image which can be used with
algorithms and \code{for\_all} loops.
-\begin{lstlisting}[frame=single]
-
-template <typename I>
-mln_rvalue(I) my_data_fun(mln_site(I) site)
-{
- ...
-}
-
-void my_fun()
-{
- ...
- // Constructs an image
- mln_VAR(graph_vertices_ima, my_data_fun | pv);
-
- //Prints each vertex
- mln_piter p(graph_vertices_ima);
- for_all(p)
- std::Cout << p << std::endl;
- ...
-}
-\end{lstlisting}
+\doxycode{graph-data}
Note that like any image in Olena, graph images share their data. Therefore,
while constructing a graph image from a graph and a function, the graph is not
copied and this is NOT a costly operation.
-Like other images, graph images also have an overloaded \code{operator()} to access the
-data associated to a vertex or an edge.
-\begin{lstlisting}
- //Prints each edge's associated value.
- mln_piter p(graph_edge_ima);
- for_all(p)
- std::cout << graph_edge_ima(p) << std::endl;
-
- //Prints each vertex's associated value.
- mln_piter p(graph_vertex_ima);
- for_all(p)
- std::cout << graph_vertex_ima(p) << std::endl;
-\end{lstlisting}
-
Of course, creating a graph image is not necessary and you can work directly
with the graph and container/function mapping indexes and data.
-\begin{lstlisting}
-// Iterator on vertices.
-mln_Viter V(g);
-
-// Prints each vertex and its associated value.
-for_all(V)
-{
- std::cout << V << " : " << my_data_fun(V) <<
std::endl;
-}
-\end{lstlisting}
+\doxycode{graph-iter}
-Graphes have iterators like any other site sets and also provide
+Graphs have iterators like any other site sets and also provide
specific iterators in order to iterate over graphes in a more intuitive way.
-\begin{lstlisting}
-// Iterator on vertices.
-mln_Viter V(g);
+Iteration over the adjacent edges of all the vertices:
+\doxycode{graph-iter-vertex}
-// Iterator on V's edges.
-mln_Eiter n(g, V);
+Iteration over the adjacent edges of all the edges:
+\doxycode{graph-iter-edge-nbh-edge}
-// Prints the graph
-// List all edges for each vertex.
-for_all(V)
-{
- std::cout << V << " : ";
- for_all(n)
- std::cout << n << " ";
- std::cout << std::endl;
-}
-
-// Iterator on edges.
-mln_Eiter E(g);
-
-// Iterator on vertices adjacent to E.
-mln_Viter n(g, E);
-
-// Prints the graph
-// List all adjacent vertices for each edge.
-for_all(E)
-{
- std::cout << E << " : ";
- for_all(n)
- std::cout << n << " ";
- std::cout << std::endl;
-}
-\end{lstlisting}
+Iteration over the adjacent vertices of all the vertices:
+\doxycode{graph-iter-vertex-nbh-vertex}
//FIXME talk about p\_vertices and p\_edges.
--
1.5.6.5