* mln/world/kn/fill_2_from_1_faces.hh: Rely on
fill_2_from_aux_1_faces.
* tests/world/kn/Makefile.am: New target.
* mln/world/kn/fill_2_from_aux_1_faces.hh,
* tests/world/kn/fill_2_from_aux_1_faces.cc: New.
---
milena/ChangeLog | 12 +++
milena/mln/world/kn/fill_2_from_1_faces.hh | 46 +++---------
..._from_1_faces.hh => fill_2_from_aux_1_faces.hh} | 78 ++++++++++++--------
milena/tests/world/kn/Makefile.am | 2 +
..._from_1_faces.cc => fill_2_from_aux_1_faces.cc} | 43 +++++------
5 files changed, 90 insertions(+), 91 deletions(-)
copy milena/mln/world/kn/{fill_2_from_1_faces.hh => fill_2_from_aux_1_faces.hh} (52%)
copy milena/tests/world/kn/{fill_2_from_1_faces.cc => fill_2_from_aux_1_faces.cc}
(74%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 63e9d85..fe23428 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2012-11-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add world::kn::fill_2_from_aux_1_faces.hh.
+
+ * mln/world/kn/fill_2_from_1_faces.hh: Rely on
+ fill_2_from_aux_1_faces.
+
+ * tests/world/kn/Makefile.am: New target.
+
+ * mln/world/kn/fill_2_from_aux_1_faces.hh,
+ * tests/world/kn/fill_2_from_aux_1_faces.cc: New.
+
+2012-11-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Handle border value with auxiliary data images.
* mln/world/kn/border/fill_1_from_2_faces.hh,
diff --git a/milena/mln/world/kn/fill_2_from_1_faces.hh
b/milena/mln/world/kn/fill_2_from_1_faces.hh
index c38f69f..afbb711 100644
--- a/milena/mln/world/kn/fill_2_from_1_faces.hh
+++ b/milena/mln/world/kn/fill_2_from_1_faces.hh
@@ -30,9 +30,9 @@
#ifndef MLN_WORLD_KN_FILL_2_FROM_1_FACES_HH
# define MLN_WORLD_KN_FILL_2_FROM_1_FACES_HH
-# include <mln/core/alias/point2d.hh>
-# include <mln/world/kn/is_2_face.hh>
-# include <mln/world/kn/safe_cast.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/world/kn/fill_2_from_aux_1_faces.hh>
namespace mln
{
@@ -59,7 +59,7 @@ namespace mln
*/
template <typename I, typename F>
- void fill_2_from_1_faces(Image<I>& inout, Function_vvvv2v<F>&
f);
+ void fill_2_from_1_faces(Image<I>& inout, const
Function_vvvv2v<F>& f);
/// \overload
template <typename I, typename A>
@@ -73,51 +73,25 @@ namespace mln
template <typename I, typename F>
- void fill_2_from_1_faces(Image<I>& inout_, Function_vvvv2v<F>&
f_)
+ void fill_2_from_1_faces(Image<I>& inout, const
Function_vvvv2v<F>& f)
{
trace::entering("mln::world::kn::fill_2_from_1_faces");
- mln_precondition(exact(inout_).is_valid());
- I& inout = exact(inout_);
- F& f = exact(f_);
+ mln_precondition(exact(inout).is_valid());
- mln_piter(I) p(inout.domain());
- for_all(p)
- if (kn::is_2_face(p))
- inout(p) = safe_cast(f(safe_cast(inout(p + up)),
- safe_cast(inout(p + left)),
- safe_cast(inout(p + right)),
- safe_cast(inout(p + down))));
+ fill_2_from_aux_1_faces(inout, inout, f);
trace::exiting("mln::world::kn::fill_2_from_1_faces");
}
template <typename I, typename A>
- void fill_2_from_1_faces(Image<I>& inout_, const
Accumulator<A>& accu_)
+ void fill_2_from_1_faces(Image<I>& inout, const Accumulator<A>&
accu)
{
trace::entering("mln::world::kn::fill_2_from_1_faces");
+ mln_precondition(exact(inout).is_valid());
- I& inout = exact(inout_);
- mln_precondition(inout.is_valid());
-
- A accu = exact(accu_);
- typedef mln_argument(A) arg;
- mln_piter(I) p(inout.domain());
- for_all(p)
- if (kn::is_2_face(p))
- {
- accu.init();
- if (inout.domain().has(p + up))
- accu.take(safe_cast_to<arg>(inout(p + up)));
- if (inout.domain().has(p + left))
- accu.take(safe_cast_to<arg>(inout(p + left)));
- if (inout.domain().has(p + right))
- accu.take(safe_cast_to<arg>(inout(p + right)));
- if (inout.domain().has(p + down))
- accu.take(safe_cast_to<arg>(inout(p + down)));
- inout(p) = safe_cast(accu.to_result());
- }
+ fill_2_from_aux_1_faces(inout, inout, accu);
trace::exiting("mln::world::kn::fill_2_from_1_faces");
}
diff --git a/milena/mln/world/kn/fill_2_from_1_faces.hh
b/milena/mln/world/kn/fill_2_from_aux_1_faces.hh
similarity index 52%
copy from milena/mln/world/kn/fill_2_from_1_faces.hh
copy to milena/mln/world/kn/fill_2_from_aux_1_faces.hh
index c38f69f..18c32f9 100644
--- a/milena/mln/world/kn/fill_2_from_1_faces.hh
+++ b/milena/mln/world/kn/fill_2_from_aux_1_faces.hh
@@ -25,14 +25,14 @@
/// \file
///
-/// \brief Fill 2 faces in a KN 2D image using its 1 faces.
+/// \brief Fill 0 faces in a KN 2D image using 2-faces values from an
+/// auxiliary image.
-#ifndef MLN_WORLD_KN_FILL_2_FROM_1_FACES_HH
-# define MLN_WORLD_KN_FILL_2_FROM_1_FACES_HH
+#ifndef MLN_WORLD_KN_FILL_2_FROM_AUX_1_FACES_HH
+# define MLN_WORLD_KN_FILL_2_FROM_AUX_1_FACES_HH
# include <mln/core/alias/point2d.hh>
# include <mln/world/kn/is_2_face.hh>
-# include <mln/world/kn/safe_cast.hh>
namespace mln
{
@@ -43,10 +43,16 @@ namespace mln
namespace kn
{
- /*! \brief Fill 0 faces in a KN 2D image using its 2 faces.
+ /*! \brief Fill 0 faces in a KN 2D image using 2-faces values
+ from an auxiliary image.
\param[in,out] inout A 2D image immersed in KN.
- \param[in,out] f A functor computing a result from four values.
+ \param[in] aux An auxiliary image with the same domain as \p
+ inout.
+ \param[in] f A functor computing a result from four values.
+
+ Warning: This function considers that 1-faces values in \p aux
+ borders are initialized.
This function use the following neighborhood:
@@ -58,12 +64,14 @@ namespace mln
*/
- template <typename I, typename F>
- void fill_2_from_1_faces(Image<I>& inout, Function_vvvv2v<F>&
f);
+ template <typename I, typename J, typename F>
+ void fill_2_from_aux_1_faces(Image<I>& inout, const Image<J>&
aux,
+ const Function_vvvv2v<F>& f);
/// \overload
- template <typename I, typename A>
- void fill_2_from_1_faces(Image<I>& inout, const Accumulator<A>&
accu);
+ template <typename I, typename J, typename A>
+ void fill_2_from_aux_1_faces(Image<I>& inout, const Image<J>&
aux,
+ const Accumulator<A>& accu);
# ifndef MLN_INCLUDE_ONLY
@@ -72,54 +80,60 @@ namespace mln
// Facade
- template <typename I, typename F>
- void fill_2_from_1_faces(Image<I>& inout_, Function_vvvv2v<F>&
f_)
+ template <typename I, typename J, typename F>
+ void fill_2_from_aux_1_faces(Image<I>& inout_, const Image<J>&
aux_,
+ const Function_vvvv2v<F>& f_)
{
- trace::entering("mln::world::kn::fill_2_from_1_faces");
+ trace::entering("mln::world::kn::fill_2_from_aux_1_faces");
mln_precondition(exact(inout_).is_valid());
+ mln_precondition(exact(inout_).domain() <= exact(aux_).domain());
I& inout = exact(inout_);
- F& f = exact(f_);
+ const J& aux = exact(aux_);
+ const F& f = exact(f_);
+
+ // FIXME: we cannot check if 1-faces in border are initialized
+ // in aux image.
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_2_face(p))
- inout(p) = safe_cast(f(safe_cast(inout(p + up)),
- safe_cast(inout(p + left)),
- safe_cast(inout(p + right)),
- safe_cast(inout(p + down))));
+ inout(p) = f(aux(p + up), aux(p + left),
+ aux(p + right), aux(p + down));
- trace::exiting("mln::world::kn::fill_2_from_1_faces");
+ trace::exiting("mln::world::kn::fill_2_from_aux_1_faces");
}
- template <typename I, typename A>
- void fill_2_from_1_faces(Image<I>& inout_, const
Accumulator<A>& accu_)
+ template <typename I, typename J, typename A>
+ void fill_2_from_aux_1_faces(Image<I>& inout_, const Image<J>&
aux_,
+ const Accumulator<A>& accu_)
{
- trace::entering("mln::world::kn::fill_2_from_1_faces");
+ trace::entering("mln::world::kn::fill_2_from_aux_1_faces");
+ mln_precondition(exact(inout_).is_valid());
+ mln_precondition(exact(inout_).domain() <= exact(aux_).domain());
I& inout = exact(inout_);
- mln_precondition(inout.is_valid());
+ const J& aux = exact(aux_);
- A accu = exact(accu_);
- typedef mln_argument(A) arg;
+ A accu(exact(accu_));
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_2_face(p))
{
accu.init();
if (inout.domain().has(p + up))
- accu.take(safe_cast_to<arg>(inout(p + up)));
+ accu.take(aux(p + up));
if (inout.domain().has(p + left))
- accu.take(safe_cast_to<arg>(inout(p + left)));
+ accu.take(aux(p + left));
if (inout.domain().has(p + right))
- accu.take(safe_cast_to<arg>(inout(p + right)));
+ accu.take(aux(p + right));
if (inout.domain().has(p + down))
- accu.take(safe_cast_to<arg>(inout(p + down)));
- inout(p) = safe_cast(accu.to_result());
+ accu.take(aux(p + down));
+ inout(p) = accu.to_result();
}
- trace::exiting("mln::world::kn::fill_2_from_1_faces");
+ trace::exiting("mln::world::kn::fill_2_from_aux_1_faces");
}
@@ -131,4 +145,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_WORLD_KN_FILL_2_FROM_1_FACES_HH
+#endif // ! MLN_WORLD_KN_FILL_2_FROM_AUX_1_FACES_HH
diff --git a/milena/tests/world/kn/Makefile.am b/milena/tests/world/kn/Makefile.am
index 9a52eb6..cc216c7 100644
--- a/milena/tests/world/kn/Makefile.am
+++ b/milena/tests/world/kn/Makefile.am
@@ -28,6 +28,7 @@ check_PROGRAMS = \
fill_1_from_2_faces \
fill_1_from_aux_2_faces \
fill_2_from_1_faces \
+ fill_2_from_aux_1_faces \
holes \
immerse \
immerse_with_inner_border \
@@ -49,6 +50,7 @@ fill_0_from_2_faces_SOURCES = fill_0_from_2_faces.cc
fill_1_from_2_faces_SOURCES = fill_1_from_2_faces.cc
fill_1_from_aux_2_faces_SOURCES = fill_1_from_aux_2_faces.cc
fill_2_from_1_faces_SOURCES = fill_2_from_1_faces.cc
+fill_2_from_aux_1_faces_SOURCES = fill_2_from_aux_1_faces.cc
holes_SOURCES = holes.cc
immerse_SOURCES = immerse.cc
immerse_with_inner_border_SOURCES = immerse_with_inner_border.cc
diff --git a/milena/tests/world/kn/fill_2_from_1_faces.cc
b/milena/tests/world/kn/fill_2_from_aux_1_faces.cc
similarity index 74%
copy from milena/tests/world/kn/fill_2_from_1_faces.cc
copy to milena/tests/world/kn/fill_2_from_aux_1_faces.cc
index d8a3bef..29b2121 100644
--- a/milena/tests/world/kn/fill_2_from_1_faces.cc
+++ b/milena/tests/world/kn/fill_2_from_aux_1_faces.cc
@@ -26,51 +26,48 @@
/// \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/fun/vvvv2v/sum.hh>
-#include <mln/world/kn/fill_2_from_1_faces.hh>
-#include <mln/border/fill.hh>
-
+#include <mln/world/kn/fill_2_from_aux_1_faces.hh>
int main()
{
using namespace mln;
- int refvals[5][5] = {
- {0, 1, 0, 1, 0},
- {1, 4, 1, 4, 1},
- {0, 1, 0, 1, 0},
- {1, 4, 1, 4, 1},
- {0, 1, 0, 1, 0}
+ int auxvals[5][5] = {
+ {0, 1, 0, 4, 0 },
+ {1, 0, 1, 0, 4 },
+ {0, 4, 0, 1, 0 },
+ {4, 0, 4, 0, 1 },
+ {0, 4, 0, 1, 0 }
};
- image2d<int> ref = make::image(refvals, point2d(-1, -1));
+ image2d<int> aux = make::image(auxvals, point2d(-1, -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 }
- };
- image2d<int> imakn = make::image(vals, point2d(-1, -1));
+ image2d<int> imakn(aux.domain());
- /// Make sure the border is set to 0 to get deterministic results.
- border::fill(imakn, 0);
+ int refvals[5][5] = {
+ {0, 0, 0, 0, 0},
+ {0, 7, 0, 10, 0},
+ {0, 0, 0, 0, 0},
+ {0, 16, 0, 7, 0},
+ {0, 0, 0, 0, 0}
+ };
+ image2d<int> ref = make::image(refvals, point2d(-1, -1));
// Overload with accumulator
{
accu::math::sum<int> accu;
- world::kn::fill_2_from_1_faces(imakn, accu);
+ world::kn::fill_2_from_aux_1_faces(imakn, aux, accu);
mln_assertion(ref == imakn);
}
// Overload with function
{
fun::vvvv2v::sum<int> f;
- world::kn::fill_2_from_1_faces(imakn, f);
+ world::kn::fill_2_from_aux_1_faces(imakn, aux, f);
+
mln_assertion(ref == imakn);
}
--
1.7.2.5