https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make w_window tests pass with from_to instead of to_w_window.
* mln/core/w_window.hh (win): Update sig.
(clear): New.
(from_to): New overload.
* mln/core/internal/site_relative_iterator_base.hh: Update.
* mln/core/neighb.hh: Update.
* mln/core/concept/proxy.hh (from_to): New overload.
* mln/core/concept/weighted_window.hh (sym): Update.
* mln/core/concept/gpoint.hh (from_to): New overload.
* mln/convert/to.hh: Decouple from convert::from_to so...
(include from_to.hh): Replace by...
(include from_to.hxx): ...this.
Update includes.
* mln/convert/to_image.hh: Fix temporary; O can be *-able.
* mln/geom/bbox.hh: Likewise.
* mln/convert/to_w_window.hh: Remove; obsolete because replaced by
from_to.
* mln/convert/from_to.hh: Fix ambiguities in multiple guards; keep
only one.
* mln/convert/all.hh,
* tests/core/alias/w_window1d_int.cc,
* tests/core/alias/w_window2d_int.cc,
* tests/core/alias/w_window3d_int.cc: Update.
* mln/convert/from_to.hxx: New.
mln/convert/all.hh | 1
mln/convert/from_to.hh | 32 ----
mln/convert/from_to.hxx | 151 +++++++++++++++++++++++
mln/convert/to.hh | 7 -
mln/convert/to_image.hh | 3
mln/core/concept/gpoint.hh | 34 +++++
mln/core/concept/proxy.hh | 30 ++++
mln/core/concept/weighted_window.hh | 4
mln/core/internal/site_relative_iterator_base.hh | 2
mln/core/neighb.hh | 1
mln/core/w_window.hh | 64 ++++++++-
mln/geom/bbox.hh | 3
tests/core/alias/w_window1d_int.cc | 8 -
tests/core/alias/w_window2d_int.cc | 8 -
tests/core/alias/w_window3d_int.cc | 5
15 files changed, 302 insertions(+), 51 deletions(-)
Index: tests/core/alias/w_window1d_int.cc
--- tests/core/alias/w_window1d_int.cc (revision 2388)
+++ tests/core/alias/w_window1d_int.cc (working copy)
@@ -30,11 +30,12 @@
#include <mln/core/alias/w_window1d_int.hh>
#include <mln/win/segment1d.hh>
+#include <mln/convert/to.hh>
+#include <mln/convert/to.hh>
+#include <mln/convert/to_fun.hh>
#include <mln/convert/to_image.hh>
-#include <mln/convert/to_w_window.hh>
-#include <mln/convert/to_fun.hh>
#include <mln/estim/sum.hh>
@@ -53,7 +54,8 @@
w_window1d_int w_win = make::w_window1d(ws);
image1d<int> ima = convert::to_image(w_win);
- w_window1d_int w_win_2 = mln::convert::to<w_window1d_int>(ima);
+
+ w_window1d_int w_win_2 = convert::to<w_window1d_int>(ima);
mln_assertion(w_win_2 == w_win);
}
Index: tests/core/alias/w_window2d_int.cc
--- tests/core/alias/w_window2d_int.cc (revision 2388)
+++ tests/core/alias/w_window2d_int.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 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
@@ -33,10 +33,10 @@
#include <mln/core/alias/w_window2d_int.hh>
#include <mln/win/rectangle2d.hh>
+#include <mln/convert/to.hh>
#include <mln/convert/to_image.hh>
-#include <mln/convert/to_w_window.hh>
-
#include <mln/convert/to_fun.hh>
+
#include <mln/estim/sum.hh>
@@ -57,7 +57,7 @@
w_window2d_int w_win = make::w_window2d(ws);
image2d<int> ima = convert::to_image(w_win);
- w_window2d_int w_win_2 = convert::to_w_window(ima);
+ w_window2d_int w_win_2 = convert::to<w_window2d_int>(ima);
mln_assertion(w_win_2 == w_win);
}
Index: tests/core/alias/w_window3d_int.cc
--- tests/core/alias/w_window3d_int.cc (revision 2388)
+++ tests/core/alias/w_window3d_int.cc (working copy)
@@ -33,9 +33,8 @@
#include <mln/core/alias/w_window3d_int.hh>
#include <mln/win/cube3d.hh>
+#include <mln/convert/to.hh>
#include <mln/convert/to_image.hh>
-#include <mln/convert/to_w_window.hh>
-
#include <mln/convert/to_fun.hh>
#include <mln/estim/sum.hh>
@@ -67,7 +66,7 @@
image3d<int> ima = convert::to_image(w_win);
debug::println(ima);
std::cout << std::endl;
- w_window3d_int w_win_2 = convert::to_w_window(ima);
+ w_window3d_int w_win_2 = convert::to<w_window3d_int>(ima);
mln_assertion(w_win_2 == w_win);
}
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 2388)
+++ mln/core/w_window.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 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
@@ -35,11 +35,17 @@
# include <map>
-# include <mln/core/window.hh>
# include <mln/core/concept/weighted_window.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/window.hh>
# include <mln/core/dpsites_piter.hh>
+
# include <mln/value/ops.hh>
# include <mln/util/ord.hh>
+# include <mln/metal/converts_to.hh>
+# include <mln/literal/zero.hh>
+# include <mln/convert/to.hh>
+
namespace mln
{
@@ -109,8 +115,11 @@
const mln::window<D>& win() const;
- /// Apply a central symmetry to the target window.
- w_window<D,W>& sym();
+ /// Apply a central symmetry to the window.
+ void sym();
+
+ /// Clear this window.
+ void clear();
protected:
@@ -119,6 +128,17 @@
};
+ namespace convert
+ {
+
+ template <typename I, typename D, typename W>
+ inline
+ void
+ from_to(const Image<I>& from, w_window<D,W>& to);
+
+ } // end of namespace mln::convert
+
+
/* \brief Print a weighted window \p w_win into an output stream \p ostr.
* \relates mln::w_window
*/
@@ -268,16 +288,48 @@
template <typename D, typename W>
inline
- w_window<D,W>&
+ void
w_window<D,W>::sym()
{
w_window<D,W> tmp;
for (unsigned i = 0; i < this->size(); ++i)
tmp.insert(this->w(i), - this->dp(i));
*this = tmp;
- return *this;
}
+ template <typename D, typename W>
+ inline
+ void
+ w_window<D,W>::clear()
+ {
+ win_.clear();
+ wei_.clear();
+ }
+
+
+ // convert::from_to
+
+ namespace convert
+ {
+
+ template <typename I, typename D, typename W>
+ inline
+ void
+ from_to(const Image<I>& from_, w_window<D,W>& to)
+ {
+ mlc_converts_to(mln_deduce(I, psite, delta), D)::check();
+ mlc_converts_to(mln_value(I), W)::check();
+ const I& ima = exact(from_);
+ to.clear();
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ if (ima(p) != literal::zero)
+ to.insert(ima(p), convert::to<D>(p));
+ }
+
+ } // end of namespace mln::convert
+
+
// operators
template <typename D, typename W>
Index: mln/core/internal/site_relative_iterator_base.hh
--- mln/core/internal/site_relative_iterator_base.hh (revision 2388)
+++ mln/core/internal/site_relative_iterator_base.hh (working copy)
@@ -139,6 +139,8 @@
site_relative_iterator_base<S,E>::center_at(const P& c)
{
internal::get_adr(c_, c);
+ mln_precondition(c_ != 0);
+ // c_ == 0 means that the center c does not have the expected type.
this->invalidate();
}
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 2388)
+++ mln/core/neighb.hh (working copy)
@@ -42,7 +42,6 @@
# include <mln/core/concept/window.hh>
# include <mln/core/internal/neighborhood_base.hh>
# include <mln/core/internal/site_relative_iterator_base.hh>
-# include <mln/convert/from_to.hh>
Index: mln/core/concept/proxy.hh
--- mln/core/concept/proxy.hh (revision 2388)
+++ mln/core/concept/proxy.hh (working copy)
@@ -41,6 +41,7 @@
# include <mln/core/concept/object.hh>
# include <mln/value/ops.hh> // So that we can handle builtins, scalars, and
objects.
+# include <mln/convert/from_to.hxx>
# include <mln/core/concept/proxy.hxx>
@@ -200,6 +201,19 @@
};
+ // convert::from_to
+
+ namespace convert
+ {
+
+ template <typename P, typename T>
+ void
+ from_to(const Proxy<P>& from, T& to);
+
+ } // end of namespace mln::convert
+
+
+
// subject
template <typename T>
@@ -273,6 +287,22 @@
}
+
+ // convert::from_to
+
+ namespace convert
+ {
+
+ template <typename P, typename T>
+ void
+ from_to(const Proxy<P>& from, T& to)
+ {
+ from_to(exact(from).unproxy_(), to);
+ }
+
+ } // end of namespace mln::convert
+
+
// unproxy_rec
template <typename T>
Index: mln/core/concept/weighted_window.hh
--- mln/core/concept/weighted_window.hh (revision 2388)
+++ mln/core/concept/weighted_window.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 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
@@ -122,7 +122,7 @@
typedef mln_fwd_qiter(W) fwd_qiter;
typedef mln_bkd_qiter(W) bkd_qiter;
- W& (W::*m1)() = & W::sym;
+ void (W::*m1)() = & W::sym;
m1 = 0;
const window& (W::*m2)() const = & W::win;
Index: mln/core/concept/gpoint.hh
--- mln/core/concept/gpoint.hh (revision 2388)
+++ mln/core/concept/gpoint.hh (working copy)
@@ -113,6 +113,16 @@
};
+ namespace convert
+ {
+
+ template <typename P>
+ void
+ from_to(const Gpoint<P>& from, mln_delta(P)& to);
+
+ } // end of namespace::convert
+
+
/*! \brief Equality comparison between a couple of grid point \p lhs
* and \p rhs.
@@ -252,6 +262,7 @@
# ifndef MLN_INCLUDE_ONLY
+
// Gpoint
template <typename E>
@@ -265,6 +276,29 @@
m = 0;
}
+
+ // convert::from_to
+
+ namespace convert
+ {
+
+ template <typename P>
+ inline
+ void
+ from_to(const Gpoint<P>& p_, mln_delta(P)& dp)
+ {
+ // Instead of "dp.to_vec() = exact(p).to_vec();" that
+ // does not compile (cause to_vec returns const), we
+ // have:
+ enum { n = P::dim };
+ const P& p = exact(p_);
+ for (unsigned i = 0; i < n; ++i)
+ dp[i] = p[i];
+ }
+
+ } // end of namespace::convert
+
+
// Operators.
template <typename L, typename R>
Index: mln/convert/to.hh
--- mln/convert/to.hh (revision 2388)
+++ mln/convert/to.hh (working copy)
@@ -35,7 +35,10 @@
* \todo Prefer a static check that fails in the "unknown" case.
*/
-# include <mln/convert/from_to.hh>
+# include <mln/core/routine/exact.hh>
+# include <mln/metal/equal.hh>
+# include <mln/trace/all.hh>
+# include <mln/convert/from_to.hxx>
namespace mln
@@ -47,7 +50,6 @@
/// Conversion of the object \p from towards an object with type \c T.
template <typename T, typename O>
- inline
T
to(const O& from);
@@ -57,7 +59,6 @@
# ifndef MLN_INCLUDE_ONLY
-
template <typename T, typename O>
inline
T
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 2388)
+++ mln/convert/to_image.hh (working copy)
@@ -156,7 +156,8 @@
box<P> b = geom::bbox(win);
mln_image_from(W, bool) ima(b);
level::fill(ima, false);
- mln_qiter(W) q(win, P::origin);
+ P O = P::origin;
+ mln_qiter(W) q(win, O);
for_all(q)
ima(q) = true;
return ima;
Index: mln/convert/from_to.hh
--- mln/convert/from_to.hh (revision 2388)
+++ mln/convert/from_to.hh (working copy)
@@ -59,20 +59,11 @@
{
- /// Guards.
- template <typename F, typename T>
- void
- from_to(const F& from, Object<T>& to);
-
+ /// Guard.
template <typename F, typename T>
void
from_to(const Object<F>& from, Object<T>& to);
- template <typename F, typename T>
- void
- from_to(const Object<F>& from, T& to);
- /// end of Guards.
-
template <typename T>
void
@@ -87,29 +78,18 @@
# ifndef MLN_INCLUDE_ONLY
- /// Guards.
- template <typename F, typename T>
- void
- from_to(const F&, Object<T>&)
- {
- mlc_abort(F)::check();
- }
-
+ // Guard.
template <typename F, typename T>
void
from_to(const Object<F>&, Object<T>&)
{
+ // This particular from-to is not defined!
+ //
+ // Either this conversion is meaningless or an overload is
+ // missing.
mlc_abort(F)::check();
}
- template <typename F, typename T>
- void
- from_to(const Object<F>&, T&)
- {
- mlc_abort(F)::check();
- }
- /// end of Guards.
-
// Image -> Site_Set.
template <typename I, typename S>
Index: mln/convert/all.hh
--- mln/convert/all.hh (revision 2388)
+++ mln/convert/all.hh (working copy)
@@ -50,6 +50,5 @@
# include <mln/convert/to_tiles.hh>
# include <mln/convert/to_p_array.hh>
# include <mln/convert/to_window.hh>
-# include <mln/convert/to_w_window.hh>
#endif // ! MLN_CONVERT_ALL_HH
Index: mln/convert/from_to.hxx
--- mln/convert/from_to.hxx (revision 0)
+++ mln/convert/from_to.hxx (revision 0)
@@ -0,0 +1,151 @@
+// 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.
+
+#ifndef MLN_CONVERT_FROM_TO_HXX
+# define MLN_CONVERT_FROM_TO_HXX
+
+/// \internal \file mln/convert/from_to.hxx
+
+// All overloaded "convert::from_to" routines have to be declared in
+// the present file. It allows for *deferred* use of these routines.
+
+
+namespace mln
+{
+
+
+ // Forward declarations.
+
+ 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 D, typename W> class w_window;
+ template <typename D> class neighb;
+ template <typename D> class window;
+
+ namespace algebra {
+ template <unsigned n, typename T> class vec;
+ template <unsigned d, typename C> class h_vec;
+ }
+
+ namespace value {
+ template <unsigned n> struct rgb;
+ }
+
+ // end of Forward declarations.
+
+
+
+ // convert::to
+
+ namespace convert
+ {
+
+ template <typename T, typename O>
+ T
+ to(const O& from);
+
+ } // end of namespace mln::convert
+
+
+
+ // convert::from_to
+
+ namespace convert
+ {
+
+ // Guard.
+ template <typename F, typename T>
+ void
+ from_to(const Object<F>&, Object<T>&);
+
+ // Image -> Site_Set.
+ template <typename I, typename S>
+ void
+ from_to(const Image<I>& from, Site_Set<S>& to);
+
+ // algebra::vec -> Gpoint.
+ template <unsigned n, typename T, typename P>
+ void
+ from_to(const algebra::vec<n,T>& from, Gpoint<P>& to_);
+
+ // algebra::vec -> rgb.
+ template <typename T, unsigned m>
+ void
+ from_to(const algebra::vec<3,T>& from, value::rgb<m>& to);
+
+ // Value -> Value
+ template <typename F, typename T>
+ void
+ from_to(const Value<F>& from, Value<T>& to);
+
+ // float -> Object
+ template <typename T>
+ void
+ from_to(const float& from, Object<T>& to);
+
+ // int -> Object
+ template <typename T>
+ void
+ from_to(const int& from, Object<T>& to);
+
+ // Proxy -> T
+ template <typename P, typename T>
+ void
+ from_to(const Proxy<P>& from, T& to);
+
+ // Gpoint -> delta
+ template <typename P>
+ void
+ from_to(const Gpoint<P>& from, mln_delta(P)& to);
+
+ // Image -> w_window
+ template <typename I, typename D, typename W>
+ void
+ from_to(const Image<I>& from, w_window<D,W>& to);
+
+ // neighb<W> -> W
+ template <typename W>
+ void
+ from_to(const mln::neighb<W>& from, W& to);
+
+ // W -> neighb<W>
+ template <typename W>
+ void
+ from_to(const W& from, mln::neighb<W>& to);
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_FROM_TO_HXX
Index: mln/geom/bbox.hh
--- mln/geom/bbox.hh (revision 2388)
+++ mln/geom/bbox.hh (working copy)
@@ -145,7 +145,8 @@
{
typedef mln_psite(W) P;
accu::bbox<P> b;
- mln_qiter(W) q(exact(win), literal::origin);
+ P O = literal::origin;
+ mln_qiter(W) q(exact(win), O);
for_all(q)
b.take(q);
return b;