* apps/graph-morpho/io.hh (make_regular_complex1d_image):
Move function...
* apps/graph-morpho/convert.hh: ...here, and turn into...
(convert::to_complex_image): ...this.
* apps/graph-morpho/asf-complex1d.cc,
* apps/graph-morpho/samples-image2d.cc,
* apps/graph-morpho/samples-complex1d.cc:
Adjust clients.
---
milena/ChangeLog | 13 +++++
milena/apps/graph-morpho/asf-complex1d.cc | 4 +-
milena/apps/graph-morpho/convert.hh | 58 ++++++++++++++++++++++++
milena/apps/graph-morpho/io.hh | 60 -------------------------
milena/apps/graph-morpho/samples-complex1d.cc | 8 ++--
milena/apps/graph-morpho/samples-image2d.cc | 2 +-
6 files changed, 78 insertions(+), 67 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index dcad3c7..39bc7c2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2009-10-01 Roland Levillain <roland(a)lrde.epita.fr>
+ Clean up another conversion routine in graph-morpho.
+
+ * apps/graph-morpho/io.hh (make_regular_complex1d_image):
+ Move function...
+ * apps/graph-morpho/convert.hh: ...here, and turn into...
+ (convert::to_complex_image): ...this.
+ * apps/graph-morpho/asf-complex1d.cc,
+ * apps/graph-morpho/samples-image2d.cc,
+ * apps/graph-morpho/samples-complex1d.cc:
+ Adjust clients.
+
+2009-10-01 Roland Levillain <roland(a)lrde.epita.fr>
+
Clean up some conversion and pretty-printing routines in graph-morpho.
* apps/graph-morpho/convert.hh,
diff --git a/milena/apps/graph-morpho/asf-complex1d.cc
b/milena/apps/graph-morpho/asf-complex1d.cc
index 72ac574..bf1d624 100644
--- a/milena/apps/graph-morpho/asf-complex1d.cc
+++ b/milena/apps/graph-morpho/asf-complex1d.cc
@@ -36,7 +36,7 @@
#include "apps/graph-morpho/morpho.hh"
#include "apps/graph-morpho/make_complex2d.hh"
-#include "apps/graph-morpho/io.hh"
+#include "apps/graph-morpho/convert.hh"
#include "apps/data.hh"
@@ -60,7 +60,7 @@ int main()
cubical 1-complex here, but they are not yet available (as of
2009-09-10). */
typedef mln::bin_1complex_image2d ima_t;
- ima_t graph_ima = make_regular_complex1d_image(input_x2);
+ ima_t graph_ima = ::convert::to_complex_image(input_x2);
// ASF.
ima_t asf_ima = asf(graph_ima, 8);
diff --git a/milena/apps/graph-morpho/convert.hh b/milena/apps/graph-morpho/convert.hh
index e51b4ac..4328765 100644
--- a/milena/apps/graph-morpho/convert.hh
+++ b/milena/apps/graph-morpho/convert.hh
@@ -32,6 +32,10 @@
# include <mln/core/alias/complex_image.hh>
# include <mln/core/image/image2d.hh>
+# include <mln/math/abs.hh>
+
+# include "apps/graph-morpho/io.hh"
+
namespace convert
{
@@ -111,6 +115,60 @@ namespace convert
return output;
}
+
+ /// Convert an mln::bin_1complex_image2d to an mln::image2d<bool>.
+ inline
+ mln::bin_1complex_image2d
+ to_complex_image(const mln::image2d<bool>& input)
+ {
+ using namespace mln;
+
+ const box2d& input_box = input.domain();
+ // The input image must have an odd number of rows and columns.
+ mln_precondition(input_box.nrows() % 2 == 1);
+ mln_precondition(input_box.ncols() % 2 == 1);
+
+ // The domain of the graph image is twice as small, since we
+ // consider only vertices (edges are set ``between'' vertices).
+ box2d output_box(input_box.nrows() / 2 + 1,
+ input_box.ncols() / 2 + 1);
+ bin_1complex_image2d output = build_regular_complex1d_image(output_box);
+
+ const unsigned dim = 1;
+ typedef geom::complex_geometry<dim, point2d> geom_t;
+
+ // Add values on vertices.
+ p_n_faces_fwd_piter<dim, geom_t> v(output.domain(), 0);
+ for_all(v)
+ {
+ mln_site_(geom_t) s(v);
+ // Site S is point2d multi-site and should be a singleton (since V
+ // iterates on vertices).
+ mln_invariant(s.size() == 1);
+ point2d p = s.front();
+ point2d q(p.row() * 2, p.col() * 2);
+ output(v) = input(q);
+ }
+
+ // Add values on edges.
+ p_n_faces_fwd_piter<dim, geom_t> e(output.domain(), 1);
+ for_all(e)
+ {
+ mln_site_(geom_t) s(e);
+ // Site S is point2d multi-site and should be a pair (since E
+ // iterates on vertices).
+ mln_invariant(s.size() == 2);
+ point2d p1 = s[0];
+ point2d p2 = s[1];
+ mln_invariant(math::abs(p1.row() - p2.row()) == 1
+ || math::abs(p1.col() - p2.col()) == 1);
+ point2d q (p1.row() + p2.row(), p1.col() + p2.col());
+ output(e) = input(q);
+ }
+
+ return output;
+ }
+
} // end of namespace convert
diff --git a/milena/apps/graph-morpho/io.hh b/milena/apps/graph-morpho/io.hh
index 8c92949..6dac2c4 100644
--- a/milena/apps/graph-morpho/io.hh
+++ b/milena/apps/graph-morpho/io.hh
@@ -32,11 +32,6 @@
# include <mln/core/alias/complex_image.hh>
# include <mln/core/image/image2d.hh>
-# include <mln/math/abs.hh>
-
-// FIXME: We should turn these routines into something much more
-// generic, and move it to the library (into make/).
-
inline
mln::bin_1complex_image2d
build_regular_complex1d_image(const mln::box2d& support)
@@ -98,59 +93,4 @@ build_regular_complex1d_image(const mln::box2d& support)
}
-template <typename I>
-inline
-mln::bin_1complex_image2d
-make_regular_complex1d_image(const mln::Image<I>& input_)
-{
- using namespace mln;
-
- const I& input = exact(input_);
- const box2d& input_box = input.domain();
- // The input image must have an odd number of rows and columns.
- mln_precondition(input_box.nrows() % 2 == 1);
- mln_precondition(input_box.ncols() % 2 == 1);
-
- // The domain of the graph image is twice as small, since we
- // consider only vertices (edges are set ``between'' vertices).
- box2d output_box(input_box.nrows() / 2 + 1,
- input_box.ncols() / 2 + 1);
- bin_1complex_image2d output = build_regular_complex1d_image(output_box);
-
- const unsigned dim = 1;
- typedef geom::complex_geometry<dim, point2d> geom_t;
-
- // Add values on vertices.
- p_n_faces_fwd_piter<dim, geom_t> v(output.domain(), 0);
- for_all(v)
- {
- mln_site_(geom_t) s(v);
- // Site S is point2d multi-site and should be a singleton (since V
- // iterates on vertices).
- mln_invariant(s.size() == 1);
- point2d p = s.front();
- point2d q(p.row() * 2, p.col() * 2);
- output(v) = input(q);
- }
-
- // Add values on edges.
- p_n_faces_fwd_piter<dim, geom_t> e(output.domain(), 1);
- for_all(e)
- {
- mln_site_(geom_t) s(e);
- // Site S is point2d multi-site and should be a pair (since E
- // iterates on vertices).
- mln_invariant(s.size() == 2);
- point2d p1 = s[0];
- point2d p2 = s[1];
- mln_invariant(math::abs(p1.row() - p2.row()) == 1
- || math::abs(p1.col() - p2.col()) == 1);
- point2d q (p1.row() + p2.row(), p1.col() + p2.col());
- output(e) = input(q);
- }
-
- return output;
-}
-
-
#endif // ! APPS_GRAPH_MORPHO_IO_HH
diff --git a/milena/apps/graph-morpho/samples-complex1d.cc
b/milena/apps/graph-morpho/samples-complex1d.cc
index 0b32236..c76bbf0 100644
--- a/milena/apps/graph-morpho/samples-complex1d.cc
+++ b/milena/apps/graph-morpho/samples-complex1d.cc
@@ -34,7 +34,7 @@
#include "apps/graph-morpho/morpho.hh"
-#include "apps/graph-morpho/io.hh"
+#include "apps/graph-morpho/convert.hh"
#include "apps/graph-morpho/debug.hh"
#include "apps/data.hh"
@@ -58,7 +58,7 @@ int main()
/* Create an image corresponding to the graph X of the ISMM 2009
paper from Jean Cousty et al. */
image2d<bool> x_pbm = io::pbm::load(MLN_APPS_DIR
"/graph-morpho/x.pbm");
- ima_t x = make_regular_complex1d_image(x_pbm);
+ ima_t x = ::convert::to_complex_image(x_pbm);
::debug::println_graph("x:", x);
::debug::println_graph("dilation_e2v(x):", dilation_e2v(x));
@@ -79,7 +79,7 @@ int main()
// Create an image corresponding to the graph Y.
image2d<bool> y_pbm = io::pbm::load(MLN_APPS_DIR
"/graph-morpho/y.pbm");
- ima_t y = make_regular_complex1d_image(y_pbm);
+ ima_t y = ::convert::to_complex_image(y_pbm);
::debug::println_graph("y:", y);
::debug::println_graph("opening_graph(y):", opening_graph(y));
@@ -88,7 +88,7 @@ int main()
// Create an image corresponding to the graph Z.
image2d<bool> z_pbm = io::pbm::load(MLN_APPS_DIR
"/graph-morpho/z.pbm");
- ima_t z = make_regular_complex1d_image(z_pbm);
+ ima_t z = ::convert::to_complex_image(z_pbm);
::debug::println_graph("z:", z);
::debug::println_graph("closing_graph(z):", closing_graph(z));
diff --git a/milena/apps/graph-morpho/samples-image2d.cc
b/milena/apps/graph-morpho/samples-image2d.cc
index 76d5f7f..ab4bcb6 100644
--- a/milena/apps/graph-morpho/samples-image2d.cc
+++ b/milena/apps/graph-morpho/samples-image2d.cc
@@ -31,7 +31,7 @@
#include "apps/graph-morpho/morpho.hh"
-#include "apps/graph-morpho/io.hh"
+#include "apps/graph-morpho/convert.hh"
#include "apps/graph-morpho/debug.hh"
#include "apps/data.hh"
--
1.6.3.1