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
00027
00032
00033 #include <iostream>
00034
00035 #include <mln/core/image/complex_image.hh>
00036 #include <mln/core/image/complex_neighborhoods.hh>
00037
00038 #include <mln/core/site_set/p_set.hh>
00039
00040 #include <mln/value/label_16.hh>
00041
00042 #include <mln/labeling/regional_minima.hh>
00043 #include <mln/morpho/closing/area.hh>
00044
00045 #include <mln/topo/is_n_face.hh>
00046 #include <mln/topo/is_simple_cell.hh>
00047 #include <mln/topo/detach.hh>
00048 #include <mln/topo/skeleton/breadth_first_thinning.hh>
00049
00050 #include <mln/io/off/load.hh>
00051
00052
00053 #include "save_bin_alt.hh"
00054
00055
00056 int
00057 main(int argc, char* argv[])
00058 {
00059 if (argc != 4)
00060 {
00061 std::cerr << "usage: " << argv[0] << " input.off lambda output.off"
00062 << std::endl;
00063 std::exit(1);
00064 }
00065
00066 std::string input_filename = argv[1];
00067 unsigned lambda = atoi(argv[2]);
00068 std::string output_filename = argv[3];
00069
00070
00071
00072
00073
00074
00075 typedef mln::float_2complex_image3df ima_t;
00076
00077 static const unsigned D = ima_t::dim;
00078
00079 typedef mln_geom_(ima_t) G;
00080
00081 ima_t input;
00082 mln::io::off::load(input, input_filename);
00083
00084
00085
00086 mln::p_n_faces_fwd_piter<D, G> v(input.domain(), 0);
00087 for_all(v)
00088 input(v) = mln_max(float);
00089 mln::p_n_faces_fwd_piter<D, G> e(input.domain(), 1);
00090 for_all(e)
00091 input(e) = mln_max(float);
00092
00093
00094
00095
00096
00098 typedef mln::complex_lower_dim_connected_n_face_neighborhood<D, G> nbh_t;
00099 nbh_t nbh;
00100
00101 ima_t closed_input = mln::morpho::closing::area(input, nbh, lambda);
00102
00103
00104
00105
00106
00107 typedef mln::value::label_16 label_t;
00108 label_t nminima;
00109
00110
00111
00112
00113 typedef mln_ch_value_(ima_t, label_t) label_ima_t;
00114 label_ima_t minima =
00115 mln::labeling::regional_minima(closed_input, nbh, nminima);
00116
00117 typedef mln::complex_higher_neighborhood<D, G> higher_nbh_t;
00118 higher_nbh_t higher_nbh;
00119
00120
00121
00122 mln_niter_(higher_nbh_t) adj_t(higher_nbh, e);
00123 for_all(e)
00124 {
00125 label_t ref_adj_minimum = mln::literal::zero;
00126 for_all(adj_t)
00127 if (minima(adj_t) == mln::literal::zero)
00128 {
00129
00130
00131 ref_adj_minimum = mln::literal::zero;
00132 break;
00133 }
00134 else
00135 {
00136 if (ref_adj_minimum == mln::literal::zero)
00137
00138 ref_adj_minimum = minima(adj_t);
00139 else
00140
00141
00142 mln_assertion(minima(adj_t) == ref_adj_minimum);
00143 }
00144 minima(e) = ref_adj_minimum;
00145 }
00146
00147
00148 mln_niter_(higher_nbh_t) adj_e(higher_nbh, v);
00149 for_all(v)
00150 {
00151 label_t ref_adj_minimum = mln::literal::zero;
00152 for_all(adj_e)
00153 if (minima(adj_e) == mln::literal::zero)
00154 {
00155
00156
00157 ref_adj_minimum = mln::literal::zero;
00158 break;
00159 }
00160 else
00161 {
00162 if (ref_adj_minimum == mln::literal::zero)
00163
00164 ref_adj_minimum = minima(adj_e);
00165 else
00166
00167
00168 mln_assertion(minima(adj_e) == ref_adj_minimum);
00169 }
00170 minima(v) = ref_adj_minimum;
00171 }
00172
00173
00174
00175
00176
00177 typedef mln_ch_value_(ima_t, bool) bin_ima_t;
00178 bin_ima_t surface(minima.domain());
00179 mln::data::fill(surface, true);
00180
00181
00182 mln_piter_(bin_ima_t) f(minima.domain());
00183 for_all(f)
00184 if (minima(f) != mln::literal::zero)
00185 surface(f) = false;
00186
00187
00188
00189
00190
00191 mln::topo::is_simple_cell<bin_ima_t> is_simple_p;
00192
00193
00194
00195
00196
00197
00198
00199
00200 mln::topo::is_n_face<bin_ima_t::dim> constraint_p;
00201 bin_ima_t skel =
00202 mln::topo::skeleton::breadth_first_thinning(surface, nbh,
00203 is_simple_p,
00204 mln::topo::detach<D, G>,
00205 constraint_p);
00206
00207
00208
00209
00210
00211
00212
00213 #if 0
00214 mln::io::off::save(skel | mln::pw::value(skel) == mln::pw::cst(true),
00215 output_filename);
00216 #endif
00217 mln::io::off::save_bin_alt(skel, output_filename);
00218 }