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 #include <iostream>
00027
00028 #include <mln/value/int_u8.hh>
00029 #include <mln/core/alias/point2d.hh>
00030
00031 #include <mln/core/site_set/p_faces.hh>
00032 #include <mln/core/image/complex_image.hh>
00033
00034
00035 #include <mln/core/image/complex_neighborhoods.hh>
00036 #include <mln/core/image/complex_neighborhood_piter.hh>
00037
00038
00039
00040
00041
00042
00043 template <typename I, typename N>
00044 void
00045 test_neighborhood(const mln::Image<I>& ima_, const mln::Neighborhood<N> nbh,
00046 const std::string& comment);
00047
00048
00049 int main()
00050 {
00051 using namespace mln;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 const unsigned D = 2;
00078
00079 topo::complex<D> c;
00080
00081
00082 topo::n_face<0, D> v0 = c.add_face();
00083 topo::n_face<0, D> v1 = c.add_face();
00084 topo::n_face<0, D> v2 = c.add_face();
00085 topo::n_face<0, D> v3 = c.add_face();
00086
00087
00088 topo::n_face<1, D> e0 = c.add_face(v0 + v1);
00089 topo::n_face<1, D> e1 = c.add_face(v0 + v2);
00090 topo::n_face<1, D> e2 = c.add_face(v1 + v2);
00091 topo::n_face<1, D> e3 = c.add_face(v0 + v3);
00092 topo::n_face<1, D> e4 = c.add_face(v2 + v3);
00093
00094
00095 topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2);
00096 topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4);
00097
00098
00099
00100
00101
00102
00103 typedef point2d P;
00104 typedef geom::complex_geometry<D, P> G;
00105 G geom;
00106 geom.add_location(point2d(0,1));
00107 geom.add_location(point2d(2,0));
00108 geom.add_location(point2d(2,2));
00109 geom.add_location(point2d(0,3));
00110
00111
00112
00113
00114
00115
00116
00117 p_complex<D, G> pc(c, geom);
00118 topo::face<D> af(e0);
00119
00120 complex_psite<D, G> cs(pc, af);
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 p_faces<0, D, G> pf0(c);
00133
00134 p_faces<1, D, G> pf1(c);
00135
00136 p_faces<2, D, G> pf2(c);
00137
00138
00139 faces_psite<0, D, G> fs0(pf0, v0);
00140 faces_psite<1, D, G> fs1(pf1, e0);
00141 faces_psite<2, D, G> fs2(pf2, t0);
00142
00143
00144
00145
00146
00147
00148 using mln::value::int_u8;
00149
00150
00151
00152 typedef complex_image<D, G, int_u8> ima_t;
00153
00154
00155 metal::vec<D + 1, std::vector< int_u8 > > values;
00156
00157 for (unsigned d = 0; d <= D; ++d)
00158 for (unsigned n = 0; n < pc.cplx().nfaces_of_dim(d); ++n)
00159 values[d].push_back(d);
00160
00161
00162 ima_t ima(pc, values);
00163
00164
00165 mln_assertion(ima(cs) == 1u);
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 mln_fwd_piter_(ima_t) fp(ima.domain());
00177 for_all(fp)
00178 std::cout << "ima(" << fp << ") = " << ima(fp) << std::endl;
00179 std::cout << std::endl;
00180
00181 mln_bkd_piter_(ima_t) bp(ima.domain());
00182 for_all(bp)
00183 std::cout << "ima(" << bp << ") = " << ima(bp) << std::endl;
00184 std::cout << std::endl;
00185
00186
00187
00188
00189
00190
00191
00192 for (unsigned n = 0; n <= D; ++n)
00193 {
00194 p_n_faces_fwd_piter<D, G> fwd_np(ima.domain(), n);
00195 p_n_faces_bkd_piter<D, G> bkd_np(ima.domain(), n);
00196 for_all_2(fwd_np, bkd_np)
00197 std::cout << "ima(" << fwd_np << ") = " << ima(fwd_np) << '\t'
00198 << "ima(" << bkd_np << ") = " << ima(bkd_np)
00199 << std::endl;
00200 std::cout << std::endl;
00201 }
00202
00203
00204
00205 # if 0
00206
00207 p_complex_faces_fwd_piter_<0, D, G> f0p(ima.domain());
00208 for_all(f0p)
00209 std::cout << "ima(" << f0p << ") = " << ima(f0p) << std::endl;
00210 #endif
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 test_neighborhood(ima, complex_lower_neighborhood<D, G>(),
00223 "Lower-dimension faces");
00224 test_neighborhood(ima, complex_higher_neighborhood<D, G>(),
00225 "Higher-dimension faces");
00226 test_neighborhood(ima, complex_lower_higher_neighborhood<D, G>(),
00227 "Lower- and higer-dimension faces");
00228
00229 test_neighborhood(ima,
00230 complex_lower_dim_connected_n_face_neighborhood<D, G>(),
00231 "Lower-dimension connected n-faces");
00232 test_neighborhood(ima,
00233 complex_higher_dim_connected_n_face_neighborhood<D, G>(),
00234 "Higher-dimension connected n-faces");
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 }
00264
00265
00266 template <typename I, typename N>
00267 void
00268 test_neighborhood(const mln::Image<I>& ima_, const mln::Neighborhood<N> nbh,
00269 const std::string& comment)
00270 {
00271 const I& ima = exact(ima_);
00272 mln_fwd_piter(I) fp(ima.domain());
00273
00274 mln_fwd_niter(N) fn(nbh, fp);
00275 mln_bkd_niter(N) bn(nbh, fp);
00276 for_all(fp)
00277 {
00278 std::cout << comment << " adjacent to " << fp << std::endl;
00279 for_all_2(fn, bn)
00280 {
00281 mln_assertion((fn.center() == static_cast<const mln_psite(I)&>(fp)));
00282 mln_assertion((bn.center() == static_cast<const mln_psite(I)&>(fp)));
00283 std::cout << " " << fn << '\t' << bn << std::endl;
00284 }
00285 }
00286 std::cout << std::endl;
00287 }