00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef APPS_GRAPH_MORPHO_CONVERT_HH
00027 # define APPS_GRAPH_MORPHO_CONVERT_HH
00028
00031
00032 # include <mln/core/alias/complex_image.hh>
00033 # include <mln/core/image/image2d.hh>
00034
00035 # include <mln/math/abs.hh>
00036
00037 # include "apps/graph-morpho/make.hh"
00038
00039
00040 namespace convert
00041 {
00042
00044 inline
00045 mln::image2d<bool>
00046 to_image2d(const mln::bin_1complex_image2d& input)
00047 {
00048 using namespace mln;
00049
00050 const unsigned dim = 1;
00051 typedef geom::complex_geometry<dim, point2d> geom_t;
00052
00053
00054 accu::shape::bbox<point2d> bbox;
00055 p_n_faces_fwd_piter<dim, geom_t> v(input.domain(), 0);
00056 for_all(v)
00057 {
00058 mln_site_(geom_t) s(v);
00059
00060
00061 mln_invariant(s.size() == 1);
00062 point2d p = s.front();
00063 bbox.take(p);
00064 }
00065 mln::box2d support = bbox;
00066
00067 image2d<bool> output(box2d(point2d(support.pmin().row() * 2,
00068 support.pmin().col() * 2),
00069 point2d(support.pmax().row() * 2,
00070 support.pmax().col() * 2)));
00071 data::fill(output, false);
00072
00073
00074 for_all(v)
00075 {
00076 mln_site_(geom_t) s(v);
00077
00078
00079 mln_invariant(s.size() == 1);
00080 point2d p_in = s.front();
00081 point2d p_out(p_in.row() * 2, p_in.col() * 2);
00082 output(p_out) = input(v);
00083 }
00084
00085
00086 p_n_faces_fwd_piter<dim, geom_t> e(input.domain(), 1);
00087 for_all(e)
00088 {
00089 mln_site_(geom_t) s(e);
00090
00091
00092 mln_invariant(s.size() == 2);
00093 point2d p1 = s[0];
00094 point2d p2 = s[1];
00095 if (p1.row() == p2.row())
00096 {
00097
00098 point2d p_out(p1.row() * 2,
00099 p1.col() + p2.col());
00100 output(p_out) = input(e);
00101 }
00102 else if (p1.col() == p2.col())
00103 {
00104
00105 point2d p_out(p1.row() + p2.row(),
00106 p1.col() * 2);
00107 output(p_out) = input(e);
00108 }
00109 else
00110 {
00111
00112 abort();
00113 }
00114 }
00115 return output;
00116 }
00117
00118
00120 inline
00121 mln::bin_1complex_image2d
00122 to_complex_image(const mln::image2d<bool>& input)
00123 {
00124 using namespace mln;
00125
00126 const box2d& input_box = input.domain();
00127
00128 mln_precondition(input_box.nrows() % 2 == 1);
00129 mln_precondition(input_box.ncols() % 2 == 1);
00130
00131
00132
00133 box2d output_box(input_box.nrows() / 2 + 1,
00134 input_box.ncols() / 2 + 1);
00135 bin_1complex_image2d output = ::make::complex1d_image<bool>(output_box);
00136
00137 const unsigned dim = 1;
00138 typedef geom::complex_geometry<dim, point2d> geom_t;
00139
00140
00141 p_n_faces_fwd_piter<dim, geom_t> v(output.domain(), 0);
00142 for_all(v)
00143 {
00144 mln_site_(geom_t) s(v);
00145
00146
00147 mln_invariant(s.size() == 1);
00148 point2d p = s.front();
00149 point2d q(p.row() * 2, p.col() * 2);
00150 output(v) = input(q);
00151 }
00152
00153
00154 p_n_faces_fwd_piter<dim, geom_t> e(output.domain(), 1);
00155 for_all(e)
00156 {
00157 mln_site_(geom_t) s(e);
00158
00159
00160 mln_invariant(s.size() == 2);
00161 point2d p1 = s[0];
00162 point2d p2 = s[1];
00163 mln_invariant(math::abs(p1.row() - p2.row()) == 1
00164 || math::abs(p1.col() - p2.col()) == 1);
00165 point2d q (p1.row() + p2.row(), p1.col() + p2.col());
00166 output(e) = input(q);
00167 }
00168
00169 return output;
00170 }
00171
00172 }
00173
00174
00175 #endif // ! APPS_GRAPH_MORPHO_CONVERT_HH