2582: Exercise mln::geom::complex_geometry with mln::p_complex.

* tests/core/image/complex_image.cc, * tests/morpho/complex_image_morpho.cc: ...here. Adjust: s/P/G/. * tests/core/site_set/p_complex.cc: New. * tests/core/site_set/Makefile.am (check_PROGRAMS): Add p_complex. (p_complex_SOURCES): New. --- milena/ChangeLog | 12 +++ milena/tests/core/image/complex_image.cc | 79 ++++++++++------- milena/tests/core/site_set/Makefile.am | 2 + milena/tests/core/site_set/p_complex.cc | 127 +++++++++++++++++++++++++++ milena/tests/morpho/complex_image_morpho.cc | 36 +++++--- 5 files changed, 209 insertions(+), 47 deletions(-) create mode 100644 milena/tests/core/site_set/p_complex.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index fa3e596..24542de 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,17 @@ 2008-10-16 Roland Levillain <roland@lrde.epita.fr> + Exercise mln::geom::complex_geometry with mln::p_complex. + + * tests/core/image/complex_image.cc, + * tests/morpho/complex_image_morpho.cc: + ...here. + Adjust: s/P/G/. + * tests/core/site_set/p_complex.cc: New. + * tests/core/site_set/Makefile.am (check_PROGRAMS): Add p_complex. + (p_complex_SOURCES): New. + +2008-10-16 Roland Levillain <roland@lrde.epita.fr> + Have complex-based site set use geometry functor for site location. * mln/core/site_set/p_complex.hh diff --git a/milena/tests/core/image/complex_image.cc b/milena/tests/core/image/complex_image.cc index d30ccc4..4b81713 100644 --- a/milena/tests/core/image/complex_image.cc +++ b/milena/tests/core/image/complex_image.cc @@ -57,15 +57,17 @@ int main() /* A 2-d (simplicial) complex and its adjacency graph. - v0 e3 v3 - o-----------o v0----e3----v3 - / \ ,-----. / / \ | / - / . \ \ t1/ / / \ t1 / - e0 / / \ e1\ / / e4 e0. ,e1Ž `e4 - / /t0 \ \ ' / / t0 \ / - / `-----' \ / / | \ / - o-----------o v1----e2----v2 - v1 e2 v2 + c 0 1 2 3 + r .------------------------ + | v0 e3 v3 + 0 | o-----------o v0----e3----v3 + | / \ ,-----. / / \ | / + | / . \ \ t1/ / / \ t1 / + 1 | e0 / / \ e1\ / / e4 e0. ,e1Ž `e4 + | / /t0 \ \ ' / / t0 \ / + | / `-----' \ / / | \ / + 2 | o-----------o v1----e2----v2 + | v1 e2 v2 v = vertex e = edge @@ -94,18 +96,29 @@ int main() topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2); topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4); - + + /*------------------------------. + | Complex geometry (location). | + `------------------------------*/ + + typedef point2d P; + typedef geom::complex_geometry<D, P> G; + G geom; + geom.add_location(point2d(0,1)); // 0-face #0. + geom.add_location(point2d(2,0)); // 0-face #1. + geom.add_location(point2d(2,2)); // 0-face #2. + geom.add_location(point2d(0,3)); // 0-face #3. + + /*---------------------. | Complex-based pset. | `---------------------*/ - typedef point2d P; - // A pset. - p_complex<D, P> pc(c); + p_complex<D, G> pc(c, geom); topo::face<D> af(e0); // An associated psite. - complex_psite<D, P> cs(pc, af); + complex_psite<D, G> cs(pc, af); /*--------------------. @@ -117,16 +130,16 @@ int main() of the test? */ // Pset of 0-faces. - p_faces<0, D, P> pf0(c); + p_faces<0, D, G> pf0(c); // Pset of 1-faces. - p_faces<1, D, P> pf1(c); + p_faces<1, D, G> pf1(c); // Pset of 2-faces. - p_faces<2, D, P> pf2(c); + p_faces<2, D, G> pf2(c); // Some psites on faces. - faces_psite<0, D, P> fs0(pf0, v0); - faces_psite<1, D, P> fs1(pf1, e0); - faces_psite<2, D, P> fs2(pf2, t0); + faces_psite<0, D, G> fs0(pf0, v0); + faces_psite<1, D, G> fs1(pf1, e0); + faces_psite<2, D, G> fs2(pf2, t0); /*----------------------. @@ -137,7 +150,7 @@ int main() // An image type built on a 2-complex with mln::int_u8 values on // each face. - typedef complex_image<D, P, int_u8> ima_t; + typedef complex_image<D, G, int_u8> ima_t; // Values. metal::vec<D + 1, std::vector< int_u8 > > values; @@ -179,8 +192,8 @@ int main() // Dynamic version. for (unsigned n = 0; n <= D; ++n) { - p_n_faces_fwd_piter<D, P> fwd_np(ima.domain(), n); - p_n_faces_bkd_piter<D, P> bkd_np(ima.domain(), n); + p_n_faces_fwd_piter<D, G> fwd_np(ima.domain(), n); + p_n_faces_bkd_piter<D, G> bkd_np(ima.domain(), n); for_all_2(fwd_np, bkd_np) std::cout << "ima(" << fwd_np << ") = " << ima(fwd_np) << '\t' << "ima(" << bkd_np << ") = " << ima(bkd_np) @@ -192,7 +205,7 @@ int main() // FIXME: Disabled (moved to the attic). # if 0 // FIXME: Sugar the name of the iterator. - p_complex_faces_fwd_piter_<0, D, P> f0p(ima.domain()); + p_complex_faces_fwd_piter_<0, D, G> f0p(ima.domain()); for_all(f0p) std::cout << "ima(" << f0p << ") = " << ima(f0p) << std::endl; #endif @@ -211,7 +224,7 @@ int main() // Iterate on the lower-dimension faces of each face. { - typedef complex_lower_neighborhood<D, P> nbh_t; + typedef complex_lower_neighborhood<D, G> nbh_t; nbh_t nbh; mln_fwd_niter_(nbh_t) fn(nbh, fp); mln_bkd_niter_(nbh_t) bn(nbh, fp); @@ -221,9 +234,9 @@ int main() for_all_2(fn, bn) { mln_assertion((fn.center() == - static_cast<const complex_psite<D, P>&>(fp))); + static_cast<const complex_psite<D, G>&>(fp))); mln_assertion((bn.center() == - static_cast<const complex_psite<D, P>&>(fp))); + static_cast<const complex_psite<D, G>&>(fp))); std::cout << " " << fn << '\t' << bn << std::endl; } } @@ -232,7 +245,7 @@ int main() // Iterate on the higher-dimension faces of each face. { - typedef complex_higher_neighborhood<D, P> nbh_t; + typedef complex_higher_neighborhood<D, G> nbh_t; nbh_t nbh; mln_fwd_niter_(nbh_t) fn(nbh, fp); mln_bkd_niter_(nbh_t) bn(nbh, fp); @@ -242,9 +255,9 @@ int main() for_all_2(fn, bn) { mln_assertion((fn.center() == - static_cast<const complex_psite<D, P>&>(fp))); + static_cast<const complex_psite<D, G>&>(fp))); mln_assertion((bn.center() == - static_cast<const complex_psite<D, P>&>(fp))); + static_cast<const complex_psite<D, G>&>(fp))); std::cout << " " << fn << '\t' << bn << std::endl; } } @@ -253,7 +266,7 @@ int main() // Iterate on the lower- and higher-dimension faces of each face. { - typedef complex_lower_higher_neighborhood<D, P> nbh_t; + typedef complex_lower_higher_neighborhood<D, G> nbh_t; nbh_t nbh; mln_fwd_niter_(nbh_t) fn(nbh, fp); mln_bkd_niter_(nbh_t) bn(nbh, fp); @@ -264,9 +277,9 @@ int main() for_all_2(fn, bn) { mln_assertion((fn.center() == - static_cast<const complex_psite<D, P>&>(fp))); + static_cast<const complex_psite<D, G>&>(fp))); mln_assertion((bn.center() == - static_cast<const complex_psite<D, P>&>(fp))); + static_cast<const complex_psite<D, G>&>(fp))); std::cout << " " << fn << '\t' << bn << std::endl; } } diff --git a/milena/tests/core/site_set/Makefile.am b/milena/tests/core/site_set/Makefile.am index 1b23c79..7c9c2a8 100644 --- a/milena/tests/core/site_set/Makefile.am +++ b/milena/tests/core/site_set/Makefile.am @@ -5,6 +5,7 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ p_array \ ## p_bgraph \ + p_complex \ p_edges \ p_image \ p_priority_queue \ @@ -16,6 +17,7 @@ check_PROGRAMS = \ p_array_SOURCES = p_array.cc ##p_bgraph_SOURCES = p_bgraph.cc +p_complex_SOURCES = p_complex.cc p_image_SOURCES = p_image.cc p_priority_queue_SOURCES = p_priority_queue.cc p_queue_SOURCES = p_queue.cc diff --git a/milena/tests/core/site_set/p_complex.cc b/milena/tests/core/site_set/p_complex.cc new file mode 100644 index 0000000..490d387 --- /dev/null +++ b/milena/tests/core/site_set/p_complex.cc @@ -0,0 +1,127 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/// \file tests/core/image/p_complex.cc +/// \brief Test of mln::p_complex and mln::geom::complex_geometry. + +#include <algorithm> +#include <iterator> +#include <iostream> + +#include <mln/value/int_u8.hh> +#include <mln/core/alias/point2d.hh> + +#include <mln/core/site_set/p_faces.hh> +#include <mln/core/image/complex_image.hh> + +/* FIXME: Split this test (and maybe factor common parts, like the + construction of the complex), since it exercises too many features + in a single file. */ + + +int main() +{ + using namespace mln; + + /*----------. + | Complex. | + `----------*/ + + /* A 2-d (simplicial) complex and its adjacency graph. + + c 0 1 2 3 + r .------------------------ + | v0 e3 v3 + 0 | o-----------o v0----e3----v3 + | / \ ,-----. / / \ | / + | / . \ \ t1/ / / \ t1 / + 1 | e0 / / \ e1\ / / e4 e0. ,e1Ž `e4 + | / /t0 \ \ ' / / t0 \ / + | / `-----' \ / / | \ / + 2 | o-----------o v1----e2----v2 + | v1 e2 v2 + + v = vertex + e = edge + t = triangle + */ + + + const unsigned D = 2; + + topo::complex<D> c; + + // 0-faces (points). + topo::n_face<0, D> v0 = c.add_face(); + topo::n_face<0, D> v1 = c.add_face(); + topo::n_face<0, D> v2 = c.add_face(); + topo::n_face<0, D> v3 = c.add_face(); + + // 1-faces (segments). + topo::n_face<1, D> e0 = c.add_face(v0 + v1); + topo::n_face<1, D> e1 = c.add_face(v0 + v2); + topo::n_face<1, D> e2 = c.add_face(v1 + v2); + topo::n_face<1, D> e3 = c.add_face(v0 + v3); + topo::n_face<1, D> e4 = c.add_face(v2 + v3); + + // 2-faces (triangles). + topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2); + topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4); + + + /*------------------------------. + | Complex geometry (location). | + `------------------------------*/ + + typedef point2d P; + typedef geom::complex_geometry<D, P> G; + G geom; + geom.add_location(point2d(0,1)); // 0-face #0. + geom.add_location(point2d(2,0)); // 0-face #1. + geom.add_location(point2d(2,2)); // 0-face #2. + geom.add_location(point2d(0,3)); // 0-face #3. + + + /*---------------------. + | Complex-based pset. | + `---------------------*/ + + // A pset. + p_complex<D, G> pc(c, geom); + + // An iterator on this pset. + p_complex_fwd_piter_<D, G> p(pc); + for_all(p) + { + std::cout << p << ": "; + // Print site(s). + mln_site_(G) s(p); + std::copy (s.sites.begin(), s.sites.end(), + std::ostream_iterator<P>(std::cout, " ")); + std::cout << std::endl; + } +} diff --git a/milena/tests/morpho/complex_image_morpho.cc b/milena/tests/morpho/complex_image_morpho.cc index e8b7d25..baf0f68 100644 --- a/milena/tests/morpho/complex_image_morpho.cc +++ b/milena/tests/morpho/complex_image_morpho.cc @@ -65,15 +65,17 @@ int main() /* A 2-d (simplicial) complex and its adjacency graph. - v0 e3 v3 - o-----------o v0----e3----v3 - / \ ,-----. / / \ | / - / . \ \ t1/ / / \ t1 / - e0 / / \ e1\ / / e4 e0. ,e1Ž `e4 - / /t0 \ \ ' / / t0 \ / - / `-----' \ / / | \ / - o-----------o v1----e2----v2 - v1 e2 v2 + c 0 1 2 3 + r .------------------------ + | v0 e3 v3 + 0 | o-----------o v0----e3----v3 + | / \ ,-----. / / \ | / + | / . \ \ t1/ / / \ t1 / + 1 | e0 / / \ e1\ / / e4 e0. ,e1Ž `e4 + | / /t0 \ \ ' / / t0 \ / + | / `-----' \ / / | \ / + 2 | o-----------o v1----e2----v2 + | v1 e2 v2 v = vertex e = edge @@ -108,7 +110,13 @@ int main() `-------------------------*/ typedef point2d P; - p_complex<D, P> pc(c); + typedef geom::complex_geometry<D, P> G; + G geom; + geom.add_location(point2d(0,1)); // 0-face #0. + geom.add_location(point2d(2,0)); // 0-face #1. + geom.add_location(point2d(2,2)); // 0-face #2. + geom.add_location(point2d(0,3)); // 0-face #3. + p_complex<D, G> pc(c, geom); /*----------------------. @@ -119,7 +127,7 @@ int main() // An image type built on a 2-complex with mln::int_u8 values on // each face. - typedef complex_image<D, P, int_u8> ima_t; + typedef complex_image<D, G, int_u8> ima_t; ima_t ima(pc); // Initialize values. debug::iota(ima); @@ -148,9 +156,9 @@ int main() | Morphological operations on complex-based images. | `---------------------------------------------------*/ - test_morpho(ima, complex_lower_window_p<D, P>()); - test_morpho(ima, complex_higher_window_p<D, P>()); - test_morpho(ima, complex_lower_higher_window_p<D, P>()); + test_morpho(ima, complex_lower_window_p<D, G>()); + test_morpho(ima, complex_higher_window_p<D, G>()); + test_morpho(ima, complex_lower_higher_window_p<D, G>()); /* FIXME: Exercise elementary erosion/dilation (with neighborhoods) when available. */ -- 1.6.0.1
participants (1)
-
Roland Levillain