* mln/world/kn/border/adjust_duplicate_2_faces.hh,
* mln/world/kn/border/duplicate_2_faces.hh,
* tests/world/kn/border/Makefile.am,
* tests/world/kn/border/adjust_duplicate_2_faces.cc,
* tests/world/kn/border/duplicate_2_faces.cc: New.
* tests/world/kn/Makefile.am: New subdir.
---
milena/ChangeLog | 12 ++
.../adjust_duplicate_2_faces.hh} | 50 ++++----
milena/mln/world/kn/border/duplicate_2_faces.hh | 144 ++++++++++++++++++++
milena/tests/world/kn/Makefile.am | 4 +-
milena/tests/world/kn/{accu => border}/Makefile.am | 10 +-
.../adjust_duplicate_2_faces.cc} | 55 ++++----
.../border/duplicate_2_faces.cc} | 53 ++++----
7 files changed, 244 insertions(+), 84 deletions(-)
copy milena/mln/world/kn/{fill_0_1_faces_internal_border.hh =>
border/adjust_duplicate_2_faces.hh} (61%)
create mode 100644 milena/mln/world/kn/border/duplicate_2_faces.hh
copy milena/tests/world/kn/{accu => border}/Makefile.am (80%)
copy milena/tests/world/kn/{fill_0_from_1_faces.cc =>
border/adjust_duplicate_2_faces.cc} (63%)
copy milena/tests/world/{k1/immerse_with.cc => kn/border/duplicate_2_faces.cc} (66%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0095a12..574132f 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2012-10-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add kn::border routines working on 2-faces.
+
+ * mln/world/kn/border/adjust_duplicate_2_faces.hh,
+ * mln/world/kn/border/duplicate_2_faces.hh,
+ * tests/world/kn/border/Makefile.am,
+ * tests/world/kn/border/adjust_duplicate_2_faces.cc,
+ * tests/world/kn/border/duplicate_2_faces.cc: New.
+
+ * tests/world/kn/Makefile.am: New subdir.
+
+2012-10-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add new overloads of fill routines in k1.
* mln/world/k1/fill_0_from_1_faces.hh,
diff --git a/milena/mln/world/kn/fill_0_1_faces_internal_border.hh
b/milena/mln/world/kn/border/adjust_duplicate_2_faces.hh
similarity index 61%
copy from milena/mln/world/kn/fill_0_1_faces_internal_border.hh
copy to milena/mln/world/kn/border/adjust_duplicate_2_faces.hh
index 915a69a..ca900f6 100644
--- a/milena/mln/world/kn/fill_0_1_faces_internal_border.hh
+++ b/milena/mln/world/kn/border/adjust_duplicate_2_faces.hh
@@ -25,12 +25,14 @@
/// \file
///
-/// \brief Fill 0 and 1 faces border with a value in a KN 2D image.
+/// \brief Adjust border size and duplicate 2 faces in Kn 2D images
+/// borders.
-#ifndef MLN_WORLD_KN_FILL_0_1_FACES_INTERNAL_BORDER_HH
-# define MLN_WORLD_KN_FILL_0_1_FACES_INTERNAL_BORDER_HH
+#ifndef MLN_WORLD_KN_BORDER_ADJUST_DUPLICATE_2_FACES_HH
+# define MLN_WORLD_KN_BORDER_ADJUST_DUPLICATE_2_FACES_HH
-# include <mln/inner_border/fill.hh>
+# include <mln/border/adjust.hh>
+# include <mln/world/kn/border/duplicate_2_faces.hh>
namespace mln
@@ -42,52 +44,52 @@ namespace mln
namespace kn
{
- /*! \brief Fill 0 and 1 faces border with a value in a KN 2D image.
+ namespace border
+ {
- \param[in,out] inout A 2D image immersed in KN.
- \param[in] v The border value.
+ /*! \brief Adjust border size and duplicate 2 faces in Kn 2D
+ * images borders.
- Example with \p v=1:
+ \param[in,out] inout A 2D image immersed in KN.
+ \param[in] min_thickness The minimum border thickness of \p
+ inout.
- . - . - . 1 1 1 1 1
- | o | o | 1 o | o 1
- . - . - . -> 1 - . - 1
- | o | o | 1 o | o 1
- . - . - . 1 1 1 1 1
+ if \p inout has a border thickness higher than \p
+ min_thickness, the border size is not adjusted.
*/
template <typename I>
- void fill_0_1_faces_internal_border(Image<I>& inout,
- const mln_value(I)& v);
+ void adjust_duplicate_2_faces(Image<I>& inout, unsigned min_thickness);
# ifndef MLN_INCLUDE_ONLY
- // Facade
-
-
template <typename I>
- void fill_0_1_faces_internal_border(Image<I>& inout_,
- const mln_value(I)& v)
+ void adjust_duplicate_2_faces(Image<I>& inout_, unsigned min_thickness)
{
- trace::entering("mln::world::kn::fill_0_1_faces_internal_border");
+ trace::entering("mln::world::kn::adjust_duplicate_2_faces");
mln_precondition(exact(inout_).is_valid());
+ mln_precondition(min_thickness > 0);
I& inout = exact(inout_);
- inner_border::fill(inout, v);
+ mln::border::adjust(inout, min_thickness);
+ kn::border::duplicate_2_faces(inout);
- trace::exiting("mln::world::kn::fill_0_1_faces_internal_border");
+ trace::exiting("mln::world::kn::adjust_duplicate_2_faces");
}
+
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::world::kn::border
+
} // end of namespace mln::world::kn
} // end of namespace mln::world
} // end of namespace mln
-#endif // ! MLN_WORLD_KN_FILL_0_1_FACES_INTERNAL_BORDER_HH
+#endif // ! MLN_WORLD_KN_BORDER_ADJUST_DUPLICATE_2_FACES_HH
diff --git a/milena/mln/world/kn/border/duplicate_2_faces.hh
b/milena/mln/world/kn/border/duplicate_2_faces.hh
new file mode 100644
index 0000000..2d1c89f
--- /dev/null
+++ b/milena/mln/world/kn/border/duplicate_2_faces.hh
@@ -0,0 +1,144 @@
+// Copyright (C) 2012 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 Duplicate 2 faces in KN 2D images borders.
+
+#ifndef MLN_WORLD_KN_BORDER_DUPLICATE_2_FACES_HH
+# define MLN_WORLD_KN_BORDER_DUPLICATE_2_FACES_HH
+
+# include <mln/core/concept/image.hh>
+# include <mln/world/kn/is_2_face.hh>
+# include <mln/geom/min_row.hh>
+# include <mln/geom/min_col.hh>
+# include <mln/geom/max_row.hh>
+# include <mln/geom/max_col.hh>
+
+
+namespace mln
+{
+
+ namespace world
+ {
+
+ namespace kn
+ {
+
+ namespace border
+ {
+
+ /*! \brief Duplicate 2 faces in Kn 2D images borders.
+
+ \param[in,out] inout A 2D image immersed in KN.
+
+ */
+ template <typename I>
+ void duplicate_2_faces(Image<I>& inout);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ void duplicate_2_faces(Image<I>& inout_)
+ {
+ trace::entering("mln::world::kn::duplicate_2_faces");
+
+ mln_precondition(exact(inout_).is_valid());
+ mln_precondition(exact(inout_).border() > 0);
+ I& inout = exact(inout_);
+
+ def::coord
+ min_row_1 = geom::min_row(inout) + 1,
+ max_row_1 = geom::max_row(inout) - 1,
+ min_col_1 = geom::min_col(inout) + 1,
+ max_col_1 = geom::max_col(inout) - 1;
+
+ /* Fill horizontal border
+
+ a b
+ . - . - .
+ | a | b |
+ . - . - .
+ a b
+ */
+ for (def::coord col = min_col_1; col <= max_col_1; ++col)
+ {
+ if (is_2_face(min_row_1, col))
+ {
+ // First row
+ inout.at_(min_row_1 - 2, col) = inout.at_(min_row_1, col);
+ // Last row
+ inout.at_(max_row_1 + 2, col) = inout.at_(max_row_1, col);
+ }
+ }
+
+ /* Fill vertical border
+
+
+ . - . - .
+ a | a | b | b
+ . - . - .
+
+ */
+ for (def::coord row = min_row_1; row <= max_row_1; ++row)
+ if (is_2_face(row, min_col_1))
+ {
+ // First col
+ inout.at_(row, min_col_1 - 2) = inout.at_(row, min_col_1);
+ // Last col
+ inout.at_(row, max_col_1 + 2) = inout.at_(row, max_col_1);
+ }
+
+ /* Handle the four corners
+
+ a | | b
+ - . - . - . -
+ | a | b |
+ - . - . - . -
+ a | | b
+ */
+ inout.at_(min_row_1 - 2, min_col_1 - 2) = inout.at_(min_row_1, min_col_1);
+ inout.at_(min_row_1 - 2, max_col_1 + 2) = inout.at_(min_row_1, max_col_1);
+ inout.at_(max_row_1 + 2, min_col_1 - 2) = inout.at_(max_row_1, min_col_1);
+ inout.at_(max_row_1 + 2, max_col_1 + 2) = inout.at_(max_row_1, max_col_1);
+
+ trace::exiting("mln::world::kn::duplicate_2_faces");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::world::kn::border
+
+ } // end of namespace mln::world::kn
+
+ } // end of namespace mln::world
+
+} // end of namespace mln
+
+#endif // ! MLN_WORLD_KN_BORDER_DUPLICATE_2_FACES_HH
diff --git a/milena/tests/world/kn/Makefile.am b/milena/tests/world/kn/Makefile.am
index 5147ad9..84b0b2f 100644
--- a/milena/tests/world/kn/Makefile.am
+++ b/milena/tests/world/kn/Makefile.am
@@ -16,7 +16,9 @@
include $(top_srcdir)/milena/tests/tests.mk
-SUBDIRS = accu
+SUBDIRS = \
+ accu \
+ border
check_PROGRAMS = \
fill_0_1_faces_internal_border \
diff --git a/milena/tests/world/kn/accu/Makefile.am
b/milena/tests/world/kn/border/Makefile.am
similarity index 80%
copy from milena/tests/world/kn/accu/Makefile.am
copy to milena/tests/world/kn/border/Makefile.am
index 98651eb..e8a2666 100644
--- a/milena/tests/world/kn/accu/Makefile.am
+++ b/milena/tests/world/kn/border/Makefile.am
@@ -17,12 +17,10 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
- max_interval \
- median_h_interval \
- min_interval
+ adjust_duplicate_2_faces \
+ duplicate_2_faces
-max_interval_SOURCES = max_interval.cc
-median_h_interval_SOURCES = median_h_interval.cc
-min_interval_SOURCES = min_interval.cc
+adjust_duplicate_2_faces_SOURCES = adjust_duplicate_2_faces.cc
+duplicate_2_faces_SOURCES = duplicate_2_faces.cc
TESTS = $(check_PROGRAMS)
diff --git a/milena/tests/world/kn/fill_0_from_1_faces.cc
b/milena/tests/world/kn/border/adjust_duplicate_2_faces.cc
similarity index 63%
copy from milena/tests/world/kn/fill_0_from_1_faces.cc
copy to milena/tests/world/kn/border/adjust_duplicate_2_faces.cc
index 00f3c01..157e52e 100644
--- a/milena/tests/world/kn/fill_0_from_1_faces.cc
+++ b/milena/tests/world/kn/border/adjust_duplicate_2_faces.cc
@@ -26,44 +26,43 @@
/// \file
#include <mln/core/image/image2d.hh>
-#include <mln/make/box2d.hh>
-#include <mln/data/compare.hh>
-#include <mln/accu/math/sum.hh>
-#include <mln/world/kn/fill_0_from_1_faces.hh>
#include <mln/border/fill.hh>
-
+#include <mln/world/kn/is_2_face.hh>
+#include <mln/world/kn/border/adjust_duplicate_2_faces.hh>
int main()
{
using namespace mln;
- int refvals[5][5] = {
- {2, 1, 3, 1, 2},
- {1, 0, 1, 0, 1},
- {3, 1, 4, 1, 3},
- {1, 0, 1, 0, 1},
- {2, 1, 3, 1, 2}
- };
- image2d<int> ref = make::image(refvals, point2d(-1, -1));
+ border::thickness = 1;
- int vals[5][5] = {
- {0, 1, 0, 1, 0 },
- {1, 0, 1, 0, 1 },
- {0, 1, 0, 1, 0 },
- {1, 0, 1, 0, 1 },
- {0, 1, 0, 1, 0 }
+ int refvals[][7] = {
+ {2, 9, 2, 9, 3, 9, 3},
+ {9, 0, 1, 0, 1, 0, 9},
+ {2, 1, 2, 1, 3, 1, 3},
+ {9, 0, 1, 0, 1, 0, 9},
+ {4, 1, 4, 1, 5, 1, 5},
+ {9, 0, 1, 0, 1, 0, 9},
+ {4, 9, 4, 9, 5, 9, 5}
};
- image2d<int> imak1 = make::image(vals, point2d(-1, -1));
+ image2d<int> ref = make::image(refvals, point2d(-2,-2));
- /// Make sure the border is set to 0 to get deterministic results.
- border::fill(imak1, 0);
+ int vals[][5] = {
+ {0, 1, 0, 1, 0},
+ {1, 2, 1, 3, 1},
+ {0, 1, 0, 1, 0},
+ {1, 4, 1, 5, 1},
+ {0, 1, 0, 1, 0}
+ };
+ image2d<int> ima = make::image(vals, point2d(-1,-1));
+
+ world::kn::border::adjust_duplicate_2_faces(ima, 2);
- // Overload with accumulator
- {
- accu::math::sum<int> accu;
- world::kn::fill_0_from_1_faces(imak1, accu);
- mln_assertion(ref == imak1);
- }
+ mln_piter(image2d<int>) p(ref.domain());
+ for_all(p)
+ if (world::kn::is_2_face(p))
+ mln_assertion(ima(p) == ref(p));
+ mln_assertion(ima.border() == 2);
}
diff --git a/milena/tests/world/k1/immerse_with.cc
b/milena/tests/world/kn/border/duplicate_2_faces.cc
similarity index 66%
copy from milena/tests/world/k1/immerse_with.cc
copy to milena/tests/world/kn/border/duplicate_2_faces.cc
index 3b7e8fc..3f91c01 100644
--- a/milena/tests/world/k1/immerse_with.cc
+++ b/milena/tests/world/kn/border/duplicate_2_faces.cc
@@ -26,38 +26,41 @@
/// \file
#include <mln/core/image/image2d.hh>
-#include <mln/world/k1/immerse_with.hh>
-#include <mln/data/compare.hh>
#include <mln/border/fill.hh>
-#include <mln/fun/vv2v/max.hh>
-#include <mln/fun/vvvv2v/max.hh>
+#include <mln/world/kn/border/duplicate_2_faces.hh>
+
int main()
{
using namespace mln;
- int ivals[][2] = {
- {1, 2},
- {3, 4}
+ border::thickness = 1;
+
+ int refvals[][7] = {
+ {2, 9, 2, 9, 3, 9, 3},
+ {9, 0, 1, 0, 1, 0, 9},
+ {2, 1, 2, 1, 3, 1, 3},
+ {9, 0, 1, 0, 1, 0, 9},
+ {4, 1, 4, 1, 5, 1, 5},
+ {9, 0, 1, 0, 1, 0, 9},
+ {4, 9, 4, 9, 5, 9, 5}
};
- 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(refvals, point2d(-2,-2));
+
+
+ int vals[][5] = {
+ {0, 1, 0, 1, 0},
+ {1, 2, 1, 3, 1},
+ {0, 1, 0, 1, 0},
+ {1, 4, 1, 5, 1},
+ {0, 1, 0, 1, 0}
};
- image2d<int> ref = make::image(fvals, point2d(-1,-1));
+ image2d<int> ima = make::image(vals, point2d(-1,-1));
- {
- image2d<long>
- immersed = world::k1::immerse_with(ima, long(),
- fun::vv2v::max<long>(),
- fun::vvvv2v::max<long>());
- mln_assertion(immersed == ref);
- }
+ border::fill(ima, 9);
+ world::kn::border::duplicate_2_faces(ima);
-}
+ mln_piter(image2d<int>) p(ref.domain());
+ for_all(p)
+ mln_assertion(ima(p) == ref(p));
+ }
--
1.7.2.5