37 #include <mln/core/image/complex_image.hh>
38 #include <mln/core/image/complex_neighborhoods.hh>
40 #include <mln/morpho/closing/area.hh>
41 #include <mln/morpho/meyer_wst.hh>
43 #include <mln/math/max.hh>
44 #include <mln/math/sqr.hh>
46 #include <mln/literal/white.hh>
48 #include <mln/io/off/load.hh>
49 #include <mln/io/off/save.hh>
51 #include "trimesh/misc.hh"
55 static const float pi = 4 * atanf(1);
58 int main(
int argc,
char* argv[])
62 std::cerr <<
"usage: " << argv[0] <<
" input.off lambda output.off"
67 std::string input_filename = argv[1];
68 unsigned lambda = atoi(argv[2]);
69 std::string output_filename = argv[3];
78 static const unsigned D = ima_t::dim;
80 typedef mln_geom_(ima_t) G;
82 mln::bin_2complex_image3df bin_input;
83 mln::io::off::load(bin_input, input_filename);
84 std::pair<ima_t, ima_t> curv = mln::geom::mesh_curvature(bin_input.domain());
87 ima_t input(bin_input.domain());
88 mln::p_n_faces_fwd_piter<D, G> v(input.domain(), 0);
91 float h = (curv.first(v) + curv.second(v)) / 2;
93 float h_inv = 1 / pi * (atan(-h) + pi / 2);
103 typedef mln::complex_lower_neighborhood<D, G> adj_vertices_nbh_t;
104 adj_vertices_nbh_t adj_vertices_nbh;
105 mln_niter_(adj_vertices_nbh_t) adj_v(adj_vertices_nbh, e);
119 mln_invariant(n <= 2);
128 mln::complex_higher_dim_connected_n_face_neighborhood<D, G>
130 adj_edges_nbh_t adj_edges_nbh;
132 ima_t closed_input = mln::morpho::closing::area(input, adj_edges_nbh, lambda);
147 typedef unsigned wst_val_t;
152 std::cout <<
"nbasins = " << nbasins << std::endl;
155 typedef mln::complex_higher_neighborhood<D, G> adj_polygons_nbh_t;
156 adj_polygons_nbh_t adj_polygons_nbh;
157 mln_niter_(adj_polygons_nbh_t) adj_p(adj_polygons_nbh, e);
161 wshed(adj_p) = wshed(e);
167 mln::rgb8_2complex_image3df output(wshed.domain());
168 mln::
data::fill(output, mln::literal::white);
172 std::vector<mln::value::rgb8> basin_color (nbasins + 1);
173 for (
unsigned i = 0; i <= nbasins; ++i)
174 basin_color[i] = mln::value::rgb8(random() % 256,
177 mln_piter_(ima_t) f(wshed.domain());
179 output(f) = basin_color[wshed(f)];
181 mln::io::off::save(output, output_filename);