olena-2.0-134-g8ea985c Add tests for inner_border routines.

* tests/Makefile.am: Add inner_border subdir. * tests/inner_border/Makefile.am, * tests/inner_border/extend.cc, * tests/inner_border/extend_and_fill.cc, * tests/inner_border/extend_and_fill_with_inner_border.cc, * tests/inner_border/fill.cc: New. --- milena/ChangeLog | 12 +++ milena/tests/Makefile.am | 3 +- .../{core/routine => inner_border}/Makefile.am | 17 ++-- .../extend.cc} | 45 ++++++------ .../extend_and_fill.cc} | 51 +++++++------ .../extend_and_fill_with_inner_border.cc} | 79 ++++++++------------ .../k1/immerse_with.cc => inner_border/fill.cc} | 65 ++++++++++------- 7 files changed, 141 insertions(+), 131 deletions(-) copy milena/tests/{core/routine => inner_border}/Makefile.am (71%) copy milena/tests/{world/kn/fill_0_1_faces_internal_border.cc => inner_border/extend.cc} (67%) copy milena/tests/{world/kn/fill_0_1_faces_internal_border.cc => inner_border/extend_and_fill.cc} (62%) copy milena/tests/{world/kn/fill_1_from_2_faces.cc => inner_border/extend_and_fill_with_inner_border.cc} (60%) copy milena/tests/{world/k1/immerse_with.cc => inner_border/fill.cc} (64%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 47a167d..8b0ef22 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,17 @@ 2012-10-25 Guillaume Lazzara <z@lrde.epita.fr> + Add tests for inner_border routines. + + * tests/Makefile.am: Add inner_border subdir. + + * tests/inner_border/Makefile.am, + * tests/inner_border/extend.cc, + * tests/inner_border/extend_and_fill.cc, + * tests/inner_border/extend_and_fill_with_inner_border.cc, + * tests/inner_border/fill.cc: New. + +2012-10-25 Guillaume Lazzara <z@lrde.epita.fr> + Add compute_tree_of_shapes algorithm. * mln/util/hqueue.hh, diff --git a/milena/tests/Makefile.am b/milena/tests/Makefile.am index 3493250..bb6f3b9 100644 --- a/milena/tests/Makefile.am +++ b/milena/tests/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2007, 2008, 2009 EPITA Research and Development +# Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development # Laboratory (LRDE). # # This file is part of Olena. @@ -36,6 +36,7 @@ SUBDIRS = \ geom \ graph \ histo \ + inner_border \ io \ labeling \ linear \ diff --git a/milena/tests/core/routine/Makefile.am b/milena/tests/inner_border/Makefile.am similarity index 71% copy from milena/tests/core/routine/Makefile.am copy to milena/tests/inner_border/Makefile.am index 2640c47..a3443ad 100644 --- a/milena/tests/core/routine/Makefile.am +++ b/milena/tests/inner_border/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE). +# Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE). # # This file is part of Olena. # @@ -17,16 +17,15 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ - duplicate \ - exact \ extend \ - initialize \ - primary + extend_and_fill \ + extend_and_fill_with_inner_border \ + fill -duplicate_SOURCES = duplicate.cc -exact_SOURCES = exact.cc extend_SOURCES = extend.cc -initialize_SOURCES = initialize.cc -primary_SOURCES = primary.cc +extend_and_fill_SOURCES = extend_and_fill.cc +extend_and_fill_with_inner_border_SOURCES = extend_and_fill_with_inner_border.cc +fill_SOURCES = fill.cc + TESTS = $(check_PROGRAMS) diff --git a/milena/tests/world/kn/fill_0_1_faces_internal_border.cc b/milena/tests/inner_border/extend.cc similarity index 67% copy from milena/tests/world/kn/fill_0_1_faces_internal_border.cc copy to milena/tests/inner_border/extend.cc index 7bd186e..2380989 100644 --- a/milena/tests/world/kn/fill_0_1_faces_internal_border.cc +++ b/milena/tests/inner_border/extend.cc @@ -23,37 +23,36 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -/// \file - +#include <mln/inner_border/extend.hh> #include <mln/core/image/image2d.hh> -#include <mln/make/box2d.hh> +#include <mln/data/fill.hh> #include <mln/data/compare.hh> -#include <mln/world/kn/fill_0_1_faces_internal_border.hh> int main() { using namespace mln; - int refvals[5][5] = { - {1, 1, 1, 1, 1 }, - {1, 2, 0, 2, 1 }, - {1, 0, 0, 0, 1 }, - {1, 2, 0, 2, 1 }, - {1, 1, 1, 1, 1 } - }; - image2d<int> ref = make::image(refvals, point2d(-1, -1)); - - int vals[5][5] = { - {0, 0, 0, 0, 0 }, - {0, 2, 0, 2, 0 }, - {0, 0, 0, 0, 0 }, - {0, 2, 0, 2, 0 }, - {0, 0, 0, 0, 0 } - }; - image2d<int> imak1 = make::image(vals, point2d(-1, -1)); + // inner_border == 1 + { + image2d<int> ima(5,5); + box2d b = ima.domain(); + data::fill(ima, 1); + ima = inner_border::extend(ima, 1); + mln_assertion(ima.domain() == box2d(point2d(-1,-1),point2d(5,5))); + mln_piter(image2d<int>) p(b); + for_all(p) + mln_assertion(ima(p) == 1); + } + // inner_border == 2 { - world::kn::fill_0_1_faces_internal_border(imak1, 1); - mln_assertion(ref == imak1); + image2d<int> ima(5,5); + box2d b = ima.domain(); + data::fill(ima, 1); + ima = inner_border::extend(ima, 2); + mln_assertion(ima.domain() == box2d(point2d(-2,-2),point2d(6,6))); + mln_piter(image2d<int>) p(b); + for_all(p) + mln_assertion(ima(p) == 1); } } diff --git a/milena/tests/world/kn/fill_0_1_faces_internal_border.cc b/milena/tests/inner_border/extend_and_fill.cc similarity index 62% copy from milena/tests/world/kn/fill_0_1_faces_internal_border.cc copy to milena/tests/inner_border/extend_and_fill.cc index 7bd186e..c1ebb2e 100644 --- a/milena/tests/world/kn/fill_0_1_faces_internal_border.cc +++ b/milena/tests/inner_border/extend_and_fill.cc @@ -23,37 +23,42 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -/// \file - +#include <mln/inner_border/extend_and_fill.hh> #include <mln/core/image/image2d.hh> -#include <mln/make/box2d.hh> +#include <mln/data/fill.hh> #include <mln/data/compare.hh> -#include <mln/world/kn/fill_0_1_faces_internal_border.hh> int main() { using namespace mln; - int refvals[5][5] = { - {1, 1, 1, 1, 1 }, - {1, 2, 0, 2, 1 }, - {1, 0, 0, 0, 1 }, - {1, 2, 0, 2, 1 }, - {1, 1, 1, 1, 1 } - }; - image2d<int> ref = make::image(refvals, point2d(-1, -1)); - - int vals[5][5] = { - {0, 0, 0, 0, 0 }, - {0, 2, 0, 2, 0 }, - {0, 0, 0, 0, 0 }, - {0, 2, 0, 2, 0 }, - {0, 0, 0, 0, 0 } - }; - image2d<int> imak1 = make::image(vals, point2d(-1, -1)); + // inner_border == 1 + { + image2d<int> ima(5,5); + box2d b = ima.domain(); + data::fill(ima, 1); + ima = inner_border::extend_and_fill(ima, 1, 2); + mln_assertion(ima.domain() == box2d(point2d(-1,-1),point2d(5,5))); + mln_piter(image2d<int>) p(ima.domain()); + for_all(p) + if (b.has(p)) + mln_assertion(ima(p) == 1); + else + mln_assertion(ima(p) == 2); + } + // inner_border == 2 { - world::kn::fill_0_1_faces_internal_border(imak1, 1); - mln_assertion(ref == imak1); + image2d<int> ima(5,5); + box2d b = ima.domain(); + data::fill(ima, 1); + ima = inner_border::extend_and_fill(ima, 2, 2); + mln_assertion(ima.domain() == box2d(point2d(-2,-2),point2d(6,6))); + mln_piter(image2d<int>) p(ima.domain()); + for_all(p) + if (b.has(p)) + mln_assertion(ima(p) == 1); + else + mln_assertion(ima(p) == 2); } } diff --git a/milena/tests/world/kn/fill_1_from_2_faces.cc b/milena/tests/inner_border/extend_and_fill_with_inner_border.cc similarity index 60% copy from milena/tests/world/kn/fill_1_from_2_faces.cc copy to milena/tests/inner_border/extend_and_fill_with_inner_border.cc index bd14ace..b5fb3d0 100644 --- a/milena/tests/world/kn/fill_1_from_2_faces.cc +++ b/milena/tests/inner_border/extend_and_fill_with_inner_border.cc @@ -23,65 +23,48 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -/// \file - +#include <mln/inner_border/extend_and_fill_with_inner_border.hh> #include <mln/core/image/image2d.hh> -#include <mln/make/box2d.hh> +#include <mln/data/fill.hh> #include <mln/data/compare.hh> #include <mln/accu/math/sum.hh> -#include <mln/world/kn/fill_1_from_2_faces.hh> -#include <mln/border/fill.hh> - - -namespace mln -{ - - struct sum_t : Function_vv2v<sum_t> - { - typedef int result; - - int operator()(const int& v1, const int& v2) const - { - return v1 + v2; - } - - }; - -} - int main() { using namespace mln; - int refvals[5][5] = { - {1, 3, 1, 3, 1}, - {3, 3, 6, 3, 3}, - {1, 6, 1, 6, 1}, - {3, 3, 6, 3, 3}, - {1, 3, 1, 3, 1} - }; - image2d<int> ref = make::image(refvals, point2d(-1, -1)); - - int vals[5][5] = { - {1, 0, 1, 0, 1 }, - {0, 3, 0, 3, 0 }, - {1, 0, 1, 0, 1 }, - {0, 3, 0, 3, 0 }, - {1, 0, 1, 0, 1 } - }; - image2d<int> imakn = make::image(vals, point2d(-1, -1)); - - /// Make sure the border is set to 0 to get deterministic results. - border::fill(imakn, 0); - - - // Overload with accumulator + // inner_border == 1 { + image2d<int> ima(5,5); + box2d b = ima.domain(); + data::fill(ima, 1); accu::math::sum<int> accu; - world::kn::fill_1_from_2_faces(imakn, accu); - mln_assertion(ref == imakn); + ima = inner_border::extend_and_fill_with_inner_border(ima, 1, accu, 2); + + mln_assertion(ima.domain() == box2d(point2d(-1,-1),point2d(5,5))); + mln_piter(image2d<int>) p(ima.domain()); + for_all(p) + if (b.has(p)) + mln_assertion(ima(p) == 1); + else + mln_assertion(ima(p) == 24); } + // inner_border == 2 + { + image2d<int> ima(5,5); + box2d b = ima.domain(); + data::fill(ima, 1); + accu::math::sum<int> accu; + ima = inner_border::extend_and_fill_with_inner_border(ima, 2, accu, 2); + + mln_assertion(ima.domain() == box2d(point2d(-2,-2),point2d(6,6))); + mln_piter(image2d<int>) p(ima.domain()); + for_all(p) + if (b.has(p)) + mln_assertion(ima(p) == 1); + else + mln_assertion(ima(p) == 24); + } } diff --git a/milena/tests/world/k1/immerse_with.cc b/milena/tests/inner_border/fill.cc similarity index 64% copy from milena/tests/world/k1/immerse_with.cc copy to milena/tests/inner_border/fill.cc index 3b7e8fc..3bc2443 100644 --- a/milena/tests/world/k1/immerse_with.cc +++ b/milena/tests/inner_border/fill.cc @@ -23,41 +23,52 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -/// \file - +#include <mln/inner_border/fill.hh> #include <mln/core/image/image2d.hh> -#include <mln/world/k1/immerse_with.hh> +#include <mln/data/fill.hh> #include <mln/data/compare.hh> -#include <mln/border/fill.hh> -#include <mln/fun/vv2v/max.hh> -#include <mln/fun/vvvv2v/max.hh> -int main() +int +main (void) { using namespace mln; - int ivals[][2] = { - {1, 2}, - {3, 4} - }; - image2d<int> ima = make::image(ivals); - border::fill(ima, 0); // Make sure there is not border effect. - - int fvals[][5] = { - {1, 1, 2, 2, 2}, - {1, 1, 2, 2, 2}, - {3, 3, 4, 4, 4}, - {3, 3, 4, 4, 4}, - {3, 3, 4, 4, 4} - }; - image2d<int> ref = make::image(fvals, point2d(-1,-1)); + // inner_border == 1 + { + int refvals[5][5] = { + {2, 2, 2, 2, 2}, + {2, 1, 1, 1, 2}, + {2, 1, 1, 1, 2}, + {2, 1, 1, 1, 2}, + {2, 2, 2, 2, 2} + }; + image2d<int> ref = make::image(refvals); + + image2d<int> ima(5,5); + data::fill(ima, 1); + inner_border::fill(ima, 2); + + mln_assertion(ima == ref); + } + + // inner_border == 2 { - image2d<long> - immersed = world::k1::immerse_with(ima, long(), - fun::vv2v::max<long>(), - fun::vvvv2v::max<long>()); - mln_assertion(immersed == ref); + int refvals[5][5] = { + {2, 2, 2, 2, 2}, + {2, 2, 2, 2, 2}, + {2, 2, 1, 2, 2}, + {2, 2, 2, 2, 2}, + {2, 2, 2, 2, 2} + }; + image2d<int> ref = make::image(refvals); + + image2d<int> ima(5,5); + data::fill(ima, 1); + + inner_border::fill(ima, 2, 2); + + mln_assertion(ima == ref); } } -- 1.7.2.5
participants (1)
-
Guillaume Lazzara