36 #include <mln/core/image/complex_image.hh>
37 #include <mln/core/image/complex_neighborhoods.hh>
39 #include <mln/core/image/dmorph/image_if.hh>
40 #include <mln/core/image/dmorph/sub_image.hh>
41 #include <mln/core/routine/extend.hh>
42 #include <mln/core/routine/mutable_extend.hh>
43 #include <mln/data/paste.hh>
45 #include <mln/value/label_16.hh>
47 #include <mln/labeling/regional_minima.hh>
48 #include <mln/morpho/closing/area.hh>
49 #include <mln/morpho/dilation.hh>
51 #include <mln/topo/is_n_face.hh>
52 #include <mln/topo/is_simple_pair.hh>
53 #include <mln/topo/detach_pair.hh>
54 #include <mln/topo/skeleton/priority_driven_thinning.hh>
56 #include <mln/arith/revert.hh>
58 #include <mln/io/vtk/load.hh>
59 #include <mln/io/vtk/save.hh>
61 #include <mln/util/timer.hh>
67 main(
int argc,
char* argv[])
71 std::cerr <<
"usage: " << argv[0] <<
" input.vtk lambda output.vtk"
76 std::string input_filename = argv[1];
77 unsigned lambda = atoi(argv[2]);
78 std::string output_filename = argv[3];
87 static const unsigned D = float_ima_t::dim;
89 typedef mln_geom_(float_ima_t) G;
91 mln::bin_2complex_image3df bin_input;
92 mln::io::vtk::
load(bin_input, input_filename);
94 const mln::topo::complex<D>& cplx = bin_input.domain().cplx();
95 for (
unsigned n = 0; n <= D; ++n)
96 std::cout << cplx.nfaces_of_dim(n) << ' ' << n << "-faces" << std::endl;
98 std::pair<float_ima_t, float_ima_t> curv =
99 mln::geom::mesh_curvature(bin_input.domain());
102 float_ima_t float_ima(bin_input.domain());
103 mln::p_n_faces_fwd_piter<D, G> v(float_ima.domain(), 0);
114 lower_adj_nbh_t lower_adj_nbh;
123 mln_niter_(lower_adj_nbh_t) adj_v(lower_adj_nbh, e);
132 s += float_ima(adj_v);
135 float_ima(e) = s / n;
137 mln_invariant(n == 2);
147 mln_niter_(lower_adj_nbh_t) adj_e(lower_adj_nbh, t);
156 s += float_ima(adj_e);
159 float_ima(t) = s / n;
161 mln_invariant(n == 3);
171 ima_t ima(float_ima.domain());
175 ima(t) = 1000 * float_ima(t);
182 typedef mln::complex_lower_dim_connected_n_face_neighborhood<D, G> nbh_t;
186 typedef mln::topo::is_n_face<mln_psite_(ima_t), 2> is_a_triangle_t;
187 is_a_triangle_t is_a_triangle;
191 mln::
data::
paste(mln::morpho::closing::
area(ima | is_a_triangle,
199 typedef mln::
value::label_16 label_t;
205 mln::initialize(minima, closed_ima);
222 bin_ima_t surface(minima.domain());
225 typedef mln::topo::is_n_face<mln_psite_(ima_t), 1> is_an_edge_t;
226 is_an_edge_t is_an_edge;
228 typedef mln::topo::is_n_face<mln_psite_(ima_t), 0> is_a_vertex_t;
229 is_a_vertex_t is_a_vertex;
233 typedef mln::complex_higher_neighborhood<D, G> higher_adj_nbh_t;
234 higher_adj_nbh_t higher_adj_nbh;
240 (mln::pw::
value(minima) == mln::pw::cst(mln::literal::zero))).rw(),
247 higher_adj_nbh.win()),
254 higher_adj_nbh.win()),
266 typedef mln::image_if<bin_ima_t, is_a_triangle_t> bin_triangle_only_ima_t;
269 typedef mln::mutable_extension_ima<bin_triangle_only_ima_t, bin_ima_t>
277 typedef mln::topo::is_simple_pair< bin_triangle_ima_t,
280 is_simple_triangle_t;
281 is_simple_triangle_t is_simple_triangle(lower_adj_nbh, higher_adj_nbh);
288 typedef mln::topo::detach_pair< bin_triangle_ima_t,
290 higher_adj_nbh_t > detach_triangle_t;
291 detach_triangle_t detach_triangle(lower_adj_nbh, higher_adj_nbh);
299 ima_t priority = mln::arith::revert(closed_ima);
302 mln::initialize(surface_2_collapse, surface);
304 (mln::topo::skeleton::priority_driven_thinning
305 (mln::mutable_extend((surface | is_a_triangle).rw(), surface),
327 typedef mln::image_if<bin_ima_t, is_an_edge_t> bin_edge_only_ima_t;
330 typedef mln::mutable_extension_ima<bin_edge_only_ima_t, bin_ima_t>
338 typedef mln::topo::is_simple_pair< bin_edge_ima_t,
342 is_simple_edge_t is_simple_edge(lower_adj_nbh, higher_adj_nbh);
349 typedef mln::topo::detach_pair< bin_edge_ima_t,
351 higher_adj_nbh_t > detach_edge_t;
352 detach_edge_t detach_edge(lower_adj_nbh, higher_adj_nbh);
359 mln::initialize(surface_1_collapse, surface_2_collapse);
361 mln::util::timer time;
364 (mln::topo::skeleton::priority_driven_thinning
365 (mln::mutable_extend((surface_2_collapse | is_an_edge).rw(),
376 | surface_2_collapse.domain(),
379 std::cout << time.read() << " s" << std::endl;
385 mln::io::vtk::
save(surface_1_collapse, output_filename);