Commit f5dd2fb9 authored by Roland Levillain's avatar Roland Levillain
Browse files

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.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4592 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent cbeadfd4
2009-10-01 Roland Levillain <roland@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@lrde.epita.fr>
 
Clean up some conversion and pretty-printing routines in graph-morpho.
......@@ -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);
......
......@@ -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
......
......@@ -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
......@@ -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));
......
......@@ -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"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment