https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean-up from_to, add some new overloads, and fix (c).
* milena/tests/core/other/w_window.cc: New.
* milena/tests/core/other/Makefile.am: Update.
* milena/tests/core/alias/window2d.cc: Remove echos.
* milena/mln/make/image2d.hh: New.
* milena/tests/make/image2d.cc: New.
* milena/tests/make/Makefile.am: Update.
* milena/tests/convert/to_image.cc: Fix copyright.
(include): Remove; useless.
* milena/mln/core/alias/window2d.hh: Fix include.
* milena/mln/core/w_window.hh (from_to): New overload.
* milena/mln/core/dpoint.hh: Fix (c).
* milena/mln/core/concept/weighted_window.hh: Fix (c).
* milena/mln/core/concept/object.hh: Include all metal math.
Include metal converts_to.
* milena/mln/core/concept/window.hh (from_to): New overload.
(todo): New.
* milena/mln/core/concept/image.hh (from_to): New overload.
* milena/mln/core/concept/gpoint.hh: Fix doc.
* milena/mln/core/concept/gdpoint.hh (from_to): New overload.
* milena/mln/core/def/all.hh: New.
* milena/mln/core/window.hh: Fix copyright.
* milena/mln/linear/convolve.hh: Fix warning + copyright.
* milena/mln/make/image.hh (image): New overload for 3D.
* milena/mln/make/w_window2d.hh: Fix copyright.
Remove useless include.
* milena/mln/convert/to_image.hh
(mln_image_from, helper_dim_, helper_image_from_): Remove.
Redundant with image_from_grid.
(to_image): Update and use convert::from_to.
* milena/mln/convert/from_to.hxx: Layout and update.
mln/convert/from_to.hxx | 84 +++++++++++++++-----
mln/convert/to_image.hh | 148 +++++++++++-------------------------
mln/core/alias/window2d.hh | 8 +
mln/core/concept/gdpoint.hh | 35 ++++++++
mln/core/concept/gpoint.hh | 4
mln/core/concept/image.hh | 51 +++++++++++-
mln/core/concept/object.hh | 3
mln/core/concept/weighted_window.hh | 1
mln/core/concept/window.hh | 74 ++++++++++++++++--
mln/core/def/all.hh | 49 +++++++++++
mln/core/dpoint.hh | 3
mln/core/w_window.hh | 63 +++++++++++++--
mln/core/window.hh | 1
mln/linear/convolve.hh | 5 -
mln/make/image.hh | 48 +++++++++--
mln/make/image2d.hh | 77 ++++++++++++++++++
mln/make/w_window2d.hh | 2
tests/convert/to_image.cc | 15 ---
tests/core/alias/window2d.cc | 23 ++---
tests/core/other/Makefile.am | 4
tests/core/other/w_window.cc | 48 +++++++++++
tests/make/Makefile.am | 2
tests/make/image2d.cc | 47 +++++++++++
23 files changed, 617 insertions(+), 178 deletions(-)
Index: milena/tests/core/other/w_window.cc
--- milena/tests/core/other/w_window.cc (revision 0)
+++ milena/tests/core/other/w_window.cc (revision 0)
@@ -0,0 +1,48 @@
+// 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/core/other/w_window.cc
+/// \brief Tests on regular weighted windows.
+
+#include <mln/core/w_window.hh>
+#include <mln/core/image/image2d.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ int vals[] = { 1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9 };
+ w_window<dpoint2d,int> w_win;
+ convert::from_to(vals, w_win);
+
+ image2d<int> ima;
+ convert::from_to(w_win, ima);
+ mln_assertion(ima.domain() == make::box2d(-1,-1, 1,1));
+}
Index: milena/tests/core/other/Makefile.am
--- milena/tests/core/other/Makefile.am (revision 2751)
+++ milena/tests/core/other/Makefile.am (working copy)
@@ -20,7 +20,8 @@
pixter2d_more \
pixter3d \
pixter3d_more \
- point_set_compatibility
+ point_set_compatibility \
+ w_window
box_runstart_piter_SOURCES = box_runstart_piter.cc
category_SOURCES = category.cc
@@ -40,5 +41,6 @@
pixter3d_SOURCES = pixter3d.cc
pixter3d_more_SOURCES = pixter3d_more.cc
point_set_compatibility_SOURCES = point_set_compatibility.cc
+w_window_SOURCES = w_window.cc
TESTS = $(check_PROGRAMS)
Index: milena/tests/core/alias/window2d.cc
--- milena/tests/core/alias/window2d.cc (revision 2751)
+++ milena/tests/core/alias/window2d.cc (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,17 +26,13 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/core/alias/window2d.cc
- *
- * \brief Tests on mln::window2d.
- */
+/// \file tests/core/alias/window2d.cc
+///
+/// Tests on mln::window2d.
#include <mln/core/alias/window2d.hh>
#include <mln/core/image/image2d.hh>
#include <mln/convert/to_image.hh>
-#include <mln/debug/println.hh>
-#include <mln/logical/not.hh>
-
int main()
@@ -50,9 +47,11 @@
w .insert(-1,-1)
.insert( 1, 1);
- image2d<bool> ima = convert::to_image(w);
- debug::println(ima);
- debug::println(logical::not_(ima));
-
mln_assertion(w.delta() == 1);
+
+ // The code below is equivalent to:
+ // image2d<bool> ima;
+ // convert::from_to(w, ima);
+ image2d<bool> ima = convert::to_image(w);
+ (void) ima;
}
Index: milena/tests/make/Makefile.am
--- milena/tests/make/Makefile.am (revision 2751)
+++ milena/tests/make/Makefile.am (working copy)
@@ -4,10 +4,12 @@
check_PROGRAMS = \
dual_neighb \
+ image2d \
mat \
w_window
dual_neighb_SOURCES = dual_neighb.cc
+image2d_SOURCES = image2d.cc
mat_SOURCES = mat.cc
w_window_SOURCES = w_window.cc
Index: milena/tests/make/image2d.cc
--- milena/tests/make/image2d.cc (revision 0)
+++ milena/tests/make/image2d.cc (revision 0)
@@ -0,0 +1,47 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// 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/image2d.cc
+ *
+ * \brief Tests on mln::make::image2d.
+ */
+
+#include <mln/make/image2d.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ bool vals[] = { 1, 1, 0, 0, 1,
+ 1, 1, 1, 1, 0,
+ 0, 1, 1, 1, 0,
+ 0, 1, 1, 1, 0,
+ 0, 1, 0, 0, 0 };
+ image2d<bool> ima = make::image2d(vals);
+ mln_assertion(ima.domain() == box2d(5,5));
+}
Index: milena/tests/convert/to_image.cc
--- milena/tests/convert/to_image.cc (revision 2751)
+++ milena/tests/convert/to_image.cc (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,10 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/convert/to_image.cc
- *
- * \brief Tests on mln::convert::to_image.
- */
+/// \file tests/convert/to_image.cc
+/// Tests on mln::convert::to_image.
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/window2d.hh>
@@ -40,10 +39,6 @@
#include <mln/convert/to.hh>
-#include <mln/debug/println.hh>
-
-
-
int main()
{
using namespace mln;
@@ -61,6 +56,4 @@
image2d<bool> ima_X = convert::to_image(box_3x3 | fun::p2b::chess, 0);
window2d win_X = convert::to<window2d>(X);
mln_assertion(convert::to_image(win_X) == ima_X);
-
- // FIXME: nbh!
}
Index: milena/mln/core/alias/window2d.hh
--- milena/mln/core/alias/window2d.hh (revision 2751)
+++ milena/mln/core/alias/window2d.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
@@ -29,7 +30,8 @@
# define MLN_CORE_ALIAS_WINDOW2D_HH
/// \file mln/core/alias/window2d.hh
-/// \brief Definition of the mln::window2d alias and of a construction
+///
+/// Definition of the mln::window2d alias and of a construction
/// routine.
///
/// \todo c8p etc.
@@ -37,7 +39,7 @@
# include <mln/core/window.hh>
# include <mln/core/alias/dpoint2d.hh>
# include <mln/metal/math/sqrt.hh>
-# include <mln/convert/from_to.hh>
+# include <mln/convert/from_to.hxx>
namespace mln
Index: milena/mln/core/w_window.hh
--- milena/mln/core/w_window.hh (revision 2751)
+++ milena/mln/core/w_window.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,11 @@
#ifndef MLN_CORE_W_WINDOW_HH
# define MLN_CORE_W_WINDOW_HH
-/*! \file mln/core/w_window.hh
- *
- * \brief Definition of the generic weighted window class mln::w_window.
- */
+/// \file mln/core/w_window.hh
+///
+/// Definition of the generic weighted window class mln::w_window.
+///
+/// \todo Generalize W_Window -> Image.
# include <map>
@@ -43,8 +45,8 @@
# include <mln/value/ops.hh>
# include <mln/util/ord.hh>
-# include <mln/metal/converts_to.hh>
-# include <mln/metal/math/root.hh>
+# include <mln/level/fill.hh>
+# include <mln/geom/bbox.hh> // FIXME: We may have some dep trouble with this include.
# include <mln/literal/zero.hh>
# include <mln/convert/to.hh>
@@ -150,6 +152,10 @@
void
from_to(const Image<I>& from, w_window<D,W>& to);
+ template <typename D, typename W, typename I>
+ void
+ from_to(const w_window<D,W>& from, Image<I>& to);
+
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&weight)[S], w_window<D,W>& to);
@@ -331,7 +337,6 @@
{
template <typename I, typename D, typename W>
- inline
void
from_to(const Image<I>& from_, w_window<D,W>& to)
{
@@ -345,10 +350,54 @@
to.insert(ima(p), convert::to<D>(p));
}
+ template <typename D, typename W, typename I>
+ void
+ from_to(const w_window<D,W>& w_win, Image<I>& ima_)
+ {
+ typedef mln_site(I) P;
+ mlc_converts_to(D, mln_delta(P))::check();
+ mlc_converts_to(W, mln_value(I))::check();
+
+ I& ima = exact(ima_);
+ mln_precondition(! ima.has_data());
+ // mln_precondition(w_win.is_valid());
+
+ ima.init_(geom::bbox(w_win));
+ level::fill(ima, literal::zero);
+
+ unsigned n = w_win.size();
+ for (unsigned i = 0; i < n; ++i)
+ ima(convert::to<P>(w_win.dp(i))) = w_win.w(i);
+ }
+
+ // FIXME: Sample code (below) to generalize the code above:
+
+// template <typename W>
+// inline
+// mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
+// {
+// const W& w_win = exact(w_win_);
+// mln_precondition(! w_win.is_empty());
+
+// typedef mln_psite(W) P;
+// box<P> b = geom::bbox(w_win);
+// mln_image_from(W, mln_weight(W)) ima(b);
+// // Fill the image with zeros, as (weighted) windows are not
+// // necessarily box-shaped (there might be holes corresponding to
+// // null weights).
+// level::fill(ima, literal::zero);
+// P O = P::origin;
+// mln_qiter(W) q(w_win, O);
+// for_all(q)
+// ima(q) = q.w();
+// return ima;
+// }
+
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&weight)[S], w_window<D,W>& to)
{
+ mlc_bool(S != 0)::check();
mlc_converts_to(V, W)::check();
enum { d = D::dim,
s = mlc_root(d,S)::value / 2 };
Index: milena/mln/core/dpoint.hh
--- milena/mln/core/dpoint.hh (revision 2751)
+++ milena/mln/core/dpoint.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
Index: milena/mln/core/concept/weighted_window.hh
--- milena/mln/core/concept/weighted_window.hh (revision 2751)
+++ milena/mln/core/concept/weighted_window.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
Index: milena/mln/core/concept/object.hh
--- milena/mln/core/concept/object.hh (revision 2751)
+++ milena/mln/core/concept/object.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
@@ -46,8 +47,10 @@
# include <mln/metal/is_a.hh>
# include <mln/metal/is.hh>
# include <mln/metal/is_not.hh>
+# include <mln/metal/converts_to.hh>
# include <mln/metal/ret.hh>
# include <mln/metal/unqualif.hh>
+# include <mln/metal/math/all.hh>
/*! \mainpage Documentation of milena
Index: milena/mln/core/concept/window.hh
--- milena/mln/core/concept/window.hh (revision 2751)
+++ milena/mln/core/concept/window.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
@@ -37,13 +38,21 @@
*
* \todo The is_centered() method could also exist when the window is
* not regular...
+ *
+ * \todo Remove hack.
*/
# include <mln/core/concept/object.hh>
# include <mln/core/concept/iterator.hh>
# include <mln/trait/windows.hh>
+
# include <mln/core/site_set/p_array.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/literal/origin.hh>
+# include <mln/level/fill.hh>
+# include <mln/convert/from_to.hxx>
+
# define mln_is_simple_window(W) \
@@ -60,9 +69,10 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename E> struct Window;
+
// Window category flag type.
template <>
struct Window<void>
@@ -105,14 +115,18 @@
- template <typename W>
- void check_simple(const Window<W>& win);
+ namespace convert
+ {
+ template <typename W, typename I>
+ void
+ from_to(const Window<W>& from, Image<I>& to);
+ } // end of namespace mln::convert
-# ifndef MLN_INCLUDE_ONLY
+# ifndef MLN_INCLUDE_ONLY
namespace internal
{
@@ -273,7 +287,7 @@
ostr << " ]";
}
- } // end of namespace mln
+ } // end of namespace mln::internal
template <typename W>
inline
@@ -289,6 +303,56 @@
return ostr;
}
+
+ namespace convert
+ {
+
+ namespace internal
+ {
+
+
+ // FIXME: Hack to avoid including geom::bbox (circular
+ // dependency).
+
+ template <typename W>
+ box<mln_psite(W)> bbox_(const Window<W>& win)
+ {
+ typedef mln_psite(W) P;
+ accu::bbox<P> b;
+ P O = literal::origin;
+ mln_qiter(W) q(exact(win), O);
+ for_all(q)
+ b.take(q);
+ return b;
+ }
+
+ }
+
+ template <typename W, typename I>
+ void
+ from_to(const Window<W>& win_, Image<I>& ima_)
+ {
+ mln_is_simple_window(W)::check();
+ typedef mln_psite(I) P;
+ mlc_converts_to(mln_dpsite(W), mln_delta(P))::check();
+ mlc_equal(mln_value(I), bool)::check();
+
+ const W& win = exact(win_);
+ I& ima = exact(ima_);
+
+ // mln_precondition(win.is_valid());
+ mln_precondition(! ima.has_data());
+
+ ima.init_(internal::bbox_(win)); // geom::bbox(win));
+ level::fill(ima, false);
+
+ unsigned n = win.size();
+ for (unsigned i = 0; i < n; ++i)
+ ima(convert::to<P>(win.dp(i))) = true;
+ }
+
+ } // end of namespace mln::convert
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: milena/mln/core/concept/image.hh
--- milena/mln/core/concept/image.hh (revision 2751)
+++ milena/mln/core/concept/image.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,15 +29,17 @@
#ifndef MLN_CORE_CONCEPT_IMAGE_HH
# define MLN_CORE_CONCEPT_IMAGE_HH
-/*! \file mln/core/concept/image.hh
- * \brief Definition of the concept of mln::Image.
- */
+/// \file mln/core/concept/image.hh
+///
+/// Definition of the concept of mln::Image.
# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/mesh.hh>
# include <mln/core/trait/all.hh> // FIXME: Move out of core!
# include <mln/core/macros.hh>
+# include <mln/core/site_set/box.hh>
+
# include <mln/trait/concrete.hh> // FIXME: Should be in all.hh!
# include <mln/trait/images.hh>
@@ -109,6 +112,18 @@
};
+
+ namespace convert
+ {
+
+ template <typename V, unsigned S, typename I>
+ void
+ from_to(const V (&values)[S], Image<I>& to);
+
+ } // end of namespace mln::convert
+
+
+
# ifndef MLN_INCLUDE_ONLY
@@ -224,10 +239,40 @@
E>::run();
}
+
+ namespace convert
+ {
+
+ template <typename V, unsigned S, typename I>
+ void
+ from_to(const V (&values)[S], Image<I>& to_)
+ {
+ mlc_bool(S != 0)::check();
+ mlc_converts_to(V, mln_value(I))::check();
+ typedef mln_site(I) P;
+ enum { d = P::dim,
+ s = mlc_root(d,S)::value / 2 };
+ metal::bool_<(mlc_pow_int(2 * s + 1, d) == S)>::check();
+
+ I& to = exact(to_);
+ mln_precondition(! to.has_data());
+
+ box<P> b(all_to(0), all_to(2 * s));
+ to.init_(b);
+ mln_fwd_piter(box<P>) p(b);
+ unsigned i = 0;
+ for_all(p)
+ to(p) = values[i++];
+ }
+
+ } // end of namespace mln::convert
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
+
# include <mln/core/routine/initialize.hh>
+
#endif // ! MLN_CORE_CONCEPT_IMAGE_HH
Index: milena/mln/core/concept/gpoint.hh
--- milena/mln/core/concept/gpoint.hh (revision 2751)
+++ milena/mln/core/concept/gpoint.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
@@ -43,7 +44,7 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename E> struct Gpoint;
@@ -308,6 +309,7 @@
// Gpoint -> algebra::vec.
template <typename P, unsigned n, typename T>
+ inline
void
from_to(const Gpoint<P>& from_, algebra::vec<n,T>& to)
{
Index: milena/mln/core/concept/gdpoint.hh
--- milena/mln/core/concept/gdpoint.hh (revision 2751)
+++ milena/mln/core/concept/gdpoint.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
@@ -124,6 +125,23 @@
+ namespace convert
+ {
+
+ template <typename D>
+ void
+ from_to(const Gdpoint<D>& from, mln_site(D)& to);
+
+// template <typename D, unsigned n, typename T>
+// void
+// from_to(const Gdpoint<D>& from, algebra::vec<n,T>& to);
+
+// template <unsigned n, typename T, typename D>
+// void
+// from_to(const algebra::vec<n,T>& from, Gdpoint<D>& to);
+
+ } // end of namespace::convert
+
# ifndef MLN_INCLUDE_ONLY
@@ -174,6 +192,23 @@
return tmp;
}
+
+ namespace convert
+ {
+
+ template <typename D>
+ inline
+ void
+ from_to(const Gdpoint<D>& dp_, mln_site(D)& p)
+ {
+ enum { n = D::dim };
+ const D& dp = exact(dp_);
+ for (unsigned i = 0; i < n; ++i)
+ p[i] = dp[i];
+ }
+
+ } // end of namespace::convert
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: milena/mln/core/def/all.hh
--- milena/mln/core/def/all.hh (revision 0)
+++ milena/mln/core/def/all.hh (revision 0)
@@ -0,0 +1,49 @@
+// 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.
+
+#ifndef MLN_CORE_DEF_ALL_HH
+# define MLN_CORE_DEF_ALL_HH
+
+/// mln/core/def/all.hh
+/// File that includes all core definitions.
+
+
+namespace mln
+{
+
+ /// Namespace for core definitions.
+ namespace def
+ {}
+
+}
+
+
+# include <mln/core/def/coord.hh>
+# include <mln/core/def/coordf.hh>
+
+
+#endif // ! MLN_CORE_DEF_ALL_HH
Index: milena/mln/core/window.hh
--- milena/mln/core/window.hh (revision 2751)
+++ milena/mln/core/window.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
Index: milena/mln/linear/convolve.hh
--- milena/mln/linear/convolve.hh (revision 2751)
+++ milena/mln/linear/convolve.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
@@ -78,6 +79,8 @@
{
mln_precondition(exact(input).has_data());
// mln_precondition(exact(w_win).is_valid());
+ (void) input;
+ (void) w_win;
}
} // end of namespace mln::linear::internal
Index: milena/mln/make/image.hh
--- milena/mln/make/image.hh (revision 2751)
+++ milena/mln/make/image.hh (working copy)
@@ -29,13 +29,14 @@
#ifndef MLN_MAKE_IMAGE_HH
# define MLN_MAKE_IMAGE_HH
-/*! \file mln/make/image.hh
- *
- * \brief Routine to create an image from various input.
- */
+/// \file mln/make/image.hh
+///
+/// Routine to create an image from values given as a C-array.
# include <mln/core/image/image1d.hh>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
+
namespace mln
@@ -44,19 +45,19 @@
namespace make
{
- /*! \brief Create an image1d from an 1d array of values.
+ /*! \brief Create an image1d from an 1D array of values.
*
- * \param[in] values 1d array.
+ * \param[in] values 1D array.
*
* \return A 1D image.
*/
template <typename V, unsigned L>
- mln::image1d<V> image1d(V (&values)[L]);
+ mln::image1d<V> image(V (&values)[L]);
- /*! \brief Create an image2d from an 2d array of values.
+ /*! \brief Create an image2d from an 2D array of values.
*
- * \param[in] values 2d array.
+ * \param[in] values 2D array.
*
* \return A 2D image.
*/
@@ -64,11 +65,22 @@
mln::image2d<V> image(V (&values)[R][C]);
+ /*! \brief Create an image3d from an 3D array of values.
+ *
+ * \param[in] values 3D array.
+ *
+ * \return A 3D image.
+ */
+ template <typename V, unsigned S, unsigned R, unsigned C>
+ mln::image3d<V> image(V (&values)[S][R][C]);
+
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename V, unsigned L>
mln::image1d<V>
- image1d(V (&values)[L])
+ image(V (&values)[L])
{
mlc_bool(L != 0)::check();
mln::image1d<V> tmp(L);
@@ -81,10 +93,24 @@
mln::image2d<V>
image(V (&values)[R][C])
{
+ mlc_bool(R != 0 && C != 0)::check();
mln::image2d<V> tmp(R, C);
for (unsigned row = 0; row < R; ++row)
for (unsigned col = 0; col < C; ++col)
- tmp(point2d(row, col)) = values[row][col];
+ tmp.at(row, col) = values[row][col];
+ return tmp;
+ }
+
+ template <typename V, unsigned S, unsigned R, unsigned C>
+ mln::image3d<V>
+ image(V (&values)[S][R][C])
+ {
+ mlc_bool(S != 0 && R != 0 && C != 0)::check();
+ mln::image3d<V> tmp(S, R, C);
+ for (unsigned sli = 0; sli < S; ++sli)
+ for (unsigned row = 0; row < R; ++row)
+ for (unsigned col = 0; col < C; ++col)
+ tmp.at(sli, row, col) = values[sli][row][col];
return tmp;
}
Index: milena/mln/make/w_window2d.hh
--- milena/mln/make/w_window2d.hh (revision 2751)
+++ milena/mln/make/w_window2d.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
@@ -35,7 +36,6 @@
# include <mln/core/w_window.hh>
# include <mln/core/alias/dpoint2d.hh>
-# include <mln/metal/math/sqrt.hh>
namespace mln
Index: milena/mln/make/image2d.hh
--- milena/mln/make/image2d.hh (revision 0)
+++ milena/mln/make/image2d.hh (revision 0)
@@ -0,0 +1,77 @@
+// 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.
+
+#ifndef MLN_MAKE_IMAGE2D_HH
+# define MLN_MAKE_IMAGE2D_HH
+
+/// \file mln/make/image2d.hh
+///
+/// Routine to create a 2D image from a 1D array.
+
+# include <mln/core/image/image2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an image2d from an 2D array of values.
+ *
+ * \param[in] values 2D array.
+ *
+ * \return A 2D image.
+ */
+ template <typename V, unsigned S>
+ mln::image2d<V>
+ image2d(V (&values)[S]);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, unsigned S>
+ mln::image2d<V>
+ image2d(V (&values)[S])
+ {
+ mlc_bool(S != 0)::check();
+ enum { s = mlc_sqrt_int(S) / 2 };
+ metal::bool_<((2 * s + 1) * (2 * s + 1) == S)>::check();
+ mln::image2d<V> tmp;
+ convert::from_to(values, tmp);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_IMAGE2D_HH
Index: milena/mln/convert/to_image.hh
--- milena/mln/convert/to_image.hh (revision 2751)
+++ milena/mln/convert/to_image.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,16 +29,11 @@
#ifndef MLN_CONVERT_TO_IMAGE_HH
# define MLN_CONVERT_TO_IMAGE_HH
-/*! \file mln/convert/to_image.hh
- *
- * \brief Conversions to mln::Image.
- *
- * \todo Remove. Use from_to instead...
- */
-
-# include <mln/core/image/image1d.hh>
-# include <mln/core/image/image2d.hh>
-# include <mln/core/image/image3d.hh>
+/// mln/convert/to_image.hh
+///
+/// Conversions to mln::Image.
+
+# include <mln/trait/image_from_grid.hh>
# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/window.hh>
@@ -45,64 +41,16 @@
# include <mln/core/concept/neighborhood.hh>
# include <mln/literal/zero.hh>
-
-# include <mln/convert/to_window.hh>
# include <mln/geom/bbox.hh>
# include <mln/level/fill.hh>
# include <mln/histo/data.hh>
-# define mln_image_from(Src, Value) typename mln::image_from_< Src, Value >::ret
-
namespace mln
{
- // FIXME: Move elsewhere.
- namespace internal
- {
-
- template <typename T>
- struct helper_dim_
- {
- typedef mln_psite(T) P;
- enum { value = P::dim };
- };
-
- template <unsigned dim, typename V> struct helper_image_from_;
-
- template <typename V>
- struct helper_image_from_< 3, V >
- {
- typedef image3d<V> ret;
- };
-
- template <typename V>
- struct helper_image_from_< 2, V >
- {
- typedef image2d<V> ret;
- };
-
- template <typename V>
- struct helper_image_from_< 1, V >
- {
- typedef image1d<V> ret;
- };
-
- } // end of namespace mln::internal
-
-
- // FIXME: Doc + move elsewhere!
- template <typename T, typename V>
- struct image_from_
- {
- enum { dim = internal::helper_dim_<T>::value };
- typedef typename internal::helper_image_from_< dim, V >::ret ret;
- };
-
-
-
namespace convert
{
@@ -110,23 +58,28 @@
/// Convert a point set \p pset into a binary image. Width of the
/// converted image will be pset.bbox + 2 * \p border.
template <typename S>
- mln_image_from(S, bool) to_image(const Site_Set<S>& pset, unsigned border = 1);
+ mln_image_from_grid(mln_site(S)::grid, bool)
+ to_image(const Site_Set<S>& pset, unsigned border = 1);
/// Convert a window \p win into a binary image.
template <typename W>
- mln_image_from(W, bool) to_image(const Window<W>& win);
-
- /// Convert a neighborhood \p nbh into a binary image.
- template <typename N>
- mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh);
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Window<W>& win);
/// Convert a weighted window \p w_win into an image.
template <typename W>
- mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win);
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Weighted_Window<W>& w_win);
+
+ /// Convert a neighborhood \p nbh into a binary image.
+ template <typename N>
+ mln_image_from_grid(mln_site(N)::grid, bool)
+ to_image(const Neighborhood<N>& nbh);
/// Convert an histo \p h into an image1d<std::size_t>.
template <typename T>
- image1d<std::size_t> to_image(const histo::data<T>& h);
+ image1d<std::size_t>
+ to_image(const histo::data<T>& h);
@@ -134,10 +87,12 @@
template <typename S>
inline
- mln_image_from(S, bool) to_image(const Site_Set<S>& pset_, unsigned border)
+ mln_image_from_grid(mln_site(S)::grid, bool)
+ to_image(const Site_Set<S>& pset_, unsigned border)
{
const S& pset = exact(pset_);
- mln_image_from(S, bool) ima(geom::bbox(pset).to_larger(border));
+ mln_image_from_grid(mln_site(S)::grid, bool) ima;
+ ima.init_(geom::bbox(pset).to_larger(border));
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
@@ -147,52 +102,41 @@
template <typename W>
inline
- mln_image_from(W, bool) to_image(const Window<W>& win_)
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Window<W>& win)
{
- const W& win = exact(win_);
- mln_precondition(! win.is_empty());
-
- typedef mln_psite(W) P;
- box<P> b = geom::bbox(win);
- mln_image_from(W, bool) ima(b);
- level::fill(ima, false);
- P O = P::origin;
- mln_qiter(W) q(win, O);
- for_all(q)
- ima(q) = true;
- return ima;
+ mln_is_simple_window(W)::check();
+ // mln_precondition(exact(win).is_valid());
+ mln_image_from_grid(mln_site(W)::grid, bool) tmp;
+ convert::from_to(win, tmp);
+ return tmp;
}
- template <typename N>
+ template <typename W>
inline
- mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh)
+ mln_image_from_grid(mln_site(W)::grid, bool)
+ to_image(const Weighted_Window<W>& w_win)
{
- return to_image(convert::to_window(nbh));
+ mln_is_simple_window(W)::check();
+ // mln_precondition(exact(w_win).is_valid());
+ mln_image_from_grid(mln_site(W)::grid, bool) tmp;
+ convert::from_to(exact(w_win), tmp);
+ return tmp;
}
- template <typename W>
+ template <typename N>
inline
- mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
+ mln_image_from_grid(mln_site(N)::grid, bool)
+ to_image(const Neighborhood<N>& nbh)
{
- const W& w_win = exact(w_win_);
- mln_precondition(! w_win.is_empty());
-
- typedef mln_psite(W) P;
- box<P> b = geom::bbox(w_win);
- mln_image_from(W, mln_weight(W)) ima(b);
- // Fill the image with zeros, as (weighted) windows are not
- // necessarily box-shaped (there might be holes corresponding to
- // null weights).
- level::fill(ima, literal::zero);
- mln_qiter(W) q(w_win, P::origin);
- for_all(q)
- ima(q) = q.w();
- return ima;
+ // mln_precondition(exact(nbh).is_valid());
+ return to_image(exact(nbh).win());
}
template <typename T>
inline
- image1d<std::size_t> to_image(const histo::data<T>& h)
+ image1d<std::size_t>
+ to_image(const histo::data<T>& h)
{
T v_min = h.vset()[0],
v_max = h.vset()[h.vset().nvalues() - 1];
Index: milena/mln/convert/from_to.hxx
--- milena/mln/convert/from_to.hxx (revision 2751)
+++ milena/mln/convert/from_to.hxx (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// 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
@@ -33,6 +33,9 @@
// All overloaded "convert::from_to" routines have to be declared in
// the present file. It allows for *deferred* use of these routines.
+# include <mln/core/def/all.hh>
+# include <mln/core/grids.hh>
+
namespace mln
{
@@ -40,17 +43,22 @@
// Forward declarations.
+ template <typename E> struct Gdpoint;
+ template <typename E> struct Gpoint;
+ template <typename E> struct Image;
template <typename E> struct Object;
template <typename E> struct Proxy;
- template <typename E> struct Image;
template <typename E> struct Site_Set;
- template <typename E> struct Weighted_Window;
- template <typename E> struct Gpoint;
template <typename E> struct Value;
+ template <typename E> struct Weighted_Window;
+ template <typename E> struct Window;
+
+ template <typename G, typename C> struct dpoint;
+ template <typename G, typename C> struct point;
- template <typename D, typename W> class w_window;
template <typename D> class neighb;
template <typename D> class window;
+ template <typename D, typename W> class w_window;
namespace algebra {
template <unsigned n, typename T> class vec;
@@ -87,16 +95,8 @@
template <typename F, typename T>
void
from_to(const Object<F>&, Object<T>&);
+ // end of Guard.
- // Image -> Site_Set.
- template <typename I, typename S>
- void
- from_to(const Image<I>& from, Site_Set<S>& to);
-
- // Gpoint -> algebra::vec.
- template <typename P, unsigned n, typename T>
- void
- from_to(const Gpoint<P>& from, algebra::vec<n,T>& to);
// algebra::vec -> Gpoint.
template <unsigned n, typename T, typename P>
@@ -108,11 +108,39 @@
void
from_to(const algebra::vec<3,T>& from, value::rgb<m>& to);
+
// bool -> rgb.
template <unsigned m>
void
from_to(bool from, value::rgb<m>& to);
+
+ // C-array -> Image.
+ template <typename V, unsigned S, typename I>
+ void
+ from_to(const V (&values)[S], Image<I>& to);
+
+ // C-array -> w_window
+ template <typename V, unsigned S, typename D, typename W>
+ void
+ from_to(const V (&weight)[S], w_window<D,W>& to);
+
+
+ // C-array -> window2d
+ template <unsigned S>
+ void
+ from_to(const bool (&values)[S], window< dpoint<grid::square, def::coord> >& win);
+ template <unsigned R, unsigned C>
+ void
+ from_to(const bool (&values)[R][C], window< dpoint<grid::square, def::coord> >& win);
+
+
+ // Gdpoint -> point
+ template <typename D>
+ void
+ from_to(const Gdpoint<D>& from, mln_site(D)& to);
+
+
// Value -> Value
template <typename F, typename T>
void
@@ -133,22 +161,28 @@
void
from_to(const Proxy<P>& from, T& to);
+
+ // Gpoint -> algebra::vec.
+ template <typename P, unsigned n, typename T>
+ void
+ from_to(const Gpoint<P>& from, algebra::vec<n,T>& to);
+
// Gpoint -> delta-point
template <typename P>
void
from_to(const Gpoint<P>& from, mln_delta(P)& to);
+ // Image -> Site_Set.
+ template <typename I, typename S>
+ void
+ from_to(const Image<I>& from, Site_Set<S>& to);
+
// Image -> w_window
template <typename I, typename D, typename W>
void
from_to(const Image<I>& from, w_window<D,W>& to);
- // C-array -> w_window
- template <typename V, unsigned S, typename D, typename W>
- void
- from_to(const V (&weight)[S], w_window<D,W>& to);
-
// neighb<W> -> W
template <typename W>
@@ -160,6 +194,18 @@
void
from_to(const W& from, mln::neighb<W>& to);
+
+ // Window -> Image
+ template <typename W, typename I>
+ void
+ from_to(const Window<W>& from, Image<I>& to);
+
+
+ // w_window -> Image
+ template <typename D, typename W, typename I>
+ void
+ from_to(const w_window<D,W>& from, Image<I>& to);
+
} // end of namespace mln::convert
} // end of namespace mln