https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Revamp directional convolution (was convolve_line).
* mln/core/concept/gdpoint.hh: Handle "Gdpoint * Scalar".
(set_binary_): New specialization.
(operator*): New overload.
(todo): Remove.
* mln/linear/log.hh: Update.
* mln/linear/sobel.hh: Update doc style.
* mln/linear/convolve.hh (pre): Fix.
* mln/linear/line_convolve.hh: Rename as...
* mln/linear/convolve_directional.hh: ...this and update.
* mln/linear/all.hh: Update.
* tests/linear/log.cc: Update.
* tests/linear/line_convolve.cc: Rename as...
* tests/linear/convolve_directional.cc: ...this.
* tests/linear/Makefile.am: Update.
* mln/make/w_window_line.hh: Rename as...
* mln/make/w_window_directional.hh: ...this and update.
* mln/make/all.hh: Update.
* tests/make/w_window_directional.cc: New.
* tests/make/Makefile.am: Update.
mln/core/concept/gdpoint.hh | 31 ++++++++++---
mln/linear/all.hh | 19 +++-----
mln/linear/convolve.hh | 2
mln/linear/convolve_directional.hh | 57 +++++++++++++-----------
mln/linear/log.hh | 83 +++++++++++++++++++++--------------
mln/linear/sobel.hh | 15 ++----
mln/make/all.hh | 10 ++--
mln/make/w_window_directional.hh | 56 ++++++++++++-----------
tests/linear/Makefile.am | 4 -
tests/linear/convolve_directional.cc | 17 +++----
tests/linear/log.cc | 11 ++--
tests/make/Makefile.am | 4 +
tests/make/w_window_directional.cc | 47 +++++++++++++++++++
13 files changed, 226 insertions(+), 130 deletions(-)
Index: tests/linear/log.cc
--- tests/linear/log.cc (revision 2798)
+++ tests/linear/log.cc (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 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
@@ -52,18 +53,16 @@
border::thickness = 2;
- image2d<int_u8> lena;
+ image2d<int_u8> lena, out;
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
- image2d<int> tmp(lena.domain());
- linear::LoG_5x5(lena, tmp);
+ image2d<float> tmp = linear::LoG_5x5(lena);
{
- int min, max;
+ float min, max;
estim::min_max(tmp, min, max);
mln_assertion(min == -929 && max == 1260);
}
- image2d<int_u8> out(lena.domain());
level::stretch(tmp, out);
io::pgm::save(out, "out.pgm");
{
Index: tests/linear/Makefile.am
--- tests/linear/Makefile.am (revision 2798)
+++ tests/linear/Makefile.am (working copy)
@@ -6,16 +6,16 @@
check_PROGRAMS = \
convolve \
+ convolve_directional \
gaussian \
lap \
- line_convolve \
log \
sobel
convolve_SOURCES = convolve.cc
gaussian_SOURCES = gaussian.cc
lap_SOURCES = lap.cc
-line_convolve_SOURCES = line_convolve.cc
+convolve_directional_SOURCES = convolve_directional.cc
log_SOURCES = log.cc
sobel_SOURCES = sobel.cc
Index: tests/linear/convolve_directional.cc
--- tests/linear/convolve_directional.cc (revision 2780)
+++ tests/linear/convolve_directional.cc (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 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
@@ -25,9 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/linear/line_convolve.cc
+/*! \file tests/linear/convolve_directional.cc
*
- * \brief Tests on mln::linear::line_convolve.
+ * \brief Tests on mln::linear::convolve_directional.
*/
#include <mln/core/image/image2d.hh>
@@ -40,7 +41,7 @@
#include <mln/core/alias/w_window2d_float.hh>
#include <mln/border/thickness.hh>
-#include <mln/linear/line_convolve.hh>
+#include <mln/linear/convolve_directional.hh>
#include "tests/data.hh"
@@ -54,12 +55,10 @@
image2d<int_u8> lena;
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
- image2d<int_u8> out(lena.domain());
- image2d<float> tmp(lena.domain());
float ws[] = { .11, .11, .11, .11, .11, .11, .11, .11, .11 };
- linear::line_convolve(lena, ws, tmp);
+ image2d<float> tmp = linear::convolve_directional(lena, 1, ws);
- level::transform(tmp, math::round<int_u8>(), out);
- io::pgm::save(out, "out.pgm");
+ io::pgm::save(level::transform(tmp, math::round<int_u8>()),
+ "out.pgm");
}
Property changes on: tests/linear/convolve_directional.cc
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/make/Makefile.am
--- tests/make/Makefile.am (revision 2798)
+++ tests/make/Makefile.am (working copy)
@@ -6,11 +6,13 @@
dual_neighb \
image2d \
mat \
- w_window
+ w_window \
+ w_window_directional
dual_neighb_SOURCES = dual_neighb.cc
image2d_SOURCES = image2d.cc
mat_SOURCES = mat.cc
w_window_SOURCES = w_window.cc
+w_window_directional_SOURCES = w_window_directional.cc
TESTS = $(check_PROGRAMS)
Index: tests/make/w_window_directional.cc
--- tests/make/w_window_directional.cc (revision 0)
+++ tests/make/w_window_directional.cc (revision 0)
@@ -0,0 +1,47 @@
+// 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/make/w_window_directional.cc
+///
+/// Tests on mln::make::w_window_directional.
+
+#include <mln/core/alias/w_window2d_int.hh>
+#include <mln/make/w_window_directional.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ int vals[] = { -1, 0, 1 };
+ w_window2d_int w_win = make::w_window_directional(right, vals);
+
+ int sum = 0;
+ for (unsigned i = 0; i < w_win.size(); ++i)
+ sum += w_win.w(i);
+ mln_assertion(sum == 0);
+}
Index: mln/core/concept/gdpoint.hh
--- mln/core/concept/gdpoint.hh (revision 2798)
+++ mln/core/concept/gdpoint.hh (working copy)
@@ -29,12 +29,9 @@
#ifndef MLN_CORE_CONCEPT_GDPOINT_HH
# define MLN_CORE_CONCEPT_GDPOINT_HH
-/*! \file mln/core/concept/delta_point_site.hh
- *
- * \brief Definition of the concept of mln::Gdpoint.
- *
- * \todo Add support for (s * dp)...
- */
+/// \file mln/core/concept/delta_point_site.hh
+///
+/// Definition of the concept of mln::Gdpoint.
# include <mln/core/concept/object.hh>
# include <mln/core/grids.hh>
@@ -52,6 +49,8 @@
namespace trait
{
+ // FIXME: Add promotion.
+
template < typename L, typename R >
struct set_binary_< op::plus,
mln::Gdpoint, L, mln::Gdpoint, R >
@@ -66,6 +65,14 @@
typedef L ret;
};
+ template < typename D, typename S >
+ struct set_binary_< op::times,
+ mln::Gdpoint, D,
+ mln::value::Scalar, S >
+ {
+ typedef D ret;
+ };
+
template <typename D>
struct set_unary_< op::ord, mln::Gdpoint, D >
{
@@ -123,6 +130,10 @@
L // FIXME: promote!
operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs);
+ template <typename D, typename S>
+ D // FIXME: promote!
+ operator*(const Gdpoint<D>& lhs, const value::Scalar<S>& rhs);
+
namespace convert
@@ -192,6 +203,14 @@
return tmp;
}
+ template <typename D, typename S>
+ D // FIXME: promote!
+ operator*(const Gdpoint<D>& lhs, const value::Scalar<S>& rhs)
+ {
+ D tmp = exact(lhs).to_vec() * exact(rhs);
+ return tmp;
+ }
+
namespace convert
{
Index: mln/linear/log.hh
--- mln/linear/log.hh (revision 2798)
+++ mln/linear/log.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 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
@@ -28,10 +29,9 @@
#ifndef MLN_LINEAR_LOG_HH
# define MLN_LINEAR_LOG_HH
-/*! \file mln/linear/log.hh
- *
- * \brief Laplacian of Gaussian.
- */
+/// \file mln/linear/log.hh
+///
+/// Laplacian of Gaussian.
# include <mln/linear/convolve.hh>
# include <mln/make/w_window2d.hh>
@@ -44,17 +44,21 @@
namespace linear
{
- template <typename I, typename O>
- void LoG_5x5(const Image<I>& input, Image<O>& output);
-
- template <typename I, typename O>
- void LoG_7x7(const Image<I>& input, Image<O>& output);
-
- template <typename I, typename O>
- void LoG_13x13(const Image<I>& input, Image<O>& output);
-
- template <typename I, typename O>
- void LoG_17x17(const Image<I>& input, Image<O>& output);
+ template <typename I>
+ mln_ch_convolve(I, int)
+ LoG_5x5(const Image<I>& input);
+
+ template <typename I>
+ mln_ch_convolve(I, int)
+ LoG_7x7(const Image<I>& input);
+
+ template <typename I>
+ mln_ch_convolve(I, int)
+ LoG_13x13(const Image<I>& input);
+
+ template <typename I>
+ mln_ch_convolve(I, int)
+ LoG_17x17(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
@@ -62,26 +66,32 @@
// LoG_5x5 (Cf. Sonka et al., pages 85-86)
// This is also a "mexican hat".
- template <typename I, typename O>
+ template <typename I>
inline
- void LoG_5x5(const Image<I>& input, Image<O>& output)
+ mln_ch_convolve(I, int)
+ LoG_5x5(const Image<I>& input)
{
- mln_precondition(exact(output).domain() == exact(input).domain());
+ trace::entering("linear::LoG_5x5");
+ mln_precondition(exact(input).has_data());
int ws[] = { +0, 0, -1, 0, 0,
+0, -1, -2, -1, 0,
-1, -2, 16, -2, -1,
+0, -1, -2, -1, 0,
+0, 0, -1, 0, 0 };
- convolve(input, make::w_window2d(ws), output);
+ mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
+ trace::exiting("linear::LoG_5x5");
+ return output;
}
// LoG 7x7 (Cf. Russ, p. 250)
- template <typename I, typename O>
+ template <typename I>
inline
- void LoG_7x7(const Image<I>& input, Image<O>& output)
+ mln_ch_convolve(I, int)
+ LoG_7x7(const Image<I>& input)
{
- mln_precondition(exact(output).domain() == exact(input).domain());
+ trace::entering("linear::LoG_7x7");
+ mln_precondition(exact(input).has_data());
int ws[] = { +0, 0, -1, -1, -1, 0, 0,
+0, -1, -3, -3, -3, -1, 0,
-1, -3, 0, 7, 0, -3, -1,
@@ -89,16 +99,20 @@
-1, -3, 0, 7, 0, -3, -1,
+0, -1, -3, -3, -3, -1, 0,
+0, 0, -1, -1, -1, 0, 0 };
- convolve(input, make::w_window2d(ws), output);
+ mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
+ trace::exiting("linear::LoG_7x7");
+ return output;
}
// LoG 13x13 (Cf. Russ, p. 250)
- template <typename I, typename O>
+ template <typename I>
inline
- void LoG_13x13(const Image<I>& input, Image<O>& output)
+ mln_ch_convolve(I, int)
+ LoG_13x13(const Image<I>& input)
{
- mln_precondition(exact(output).domain() == exact(input).domain());
+ trace::entering("linear::LoG_13x13");
+ mln_precondition(exact(input).has_data());
int ws[] = { +0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0,
+0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
@@ -112,17 +126,20 @@
+0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
+0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0 };
- convolve(input, make::w_window2d(ws), output);
+ mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
+ return output;
}
// LoG 17x17 (Cf. Sonka et al., pages 85-86)
- template <typename I, typename O>
+ template <typename I>
inline
- void LoG_17x17(const Image<I>& input, Image<O>& output)
+ mln_ch_convolve(I, int)
+ LoG_17x17(const Image<I>& input)
{
- mln_precondition(exact(output).domain() == exact(input).domain());
+ trace::entering("linear::LoG_17x17");
+ mln_precondition(exact(input).has_data());
int ws[] = { +0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
+0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
@@ -140,7 +157,9 @@
+0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
+0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0 };
- convolve(input, make::w_window2d(ws), output);
+ mln_ch_convolve(I, int) output = convolve(input, make::w_window2d(ws));
+ trace::exiting("linear::LoG_17x17");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/linear/sobel.hh
--- mln/linear/sobel.hh (revision 2798)
+++ mln/linear/sobel.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 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
@@ -28,13 +29,11 @@
#ifndef MLN_LINEAR_SOBEL_HH
# define MLN_LINEAR_SOBEL_HH
-/*! \file mln/linear/sobel.hh
- *
- * \brief Sobel filter.
- *
- * \todo Extends to the case of other dimensions (only the 2-d case
- * is handled here).
- */
+/// \file mln/linear/sobel.hh
+///
+/// Sobel filter.
+/// \todo Extends to the case of other dimensions (only the 2-d case
+/// is handled here).
# include <mln/trait/ch_value.hh>
# include <mln/trait/value/nature.hh>
Index: mln/linear/all.hh
--- mln/linear/all.hh (revision 2798)
+++ mln/linear/all.hh (working copy)
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 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
@@ -28,10 +29,9 @@
#ifndef MLN_LINEAR_ALL_HH
# define MLN_LINEAR_ALL_HH
-/*! \file mln/linear/all.hh
- *
- * \brief File that includes all linear image processing routines.
- */
+/// \file mln/linear/all.hh
+///
+/// File that includes all linear image processing routines.
namespace mln
@@ -43,8 +43,7 @@
/// Namespace of linear image processing routines implementation details.
namespace impl
- {
- }
+ {}
/// Specializations of local linear routines.
namespace local
@@ -52,21 +51,21 @@
/// Namespace of local linear routines implementation details.
namespace impl
- {
- }
+ {}
}
}
-
}
+
# include <mln/linear/convolve.hh>
+# include <mln/linear/convolve_directional.hh>
# include <mln/linear/gaussian.hh>
# include <mln/linear/lap.hh>
-# include <mln/linear/line_convolve.hh>
# include <mln/linear/line_x2_convolve.hh>
# include <mln/linear/log.hh>
//# include <mln/linear/sobel.hh>
//# include <mln/linear/local/convolve.hh>
+
#endif // ! MLN_LINEAR_ALL_HH
Index: mln/linear/convolve_directional.hh
--- mln/linear/convolve_directional.hh (revision 2780)
+++ mln/linear/convolve_directional.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 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
@@ -25,16 +26,16 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_LINEAR_LINE_CONVOLVE_HH
-# define MLN_LINEAR_LINE_CONVOLVE_HH
+#ifndef MLN_LINEAR_CONVOLVE_DIRECTIONAL_HH
+# define MLN_LINEAR_CONVOLVE_DIRECTIONAL_HH
-/*! \file mln/linear/line_convolve.hh
- *
- * \brief Convolution by a line-shaped kernel.
- */
+/// mln/linear/convolve_directional.hh
+///
+/// Convolution by a line-shaped (directional) kernel.
# include <mln/linear/convolve.hh>
-# include <mln/make/w_window_line.hh>
+# include <mln/make/w_window_directional.hh>
+# include <mln/literal/zero.hh>
@@ -44,8 +45,9 @@
namespace linear
{
- /*! Convolution of an image \p input by a line-shaped weighted
- * window defined by the array of \p weights.
+ /*! Convolution of an image \p input by a line-shaped
+ * (directional) weighted window defined by the array of \p
+ * weights.
*
* \warning Computation of \p output(p) is performed with the
* value type of \p output.
@@ -53,26 +55,33 @@
* \warning The weighted window is used as-is, considering that
* its symmetrization is handled by the client.
*
- * \pre output.domain = input.domain
- *
- * \todo Optimize.
+ * \pre input.has_data
*/
- template <typename I, typename W, unsigned N, typename O>
- void line_convolve(const Image<I>& input, W (&weights)[N],
- Image<O>& output);
+ template <typename I, typename W, unsigned S>
+ mln_ch_convolve(I, W)
+ convolve_directional(const Image<I>& input, unsigned dir, W
(&weights)[S]);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename W, unsigned N, typename O>
+ template <typename I, typename W, unsigned S>
inline
- void line_convolve(const Image<I>& input, W (&weights)[N],
- Image<O>& output)
+ mln_ch_convolve(I, W)
+ convolve_directional(const Image<I>& input, unsigned dir, W
(&weights)[S])
{
- mln_precondition(exact(output).domain() == exact(input).domain());
- linear::convolve(input,
- make::w_window_line<mln_dpsite(I)>(weights),
- output);
+ trace::entering("linear::convolve_directional");
+ mln_precondition(exact(input).has_data());
+ typedef mln_site(I) P;
+ mln_precondition(dir < P::dim);
+
+ typedef mln_delta(P) D;
+ D dp = literal::zero;
+ ++dp[dir];
+ w_window<D,W> w_win = make::w_window_directional(dp, weights);
+ mln_ch_convolve(I, W) output = convolve(input, w_win);
+
+ trace::exiting("linear::convolve_directional");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -82,4 +91,4 @@
} // end of namespace mln
-#endif // ! MLN_LINEAR_LINE_CONVOLVE_HH
+#endif // ! MLN_LINEAR_CONVOLVE_DIRECTIONAL_HH
Property changes on: mln/linear/convolve_directional.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 2798)
+++ mln/linear/convolve.hh (working copy)
@@ -54,7 +54,7 @@
* \warning The weighted window is used as-is, considering that
* its symmetrization is handled by the client.
*
- * \pre output.domain = input.domain
+ * \pre input.has_data
*/
template <typename I, typename W>
mln_ch_convolve(I, W)
Index: mln/make/all.hh
--- mln/make/all.hh (revision 2798)
+++ mln/make/all.hh (working copy)
@@ -29,10 +29,9 @@
#ifndef MLN_MAKE_ALL_HH
# define MLN_MAKE_ALL_HH
-/*! \file mln/make/all.hh
- *
- * \brief File that includes all make routines.
- */
+/// \file mln/make/all.hh
+///
+/// File that includes all make routines.
namespace mln
@@ -64,7 +63,8 @@
# include <mln/make/w_window2d_int.hh>
# include <mln/make/w_window3d.hh>
# include <mln/make/w_window3d_int.hh>
-# include <mln/make/w_window_line.hh>
+# include <mln/make/w_window_directional.hh>
# include <mln/make/win_chamfer.hh>
+
#endif // ! MLN_MAKE_ALL_HH
Index: mln/make/w_window_directional.hh
--- mln/make/w_window_directional.hh (revision 2780)
+++ mln/make/w_window_directional.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 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
@@ -25,15 +26,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MAKE_W_WINDOW_LINE_HH
-# define MLN_MAKE_W_WINDOW_LINE_HH
+#ifndef MLN_MAKE_W_WINDOW_DIRECTIONAL_HH
+# define MLN_MAKE_W_WINDOW_DIRECTIONAL_HH
-/*! \file mln/make/w_window_line.hh
- *
- * \brief Routine to create an horizontal mln::w_window.
- */
+/// \file mln/make/w_window_directional.hh
+///
+/// Routine to create a directional mln::w_window.
# include <mln/core/w_window.hh>
+# include <mln/core/concept/gdpoint.hh>
# include <mln/literal/zero.hh>
@@ -43,33 +44,36 @@
namespace make
{
- /*! \brief Create an horizontal centered and symmetrical
- * mln::w_window.
- *
- * The free parameter \c D is a type of delta-point.
- *
- * \pre The window length \c L has to be odd.
- *
- * \return A window.
- */
+ /// Create a directional centered weighted window.
+ ///
+ /// \param[in] dp A delta-point to set the orientation.
+ /// \param[in] weights An array of weights.
+ /// \return A weighted window.
+ ///
+ /// The window length \c L has to be odd.
template <typename D, typename W, unsigned L>
- mln::w_window<D,W> w_window_line(W (&w)[L]);
+ mln::w_window<D,W>
+ w_window_directional(const Gdpoint<D>& dp, W (&weights)[L]);
# ifndef MLN_INCLUDE_ONLY
template <typename D, typename W, unsigned L>
inline
- mln::w_window<D,W> w_window_line(W (&w)[L])
+ mln::w_window<D,W>
+ w_window_directional(const Gdpoint<D>& dp_, W (&weights)[L])
{
- mln_precondition(L % 2 == 1);
+ mlc_bool(L % 2 == 1)::check();
+ int half = L / 2;
+
+ const D& dp = exact(dp_);
+ D zero = literal::zero;
+ mln_precondition(dp != zero);
+
mln::w_window<D,W> w_win;
- D dp = literal::zero;
- for (unsigned i = 0; i < L; ++i)
- {
- dp[D::dim - 1] = i - L / 2;
- w_win.insert(w[i], dp);
- }
+ for (int i = - half; i <= half; ++i)
+ if (weights[half + i] != 0)
+ w_win.insert(weights[half + i], zero + dp * i);
return w_win;
}
@@ -80,4 +84,4 @@
} // end of namespace mln
-#endif // ! MLN_MAKE_W_WINDOW_LINE_HH
+#endif // ! MLN_MAKE_W_WINDOW_DIRECTIONAL_HH
Property changes on: mln/make/w_window_directional.hh
___________________________________________________________________
Added: svn:mergeinfo