
* tests/core/image/complex_image.hh (make_test_bin_2complex_image2d): New function. * tests/topo/is_facet.cc, * tests/make/detachment.cc, * tests/make/attachment.cc: New. * tests/topo/Makefile.am (check_PROGRAMS): Add is_facet. (is_facet_SOURCES): New. * tests/make/Makefile.am (check_PROGRAMS): Add attachment and detachment. (attachment_SOURCES, detachment_SOURCES): New. --- milena/ChangeLog | 16 +++++ milena/tests/core/image/complex_image.hh | 20 ++++++- milena/tests/make/Makefile.am | 6 ++- milena/tests/make/attachment.cc | 77 +++++++++++++++++++++++ milena/tests/make/detachment.cc | 98 ++++++++++++++++++++++++++++++ milena/tests/topo/Makefile.am | 7 ++- milena/tests/topo/is_facet.cc | 80 ++++++++++++++++++++++++ 7 files changed, 299 insertions(+), 5 deletions(-) create mode 100644 milena/tests/make/attachment.cc create mode 100644 milena/tests/make/detachment.cc create mode 100644 milena/tests/topo/is_facet.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index e2f6ec2..0f8afb9 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,21 @@ 2011-02-24 Roland Levillain <roland@lrde.epita.fr> + Exercise topology-related routines. + + * tests/core/image/complex_image.hh + (make_test_bin_2complex_image2d): New function. + * tests/topo/is_facet.cc, + * tests/make/detachment.cc, + * tests/make/attachment.cc: + New. + * tests/topo/Makefile.am (check_PROGRAMS): Add is_facet. + (is_facet_SOURCES): New. + * tests/make/Makefile.am (check_PROGRAMS): Add attachment and + detachment. + (attachment_SOURCES, detachment_SOURCES): New. + +2011-02-24 Roland Levillain <roland@lrde.epita.fr> + New complex image alias: mln::bin_2complex_image2d. * mln/core/alias/complex_image.hh (mln::bin_2complex_image2d): diff --git a/milena/tests/core/image/complex_image.hh b/milena/tests/core/image/complex_image.hh index 5836147..030006a 100644 --- a/milena/tests/core/image/complex_image.hh +++ b/milena/tests/core/image/complex_image.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory +// Copyright (C) 2008, 2009, 2011 EPITA Research and Development Laboratory // (LRDE) // // This file is part of Olena. @@ -34,6 +34,8 @@ # include <mln/core/alias/complex_image.hh> # include <mln/value/int_u8.hh> +# include <mln/data/fill.hh> + // FIXME: Keep this? (See below.) # include <mln/core/site_set/p_faces.hh> @@ -149,7 +151,7 @@ make_test_complex_image() mln::metal::vec<D + 1, std::vector< int_u8 > > values; // Assign 0 to 0-faces, 1 to 1-faces and 2 to 2-faces. for (unsigned d = 0; d <= D; ++d) - for (unsigned n = 0; n < pc.cplx().nfaces(d); ++n) + for (unsigned n = 0; n < pc.cplx().nfaces_of_dim(d); ++n) values[d].push_back(d); // Create and init an image based on PC. @@ -161,4 +163,18 @@ make_test_complex_image() return ima; } + +/* FIXME: Quick and dirty implementation, based on + `make_test_complex_image'. Factor and revamp. */ +inline +mln::bin_2complex_image2d +make_test_bin_2complex_image2d() +{ + mln::int_u8_2complex_image2d model = make_test_complex_image(); + mln::bin_2complex_image2d ima; + mln::initialize(ima, model); + mln::data::fill(ima, true); + return ima; +} + #endif // ! TESTS_CORE_IMAGE_COMPLEX_IMAGE_HH diff --git a/milena/tests/make/Makefile.am b/milena/tests/make/Makefile.am index 34e0eff..5b28d6b 100644 --- a/milena/tests/make/Makefile.am +++ b/milena/tests/make/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2007, 2008, 2009 EPITA Research and Development +# Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development # Laboratory (LRDE). # # This file is part of Olena. @@ -18,6 +18,8 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ + attachment \ + detachment \ dual_neighb \ dummy_p_edges \ dummy_p_vertices \ @@ -33,6 +35,8 @@ check_PROGRAMS = \ w_window \ w_window_directional +attachment_SOURCES = attachment.cc +detachment_SOURCES = detachment.cc dual_neighb_SOURCES = dual_neighb.cc dummy_p_edges_SOURCES = dummy_p_edges.cc dummy_p_vertices_SOURCES = dummy_p_vertices.cc diff --git a/milena/tests/make/attachment.cc b/milena/tests/make/attachment.cc new file mode 100644 index 0000000..2674727 --- /dev/null +++ b/milena/tests/make/attachment.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 +/// \brief Exercise mln::make::attachment. + +#include <mln/make/attachment.hh> + +#include "tests/core/image/complex_image.hh" + + +int +main() +{ + typedef mln::bin_2complex_image2d I; + typedef mln_psite_(I) P; + + // Neighborhood (n-face to (n+1)-faces relationship) required by + // mln::is_facet. + mln::complex_lower_higher_neighborhood<I::dim, mln_geom_(I)> adj_nbh; + + /* 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 + */ + I ima = make_test_bin_2complex_image2d(); + + // A few faces. + P v0(ima.domain(), 0, 0); + P v2(ima.domain(), 0, 2); + P e1(ima.domain(), 1, 1); + P t0(ima.domain(), 2, 0); + + // The attachment of the cell corresponding to T0 from IMA yields a + // set containing E1, V0 and V1. + mln::p_set<P> attach_t0 = mln::make::attachment(ima, t0, adj_nbh); + mln_assertion(attach_t0.nsites() == 3); + mln_assertion(attach_t0.has(e1)); + mln_assertion(attach_t0.has(v0)); + mln_assertion(attach_t0.has(v2)); +} diff --git a/milena/tests/make/detachment.cc b/milena/tests/make/detachment.cc new file mode 100644 index 0000000..759c642 --- /dev/null +++ b/milena/tests/make/detachment.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 +/// \brief Exercise mln::make::detachment. + +#include <mln/make/detachment.hh> + +#include "tests/core/image/complex_image.hh" + + +int +main() +{ + typedef mln::bin_2complex_image2d I; + typedef mln_psite_(I) P; + + // Neighborhood (n-face to (n+1)-faces relationship) required by + // mln::is_facet. + mln::complex_lower_higher_neighborhood<I::dim, mln_geom_(I)> adj_nbh; + + /* 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 + */ + I ima = make_test_bin_2complex_image2d(); + + // A few faces. + P v0(ima.domain(), 0, 0); + P v1(ima.domain(), 0, 1); + P e0(ima.domain(), 1, 0); + P e2(ima.domain(), 1, 2); + P t0(ima.domain(), 2, 0); + + /* Remember that `detachment' does not have the same meaning as in + couprie.08.pami. + + mln::make::detachment(ima, f, adj_nbh) + + does not correspond to the complex resulting from the collapsing + of the cell CELL associated to F onto IMA, but the part that is + removed, i.e., the detached part CELL - attachment(ima, f, + adj_nbh). (see mln/make/detachment). */ + + // Detaching the cell corresponding to T0 from IMA yields a set + // containing T0, E0, E2 and V1. + mln::p_set<P> detach_t0 = mln::make::detachment(ima, t0, adj_nbh); + mln_assertion(detach_t0.nsites() == 4); + mln_assertion(detach_t0.has(t0)); + mln_assertion(detach_t0.has(e0)); + mln_assertion(detach_t0.has(e2)); + mln_assertion(detach_t0.has(v1)); + + // E0 is not a facet and thus its corresponding cell cannot be + // detached from IMA. + mln::p_set<P> detach_e0 = mln::make::detachment(ima, e0, adj_nbh); + mln_assertion(detach_e0.nsites() == 0); + + // Likewise for V0. + mln::p_set<P> detach_v0 = mln::make::detachment(ima, v0, adj_nbh); + mln_assertion(detach_v0.nsites() == 0); +} diff --git a/milena/tests/topo/Makefile.am b/milena/tests/topo/Makefile.am index b8684bf..6da7c28 100644 --- a/milena/tests/topo/Makefile.am +++ b/milena/tests/topo/Makefile.am @@ -1,4 +1,5 @@ -# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE). +# Copyright (C) 2008, 2009, 2011 EPITA Research and Development +# Laboratory (LRDE). # # This file is part of Olena. # @@ -19,8 +20,10 @@ include $(top_srcdir)/milena/tests/tests.mk SUBDIRS = skeleton check_PROGRAMS = \ - complex + complex \ + is_facet complex_SOURCES = complex.cc +is_facet_SOURCES = is_facet.cc TESTS = $(check_PROGRAMS) diff --git a/milena/tests/topo/is_facet.cc b/milena/tests/topo/is_facet.cc new file mode 100644 index 0000000..36be66a --- /dev/null +++ b/milena/tests/topo/is_facet.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 +/// \brief Exercise mln::topo::is_facet. + +#include <mln/topo/is_facet.hh> + +#include "tests/core/image/complex_image.hh" + + +int +main() +{ + typedef mln::bin_2complex_image2d I; + typedef mln_psite_(I) P; + + // Neighborhood (n-face to (n+1)-faces relationship) required by + // mln::is_facet. + mln::complex_higher_neighborhood<I::dim, mln_geom_(I)> higher_adj_nbh; + + /* 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 + */ + I ima = make_test_bin_2complex_image2d(); + + // The first triangle (2-face), t0; + P t0(ima.domain(), 2, 0); + mln_assertion(mln::topo::is_facet(ima, t0, higher_adj_nbh)); + + // E2 is not a facet in the initial image. + P e2(ima.domain(), 1, 2); + mln_assertion(!mln::topo::is_facet(ima, e2, higher_adj_nbh)); + + // ``Remove'' T0 and E0 (simple pair collapse). + P e0(ima.domain(), 1, 0); + ima(t0) = false; + ima(e0) = false; + // T0 is no longer a facet. + mln_assertion(!mln::topo::is_facet(ima, t0, higher_adj_nbh)); + // E2 is now a facet. + mln_assertion(mln::topo::is_facet(ima, e2, higher_adj_nbh)); +} -- 1.5.6.5