URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-03 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Fix image_if_interval. Does NOT compile yet !.
* mln/core/image_if_interval.hh: Update.
* tests/image_if_interval.cc: New.
---
mln/core/image_if_interval.hh | 116 ++++++++++++++++++++++++++++--------------
tests/image_if_interval.cc | 48 +++++++++++++++++
2 files changed, 128 insertions(+), 36 deletions(-)
Index: trunk/milena/tests/image_if_interval.cc
===================================================================
--- trunk/milena/tests/image_if_interval.cc (revision 0)
+++ trunk/milena/tests/image_if_interval.cc (revision 1228)
@@ -0,0 +1,48 @@
+// Copyright (C) 2007 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/image_if_value.cc
+ *
+ * \brief Tests on mln::image_if_value.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image_if_interval.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(3, 3);
+ debug::iota(ima);
+ debug::println(ima);
+ debug::println(ima | value::interval(4, 7) );
+}
Index: trunk/milena/mln/core/image_if_interval.hh
===================================================================
--- trunk/milena/mln/core/image_if_interval.hh (revision 1227)
+++ trunk/milena/mln/core/image_if_interval.hh (revision 1228)
@@ -34,18 +34,62 @@
*/
# include <mln/core/internal/image_if_base.hh>
+# include <mln/metal/unconst.hh>
+# include <mln/value/interval.hh>
+
+
+# define F fun::and_p2b_expr_< \
+ fun::geq_p2b_expr_< \
+ pw::value_<I>, \
+ pw::cst_<mln_value(I)> >, \
+ fun::leq_p2b_expr_< \
+ pw::value_<I>, \
+ pw::cst_<mln_value(I)> > > >
+
+# define Super mln::internal::image_if_base_< I, F, image_if_interval<I> >
+
namespace mln
{
+ // Fwd decl.
+ template <typename I> struct image_if_interval;
+
+
+ // internal::data_.
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< image_if_interval<I> > : data_< Super >
+ {
+ data_(I& ima, const F& f);
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct image_< image_if_interval<I> > : trait::image_< Super >
+ {
+ };
+
+ } // end of namespace mln::trait
+
+
+
/*! \brief An image class FIXME.
*
*/
- template <typename I, typename F>
- struct image_if_interval : public internal::image_if_base< I, F >
+ template <typename I>
+ struct image_if_interval : public Super
{
/// Skeleton.
- typedef image_if_interval< tag::image_<I>, tag::function_<F> >
skeleton;
+ typedef image_if_interval< tag::image_<I> > skeleton;
/// Constructor from an image \p ima and a predicate \p f.
image_if_interval(I& ima, const F& f);
@@ -54,7 +98,7 @@
image_if_interval();
/// Const promotion via convertion.
- operator image_if_interval<const I, F>() const;
+ operator image_if_interval<const I>() const;
};
// Operators.
@@ -62,69 +106,66 @@
// Image | [from, to].
template <typename I>
- image_if_interval< I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<I>
operator | (Image<I>& ima, const value::interval_<mln_value(I)>&
vv);
template <typename I>
- image_if_interval< const I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<const I>
operator | (const Image<I>& ima, const
value::interval_<mln_value(I)>& vv);
# ifndef MLN_INCLUDE_ONLY
- // image_if_interval<I,F>
+ // image_if_interval<I>
- template <typename I, typename F>
- image_if_interval<I,F>::image_if_interval()
+ template <typename I>
+ image_if_interval<I>::image_if_interval()
{
}
- template <typename I, typename F>
- image_if_interval<I,F>::image_if_interval(I& ima, const F& f)
+ template <typename I>
+ image_if_interval<I>::image_if_interval(I& ima, const F& f)
{
this->init_(ima, f);
}
- template <typename I, typename F>
- image_if_interval<I,F>::operator image_if_interval<const I, F>() const
+ template <typename I>
+ image_if_interval<I>::operator image_if_interval<const I, F>() const
{
- image_if_interval<const I, F> tmp(this->data_->ima_,
this->data_->pset_);
+ image_if_interval<const I> tmp(this->data_->ima_,
this->data_->pset_);
return tmp;
}
+ // internal::data_< image_if_interval<I> >
+
+ namespace internal
+ {
+
+ template <typename I>
+ data_< image_if_value<I> >::data_(I& ima, const F& f)
+ : data_< Super >(ima, f)
+ {
+ }
+
+ } // end of namespace mln::internal
+
// Operators.
template <typename I>
- image_if_interval< I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<I>
operator | (Image<I>& ima, const value::interval_<mln_value(I)>&
vv)
{
- return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
- (pw::value(ima) <= pw::cst(vv.to)) );
+ image_if_interval<I> tmp(exact(ima), vv);
+ return tmp;
}
template <typename I>
- image_if_interval< const I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<const I>
operator | (const Image<I>& ima, const
value::interval_<mln_value(I)>& vv)
{
- return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
- (pw::value(ima) <= pw::cst(vv.to)) );
+ image_if_interval<const I> tmp(exact(ima), vv);
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -132,4 +173,7 @@
} // end of namespace mln
+# undef Super
+# undef F
+
#endif // ! MLN_CORE_IMAGE_IF_INTERVAL_HH