https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Handle const promotion for morphers.
* mln/core/internal/image_adaptor.hh (operator I): New.
(pset_): Remove; uncompatible with temporary pset.
(domain): Change sig.
* mln/core/inplace.hh: New.
* tests/line2d.cc: Augment; use inplace.
* mln/core/sub_image.hh: New.
* tests/sub_image.cc: New.
* mln/core/safe.hh (safe): New overload; const version.
(safe_image): Update.
(default_value): New.
(operator safe_image<const I>): New.
* tests/safe_image.cc: Augment.
* mln/core/queue_p.hh (push): Fix missing return.
* mln/core/internal/image_base.hh: Add doc.
* mln/core/pset_if_piter.hh (fixme): Remove include; useless.
* mln/core/vec_p_piter.hh: Likewise.
* mln/make/box2d: Change arg list (all min first).
* tests/to_image.cc: Update.
mln/core/image_if.hh | 10 ++
mln/core/inplace.hh | 63 ++++++++++++++++++
mln/core/internal/image_adaptor.hh | 19 +++--
mln/core/internal/image_base.hh | 27 +++++--
mln/core/pset_if_piter.hh | 1
mln/core/queue_p.hh | 1
mln/core/safe.hh | 62 +++++++++++++----
mln/core/sub_image.hh | 129 +++++++++++++++++++++++++++++++++++++
mln/core/vec_p_piter.hh | 1
mln/make/box2d.hh | 10 +-
tests/line2d.cc | 9 ++
tests/safe_image.cc | 30 +++++++-
tests/sub_image.cc | 53 +++++++++++++++
tests/to_image.cc | 4 -
14 files changed, 378 insertions(+), 41 deletions(-)
Index: tests/sub_image.cc
--- tests/sub_image.cc (revision 0)
+++ tests/sub_image.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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/sub_image.cc
+ *
+ * \brief Tests on mln::sub_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/level/fill.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(8, 8);
+ level::fill(ima, 0);
+ debug::println(ima);
+
+ level::fill(inplace(ima | make::box2d(1,1, 3,3)), 5);
+ level::fill(inplace(ima | make::box2d(4,4, 6,6)), 1);
+
+ debug::println(ima);
+}
Index: tests/line2d.cc
--- tests/line2d.cc (revision 1048)
+++ tests/line2d.cc (working copy)
@@ -33,10 +33,13 @@
#include <iterator>
#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/inplace.hh>
#include <mln/level/fill.hh>
#include <mln/level/compare.hh>
#include <mln/draw/line.hh>
+#include <mln/debug/println.hh>
int main()
@@ -56,4 +59,10 @@
level::paste(pw::cst(true) | l, ima2);
mln_assertion(ima2 = ima);
+
+ image2d_b<bool> ima3(10,10);
+ level::fill(ima3, false);
+ level::fill(inplace(ima3 | l), true);
+
+ mln_assertion(ima3 = ima);
}
Index: tests/to_image.cc
--- tests/to_image.cc (revision 1048)
+++ tests/to_image.cc (working copy)
@@ -47,9 +47,9 @@
{
using namespace mln;
- box2d box_3x3 = make::box2d(-1,+1, -1,+1);
+ box2d box_3x3 = make::box2d(-1,-1, +1,+1);
// ^^^^^ ^^^^^
- // rows cols
+ // from to
// center point
// V
Index: tests/safe_image.cc
--- tests/safe_image.cc (revision 1048)
+++ tests/safe_image.cc (working copy)
@@ -32,7 +32,6 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/safe.hh>
-#include <mln/level/paste.hh>
int main()
@@ -41,9 +40,30 @@
typedef image2d_b<int> I;
I ima(1, 1);
- safe_image<I> ima_ = safe(ima);
+ point2d
+ in = make::point2d(0, 0),
+ out = make::point2d(-999, -999);
+
+ {
+ safe_image<I> ima_ = safe(ima, 7);
+
+ ima_(in) = 51;
+ mln_assertion(ima_(in) = 51);
+
+ ima_(out) = 0;
+ mln_assertion(ima_(out) = 7);
+
+ // test "image_adaptor_<..>::operator I() const"
+ I ima2 = ima_;
+ const I ima3 = ima_;
+ }
+
+ {
+ safe_image<const I> ima_ = safe(ima, 7);
+
+ ima(in) = 51;
+ mln_assertion(ima_(in) = 51);
+ mln_assertion(ima_(out) = 7);
+ }
- point2d p = make::point2d(-5, -1);
- ima_(p) = 0;
- level::paste(ima, ima_);
}
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 1048)
+++ mln/core/image_if.hh (working copy)
@@ -66,6 +66,9 @@
typedef image_if<mln_ch_value(I,T), F> ret;
};
+ /// Const promotion via convertion.
+ operator image_if<const I, F>() const;
+
protected:
pset pset_;
@@ -110,6 +113,13 @@
return pset_;
}
+ template <typename I, typename F>
+ image_if<I,F>::operator image_if<const I, F>() const
+ {
+ image_if<const I, F> tmp(this->adaptee_, this->f_);
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/queue_p.hh
--- mln/core/queue_p.hh (revision 1048)
+++ mln/core/queue_p.hh (working copy)
@@ -196,6 +196,7 @@
vect_needs_update_ = true;
bb_needs_update_ = true;
}
+ return *this;
}
template <typename P>
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1048)
+++ mln/core/safe.hh (working copy)
@@ -37,14 +37,17 @@
// FIXME: Doc!
template <typename I>
- struct safe_image : public internal::image_adaptor_< I, safe_image<I> >
+ class safe_image : public internal::image_adaptor_< I, safe_image<I> >
{
- typedef internal::image_adaptor_< I, safe_image<I> > super;
+ typedef internal::image_adaptor_< I, safe_image<I> > super_;
+ public:
- safe_image(Image<I>& ima);
+ safe_image(I& ima, const mln_value(I)& default_value);
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
- mln_lvalue(I) operator()(const mln_psite(I)& p);
+
+ typedef typename super_::lvalue lvalue;
+ lvalue operator()(const mln_psite(I)& p);
template <typename U>
struct change_value
@@ -52,20 +55,33 @@
typedef safe_image<mln_ch_value(I, U)> ret;
};
+ /// Const promotion via convertion.
+ operator safe_image<const I>() const;
+
+ protected:
+ mln_value(I) default_value_;
};
template <typename I>
- safe_image<I> safe(Image<I>& ima);
+ safe_image<I> safe(Image<I>& ima,
+ mln_value(I) default_value = mln_value(I)());
+
+ template <typename I>
+ safe_image<const I> safe(const Image<I>& ima,
+ mln_value(I) default_value = mln_value(I)());
# ifndef MLN_INCLUDE_ONLY
+ // safe_image<I>
+
template <typename I>
- safe_image<I>::safe_image(Image<I>& ima)
- : super(exact(ima))
+ safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
+ : super_(exact(ima)),
+ default_value_(default_value)
{
}
@@ -73,26 +89,44 @@
mln_rvalue(I)
safe_image<I>::operator()(const mln_psite(I)& p) const
{
- static mln_value(I) tmp;
if (! this->owns_(p))
- return tmp;
+ return default_value_;
return this->adaptee_(p);
}
template <typename I>
- mln_lvalue(I)
+ typename safe_image<I>::lvalue
safe_image<I>::operator()(const mln_psite(I)& p)
{
- static mln_value(I) tmp;
+ static mln_value(I) forget_it_;
if (! this->owns_(p))
- return tmp;
+ // so default_value_ is returned but cannot be modified
+ return forget_it_ = default_value_;
return this->adaptee_(p);
}
template <typename I>
- safe_image<I> safe(Image<I>& ima)
+ safe_image<I>::operator safe_image<const I>() const
+ {
+ safe_image<const I> tmp(this->adaptee_, default_value_);
+ return tmp;
+ }
+
+ // safe
+
+ template <typename I>
+ safe_image<I> safe(Image<I>& ima,
+ mln_value(I) default_value)
+ {
+ safe_image<I> tmp(exact(ima), default_value);
+ return tmp;
+ }
+
+ template <typename I>
+ safe_image<const I> safe(const Image<I>& ima,
+ mln_value(I) default_value)
{
- safe_image<I> tmp(ima);
+ safe_image<const I> tmp(exact(ima), default_value);
return tmp;
}
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1048)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -78,7 +78,7 @@
bool owns_(const psite& p) const;
/// Give the definition domain.
- const S& domain() const;
+ const mln_pset(I)& domain() const;
/// Give the set of values.
const vset& values() const;
@@ -89,6 +89,8 @@
/// Read-write access of pixel value at point site \p p.
lvalue operator()(const psite& p);
+ /// Convertion to the underlying (adapted) image.
+ operator I() const;
protected:
I& adaptee_;
@@ -97,13 +99,17 @@
image_adaptor_(I& adaptee);
};
- // FIXME: image_const_adaptor_
-
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename E, typename S>
+ image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
+ : adaptee_(adaptee)
+ {
+ }
+
+ template <typename I, typename E, typename S>
bool image_adaptor_<I,E,S>::has_data() const
{
return adaptee_.has_data();
@@ -117,7 +123,7 @@
}
template <typename I, typename E, typename S>
- const S&
+ const mln_pset(I)&
image_adaptor_<I,E,S>::domain() const
{
mln_precondition(exact(this)->has_data());
@@ -148,9 +154,10 @@
}
template <typename I, typename E, typename S>
- image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
- : adaptee_(adaptee)
+ image_adaptor_<I,E,S>::operator I() const
{
+ mln_precondition(exact(this)->has_data());
+ return adaptee_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1048)
+++ mln/core/internal/image_base.hh (working copy)
@@ -43,6 +43,11 @@
{
+ /*! \brief Return the lvalue type when an image with type \c I is
+ * morphed.
+ *
+ * \internal
+ */
template <typename I>
struct morpher_lvalue_
{
@@ -56,7 +61,10 @@
};
-
+ /*! \brief Selector for image inheritance (fast or regular).
+ *
+ * \internal
+ */
template <typename Is_fast, typename E>
struct select_image_concept_;
@@ -77,7 +85,9 @@
* \internal
*/
template <typename S, typename E>
- struct image_base_ : public select_image_concept_< typename trait::is_fast<E>::ret,
+ struct image_base_
+
+ : public select_image_concept_< typename trait::is_fast<E>::ret,
E >
{
/// Point_Set associated type.
@@ -113,6 +123,9 @@
/// Give the number of points of the image domain.
std::size_t npoints() const;
+
+ // FIXME: Add owns_(p) based on has(p)?
+
protected:
image_base_();
};
@@ -121,6 +134,11 @@
# ifndef MLN_INCLUDE_ONLY
template <typename S, typename E>
+ image_base_<S,E>::image_base_()
+ {
+ }
+
+ template <typename S, typename E>
bool
image_base_<S,E>::has(const psite& p) const
{
@@ -144,11 +162,6 @@
return exact(this)->domain().npoints();
}
- template <typename S, typename E>
- image_base_<S,E>::image_base_()
- {
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
Index: mln/core/sub_image.hh
--- mln/core/sub_image.hh (revision 0)
+++ mln/core/sub_image.hh (revision 0)
@@ -0,0 +1,129 @@
+// 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.
+
+#ifndef MLN_CORE_SUB_IMAGE_HH
+# define MLN_CORE_SUB_IMAGE_HH
+
+# include <mln/core/internal/image_adaptor.hh>
+
+
+namespace mln
+{
+
+ // FIXME: Doc!
+
+ template <typename I, typename S>
+ class sub_image : public internal::image_adaptor_< I,
+ sub_image<I,S>,
+ S >
+ {
+ typedef internal::image_adaptor_<I, sub_image<I,S>, S> super_;
+ public:
+
+ sub_image(I& ima, const S& pset);
+
+ bool owns_(const mln_psite(I)& p) const;
+
+ template <typename U>
+ struct change_value
+ {
+ typedef internal::fixme ret;
+ };
+
+ const S& domain() const;
+
+ /// Const promotion via convertion.
+ operator sub_image<const I, S>() const;
+
+ protected:
+ const S& pset_;
+ };
+
+
+
+ template <typename I, typename S>
+ sub_image<const I, S> operator|(const Image<I>& ima, const Point_Set<S>& pset);
+
+ template <typename I, typename S>
+ sub_image<I, S> operator|(Image<I>& ima, const Point_Set<S>& pset);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename S>
+ sub_image<I,S>::sub_image(I& ima, const S& pset)
+ : super_(ima),
+ pset_(pset)
+ {
+ }
+
+ template <typename I, typename S>
+ bool
+ sub_image<I,S>::owns_(const mln_psite(I)& p) const
+ {
+ return this->domain().has(p);
+ }
+
+ template <typename I, typename S>
+ const S&
+ sub_image<I,S>::domain() const
+ {
+ return pset_;
+ }
+
+ template <typename I, typename S>
+ sub_image<I,S>::operator sub_image<const I, S>() const
+ {
+ sub_image<const I, S> tmp(this->adaptee_, this->pset_);
+ return tmp;
+ }
+
+ // operator
+
+ template <typename I, typename S>
+ sub_image<const I, S>
+ operator|(const Image<I>& ima, const Point_Set<S>& pset)
+ {
+ sub_image<const I, S> tmp(exact(ima), exact(pset));
+ return tmp;
+ }
+
+ template <typename I, typename S>
+ sub_image<I, S>
+ operator|(Image<I>& ima, const Point_Set<S>& pset)
+ {
+ sub_image<I, S> tmp(exact(ima), exact(pset));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SUB_IMAGE_HH
Index: mln/core/pset_if_piter.hh
--- mln/core/pset_if_piter.hh (revision 1048)
+++ mln/core/pset_if_piter.hh (working copy)
@@ -35,7 +35,6 @@
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/internal/piter_adaptor.hh>
-# include <mln/core/internal/fixme.hh>
# include <mln/core/pset_if.hh>
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1048)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -34,7 +34,6 @@
*/
# include <mln/core/vec_p.hh>
-# include <mln/core/internal/fixme.hh>
namespace mln
Index: mln/core/inplace.hh
--- mln/core/inplace.hh (revision 0)
+++ mln/core/inplace.hh (revision 0)
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef MLN_CORE_INPLACE_HH
+# define MLN_CORE_INPLACE_HH
+
+/*! \file mln/core/inplace.hh
+ * \brief Definition of the mln::inplace routine.
+ */
+
+# include <mln/core/exact.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Routine to make temporary objects become mutable.
+ *
+ * \warning This routine is not safe! FIXME: Explain.
+ */
+ template <typename E>
+ E& inplace(const Object<E>& temp);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ E& inplace(const Object<E>& temp)
+ {
+ return const_cast<E&>( exact(temp) );
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INPLACE_HH
Index: mln/make/box2d.hh
--- mln/make/box2d.hh (revision 1048)
+++ mln/make/box2d.hh (working copy)
@@ -60,16 +60,16 @@
* \overload
*
* \param[in] min_row Index of the top most row.
- * \param[in] max_row Index of the botton most row.
* \param[in] min_col Index of the left most column.
+ * \param[in] max_row Index of the botton most row.
* \param[in] max_col Index of the right most column.
*
* \pre \p max_row >= \p min_row and \p max_col >= \p min_col.
*
* \return A 2D box.
*/
- mln::box2d box2d(int min_row, int max_row,
- int min_col, int max_col);
+ mln::box2d box2d(int min_row, int min_col,
+ int max_row, int max_col);
# ifndef MLN_INCLUDE_ONLY
@@ -82,8 +82,8 @@
return tmp;
}
- mln::box2d box2d(int min_row, int max_row,
- int min_col, int max_col)
+ mln::box2d box2d(int min_row, int min_col,
+ int max_row, int max_col)
{
mln_precondition(max_row >= min_row && max_col >= min_col);
mln::box2d tmp(make::point2d(min_row, min_col),
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Renaming.
* mln/core/fimage.hh,
* tests/fimage.cc: Rename as...
* mln/pw/image.hh,
* tests/pw_image.cc: ...these.
* mln/pw/all.hh,
* mln/draw/line.hh,
* tests/line2d.cc: Update.
* mln/core/pqueue.hh,
* mln/core/pvec.hh,
* mln/core/pvec_piter.hh,
* mln/core/pset.hh,
* tests/pqueue.cc,
* tests/pset.cc: Rename as...
* mln/core/queue_p.hh,
* mln/core/vec_p.hh,
* mln/core/vec_p_piter.hh,
* mln/core/set_p.hh,
* tests/queue_p.cc,
* tests/set_p.cc: ...these.
* mln/core/line2d.hh: Update.
* mln/core/psubset.hh,
* mln/core/psubset_piter.hh,
* mln/core/subimage.hh,
* tests/psubset.cc,
* tests/subimage.cc: Rename as...
* mln/core/pset_if.hh,
* mln/core/pset_if_piter.hh,
* mln/core/image_if.hh,
* tests/pset_if.cc,
* tests/image_if.cc: ...these.
* tests/to_image.cc: Update.
* mln/accu/counter.hh: Rename as...
* mln/accu/count.hh: ...this.
* mln/accu/count.hh,
* mln/accu/mean.hh,
* mln/accu/sum.hh (operator+=): New.
* mln/value/props.hh (mln_sum, sum): New.
* mln/accu/mean.hh,
* mln/accu/sum.hh,
* mln/value/int_u.hh,
* mln/value/int_s.hh: Update.
* mln/level/apply.hh: Move accumulator version into...
* mln/level/take.hh: ...this new file.
* mln/level/run.hh: New.
* mln/estim/mean.hh: Update.
* mln/core/internal/set_of.hh (operator=): Remove;
too error-prone.
* mln/core/concept/window.hh (operator=): New.
* tests/rectangle2d.cc: Fix.
mln/accu/count.hh | 119 ++++++++++++++++++++
mln/accu/mean.hh | 26 +++-
mln/accu/sum.hh | 19 ++-
mln/core/concept/window.hh | 28 ++++
mln/core/image_if.hh | 118 ++++++++++++++++++++
mln/core/internal/set_of.hh | 22 ---
mln/core/line2d.hh | 6 -
mln/core/pset_if.hh | 191 +++++++++++++++++++++++++++++++++
mln/core/pset_if_piter.hh | 125 +++++++++++++++++++++
mln/core/queue_p.hh | 253 ++++++++++++++++++++++++++++++++++++++++++++
mln/core/set_p.hh | 162 ++++++++++++++++++++++++++++
mln/core/vec_p.hh | 208 ++++++++++++++++++++++++++++++++++++
mln/core/vec_p_piter.hh | 172 +++++++++++++++++++++++++++++
mln/draw/line.hh | 30 +----
mln/estim/mean.hh | 28 +---
mln/level/apply.hh | 51 ++++----
mln/level/run.hh | 79 +++++++++++++
mln/level/take.hh | 102 +++++++++++++++++
mln/pw/all.hh | 1
mln/pw/image.hh | 192 +++++++++++++++++++++++++++++++++
mln/value/int_s.hh | 1
mln/value/int_u.hh | 1
mln/value/props.hh | 13 ++
tests/image_if.cc | 46 ++++++++
tests/line2d.cc | 7 -
tests/mean.cc | 53 +++++++++
tests/pset_if.cc | 45 +++++++
tests/pw_image.cc | 44 +++++++
tests/queue_p.cc | 57 +++++++++
tests/rectangle2d.cc | 2
tests/set_p.cc | 59 ++++++++++
tests/to_image.cc | 2
32 files changed, 2152 insertions(+), 110 deletions(-)
Index: tests/set_p.cc
--- tests/set_p.cc (revision 0)
+++ tests/set_p.cc (revision 0)
@@ -0,0 +1,59 @@
+// 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/set_p.cc
+ *
+ * \brief Tests on mln::set_p.
+ */
+
+#include <iterator>
+
+#include <mln/core/point2d.hh>
+#include <mln/core/set_p.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ set_p<point2d> ps;
+ ps
+ .insert(make::point2d(6, 9))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(5, 1));
+ mln_assertion(ps.npoints() = 3);
+
+ std::cout << ps.bbox() << std::endl;
+
+ std::copy(ps.vect().begin(), ps.vect().end(),
+ std::ostream_iterator<point2d>(std::cout, " "));
+ std::cout << std::endl;
+
+
+}
Index: tests/line2d.cc
--- tests/line2d.cc (revision 1047)
+++ tests/line2d.cc (working copy)
@@ -35,13 +35,8 @@
#include <mln/core/image2d_b.hh>
#include <mln/level/fill.hh>
-#include <mln/draw/line.hh>
-#include <mln/debug/println.hh>
-
-#include <mln/core/fimage.hh>
-#include <mln/pw/cst.hh>
-#include <mln/level/paste.hh>
#include <mln/level/compare.hh>
+#include <mln/draw/line.hh>
int main()
Index: tests/mean.cc
--- tests/mean.cc (revision 0)
+++ tests/mean.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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/assign.cc
+ *
+ * \brief Tests on mln::level::assign.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/estim/mean.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d_b<int_u8> ima(3, 3);
+ debug::iota(ima);
+ // 1 2 3
+ // 4 5 6
+ // 7 8 9
+ mln_assertion(estim::mean(ima) = 5);
+
+ // FIXME: Add example on accu::mean used several times.
+}
Index: tests/to_image.cc
--- tests/to_image.cc (revision 1047)
+++ tests/to_image.cc (working copy)
@@ -32,7 +32,7 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/window2d.hh>
-#include <mln/core/psubset.hh>
+#include <mln/core/pset_if.hh>
#include <mln/fun/p2b/chess.hh>
#include <mln/level/compare.hh>
Index: tests/pw_image.cc
--- tests/pw_image.cc (revision 0)
+++ tests/pw_image.cc (revision 0)
@@ -0,0 +1,44 @@
+// 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/fimage.cc
+ *
+ * \brief Tests on mln::fimage.
+ */
+
+#include <mln/fun/p2b/chess.hh>
+#include <mln/core/box2d.hh>
+#include <mln/pw/image.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ debug::println( fun::p2b::chess | make::box2d(8, 8) );
+}
Index: tests/rectangle2d.cc
--- tests/rectangle2d.cc (revision 1047)
+++ tests/rectangle2d.cc (working copy)
@@ -44,6 +44,6 @@
mln_assertion(rec.is_centered());
mln_assertion(rec.is_symmetric());
mln_assertion(rec = -rec);
- mln_assertion(rec.nelements() = h * w);
+ mln_assertion(rec.ndpoints() = h * w);
}
Index: tests/image_if.cc
--- tests/image_if.cc (revision 0)
+++ tests/image_if.cc (revision 0)
@@ -0,0 +1,46 @@
+// 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.cc
+ *
+ * \brief Tests on mln::image_if.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(8, 8);
+ // debug::println(ima | fun::p2b::chess);
+ mln_assertion((ima | fun::p2b::chess).npoints() = 32);
+}
Index: tests/queue_p.cc
--- tests/queue_p.cc (revision 0)
+++ tests/queue_p.cc (revision 0)
@@ -0,0 +1,57 @@
+// 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/queue_p.cc
+ *
+ * \brief Tests on mln::queue_p.
+ */
+
+#include <mln/core/point2d.hh>
+#include <mln/core/queue_p.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ queue_p<point2d> q;
+ q
+ .push(make::point2d(6, 9))
+ .push(make::point2d(5, 1))
+ .push(make::point2d(4, 2));
+ mln_assertion(q.npoints() = 3);
+
+ std::cout << q.bbox() << std::endl;
+ std::cout << q << std::endl;
+
+ q.pop();
+ mln_assertion(q.npoints() = 2);
+ point2d p = q.front();
+ mln_assertion(q.npoints() = 2);
+ mln_assertion(p = make::point2d(5, 1));
+}
Index: tests/pset_if.cc
--- tests/pset_if.cc (revision 0)
+++ tests/pset_if.cc (revision 0)
@@ -0,0 +1,45 @@
+// 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/pset_if.cc
+ *
+ * \brief Tests on mln::pset_if.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/pset_if.hh>
+#include <mln/fun/p2b/chess.hh>
+#include <mln/convert/to_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d box_8x8 = make::box2d(8, 8);
+ mln_assertion((box_8x8 | fun::p2b::chess).npoints() = 32);
+}
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1047)
+++ mln/estim/mean.hh (working copy)
@@ -33,8 +33,8 @@
* \brief Compute the mean pixel value.
*/
-# include <mln/core/concept/image.hh>
# include <mln/accu/mean.hh>
+# include <mln/level/run.hh>
namespace mln
@@ -43,32 +43,22 @@
namespace estim
{
-
/*! \brief Compute the mean value of the pixels of image \p input.
*
- * Parameter \c S is the type of the mean value.
+ * \param[in] input The image.
*/
- template <typename S, typename I>
- S mean(const Image<I>& input);
-
+ template <typename I>
+ mln_sum(mln_value(I)) mean(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
- template <typename S, typename I>
- S
- mean(const Image<I>& input_)
+ template <typename I>
+ mln_sum(mln_value(I)) mean(const Image<I>& input)
{
- const I& input = exact(input_);
- mln_precondition(input.has_data());
-
- accu::mean<mln_value(I), S> m;
-
- mln_piter(I) p(input.domain());
- for_all(p)
- m.take(input(p));
-
- return m;
+ typedef mln_value(I) V;
+ typedef mln_sum(V) S;
+ return level::run(input, accu::mean<V, S>());
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/pw/image.hh
--- mln/pw/image.hh (revision 0)
+++ mln/pw/image.hh (revision 0)
@@ -0,0 +1,192 @@
+// 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.
+
+#ifndef MLN_PW_IMAGE_HH
+# define MLN_PW_IMAGE_HH
+
+/*! \file mln/pw/image.hh
+ *
+ * \brief Definition of an image class FIXME
+ */
+
+# include <mln/core/internal/image_base.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ namespace pw { template <typename F, typename S> struct image; }
+
+
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename F, typename S>
+ pw::image<F,S>
+ operator | (const Function_p2v<F>& f, const Point_Set<S>& ps);
+
+
+
+ namespace pw
+ {
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename F, typename S>
+ struct image : public internal::image_base_< S, image<F,S> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point_Set associated type.
+ typedef S pset;
+
+ /// Value associated type.
+ typedef mln_result(F) value;
+
+ /// Return type of read-only access.
+ typedef mln_result(F) rvalue;
+
+ /// Return type of read-write access.
+ typedef void lvalue; // FIXME
+
+ /// Value set associated type.
+ typedef mln::value::set<mln_result(F)> vset;
+
+
+ /// Constructor.
+ image(const Function_p2v<F>& f, const Point_Set<S>& ps);
+
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const psite& p) const;
+
+ /// Give the definition domain.
+ const S& domain() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_result(F) operator()(const psite& p) const;
+
+ /// Read-write access is present but disabled.
+ void operator()(const psite&);
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Change value type. FIXME!
+ template <typename U>
+ struct change_value
+ {
+ typedef void ret;
+ };
+
+ protected:
+ F f_;
+ S pset_;
+ };
+
+ } // end of namespace mln::pw
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename F, typename S>
+ pw::image<F,S>
+ operator | (const Function_p2v<F>& f, const Point_Set<S>& ps)
+ {
+ pw::image<F,S> tmp(f, ps);
+ return tmp;
+ }
+
+ namespace pw
+ {
+
+ template <typename F, typename S>
+ image<F,S>::image(const Function_p2v<F>& f, const Point_Set<S>& ps)
+ : f_(exact(f)),
+ pset_(exact(ps))
+ {
+ }
+
+ template <typename F, typename S>
+ bool image<F,S>::has_data() const
+ {
+ return true;
+ }
+
+ template <typename F, typename S>
+ bool image<F,S>::owns_(const psite& p) const
+ {
+ return pset_.has(p);
+ }
+
+ template <typename F, typename S>
+ const S&
+ image<F,S>::domain() const
+ {
+ return pset_;
+ }
+
+ template <typename F, typename S>
+ mln_result(F)
+ image<F,S>::operator()(const psite& p) const
+ {
+ mln_precondition(pset_.has(p));
+ return f_(p);
+ }
+
+ template <typename F, typename S>
+ void
+ image<F,S>::operator()(const psite&)
+ {
+ mln_invariant(0); // FIXME: Turn into a compile-time error...
+ }
+
+ template <typename F, typename S>
+ const mln::value::set<mln_result(F)>&
+ image<F,S>::values() const
+ {
+ return vset::the();
+ }
+
+ } // end of namespace mln::pw
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_PW_IMAGE_HH
Index: mln/pw/all.hh
--- mln/pw/all.hh (revision 1047)
+++ mln/pw/all.hh (working copy)
@@ -47,6 +47,7 @@
# include <mln/pw/value.hh>
# include <mln/pw/cst.hh>
# include <mln/pw/var.hh>
+# include <mln/pw/image.hh>
# include <mln/fun/ops.hh>
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 0)
+++ mln/core/image_if.hh (revision 0)
@@ -0,0 +1,118 @@
+// 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.
+
+#ifndef MLN_CORE_IMAGE_IF_HH
+# define MLN_CORE_IMAGE_IF_HH
+
+/*! \file mln/core/image_if.hh
+ *
+ * \brief Definition of a base class for image adaptors.
+ */
+
+# include <mln/core/internal/image_adaptor.hh>
+# include <mln/core/pset_if.hh>
+
+
+namespace mln
+{
+
+ /*! \brief A base class for image adaptors.
+ *
+ */
+ template <typename I, typename F>
+ struct image_if : public internal::image_adaptor_< I,
+ image_if<I,F>,
+ pset_if<mln_pset(I),F> >
+ {
+ /// Point_Set associated type.
+ typedef pset_if<mln_pset(I), F> pset;
+
+ /// Constructor from an \p adaptee image.
+ image_if(I& adaptee, const F& f);
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_psite(I)& p) const;
+
+ /// Give the definition domain.
+ const pset& domain() const;
+
+ template <typename T>
+ struct change_value
+ {
+ typedef image_if<mln_ch_value(I,T), F> ret;
+ };
+
+ protected:
+
+ pset pset_;
+ F f_;
+
+ typedef image_if<I,F> self_;
+ typedef internal::image_adaptor_< I, self_, pset > super_;
+ };
+
+
+
+ template <typename I, typename F>
+ image_if<I, F>
+ operator | (Image<I>& ima, const Function_p2b<F>& f)
+ {
+ image_if<I, F> tmp(exact(ima), exact(f));
+ return tmp;
+ }
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename F>
+ image_if<I,F>::image_if(I& adaptee, const F& f)
+ : super_(adaptee),
+ pset_(adaptee.domain() | f),
+ f_(f)
+ {
+ }
+
+ template <typename I, typename F>
+ bool
+ image_if<I,F>::owns_(const mln_psite(I)& p) const
+ {
+ return pset_.has(p);
+ }
+
+ template <typename I, typename F>
+ const pset_if<mln_pset(I), F>&
+ image_if<I,F>::domain() const
+ {
+ return pset_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_IF_HH
Index: mln/core/queue_p.hh
--- mln/core/queue_p.hh (revision 0)
+++ mln/core/queue_p.hh (revision 0)
@@ -0,0 +1,253 @@
+// 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.
+
+#ifndef MLN_CORE_QUEUE_P_HH
+# define MLN_CORE_QUEUE_P_HH
+
+/*! \file mln/core/queue_p.hh
+ *
+ * \brief Definition of a point set class based on std::deque.
+ */
+
+# include <vector>
+# include <deque>
+# include <algorithm>
+# include <iterator>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/vec_p_piter.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct vec_p_fwd_piter_;
+ template <typename P> struct vec_p_bkd_piter_;
+
+
+ /*! \brief Point queue class (based on std::deque).
+ *
+ * This is a mathematical set of points (unique insertion).
+ *
+ * \todo Make it work with P being a Point_Site.
+ * \todo Add a parameter flag to choose another policy for "push"
+ * (i.e., no-op if multiple or allow multiple insertions).
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints() when this container is multiple.
+ */
+ template <typename P>
+ class queue_p : public Point_Set< queue_p<P> >
+ {
+ public:
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ queue_p();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Push a point \p p in the queue.
+ queue_p<P>& push(const P& p);
+
+ /// Pop (remove) the front point \p p from the queue; \p p is the
+ /// least recently inserted point.
+ void pop();
+
+ /// Give the front point \p p of the queue; \p p is the least
+ /// recently inserted point.
+ const P& front() const;
+
+ /// Clear the queue.
+ void clear();
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<P>& vect() const;
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ protected:
+
+ std::deque<P> q_;
+
+ mutable std::vector<P> vect_;
+ mutable bool vect_needs_update_;
+ void vect_update_() const;
+
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+ void bb_update_() const;
+
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ queue_p<P>::queue_p()
+ {
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::vect_update_() const
+ {
+ vect_.clear();
+ vect_.reserve(q_.size());
+ std::copy(q_.begin(), q_.end(),
+ std::back_inserter(vect_));
+ vect_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::bb_update_() const
+ {
+ bb_.init();
+ for (unsigned i = 0; i < q_.size(); ++i)
+ bb_.take(q_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ queue_p<P>::has(const P& p) const
+ {
+ for (unsigned i = 0; i < q_.size(); ++i)
+ if (q_[i] = p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ std::size_t
+ queue_p<P>::npoints() const
+ {
+ return q_.size();
+ }
+
+ template <typename P>
+ const box_<P>&
+ queue_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ bb_update_();
+ return bb_.to_value();
+ }
+
+ template <typename P>
+ queue_p<P>&
+ queue_p<P>::push(const P& p)
+ {
+ mln_precondition(! has(p));
+ // FIXME: Our choice is "error if multiple insertions"
+ q_.push_back(p);
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::pop()
+ {
+ q_.pop_front();
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ const P&
+ queue_p<P>::front() const
+ {
+ mln_precondition(! q_.empty());
+ return q_.front();
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::clear()
+ {
+ q_.clear();
+ vect_.clear();
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ queue_p<P>::vect() const
+ {
+ if (vect_needs_update_)
+ vect_update_();
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ queue_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return q_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_QUEUE_P_HH
Index: mln/core/internal/set_of.hh
--- mln/core/internal/set_of.hh (revision 1047)
+++ mln/core/internal/set_of.hh (working copy)
@@ -173,16 +173,6 @@
std::ostream& operator<<(std::ostream& ostr, const set_of_<E>& s);
- /*! \brief Test if both sets \p lhs and \p rhs are equal.
- *
- * \param[in] lhs A set.
- * \param[in] rhs Another set.
- *
- * \relates mln::internal::set_of_
- */
- template <typename E>
- bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs);
-
# ifndef MLN_INCLUDE_ONLY
@@ -279,18 +269,6 @@
return ostr;
}
- template <typename E>
- bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs)
- {
- if (lhs.nelements() != rhs.nelements())
- return false;
- const unsigned n = lhs.nelements();
- for (unsigned i = 0; i < n; ++i)
- if (rhs.element(i) != lhs.element(i))
- return false;
- return true;
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
Index: mln/core/pset_if.hh
--- mln/core/pset_if.hh (revision 0)
+++ mln/core/pset_if.hh (revision 0)
@@ -0,0 +1,191 @@
+// 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.
+
+#ifndef MLN_CORE_PSET_IF_HH
+# define MLN_CORE_PSET_IF_HH
+
+/*! \file mln/core/pset_if.hh
+ *
+ * \brief Definition of the restriction of a point set w.r.t. a predicate.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename S, typename F> struct pset_if;
+ template <typename S, typename F> struct pset_if_fwd_piter_;
+ template <typename S, typename F> struct pset_if_bkd_piter_;
+
+
+
+ /*! \brief Restrict a point set \p pset to points that verify \p f.
+ *
+ * \param[in] pset A point set.
+ * \param[in] f A function from point to Boolean.
+ * \return A subset of points.
+ */
+ template <typename S, typename F>
+ pset_if<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f);
+
+
+
+ /*! \brief Generic subset class.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ */
+ template <typename S, typename F>
+ struct pset_if : public Point_Set< pset_if<S,F> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point associated type.
+ typedef mln_point(S) point;
+
+
+ /// Forward Point_Iterator associated type.
+ typedef pset_if_fwd_piter_<S,F> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef internal::fixme bkd_piter;
+
+
+ /// Constructor without argument.
+ pset_if(const S& pset, const F& f);
+
+
+ /// Test if \p p belongs to the subset.
+ bool has(const psite& p) const;
+
+ /// Give a bounding box of the subset.
+ const box_<point>& bbox() const;
+
+ /// Give the number of points of the subset.
+ std::size_t npoints() const;
+
+ /// Give the primary overset.
+ const S& overset() const;
+
+ /// Test predicate on point site \p p.
+ bool pred(const psite& p) const;
+
+ protected:
+
+ const S& pset_;
+ F f_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename S, typename F>
+ pset_if<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f)
+ {
+ pset_if<S, F> tmp(exact(pset), exact(f));
+ return tmp;
+ }
+
+
+ // pset_if<S,F>
+
+ template <typename S, typename F>
+ bool
+ pset_if<S,F>::has(const psite& p) const
+ {
+ return pset_.has(p) && f_(p);
+ }
+
+ template <typename S, typename F>
+ const box_<mln_point(S)>&
+ pset_if<S,F>::bbox() const
+ {
+ return pset_.bbox();
+ }
+
+ template <typename S, typename F>
+ const S&
+ pset_if<S,F>::overset() const
+ {
+ return pset_;
+ }
+
+ template <typename S, typename F>
+ bool
+ pset_if<S,F>::pred(const psite& p) const
+ {
+ return f_(p);
+ }
+
+ template <typename S, typename F>
+ pset_if<S,F>::pset_if(const S& pset, const F& f)
+ : pset_(pset),
+ f_(f)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+# include <mln/core/pset_if_piter.hh>
+
+
+
+namespace mln
+{
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ std::size_t
+ pset_if<S,F>::npoints() const
+ {
+ std::size_t n = 0;
+ fwd_piter p(*this);
+ for_all(p)
+ ++n;
+ return n;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSET_IF_HH
Index: mln/core/pset_if_piter.hh
--- mln/core/pset_if_piter.hh (revision 0)
+++ mln/core/pset_if_piter.hh (revision 0)
@@ -0,0 +1,125 @@
+// 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.
+
+#ifndef MLN_CORE_PSET_IF_PITER_HH
+# define MLN_CORE_PSET_IF_PITER_HH
+
+/*! \file mln/core/pset_if_piter.hh
+ *
+ * \brief Definition of iterators on points of pset_ifes.
+ */
+
+# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/piter_adaptor.hh>
+# include <mln/core/internal/fixme.hh>
+# include <mln/core/pset_if.hh>
+
+
+namespace mln
+{
+
+ /*! \brief A generic forward iterator on points of subsets.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ *
+ * \see mln::pset_if
+ */
+ template <typename S, typename F>
+ class pset_if_fwd_piter_
+ : public internal::piter_adaptor_< mln_fwd_piter(S),
+ pset_if_fwd_piter_<S,F> >
+ {
+ typedef mln_fwd_piter(S) adaptee_;
+ typedef pset_if_fwd_piter_<S,F> self_;
+ typedef internal::piter_adaptor_<adaptee_, self_> super_;
+
+ public:
+
+ /// Constructor from a subset of points.
+ pset_if_fwd_piter_(const pset_if<S,F>& subset);
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ private:
+
+ const pset_if<S,F>& subset_;
+ };
+
+
+ // FIXME:
+ template <typename S, typename F>
+ class pset_if_bkd_piter_
+ : public internal::fixme
+ {};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // pset_if_fwd_piter_<S,F>
+
+ template <typename S, typename F>
+ pset_if_fwd_piter_<S,F>::pset_if_fwd_piter_(const pset_if<S,F>& subset)
+ : super_(adaptee_(subset.overset())),
+ subset_(subset)
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ pset_if_fwd_piter_<S,F>::start()
+ {
+ this->piter_.start();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_))
+ this->piter_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ pset_if_fwd_piter_<S,F>::next_()
+ {
+ do
+ this->piter_.next();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_));
+ }
+
+
+ // FIXME: pset_if_bkd_piter_<S,F>
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSET_IF_PITER_HH
Index: mln/core/vec_p.hh
--- mln/core/vec_p.hh (revision 0)
+++ mln/core/vec_p.hh (revision 0)
@@ -0,0 +1,208 @@
+// 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.
+
+#ifndef MLN_CORE_VEC_P_HH
+# define MLN_CORE_VEC_P_HH
+
+/*! \file mln/core/vec_p.hh
+ *
+ * \brief Definition of a point set class based on std::vector.
+ */
+
+# include <vector>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct vec_p_fwd_piter_;
+ template <typename P> struct vec_p_bkd_piter_;
+
+
+ /*! \brief Point set class based on std::vector.
+ *
+ * This is a multi-set of points.
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints(). FIXME: Explain!
+ *
+ * \todo Make it work with P being a Point_Site.
+ */
+ template <typename P>
+ class vec_p : public Point_Set< vec_p<P> >
+ {
+ public:
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ vec_p();
+
+ /// Constructor from a vector \p vect.
+ vec_p(const std::vector<P>& vect);
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Append a point \p p.
+ vec_p<P>& append(const P& p);
+
+ /// Clear this set.
+ void clear();
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<P>& vect() const;
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ protected:
+
+ std::vector<P> vect_;
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+
+ void update_bb_() const;
+ // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ vec_p<P>::vec_p()
+ {
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ vec_p<P>::vec_p(const std::vector<P>& vect)
+ : vect_(vect)
+ {
+ bb_needs_update_ = true;
+ }
+
+ template <typename P>
+ void
+ vec_p<P>::update_bb_() const
+ {
+ bb_.init();
+ for (unsigned i = 0; i < vect_.size(); ++i)
+ bb_.take(vect_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ vec_p<P>::has(const P& p) const
+ {
+ for (unsigned i = 0; i < vect_.size(); ++i)
+ if (vect_[i] = p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ std::size_t
+ vec_p<P>::npoints() const
+ {
+ return vect_.size();
+ }
+
+ template <typename P>
+ const box_<P>&
+ vec_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ update_bb_();
+ return bb_.to_value();
+ }
+
+ template <typename P>
+ vec_p<P>&
+ vec_p<P>::append(const P& p)
+ {
+ vect_.push_back(p);
+ if (! bb_needs_update_)
+ bb_needs_update_ = true;
+ return *this;
+ }
+
+ template <typename P>
+ void
+ vec_p<P>::clear()
+ {
+ vect_.clear();
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ vec_p<P>::vect() const
+ {
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ vec_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return vect_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+# include <mln/core/vec_p_piter.hh>
+
+
+#endif // ! MLN_CORE_VEC_P_HH
Index: mln/core/concept/window.hh
--- mln/core/concept/window.hh (revision 1047)
+++ mln/core/concept/window.hh (working copy)
@@ -77,6 +77,14 @@
W operator-(const Window<W>& rhs);
+ /*! \brief Equality comparison between windows \p lhs and \p rhs.
+ *
+ * \relates mln::Window
+ */
+ template <typename Wl, typename Wr>
+ bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
@@ -107,6 +115,26 @@
return exact(rhs).sym_();
}
+ template <typename Wl, typename Wr>
+ bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs)
+ {
+ // FIXME: Same grid!
+ typedef mln_point(Wl) P;
+
+ mln_fwd_qiter(Wl) ql(exact(lhs), P::zero);
+ mln_fwd_qiter(Wr) qr(exact(rhs), P::zero);
+
+ for (ql.start(), qr.start();
+ ql.is_valid() && qr.is_valid();
+ ql.next(), qr.next())
+ if (ql != qr)
+ return false; // difference found
+
+ // both windows are equal only if both browsings are completed at
+ // the same time:
+ return ! ql.is_valid() && ! qr.is_valid();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 0)
+++ mln/core/vec_p_piter.hh (revision 0)
@@ -0,0 +1,172 @@
+// 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.
+
+#ifndef MLN_CORE_VEC_P_PITER_HH
+# define MLN_CORE_VEC_P_PITER_HH
+
+/*! \file mln/core/vec_p_piter.hh
+ *
+ * \brief Definition of point iterators on mln::vec_p.
+ */
+
+# include <mln/core/vec_p.hh>
+# include <mln/core/internal/fixme.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Forward iterator on points of a vec_p<P>.
+ *
+ */
+ template <typename P>
+ struct vec_p_fwd_piter_ : public Point_Iterator< vec_p_fwd_piter_<P> >
+ {
+ enum { dim = P::dim };
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(P) dpoint;
+
+ /// Coordinate associated type.
+ typedef mln_coord(P) coord;
+
+ /// Coordinate associated type.
+ template <typename S>
+ vec_p_fwd_piter_(const Point_Set<S>& s);
+
+ /// Give a hook to the point address.
+ const P* pointer_() const;
+
+ /// Read-only access to the \p i-th coordinate.
+ coord operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convert the iterator into a point.
+ operator P() const;
+
+ protected:
+ const std::vector<P>& vect_;
+ unsigned i_;
+ P p_;
+ };
+
+
+
+ // FIXME:
+ template <typename P>
+ struct vec_p_bkd_piter_ : internal::fixme
+ {};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ template <typename S>
+ vec_p_fwd_piter_<P>::vec_p_fwd_piter_(const Point_Set<S>& s)
+ : vect_(exact(s).vect())
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ const P*
+ vec_p_fwd_piter_<P>::pointer_() const
+ {
+ return & p_;
+ }
+
+ template <typename P>
+ mln_coord(P)
+ vec_p_fwd_piter_<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ mln_precondition(is_valid());
+ return p_[i];
+ }
+
+ template <typename P>
+ bool
+ vec_p_fwd_piter_<P>::is_valid() const
+ {
+ return i_ < vect_.size();
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::invalidate()
+ {
+ i_ = vect_.size();
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::start()
+ {
+ i_ = 0;
+ if (is_valid())
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::next_()
+ {
+ ++i_;
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ vec_p_fwd_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_VEC_P_PITER_HH
Index: mln/core/set_p.hh
--- mln/core/set_p.hh (revision 0)
+++ mln/core/set_p.hh (revision 0)
@@ -0,0 +1,162 @@
+// 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.
+
+#ifndef MLN_CORE_SET_P_HH
+# define MLN_CORE_SET_P_HH
+
+/*! \file mln/core/set_p.hh
+ *
+ * \brief Definition of a point set class based on std::set.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/set_of.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/core/vec_p.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Point set class based on std::set.
+ *
+ * This is a mathematical set of points (not a multi-set). The
+ * parameter \p P shall be a Point type.
+ *
+ * \todo Test if \p P being a Point_Site is ok.
+ */
+ template <typename P>
+ class set_p : public Point_Set< set_p<P> >,
+ private internal::set_of_<P>
+ {
+ typedef internal::set_of_<P> super_;
+
+ public:
+
+ /// Point associated type.
+ typedef mln_point(P) point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ set_p();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Return the corresponding std::vector of points.
+ using super_::vect;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Insert a point \p p.
+ set_p<P>& insert(const P& p);
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ /// Clear this set.
+ void clear();
+
+ /// Give the exact bounding box.
+ const box_<point>& bbox() const;
+
+ protected:
+
+ accu::bbox<P> bb_;
+ // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ set_p<P>::set_p()
+ {
+ }
+
+ template <typename P>
+ bool
+ set_p<P>::has(const P& p) const
+ {
+ return this->super_::has(p);
+ }
+
+ template <typename P>
+ std::size_t
+ set_p<P>::npoints() const
+ {
+ return this->super_::nelements();
+ }
+
+ template <typename P>
+ set_p<P>&
+ set_p<P>::insert(const P& p)
+ {
+ this->super_::insert(p);
+ bb_.take(p);
+ return *this;
+ }
+
+ template <typename P>
+ const P&
+ set_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return this->super_::element(i);
+ }
+
+ template <typename P>
+ void
+ set_p<P>::clear()
+ {
+ this->super_::clear();
+ bb_.init();
+ }
+
+ template <typename P>
+ const box_<mln_point(P)>&
+ set_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ return bb_.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SET_P_HH
Index: mln/core/line2d.hh
--- mln/core/line2d.hh (revision 1047)
+++ mln/core/line2d.hh (working copy)
@@ -36,7 +36,7 @@
# include <vector>
# include <mln/core/concept/point_set.hh>
-# include <mln/core/pvec_piter.hh>
+# include <mln/core/vec_p_piter.hh>
# include <mln/core/box2d.hh>
# include <mln/math/all.hh>
@@ -58,10 +58,10 @@
typedef point2d psite;
/// Forward Point_Iterator associated type.
- typedef pvec_fwd_piter_<point2d> fwd_piter;
+ typedef vec_p_fwd_piter_<point2d> fwd_piter;
/// Backward Point_Iterator associated type.
- typedef pvec_bkd_piter_<point2d> bkd_piter;
+ typedef vec_p_bkd_piter_<point2d> bkd_piter;
/// Constructor from point \p beg to point \p end.
Index: mln/draw/line.hh
--- mln/draw/line.hh (revision 1047)
+++ mln/draw/line.hh (working copy)
@@ -35,6 +35,9 @@
# include <mln/core/concept/image.hh>
# include <mln/core/line2d.hh>
+# include <mln/level/paste.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
namespace mln
@@ -43,7 +46,8 @@
namespace draw
{
- /// Draw a line at level \p v in image \p ima between the points \p beg and \p end.
+ /// Draw a line at level \p v in image \p ima between the points
+ /// \p beg and \p end.
template <typename I>
void line(Image<I>& ima,
const mln_point(I)& beg, const mln_point(I)& end,
@@ -52,27 +56,6 @@
# ifndef MLN_INCLUDE_ONLY
- namespace impl
- {
-
- template <typename I>
- void line(I& ima,
- const point2d& beg, const point2d& end,
- const mln_value(I)& v)
- {
- line2d l(beg, end);
- mln_piter(line2d) p(l);
- for_all(p)
- ima(p) = v;
- }
-
- // FIXME: Overload.
-
- } // end of namespace mln::draw::impl
-
-
- // Facade.
-
template <typename I>
void line(Image<I>& ima,
const mln_point(I)& beg, const mln_point(I)& end,
@@ -80,7 +63,8 @@
{
mln_precondition(exact(ima).has_data());
mln_precondition(exact(ima).has(beg) && exact(ima).has(end));
- impl::line(exact(ima), beg, end, v);
+ level::paste(pw::cst(v) | line2d(beg, end),
+ ima);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/take.hh
--- mln/level/take.hh (revision 0)
+++ mln/level/take.hh (revision 0)
@@ -0,0 +1,102 @@
+// 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.
+
+#ifndef MLN_LEVEL_TAKE_HH
+# define MLN_LEVEL_TAKE_HH
+
+/*! \file mln/level/take.hh
+ *
+ * \brief Make an accumulator take image pixel values.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Make an accumulator take the values of the image \p input.
+ *
+ * \param[in,out] a The accumulator.
+ * \param[in] input The input image.
+ *
+ * This routine runs: \n
+ * for all p of \p input, \p a.take( \p input(p) ) \n
+ *
+ * \warning This routine does not perform a.init().
+ */
+ template <typename A, typename I>
+ void take(Accumulator<A>& a, const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename A, typename I>
+ void take(A& a, const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ a.take(input(p));
+ }
+
+ template <typename A, typename I>
+ void take(A& a, const Fast_Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_pixter(const I) pxl(input);
+ for_all(pxl)
+ a.take(*pxl);
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facade.
+
+ template <typename A, typename I>
+ void take(Accumulator<A>& a, const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ impl::take(exact(a), exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_TAKE_HH
Index: mln/level/apply.hh
--- mln/level/apply.hh (revision 1047)
+++ mln/level/apply.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/level/apply.hh
*
- * \brief Apply some function-objects on an image.
+ * \brief Apply a function-object onto image pixel values.
*/
# include <mln/core/concept/image.hh>
@@ -52,34 +52,25 @@
* This routine runs: \n
* for all p of \p input, \p f( \p input(p) ) \n
* return \p f
+ *
+ * \todo Find a meaning for this routine! (Clue: f is mutable
+ * and/or same for input?)
*/
template <typename I, typename F>
F apply(const Image<I>& input, const Function<F>& f);
- /*! Apply an accumulator to the image \p input.
- *
- * \param[in] input The input image.
- * \param[in] a The accumulator.
- * \result A copy of the accumulator.
- *
- * This routine runs: \n
- * a.init() \n
- * for all p of \p input, \p a.take( \p input(p) ) \n
- * return \p a
- */
- template <typename I, typename A>
- A apply(const Image<I>& input, const Accumulator<A>& a);
-
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename I, typename F>
F apply(const Image<I>& input_, const Function<F>& f_)
{
const I& input = exact(input_);
F f = exact(f_);
- mln_precondition(input.has_data());
mln_piter(I) p(input.domain());
for_all(p)
@@ -87,18 +78,28 @@
return f;
}
- template <typename I, typename A>
- A apply(const Image<I>& input_, const Accumulator<A>& a_)
+ template <typename I, typename F>
+ F apply(const Fast_Image<I>& input_, const Function<F>& f_)
{
const I& input = exact(input_);
- A a = exact(a_);
- mln_precondition(input.has_data());
+ F f = exact(f_);
- a.init();
- mln_piter(I) p(input.domain());
- for_all(p)
- a.take(input(p));
- return a;
+ mln_pixter(const I) pxl(input);
+ for_all(pxl)
+ f(input(*pxl));
+ return f;
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facades.
+
+ template <typename I, typename F>
+ F apply(const Image<I>& input, const Function<F>& f)
+ {
+ mln_precondition(exact(input).has_data());
+ return impl::apply(exact(input), f);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/run.hh
--- mln/level/run.hh (revision 0)
+++ mln/level/run.hh (revision 0)
@@ -0,0 +1,79 @@
+// 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.
+
+#ifndef MLN_LEVEL_RUN_HH
+# define MLN_LEVEL_RUN_HH
+
+/*! \file mln/level/run.hh
+ *
+ * \brief Run an accumulator onto image pixel values.
+ */
+
+# include <mln/level/take.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Run an accumulator onto the pixel values of the image \p input.
+ *
+ * \param[in] input The input image.
+ * \param[in] a The accumulator.
+ * \return A resulting accumulator.
+ *
+ * This routine runs: \n
+ * res = \p a \n
+ * res.init() \n
+ * level::take(res, \p input) \n
+ * return res \n
+ */
+ template <typename I, typename A>
+ A run(const Image<I>& input, const Accumulator<A>& a);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename A>
+ A run(const Image<I>& input, const Accumulator<A>& a)
+ {
+ A res = exact(a);
+ res.init();
+ level::take(res, input);
+ return res;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_RUN_HH
Index: mln/accu/sum.hh
--- mln/accu/sum.hh (revision 1047)
+++ mln/accu/sum.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/accumulator.hh>
+# include <mln/value/props.hh>
namespace mln
@@ -46,10 +47,10 @@
/*! Generic sum accumulator class.
*
* Parameter \c V is the type of values that we sum. Parameter \c
- * S is the type to store the sum value; the default type of
- * \c S is \c V.
+ * S is the type to store the value sum; the default type of
+ * \c S is the summation type (property) of \c V.
*/
- template <typename V, typename S = V>
+ template <typename V, typename S = mln_sum(V)>
struct sum : public Accumulator< sum<V,S> >
{
typedef V value;
@@ -61,6 +62,8 @@
operator S() const;
S to_value() const;
+ sum<V,S>& operator+=(const sum<V,S>& rhs);
+
protected:
S sum_;
@@ -99,7 +102,15 @@
S
sum<V,S>::to_value() const
{
- return sum_ / count_;
+ return sum_;
+ }
+
+ template <typename V, typename S>
+ sum<V,S>&
+ sum<V,S>::operator+=(const sum<V,S>& rhs)
+ {
+ sum_ += rhs.sum_;
+ return *this;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/accu/count.hh
--- mln/accu/count.hh (revision 0)
+++ mln/accu/count.hh (revision 0)
@@ -0,0 +1,119 @@
+// 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.
+
+#ifndef MLN_ACCU_COUNT_HH
+# define MLN_ACCU_COUNT_HH
+
+/*! \file mln/accu/count.hh
+ *
+ * \brief Define an accumulator that counts.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! Generic counter accumulator class.
+ */
+ template <typename V>
+ struct count : public Accumulator< count<V> >
+ {
+ typedef V value;
+
+ count();
+ void take(const value&);
+ void init();
+
+ operator std::size_t() const;
+ std::size_t to_value() const;
+
+ count<V>& operator+=(const count<V>& rhs);
+
+ protected:
+
+ std::size_t count_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ count<V>::count()
+ {
+ init();
+ }
+
+ template <typename V>
+ void
+ count<V>::take(const value&)
+ {
+ ++count_;
+ }
+
+ template <typename V>
+ void
+ count<V>::init()
+ {
+ count_ = 0;
+ }
+
+ template <typename V>
+ count<V>::operator std::size_t() const
+ {
+ return to_value();
+ }
+
+ template <typename V>
+ std::size_t
+ count<V>::to_value() const
+ {
+ return count_;
+ }
+
+ template <typename V>
+ count<V>&
+ count<V>::operator+=(const count<V>& rhs)
+ {
+ count_ += rhs.count_;
+ return *this;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_COUNT_HH
Index: mln/accu/mean.hh
--- mln/accu/mean.hh (revision 1047)
+++ mln/accu/mean.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Define an accumulator that computes a mean.
*/
-# include <mln/accu/counter.hh>
+# include <mln/accu/count.hh>
# include <mln/accu/sum.hh>
@@ -48,10 +48,13 @@
*
* Parameter \c V is the type of values that we sum. Parameter \c
* S is the type to store the sum of values; the default type of
- * \c S is \c V. Parameter \c M is the type of the mean value;
- * the default type of \c M is \c S.
+ * \c S is the summation type (property) of \c V. Parameter \c M
+ * is the type of the mean value; the default type of \c M is \c
+ * S.
*/
- template <typename V, typename S = V, typename M = S>
+ template <typename V,
+ typename S = mln_sum(V),
+ typename M = S>
struct mean : public Accumulator< mean<V,S,M> >
{
typedef V value;
@@ -63,9 +66,11 @@
operator M() const;
M to_value() const;
+ mean<V,S,M>& operator+=(const mean<V,S,M>& rhs);
+
protected:
- accu::counter<V> count_;
+ accu::count<V> count_;
accu::sum<V,S> sum_;
};
@@ -97,7 +102,7 @@
template <typename V, typename S, typename M>
mean<V,S,M>::operator M() const
{
- return to_value;
+ return to_value();
}
template <typename V, typename S, typename M>
@@ -107,6 +112,15 @@
return sum_.to_value() / count_.to_value();
}
+ template <typename V, typename S, typename M>
+ mean<V,S,M>&
+ mean<V,S,M>::operator+=(const mean<V,S,M>& rhs)
+ {
+ count_ += rhs.count_;
+ sum_ += rhs.sum_;
+ return *this;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1047)
+++ mln/value/props.hh (working copy)
@@ -61,6 +61,9 @@
# define mln_is_lowq(T) typename metal::bool_<( mln_card_(T) != 0 )>::type
+/// Give the summation type for values of type \c T.
+# define mln_sum(T) typename mln::value::props< T >::sum
+
namespace mln
@@ -121,6 +124,7 @@
static const unsigned char max = 255;
static const std::size_t card_ = 256;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -130,6 +134,7 @@
static const signed char max = 127;
static const std::size_t card_ = 256;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -139,6 +144,7 @@
static const unsigned short max = 65535;
static const std::size_t card_ = 65536;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -148,6 +154,7 @@
static const signed short max = 32767;
static const std::size_t card_ = 655356;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -157,6 +164,7 @@
static const unsigned int max = UINT_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -166,6 +174,7 @@
static const signed int max = INT_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -175,6 +184,7 @@
static const unsigned long int max = ULONG_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -184,6 +194,7 @@
static const signed long int max = LONG_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
@@ -196,6 +207,7 @@
static const float max() { return FLT_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -205,6 +217,7 @@
static const double max() { return DBL_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef double sum;
};
} // end of namespace mln::value
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1047)
+++ mln/value/int_s.hh (working copy)
@@ -97,6 +97,7 @@
static const std::size_t card_ = metal::pow<2, n>::value;
static const unsigned nbits = n;
typedef data_kind kind;
+ typedef float sum;
};
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1047)
+++ mln/value/int_u.hh (working copy)
@@ -99,6 +99,7 @@
static const int_u<n> max; // = card_ - 1
static const unsigned nbits = n;
typedef data_kind kind;
+ typedef float sum;
};
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add RLE and Sparse image to milena.
* tests/sparse_image.cc,
* tests/run_pset.cc,
* tests/rle_image.cc: test.
* mln/core/sparse_encode.hh: Encode an image into a sparse image.
* mln/core/internal/run_image.hh: New, factorisation class.
* mln/core/internal/run_psite.hh: New, run psite class.
* mln/core/internal/run_pset.hh: New, point set of run image.
* mln/core/rle_image.hh: New, rle_image class.
* mln/core/rle_encode.hh: Encode an image into an rle image.
* mln/core/sparse_image.hh: New, sparse_image class.
mln/core/internal/run_image.hh | 97 +++++++++
mln/core/internal/run_pset.hh | 413 +++++++++++++++++++++++++++++++++++++++++
mln/core/internal/run_psite.hh | 146 ++++++++++++++
mln/core/rle_encode.hh | 110 ++++++++++
mln/core/rle_image.hh | 143 ++++++++++++++
mln/core/sparse_encode.hh | 104 ++++++++++
mln/core/sparse_image.hh | 147 ++++++++++++++
tests/rle_image.cc | 59 +++++
tests/run_pset.cc | 58 +++++
tests/sparse_image.cc | 81 ++++++++
10 files changed, 1358 insertions(+)
Index: tests/sparse_image.cc
--- tests/sparse_image.cc (revision 0)
+++ tests/sparse_image.cc (revision 0)
@@ -0,0 +1,81 @@
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sparse_image.hh>
+#include <mln/core/sparse_encode.hh>
+#include <vector>
+
+using namespace mln;
+
+
+template <typename Pset>
+void test(const Pset& my_set)
+{
+ typename Pset::fwd_piter run (my_set);
+ for (run.start(); run.is_valid(); run.next())
+ ;
+ //std::cout << run << std::endl;
+
+ // std::cout << "Reverse" << std::endl;
+ typename Pset::bkd_piter run2 (my_set);
+
+ //std::cout << "Reverse\n";
+
+ for (run2.start(); run2.is_valid(); run2.next())
+ ;
+ // std::cout << run2 << std::endl;
+}
+
+template <typename I>
+void test2(I& ima)
+{
+ typename I::fwd_piter run (ima.domain());
+ for_all(run)
+ ++ima(run);
+
+ typename I::bkd_piter run2 (ima.domain());
+ for_all(run2)
+ assert(ima(run2) == 1);
+}
+
+int
+main()
+{
+ mln::point2d p, q, r;
+ p = mln::make::point2d(0, 1);
+ q = mln::make::point2d(3, 0);
+ r = mln::make::point2d(2, 2);
+ mln::internal::run_pset_<mln::point2d> my_set;
+ mln::sparse_image<mln::point2d, int> sparse;
+ mln::sparse_image<mln::point2d, int> sparse2;
+
+
+ my_set.insert(p, 5);
+ my_set.insert(q, 8);
+ test(my_set);
+
+ std::vector<int> values;
+ int a = 0;
+ values.push_back(a);
+ a = 0;
+ values.push_back(a);
+ a = 0;
+ values.push_back(a);
+ sparse.insert(q, 3, values);
+
+ test(sparse.domain());
+ test2(sparse);
+
+ mln::image2d_b<int> ima2d (1, 5);
+
+ ima2d(mln::make::point2d(0, 4)) = 5;
+ ima2d(mln::make::point2d(0, 3)) = 2;
+
+// oln::debug::print(ima2d);
+
+ sparse2 = sparse_encode(ima2d);
+
+
+// oln::debug::print(sparse2);
+// std::cout << std::endl;
+
+ return 0;
+}
Index: tests/run_pset.cc
--- tests/run_pset.cc (revision 0)
+++ tests/run_pset.cc (revision 0)
@@ -0,0 +1,58 @@
+#include <mln/core/internal/run_pset.hh>
+#include <mln/core/image2d_b.hh>
+#include <iostream>
+
+using namespace mln;
+
+template <typename Pset>
+void
+parc(const Pset& pset)
+{
+ typename Pset::fwd_piter it_(pset);
+
+ for_all(it_)
+ {
+ std::cout << (typename Pset::point) it_ << std::endl;
+ }
+
+ typename Pset::bkd_piter rit_(pset);
+
+ for_all(rit_)
+ {
+ std::cout << (typename Pset::point) rit_ << std::endl;
+ }
+}
+
+
+int
+main()
+{
+ point2d p, q, r;
+ p = make::point2d(2, 4);
+ q = make::point2d(18, 42);
+ r = make::point2d(50, 76);
+
+ // Psite declaration
+ run_psite<point2d> site(p, 5, 0);
+ run_psite<point2d> site2(r, 40, 0);
+
+ // Pset test
+ internal::run_pset_<point2d> ps;
+
+ ps.insert(p, 7);
+ assert(ps.npoints() == 7);
+
+ ps.insert(q, 42);
+ assert(ps.npoints() == 49);
+
+ assert(ps.has(site));
+ assert(!ps.has(site2));
+
+ ps.insert(r, 14);
+ assert(!ps.has(site2));
+
+ // FIXME bbox test
+
+ parc(ps);
+ return 0;
+}
Index: tests/rle_image.cc
--- tests/rle_image.cc (revision 0)
+++ tests/rle_image.cc (revision 0)
@@ -0,0 +1,59 @@
+#include <mln/core/image2d_b.hh>
+#include <mln/core/rle_image.hh>
+#include <mln/core/rle_encode.hh>
+
+using namespace mln;
+
+template <typename Pset>
+void test(const Pset& my_set)
+{
+ typename Pset::fwd_piter run (my_set);
+ for (run.start(); run.is_valid(); run.next())
+ /*std::cout << run << std::endl*/;
+
+ // std::cout << "Reverse" << std::endl;
+
+ typename Pset::bkd_piter run2 (my_set);
+ for (run2.start(); run2.is_valid(); run2.next())
+ /*std::cout << run2 << std::endl*/;
+}
+
+int
+main()
+{
+ mln::point2d p, q, r;
+ r = make::point2d(0, 1);
+ q = make::point2d(2, 2);
+ r = make::point2d(3, 0);
+ mln::internal::run_pset_<mln::point2d> my_set;
+ mln::rle_image<mln::point2d, int> rle;
+ mln::rle_image<mln::point2d, int> rle2;
+
+ my_set.insert(p, 5);
+ my_set.insert(q, 8);
+ test(my_set);
+
+ rle.insert(p, 5, 4);
+ rle.insert(q, 8, 9);
+
+// mln::debug::print(rle);
+// std::cout << std::endl;
+
+ mln::image2d_b<int> ima2d (1, 5);
+ ima2d(make::point2d(0, 4)) = 5;
+
+// mln::debug::print(ima2d);
+
+ rle2 = rle_encode(ima2d);
+
+ mln::rle_image<mln::point2d, int>::fwd_piter p1(rle2.domain());
+ for_all(p1)
+ {
+ assert(ima2d(p1) == rle2(p1));
+ }
+
+// mln::debug::print(rle2);
+// std::cout << std::endl;
+
+ return 0;
+}
Index: mln/core/sparse_encode.hh
--- mln/core/sparse_encode.hh (revision 0)
+++ mln/core/sparse_encode.hh (revision 0)
@@ -0,0 +1,104 @@
+// 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.
+
+#ifndef MLN_CORE_SPARSE_ENCODE_HH
+# define MLN_CORE_SPARSE_ENCODE_HH
+
+/*! \file mln/core/sparse_image.hh
+ *
+ * \brief FIXME
+ */
+
+# include <mln/core/sparse_image.hh>
+# include <vector>
+
+namespace mln
+{
+
+ /*!
+ ** encode a generic image to a sparse image format
+ **
+ ** @param input an Image
+ **
+ ** @return a sparse image
+ */
+ template <typename I>
+ sparse_image<mln_point(I), mln_value(I)>
+ sparse_encode(const Image<I>& input);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ sparse_image<mln_point(I), mln_value(I)>
+ sparse_encode(const Image<I>& input)
+ {
+ sparse_image<mln_point(I), mln_value(I)> output;
+ mln_piter(I) p(exact(input).domain());
+ unsigned len = 1;
+ // old point first dim coordinate
+ typename I::coord old = 1;
+ // range pointstart
+ mln_point(I) rstart;
+ // range value
+ std::vector<mln_value(I)> values;
+
+ p.start();
+ if (not p.is_valid())
+ return output;
+
+ rstart = p;
+
+ old = p[0];
+ values.push_back(exact(input)(p));
+ p.next_();
+ while (p.is_valid())
+ {
+ if (p[0] - 1 == old)
+ {
+ ++len;
+ values.push_back(exact(input)(p));
+ }
+ else
+ {
+ output.insert(rstart, len, values);
+ rstart = p;
+ len = 1;
+ values.clear();
+ values.push_back(exact(input)(p));
+ }
+ old = p[0];
+ p.next_();
+ }
+ output.insert(rstart, len, values);
+ return output;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+}
+
+#endif // ! MLN_CORE_SPARSE_ENCODE_HH
Index: mln/core/internal/run_image.hh
--- mln/core/internal/run_image.hh (revision 0)
+++ mln/core/internal/run_image.hh (revision 0)
@@ -0,0 +1,97 @@
+// 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.
+
+#ifndef MLN_CORE_INTERNAL_RUN_IMAGE_HH
+# define MLN_CORE_INTERNAL_RUN_IMAGE_HH
+
+/*! \file mln/core/internal/run_image.hh
+ *
+ * \brief Definition of mln::internal::run_image_ class for internal use only
+ */
+
+# include <mln/core/internal/image_base.hh>
+# include <mln/core/internal/run_pset.hh>
+# include <mln/core/internal/run_psite.hh>
+# include <mln/value/set.hh>
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ /*! \brief Factorization class for run_image.
+ *
+ * Parameter \c P is the type of the image point.
+ * Parameter \c E is the Exact type of the image.
+ */
+ template <typename P, typename E>
+ class run_image_ : public image_base_<run_pset_<P>, E>
+ {
+ public:
+ typedef run_pset_<P> pset;
+ typedef mln_psite(pset) psite;
+
+ /// Give the definition domain.
+ const pset& domain() const;
+ /// Test if \p p is valid.
+ bool owns_(const psite& site) const;
+ protected:
+ /// domain of the image
+ pset domain_;
+
+ run_image_();
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ run_image_<P, E>::run_image_()
+ {
+ }
+
+ template <typename P, typename E>
+ const typename run_image_<P, E>::pset&
+ run_image_<P, E>::domain() const
+ {
+ return domain_;
+ }
+
+ template <typename P, typename E>
+ bool
+ run_image_<P, E>::owns_(const typename run_image_<P, E>::psite& site) const
+ {
+ return domain_.has(site);
+ }
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_RUN_IMAGE_HH
Index: mln/core/internal/run_psite.hh
--- mln/core/internal/run_psite.hh (revision 0)
+++ mln/core/internal/run_psite.hh (revision 0)
@@ -0,0 +1,146 @@
+// 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.
+
+#ifndef MLN_CORE_INTERNAL_RUN_PSITE_HH
+# define MLN_CORE_INTERNAL_RUN_PSITE_HH
+
+/*! \file mln/core/internal/run_psite.hh
+ *
+ * \brief Definition of class mln::internal::run_psite_ for internal use only
+ */
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ /*! \brief Psite class used in run_image_.
+ *
+ * Parameter \c P is the type of the image point.
+ */
+ template <typename P>
+ class run_psite
+ {
+ public:
+ run_psite();
+ run_psite(P point, unsigned index, unsigned pset_pos);
+
+ operator P () const;
+ /// Return the point at the start of the current run.
+ P& range_start_();
+ /// Return the point at the start of the current run.
+ const P& range_start_() const;
+ /// Return the position of this psite in the point set.
+ unsigned pset_pos_() const;
+ /// Return the position of this psite in the point set.
+ unsigned& pset_pos_();
+ /// Return the position of this psite in the current range.
+ unsigned index_() const;
+ /// Return the position of this psite in the current range.
+ unsigned& index_();
+
+ protected:
+ /// Start of the psite range.
+ P point_;
+ /// Position in the psite range.
+ unsigned range_index_;
+ /// Position of the psite in the point set.
+ unsigned pset_position_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+ template <typename P>
+ run_psite<P>::run_psite()
+ {
+ }
+
+ template <typename P>
+ run_psite<P>::run_psite(P point, unsigned index, unsigned pset_pos) :
+ point_(point),
+ range_index_(index),
+ pset_position_(pset_pos)
+ {
+ }
+
+ template <typename P>
+ run_psite<P>::operator P() const
+ {
+ P tmp = point_;
+ tmp[0] += range_index_;
+ return tmp;
+ }
+
+ template <typename P>
+ const P&
+ run_psite<P>::range_start_() const
+ {
+ return point_;
+ }
+
+ template <typename P>
+ P&
+ run_psite<P>::range_start_()
+ {
+ return point_;
+ }
+
+ template <typename P>
+ unsigned
+ run_psite<P>::pset_pos_() const
+ {
+ return pset_position_;
+ }
+
+ template <typename P>
+ unsigned&
+ run_psite<P>::pset_pos_()
+ {
+ return pset_position_;
+ }
+
+ template <typename P>
+ unsigned
+ run_psite<P>::index_() const
+ {
+ return range_index_;
+ }
+
+ template <typename P>
+ unsigned&
+ run_psite<P>::index_()
+ {
+ return range_index_;
+ }
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_RUN_PSITE_HH
Index: mln/core/internal/run_pset.hh
--- mln/core/internal/run_pset.hh (revision 0)
+++ mln/core/internal/run_pset.hh (revision 0)
@@ -0,0 +1,413 @@
+// 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.
+
+#ifndef MLN_CORE_INTERNAL_RUN_PSET_HH
+# define MLN_CORE_INTERNAL_RUN_PSET_HH
+
+/*! \file mln/core/internal/run_pset.hh
+ *
+ * \brief Definition of mln::internal::run_pset_ class and its iterators
+ * (for internal use only).
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/run_psite.hh>
+# include <mln/accu/bbox.hh>
+
+# include <vector>
+# include <utility>
+
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+ // Forward declaration
+ template <typename P> struct run_fwd_piter_;
+ template <typename P> struct run_bkd_piter_;
+
+
+ /*! \brief run_pset_ class represent a point set used in run_image_ class.
+ *
+ * Parameter \c P is the type of the image point.
+ */
+ template <typename P>
+ class run_pset_ : public Point_Set<run_pset_<P> >
+ {
+ public:
+ typedef P point;
+ typedef internal::run_psite<point> psite;
+ typedef std::vector<std::pair<point, unsigned> > std_container;
+ typedef run_fwd_piter_<P> fwd_piter;
+ typedef run_bkd_piter_<P> bkd_piter;
+
+
+ run_pset_();
+ /// Test is \p p belongs to this point set.
+ bool has(const psite& p) const;
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+ /// Give the number of points.
+ typename std::size_t npoints() const;
+
+ /// Insert a range, start at point \p p wit len \p len.
+ void insert(const P& p, unsigned len);
+ /// Return the len of the range starting at point \p p.
+ unsigned range_len_(const P& p) const;
+
+ /// Return the container of the pset (internal use only).
+ const std_container& con() const;
+
+ protected:
+ /// Number of points.
+ typename std::size_t npoints_;
+ /// Points container
+ std_container con_;
+ /// Exact bounding box.
+ accu::bbox<P> fb_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ run_pset_<P>::run_pset_() :
+ npoints_(0)
+ {
+ }
+
+ template <typename P>
+ bool
+ run_pset_<P>::has(const typename run_pset_<P>::psite& p) const
+ {
+ for (unsigned i = 0; i < con_.size(); ++i)
+ {
+ if (con_[i].first == p.range_start_() && con_[i].second > p.index_())
+ return true;
+ }
+ return false;
+ }
+
+ template <typename P>
+ const box_<P>&
+ run_pset_<P>::bbox() const
+ {
+ return fb_.to_value();
+ }
+
+ template <typename P>
+ typename std::size_t
+ run_pset_<P>::npoints() const
+ {
+ return npoints_;
+ }
+
+ template <typename P>
+ void
+ run_pset_<P>::insert(const P& p, unsigned len)
+ {
+ point run_pend;
+ typename std_container::value_type elt (p, len);
+ con_.push_back(elt);
+
+ // update box
+ fb_.take(p);
+ run_pend = p;
+ run_pend[0] += len - 1;
+ fb_.take(run_pend);
+ // update size
+ npoints_ += len;
+ }
+
+ template <typename P>
+ unsigned
+ run_pset_<P>::range_len_(const P& p) const
+ {
+ unsigned i;
+ for (i = 0; i < con_.size(); ++i)
+ {
+ if (con_[i].first == p)
+ return con_[i].second;
+ }
+ mln_assertion(i < con.size());
+
+ //Hack
+ return (con_[i].second);
+ }
+
+ template <typename P>
+ const typename run_pset_<P>::std_container&
+ run_pset_<P>::con() const
+ {
+ return con_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ /*! \brief Factorization class for run_pset_iterator_.
+ *
+ * Parameter \c P is the type of the point used in the point set.
+ * Parameter \c E is the exact type of the iterator
+ */
+ template <typename P, typename E>
+ class run_piter_ : public Point_Iterator<E>
+ {
+ public:
+ typedef typename run_pset_<P>::std_container std_container;
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+ typedef internal::run_psite<P> psite;
+
+ enum { dim = P::dim };
+
+ /// Convertion into a point-site.
+ operator psite () const;
+ /// Convertion into a point.
+ operator P () const;
+ /// Return a pointer of the current point.
+ const P* pointer_() const;
+ /// Access to the current point coordinates.
+ coord operator[](unsigned i) const;
+
+ protected:
+ /// Current point.
+ P p_;
+ /// Current site.
+ psite site_;
+ /// Point set container.
+ const std_container& con_;
+
+ run_piter_(const run_pset_<P>& pset);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ run_piter_<P, E>::run_piter_(const run_pset_<P>& pset) :
+ con_(pset.con())
+ {
+ }
+
+ template <typename P, typename E>
+ run_piter_<P, E>::operator typename run_piter_<P, E>::psite () const
+ {
+ return site_;
+ }
+
+ template <typename P, typename E>
+ run_piter_<P, E>::operator P () const
+ {
+ return p_;
+ }
+
+ template <typename P, typename E>
+ const P*
+ run_piter_<P, E>::pointer_() const
+ {
+ mln_precondition(exact(this)->is_valid());
+ return &p_;
+ }
+
+ template <typename P, typename E>
+ typename run_piter_<P, E>::coord
+ run_piter_<P, E>::operator[] (unsigned i) const
+ {
+ mln_precondition(exact(this)->is_valid());
+ return p_[i];
+ }
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ /*! \brief Forward iterator on run_pset_ point set.
+ *
+ * Parameter \c P is the type of the point used in the point set.
+ */
+ template <typename P>
+ class run_fwd_piter_ : public run_piter_<P, run_fwd_piter_<P> >
+ {
+ typedef run_piter_<P, run_fwd_piter_<P> > super;
+ public:
+
+ run_fwd_piter_(const run_pset_<P>& pset);
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+ /// Invalidate the iterator.
+ void invalidate();
+ /// Start an iteration.
+ void start();
+ /// Go to the next point.
+ void next_();
+ protected:
+ typename super::std_container::const_iterator it_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+ template <typename P>
+ run_fwd_piter_<P>::run_fwd_piter_(const run_pset_<P>& pset) :
+ super(pset)
+ {
+ it_ = this->con_.end();
+ this->site_.pset_pos_() = this->con_.size();
+ }
+
+ template <typename P>
+ bool
+ run_fwd_piter_<P>::is_valid() const
+ {
+ return it_ != this->con_.end();
+ }
+
+ template <typename P>
+ void
+ run_fwd_piter_<P>::invalidate()
+ {
+ it_ = this->con_.end();
+ this->site_.pset_pos_() = this->con_.size();
+ }
+
+ template <typename P>
+ void
+ run_fwd_piter_<P>::start()
+ {
+ it_ = this->con_.begin();
+ this->site_.range_start_() = it_->first;
+ this->site_.index_() = 0;
+ this->site_.pset_pos_() = 0;
+ this->p_ = it_->first;
+ }
+
+ template <typename P>
+ void
+ run_fwd_piter_<P>::next_()
+ {
+ mln_precondition(this->is_valid());
+ ++(this->site_.index_());
+
+ if (this->site_.index_() >= it_->second)
+ {
+ ++it_;
+ ++this->site_.pset_pos_();
+ this->site_.range_start_() = it_->first;
+ this->site_.index_() = 0;
+ }
+ this->p_ = this->site_.range_start_();
+ this->p_[0] += this->site_.index_();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ /*! \brief Backward iterator on run_pset_ point set.
+ *
+ * Parameter \c P is the type of the point used in the point set.
+ */
+ template <typename P>
+ class run_bkd_piter_ : public run_piter_<P, run_bkd_piter_<P> >
+ {
+ typedef run_piter_<P, run_bkd_piter_<P> > super;
+ public:
+
+ run_bkd_piter_(const run_pset_<P>& pset);
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+ /// Invalidate the iterator.
+ void invalidate();
+ /// Start an iteration.
+ void start();
+ /// Go to the next point.
+ void next_();
+ protected:
+ typename super::std_container::const_reverse_iterator it_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+ template <typename P>
+ run_bkd_piter_<P>::run_bkd_piter_(const run_pset_<P>& pset) :
+ super(pset)
+ {
+ it_ = this->con_.rend();
+ this->site_.pset_pos_() = this->con_.size();
+ }
+
+ template <typename P>
+ bool
+ run_bkd_piter_<P>::is_valid() const
+ {
+ return it_ != this->con_.rend();
+ }
+
+ template <typename P>
+ void
+ run_bkd_piter_<P>::invalidate()
+ {
+ it_ = this->con_.rend();
+ this->site_.pset_pos_() = this->con_.size();
+ }
+
+ template <typename P>
+ void
+ run_bkd_piter_<P>::start()
+ {
+ it_ = this->con_.rbegin();
+ this->site_.range_start_() = it_->first;
+ this->site_.index_() = it_->second - 1;
+ this->site_.pset_pos_() = this->con_.size() - 1;
+ this->p_ = this->site_.range_start_();
+ this->p_[0] += this->site_.index_();
+ }
+
+ template <typename P>
+ void
+ run_bkd_piter_<P>::next_()
+ {
+ mln_precondition(this->is_valid());
+ --(this->site_.index_());
+
+ if (this->site_.index_() + 1 == 0)
+ {
+ ++it_;
+ --this->site_.pset_pos_();
+ this->site_.range_start_() = it_->first;
+ this->site_.index_() = this->it_->second - 1;
+ }
+ this->p_ = this->site_.range_start_();
+ this->p_[0] += this->site_.index_();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_RUN_PSET_HH
Index: mln/core/rle_image.hh
--- mln/core/rle_image.hh (revision 0)
+++ mln/core/rle_image.hh (revision 0)
@@ -0,0 +1,143 @@
+// 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.
+
+#ifndef MLN_CORE_RLE_IMAGE_HH
+# define MLN_CORE_RLE_IMAGE_HH
+
+/*! \file mln/core/rle_image.hh
+ *
+ * \brief Definition of mln::rle_image
+ */
+
+# include <mln/core/internal/run_image.hh>
+# include <mln/core/internal/run_psite.hh>
+# include <mln/value/set.hh>
+# include <vector>
+
+namespace mln
+{
+
+ /*! \brief RLE image.
+ *
+ *
+ * Parameter \c P is the type of the image points.
+ * Parameter \c T is the type of the pixel values.
+ * This image is not point wise accessible.
+ */
+ template <typename P, typename T>
+ class rle_image : public internal::run_image_< P, rle_image<P, T> >
+ {
+ public:
+ typedef T value;
+ typedef T& lvalue;
+ typedef const T rvalue;
+ typedef internal::run_psite<P> psite;
+ typedef mln::value::set<T> vset;
+
+ rle_image();
+
+ /// Add a new range to the image.
+ void insert(const P& p, unsigned len, T value);
+
+ /// Read-only access to the image value located at point \p p.
+ rvalue operator() (const psite& site) const;
+
+ /// Read-write access to the image value located at point \p p.
+ lvalue operator() (const psite& site);
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Change value type.
+ template <typename U>
+ struct change_value
+ {
+ typedef rle_image<P, U> ret;
+ };
+ protected:
+ /// Image values.
+ std::vector<T> values_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename T>
+ rle_image<P, T>::rle_image()
+ {
+ }
+
+ template <typename P, typename T>
+ bool
+ rle_image<P, T>::has_data() const
+ {
+ return values_.size() != 0;
+ }
+
+ template <typename P, typename T>
+ const typename rle_image<P, T>::vset&
+ rle_image<P, T>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename T>
+ void
+ rle_image<P, T>::insert(const P& p, unsigned len, T value)
+ {
+ this->domain_.insert(p, len);
+ values_.push_back(value);
+ }
+
+ template <typename P, typename T>
+ typename rle_image<P, T>::rvalue
+ rle_image<P, T>::operator() (const typename rle_image<P, T>::psite& site)
+ const
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < values_.size());
+ return values_[site.pset_pos_()];
+ }
+
+ template <typename P, typename T>
+ typename rle_image<P, T>::lvalue
+ rle_image<P, T>::operator() (const typename rle_image<P, T>::psite& site)
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < values_.size());
+ return values_[site.pset_pos_()];
+ }
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_RLE_IMAGE_HH
Index: mln/core/rle_encode.hh
--- mln/core/rle_encode.hh (revision 0)
+++ mln/core/rle_encode.hh (revision 0)
@@ -0,0 +1,110 @@
+// 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.
+
+#ifndef MLN_CORE_RLE_ENCODE_HH
+# define MLN_CORE_RLE_ENCODE_HH
+
+/*! \file mln/core/sparse_image.hh
+ *
+ * \brief FIXME
+ */
+
+# include <mln/core/sparse_image.hh>
+# include <vector>
+
+namespace mln
+{
+
+ /*!
+ ** encode an image class to a rle_image
+ **
+ ** @param input has to respect the Image concept
+ **
+ ** @return rle_image
+ */
+ template <typename I>
+ rle_image<mln_point(I), mln_value(I)>
+ rle_encode(const Image<I>& input);
+
+# ifndef MLN_INCLUDE_ONLY
+ /*!
+ ** test if Point p1 and p2 are on the same line
+ */
+ template <typename P>
+ bool
+ on_the_same_line(const P& p1, const P& p2)
+ {
+ unsigned dim = P::dim;
+ bool same_line = true;
+
+ for (int n = dim - 1; same_line and n > 0; --n)
+ same_line = (p1[n] == p2[n]);
+ return same_line;
+ }
+
+ template <typename I>
+ rle_image<mln_point(I), mln_value(I)>
+ rle_encode(const Image<I>& input)
+ {
+ rle_image<mln_point(I), mln_value(I)> output;
+ mln_piter(I) p (exact(input).domain());
+ unsigned len = 1;
+ /// range point start
+ mln_point(I) rstart;
+ /// range value
+ mln_value(I) rvalue;
+
+ p.start();
+ if (!p.is_valid())
+ return output;
+
+ rstart = p;
+ rvalue = exact(input)(p);
+ p.next_();
+ while (p.is_valid())
+ {
+ if (rvalue == exact(input)(p) and
+ on_the_same_line(rstart, mln_point(I)(p)))
+ ++len;
+ else
+ {
+ output.insert(rstart, len, rvalue);
+ len = 1;
+ rstart = p;
+ rvalue = exact(input)(p);
+ }
+ p.next_();
+ }
+ output.insert(rstart, len, rvalue);
+ return output;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+}
+
+#endif // ! MLN_CORE_RLE_ENCODE_HH
Index: mln/core/sparse_image.hh
--- mln/core/sparse_image.hh (revision 0)
+++ mln/core/sparse_image.hh (revision 0)
@@ -0,0 +1,147 @@
+// 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.
+
+#ifndef MLN_CORE_SPARSE_IMAGE_HH
+# define MLN_CORE_SPARSE_IMAGE_HH
+
+/*! \file mln/core/sparse_image.hh
+ *
+ * \brief Definition of mln::sparse_image
+ */
+
+# include <mln/core/internal/run_image.hh>
+# include <mln/core/internal/run_psite.hh>
+# include <mln/value/set.hh>
+# include <vector>
+
+namespace mln
+{
+
+ /*! \brief Sparse image.
+ *
+ *
+ * Parameter \c P is the type of the image points.
+ * Parameter \c T is the type of the pixel values.
+ * This image is not point wise accessible.
+ */
+ template <typename P, typename T>
+ class sparse_image : public internal::run_image_< P, sparse_image<P, T> >
+ {
+ public:
+ typedef T value;
+ typedef T& lvalue;
+ typedef const T rvalue;
+ typedef internal::run_psite<P> psite;
+ typedef mln::value::set<T> vset;
+
+ sparse_image();
+
+ /// Add a new range to the image.
+ void insert(const P& p, unsigned len, const std::vector<T>& value);
+
+ /// Read-only access to the image value located at point \p p.
+ rvalue operator() (const psite& p) const;
+
+ /// Read-write access to the image value located at point \p p.
+ lvalue operator() (const psite& p);
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Change value type.
+ template <typename U>
+ struct change_value
+ {
+ typedef sparse_image<P, U> ret;
+ };
+ protected:
+ /// Image values.
+ std::vector< std::vector<value> > values_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename T>
+ sparse_image<P, T>::sparse_image()
+ {
+ }
+
+ template <typename P, typename T>
+ bool
+ sparse_image<P, T>::has_data() const
+ {
+ return values_.size() != 0;
+ }
+
+ template <typename P, typename T>
+ const typename sparse_image<P, T>::vset&
+ sparse_image<P, T>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename T>
+ void
+ sparse_image<P, T>::insert(const P& p, unsigned len,
+ const std::vector<T>& value)
+ {
+ this->domain_.insert(p, len);
+ values_.push_back(value);
+ }
+
+ template <typename P, typename T>
+ typename sparse_image<P, T>::rvalue
+ sparse_image<P, T>::operator()
+ (const typename sparse_image<P, T>::psite& site) const
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < values_.size() &&
+ site.index_() < values_[site.pset_pos_()].size());
+ return values_[site.pset_pos_()][site.index_()];
+ }
+
+ template <typename P, typename T>
+ typename sparse_image<P, T>::lvalue
+ sparse_image<P, T>::operator()
+ (const typename sparse_image<P,T>::psite& site)
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < values_.size() &&
+ site.index_() < values_[site.pset_pos_()].size());
+ return values_[site.pset_pos_()][site.index_()];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SPARSE_IMAGE_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean-up windows!
* mln/core/internal/dpoints_base.hh: New.
* mln/core/concept/doc/weighted_window.hh: New.
* mln/core/w_window.hh
(element, nelements): Rename as...
(dp, ndpoints): ...these.
(sym_): Add body.
Update.
* mln/core/window.hh (super_): Update.
(qiter): Remove; obsolete.
(point, dpoint, is_centered, delta): Remove; factored.
* mln/core/dpoints_pixter.hh: Update.
* mln/core/concept/weighted_window.hh
(is_symmetric): Remove; too ambiguous.
* mln/core/win/vline2d.hh: Update inheritance.
* mln/core/win/hline2d.hh: Likewise.
* mln/core/win/rectangle2d.hh: Likewise.
(qiter): Remove; obsolete.
concept/doc/weighted_window.hh | 83 ++++++++++++++++++++
concept/weighted_window.hh | 16 +--
dpoints_pixter.hh | 8 -
internal/dpoints_base.hh | 166 +++++++++++++++++++++++++++++++++++++++++
w_window.hh | 79 ++++++++++---------
win/hline2d.hh | 4
win/rectangle2d.hh | 8 -
win/vline2d.hh | 4
window.hh | 61 ++++-----------
9 files changed, 329 insertions(+), 100 deletions(-)
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 1044)
+++ mln/core/w_window.hh (working copy)
@@ -62,21 +62,21 @@
/// Dpoint associated type.
typedef D dpoint;
- /// Point_Iterator type to browse the points of a generic w_window.
+
+ /// Point_Iterator type to browse (forward) the points of a generic w_window.
typedef with_w_< dpoints_fwd_piter<D>, W > fwd_qiter;
- /// Point_Iterator type to browse the points of a generic w_window.
+ /// Point_Iterator type to browse (backward) the points of a generic w_window.
typedef with_w_< dpoints_bkd_piter<D>, W > bkd_qiter;
/// Constructor without argument.
w_window_();
- /// Give the corresponding window.
- const window_<D>& window() const;
- /// Give the symmetrical w_window.
- w_window_<D,W> sym_() const;
+ /// Insert a delta-point \p d and its associated weight \p w.
+ w_window_<D,W>& insert(const D& d, const W& w);
+
/// Give the \p i-th weight.
W weight(unsigned i) const;
@@ -84,17 +84,22 @@
/// Give access to the vector of weights.
const std::vector<W>& weights() const;
+
+ // Give the \p i-th delta-point.
+ const D& dp(unsigned i) const;
+
+ /// Give the number of delta-points.
+ unsigned ndpoints() const;
+
/// Give access to the vector of delta-points.
const std::vector<D>& vect() const;
- /// Insert a delta-point \p d and its associated weight \p w.
- w_window_<D,W>& insert(const D& d, const W& w);
+ /// Give the corresponding window.
+ const window_<D>& window() const;
- /// Give the number of elements (pairs of delta-point/weight).
- unsigned nelements() const;
- // FIXME: Rename as dpoint(i); same in mln/core/dpoints_pixter.hh:174.
- const D& element(unsigned i) const;
+ /// Give the symmetrical w_window.
+ w_window_<D,W> sym_() const;
protected:
@@ -154,7 +159,7 @@
std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin)
{
ostr << '[';
- for (unsigned i = 0; i < wwin.window().nelements(); ++i)
+ for (unsigned i = 0; i < wwin.window().ndpoints(); ++i)
ostr << wwin.vect()[i] << ':' << wwin.weight(i) << ' ';
return ostr << ']';
}
@@ -172,34 +177,34 @@
}
template <typename D, typename W>
- const std::vector<D>&
- w_window_<D,W>::vect() const
+ const D&
+ w_window_<D,W>::dp(unsigned i) const
{
- return win_.vect();
+ mln_precondition(i < win_.ndpoints());
+ mln_invariant(wei_.size() = win_.ndpoints());
+ return win_.dp(i);
}
template <typename D, typename W>
- const std::vector<W>&
- w_window_<D,W>::weights() const
+ unsigned
+ w_window_<D,W>::ndpoints() const
{
- return wei_;
+ mln_invariant(wei_.size() = win_.ndpoints());
+ return win_.ndpoints();
}
template <typename D, typename W>
- unsigned
- w_window_<D,W>::nelements() const
+ const std::vector<D>&
+ w_window_<D,W>::vect() const
{
- mln_invariant(wei_.size() = win_.nelements());
- return win_.nelements();
+ return win_.vect();
}
template <typename D, typename W>
- const D&
- w_window_<D,W>::element(unsigned i) const
+ const std::vector<W>&
+ w_window_<D,W>::weights() const
{
- mln_precondition(i < wei_.size());
- mln_invariant(wei_.size() = win_.nelements());
- return win_.element(i);
+ return wei_;
}
template <typename D, typename W>
@@ -207,7 +212,7 @@
w_window_<D,W>::weight(unsigned i) const
{
mln_precondition(i < wei_.size());
- mln_invariant(wei_.size() = win_.nelements());
+ mln_invariant(wei_.size() = win_.ndpoints());
return wei_[i];
}
@@ -215,24 +220,27 @@
w_window_<D,W>&
w_window_<D,W>::insert(const D& d, const W& w)
{
+ mln_invariant(wei_.size() = win_.ndpoints());
+
if (win_.has(d))
// no-op
return *this;
// memorization: d_i -> w_i
std::map<D, W> memo_wei_;
- for (unsigned i = 0; i < win_.nelements(); ++i)
- memo_wei_[win_.element(i)] = wei_[i];
+ for (unsigned i = 0; i < win_.ndpoints(); ++i)
+ memo_wei_[win_.dp(i)] = wei_[i];
// insertion of d and w:
win_.insert(d);
memo_wei_[d] = w;
// re-mapping: w_i <- d_i
- wei_.resize(win_.nelements());
- for (unsigned i = 0; i < win_.nelements(); ++i)
- wei_[i] = memo_wei_[win_.element(i)];
+ wei_.resize(win_.ndpoints());
+ for (unsigned i = 0; i < win_.ndpoints(); ++i)
+ wei_[i] = memo_wei_[win_.dp(i)];
+ mln_invariant(wei_.size() = win_.ndpoints());
return *this;
}
@@ -241,7 +249,8 @@
w_window_<D,W>
w_window_<D,W>::sym_() const
{
- // FIXME
+ w_window_<D,W> tmp(*this);
+ tmp.win_ = - this->win_;
return *this;
}
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1044)
+++ mln/core/window.hh (working copy)
@@ -35,13 +35,11 @@
# include <mln/core/concept/window.hh>
# include <mln/core/concept/generalized_point.hh>
-# include <mln/core/internal/set_of.hh>
+# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint.hh>
# include <mln/core/box.hh>
# include <mln/convert/to_dpoint.hh>
-# include <mln/fun/i2v/all.hh>
-# include <mln/norm/infty.hh>
namespace mln
@@ -58,14 +56,11 @@
* parameter is \c D, type of delta-point.
*/
template <typename D>
- struct window_ : public Window< window_<D> >,
- public internal::set_of_<D>
+ class window_ : public Window< window_<D> >,
+ public internal::dpoints_base_<D, window_<D> >
{
- /// Point associated type.
- typedef mln_point(D) point;
-
- /// Dpoint associated type.
- typedef D dpoint;
+ typedef internal::dpoints_base_<D, window_<D> > super_;
+ public:
/*! \brief Point_Iterator type to browse the points of a generic window
* w.r.t. the ordering of delta-points.
@@ -75,11 +70,7 @@
/*! \brief Point_Iterator type to browse the points of a generic window
* w.r.t. the reverse ordering of delta-points.
*/
- typedef internal::fixme bkd_qiter;
-
- /*! \brief Same as fwd_qiter.
- */
- typedef fwd_qiter qiter;
+ typedef dpoints_bkd_piter<D> bkd_qiter;
/*! \brief Constructor without argument.
@@ -88,27 +79,20 @@
*/
window_();
- /*! \brief Test if the window is centered.
- *
- * \return True if the delta-point 0 belongs to the window.
- */
- bool is_centered() const;
/*! \brief Test if the window is symmetric.
*/
bool is_symmetric() const;
- /*! \brief Give the maximum coordinate gap between the window
- center and a window point.
- */
- unsigned delta() const;
+ /// Insert a delta-point \p dp.
+ window_<D>& insert(const D& dp);
/// Give the symmetrical window.
window_<D> sym_() const;
protected:
- box_<point> b_;
+ box_<mln_point(D)> b_;
};
@@ -142,30 +126,18 @@
}
template <typename D>
- bool window_<D>::is_centered() const
- {
- static const D origin = all(0);
- return this->has(origin);
- }
-
- template <typename D>
bool window_<D>::is_symmetric() const
{
return this->sym_() = *this;
}
template <typename D>
- unsigned window_<D>::delta() const
+ window_<D>&
+ window_<D>::insert(const D& dp)
{
- unsigned d = 0;
- const unsigned n = this->nelements();
- for (unsigned i = 0; i < n; ++i)
- {
- unsigned dd = norm::infty(this->element(i).to_vec());
- if (dd > d)
- d = dd;
- }
- return d;
+ mln_precondition(! has(dp));
+ this->super_::insert(dp);
+ return *this;
}
template <typename D>
@@ -173,12 +145,13 @@
window_<D>::sym_() const
{
window_<D> tmp;
- const unsigned n = this->nelements();
+ const unsigned n = this->ndpoints();
for (unsigned i = 0; i < n; ++i)
- tmp.insert(- this->element(i));
+ tmp.insert(- this->dp(i));
return tmp;
}
+
// operators
template <typename W>
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 1044)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -170,12 +170,12 @@
void
dpoints_fwd_pixter<I>::init_(const Dps& dps)
{
- for (unsigned i = 0; i < dps.nelements(); ++i)
- offset_.push_back(this->image_.offset(dps.element(i)));
+ for (unsigned i = 0; i < dps.ndpoints(); ++i)
+ offset_.push_back(this->image_.offset(dps.dp(i)));
// offset_[0] is absolute
// other offsets are relative:
- if (dps.nelements() > 1)
- for (unsigned i = dps.nelements() - 1; i > 0; --i)
+ if (dps.ndpoints() > 1)
+ for (unsigned i = dps.ndpoints() - 1; i > 0; --i)
offset_[i] -= offset_[i - 1];
invalidate();
}
Index: mln/core/internal/dpoints_base.hh
--- mln/core/internal/dpoints_base.hh (revision 0)
+++ mln/core/internal/dpoints_base.hh (revision 0)
@@ -0,0 +1,166 @@
+// 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.
+
+#ifndef MLN_CORE_INTERNAL_DPOINTS_BASE_HH
+# define MLN_CORE_INTERNAL_DPOINTS_BASE_HH
+
+/*! \file mln/core/internal/dpoints_base_.hh
+ *
+ * \brief Definition of a base class for classes based on a set of dpoints.
+ */
+
+# include <mln/core/internal/set_of.hh>
+# include <mln/fun/i2v/all.hh>
+# include <mln/norm/infty.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+
+ /*! \brief FIXME.
+ */
+ template <typename D, typename E>
+ class dpoints_base_ : protected internal::set_of_<D>
+ {
+ typedef internal::set_of_<D> super_;
+ public:
+
+ /// Point associated type.
+ typedef mln_point(D) point;
+
+ /// Dpoint associated type.
+ typedef D dpoint;
+
+
+ /*! \brief Test if the window is centered.
+ *
+ * \return True if the delta-point 0 belongs to the window.
+ */
+ bool is_centered() const;
+
+ /*! \brief Test if the window is empty (null size; no delta-point).
+ */
+ bool is_empty() const;
+
+ /*! \brief Give the maximum coordinate gap between the window
+ center and a window point.
+ */
+ unsigned delta() const;
+
+ /// Give the number of delta-points.
+ unsigned ndpoints() const;
+
+ /// Test if the delta-point \p dp belongs to the window.
+ bool has(const D& dp) const;
+
+ // Give the \p i-th delta-point.
+ const D& dp(unsigned i) const;
+
+ // Give the vector of delta-points.
+ const std::vector<D>& vect() const;
+
+ protected:
+ dpoints_base_();
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename D, typename E>
+ dpoints_base_<D,E>::dpoints_base_()
+ {
+ }
+
+ template <typename D, typename E>
+ bool dpoints_base_<D,E>::is_centered() const
+ {
+ static const D origin = all(0);
+ return this->super_::has(origin);
+ }
+
+ template <typename D, typename E>
+ bool dpoints_base_<D,E>::is_empty() const
+ {
+ return this->super_::is_empty();
+ }
+
+ template <typename D, typename E>
+ unsigned dpoints_base_<D,E>::delta() const
+ {
+ unsigned d = 0;
+ const unsigned n = ndpoints();
+ for (unsigned i = 0; i < n; ++i)
+ {
+ unsigned dd = norm::infty(dp(i).to_vec());
+ if (dd > d)
+ d = dd;
+ }
+ return d;
+ }
+
+ template <typename D, typename E>
+ unsigned
+ dpoints_base_<D,E>::ndpoints() const
+ {
+ return this->super_::nelements();
+ }
+
+ template <typename D, typename E>
+ const D&
+ dpoints_base_<D,E>::dp(unsigned i) const
+ {
+ mln_precondition(i < ndpoints());
+ return this->element(i);
+ }
+
+ template <typename D, typename E>
+ const std::vector<D>&
+ dpoints_base_<D,E>::vect() const
+ {
+ return this->super_::vect();
+ }
+
+ template <typename D, typename E>
+ bool
+ dpoints_base_<D,E>::has(const D& dp) const
+ {
+ return this->super_::has(dp);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_DPOINTS_BASE_HH
Index: mln/core/concept/weighted_window.hh
--- mln/core/concept/weighted_window.hh (revision 1044)
+++ mln/core/concept/weighted_window.hh (working copy)
@@ -50,30 +50,30 @@
struct Weighted_Window : public Object<E>
{
/*
+ typedef fwd_qiter;
+ typedef bkd_piter;
+
typedef point;
typedef dpoint;
- typedef fwd_qiter;
- typedef bkd_qiter;
-
E sym_() const;
*/
+ /// Test if the weighted window is empty; final method.
bool is_empty() const
{
return exact(this)->window().is_empty();
}
+ /// Test if the weighted window is centered; final method.
bool is_centered() const
{
return exact(this)->window().is_centered();
}
- bool is_symmetric() const
- {
- return exact(this)->window().is_symmetric();
- }
+ // FIXME: Remove because too ambiguous: bool is_symmetric() const
+ /// Give the maximum coordinate gap.
unsigned delta() const
{
return exact(this)->window().delta();
@@ -84,7 +84,7 @@
};
- /*! \brief Compute the symmetrical weighted_window of \p rhs.
+ /*! \brief Compute the symmetrical weighted window of \p rhs.
*
* \relates mln::Weighted_Window
*/
Index: mln/core/concept/doc/weighted_window.hh
--- mln/core/concept/doc/weighted_window.hh (revision 0)
+++ mln/core/concept/doc/weighted_window.hh (revision 0)
@@ -0,0 +1,83 @@
+// 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 mln/core/concept/doc/weighted_window.hh
+ * \brief This file documents the concept of mln::Weighted_Window.
+ */
+
+namespace mln
+{
+
+ namespace doc
+ {
+
+ /*! \brief Documentation class for mln::Weighted_Window.
+ *
+ * A weighted_window is the definition of a set of points located
+ * around a central point, with a weight associated to each point.
+ *
+ * \see mln::Weighted_Window
+ */
+ template <typename E>
+ struct Weighted_Window : public Object<E>
+ {
+
+ /*! \brief Point_Iterator type associated to this weighted_window to browse its
+ * points in a forward way.
+ */
+ typedef void fwd_qiter;
+
+ /*! \brief Point_Iterator type associated to this weighted_window to browse its
+ * points in a backward way.
+ */
+ typedef void bkd_qiter;
+
+ /*! \brief Test if the weighted window is empty.
+ *
+ * A weighted_window of null size is empty.
+ */
+ bool is_empty() const;
+
+ /*! \brief Test if the weighted_window is centered.
+ *
+ * A weighted window is centered is the origin belongs to it.
+ */
+ bool is_centered() const;
+
+ /*! \brief Give the maximum coordinate gap between the window
+ center and a window point.
+ */
+ unsigned delta() const;
+
+ /*! \brief Give the symmetrical weighted_window.
+ */
+ E sym_() const;
+ };
+
+ } // end of namespace mln::doc
+
+} // end of namespace mln
Index: mln/core/win/vline2d.hh
--- mln/core/win/vline2d.hh (revision 1044)
+++ mln/core/win/vline2d.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/window.hh>
-# include <mln/core/internal/set_of.hh>
+# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint2d.hh>
# include <mln/core/dpoints_piter.hh>
@@ -57,7 +57,7 @@
* is defined with length = 5.
*/
struct vline2d : public Window< vline2d >,
- public mln::internal::set_of_<dpoint2d>
+ public internal::dpoints_base_< dpoint2d, vline2d >
{
/// Point associated type.
typedef point2d point;
Index: mln/core/win/hline2d.hh
--- mln/core/win/hline2d.hh (revision 1044)
+++ mln/core/win/hline2d.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/window.hh>
-# include <mln/core/internal/set_of.hh>
+# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint2d.hh>
# include <mln/core/dpoints_piter.hh>
@@ -55,7 +55,7 @@
* is defined with length = 5.
*/
struct hline2d : public Window< hline2d >,
- public mln::internal::set_of_<dpoint2d>
+ public internal::dpoints_base_< dpoint2d, hline2d >
{
/// Point associated type.
typedef point2d point;
Index: mln/core/win/rectangle2d.hh
--- mln/core/win/rectangle2d.hh (revision 1044)
+++ mln/core/win/rectangle2d.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/window.hh>
-# include <mln/core/internal/set_of.hh>
+# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint2d.hh>
# include <mln/core/dpoints_piter.hh>
@@ -57,7 +57,7 @@
* is defined with height = 3 and width = 5.
*/
struct rectangle2d : public Window< rectangle2d >,
- public mln::internal::set_of_<dpoint2d>
+ public internal::dpoints_base_< dpoint2d, rectangle2d >
{
/// Point associated type.
typedef point2d point;
@@ -75,9 +75,6 @@
*/
typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
- /*! \brief Same as fwd_qiter.
- */
- typedef fwd_qiter qiter;
/*! \brief Constructor.
*
@@ -88,6 +85,7 @@
*/
rectangle2d(unsigned height, unsigned width);
+
/*! \brief Test if the window is centered.
*
* \return True.
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a queue of points.
* tests/pqueue.cc: New.
* TODO: Update.
* mln/core/pvec.hh: Fix.
* mln/core/pqueue.hh: New.
TODO | 4
mln/core/pqueue.hh | 253 +++++++++++++++++++++++++++++++++++++++++++++++++++++
mln/core/pvec.hh | 8 +
tests/pqueue.cc | 57 +++++++++++
4 files changed, 315 insertions(+), 7 deletions(-)
Index: tests/pqueue.cc
--- tests/pqueue.cc (revision 0)
+++ tests/pqueue.cc (revision 0)
@@ -0,0 +1,57 @@
+// 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/pqueue.cc
+ *
+ * \brief Tests on mln::pqueue.
+ */
+
+#include <mln/core/point2d.hh>
+#include <mln/core/pqueue.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ pqueue<point2d> q;
+ q
+ .push(make::point2d(6, 9))
+ .push(make::point2d(5, 1))
+ .push(make::point2d(4, 2));
+ mln_assertion(q.npoints() = 3);
+
+ std::cout << q.bbox() << std::endl;
+ std::cout << q << std::endl;
+
+ q.pop();
+ mln_assertion(q.npoints() = 2);
+ point2d p = q.front();
+ mln_assertion(q.npoints() = 2);
+ mln_assertion(p = make::point2d(5, 1));
+}
Index: TODO
--- TODO (revision 1042)
+++ TODO (working copy)
@@ -17,7 +17,6 @@
value::proxy to dispatch read/write + the corresponding image type
a mean_value object { sum; count } and operator+
-t_image to "transpose" the 0 and the i-th coordinates
** extensions
@@ -28,9 +27,6 @@
* renaming
-mlc into metal
-+ look for "same_grid" etc.
-rectangle2d, hlin2d, etc -> core/win/
* clean-up
Index: mln/core/pvec.hh
--- mln/core/pvec.hh (revision 1042)
+++ mln/core/pvec.hh (working copy)
@@ -106,7 +106,7 @@
mutable accu::bbox<P> bb_;
mutable bool bb_needs_update_;
- void update_bb_();
+ void update_bb_() const;
// FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
};
@@ -129,9 +129,9 @@
template <typename P>
void
- pvec<P>::update_bb_()
+ pvec<P>::update_bb_() const
{
- bb_.clear();
+ bb_.init();
for (unsigned i = 0; i < vect_.size(); ++i)
bb_.take(vect_[i]);
bb_needs_update_ = false;
@@ -169,6 +169,8 @@
pvec<P>::append(const P& p)
{
vect_.push_back(p);
+ if (! bb_needs_update_)
+ bb_needs_update_ = true;
return *this;
}
Index: mln/core/pqueue.hh
--- mln/core/pqueue.hh (revision 0)
+++ mln/core/pqueue.hh (revision 0)
@@ -0,0 +1,253 @@
+// 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.
+
+#ifndef MLN_CORE_PQUEUE_HH
+# define MLN_CORE_PQUEUE_HH
+
+/*! \file mln/core/pqueue.hh
+ *
+ * \brief Definition of a point set class based on std::deque.
+ */
+
+# include <vector>
+# include <deque>
+# include <algorithm>
+# include <iterator>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/pvec_piter.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct pvec_fwd_piter_;
+ template <typename P> struct pvec_bkd_piter_;
+
+
+ /*! \brief Point queue class (based on std::deque).
+ *
+ * This is a mathematical set of points (unique insertion).
+ *
+ * \todo Make it work with P being a Point_Site.
+ * \todo Add a parameter flag to choose another policy for "push"
+ * (i.e., no-op if multiple or allow multiple insertions).
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints() when this container is multiple.
+ */
+ template <typename P>
+ class pqueue : public Point_Set< pqueue<P> >
+ {
+ public:
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef pvec_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef pvec_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ pqueue();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Push a point \p p in the queue.
+ pqueue<P>& push(const P& p);
+
+ /// Pop (remove) the front point \p p from the queue; \p p is the
+ /// least recently inserted point.
+ void pop();
+
+ /// Give the front point \p p of the queue; \p p is the least
+ /// recently inserted point.
+ const P& front() const;
+
+ /// Clear the queue.
+ void clear();
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<P>& vect() const;
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ protected:
+
+ std::deque<P> q_;
+
+ mutable std::vector<P> vect_;
+ mutable bool vect_needs_update_;
+ void vect_update_() const;
+
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+ void bb_update_() const;
+
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ pqueue<P>::pqueue()
+ {
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ pqueue<P>::vect_update_() const
+ {
+ vect_.clear();
+ vect_.reserve(q_.size());
+ std::copy(q_.begin(), q_.end(),
+ std::back_inserter(vect_));
+ vect_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ pqueue<P>::bb_update_() const
+ {
+ bb_.init();
+ for (unsigned i = 0; i < q_.size(); ++i)
+ bb_.take(q_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ pqueue<P>::has(const P& p) const
+ {
+ for (unsigned i = 0; i < q_.size(); ++i)
+ if (q_[i] = p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ std::size_t
+ pqueue<P>::npoints() const
+ {
+ return q_.size();
+ }
+
+ template <typename P>
+ const box_<P>&
+ pqueue<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ bb_update_();
+ return bb_.to_value();
+ }
+
+ template <typename P>
+ pqueue<P>&
+ pqueue<P>::push(const P& p)
+ {
+ mln_precondition(! has(p));
+ // FIXME: Our choice is "error if multiple insertions"
+ q_.push_back(p);
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ void
+ pqueue<P>::pop()
+ {
+ q_.pop_front();
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ const P&
+ pqueue<P>::front() const
+ {
+ mln_precondition(! q_.empty());
+ return q_.front();
+ }
+
+ template <typename P>
+ void
+ pqueue<P>::clear()
+ {
+ q_.clear();
+ vect_.clear();
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ pqueue<P>::vect() const
+ {
+ if (vect_needs_update_)
+ vect_update_();
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ pqueue<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return q_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PQUEUE_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add stack and transpose morphers.
* tests/t_image.cc: New.
* tests/stack.cc: New.
* tests/approx_median.cc: New.
* mln/core/t_image.hh: New.
* mln/value/stack.hh: New.
* tests/median.cc: Update.
* tests/README: Update.
* mln/core/internal/image_base.hh
(morpher_lvalue_): New.
* mln/core/internal/image_adaptor.hh: Use morpher_lvalue_.
(image_adaptor_): Change Image<I> into I.
* mln/core/safe.hh: Update.
* mln/core/image2d_b.hh: Remove dead code.
* mln/metal/vec.hh: Split decls and defs.
(operator<<): New.
* mln/level/median.hh (hline2d): Update.
(vline2d): New.
mln/core/image2d_b.hh | 18 ---
mln/core/internal/image_adaptor.hh | 8 -
mln/core/internal/image_base.hh | 13 ++
mln/core/safe.hh | 4
mln/core/t_image.hh | 178 ++++++++++++++++++++++++++++++++++
mln/level/median.hh | 45 ++++----
mln/metal/vec.hh | 44 +++++++-
mln/value/stack.hh | 191 +++++++++++++++++++++++++++++++++++++
tests/README | 14 ++
tests/approx_median.cc | 59 +++++++++++
tests/median.cc | 4
tests/stack.cc | 49 +++++++++
tests/t_image.cc | 52 ++++++++++
13 files changed, 626 insertions(+), 53 deletions(-)
Index: tests/median.cc
--- tests/median.cc (revision 1041)
+++ tests/median.cc (working copy)
@@ -38,7 +38,6 @@
#include <mln/value/int_u8.hh>
#include <mln/level/median.hh>
-#include <mln/level/approx/median.hh>
@@ -57,7 +56,4 @@
level::median(lena, rect, out);
io::save_pgm(out, "out.pgm");
-
-// level::approx::median(lena, rec, out);
-// io::save_pgm(out, "outa.pgm");
}
Index: tests/t_image.cc
--- tests/t_image.cc (revision 0)
+++ tests/t_image.cc (revision 0)
@@ -0,0 +1,52 @@
+// 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/+t_image.cc
+ *
+ * \brief Tests on mln::t_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/t_image.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+
+ I ima(2, 3);
+ debug::iota(ima);
+ debug::println(ima);
+
+ t_image<I> tima(ima, 0, 1);
+ debug::println(tima);
+}
Index: tests/stack.cc
--- tests/stack.cc (revision 0)
+++ tests/stack.cc (revision 0)
@@ -0,0 +1,49 @@
+// 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/stack.cc
+ *
+ * \brief Tests on mln::value::stack.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/stack.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+
+ I ima(2, 3);
+ debug::iota(ima);
+ debug::println(ima);
+ debug::println(value::stack(ima, ima));
+}
Index: tests/approx_median.cc
--- tests/approx_median.cc (revision 0)
+++ tests/approx_median.cc (revision 0)
@@ -0,0 +1,59 @@
+// 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/approx_median.cc
+ *
+ * \brief Test on mln::level::approx::median.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/win/rectangle2d.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/level/approx/median.hh>
+
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ win::rectangle2d rect(51, 51);
+ border::thickness = 52;
+
+ image2d_b<int_u8>
+ lena = io::load_pgm("../img/lena.pgm"),
+ out(lena.domain());
+
+ level::approx::median(lena, rect, out);
+ io::save_pgm(out, "out.pgm");
+}
Index: tests/README
--- tests/README (revision 1041)
+++ tests/README (working copy)
@@ -1,3 +1,17 @@
+
+ -*- outline -*-
+
+
+* compilation
+
g++-4.1 -ansi -pedantic -W -Wall -Wextra -Wconversion -I.. sample.cc
g++-2.95 -ansi -pedantic -W -Wall -Wconversion -ftemplate-depth-51 -I.. sample.cc
+
+
+* bench
+
+naive: 18s
+median: 1s
+approx: 0.05s
+
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1041)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -68,7 +68,7 @@
typedef mln_rvalue(I) rvalue;
/// Return type of read-write access.
- typedef mln_lvalue(I) lvalue;
+ typedef typename internal::morpher_lvalue_<I>::ret lvalue;
/// Test if this image has been initialized.
@@ -94,7 +94,7 @@
I& adaptee_;
/// Constructor from an \p adaptee image.
- image_adaptor_(Image<I>& adaptee);
+ image_adaptor_(I& adaptee);
};
// FIXME: image_const_adaptor_
@@ -148,8 +148,8 @@
}
template <typename I, typename E, typename S>
- image_adaptor_<I,E,S>::image_adaptor_(Image<I>& adaptee)
- : adaptee_(exact(adaptee))
+ image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
+ : adaptee_(adaptee)
{
}
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1041)
+++ mln/core/internal/image_base.hh (working copy)
@@ -43,6 +43,19 @@
{
+ template <typename I>
+ struct morpher_lvalue_
+ {
+ typedef mln_lvalue(I) ret;
+ };
+
+ template <typename I>
+ struct morpher_lvalue_< const I >
+ {
+ typedef mln_rvalue(I) ret;
+ };
+
+
template <typename Is_fast, typename E>
struct select_image_concept_;
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1041)
+++ mln/core/safe.hh (working copy)
@@ -51,6 +51,7 @@
{
typedef safe_image<mln_ch_value(I, U)> ret;
};
+
};
@@ -62,10 +63,9 @@
# ifndef MLN_INCLUDE_ONLY
-
template <typename I>
safe_image<I>::safe_image(Image<I>& ima)
- : super(ima)
+ : super(exact(ima))
{
}
Index: mln/core/t_image.hh
--- mln/core/t_image.hh (revision 0)
+++ mln/core/t_image.hh (revision 0)
@@ -0,0 +1,178 @@
+// 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.
+
+#ifndef MLN_CORE_T_IMAGE_HH
+# define MLN_CORE_T_IMAGE_HH
+
+/*! \file mln/core/t_image.hh
+ *
+ * \brief Definition of the "transposed" image class mln::t_image.
+ */
+
+# include <mln/core/internal/image_adaptor.hh>
+
+
+namespace mln
+{
+
+
+ /*! \brief Transposed image class.
+ *
+ * Swap a couple of coordinates.
+ *
+ * \warning This class only works on images whose domain is a box.
+ */
+ template <typename I>
+ struct t_image : public internal::image_adaptor_< I, t_image<I> >
+ {
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_point(I)& p) const;
+
+ /// Give the definition domain.
+ const box_<mln_point(I)>& domain() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_rvalue(I) operator()(const mln_point(I)& p) const;
+
+ /// Type returned by the read-write pixel value operator.
+ typedef typename internal::morpher_lvalue_<I>::ret lvalue;
+
+ /// Read-write access of pixel value at point site \p p.
+ lvalue operator()(const mln_point(I)& p);
+
+
+ /// Change value type.
+ template <typename U>
+ struct change_value
+ {
+ typedef mln_ch_value(I, U) ret;
+ };
+
+
+ /// Constructor.
+ t_image(I& ima, unsigned c1, unsigned c2);
+
+ protected:
+
+ typedef internal::image_adaptor_< I, t_image<I> > super_;
+ const unsigned c1_, c2_; // coords to swap
+ box_<mln_point(I)> b_;
+
+ mln_point(I) transpose_(const mln_point(I)& p) const;
+ };
+
+
+ template <typename I>
+ t_image<I> swap_coords(Image<I>& ima, unsigned c1, unsigned c2);
+
+ template <typename I>
+ t_image<const I> swap_coords(const Image<I>& ima, unsigned c1, unsigned c2);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ t_image<I> swap_coords(Image<I>& ima, unsigned c1, unsigned c2)
+ {
+ typedef mln_point(I) P;
+ mln_precondition(c1 != c2);
+ mln_precondition(c1 <= P::dim && c2 <= P::dim);
+ t_image<I> tmp(exact(ima), c1, c2);
+ return tmp;
+ }
+
+ template <typename I>
+ t_image<const I> swap_coords(const Image<I>& ima, unsigned c1, unsigned c2)
+ {
+ typedef mln_point(I) P;
+ mln_precondition(c1 != c2);
+ mln_precondition(c1 <= P::dim && c2 <= P::dim);
+ t_image<const I> tmp(exact(ima), c1, c2);
+ return tmp;
+ }
+
+ template <typename I>
+ t_image<I>::t_image(I& ima, unsigned c1, unsigned c2)
+ : super_(ima),
+ c1_(c1),
+ c2_(c2)
+ {
+ mln_precondition(ima.has_data());
+ b_.pmin() = transpose_(this->adaptee_.bbox().pmin());
+ b_.pmax() = transpose_(this->adaptee_.bbox().pmax());
+ }
+
+ template <typename I>
+ mln_point(I)
+ t_image<I>::transpose_(const mln_point(I)& p) const
+ {
+ mln_point(I) tmp(p);
+ tmp[c1_] = p[c2_];
+ tmp[c2_] = p[c1_];
+ return tmp;
+ }
+
+ template <typename I>
+ const box_<mln_point(I)>&
+ t_image<I>::domain() const
+ {
+ mln_precondition(this->has_data());
+ return b_;
+ }
+
+ template <typename I>
+ bool
+ t_image<I>::owns_(const mln_point(I)& p) const
+ {
+ mln_precondition(this->has_data());
+ return this->adaptee_.owns_(transpose_(p));
+ }
+
+ template <typename I>
+ mln_rvalue(I)
+ t_image<I>::operator()(const mln_point(I)& p) const
+ {
+ mln_precondition(this->owns_(p));
+ return this->adaptee_(transpose_(p));
+ }
+
+ template <typename I>
+ typename internal::morpher_lvalue_<I>::ret
+ t_image<I>::operator()(const mln_point(I)& p)
+ {
+ mln_precondition(this->owns_(p));
+ return this->adaptee_(transpose_(p));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_T_IMAGE_HH
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1041)
+++ mln/core/image2d_b.hh (working copy)
@@ -78,28 +78,14 @@
struct image2d_b : public internal::image_base_< box2d, image2d_b<T> >,
public internal::box_impl_< 2, int, image2d_b<T> >
{
-
- // warning: just to make effective types appear in Doxygen
+ // Warning: just to make effective types appear in Doxygen:
typedef box2d pset;
typedef point2d psite;
typedef point2d point;
typedef dpoint2d dpoint;
typedef mln_fwd_piter(box2d) fwd_piter;
typedef mln_bkd_piter(box2d) bkd_piter;
- // end of warning
-
-
-
- // FIXME:
-
-// /// Forward pixel iterator associated to image2d
-// typedef fwd_pixter2d_b<T> fwd_pixter;
-
-// /// Foward pixel iterator on dpoints assoicated to image 2d
-// typedef dpoints_pixter< image2d_b<T> > fwd_qixter;
-
-// typedef fwd_pixter pixter;
-// typedef fwd_qixter qixter;
+ // End of warning.
/// Value associated type.
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1041)
+++ mln/metal/vec.hh (working copy)
@@ -28,6 +28,8 @@
#ifndef MLN_CORE_METAL_VEC_HH
# define MLN_CORE_METAL_VEC_HH
+# include <cstdarg>
+
# include <mln/core/concept/object.hh>
@@ -37,27 +39,55 @@
namespace metal
{
+ // FIXME: Doc! + Change coord into comp.
+
template <unsigned n, typename T>
struct vec : public Object< vec<n,T> >
{
enum { dim = n };
typedef T coord;
- T& operator[](unsigned i)
+ T& operator[](unsigned i);
+ T operator[](unsigned i) const;
+
+ protected:
+ T coord_[n];
+ };
+
+
+ template <unsigned n, typename T>
+ std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n, typename T>
+ T&
+ vec<n,T>::operator[](unsigned i)
{
- assert(i < n);
+ mln_precondition(i < n);
return coord_[i];
}
- T operator[](unsigned i) const
+ template <unsigned n, typename T>
+ T
+ vec<n,T>::operator[](unsigned i) const
{
- assert(i < n);
+ mln_precondition(i < n);
return coord_[i];
}
- protected:
- T coord_[n];
- };
+ template <unsigned n, typename T>
+ std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v)
+ {
+ ostr << "[ ";
+ for (unsigned i = 0; i < n; ++i)
+ ostr << v[i] << ' ';
+ return ostr << ']';
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln::metal
Index: mln/level/median.hh
--- mln/level/median.hh (revision 1041)
+++ mln/level/median.hh (working copy)
@@ -38,6 +38,7 @@
# include <mln/core/window2d.hh>
# include <mln/core/win/hline2d.hh>
+# include <mln/core/t_image.hh>
# include <mln/accu/median.hh>
# include <mln/canvas/sbrowsing.hh>
@@ -156,37 +157,41 @@
}
-
-
template <typename I, typename O>
void median(const I& input, const win::hline2d& win, O& output)
{
typedef mln_coord(I) coord;
const coord
- max_row = input.max_row(),
- min_col = input.min_col(),
- max_col = input.max_col();
+ max_row = input.bbox().max_row(),
+ min_col = input.bbox().min_col(),
+ max_col = input.bbox().max_col();
const coord half = win.length() / 2;
point2d p;
coord& row = p.row();
coord& col = p.col();
+ point2d pt;
+ coord& ct = pt.col();
+
+ point2d pu;
+ coord& cu = pu.col();
+
accu::median<mln_vset(I)> med(input.values());
- for (row = input.min_row(); row <= max_row; ++row)
+ for (row = input.bbox().min_row(); row <= max_row; ++row)
{
- coord ct, cu;
+ pt.row() = pu.row() = row;
// initialization (before first point of the row)
med.init();
for (ct = min_col; ct < min_col + half; ++ct)
- med.take(input.at(row, ct));
+ med.take(input(pt));
// left columns (just take new points)
for (col = min_col; col <= min_col + half; ++col, ++ct)
{
- med.take(input.at(row, ct));
+ med.take(input(pt));
output(p) = med;
}
@@ -194,29 +199,29 @@
cu = min_col;
for (; col <= max_col - half; ++cu, ++col, ++ct)
{
- med.take(input.at(row, ct));
- med.untake(input.at(row, cu));
+ med.take(input(pt));
+ med.untake(input(pu));
output(p) = med;
}
// right columns (now just untake old points)
for (; col <= max_col; ++cu, ++col)
{
- med.untake(input.at(row, cu));
+ med.untake(input(pu));
output(p) = med;
}
}
}
- // FIXME: Use transpose.
-
-// template <typename I, typename O>
-// void median(const I& input, const win::vline2d& win, O& output)
-// {
-
-// median(, win::hline2d(win.length()), output);
-// }
+ template <typename I, typename O>
+ void median(const I& input, const win::vline2d& win, O& output)
+ {
+ t_image<O> swap_output = swap_coords(output, 0, 1);
+ impl::median(swap_coords(input, 0, 1),
+ win::hline2d(win.length()),
+ swap_output);
+ }
} // end of namespace mln::level::impl
Index: mln/value/stack.hh
--- mln/value/stack.hh (revision 0)
+++ mln/value/stack.hh (revision 0)
@@ -0,0 +1,191 @@
+// 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.
+
+#ifndef MLN_VALUE_STACK_HH
+# define MLN_VALUE_STACK_HH
+
+/*! \file mln/value/stack.hh
+ *
+ * \brief Definition of an image class FIXME
+ */
+
+# include <mln/core/internal/image_base.hh>
+# include <mln/metal/vec.hh>
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ /*! \brief FIXME
+ *
+ */
+ template <unsigned n, typename I>
+ struct stack_image : public mln::internal::image_base_< mln_pset(I), stack_image<n,I> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(I) psite;
+
+ /// Point_Set associated type.
+ typedef mln_pset(I) pset;
+
+ /// Value associated type.
+ typedef metal::vec<n, mln_value(I)> value;
+
+ /// Return type of read-only access.
+ typedef value rvalue;
+
+ /// Return type of read-write access.
+ typedef void lvalue; // FIXME
+
+ /// Value set associated type.
+ typedef mln::value::set<value> vset;
+
+
+ /// Constructor.
+ stack_image(const metal::vec<n,I*>& imas);
+
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const psite& p) const;
+
+ /// Give the definition domain.
+ const mln_pset(I)& domain() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ rvalue operator()(const psite& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ void operator()(const psite&);
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Change value type.
+ template <typename U>
+ struct change_value
+ {
+ typedef metal::vec<n,U> vec_n_U;
+ typedef mln_ch_value(I, vec_n_U) ret;
+ };
+
+ protected:
+ metal::vec<n,I*> imas_;
+ };
+
+
+
+ template <typename I>
+ stack_image<2,const I>
+ stack(const Image<I>& ima1, const Image<I>& ima2)
+ {
+ mln_precondition(exact(ima1).domain() = exact(ima2).domain());
+ metal::vec<2, const I*> imas;
+ imas[0] = & exact(ima1);
+ imas[1] = & exact(ima2);
+ stack_image<2, const I> tmp(imas);
+ return tmp;
+ }
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n, typename I>
+ stack_image<n,I>::stack_image(const metal::vec<n,I*>& imas)
+ : imas_(imas)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ {
+ mln_precondition(imas[i] != 0);
+ mln_precondition(imas[i]->has_data());
+ }
+ }
+
+ template <unsigned n, typename I>
+ bool stack_image<n,I>::has_data() const
+ {
+ for (unsigned i = 0; i < n; ++i)
+ mln_invariant(imas_[i]->has_data());
+ return true;
+ }
+
+ template <unsigned n, typename I>
+ bool stack_image<n,I>::owns_(const psite& p) const
+ {
+ for (unsigned i = 0; i < n; ++i)
+ if (! imas_[i]->owns_(p))
+ return false;
+ return true;
+ }
+
+ template <unsigned n, typename I>
+ const mln_pset(I)&
+ stack_image<n,I>::domain() const
+ {
+ return imas_[0]->domain();
+ }
+
+ template <unsigned n, typename I>
+ metal::vec<n, mln_value(I)>
+ stack_image<n,I>::operator()(const psite& p) const
+ {
+ mln_precondition(this->owns_(p));
+ metal::vec<n, mln_value(I)> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = imas_[i]->operator()(p);
+ return tmp;
+ }
+
+ template <unsigned n, typename I>
+ void
+ stack_image<n,I>::operator()(const psite&)
+ {
+ mln_invariant(0); // FIXME: Turn into a compile-time error...
+ }
+
+ template <unsigned n, typename I>
+ const mln::value::set< metal::vec<n, mln_value(I)> >&
+ stack_image<n,I>::values() const
+ {
+ return vset::the();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_STACK_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Various clean-ups + add line2d.
Clean-up functions.
* mln/fun/i2v,
* mln/fun/p2b,
* mln/fun/p2v,
* mln/fun/v2v: New directories.
* mln/fun/chess.hh: Rename as...
* mln/fun/p2b/chess.hh: New.
* mln/fun/to_enc.hh: Rename as...
* mln/fun/v2v/enc.hh: ...this.
(to_enc): Rename as...
(enc): ...this.
* mln/fun/all.hh: Rename as...
* mln/fun/i2v/all.hh: ...this.
* mln/core/point.hh,
* mln/core/window.hh,
* mln/core/dpoint.hh,
* mln/core/image2d_b.hh,
* mln/level/to_enc.hh: Update.
Clean-up windows.
* mln/core/win: New directory.
* mln/core/hline2d.hh: Rename as...
* mln/core/win/hline2d.hh: ...this.
* mln/core/rectangle2d.hh: Rename as...
* mln/core/win/rectangle2d.hh: ...this.
* mln/core/vline2d.hh: Rename as...
* mln/core/win/vline2d.hh: ...this.
* tests/median.cc,
* tests/fast_median.cc,
* tests/main.cc,
* tests/to_image.cc,
* tests/psubset.cc,
* tests/fimage.cc,
* tests/rectangle2d.cc,
* tests/cast_image.cc,
* tests/subimage.cc,
* tests/hmedian.cc,
* tests/erosion.cc,
* tests/naive_median.cc,
* mln/core/box2d.hh,
* mln/morpho/erosion.hh,
* mln/level/was.median.hh,
* mln/level/median.hh,
* mln/level/approx/median.hh: Update.
Clean-up metal.
* mlc/equal.hh: Rename as...
* mln/metal/equal.hh: ...this.
* mlc/same_coord.hh: Rename as...
* mln/metal/same_coord.hh: ...this.
* mlc/same_point.hh: Rename as...
* mln/metal/same_point.hh: ...this.
* mlc: Remove.
* mln/core/concept/generalized_point.hh: Update.
Light changes.
* TODO: Update.
* mln/core/dpoints_piter.hh
(dpoints_bkd_piter): New; fake.
* mln/core/fimage.hh: Add doc.
* mln/core/pvec.hh
(pvec_fwd_piter_, pvec_bkd_piter_): Move to...
* mln/core/pvec_piter.hh: ...this new file.
* mln/core/internal/fixme.hh: Add empty body.
New stuff.
* tests/line2d.cc: New.
* mln/pw/all.hh: New.
* mln/core/line2d.hh: New.
* mln/math: New.
* mln/math/min.hh: New.
* mln/math/abs.hh: New.
* mln/math/max.hh: New.
* mln/math/all.hh: New.
* mln/math/sign.hh: New.
* mln/draw: New.
* mln/draw/line.hh: New.
TODO | 3
mln/core/box2d.hh | 2
mln/core/concept/generalized_point.hh | 18 +--
mln/core/dpoint.hh | 2
mln/core/dpoints_piter.hh | 6 +
mln/core/fimage.hh | 3
mln/core/image2d_b.hh | 2
mln/core/internal/fixme.hh | 3
mln/core/line2d.hh | 199 ++++++++++++++++++++++++++++++++++
mln/core/point.hh | 2
mln/core/pvec.hh | 135 +----------------------
mln/core/pvec_piter.hh | 197 +++------------------------------
mln/core/win/hline2d.hh | 19 ++-
mln/core/win/rectangle2d.hh | 23 ++-
mln/core/win/vline2d.hh | 19 ++-
mln/core/window.hh | 2
mln/draw/line.hh | 93 +++++++++++++++
mln/fun/i2v/all.hh | 18 ++-
mln/fun/p2b/chess.hh | 13 +-
mln/fun/v2v/enc.hh | 17 +-
mln/level/approx/median.hh | 10 -
mln/level/median.hh | 8 -
mln/level/to_enc.hh | 4
mln/level/was.median.hh | 2
mln/math/abs.hh | 65 +++++++++++
mln/math/all.hh | 54 +++++++++
mln/math/max.hh | 62 ++++++++++
mln/math/min.hh | 62 ++++++++++
mln/math/sign.hh | 70 +++++++++++
mln/metal/equal.hh | 10 -
mln/metal/same_coord.hh | 14 +-
mln/metal/same_point.hh | 14 +-
mln/morpho/erosion.hh | 10 -
mln/pw/all.hh | 54 +++++++++
tests/cast_image.cc | 4
tests/erosion.cc | 4
tests/fast_median.cc | 6 -
tests/fimage.cc | 4
tests/hmedian.cc | 6 -
tests/line2d.cc | 64 ++++++++++
tests/main.cc | 2
tests/median.cc | 4
tests/naive_median.cc | 4
tests/psubset.cc | 4
tests/rectangle2d.cc | 6 -
tests/subimage.cc | 6 -
tests/to_image.cc | 4
47 files changed, 917 insertions(+), 416 deletions(-)
Index: tests/median.cc
--- tests/median.cc (revision 1039)
+++ tests/median.cc (working copy)
@@ -31,7 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
-#include <mln/core/rectangle2d.hh>
+#include <mln/core/win/rectangle2d.hh>
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
@@ -48,7 +48,7 @@
using namespace mln;
using value::int_u8;
- rectangle2d rect(51, 51);
+ win::rectangle2d rect(51, 51);
border::thickness = 52;
image2d_b<int_u8>
Index: tests/fast_median.cc
--- tests/fast_median.cc (revision 1039)
+++ tests/fast_median.cc (working copy)
@@ -31,7 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
-#include <mln/core/rectangle2d.hh>
+#include <mln/core/win/rectangle2d.hh>
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
@@ -80,7 +80,7 @@
using value::int_u8;
// {
-// rectangle2d rect(3, 3);
+// win::rectangle2d rect(3, 3);
// border::thickness = 4;
// image2d_b<int_u8> ima(3, 3);
// debug::iota(ima);
@@ -90,7 +90,7 @@
{
- rectangle2d rect(51, 51);
+ win::rectangle2d rect(51, 51);
border::thickness = 52;
image2d_b<int_u8>
Index: tests/line2d.cc
--- tests/line2d.cc (revision 0)
+++ tests/line2d.cc (revision 0)
@@ -0,0 +1,64 @@
+// 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/line2d.cc
+ *
+ * \brief Tests on mln::line2d.
+ */
+
+#include <iterator>
+
+#include <mln/core/image2d_b.hh>
+
+#include <mln/level/fill.hh>
+#include <mln/draw/line.hh>
+#include <mln/debug/println.hh>
+
+#include <mln/core/fimage.hh>
+#include <mln/pw/cst.hh>
+#include <mln/level/paste.hh>
+#include <mln/level/compare.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ point2d b = make::point2d(0,0), e = make::point2d(6,9);
+ line2d l(b, e);
+ mln_assertion(l.npoints() = 10);
+
+ image2d_b<bool> ima(10,10);
+ level::fill(ima, false);
+ draw::line(ima, b, e, true);
+
+ image2d_b<bool> ima2(10,10);
+ level::fill(ima2, false);
+ level::paste(pw::cst(true) | l, ima2);
+
+ mln_assertion(ima2 = ima);
+}
Index: tests/main.cc
--- tests/main.cc (revision 1039)
+++ tests/main.cc (working copy)
@@ -32,7 +32,7 @@
#include <mln/debug/println.hh>
#include <mln/core/window2d.hh>
-#include <mln/core/rectangle2d.hh>
+#include <mln/core/win/rectangle2d.hh>
#include <mln/core/neighb2d.hh>
Index: tests/to_image.cc
--- tests/to_image.cc (revision 1039)
+++ tests/to_image.cc (working copy)
@@ -33,7 +33,7 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/window2d.hh>
#include <mln/core/psubset.hh>
-#include <mln/fun/chess.hh>
+#include <mln/fun/p2b/chess.hh>
#include <mln/level/compare.hh>
#include <mln/convert/to_image.hh>
@@ -57,7 +57,7 @@
0, 1, 0, // < center point
1, 0, 1 };
- image2d_b<bool> ima_X = convert::to_image(box_3x3 | fun::chess);
+ image2d_b<bool> ima_X = convert::to_image(box_3x3 | fun::p2b::chess);
window2d win_X = make::window2d(X);
mln_assertion(convert::to_image(win_X) = ima_X);
Index: tests/psubset.cc
--- tests/psubset.cc (revision 1039)
+++ tests/psubset.cc (working copy)
@@ -32,7 +32,7 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/psubset.hh>
-#include <mln/fun/chess.hh>
+#include <mln/fun/p2b/chess.hh>
#include <mln/convert/to_image.hh>
@@ -41,5 +41,5 @@
using namespace mln;
box2d box_8x8 = make::box2d(8, 8);
- mln_assertion((box_8x8 | fun::chess).npoints() = 32);
+ mln_assertion((box_8x8 | fun::p2b::chess).npoints() = 32);
}
Index: tests/fimage.cc
--- tests/fimage.cc (revision 1039)
+++ tests/fimage.cc (working copy)
@@ -32,7 +32,7 @@
#include <mln/core/fimage.hh>
#include <mln/core/box2d.hh>
-#include <mln/fun/chess.hh>
+#include <mln/fun/p2b/chess.hh>
#include <mln/debug/println.hh>
@@ -40,5 +40,5 @@
{
using namespace mln;
- debug::println( fun::chess | make::box2d(8, 8) );
+ debug::println( fun::p2b::chess | make::box2d(8, 8) );
}
Index: tests/rectangle2d.cc
--- tests/rectangle2d.cc (revision 1039)
+++ tests/rectangle2d.cc (working copy)
@@ -27,10 +27,10 @@
/*! \file tests/rectangle2d.cc
*
- * \brief Tests on mln::rectangle2d.
+ * \brief Tests on mln::win/rectangle2d.
*/
-#include <mln/core/rectangle2d.hh>
+#include <mln/core/win/rectangle2d.hh>
@@ -39,7 +39,7 @@
using namespace mln;
const unsigned h = 3, w = 5;
- rectangle2d rec(h, w);
+ win::rectangle2d rec(h, w);
mln_assertion(rec.is_centered());
mln_assertion(rec.is_symmetric());
Index: tests/cast_image.cc
--- tests/cast_image.cc (revision 1039)
+++ tests/cast_image.cc (working copy)
@@ -31,7 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
-#include <mln/fun/chess.hh>
+#include <mln/fun/p2b/chess.hh>
#include <mln/level/fill.hh>
#include <mln/debug/println.hh>
#include <mln/value/cast.hh>
@@ -42,7 +42,7 @@
using namespace mln;
image2d_b<bool> ima(8, 8);
- level::fill(ima, fun::chess);
+ level::fill(ima, fun::p2b::chess);
debug::println(ima);
debug::println( value::cast<int>(ima) );
}
Index: tests/subimage.cc
--- tests/subimage.cc (revision 1039)
+++ tests/subimage.cc (working copy)
@@ -32,7 +32,7 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/subimage.hh>
-#include <mln/fun/chess.hh>
+#include <mln/fun/p2b/chess.hh>
#include <mln/debug/println.hh>
@@ -41,7 +41,7 @@
using namespace mln;
image2d_b<int> ima(8, 8);
- debug::println(ima | fun::chess);
+ debug::println(ima | fun::p2b::chess);
- // mln_assertion((box_8x8 | fun::chess).npoints() = 32);
+ // mln_assertion((box_8x8 | fun::p2b::chess).npoints() = 32);
}
Index: tests/hmedian.cc
--- tests/hmedian.cc (revision 1039)
+++ tests/hmedian.cc (working copy)
@@ -31,7 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
-#include <mln/core/rectangle2d.hh>
+#include <mln/core/win/rectangle2d.hh>
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
@@ -55,9 +55,9 @@
out(lena.domain()),
ref(lena.domain());
- level::median(lena, rectangle2d(1, 101), ref);
+ level::median(lena, win::rectangle2d(1, 101), ref);
- level::median(lena, hline2d(101), out);
+ level::median(lena, win::hline2d(101), out);
io::save_pgm(out, "out.pgm");
// FIXME: mln_assertion(out = ref);
Index: tests/erosion.cc
--- tests/erosion.cc (revision 1039)
+++ tests/erosion.cc (working copy)
@@ -31,7 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
-#include <mln/core/rectangle2d.hh>
+#include <mln/core/win/rectangle2d.hh>
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
@@ -51,7 +51,7 @@
using namespace mln;
using value::int_u8;
- rectangle2d rec(21, 21);
+ win::rectangle2d rec(21, 21);
border::thickness = 66;
image2d_b<int_u8>
Index: tests/naive_median.cc
--- tests/naive_median.cc (revision 1039)
+++ tests/naive_median.cc (working copy)
@@ -31,7 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
-#include <mln/core/rectangle2d.hh>
+#include <mln/core/win/rectangle2d.hh>
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
@@ -46,7 +46,7 @@
int main()
{
- rectangle2d rec(51, 51);
+ win::rectangle2d rec(51, 51);
border::thickness = 52;
image2d_b<int_u8>
Index: TODO
--- TODO (revision 1039)
+++ TODO (working copy)
@@ -30,18 +30,19 @@
mlc into metal
+ look for "same_grid" etc.
+rectangle2d, hlin2d, etc -> core/win/
* clean-up
select_function in fun::internal::selector_p2? etc.
+value::cast(something) -> mln::cast_image or mln::fun::casted<F> etc.
* processing routines
reconstructions + their canvases
fast versions of level::fill and level::paste
-histogram class
sorting points w.r.t. their value (array of offsets, psites, points)
arith::inplace_plus et al.
linear:: for convolutions
Index: mln/pw/all.hh
--- mln/pw/all.hh (revision 0)
+++ mln/pw/all.hh (revision 0)
@@ -0,0 +1,54 @@
+// 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.
+
+#ifndef MLN_PW_ALL_HH
+# define MLN_PW_ALL_HH
+
+/*! \file mln/fun/pw/all.hh
+ *
+ * \brief File that includes all "point-wise" expression tools.
+ */
+
+
+namespace mln
+{
+
+ /*! Namespace of "point-wise" expression tools.
+ */
+ namespace pw {}
+
+} // end of namespace mln
+
+
+# include <mln/pw/value.hh>
+# include <mln/pw/cst.hh>
+# include <mln/pw/var.hh>
+
+# include <mln/fun/ops.hh>
+
+
+#endif // ! MLN_PW_ALL_HH
Index: mln/fun/i2v/all.hh
--- mln/fun/i2v/all.hh (revision 0)
+++ mln/fun/i2v/all.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_FUN_ALL_HH
# define MLN_FUN_ALL_HH
-/*! \file mln/fun/all.hh
+/*! \file mln/fun/i2v/all.hh
*
* \brief FIXME.
*/
@@ -44,6 +44,9 @@
namespace fun
{
+ namespace i2v
+ {
+
template <typename T>
struct all : public Function_i2v< all<T> >
{
@@ -55,10 +58,12 @@
T t_;
};
+ } // end of namespace mln::fun::i2v
+
} // end of namespace mln::fun
template <typename T>
- fun::all<T> all(T t);
+ fun::i2v::all<T> all(T t);
# ifndef MLN_INCLUDE_ONLY
@@ -66,6 +71,9 @@
namespace fun
{
+ namespace i2v
+ {
+
template <typename T>
all<T>::all(T t)
: t_(t)
@@ -80,12 +88,14 @@
return t_;
}
+ } // end of namespace mln::fun::i2v
+
} // end of namespace mln::fun
template <typename T>
- fun::all<T> all(T t)
+ fun::i2v::all<T> all(T t)
{
- fun::all<T> tmp(t);
+ fun::i2v::all<T> tmp(t);
return tmp;
}
Index: mln/fun/p2b/chess.hh
--- mln/fun/p2b/chess.hh (revision 0)
+++ mln/fun/p2b/chess.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_CHESS_HH
-# define MLN_FUN_CHESS_HH
+#ifndef MLN_FUN_P2B_CHESS_HH
+# define MLN_FUN_P2B_CHESS_HH
-/*! \file mln/fun/chess.hh
+/*! \file mln/fun/p2b/chess.hh
*
* \brief FIXME.
*/
@@ -43,6 +43,9 @@
namespace fun
{
+ namespace p2b
+ {
+
// FIXME: Doc!
struct chess_t : public Function_p2b< chess_t >
@@ -64,9 +67,11 @@
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::fun::p2b
+
} // end of namespace mln::fun
} // end of namespace mln
-#endif // ! MLN_FUN_CHESS_HH
+#endif // ! MLN_FUN_P2B_CHESS_HH
Index: mln/fun/v2v/enc.hh
--- mln/fun/v2v/enc.hh (revision 0)
+++ mln/fun/v2v/enc.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_TO_ENC_HH
-# define MLN_FUN_TO_ENC_HH
+#ifndef MLN_FUN_V2V_ENC_HH
+# define MLN_FUN_V2V_ENC_HH
-/*! \file mln/fun/to_enc.hh
+/*! \file mln/fun/v2v/enc.hh
*
* \brief FIXME.
*/
@@ -42,10 +42,13 @@
namespace fun
{
+ namespace v2v
+ {
+
// FIXME: Doc!
template <typename V>
- struct to_enc : public Function_v2v< to_enc<V> >
+ struct enc : public Function_v2v< enc<V> >
{
typedef typename V::enc result;
result operator()(const V& v) const;
@@ -56,16 +59,18 @@
template <typename V>
typename V::enc
- to_enc<V>::operator()(const V& v) const
+ enc<V>::operator()(const V& v) const
{
return v.to_enc();
}
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::fun::v2v
+
} // end of namespace mln::fun
} // end of namespace mln
-#endif // ! MLN_FUN_TO_ENC_HH
+#endif // ! MLN_FUN_V2V_ENC_HH
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1039)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -112,6 +112,12 @@
};
+ // FIXME:
+ template <typename D>
+ class dpoints_bkd_piter : public internal::fixme
+ {};
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename D>
Index: mln/core/fimage.hh
--- mln/core/fimage.hh (revision 1039)
+++ mln/core/fimage.hh (working copy)
@@ -102,6 +102,9 @@
+ /*! \brief FIXME
+ *
+ */
template <typename F, typename S>
fimage<F,S>
operator | (const Function_p2v<F>& f, const Point_Set<S>& ps)
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1039)
+++ mln/core/point.hh (working copy)
@@ -35,7 +35,7 @@
# include <mln/core/concept/point.hh>
# include <mln/core/internal/coord_impl.hh>
-# include <mln/fun/all.hh>
+# include <mln/fun/i2v/all.hh>
namespace mln
Index: mln/core/pvec.hh
--- mln/core/pvec.hh (revision 1039)
+++ mln/core/pvec.hh (working copy)
@@ -36,7 +36,6 @@
# include <vector>
# include <mln/core/concept/point_set.hh>
-# include <mln/core/internal/fixme.hh>
# include <mln/accu/bbox.hh>
@@ -54,6 +53,8 @@
*
* \warning We have some troubles with point set comparison based on
* a call to npoints(). FIXME: Explain!
+ *
+ * \todo Make it work with P being a Point_Site.
*/
template <typename P>
class pvec : public Point_Set< pvec<P> >
@@ -61,7 +62,7 @@
public:
/// Point associated type.
- typedef mln_point(P) point;
+ typedef P point;
/// Point_Site associated type.
typedef P psite;
@@ -70,7 +71,7 @@
typedef pvec_fwd_piter_<P> fwd_piter;
/// Backward Point_Iterator associated type.
- typedef internal::fixme bkd_piter;
+ typedef pvec_bkd_piter_<P> bkd_piter;
/// Constructor.
pvec();
@@ -85,7 +86,7 @@
std::size_t npoints() const;
/// Give the exact bounding box.
- const box_<point>& bbox() const;
+ const box_<P>& bbox() const;
/// Append a point \p p.
pvec<P>& append(const P& p);
@@ -111,65 +112,8 @@
- /*! \brief Forward iterator on points of a pvec<P>.
- *
- */
- template <typename P>
- struct pvec_fwd_piter_
- {
- enum { dim = P::dim };
-
- /// Point_Site associated type.
- typedef P psite;
-
- /// Point associated type.
- typedef mln_point(P) point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
- /// Coordinate associated type.
- typedef mln_coord(P) coord;
-
- /// Coordinate associated type.
- template <typename S>
- pvec_fwd_piter_(const Point_Set<S>& s);
-
- /// Give a hook to the point address.
- const point* pointer_() const;
-
- /// Read-only access to the \p i-th coordinate.
- coord operator[](unsigned i) const;
-
- /// Test if the iterator is valid.
- bool is_valid() const;
-
- /// Invalidate the iterator.
- void invalidate();
-
- /// Start an iteration.
- void start();
-
- /// Go to the next point.
- void next_();
-
- /// Convert the iterator into a point.
- operator P() const;
-
- protected:
- const std::vector<P>& vect_;
- point p_;
- };
-
-
-
-
# ifndef MLN_INCLUDE_ONLY
-
- // pvec<P>
-
-
template <typename P>
pvec<P>::pvec()
{
@@ -211,7 +155,7 @@
}
template <typename P>
- const box_<mln_point(P)>&
+ const box_<P>&
pvec<P>::bbox() const
{
mln_precondition(npoints() != 0);
@@ -251,73 +195,12 @@
return vect_[i];
}
-
-
- // pvec_fwd_piter_<P>
-
-
- template <typename P>
- template <typename S>
- pvec_fwd_piter_<P>::pvec_fwd_piter_(const Point_Set<S>& s)
- : vect_(exact(s).vect())
- {
- invalidate();
- }
-
- template <typename P>
- const mln_point(P)*
- pvec_fwd_piter_<P>::pointer_() const
- {
- return & p_;
- }
-
- template <typename P>
- mln_coord(P)
- pvec_fwd_piter_<P>::operator[](unsigned i) const
- {
- mln_precondition(i < dim);
- mln_precondition(is_valid());
- return p_[i];
- }
-
- template <typename P>
- bool
- pvec_fwd_piter_<P>::is_valid() const
- {
- return i < vect_.size();
- }
-
- template <typename P>
- void
- pvec_fwd_piter_<P>::invalidate()
- {
- i = vect_.size();
- }
-
- template <typename P>
- void
- pvec_fwd_piter_<P>::start()
- {
- i = 0;
- }
-
- template <typename P>
- void
- pvec_fwd_piter_<P>::next_()
- {
- ++i;
- }
-
- template <typename P>
- pvec_fwd_piter_<P>::operator P() const
- {
- mln_precondition(is_valid());
- return p_;
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
+# include <mln/core/pvec_piter.hh>
+
+
#endif // ! MLN_CORE_PVEC_HH
Index: mln/core/pvec_piter.hh
--- mln/core/pvec_piter.hh (revision 1039)
+++ mln/core/pvec_piter.hh (working copy)
@@ -25,97 +25,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_PVEC_HH
-# define MLN_CORE_PVEC_HH
+#ifndef MLN_CORE_PVEC_PITER_HH
+# define MLN_CORE_PVEC_PITER_HH
-/*! \file mln/core/pvec.hh
+/*! \file mln/core/pvec_piter.hh
*
- * \brief Definition of a point set class based on std::vector.
+ * \brief Definition of point iterators on mln::pvec.
*/
-# include <vector>
-
-# include <mln/core/concept/point_set.hh>
+# include <mln/core/pvec.hh>
# include <mln/core/internal/fixme.hh>
-# include <mln/accu/bbox.hh>
namespace mln
{
- // Fwd decls.
- template <typename P> struct pvec_fwd_piter_;
- template <typename P> struct pvec_bkd_piter_;
-
-
- /*! \brief Point set class based on std::vector.
- *
- * This is a multi-set of points.
- *
- * \warning We have some troubles with point set comparison based on
- * a call to npoints(). FIXME: Explain!
- */
- template <typename P>
- class pvec : public Point_Set< pvec<P> >
- {
- public:
-
- /// Point associated type.
- typedef mln_point(P) point;
-
- /// Point_Site associated type.
- typedef P psite;
-
- /// Forward Point_Iterator associated type.
- typedef pvec_fwd_piter_<P> fwd_piter;
-
- /// Backward Point_Iterator associated type.
- typedef internal::fixme bkd_piter;
-
- /// Constructor.
- pvec();
-
- /// Constructor from a vector \p vect.
- pvec(const std::vector<P>& vect);
-
- /// Test is \p p belongs to this point set.
- bool has(const P& p) const;
-
- /// Give the number of points.
- std::size_t npoints() const;
-
- /// Give the exact bounding box.
- const box_<point>& bbox() const;
-
- /// Append a point \p p.
- pvec<P>& append(const P& p);
-
- /// Clear this set.
- void clear();
-
- /// Return the corresponding std::vector of points.
- const std::vector<P>& vect() const;
-
- /// Return the \p i-th point.
- const P& operator[](unsigned i) const;
-
- protected:
-
- std::vector<P> vect_;
- mutable accu::bbox<P> bb_;
- mutable bool bb_needs_update_;
-
- void update_bb_();
- // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
- };
-
-
-
/*! \brief Forward iterator on points of a pvec<P>.
*
*/
template <typename P>
- struct pvec_fwd_piter_
+ struct pvec_fwd_piter_ : public Point_Iterator< pvec_fwd_piter_<P> >
{
enum { dim = P::dim };
@@ -123,7 +52,7 @@
typedef P psite;
/// Point associated type.
- typedef mln_point(P) point;
+ typedef P point;
/// Dpoint associated type.
typedef mln_dpoint(P) dpoint;
@@ -136,7 +65,7 @@
pvec_fwd_piter_(const Point_Set<S>& s);
/// Give a hook to the point address.
- const point* pointer_() const;
+ const P* pointer_() const;
/// Read-only access to the \p i-th coordinate.
coord operator[](unsigned i) const;
@@ -158,103 +87,20 @@
protected:
const std::vector<P>& vect_;
- point p_;
+ unsigned i_;
+ P p_;
};
-
-# ifndef MLN_INCLUDE_ONLY
-
-
- // pvec<P>
-
-
+ // FIXME:
template <typename P>
- pvec<P>::pvec()
- {
- bb_needs_update_ = false;
- }
-
- template <typename P>
- pvec<P>::pvec(const std::vector<P>& vect)
- : vect_(vect)
- {
- bb_needs_update_ = true;
- }
-
- template <typename P>
- void
- pvec<P>::update_bb_()
- {
- bb_.clear();
- for (unsigned i = 0; i < vect_.size(); ++i)
- bb_.take(vect_[i]);
- bb_needs_update_ = false;
- }
-
- template <typename P>
- bool
- pvec<P>::has(const P& p) const
- {
- for (unsigned i = 0; i < vect_.size(); ++i)
- if (vect_[i] = p)
- return true;
- return false;
- }
-
- template <typename P>
- std::size_t
- pvec<P>::npoints() const
- {
- return vect_.size();
- }
-
- template <typename P>
- const box_<mln_point(P)>&
- pvec<P>::bbox() const
- {
- mln_precondition(npoints() != 0);
- if (bb_needs_update_)
- update_bb_();
- return bb_.to_value();
- }
-
- template <typename P>
- pvec<P>&
- pvec<P>::append(const P& p)
- {
- vect_.push_back(p);
- return *this;
- }
-
- template <typename P>
- void
- pvec<P>::clear()
- {
- vect_.clear();
- bb_needs_update_ = false;
- }
-
- template <typename P>
- const std::vector<P>&
- pvec<P>::vect() const
- {
- return vect_;
- }
-
- template <typename P>
- const P&
- pvec<P>::operator[](unsigned i) const
- {
- mln_precondition(i < npoints());
- return vect_[i];
- }
+ struct pvec_bkd_piter_ : internal::fixme
+ {};
- // pvec_fwd_piter_<P>
-
+# ifndef MLN_INCLUDE_ONLY
template <typename P>
template <typename S>
@@ -265,7 +111,7 @@
}
template <typename P>
- const mln_point(P)*
+ const P*
pvec_fwd_piter_<P>::pointer_() const
{
return & p_;
@@ -284,28 +130,31 @@
bool
pvec_fwd_piter_<P>::is_valid() const
{
- return i < vect_.size();
+ return i_ < vect_.size();
}
template <typename P>
void
pvec_fwd_piter_<P>::invalidate()
{
- i = vect_.size();
+ i_ = vect_.size();
}
template <typename P>
void
pvec_fwd_piter_<P>::start()
{
- i = 0;
+ i_ = 0;
+ if (is_valid())
+ p_ = vect_[i_];
}
template <typename P>
void
pvec_fwd_piter_<P>::next_()
{
- ++i;
+ ++i_;
+ p_ = vect_[i_];
}
template <typename P>
@@ -320,4 +169,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_PVEC_HH
+#endif // ! MLN_CORE_PVEC_PITER_HH
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1039)
+++ mln/core/window.hh (working copy)
@@ -40,7 +40,7 @@
# include <mln/core/box.hh>
# include <mln/convert/to_dpoint.hh>
-# include <mln/fun/all.hh>
+# include <mln/fun/i2v/all.hh>
# include <mln/norm/infty.hh>
Index: mln/core/internal/fixme.hh
--- mln/core/internal/fixme.hh (revision 1039)
+++ mln/core/internal/fixme.hh (working copy)
@@ -45,7 +45,8 @@
*
* \internal
*/
- struct fixme;
+ struct fixme
+ {};
} // end of namespace mln::internal
Index: mln/core/box2d.hh
--- mln/core/box2d.hh (revision 1039)
+++ mln/core/box2d.hh (working copy)
@@ -44,7 +44,7 @@
/*! \brief Type alias for a box defined on the 2D square grid with
* integer coordinates.
*
- * \see mln::rectangle2d.
+ * \see mln::win::rectangle2d.
*/
typedef box_<point2d> box2d;
Index: mln/core/concept/generalized_point.hh
--- mln/core/concept/generalized_point.hh (revision 1039)
+++ mln/core/concept/generalized_point.hh (working copy)
@@ -31,9 +31,9 @@
/*! \file mln/core/concept/generalized_point.hh
* \brief Definition of the concept of mln::Generalized_Point.
*/
-# include <mlc/equal.hh>
-# include <mlc/same_point.hh>
-# include <mlc/same_coord.hh>
+# include <mln/metal/equal.hh>
+# include <mln/metal/same_point.hh>
+# include <mln/metal/same_coord.hh>
# include <mln/core/concept/object.hh>
# include <mln/core/internal/force_exact.hh>
@@ -225,10 +225,10 @@
template <typename Pl, typename Pr>
bool operator=(const Generalized_Point<Pl>& lhs, const Generalized_Point<Pr>& rhs)
{
- // FIXME: mlc::same_grid<Pl, Pr>::check();
+ // FIXME: metal::same_grid<Pl, Pr>::check();
const Pl& lhs_ = internal::force_exact<Pl>(lhs);
const Pr& rhs_ = internal::force_exact<Pr>(rhs);
- mlc::same_point<Pl, Pr>::check();
+ metal::same_point<Pl, Pr>::check();
for (unsigned i = 0; i < Pl::dim; ++i)
if (lhs_[i] != rhs_[i])
return false;
@@ -238,7 +238,7 @@
template <typename Pl, typename Pr>
bool operator<(const Generalized_Point<Pl>& lhs, const Generalized_Point<Pr>& rhs)
{
- // FIXME: mlc::same_grid<Pl, Pr>::check();
+ // FIXME: metal::same_grid<Pl, Pr>::check();
const Pl& lhs_ = internal::force_exact<Pl>(lhs);
const Pr& rhs_ = internal::force_exact<Pr>(rhs);
for (unsigned i = 0; i < Pl::dim; ++i)
@@ -254,9 +254,9 @@
mln_dpoint(Pl)
operator-(const Generalized_Point<Pl>& lhs, const Generalized_Point<Pr>& rhs)
{
- mlc::equal<mln_dpoint(Pl), mln_dpoint(Pr)>::check();
- // FIXME: mlc::same_grid<Pl, Pr>::check();
- mlc::same_coord<Pl, Pr>::check();
+ metal::equal<mln_dpoint(Pl), mln_dpoint(Pr)>::check();
+ // FIXME: metal::same_grid<Pl, Pr>::check();
+ metal::same_coord<Pl, Pr>::check();
const Pl& lhs_ = internal::force_exact<Pl>(lhs);
const Pr& rhs_ = internal::force_exact<Pr>(rhs);
mln_dpoint(Pl) tmp;
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1039)
+++ mln/core/dpoint.hh (working copy)
@@ -35,7 +35,7 @@
# include <mln/core/concept/dpoint.hh>
# include <mln/core/internal/coord_impl.hh>
-# include <mln/fun/all.hh>
+# include <mln/fun/i2v/all.hh>
namespace mln
Index: mln/core/win/vline2d.hh
--- mln/core/win/vline2d.hh (revision 0)
+++ mln/core/win/vline2d.hh (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_VLINE2D_HH
-# define MLN_CORE_VLINE2D_HH
+#ifndef MLN_CORE_WIN_VLINE2D_HH
+# define MLN_CORE_WIN_VLINE2D_HH
-/*! \file mln/core/vline2d.hh
+/*! \file mln/core/win/vline2d.hh
*
- * \brief Definition of the mln::vline2d window.
+ * \brief Definition of the mln::win::vline2d window.
*/
# include <mln/core/concept/window.hh>
@@ -42,6 +42,9 @@
namespace mln
{
+ namespace win
+ {
+
/*! \brief Vertical line window defined on the 2D square grid.
*
* An vline2d is centered and symmetrical; so its width is 1 and
@@ -54,7 +57,7 @@
* is defined with length = 5.
*/
struct vline2d : public Window< vline2d >,
- public internal::set_of_<dpoint2d>
+ public mln::internal::set_of_<dpoint2d>
{
/// Point associated type.
typedef point2d point;
@@ -70,7 +73,7 @@
/*! \brief Point_Iterator type to browse a vline such as: "for each row
* (decreasing), for each column (decreasing)."
*/
- typedef internal::fixme bkd_qiter;
+ typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
/*! \brief Same as fwd_qiter.
*/
@@ -171,8 +174,10 @@
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::win
+
} // end of namespace mln
-#endif // ! MLN_CORE_VLINE2D_HH
+#endif // ! MLN_CORE_WIN_VLINE2D_HH
Index: mln/core/win/hline2d.hh
--- mln/core/win/hline2d.hh (revision 0)
+++ mln/core/win/hline2d.hh (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_HLINE2D_HH
-# define MLN_CORE_HLINE2D_HH
+#ifndef MLN_CORE_WIN_HLINE2D_HH
+# define MLN_CORE_WIN_HLINE2D_HH
-/*! \file mln/core/hline2d.hh
+/*! \file mln/core/win/hline2d.hh
*
- * \brief Definition of the mln::hline2d window.
+ * \brief Definition of the mln::win::hline2d window.
*/
# include <mln/core/concept/window.hh>
@@ -42,6 +42,9 @@
namespace mln
{
+ namespace win
+ {
+
/*! \brief Horizontal line window defined on the 2D square grid.
*
* An hline2d is centered and symmetrical; so its height is 1 and
@@ -52,7 +55,7 @@
* is defined with length = 5.
*/
struct hline2d : public Window< hline2d >,
- public internal::set_of_<dpoint2d>
+ public mln::internal::set_of_<dpoint2d>
{
/// Point associated type.
typedef point2d point;
@@ -68,7 +71,7 @@
/*! \brief Point_Iterator type to browse a hline such as: "for each row
* (decreasing), for each column (decreasing)."
*/
- typedef internal::fixme bkd_qiter;
+ typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
/*! \brief Same as fwd_qiter.
*/
@@ -169,8 +172,10 @@
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::win
+
} // end of namespace mln
-#endif // ! MLN_CORE_HLINE2D_HH
+#endif // ! MLN_CORE_WIN_HLINE2D_HH
Index: mln/core/win/rectangle2d.hh
--- mln/core/win/rectangle2d.hh (revision 0)
+++ mln/core/win/rectangle2d.hh (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_RECTANGLE2D_HH
-# define MLN_CORE_RECTANGLE2D_HH
+#ifndef MLN_CORE_WIN_RECTANGLE2D_HH
+# define MLN_CORE_WIN_RECTANGLE2D_HH
-/*! \file mln/core/rectangle2d.hh
+/*! \file mln/core/win/rectangle2d.hh
*
- * \brief Definition of the mln::rectangle2d window.
+ * \brief Definition of the mln::win::rectangle2d window.
*/
# include <mln/core/concept/window.hh>
@@ -42,6 +42,9 @@
namespace mln
{
+ namespace win
+ {
+
/*! \brief Rectangular window defined on the 2D square grid.
*
* A rectangle2d is a 2D window with rectangular shape. It is
@@ -54,7 +57,7 @@
* is defined with height = 3 and width = 5.
*/
struct rectangle2d : public Window< rectangle2d >,
- public internal::set_of_<dpoint2d>
+ public mln::internal::set_of_<dpoint2d>
{
/// Point associated type.
typedef point2d point;
@@ -70,7 +73,7 @@
/*! \brief Point_Iterator type to browse a rectangle such as: "for each row
* (decreasing), for each column (decreasing)."
*/
- typedef internal::fixme bkd_qiter;
+ typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
/*! \brief Same as fwd_qiter.
*/
@@ -183,13 +186,15 @@
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::win
+
} // end of namespace mln
// when rectangle2d is involved, one surely also wants:
-# include <mln/core/hline2d.hh>
-# include <mln/core/vline2d.hh>
+# include <mln/core/win/hline2d.hh>
+# include <mln/core/win/vline2d.hh>
-#endif // ! MLN_CORE_RECTANGLE2D_HH
+#endif // ! MLN_CORE_WIN_RECTANGLE2D_HH
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1039)
+++ mln/core/image2d_b.hh (working copy)
@@ -39,7 +39,7 @@
# include <mln/border/thickness.hh>
# include <mln/value/set.hh>
-# include <mln/fun/all.hh>
+# include <mln/fun/i2v/all.hh>
// FIXME:
Index: mln/core/line2d.hh
--- mln/core/line2d.hh (revision 0)
+++ mln/core/line2d.hh (revision 0)
@@ -0,0 +1,199 @@
+// 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.
+
+#ifndef MLN_CORE_LINE2D_HH
+# define MLN_CORE_LINE2D_HH
+
+/*! \file mln/core/line2d.hh
+ *
+ * \brief Definition of a point set class based on std::vector.
+ */
+
+# include <vector>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/pvec_piter.hh>
+# include <mln/core/box2d.hh>
+# include <mln/math/all.hh>
+
+
+namespace mln
+{
+
+
+ /*! \brief 2D line point set class.
+ */
+ class line2d : public Point_Set< line2d >
+ {
+ public:
+
+ /// Point associated type.
+ typedef point2d point;
+
+ /// Point_Site associated type.
+ typedef point2d psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef pvec_fwd_piter_<point2d> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef pvec_bkd_piter_<point2d> bkd_piter;
+
+
+ /// Constructor from point \p beg to point \p end.
+ line2d(const point2d& beg, const point2d& end);
+
+
+ /// Test is \p p belongs to this point set.
+ bool has(const point2d& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<point2d>& bbox() const;
+
+ /// Append a point \p p.
+ line2d& append(const point2d& p);
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<point2d>& vect() const;
+
+ /// Return the \p i-th point.
+ const point2d& operator[](unsigned i) const;
+
+ protected:
+
+ point2d beg_, end_;
+ std::vector<point2d> vect_;
+ box2d bb_;
+
+ void compute_();
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ line2d::line2d(const point2d& beg, const point2d& end)
+ : beg_(beg),
+ end_(end)
+ {
+ compute_();
+ }
+
+ void
+ line2d::compute_()
+ {
+ // vect_
+ dpoint2d dp = end_ - beg_;
+ int
+ srow = math::sign(dp.row()), drow = math::abs(dp.row()), ddrow = 2 * drow,
+ scol = math::sign(dp.col()), dcol = math::abs(dp.col()), ddcol = 2 * dcol,
+ row = beg_.row(),
+ col = beg_.row();
+ if ( dcol > drow )
+ {
+ int e = ddrow - dcol;
+ for (int i = 0; i < dcol; ++i)
+ {
+ vect_.push_back(make::point2d(row, col));
+ while (e >= 0)
+ {
+ row += srow;
+ e -= ddcol;
+ }
+ col += scol;
+ e += ddrow;
+ }
+ }
+ else
+ {
+ int e = ddcol - drow;
+ for (int i = 0; i < drow; ++i)
+ {
+ vect_.push_back(make::point2d(row, col));
+ while (e >= 0)
+ {
+ col += scol;
+ e -= ddrow;
+ }
+ row += srow;
+ e += ddcol;
+ }
+ }
+ vect_.push_back(make::point2d(row, col));
+ // bb_
+ bb_.pmin() = make::point2d(math::min(beg_.row(), end_.row()),
+ math::min(beg_.col(), end_.col()));
+ bb_.pmax() = make::point2d(math::max(beg_.row(), end_.row()),
+ math::max(beg_.col(), end_.col()));
+ }
+
+ bool
+ line2d::has(const point2d& p) const
+ {
+ if (! bb_.has(p))
+ return false;
+ // FIXME: Optimize!
+ for (unsigned i = 0; i < vect_.size(); ++i)
+ if (vect_[i] = p)
+ return true;
+ return false;
+ }
+
+ std::size_t
+ line2d::npoints() const
+ {
+ return vect_.size();
+ }
+
+ const box2d&
+ line2d::bbox() const
+ {
+ return bb_;
+ }
+
+ const std::vector<point2d>&
+ line2d::vect() const
+ {
+ return vect_;
+ }
+
+ const point2d&
+ line2d::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return vect_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_LINE2D_HH
Index: mln/math/min.hh
--- mln/math/min.hh (revision 0)
+++ mln/math/min.hh (revision 0)
@@ -0,0 +1,62 @@
+// 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.
+
+#ifndef MLN_MATH_MIN_HH
+# define MLN_MATH_MIN_HH
+
+/*! \file mln/math/min.hh
+ *
+ * \brief Define min routine.
+ */
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ template <typename T>
+ T min(const T& v1, const T& v2);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ T min(const T& v1, const T& v2)
+ {
+ return v1 < v2 ? v1 : v2;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::math
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_MIN_HH
Index: mln/math/abs.hh
--- mln/math/abs.hh (revision 0)
+++ mln/math/abs.hh (revision 0)
@@ -0,0 +1,65 @@
+// 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.
+
+#ifndef MLN_MATH_ABS_HH
+# define MLN_MATH_ABS_HH
+
+/*! \file mln/math/abs.hh
+ *
+ * \brief Define abs routine.
+ */
+
+# include <cmath>
+
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ template <typename T>
+ T abs(const T& v);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ T abs(const T& v)
+ {
+ return std::abs(v);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::math
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_ABS_HH
Index: mln/math/max.hh
--- mln/math/max.hh (revision 0)
+++ mln/math/max.hh (revision 0)
@@ -0,0 +1,62 @@
+// 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.
+
+#ifndef MLN_MATH_MAX_HH
+# define MLN_MATH_MAX_HH
+
+/*! \file mln/math/max.hh
+ *
+ * \brief Define max routine.
+ */
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ template <typename T>
+ T max(const T& v1, const T& v2);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ T max(const T& v1, const T& v2)
+ {
+ return v1 > v2 ? v1 : v2;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::math
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_MAX_HH
Index: mln/math/all.hh
--- mln/math/all.hh (revision 0)
+++ mln/math/all.hh (revision 0)
@@ -0,0 +1,54 @@
+// 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.
+
+#ifndef MLN_MATH_ALL_HH
+# define MLN_MATH_ALL_HH
+
+/*! \file mln/math/all.hh
+ *
+ * \brief File that includes all mathematical routines.
+ */
+
+
+namespace mln
+{
+
+ /*! Namespace of mathematical routines.
+ */
+ namespace math {}
+
+}
+
+
+# include <mln/math/sign.hh>
+# include <mln/math/abs.hh>
+# include <mln/math/min.hh>
+# include <mln/math/max.hh>
+
+
+
+#endif // ! MLN_MATH_ALL_HH
Index: mln/math/sign.hh
--- mln/math/sign.hh (revision 0)
+++ mln/math/sign.hh (revision 0)
@@ -0,0 +1,70 @@
+// 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.
+
+#ifndef MLN_MATH_SIGN_HH
+# define MLN_MATH_SIGN_HH
+
+/*! \file mln/math/sign.hh
+ *
+ * \brief Define sign routine.
+ */
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ enum sign_t
+ {
+ negative = -1,
+ null = 0,
+ positive = +1
+ };
+
+
+ template <typename T>
+ sign_t sign(const T& v);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ sign_t sign(const T& v)
+ {
+ return v > 0 ? positive : (v < 0 ? negative : null);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::math
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_SIGN_HH
Index: mln/draw/line.hh
--- mln/draw/line.hh (revision 0)
+++ mln/draw/line.hh (revision 0)
@@ -0,0 +1,93 @@
+// 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.
+
+#ifndef MLN_DRAW_LINE_HH
+# define MLN_DRAW_LINE_HH
+
+/*! \file mln/draw/line.hh
+ *
+ * \brief Draw a line in an image.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/line2d.hh>
+
+
+namespace mln
+{
+
+ namespace draw
+ {
+
+ /// Draw a line at level \p v in image \p ima between the points \p beg and \p end.
+ template <typename I>
+ void line(Image<I>& ima,
+ const mln_point(I)& beg, const mln_point(I)& end,
+ const mln_value(I)& v);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ void line(I& ima,
+ const point2d& beg, const point2d& end,
+ const mln_value(I)& v)
+ {
+ line2d l(beg, end);
+ mln_piter(line2d) p(l);
+ for_all(p)
+ ima(p) = v;
+ }
+
+ // FIXME: Overload.
+
+ } // end of namespace mln::draw::impl
+
+
+ // Facade.
+
+ template <typename I>
+ void line(Image<I>& ima,
+ const mln_point(I)& beg, const mln_point(I)& end,
+ const mln_value(I)& v)
+ {
+ mln_precondition(exact(ima).has_data());
+ mln_precondition(exact(ima).has(beg) && exact(ima).has(end));
+ impl::line(exact(ima), beg, end, v);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::draw
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DRAW_LINE_HH
Index: mln/metal/equal.hh
--- mln/metal/equal.hh (revision 1039)
+++ mln/metal/equal.hh (working copy)
@@ -25,14 +25,14 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLC_EQUAL_HH
-# define MLC_EQUAL_HH
+#ifndef MLN_METAL_EQUAL_HH
+# define MLN_METAL_EQUAL_HH
namespace mln
{
- namespace mlc
+ namespace metal
{
template <typename T1, typename T2>
@@ -47,9 +47,9 @@
};
- } // end of namespace mln::mlc
+ } // end of namespace mln::metal
} // end of namespace mln
-#endif // ! MLC_EQUAL_HH
+#endif // ! MLN_METAL_EQUAL_HH
Index: mln/metal/same_coord.hh
--- mln/metal/same_coord.hh (revision 1039)
+++ mln/metal/same_coord.hh (working copy)
@@ -25,27 +25,27 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLC_SAME_COORD_HH
-# define MLC_SAME_COORD_HH
+#ifndef MLN_METAL_SAME_COORD_HH
+# define MLN_METAL_SAME_COORD_HH
-# include <mlc/equal.hh>
+# include <mln/metal/equal.hh>
# include <mln/core/macros.hh>
namespace mln
{
- namespace mlc
+ namespace metal
{
template <typename T1, typename T2>
- struct same_coord : mlc::equal<mln_coord(T1), mln_coord(T2)>
+ struct same_coord : metal::equal<mln_coord(T1), mln_coord(T2)>
{
};
- } // end of namespace mln::mlc
+ } // end of namespace mln::metal
} // end of namespace mln
-#endif // ! MLC_SAME_COORD_HH
+#endif // ! MLN_METAL_SAME_COORD_HH
Index: mln/metal/same_point.hh
--- mln/metal/same_point.hh (revision 1039)
+++ mln/metal/same_point.hh (working copy)
@@ -25,27 +25,27 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLC_SAME_POINT_HH
-# define MLC_SAME_POINT_HH
+#ifndef MLN_METAL_SAME_POINT_HH
+# define MLN_METAL_SAME_POINT_HH
-# include <mlc/equal.hh>
+# include <mln/metal/equal.hh>
# include <mln/core/macros.hh>
namespace mln
{
- namespace mlc
+ namespace metal
{
template <typename T1, typename T2>
- struct same_point : mlc::equal<mln_point(T1), mln_point(T2)>
+ struct same_point : metal::equal<mln_point(T1), mln_point(T2)>
{
};
- } // end of namespace mln::mlc
+ } // end of namespace mln::metal
} // end of namespace mln
-#endif // ! MLC_SAME_POINT_HH
+#endif // ! MLN_METAL_SAME_POINT_HH
Index: mln/morpho/erosion.hh
--- mln/morpho/erosion.hh (revision 1039)
+++ mln/morpho/erosion.hh (working copy)
@@ -137,17 +137,17 @@
// --> call stage 2: dispatch w.r.t. the value kind
}
-# ifdef MLN_CORE_RECTANGLE2D_HH
+# ifdef MLN_CORE_WIN_RECTANGLE2D_HH
template <typename I, typename O>
- void erosion_wrt_win(const Image<I>& input, const rectangle2d& win, Image<O>& output)
+ void erosion_wrt_win(const Image<I>& input, const win::rectangle2d& win, Image<O>& output)
{
O tmp(exact(output).domain());
- morpho::erosion(input, hline2d(win.width()), tmp);
- morpho::erosion(tmp, vline2d(win.height()), output);
+ morpho::erosion(input, win::hline2d(win.width()), tmp);
+ morpho::erosion(tmp, win::vline2d(win.height()), output);
}
-# endif // MLN_CORE_RECTANGLE2D_HH
+# endif // MLN_CORE_WIN_RECTANGLE2D_HH
// ^
// |
Index: mln/level/was.median.hh
--- mln/level/was.median.hh (revision 1039)
+++ mln/level/was.median.hh (working copy)
@@ -133,7 +133,7 @@
// horizontal median
template <typename I, typename O>
- void hmedian(const I& input, const hline2d& win, O& output)
+ void hmedian(const I& input, const win::hline2d& win, O& output)
{
const int
Index: mln/level/median.hh
--- mln/level/median.hh (revision 1039)
+++ mln/level/median.hh (working copy)
@@ -36,7 +36,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/window2d.hh>
-# include <mln/core/hline2d.hh>
+# include <mln/core/win/hline2d.hh>
# include <mln/accu/median.hh>
# include <mln/canvas/sbrowsing.hh>
@@ -159,7 +159,7 @@
template <typename I, typename O>
- void median(const I& input, const hline2d& win, O& output)
+ void median(const I& input, const win::hline2d& win, O& output)
{
typedef mln_coord(I) coord;
const coord
@@ -212,10 +212,10 @@
// FIXME: Use transpose.
// template <typename I, typename O>
-// void median(const I& input, const vline2d& win, O& output)
+// void median(const I& input, const win::vline2d& win, O& output)
// {
-// median(, hline2d(win.length()), output);
+// median(, win::hline2d(win.length()), output);
// }
Index: mln/level/to_enc.hh
--- mln/level/to_enc.hh (revision 1039)
+++ mln/level/to_enc.hh (working copy)
@@ -35,7 +35,7 @@
*/
# include <mln/level/transform.hh>
-# include <mln/fun/to_enc.hh>
+# include <mln/fun/v2v/enc.hh>
namespace mln
@@ -61,7 +61,7 @@
void to_enc(const Image<I>& input, Image<O>& output)
{
mln_precondition(exact(output).domain() >= exact(input).domain());
- level::transform(input, fun::to_enc< mln_value(I) >(), output);
+ level::transform(input, fun::v2v::enc< mln_value(I) >(), output);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/approx/median.hh
--- mln/level/approx/median.hh (revision 1039)
+++ mln/level/approx/median.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/level/median.hh>
-# include <mln/core/rectangle2d.hh>
+# include <mln/core/win/rectangle2d.hh>
namespace mln
@@ -59,14 +59,14 @@
* \pre \p input and \p output have to be initialized.
*/
template <typename I, typename O>
- void median(const Image<I>& input, const rectangle2d& win,
+ void median(const Image<I>& input, const win::rectangle2d& win,
Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename O>
- void median(const Image<I>& input_, const rectangle2d& win,
+ void median(const Image<I>& input_, const win::rectangle2d& win,
Image<O>& output_)
{
const I& input = exact(input_);
@@ -74,8 +74,8 @@
mln_assertion(output.domain() = input.domain());
O tmp(output.domain());
- level::median(input, hline2d(win.width()), tmp);
- level::median(tmp, vline2d(win.height()), output);
+ level::median(input, win::hline2d(win.width()), tmp);
+ level::median(tmp, win::vline2d(win.height()), output);
}
# endif // ! MLN_INCLUDE_ONLY