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 <algorithm>
00027 #include <iterator>
00028 #include <iostream>
00029
00030 #include <mln/topo/complex.hh>
00031
00032 using namespace mln;
00033
00034
00035
00036
00037
00038
00039 template <unsigned N, unsigned D>
00040 void test_static_n_face_iter(topo::complex<D>& c);
00041
00042 #if 0
00043 template <unsigned N, unsigned D>
00044 void test_faces_iter(topo::complex<D>& c);
00045 #endif
00046
00047
00048 int main()
00049 {
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 const unsigned D = 2;
00069
00070
00071
00072
00073
00074 topo::complex<D> c;
00075
00076
00077 topo::n_face<0, D> v0 = c.add_face();
00078 topo::n_face<0, D> v1 = c.add_face();
00079 topo::n_face<0, D> v2 = c.add_face();
00080 topo::n_face<0, D> v3 = c.add_face();
00081
00082
00083 topo::n_face<1, D> e0 = c.add_face(-v1 + v0);
00084 topo::n_face<1, D> e1 = c.add_face(-v0 + v2);
00085 topo::n_face<1, D> e2 = c.add_face(-v2 + v1);
00086 topo::n_face<1, D> e3 = c.add_face(-v0 + v3);
00087 topo::n_face<1, D> e4 = c.add_face(-v3 + v2);
00088
00089
00090 topo::n_face<2, D> t0 = c.add_face( e0 + e1 + e2);
00091 topo::n_face<2, D> t1 = c.add_face(-e1 + e3 + e4);
00092
00093 std::cout << c << std::endl;
00094
00095 std::cout
00096 << "Using ``static'' manipulators." << std::endl
00097 << " number of 0-faces: c.nfaces_of_static_dim<0>() = "
00098 << c.nfaces_of_static_dim<0>() << std::endl
00099 << " number of 1-faces: c.nfaces_of_static_dim<1>() = "
00100 << c.nfaces_of_static_dim<1>() << std::endl
00101 << " number of 2-faces: c.nfaces_of_static_dim<2>() = "
00102 << c.nfaces_of_static_dim<2>() << std::endl
00103 << " total number of faces: c.nfaces() = " << c.nfaces() << std::endl
00104 << std::endl;
00105
00106 std::cout
00107 << "Using ``dynamic'' manipulators." << std::endl
00108 << " number of 0-faces: c.nfaces_of_dim(0) = "
00109 << c.nfaces_of_dim(0) << std::endl
00110 << " number of 1-faces: c.nfaces_of_dim(1) = "
00111 << c.nfaces_of_dim(1) << std::endl
00112 << " number of 2-faces: c.nfaces_of_dim(2) = "
00113 << c.nfaces_of_dim(2) << std::endl
00114 << std::endl;
00115
00116
00117
00118
00119
00120
00121 const topo::face_data<1, D>& face1 = e0.data();
00122
00123
00124
00125
00126 topo::face<D> af(e0);
00127
00128 const topo::face_data<1, D>& face2 = af.data<1>();
00129
00130 mln_assertion(&face1 == &face2);
00131
00132
00133
00134
00135
00136
00137 std::vector< topo::algebraic_face<D> > af_lower_dim_adj_faces =
00138 af.lower_dim_adj_faces();
00139 std::cout << "lower-dimension faces adjacent to " << af << ":" << std::endl;
00140 std::copy (af_lower_dim_adj_faces.begin(), af_lower_dim_adj_faces.end(),
00141 std::ostream_iterator< topo::face<D> > (std::cout, "\n"));
00142 std::cout << std::endl;
00143
00144
00145 std::vector< topo::algebraic_face<D> > af_higher_dim_adj_faces =
00146 af.higher_dim_adj_faces();
00147 std::cout << "higher-dimension faces adjacent to " << af << ":" << std::endl;
00148 std::copy (af_higher_dim_adj_faces.begin(), af_higher_dim_adj_faces.end(),
00149 std::ostream_iterator< topo::face<D> > (std::cout, "\n"));
00150 std::cout << std::endl;
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 topo::face_fwd_iter<D> fwd_f(c);
00166 topo::face_bkd_iter<D> bkd_f(c);
00167 for_all_2(fwd_f, bkd_f)
00168 std::cout << fwd_f << ' ' << bkd_f << std::endl;
00169 std::cout << std::endl;
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 for (unsigned n = 0; n <= D; ++n)
00182 {
00183 topo::n_face_fwd_iter<D> fwd_nf(c, n);
00184 topo::n_face_fwd_iter<D> bkd_nf(c, n);
00185 std::cout << "test (dynamic) n_face_iters (n = " << n << "):"
00186 << std::endl;
00187 for_all_2(fwd_nf, bkd_nf)
00188 std::cout << fwd_nf << ' ' << bkd_nf << std::endl;
00189 std::cout << std::endl;
00190 }
00191
00192
00193 test_static_n_face_iter<0>(c);
00194 test_static_n_face_iter<1>(c);
00195 test_static_n_face_iter<2>(c);
00196
00197
00198 # if 0
00199
00200
00201 test_faces_iter<0>(c);
00202 test_faces_iter<1>(c);
00203 test_faces_iter<2>(c);
00204 #endif
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 topo::adj_lower_face_fwd_iter<D> fwd_alf(fwd_f);
00229 topo::adj_lower_face_bkd_iter<D> bkd_alf(fwd_f);
00230 for_all(fwd_f)
00231 {
00232 std::cout << "Lower-dimension faces adjacent to " << fwd_f << ": "
00233 << std::endl;
00234 for_all_2(fwd_alf, bkd_alf)
00235 std::cout << " " << fwd_alf << '\t' << bkd_alf << std::endl;
00236 }
00237 std::cout << std::endl;
00238
00239
00240 topo::adj_higher_face_fwd_iter<D> fwd_ahf(fwd_f);
00241 topo::adj_higher_face_bkd_iter<D> bkd_ahf(fwd_f);
00242 for_all(fwd_f)
00243 {
00244 std::cout << "Higher-dimension faces adjacent to " << fwd_f << ": "
00245 << std::endl;
00246 for_all_2(fwd_ahf, bkd_ahf)
00247 std::cout << " " << fwd_ahf << '\t' << bkd_ahf << std::endl;
00248 }
00249 std::cout << std::endl;
00250
00251
00252
00253 topo::adj_lower_higher_face_fwd_iter<D> fwd_alhf(fwd_f);
00254 topo::adj_lower_higher_face_bkd_iter<D> bkd_alhf(fwd_f);
00255 for_all(fwd_f)
00256 {
00257 std::cout << "Lower- and higher-dimension faces adjacent to " << fwd_f
00258 << ": " << std::endl;
00259 for_all_2(fwd_alhf, bkd_alhf)
00260 std::cout << " " << fwd_alhf << '\t' << bkd_alhf << std::endl;
00261 }
00262 std::cout << std::endl;
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 topo::adj_lower_dim_connected_n_face_fwd_iter<D> fwd_aldcf(fwd_f);
00273 topo::adj_lower_dim_connected_n_face_bkd_iter<D> bkd_aldcf(fwd_f);
00274 for_all(fwd_f)
00275 {
00276 std::cout << "Lower-dim-connected faces adjacent to " << fwd_f
00277 << ": " << std::endl;
00278 for_all_2(fwd_aldcf, bkd_aldcf)
00279 std::cout << " " << fwd_aldcf << '\t' << bkd_aldcf << std::endl;
00280 }
00281 std::cout << std::endl;
00282
00283
00284
00285 topo::adj_higher_dim_connected_n_face_fwd_iter<D> fwd_ahdcf(fwd_f);
00286 topo::adj_higher_dim_connected_n_face_bkd_iter<D> bkd_ahdcf(fwd_f);
00287 for_all(fwd_f)
00288 {
00289 std::cout << "Higher-dim-connected faces adjacent to " << fwd_f
00290 << ": " << std::endl;
00291 for_all_2(fwd_ahdcf, bkd_ahdcf)
00292 std::cout << " " << fwd_ahdcf << '\t' << bkd_ahdcf << std::endl;
00293 }
00294 std::cout << std::endl;
00295
00296
00297
00298 topo::adj_m_face_fwd_iter<D> fwd_amf(fwd_f, 0);
00299 topo::adj_m_face_bkd_iter<D> bkd_amf(fwd_f, 0);
00300 for_all(fwd_f)
00301 {
00302 for (unsigned m = 0; m <= D; ++m)
00303 {
00304 fwd_amf.set_m(m);
00305 bkd_amf.set_m(m);
00306 std::cout << m << "-faces (transitively) adjacent to " << fwd_f
00307 << ": " << std::endl;
00308 for_all_2(fwd_amf, bkd_amf)
00309 std::cout << " " << fwd_amf << '\t' << bkd_amf << std::endl;
00310 }
00311 std::cout << std::endl;
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 std::cout << "Center-only iterator:" << std::endl;
00372 topo::center_only_iter<D> center(fwd_f);
00373 for_all(fwd_f)
00374 for_all(center)
00375 std::cout << " " << center << std::endl;
00376 std::cout << std::endl;
00377 }
00378
00379
00380 template <unsigned N, unsigned D>
00381 void
00382 test_static_n_face_iter(topo::complex<D>& c)
00383 {
00384 std::cout << "test_static_n_face_iter<" << N << ", " << D << ">:"
00385 << std::endl;
00386
00387
00388
00389 topo::static_n_face_fwd_iter<N, D> fwd_nf(c);
00390 topo::static_n_face_bkd_iter<N, D> bkd_nf(c);
00391 for_all_2(fwd_nf, bkd_nf)
00392 std::cout << fwd_nf << ' ' << bkd_nf << std::endl;
00393 std::cout << std::endl;
00394 }
00395
00396
00397 # if 0
00398 template <unsigned N, unsigned D>
00399 void
00400 test_faces_iter(topo::complex<D>& c)
00401 {
00402 std::cout << "test_faces_iter<" << N << ", " << D << ">:"
00403 << std::endl;
00404 mln_fwd_fiter(N, topo::complex<D>) fwd_nf(c);
00405 mln_bkd_fiter(N, topo::complex<D>) bkd_nf(c);
00406 for_all_2(fwd_nf, bkd_nf)
00407 std::cout << fwd_nf << ' ' << bkd_nf << std::endl;
00408 std::cout << std::endl;
00409 }
00410 #endif