Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
July 2007
- 6 participants
- 59 discussions
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
1
0
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.
1
0
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
1
0
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
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix doc.
* tests/int_s8.cc: Rename as...
* tests/int_s.cc: ...this.
* tests/sort_points.cc,
* mln/pw/all.hh,
* mln/pw/value.hh,
* mln/core/win/vline2d.hh,
* mln/core/win/hline2d.hh,
* mln/core/win/rectangle2d.hh: Fix doc.
* doc/Doxyfile.in: Update.
doc/Doxyfile.in | 2 ++
mln/core/win/hline2d.hh | 2 +-
mln/core/win/rectangle2d.hh | 2 +-
mln/core/win/vline2d.hh | 2 +-
mln/pw/all.hh | 2 +-
mln/pw/value.hh | 2 +-
tests/sort_points.cc | 4 ++--
7 files changed, 9 insertions(+), 7 deletions(-)
Index: tests/sort_points.cc
--- tests/sort_points.cc (revision 1040)
+++ tests/sort_points.cc (working copy)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/histo.cc
+/*! \file tests/sort_points.cc
*
- * \brief Tests on mln::accu::histo<S> and mln::histo::data<S>.
+ * \brief Tests on mln::level::sort_points.
*/
#include <iterator>
Index: doc/Doxyfile.in
--- doc/Doxyfile.in (revision 1040)
+++ doc/Doxyfile.in (working copy)
@@ -1054,9 +1054,11 @@
"mln_viter(T)=typename T::viter" \
"mln_fwd_viter(T)=typename T::fwd_viter" \
"mln_bkd_viter(T)=typename T::bkd_viter" \
+ "mln_result(T)=typename T::result" \
"mln_enc(T)=typename T::enc" \
"mln_value(T)=typename T::value" \
"mln_qlf_value(T)=typename T::qlf_value" \
+ "mln_pset(T)=typename T::pset" \
"mln_vset(T)=typename T::vset" \
"mln_rvalue(T)=typename T::rvalue" \
"mln_lvalue(T)=typename T::lvalue" \
Index: mln/pw/all.hh
--- mln/pw/all.hh (revision 1040)
+++ mln/pw/all.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_PW_ALL_HH
# define MLN_PW_ALL_HH
-/*! \file mln/fun/pw/all.hh
+/*! \file mln/pw/all.hh
*
* \brief File that includes all "point-wise" expression tools.
*/
Index: mln/pw/value.hh
--- mln/pw/value.hh (revision 1040)
+++ mln/pw/value.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef MLN_PW_VALUE_HH
# define MLN_PW_VALUE_HH
-/*! \file mln/fun/pw/value.hh
+/*! \file mln/pw/value.hh
*
* \brief FIXME.
*/
Index: mln/core/win/vline2d.hh
--- mln/core/win/vline2d.hh (revision 1040)
+++ mln/core/win/vline2d.hh (working copy)
@@ -124,7 +124,7 @@
*
* \return The modified output stream \p ostr.
*
- * \relates mln::vline2d
+ * \relates mln::win::vline2d
*/
std::ostream& operator<<(std::ostream& ostr, const vline2d& win);
Index: mln/core/win/hline2d.hh
--- mln/core/win/hline2d.hh (revision 1040)
+++ mln/core/win/hline2d.hh (working copy)
@@ -122,7 +122,7 @@
*
* \return The modified output stream \p ostr.
*
- * \relates mln::hline2d
+ * \relates mln::win::hline2d
*/
std::ostream& operator<<(std::ostream& ostr, const hline2d& win);
Index: mln/core/win/rectangle2d.hh
--- mln/core/win/rectangle2d.hh (revision 1040)
+++ mln/core/win/rectangle2d.hh (working copy)
@@ -129,7 +129,7 @@
*
* \return The modified output stream \p ostr.
*
- * \relates mln::rectangle2d
+ * \relates mln::win::rectangle2d
*/
std::ostream& operator<<(std::ostream& ostr, const rectangle2d& win);
1
0
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
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a label type and labeling.
* tests/labeling.cc: New.
* tests/label.cc: New.
* mln/fun/to_enc.hh: New.
* mln/level/to_enc.hh: New.
* mln/level/labeling.hh: New.
* mln/value/label.hh: New.
* img/tiny.pgm: New.
* tests/README: Fix missing CR.
* doc/Doxyfile.in: Update.
* mln/core/trait/is_lowq.hh: Remove.
* mln/core/trait/all.hh: Update.
* mln/core/macros.hh: Update.
* mln/value/set.hh: Update.
* mln/core/concept/value.hh (++, --): New.
* mln/level/fill.hh (memset): Force cast.
* mln/value/lut_vec.hh: Fix warning.
* mln/value/props.hh (card, mln_card): Rename as...
(card_, mln_card_): ...these.
(convert_): New.
* mln/value/int_s.hh (+=, -=): New.
* mln/value/int_u.hh: Likewise.
* mln/value/internal/iterable_set.hh: Use convert_.
* mln/value/internal/encoding.hh: Factor names.
* mln/value/internal/value_like.hh (to_enc): New.
doc/Doxyfile.in | 1
img/tiny.pgm | 4
mln/core/concept/value.hh | 22 +++
mln/core/macros.hh | 2
mln/core/trait/all.hh | 1
mln/fun/to_enc.hh | 71 +++++++++++
mln/level/fill.hh | 2
mln/level/labeling.hh | 175 +++++++++++++++++++++++++++
mln/level/to_enc.hh | 74 +++++++++++
mln/level/transform.hh | 2
mln/value/int_s.hh | 36 ++++-
mln/value/int_u.hh | 35 ++++-
mln/value/internal/encoding.hh | 32 ++---
mln/value/internal/iterable_set.hh | 8 -
mln/value/internal/value_like.hh | 10 +
mln/value/label.hh | 236 +++++++++++++++++++++++++++++++++++++
mln/value/lut_vec.hh | 3
mln/value/props.hh | 49 +++++--
mln/value/set.hh | 23 +--
tests/label.cc | 49 +++++++
tests/labeling.cc | 78 ++++++++++++
21 files changed, 850 insertions(+), 63 deletions(-)
Index: tests/labeling.cc
--- tests/labeling.cc (revision 0)
+++ tests/labeling.cc (revision 0)
@@ -0,0 +1,78 @@
+// 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/labeling.cc
+ *
+ * \brief Tests on mln::level::labeling.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/label.hh>
+
+#include <mln/pw/value.hh>
+#include <mln/pw/cst.hh>
+#include <mln/fun/ops.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/level/fill.hh>
+#include <mln/level/labeling.hh>
+#include <mln/level/to_enc.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::label;
+
+ image2d_b<int_u8> lena = io::load_pgm("../img/lena.pgm");
+
+ image2d_b<bool> bin(lena.domain());
+ level::fill(bin, pw::value(lena) > pw::cst(127));
+
+ {
+ image2d_b<int_u8> lab(lena.domain());
+ level::labeling(bin, c4(), lab);
+ io::save_pgm(lab, "lab.pgm");
+ }
+
+ {
+ image2d_b< label<8> > lab(lena.domain());
+ level::labeling(bin, c4(), lab);
+
+ image2d_b< int_u8 > out(lena.domain());
+ level::to_enc(lab, out);
+ io::save_pgm(out, "out.pgm");
+ }
+
+}
Index: tests/label.cc
--- tests/label.cc (revision 0)
+++ tests/label.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/label.cc
+ *
+ * \brief Tests on mln::value::label.
+ */
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/label.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::label;
+
+ int_u8 i = 51;
+ label<8> l = 50;
+ ++l;
+ mln_assertion(l = l);
+ mln_assertion(i = l.to_enc());
+}
Index: tests/README
Index: doc/Doxyfile.in
--- doc/Doxyfile.in (revision 1038)
+++ doc/Doxyfile.in (working copy)
@@ -1054,6 +1054,7 @@
"mln_viter(T)=typename T::viter" \
"mln_fwd_viter(T)=typename T::fwd_viter" \
"mln_bkd_viter(T)=typename T::bkd_viter" \
+ "mln_enc(T)=typename T::enc" \
"mln_value(T)=typename T::value" \
"mln_qlf_value(T)=typename T::qlf_value" \
"mln_vset(T)=typename T::vset" \
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1038)
+++ mln/core/macros.hh (working copy)
@@ -152,7 +152,7 @@
# define mln_value_kind(I) typename mln::value::props< mln_value(I) >::kind
/// Shortcut to test if the values of an image with type \c I are lowly quantifized.
-# define mln_is_value_lowq(I) typename mln::trait::is_lowq< mln_value(I) >::ret
+# define mln_is_value_lowq(I) mln_is_lowq( mln_value(I) )
/// Shortcut to access the type of value set (vset) associated to T.
# define mln_vset(T) typename T::vset
Index: mln/core/trait/all.hh
--- mln/core/trait/all.hh (revision 1038)
+++ mln/core/trait/all.hh (working copy)
@@ -45,7 +45,6 @@
# include <mln/core/trait/is_fast.hh>
-# include <mln/core/trait/is_lowq.hh>
# include <mln/core/trait/pixter.hh>
Index: mln/core/concept/value.hh
--- mln/core/concept/value.hh (revision 1038)
+++ mln/core/concept/value.hh (working copy)
@@ -51,6 +51,12 @@
typedef equiv; // equivalent type
*/
+ /// Pre-incrementation.
+ E& operator++();
+
+ /// Pre-decrementation.
+ E& operator--();
+
protected:
Value();
};
@@ -65,6 +71,22 @@
typedef mln_equiv(E) equiv;
}
+ template <typename E>
+ E&
+ Value<E>::operator++()
+ {
+ exact(this)->operator+=(E::one);
+ return exact(*this);
+ }
+
+ template <typename E>
+ E&
+ Value<E>::operator--()
+ {
+ exact(this)->operator-=(E::one);
+ return exact(*this);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/fun/to_enc.hh
--- mln/fun/to_enc.hh (revision 0)
+++ mln/fun/to_enc.hh (revision 0)
@@ -0,0 +1,71 @@
+// 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_FUN_TO_ENC_HH
+# define MLN_FUN_TO_ENC_HH
+
+/*! \file mln/fun/to_enc.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ // FIXME: Doc!
+
+ template <typename V>
+ struct to_enc : public Function_v2v< to_enc<V> >
+ {
+ typedef typename V::enc result;
+ result operator()(const V& v) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ typename V::enc
+ to_enc<V>::operator()(const V& v) const
+ {
+ return v.to_enc();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_TO_ENC_HH
Index: mln/level/fill.hh
--- mln/level/fill.hh (revision 1038)
+++ mln/level/fill.hh (working copy)
@@ -146,7 +146,7 @@
if (sizeof(mln_value(I)) = 1)
{
std::memset((void*)(ima.buffer()),
- value,
+ *(const int*)(& value), // violent cast
sizeof(mln_value(I)) * ima.ncells());
}
else
Index: mln/level/to_enc.hh
--- mln/level/to_enc.hh (revision 0)
+++ mln/level/to_enc.hh (revision 0)
@@ -0,0 +1,74 @@
+// 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_TO_ENC_HH
+# define MLN_LEVEL_TO_ENC_HH
+
+/*! \file mln/level/to_enc.hh
+ *
+ * \brief Transform with fun::to_enc the contents of an image into
+ * another one.
+ */
+
+# include <mln/level/transform.hh>
+# include <mln/fun/to_enc.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Set the \p output image with the encoding values of the image \p input pixels.
+ *
+ * \param[in] input The input image.
+ * \param[out] output The result image.
+ *
+ * \pre \p output.domain >= \p input.domain
+ */
+ template <typename I, typename O>
+ void to_enc(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename O>
+ 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);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_TO_ENC_HH
Index: mln/level/transform.hh
--- mln/level/transform.hh (revision 1038)
+++ mln/level/transform.hh (working copy)
@@ -80,6 +80,7 @@
output(p) = f( input(p) );
}
+
template <typename I, typename F, typename O>
void transform(metal::true_, // low quantization
const Image<I>& input_, const Function_v2v<F>& f_, Image<O>& output_)
@@ -94,6 +95,7 @@
output(p) = lut(input(p));
}
+
// template <typename I, typename F, typename O>
// void transform(metal::true_, // low quantization
// const Fast_Image<I>& input_, const Function_v2v<F>& f_, Image<O>& output_)
Index: mln/level/labeling.hh
--- mln/level/labeling.hh (revision 0)
+++ mln/level/labeling.hh (revision 0)
@@ -0,0 +1,175 @@
+// 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_LABELING_HH
+# define MLN_LEVEL_LABELING_HH
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/value/props.hh>
+# include <mln/level/fill.hh>
+
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ template <typename I, typename N, typename O>
+ void labeling(const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename N, typename O>
+ struct component_labeling
+ {
+ typedef mln_point(I) point;
+ typedef mln_value(I) value;
+
+ // in:
+ const I& input;
+ const N& nbh;
+
+ // out:
+ O& output;
+
+ // aux:
+ mln_ch_value(I, point) parent;
+ mln_ch_value(I, bool) deja_vu;
+ mln_value(O) current_l;
+
+ component_labeling(const I& input_, const N& nbh_, O& output_)
+ : // in
+ input(input_),
+ nbh(nbh_),
+ // out
+ output(output_),
+ // aux
+ parent(input.domain()),
+ deja_vu(input.domain())
+ {
+ }
+
+ void run()
+ {
+ // init
+ {
+ level::fill(deja_vu, false);
+ current_l = 0;
+ level::fill(output, 0);
+ }
+
+ // first pass
+ {
+ mln_bkd_piter(I) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ if (input(p))
+ {
+ parent(p) = p;
+ for_all(n)
+ if (input.has(n) && input(n) && deja_vu(n))
+ {
+ point r = find_root(n);
+ if (r != p)
+ parent(r) = p;
+ }
+ deja_vu(p) = true;
+ }
+ }
+
+ // second pass
+ {
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p))
+ if (parent(p) = p)
+ output(p) = ++current_l;
+ else
+ output(p) = output(parent(p));
+ }
+
+ }
+
+ point find_root(const point& x)
+ {
+ if (parent(x) = x)
+ return x;
+ else
+ return parent(x) = find_root(parent(x));
+ }
+
+ }; // end of component_labeling
+
+
+
+ template <typename I, typename N, typename O>
+ void labeling(value::binary_kind,
+ const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output)
+ {
+ impl::component_labeling<I,N,O> f(exact(input), exact(nbh), exact(output));
+ f.run();
+ }
+
+ /*
+ template <typename K, typename I, typename N, typename O>
+ void labeling(K,
+ const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output)
+ {
+ impl::flat_labeling<I,N,O> f(exact(input), exact(nbh), exact(output));
+ f.run();
+ }
+ */
+
+
+ } // end of namespace mln::level::impl
+
+
+ // facade
+
+ template <typename I, typename N, typename O>
+ void labeling(const Image<I>& input, const Neighborhood<N>& nbh, Image<O>& output)
+ {
+ mln_assertion(exact(output).domain() = exact(input).domain());
+ impl::labeling(mln_value_kind(I)(),
+ exact(input), exact(nbh), exact(output));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_LABELING_HH
Index: mln/value/lut_vec.hh
--- mln/value/lut_vec.hh (revision 1038)
+++ mln/value/lut_vec.hh (working copy)
@@ -131,8 +131,7 @@
T
lut_vec<S,T>::operator()(const mln_value(S)& val) const
{
- unsigned i = vset_.index_of(val);
- mln_precondition(i < n_);
+ mln_precondition(vset_.index_of(val) < n_);
return vec_[vset_.index_of(val)];
}
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1038)
+++ mln/value/props.hh (working copy)
@@ -38,6 +38,7 @@
# include <mln/core/macros.hh>
# include <mln/value/kind.hh>
+# include <mln/metal/bool.hh>
/// Get the minimum value of type \c T.
@@ -49,13 +50,17 @@
/// Get the number of values for value type \c T.
-# define mln_card(T) mln::value::props< T >::card
+# define mln_card_(T) mln::value::props< T >::card_
/// Get the kind of value type \c T.
# define mln_kind(T) typename mln::value::props< T >::kind
+/// Test is the value type \c T is low quantized.
+# define mln_is_lowq(T) typename metal::bool_<( mln_card_(T) != 0 )>::type
+
+
namespace mln
@@ -72,9 +77,27 @@
struct props
{
typedef data_kind kind;
- static const std::size_t card = 0;
+ static const std::size_t card_ = 0;
+ };
+
+
+ namespace internal
+ {
+
+ template <typename T>
+ struct convert_
+ {
+ static T value_at_index(std::size_t i)
+ {
+ return mln_min(T) + i;
+ }
+ static std::size_t index_of_value(const T& v)
+ {
+ return v - mln_min(T);
+ }
};
+ } // end of namespace mln::value::internal
// bool
@@ -84,7 +107,7 @@
{
static const bool min = false;
static const bool max = true;
- static const std::size_t card = 2;
+ static const std::size_t card_ = 2;
typedef binary_kind kind;
};
@@ -96,7 +119,7 @@
{
static const unsigned char min = 0;
static const unsigned char max = 255;
- static const std::size_t card = 256;
+ static const std::size_t card_ = 256;
typedef data_kind kind;
};
@@ -105,7 +128,7 @@
{
static const signed char min = -128;
static const signed char max = 127;
- static const std::size_t card = 256;
+ static const std::size_t card_ = 256;
typedef data_kind kind;
};
@@ -114,7 +137,7 @@
{
static const unsigned short min = 0;
static const unsigned short max = 65535;
- static const std::size_t card = 65536;
+ static const std::size_t card_ = 65536;
typedef data_kind kind;
};
@@ -123,7 +146,7 @@
{
static const signed short min = -32768;
static const signed short max = 32767;
- static const std::size_t card = 655356;
+ static const std::size_t card_ = 655356;
typedef data_kind kind;
};
@@ -133,7 +156,7 @@
static const unsigned int min = 0;
static const unsigned int max = UINT_MAX;
typedef data_kind kind;
- static const std::size_t card = 0;
+ static const std::size_t card_ = 0;
};
template <>
@@ -142,7 +165,7 @@
static const signed int min = INT_MIN;
static const signed int max = INT_MAX;
typedef data_kind kind;
- static const std::size_t card = 0;
+ static const std::size_t card_ = 0;
};
template <>
@@ -151,7 +174,7 @@
static const unsigned long int min = 0;
static const unsigned long int max = ULONG_MAX;
typedef data_kind kind;
- static const std::size_t card = 0;
+ static const std::size_t card_ = 0;
};
template <>
@@ -160,7 +183,7 @@
static const signed long int min = LONG_MIN;
static const signed long int max = LONG_MAX;
typedef data_kind kind;
- static const std::size_t card = 0;
+ static const std::size_t card_ = 0;
};
@@ -172,7 +195,7 @@
static const float min() { return FLT_MIN; }
static const float max() { return FLT_MAX; }
typedef data_kind kind;
- static const std::size_t card = 0;
+ static const std::size_t card_ = 0;
};
template <>
@@ -181,7 +204,7 @@
static const double min() { return DBL_MIN; }
static const double max() { return DBL_MAX; }
typedef data_kind kind;
- static const std::size_t card = 0;
+ static const std::size_t card_ = 0;
};
} // end of namespace mln::value
Index: mln/value/set.hh
--- mln/value/set.hh (revision 1038)
+++ mln/value/set.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/value/internal/iterable_set.hh>
-# include <mln/core/trait/is_lowq.hh>
+# include <mln/value/props.hh>
namespace mln
@@ -43,26 +43,17 @@
namespace value
{
-
- // Fwd decl.
- template <typename T> struct set;
-
-
namespace internal
{
- template <typename T, typename lowq = metal::false_ >
- struct run_set_selector_ // no inheritance
+ template <typename T, typename E, typename is_lowq = metal::false_>
+ struct set_selector_ // no inheritance
{};
- template <typename T>
- struct run_set_selector_< T, metal::true_ > // lowq so iterable
+ template <typename T, typename E>
+ struct set_selector_< T, E, metal::true_ > // lowq so iterable
:
- public iterable_set< T, mln::value::set<T> >
- {};
-
- template <typename T>
- struct set_selector_ : public run_set_selector_< T, mln_is_lowq(T) >
+ public iterable_set< T, E >
{};
} // end of namespace mln::value::internal
@@ -74,7 +65,7 @@
* This is the exhaustive set of values obtainable from type \c T.
*/
template <typename T>
- struct set : public internal::set_selector_<T>
+ struct set : public internal::set_selector_< T, set<T>, mln_is_lowq(T) >
{
/// Return a singleton.
static const set<T>& the();
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1038)
+++ mln/value/int_s.hh (working copy)
@@ -37,7 +37,6 @@
# include <mln/value/internal/value_like.hh>
# include <mln/value/internal/encoding.hh>
# include <mln/value/props.hh>
-# include <mln/value/set.hh>
# include <mln/debug/format.hh>
@@ -54,11 +53,11 @@
*/
template <unsigned n>
struct int_s
- : public internal::value_like_< typename internal::encoding_int_s_<n>::ret,
+ : public internal::value_like_< typename internal::encoding_signed_<n>::ret,
int_s<n> >
{
protected:
- typedef internal::value_like_< typename internal::encoding_int_s_<n>::ret,
+ typedef internal::value_like_< typename internal::encoding_signed_<n>::ret,
int_s<n> > super;
public:
@@ -80,6 +79,12 @@
/// Unit value.
static const int_s<n> one;
+
+ /// Self addition.
+ int_s<n>& operator+=(int i);
+
+ /// Self subtraction.
+ int_s<n>& operator-=(int i);
};
@@ -89,7 +94,7 @@
{
static const int_s<n> max; // = 2^(n-1) - 1
static const int_s<n> min; // = - max
- static const std::size_t card = metal::pow<2, n>::value;
+ static const std::size_t card_ = metal::pow<2, n>::value;
static const unsigned nbits = n;
typedef data_kind kind;
};
@@ -128,12 +133,33 @@
}
template <unsigned n>
- int_s<n> int_s<n>::operator-() const
+ int_s<n>
+ int_s<n>::operator-() const
{
return - this->v_;
}
template <unsigned n>
+ int_s<n>&
+ int_s<n>::operator+=(int i)
+ {
+ mln_precondition(long(this->v_) + i >= mln_min(enc));
+ mln_precondition(long(this->v_) + i <= mln_max(enc));
+ this->v_ += i;
+ return *this;
+ }
+
+ template <unsigned n>
+ int_s<n>&
+ int_s<n>::operator-=(int i)
+ {
+ mln_precondition(long(this->v_) - i >= mln_min(enc));
+ mln_precondition(long(this->v_) - i <= mln_max(enc));
+ this->v_ -= i;
+ return *this;
+ }
+
+ template <unsigned n>
const int_s<n> int_s<n>::zero = 0;
template <unsigned n>
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1038)
+++ mln/value/int_u.hh (working copy)
@@ -37,7 +37,6 @@
# include <mln/value/internal/value_like.hh>
# include <mln/value/internal/encoding.hh>
# include <mln/value/props.hh>
-# include <mln/value/set.hh>
# include <mln/debug/format.hh>
@@ -54,11 +53,11 @@
*/
template <unsigned n>
struct int_u
- : public internal::value_like_< typename internal::encoding_int_u_<n>::ret,
+ : public internal::value_like_< typename internal::encoding_unsigned_<n>::ret,
int_u<n> >
{
protected:
- typedef internal::value_like_< typename internal::encoding_int_u_<n>::ret,
+ typedef internal::value_like_< typename internal::encoding_unsigned_<n>::ret,
int_u<n> > super;
public:
@@ -77,6 +76,12 @@
/// Unit value.
static const int_u<n> one;
+
+ /// Self addition.
+ int_u<n>& operator+=(int i);
+
+ /// Self subtraction.
+ int_u<n>& operator-=(int i);
};
@@ -89,9 +94,9 @@
template <unsigned n>
struct props< int_u<n> >
{
- static const std::size_t card = metal::pow<2, n>::value;
+ static const std::size_t card_ = metal::pow<2, n>::value;
static const int_u<n> min; // = 0
- static const int_u<n> max; // = card - 1
+ static const int_u<n> max; // = card_ - 1
static const unsigned nbits = n;
typedef data_kind kind;
};
@@ -125,6 +130,26 @@
}
template <unsigned n>
+ int_u<n>&
+ int_u<n>::operator+=(int i)
+ {
+ mln_precondition(long(this->v_) + i >= 0);
+ mln_precondition(long(this->v_) + i <= mln_max(enc));
+ this->v_ += i;
+ return *this;
+ }
+
+ template <unsigned n>
+ int_u<n>&
+ int_u<n>::operator-=(int i)
+ {
+ mln_precondition(long(this->v_) - i >= 0);
+ mln_precondition(long(this->v_) - i <= mln_max(enc));
+ this->v_ -= i;
+ return *this;
+ }
+
+ template <unsigned n>
const int_u<n> int_u<n>::zero = 0;
template <unsigned n>
Index: mln/value/internal/iterable_set.hh
--- mln/value/internal/iterable_set.hh (revision 1038)
+++ mln/value/internal/iterable_set.hh (working copy)
@@ -96,21 +96,23 @@
iterable_set<T,E>::operator[](std::size_t i) const
{
mln_precondition(i < nvalues());
- return mln_min(T) + i;
+ return mln::value::internal::convert_<T>::value_at_index(i);
+ // FIXME: Was: mln_min(T) + i;
}
template <typename T, typename E>
std::size_t
iterable_set<T,E>::index_of(const T& v) const
{
- return v - mln_min(T);
+ return mln::value::internal::convert_<T>::index_of_value(v);
+ // FIXME: Was: v - mln_min(T);
}
template <typename T, typename E>
std::size_t
iterable_set<T,E>::nvalues() const
{
- return mln_card(T);
+ return mln_card_(T);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/internal/encoding.hh
--- mln/value/internal/encoding.hh (revision 1038)
+++ mln/value/internal/encoding.hh (working copy)
@@ -43,36 +43,36 @@
namespace internal
{
- template <unsigned n> struct encoding_int_u_;
+ template <unsigned n> struct encoding_unsigned_;
- template <> struct encoding_int_u_<8> { typedef unsigned char ret; };
- template <> struct encoding_int_u_<16> { typedef unsigned short ret; };
- template <> struct encoding_int_u_<32> { typedef unsigned int ret; }; // FIXME!!!
- template <> struct encoding_int_u_<64> { typedef unsigned long ret; }; // FIXME!!!
+ template <> struct encoding_unsigned_<8> { typedef unsigned char ret; };
+ template <> struct encoding_unsigned_<16> { typedef unsigned short ret; };
+ template <> struct encoding_unsigned_<32> { typedef unsigned int ret; }; // FIXME!!!
+ template <> struct encoding_unsigned_<64> { typedef unsigned long ret; }; // FIXME!!!
- template <> struct encoding_int_u_<99> { typedef void ret; }; // stopper
+ template <> struct encoding_unsigned_<99> { typedef void ret; }; // stopper
template <unsigned n>
- struct encoding_int_u_
+ struct encoding_unsigned_
{
- typedef typename encoding_int_u_<n+1>::ret ret;
+ typedef typename encoding_unsigned_<n+1>::ret ret;
};
- template <unsigned n> struct encoding_int_s_;
+ template <unsigned n> struct encoding_signed_;
- template <> struct encoding_int_s_<8> { typedef signed char ret; };
- template <> struct encoding_int_s_<16> { typedef signed short ret; };
- template <> struct encoding_int_s_<32> { typedef signed int ret; }; // FIXME!!!
- template <> struct encoding_int_s_<64> { typedef signed long ret; }; // FIXME!!!
+ template <> struct encoding_signed_<8> { typedef signed char ret; };
+ template <> struct encoding_signed_<16> { typedef signed short ret; };
+ template <> struct encoding_signed_<32> { typedef signed int ret; }; // FIXME!!!
+ template <> struct encoding_signed_<64> { typedef signed long ret; }; // FIXME!!!
- template <> struct encoding_int_s_<99> { typedef void ret; }; // stopper
+ template <> struct encoding_signed_<99> { typedef void ret; }; // stopper
template <unsigned n>
- struct encoding_int_s_
+ struct encoding_signed_
{
- typedef typename encoding_int_s_<n+1>::ret ret;
+ typedef typename encoding_signed_<n+1>::ret ret;
};
Index: mln/value/internal/value_like.hh
--- mln/value/internal/value_like.hh (revision 1038)
+++ mln/value/internal/value_like.hh (working copy)
@@ -70,6 +70,9 @@
/// Explicit convertion towards equivalent type.
V to_equiv() const;
+ /// Explicit convertion towards encoding type.
+ V to_enc() const;
+
/// Assignment from equivalent type.
E& operator=(const V& v);
@@ -112,6 +115,13 @@
}
template <typename V, typename E>
+ V
+ value_like_<V, E>::to_enc() const
+ {
+ return v_;
+ }
+
+ template <typename V, typename E>
E&
value_like_<V, E>::operator=(const V& v)
{
Index: mln/value/label.hh
--- mln/value/label.hh (revision 0)
+++ mln/value/label.hh (revision 0)
@@ -0,0 +1,236 @@
+// 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_LABEL_HH
+# define MLN_VALUE_LABEL_HH
+
+/*! \file mln/value/label.hh
+ *
+ * \brief Define a generic class for labels.
+ */
+
+# include <mln/metal/math.hh>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
+# include <mln/value/props.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+
+ /*! \brief Label value class.
+ *
+ * The parameter \c n is the number of encoding bits.
+ */
+ template <unsigned n>
+ struct label
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef typename internal::encoding_unsigned_<n>::ret enc;
+
+ /// Constructor without argument.
+ label();
+
+ /// Constructor from an (unsigned) integer.
+ label(unsigned i);
+
+ /// Assignment from an (unsigned) integer.
+ label<n>& operator=(unsigned i);
+
+ /// Self increment.
+ label<n>& operator++();
+
+ /// Self decrement.
+ label<n>& operator--();
+
+ /// Convertion to unsigned.
+ const enc& to_enc() const;
+
+ /// Unit value.
+ static const label<n> one;
+
+ protected:
+
+ enc v_;
+ };
+
+
+ namespace internal
+ {
+
+ template <unsigned n>
+ struct convert_< label<n> >
+ {
+ static label<n> value_at_index(std::size_t i)
+ {
+ return i;
+ }
+ static std::size_t index_of_value(const label<n>& v)
+ {
+ return v.to_enc();
+ }
+ };
+
+ } // end of mln::value::internal
+
+
+
+ // Safety.
+ template <> struct label<0>;
+ template <> struct label<1>;
+
+
+ /// Equality comparison.
+ template <unsigned n>
+ bool operator=(const label<n>& lhs, const label<n>& rhs);
+
+ /// Ordering comparison.
+ template <unsigned n>
+ bool operator<(const label<n>& lhs, const label<n>& rhs);
+
+
+
+
+ template <unsigned n>
+ struct props< label<n> >
+ {
+ static const std::size_t card_ = metal::pow<2, n>::value;
+ static const label<n> min; // = 0
+ static const label<n> max; // = card_ - 1
+ static const unsigned nbits = n;
+ typedef label_kind kind;
+ };
+
+
+
+
+
+
+
+ /*! \brief Print a label \p l into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] l A label.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const label<n>& l);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n>
+ label<n>::label()
+ {
+ }
+
+ template <unsigned n>
+ label<n>::label(unsigned i)
+ {
+ mln_precondition(i <= mln_max(enc));
+ v_ = enc(i);
+ }
+
+ template <unsigned n>
+ label<n>&
+ label<n>::operator=(unsigned i)
+ {
+ mln_precondition(i <= mln_max(enc));
+ v_ = enc(i);
+ return *this;
+ }
+
+ template <unsigned n>
+ label<n>&
+ label<n>::operator++()
+ {
+ mln_precondition(v_ < mln_max(enc));
+ ++v_;
+ return *this;
+ }
+
+ template <unsigned n>
+ label<n>&
+ label<n>::operator--()
+ {
+ mln_precondition(v_ != 0);
+ --v_;
+ return *this;
+ }
+
+ template <unsigned n>
+ const label<n> label<n>::one = 1;
+
+ template <unsigned n>
+ const mln_enc(label<n>)&
+ label<n>::to_enc() const
+ {
+ return v_;
+ }
+
+ template <unsigned n>
+ bool operator=(const label<n>& lhs, const label<n>& rhs)
+ {
+ return lhs.to_enc() = rhs.to_enc();
+ }
+
+ template <unsigned n>
+ bool operator<(const label<n>& lhs, const label<n>& rhs)
+ {
+ return lhs.to_enc() < rhs.to_enc();
+ }
+
+ template <unsigned n>
+ const label<n>
+ props< label<n> >::min = 0;
+
+ template <unsigned n>
+ const label<n>
+ props< label<n> >::max = metal::pow<2, n>::value - 1;
+
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const label<n>& i)
+ {
+ return ostr << i.to_enc();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_LABEL_HH
Index: img/tiny.pgm
--- img/tiny.pgm (revision 0)
+++ img/tiny.pgm (revision 0)
@@ -0,0 +1,4 @@
+P5
+64 64
+255
+©¥`fijjqy~
~ynw°×ºqtyyy{{||{~¡¨¡~^chhhpy}zpoÉÒnvyyz{~~^9¤¤^cighpx|
{sk~ ¬Ö¿vrxy{\3/£¥~\chghox|~|~~~~~|ulzÂÙpxy{Z2.3£¦¢}[bgfgowz}~}zzzy}~~~{uny£ÕÎpy}Y0332¢£|Ybgfgowz|}~}|~~~ztnw½Ý®otX/171- ¥¢~X`ggipx{}~¥¯®¤{}}|ysmuÑ×T./54/-¥¢¤ }T\bdhovy{|~¡©°¶¼¾¦wyyupju²á¥0.521//©ex ¤|QYacfkruy{|wyz©±·»ÀĶmprmhsµY*24102-¡zUy ¦zP[ccekqtxyxou{¤²¸½ÀÁÅÆ¦ohifr~~R+120257Q`Vz ¦yR[bdekquy{xnrwx{¢´¸·¿ÉÎÒÚ¦_bbqsXc+04013@YjXYy¦xS\bdekrvyyoousvª²ÂÍÌËÍÓÖV[ov<f{6/4131<]YZZx¥yR[cceksv{soqsv~
ÁÈÇÇÉÌÏÓÏPjw6C|F*53124OZ[Zx£zRYadekru
jmpsz®¾¾¾ÃÊËÌÍÎÔÓvax9+Rb-26331>|¢ZZWv£{PW_bejm~gnqv
|¯¶¶¸ÀÄÅÇÉÊÍÏ×·cx8*g¼Î½D.65344l[][u¥yNVacdilemrz}~{ª«¯³º¼½ÀÄÇÉÉÌÎÒp<z½ÑÖÙ_-4013W`b`w§¡|QZceflndksy{~{ £¬²´µ²·¿ÂľÇÊÌÅÄÎÍÎØd/2.09ccbz©¥~S[cedim¥fhnvy{¢««®«¯³µ»¼·ºÃÂÂù¿ÉÌËËÒÑS00/6ecbcz¬¨RZbccfp±nipv{§§§«®¬±µ³¸»¹µµ²º½ÆÉÉÇÊÃо<0/1Pa`ay¬§S[bbcds³}imv¤¨¨©¦¦¬±µ²¯«·ÀÅÆÆÇÊÁ©º/1.:u`_`{ «§T\bacasµmp
£§¨¨¥¥®¹ÁÃÂÃÈÊÌ©\-11Zaad~ «¨QZaab_u¿§z{¡±¾Â¾ÁÅÉÌϹ8/3<|ccg¢¬©PYacc_o°}uy
{h[m^ZDB±¿ÃÂÁÅÈË»qlh,0/Rgdg¡«¨QYaccad¸·r~ucOG_VT@:v¨»À½¿ÁÅ» ri£f1018s¡ iff ª¨RX`bbc_Á~}}z~zhOA4KKTFO·µµ·¾¼qx£¬g/511K¤¢ jgcz «©
PW`aaeey¾ª|{|}wXNÈ@=KXx®½´±¯¶½«^dy¡\.35/5d££¢¡jg`u¬ªPU`abgle¬·u{~uZDM:H>36Jl¶±®°½Á¾{QlS*482/Bx¥£¢¡ hf_t¬ªQWbdchpi¦§qvyvQ>1@DDO,?t¯´¦ª©ºÆÈÊ?Q?/7:0/Z¢¡¡¡ge`s¬ªTYdfdmupq|oK:;45=LK;|¦ ¯¯£¢±ÁÈÍÒJ8E4:807tfc^r«U[dgfmtt{
}{O=4?95:?Cs²ª¬¤¡©³ÁÇÌÓÀb0rN6<51J¡ec_r¬TYeffltqh`BD6?37A:\¨²®
¬±»ÁÆÍ¸`+f[;<33e¡ee_p®UZeediyn[cKGI8:72=K´¯¢wl`¤³¿¸lT0\f<92<wcaYl¯¬TXcc_~|KGQU<>3B32{®ÀP>BTSz¯ÀyMD<0Wm>41Ib^Sg°®U\dcU§|E?CI_5690/T»nFMc«os¶©Qfi0.VsC21ae_Qe±±[bm^fIPDDWmD,1,7³©~v¦|¹^;3T{B0:v¦³bYK_²³Zal{\<FeDB\lL-..a¦©r²ÂkK3O>/E¤º¾½XRD[±±YawjLEc[2:XX\7+D¯dk¦«ªÈ£}R7I:.X¤Á¾ÁNJ@Y¯¯Ybrl\PKcI10:8lM)etBs ¯¨£É¢~L7B@3m½ÂÃÇÊLI;U¬¬Vj{`bRSkP3,DQxR:7Fo£¨£|É¢y?;<J;²ÂÃËÎÌOI8Q®YjrW\OUiT3/KcM4nN/OmÆi2>6{WJÁÂÊÎÎÏOJ?]¬¯\aiTWPPfh;<7O3S§o,6Xoyp¯
M0@4oebÄÈÎÏÐÏLJFpª¯X]nKOJMdtNW9Uyy~84:`r~©°t75G7`qz·ÆÎÎÐÑÑGEDr«°WcoRP>GRboKNnF199^qµ¿®U/:I8R}½ÌÐÏÐÒÒ=@Dq¡±^ijGC?WXTd]¦xP44<9Th~{{y91=I:IÄÐÐÐÒÔÔ8<Ft¡°±ihjF8Eh^^[|l613;;J]v}w{V/1=J@FÍÒÒÓÔÓÑ56Gq°²XmWN9Jug`oA545;<DNgt
v505=NDHÔÕÖÕÑÏÏ11Rt®°WcPD9CntljnQ164369:@Og{M/67@RGIØÖÕÓÑÑÑ/0Ov¯TWFD;=bWuyy^63:54269=<Dcy¡¦¡~9595EVLM~ªÙÓÕÓͼ0,Am¬pa?B;5nZ^uqK2@6423::BOduW;74GXPT{}~¹ÖÑÑÇO:O99Vª¬kQ2A=DXigjkovB>842288Bl~¨¿½\0FUNXztopsuv½ÐÐÉD;NjHFª¬vD)JJSC\`Yr~eX<86468?@iz«»ÃËÅEJGW
{oenkºÒÍIHUVjF¬¡}41?EC@IHOnjkD8969;PCiz¨²ºÃÍÒ??Yx{ÊÔ¶WQ]c\TJ¯¯i,558I4@JR`{{a[39398_Ie¢«³¾ÉÒÔm0\
~§ÔÒU`had6E°°d/3.BL3:AYYuyYe55<eMg§±»ÇÐÙ²2a¬Ê×Âq]jc`f,
E°±Y1./QD514IZu{`:;55OuTl
£¹ÅÎÔÓUg
}ÐÓÕ¢bcl`ea(~K¯®Z..7A?607?R|j`SOJ7:ezUs ©µÂÌÒÙ
p
}ÑÔÈ
ffcabZ&rS¯°^.386:63:ESoeW8;?4GruX~¥°¾ÈÐÖ±»Ó´tc^[c^]$g\¯f2428<72:LPLPj;1.4Yxca¡«¹ÅÏÔÎbq£Ód\U`_^R#a¦e«°b5.58;8/4KmTP?0,+EmoMu§³ÁÌÒ×STQQ^·ÈsMT\^_]@Fl¬t¬²]2234:;016Yw^2,)4]qO]¢®¼ÈÐרbdU?-x¹ÃGGX^UdV<[}«¬³X0232;@8:>DdR/*,H\OU{
¨´ÃÍÔÁigbUFÁN@R_N[hPAGm¤
¬µH/587?FQ?BJfM-+1DQfz¥°½ÈÑÐx^gfgzWKP`ONlcE<7V¬µ<<B@]JFGTO.1Kfs{¢¬·ÂÍÓYiruoggZZPKepR:91M·¯«´:1:BBODUSL?BRBDarx}¡¨³¿ÉÒ«[cs{w|oZUQ]y`:9Q
\ No newline at end of file
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add pset and pvec point sets.
* tests/sort_points.cc: New.
* tests/pset.cc: New.
* tests/histo.cc: Update.
* mln/histo/sort.hh: Rename as...
* mln/level/sort_points.hh: ...this new file.
(sort_points): New overload.
* mln/histo/data.hh (vec): Rename as...
(vect): ...this.
* mln/core/dpoints_piter.hh: Update.
* mln/core/pvec.hh: New.
* mln/core/pset.hh: New.
* mln/core/internal/set_of.hh: Update.
* mln/accu/histo.hh: Update.
* mln/accu/bbox.hh: New.
mln/accu/bbox.hh | 134 ++++++++++++++++++
mln/accu/histo.hh | 4
mln/core/dpoints_piter.hh | 2
mln/core/internal/set_of.hh | 6
mln/core/pset.hh | 162 ++++++++++++++++++++++
mln/core/pvec.hh | 323 ++++++++++++++++++++++++++++++++++++++++++++
mln/histo/data.hh | 4
mln/level/sort_points.hh | 158 +++++++++++++++++++++
tests/histo.cc | 6
tests/pset.cc | 59 ++++++++
tests/sort_points.cc | 56 +++++++
11 files changed, 901 insertions(+), 13 deletions(-)
Index: tests/sort_points.cc
--- tests/sort_points.cc (revision 0)
+++ tests/sort_points.cc (revision 0)
@@ -0,0 +1,56 @@
+// 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/histo.cc
+ *
+ * \brief Tests on mln::accu::histo<S> and mln::histo::data<S>.
+ */
+
+#include <iterator>
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/level/sort_points.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d_b<int_u8> ima(3, 3);
+ debug::iota(ima);
+ std::vector<point2d> vec = level::sort_points(ima);
+
+ std::copy(vec.begin(), vec.end(),
+ std::ostream_iterator<point2d>(std::cout, " "));
+ std::cout << std::endl;
+
+}
Index: tests/pset.cc
--- tests/pset.cc (revision 0)
+++ tests/pset.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/pset.cc
+ *
+ * \brief Tests on mln::pset.
+ */
+
+#include <iterator>
+
+#include <mln/core/point2d.hh>
+#include <mln/core/pset.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ pset<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/histo.cc
--- tests/histo.cc (revision 1037)
+++ tests/histo.cc (working copy)
@@ -38,7 +38,6 @@
#include <mln/debug/iota.hh>
#include <mln/accu/histo.hh>
#include <mln/histo/compute.hh>
-#include <mln/histo/sort.hh>
@@ -65,11 +64,6 @@
debug::iota(ima);
histo::data< value::set<int_u8> > h = histo::compute(ima);
std::cout << h << std::endl;
-
- std::vector<point2d> vec = histo::sort_points_decreasing(ima);
- std::copy(vec.begin(), vec.end(),
- std::ostream_iterator<point2d>(std::cout, " "));
- std::cout << std::endl;
}
}
Index: mln/histo/data.hh
--- mln/histo/data.hh (revision 1037)
+++ mln/histo/data.hh (working copy)
@@ -60,7 +60,7 @@
std::size_t operator()(const value& v) const;
std::size_t& operator()(const value& v);
- const std::vector<std::size_t>& vec() const;
+ const std::vector<std::size_t>& vect() const;
const S& vset() const;
std::size_t operator[](unsigned i) const;
@@ -124,7 +124,7 @@
template <typename S>
const std::vector<std::size_t>&
- data<S>::vec() const
+ data<S>::vect() const
{
return h_;
}
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1037)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -118,7 +118,7 @@
template <typename Dps, typename Pref>
dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps,
const Generalized_Point<Pref>& p_ref)
- : dps_(exact(dps).vec()),
+ : dps_(exact(dps).vect()),
p_ref_(* internal::force_exact<Pref>(p_ref).pointer_())
{
invalidate();
Index: mln/core/pvec.hh
--- mln/core/pvec.hh (revision 0)
+++ mln/core/pvec.hh (revision 0)
@@ -0,0 +1,323 @@
+// 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_PVEC_HH
+# define MLN_CORE_PVEC_HH
+
+/*! \file mln/core/pvec.hh
+ *
+ * \brief Definition of a point set class based on std::vector.
+ */
+
+# include <vector>
+
+# include <mln/core/concept/point_set.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_
+ {
+ 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()
+ {
+ 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];
+ }
+
+
+
+ // 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
+
+
+#endif // ! MLN_CORE_PVEC_HH
Index: mln/core/pset.hh
--- mln/core/pset.hh (revision 0)
+++ mln/core/pset.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_PSET_HH
+# define MLN_CORE_PSET_HH
+
+/*! \file mln/core/pset.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/pvec.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 pset : public Point_Set< pset<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 pvec_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef internal::fixme bkd_piter;
+
+ /// Constructor.
+ pset();
+
+ /// 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.
+ pset<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>
+ pset<P>::pset()
+ {
+ }
+
+ template <typename P>
+ bool
+ pset<P>::has(const P& p) const
+ {
+ return this->super_::has(p);
+ }
+
+ template <typename P>
+ std::size_t
+ pset<P>::npoints() const
+ {
+ return this->super_::nelements();
+ }
+
+ template <typename P>
+ pset<P>&
+ pset<P>::insert(const P& p)
+ {
+ this->super_::insert(p);
+ bb_.take(p);
+ return *this;
+ }
+
+ template <typename P>
+ const P&
+ pset<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return this->super_::element(i);
+ }
+
+ template <typename P>
+ void
+ pset<P>::clear()
+ {
+ this->super_::clear();
+ bb_.init();
+ }
+
+ template <typename P>
+ const box_<mln_point(P)>&
+ pset<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ return bb_.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSET_HH
Index: mln/core/internal/set_of.hh
--- mln/core/internal/set_of.hh (revision 1037)
+++ mln/core/internal/set_of.hh (working copy)
@@ -59,6 +59,8 @@
*
* The parameter \c E is the element type, which shall not be
* const-qualified.
+ *
+ * \todo Add a remove method.
*/
template <typename E>
class set_of_
@@ -123,7 +125,7 @@
*
* \return An array (std::vector) of elements.
*/
- const std::vector<E>& vec() const;
+ const std::vector<E>& vect() const;
protected:
@@ -245,7 +247,7 @@
template <typename E>
const std::vector<E>&
- set_of_<E>::vec() const
+ set_of_<E>::vect() const
{
if (needs_update_)
update_();
Index: mln/core/concept/point_iterator.hh
Index: mln/core/concept/point_site.hh
Index: mln/level/sort_points.hh
--- mln/level/sort_points.hh (revision 0)
+++ mln/level/sort_points.hh (revision 0)
@@ -0,0 +1,158 @@
+// 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_SORT_POINTS_HH
+# define MLN_LEVEL_SORT_POINTS_HH
+
+/*! \file mln/level/sort_points.hh
+ *
+ * \brief Sort_Points the contents of an image into another one.
+ */
+
+# include <vector>
+# include <utility>
+# include <algorithm>
+
+# include <mln/core/concept/image.hh>
+# include <mln/histo/compute.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Sort points the image \p input through a function \p f to set
+ * the \p output image.
+ *
+ * \param[in] input The input image.
+ *
+ * \pre \p input.has_data
+ */
+ template <typename I>
+ std::vector<mln_point(I)> sort_points(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ struct value_point_less_
+ {
+ const I& ima_;
+
+ value_point_less_(const I& ima)
+ : ima_(ima)
+ {
+ }
+
+ bool operator()(const mln_point(I)& lhs,
+ const mln_point(I)& rhs) const
+ {
+ return ima_(lhs) < ima_(rhs) || (ima_(lhs) = ima_(rhs)
+ && lhs < rhs);
+ }
+ };
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points(metal::false_, // general case
+ const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+
+ std::vector<mln_point(I)> vec;
+ vec.reserve(input.npoints());
+
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ vec.push_back(p);
+
+ std::sort(vec.begin(), vec.end(),
+ value_point_less_<I>(input));
+ return vec;
+ }
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points(metal::true_, // low quantization
+ const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+
+ typedef mln_vset(I) S;
+ const S& vset = input.values();
+ const unsigned n = vset.nvalues();
+
+ // h
+ histo::data<S> h = histo::compute(input);
+
+ // preparing output data
+ std::vector<unsigned> loc(vset.nvalues());
+ loc[0] = 0;
+ for (unsigned i = 1; i != n; ++i)
+ loc[i] = loc[i-1] + h[i-1];
+
+ /*
+ MEMO. Decreasing case is:
+ loc[n-1] = 0;
+ for (unsigned i = n - 2; i != 0; --i)
+ loc[i] = loc[i+1] + h[i+1];
+ */
+
+ // computing output data
+ std::vector<mln_point(I)> vec(input.npoints());
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ vec[loc[vset.index_of(input(p))]++] = p;
+
+ return vec;
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ return impl::sort_points(mln_is_value_lowq(I)(), exact(input));
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_SORT_POINTS_HH
Index: mln/accu/histo.hh
--- mln/accu/histo.hh (revision 1037)
+++ mln/accu/histo.hh (working copy)
@@ -67,7 +67,7 @@
std::size_t nvalues() const;
std::size_t sum() const;
- const std::vector<std::size_t>& vec() const;
+ const std::vector<std::size_t>& vect() const;
const S& vset() const;
@@ -160,7 +160,7 @@
template <typename S>
const std::vector<std::size_t>&
- histo<S>::vec() const
+ histo<S>::vect() const
{
return h_;
}
Index: mln/accu/bbox.hh
--- mln/accu/bbox.hh (revision 0)
+++ mln/accu/bbox.hh (revision 0)
@@ -0,0 +1,134 @@
+// 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_BBOX_HH
+# define MLN_ACCU_BBOX_HH
+
+/*! \file mln/accu/bbox.hh
+ *
+ * \brief Define an accumulator that computes a bbox.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/box.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! Generic bbox accumulator class.
+ *
+ * The parameter \c P is the type of points.
+ */
+ template <typename P>
+ struct bbox : public Accumulator< bbox<P> >
+ {
+ typedef P value;
+
+ bbox();
+ void take(const P& p);
+ void init();
+
+ operator box_<P>() const;
+ const box_<P>& to_value() const;
+
+ bool is_valid() const;
+
+ protected:
+
+ bool is_valid_;
+ box_<P> b_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ bbox<P>::bbox()
+ {
+ init();
+ }
+
+ template <typename P>
+ void bbox<P>::take(const P& p)
+ {
+ if (! is_valid_)
+ {
+ b_.pmin() = p;
+ b_.pmax() = p;
+ is_valid_ = true;
+ return;
+ }
+ for (unsigned i = 0; i < P::dim; ++i)
+ if (p[i] < b_.pmin()[i])
+ b_.pmin()[i] = p[i];
+ else if (p[i] > b_.pmax()[i])
+ b_.pmax()[i] = p[i];
+ }
+
+ template <typename P>
+ void
+ bbox<P>::init()
+ {
+ is_valid_ = false;
+ }
+
+ template <typename P>
+ bbox<P>::operator box_<P>() const
+ {
+ mln_precondition(is_valid_);
+ return b_;
+ }
+
+ template <typename P>
+ const box_<P>&
+ bbox<P>::to_value() const
+ {
+ mln_precondition(is_valid_);
+ return b_;
+ }
+
+ template <typename P>
+ bool
+ bbox<P>::is_valid() const
+ {
+ return is_valid_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_BBOX_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add int_s, an histogram class, and distributed sort.
* tests/int_s8.cc: New.
* tests/int_u8.cc: Augment.
* mln/histo/sort.hh: New.
* mln/histo/data.hh: New.
* mln/histo/compute.hh: New.
* mln/accu/histo.hh: Fix doc.
* mln/accu/median.hh: Fix doc.
* mln/value/int_s8.hh: New.
* mln/value/int_u16.hh: New.
* mln/value/int_u8.hh: New.
* mln/value/int_s.hh: New.
* mln/value/int_u.hh (zero, one): New.
(encoding_): Move to...
* mln/value/internal/encoding.hh: ...this new file.
* tests/median.cc,
* tests/fast_median.cc,
* tests/main.cc,
* tests/hmedian.cc,
* tests/erosion.cc,
* tests/naive_median.cc,
* tests/vset.cc,
* tests/histo.cc,
* mln/io/save_pgm.hh,
* mln/io/load_pgm.hh: Update.
mln/accu/histo.hh | 2
mln/accu/median.hh | 2
mln/histo/compute.hh | 95 +++++++++++++++++++++++
mln/histo/data.hh | 149 +++++++++++++++++++++++++++++++++++++
mln/histo/sort.hh | 147 ++++++++++++++++++++++++++++++++++++
mln/io/load_pgm.hh | 2
mln/io/save_pgm.hh | 2
mln/value/int_s.hh | 163 +++++++++++++++++++++++++++++++++++++++++
mln/value/int_s8.hh | 55 +++++++++++++
mln/value/int_u.hh | 79 ++++++++++++-------
mln/value/int_u16.hh | 55 +++++++++++++
mln/value/int_u8.hh | 55 +++++++++++++
mln/value/internal/encoding.hh | 86 +++++++++++++++++++++
tests/erosion.cc | 2
tests/fast_median.cc | 2
tests/histo.cc | 26 ++++++
tests/hmedian.cc | 2
tests/int_s8.cc | 51 ++++++++++++
tests/int_u8.cc | 9 ++
tests/main.cc | 9 +-
tests/median.cc | 2
tests/naive_median.cc | 2
tests/vset.cc | 2
23 files changed, 951 insertions(+), 48 deletions(-)
Index: tests/median.cc
--- tests/median.cc (revision 1036)
+++ tests/median.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/median.hh>
#include <mln/level/approx/median.hh>
Index: tests/int_s8.cc
--- tests/int_s8.cc (revision 0)
+++ tests/int_s8.cc (revision 0)
@@ -0,0 +1,51 @@
+// 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/int_s.cc
+ *
+ * \brief Tests on mln::value::int_s.
+ */
+
+#include <mln/value/int_s.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_s;
+
+ {
+ int_s<7> i = 3;
+ i = 2;
+ mln_assertion(i = 2);
+ mln_assertion(i != 3);
+
+ mln_assertion(-i = -2);
+ mln_assertion(-3 * i = -6);
+ }
+
+}
Index: tests/int_u8.cc
--- tests/int_u8.cc (revision 1036)
+++ tests/int_u8.cc (working copy)
@@ -30,7 +30,7 @@
* \brief Tests on mln::value::int_u8.
*/
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
@@ -39,6 +39,7 @@
using namespace mln;
using value::int_u8;
+ {
int_u8 i = 3;
i = 2;
mln_assertion(i = 2);
@@ -47,3 +48,9 @@
mln_assertion(-i = -2);
mln_assertion(-3 * i = -6);
}
+
+ {
+ int_u8 i = 128;
+ std::cout << i + i << std::endl;
+ }
+}
Index: tests/fast_median.cc
--- tests/fast_median.cc (revision 1036)
+++ tests/fast_median.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
#include <mln/level/fast_median.hh>
Index: tests/main.cc
--- tests/main.cc (revision 1036)
+++ tests/main.cc (working copy)
@@ -39,13 +39,12 @@
#include <mln/morpho/erosion.hh>
#include <mln/morpho/Rd.hh>
+#include <mln/value/int_u8.hh>
-typedef unsigned char int_u8;
-
-// static int_u8 cos_sin(const mln::point2d& p)
+// static value::int_u8 cos_sin(const mln::point2d& p)
// {
-// return (int_u8)(255 * std::cos(float(p.row())) * std::sin(float(p.col())));
+// return (value::int_u8)(255 * std::cos(float(p.row())) * std::sin(float(p.col())));
// }
@@ -54,7 +53,7 @@
using namespace mln;
const unsigned size = 1000;
- image2d_b<int_u8> f(size, size);
+ image2d_b<value::int_u8> f(size, size);
morpho::Rd(f, f, c8());
}
Index: tests/hmedian.cc
--- tests/hmedian.cc (revision 1036)
+++ tests/hmedian.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/median.hh>
#include <mln/level/compare.hh>
Index: tests/erosion.cc
--- tests/erosion.cc (revision 1036)
+++ tests/erosion.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/fill.hh>
#include <mln/morpho/erosion.hh>
Index: tests/naive_median.cc
--- tests/naive_median.cc (revision 1036)
+++ tests/naive_median.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/naive/median.hh>
Index: tests/vset.cc
--- tests/vset.cc (revision 1036)
+++ tests/vset.cc (working copy)
@@ -30,7 +30,7 @@
* \brief Tests on mln::value::set_<T>.
*/
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/value/set.hh>
Index: tests/histo.cc
--- tests/histo.cc (revision 1036)
+++ tests/histo.cc (working copy)
@@ -27,17 +27,27 @@
/*! \file tests/histo.cc
*
- * \brief Tests on mln::value::histo<S>.
+ * \brief Tests on mln::accu::histo<S> and mln::histo::data<S>.
*/
+#include <iterator>
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
#include <mln/accu/histo.hh>
+#include <mln/histo/compute.hh>
+#include <mln/histo/sort.hh>
int main()
{
using namespace mln;
+ using value::int_u8;
+ {
accu::histo< value::set<bool> > h;
for (unsigned i = 0; i < 5; ++i)
@@ -49,3 +59,17 @@
mln_assertion(h[0] * 10 + h[1] = 51);
mln_assertion(h(false) * 10 + h(true) = 51);
}
+
+ {
+ image2d_b<int_u8> ima(3, 3);
+ debug::iota(ima);
+ histo::data< value::set<int_u8> > h = histo::compute(ima);
+ std::cout << h << std::endl;
+
+ std::vector<point2d> vec = histo::sort_points_decreasing(ima);
+ std::copy(vec.begin(), vec.end(),
+ std::ostream_iterator<point2d>(std::cout, " "));
+ std::cout << std::endl;
+ }
+
+}
Index: mln/histo/sort.hh
--- mln/histo/sort.hh (revision 0)
+++ mln/histo/sort.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_HISTO_SORT_HH
+# define MLN_HISTO_SORT_HH
+
+/*! \file mln/histo/sort.hh
+ *
+ * \brief Routine to sort an histogram.
+ */
+
+# include <vector>
+
+# include <mln/core/concept/image.hh>
+# include <mln/histo/compute.hh>
+
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+ /// Sort points of image \p input by decreasing values.
+ template <typename I>
+ std::vector<mln_point(I)> sort_points_decreasing(const Image<I>& input);
+
+ /// Sort points of image \p input by increasing values.
+ template <typename I>
+ std::vector<mln_point(I)> sort_points_increasing(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_decreasing(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+
+ typedef mln_vset(I) S;
+ const S& vset = input.values();
+ const unsigned n = vset.nvalues();
+
+ // h
+ histo::data<S> h = compute(input);
+
+ // preparing output data
+ std::vector<unsigned> loc(vset.nvalues());
+ loc[n-1] = 0;
+ for (unsigned i = n - 2; i != 0; --i)
+ loc[i] = loc[i+1] + h[i+1];
+
+ // computing output data
+ std::vector<mln_point(I)> vec(input.npoints());
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ vec[loc[vset.index_of(input(p))]++] = p;
+
+ return vec;
+ }
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_increasing(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+
+ typedef mln_vset(I) S;
+ const S& vset = input.values();
+ const unsigned n = vset.nvalues();
+
+ // h
+ histo::data<S> h = compute(input);
+
+ // preparing output data
+ std::vector<unsigned> loc(vset.nvalues());
+ loc[0] = 0;
+ for (unsigned i = 1; i != n; ++i)
+ loc[i] = loc[i-1] + h[i-1];
+
+ // computing output data
+ std::vector<mln_point(I)> vec(input.npoints());
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ vec[loc[vset.index_of(input(p))]++] = p;
+
+ return vec;
+ }
+
+ } // end of namespace mln::histo::impl
+
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_decreasing(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ mln_precondition(exact(input).values().nvalues() > 1); // FIXME
+ return impl::sort_points_decreasing(exact(input));
+ }
+
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_increasing(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ mln_precondition(exact(input).values().nvalues() > 1); // FIXME
+ return impl::sort_points_increasing(exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::histo
+
+} // end of namespace mln
+
+
+#endif // ! MLN_HISTO_SORT_HH
Index: mln/histo/data.hh
--- mln/histo/data.hh (revision 0)
+++ mln/histo/data.hh (revision 0)
@@ -0,0 +1,149 @@
+// 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_HISTO_DATA_HH
+# define MLN_HISTO_DATA_HH
+
+/*! \file mln/histo/data.hh
+ *
+ * \brief Define a generic histogram class.
+ */
+
+# include <vector>
+# include <algorithm>
+
+# include <mln/core/concept/value_set.hh>
+
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+
+ /*! Generic histogram class over a value set with type \c S.
+ */
+ template <typename S>
+ struct data
+ {
+ typedef mln_value(S) value;
+
+ data(const Value_Set<S>& s);
+
+ void clear();
+
+ std::size_t operator()(const value& v) const;
+ std::size_t& operator()(const value& v);
+
+ const std::vector<std::size_t>& vec() const;
+ const S& vset() const;
+ std::size_t operator[](unsigned i) const;
+
+ protected:
+
+ const S& s_;
+ std::vector<std::size_t> h_;
+ };
+
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const data<S>& h);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ data<S>::data(const Value_Set<S>& s)
+ : s_(exact(s)),
+ h_(s_.nvalues(), 0)
+ {
+ clear();
+ }
+
+ template <typename S>
+ void
+ data<S>::clear()
+ {
+ std::fill(h_.begin(), h_.end(), 0);
+ }
+
+ template <typename S>
+ std::size_t
+ data<S>::operator()(const value& v) const
+ {
+ return h_[s_.index_of(v)];
+ }
+
+ template <typename S>
+ std::size_t&
+ data<S>::operator()(const value& v)
+ {
+ return h_[s_.index_of(v)];
+ }
+
+ template <typename S>
+ const S&
+ data<S>::vset() const
+ {
+ return s_;
+ }
+
+ template <typename S>
+ std::size_t
+ data<S>::operator[](unsigned i) const
+ {
+ mln_precondition(i < s_.nvalues());
+ return h_[i];
+ }
+
+ template <typename S>
+ const std::vector<std::size_t>&
+ data<S>::vec() const
+ {
+ return h_;
+ }
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const data<S>& h)
+ {
+ mln_viter(S) v(h.vset());
+ for_all(v)
+ if (h(v) != 0)
+ ostr << v << ':' << h(v) << ' ';
+ return ostr;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::histo
+
+} // end of namespace mln
+
+
+#endif // ! MLN_HISTO_DATA_HH
Index: mln/histo/compute.hh
--- mln/histo/compute.hh (revision 0)
+++ mln/histo/compute.hh (revision 0)
@@ -0,0 +1,95 @@
+// 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_HISTO_COMPUTE_HH
+# define MLN_HISTO_COMPUTE_HH
+
+/*! \file mln/histo/compute.hh
+ *
+ * \brief Routine to compute an histogram.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/histo/data.hh>
+
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+ /// Compute the histogram of image \p input.
+ template <typename I>
+ data<mln_vset(I)> compute(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ data<mln_vset(I)> compute(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ data<mln_vset(I)> h(input.values());
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ ++h(input(p));
+ return h;
+ }
+
+ template <typename I>
+ data<mln_vset(I)> compute(const Fast_Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ data<mln_vset(I)> h(input.values());
+ mln_pixter(const I) p(input);
+ for_all(p)
+ ++h(*p);
+ return h;
+ }
+
+ } // end of namespace mln::histo::impl
+
+
+ template <typename I>
+ data<mln_vset(I)> compute(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ return impl::compute(exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::histo
+
+} // end of namespace mln
+
+
+#endif // ! MLN_HISTO_COMPUTE_HH
Index: mln/io/save_pgm.hh
--- mln/io/save_pgm.hh (revision 1036)
+++ mln/io/save_pgm.hh (working copy)
@@ -33,7 +33,7 @@
# include <fstream>
# include <mln/core/image2d_b.hh>
-# include <mln/value/int_u.hh>
+# include <mln/value/int_u8.hh>
namespace mln
Index: mln/io/load_pgm.hh
--- mln/io/load_pgm.hh (revision 1036)
+++ mln/io/load_pgm.hh (working copy)
@@ -34,7 +34,7 @@
# include <string>
# include <mln/core/image2d_b.hh>
-# include <mln/value/int_u.hh>
+# include <mln/value/int_u8.hh>
namespace mln
Index: mln/accu/histo.hh
--- mln/accu/histo.hh (revision 1036)
+++ mln/accu/histo.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/accu/histo.hh
*
- * \brief Define a couple of generic histogram classes.
+ * \brief Define a generic histogram accumulator class.
*/
# include <vector>
Index: mln/accu/median.hh
--- mln/accu/median.hh (revision 1036)
+++ mln/accu/median.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/accu/median.hh
*
- * \brief Define FIXME
+ * \brief Define a generic median accumulator class.
*/
# include <mln/core/concept/accumulator.hh>
Index: mln/value/int_s8.hh
--- mln/value/int_s8.hh (revision 0)
+++ mln/value/int_s8.hh (revision 0)
@@ -0,0 +1,55 @@
+// 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_INT_S8_HH
+# define MLN_VALUE_INT_S8_HH
+
+/*! \file mln/value/int_s8.hh
+ *
+ * \brief Define the alias value::int_s8.
+ */
+
+# include <mln/value/int_s.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for signed 8 bit integers.
+ typedef int_s<8> int_s8;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_S8_HH
Index: mln/value/int_u16.hh
--- mln/value/int_u16.hh (revision 0)
+++ mln/value/int_u16.hh (revision 0)
@@ -0,0 +1,55 @@
+// 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_INT_U16_HH
+# define MLN_VALUE_INT_U16_HH
+
+/*! \file mln/value/int_u16.hh
+ *
+ * \brief Define the alias value::int_u16.
+ */
+
+# include <mln/value/int_u.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for unsigned 16 bit integers.
+ typedef int_u<16> int_u16;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U16_HH
Index: mln/value/int_u8.hh
--- mln/value/int_u8.hh (revision 0)
+++ mln/value/int_u8.hh (revision 0)
@@ -0,0 +1,55 @@
+// 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_INT_U8_HH
+# define MLN_VALUE_INT_U8_HH
+
+/*! \file mln/value/int_u8.hh
+ *
+ * \brief Define the alias value::int_u8.
+ */
+
+# include <mln/value/int_u.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for unsigned 8 bit integers.
+ typedef int_u<8> int_u8;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U8_HH
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 0)
+++ mln/value/int_s.hh (revision 0)
@@ -0,0 +1,163 @@
+// 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_INT_S_HH
+# define MLN_VALUE_INT_S_HH
+
+/*! \file mln/value/int_s.hh
+ *
+ * \brief Define a generic class for signed integers.
+ */
+
+# include <mln/metal/math.hh>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
+# include <mln/value/props.hh>
+# include <mln/value/set.hh>
+# include <mln/debug/format.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! \brief Signed integer value class.
+ *
+ * The parameter is \c n the number of encoding bits.
+ */
+ template <unsigned n>
+ struct int_s
+ : public internal::value_like_< typename internal::encoding_int_s_<n>::ret,
+ int_s<n> >
+ {
+ protected:
+ typedef internal::value_like_< typename internal::encoding_int_s_<n>::ret,
+ int_s<n> > super;
+
+ public:
+
+ /// Encoding associated type.
+ typedef typename super::enc enc;
+
+ /// Constructor without argument.
+ int_s();
+
+ /// Constructor from an integer.
+ int_s(int i);
+
+ /// Negation.
+ int_s<n> operator-() const;
+
+ /// Zero value.
+ static const int_s<n> zero;
+
+ /// Unit value.
+ static const int_s<n> one;
+ };
+
+
+
+ template <unsigned n>
+ struct props< int_s<n> >
+ {
+ static const int_s<n> max; // = 2^(n-1) - 1
+ static const int_s<n> min; // = - max
+ static const std::size_t card = metal::pow<2, n>::value;
+ static const unsigned nbits = n;
+ typedef data_kind kind;
+ };
+
+
+ // Safety.
+ template <> struct int_s<0>;
+ template <> struct int_s<1>;
+
+
+
+ /*! \brief Print an signed integer \p i into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] i An signed integer.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_s<n>& i);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n>
+ int_s<n>::int_s()
+ {
+ }
+
+ template <unsigned n>
+ int_s<n>::int_s(int i)
+ {
+ mln_precondition(i >= mln_min(enc));
+ mln_precondition(i <= mln_max(enc));
+ this->v_ = enc(i);
+ }
+
+ template <unsigned n>
+ int_s<n> int_s<n>::operator-() const
+ {
+ return - this->v_;
+ }
+
+ template <unsigned n>
+ const int_s<n> int_s<n>::zero = 0;
+
+ template <unsigned n>
+ const int_s<n> int_s<n>::one = 1;
+
+ template <unsigned n>
+ const int_s<n>
+ props< int_s<n> >::min = 1 - metal::pow<2, n - 1>::value;
+
+ template <unsigned n>
+ const int_s<n>
+ props< int_s<n> >::max = metal::pow<2, n - 1>::value - 1;
+
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_s<n>& i)
+ {
+ return ostr << debug::format(i.to_equiv());
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_S_HH
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1036)
+++ mln/value/int_u.hh (working copy)
@@ -35,8 +35,10 @@
# include <mln/metal/math.hh>
# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
# include <mln/value/props.hh>
# include <mln/value/set.hh>
+# include <mln/debug/format.hh>
namespace mln
@@ -46,25 +48,18 @@
{
- namespace internal
- {
- template <unsigned n> struct encoding_;
- template <> struct encoding_<8> { typedef unsigned char ret; };
- }
-
-
/*! \brief Unsigned integer value class.
*
* The parameter is \c n the number of encoding bits.
*/
template <unsigned n>
- struct int_u_
- : public internal::value_like_< typename internal::encoding_<n>::ret,
- int_u_<n> >
+ struct int_u
+ : public internal::value_like_< typename internal::encoding_int_u_<n>::ret,
+ int_u<n> >
{
protected:
- typedef internal::value_like_< typename internal::encoding_<n>::ret,
- int_u_<n> > super;
+ typedef internal::value_like_< typename internal::encoding_int_u_<n>::ret,
+ int_u<n> > super;
public:
@@ -72,60 +67,82 @@
typedef typename super::enc enc;
/// Constructor without argument.
- int_u_();
+ int_u();
/// Constructor from an integer.
- int_u_(int i);
+ int_u(int i);
+
+ /// Zero value.
+ static const int_u<n> zero;
+
+ /// Unit value.
+ static const int_u<n> one;
};
+ // Safety.
+ template <> struct int_u<0>;
+ template <> struct int_u<1>;
+
template <unsigned n>
- struct props< int_u_<n> > : public props< typename internal::encoding_<n>::ret >
+ struct props< int_u<n> >
{
- static const unsigned nbits = n;
static const std::size_t card = metal::pow<2, n>::value;
+ static const int_u<n> min; // = 0
+ static const int_u<n> max; // = card - 1
+ static const unsigned nbits = n;
+ typedef data_kind kind;
};
- /// Alias for unsigned 8bit integers.
- typedef int_u_<8> int_u8;
-
- /// Alias for the set of unsigned 8bit integers.
- typedef set<int_u8> int_u8_set;
-
-
-
- /*! \brief Print an int_u8 \p i into the output stream \p ostr.
+ /*! \brief Print an unsigned integer \p i into the output stream \p ostr.
*
* \param[in,out] ostr An output stream.
- * \param[in] i An int_u8.
+ * \param[in] i An unsigned integer.
*
* \return The modified output stream \p ostr.
*/
- std::ostream& operator<<(std::ostream& ostr, const int_u8& i);
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i);
# ifndef MLN_INCLUDE_ONLY
template <unsigned n>
- int_u_<n>::int_u_()
+ int_u<n>::int_u()
{
}
template <unsigned n>
- int_u_<n>::int_u_(int i)
+ int_u<n>::int_u(int i)
{
mln_precondition(i >= 0);
mln_precondition(i <= mln_max(enc));
this->v_ = enc(i);
}
- std::ostream& operator<<(std::ostream& ostr, const int_u8& i)
+ template <unsigned n>
+ const int_u<n> int_u<n>::zero = 0;
+
+ template <unsigned n>
+ const int_u<n> int_u<n>::one = 1;
+
+
+ template <unsigned n>
+ const int_u<n>
+ props< int_u<n> >::min = 0;
+
+ template <unsigned n>
+ const int_u<n>
+ props< int_u<n> >::max = metal::pow<2, n>::value - 1;
+
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i)
{
- return ostr << unsigned(i.to_equiv());
+ return ostr << debug::format(i.to_equiv());
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/internal/encoding.hh
--- mln/value/internal/encoding.hh (revision 0)
+++ mln/value/internal/encoding.hh (revision 0)
@@ -0,0 +1,86 @@
+// 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_INTERNAL_ENCODING_HH
+# define MLN_VALUE_INTERNAL_ENCODING_HH
+
+/*! \file mln/value/internal/encoding.hh
+ *
+ * \brief Define some information about how to encode some value types.
+ */
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ namespace internal
+ {
+
+ template <unsigned n> struct encoding_int_u_;
+
+ template <> struct encoding_int_u_<8> { typedef unsigned char ret; };
+ template <> struct encoding_int_u_<16> { typedef unsigned short ret; };
+ template <> struct encoding_int_u_<32> { typedef unsigned int ret; }; // FIXME!!!
+ template <> struct encoding_int_u_<64> { typedef unsigned long ret; }; // FIXME!!!
+
+ template <> struct encoding_int_u_<99> { typedef void ret; }; // stopper
+
+ template <unsigned n>
+ struct encoding_int_u_
+ {
+ typedef typename encoding_int_u_<n+1>::ret ret;
+ };
+
+
+
+ template <unsigned n> struct encoding_int_s_;
+
+ template <> struct encoding_int_s_<8> { typedef signed char ret; };
+ template <> struct encoding_int_s_<16> { typedef signed short ret; };
+ template <> struct encoding_int_s_<32> { typedef signed int ret; }; // FIXME!!!
+ template <> struct encoding_int_s_<64> { typedef signed long ret; }; // FIXME!!!
+
+ template <> struct encoding_int_s_<99> { typedef void ret; }; // stopper
+
+ template <unsigned n>
+ struct encoding_int_s_
+ {
+ typedef typename encoding_int_s_<n+1>::ret ret;
+ };
+
+
+ } // end of namespace mln::value::internal
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INTERNAL_ENCODING_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make value::set works for any type.
* mln/value/set.hh: Rename as...
* mln/value/internal/iterable_set.hh: ...this.
(the): Remove.
(E): New.
* mln/value/set.hh: New.
* tests/vset.cc,
* tests/histo.cc,
* TODO,
* mln/core/macros.hh,
* mln/core/trait/is_lowq.hh,
* mln/core/fimage.hh,
* mln/core/image2d_b.hh,
* mln/level/naive/median.hh,
* mln/level/was.median.hh,
* mln/level/fast_median.hh,
* mln/level/transform.hh,
* mln/level/median.hh,
* mln/accu/histo.hh,
* mln/accu/median.hh,
* mln/accu/median_alt.hh,
* mln/value/props.hh,
* mln/value/cast.hh,
* mln/value/int_u.hh: Update.
TODO | 2
mln/accu/histo.hh | 68 +++++++++------------------
mln/accu/median.hh | 47 ++++---------------
mln/accu/median_alt.hh | 4 -
mln/core/fimage.hh | 4 -
mln/core/image2d_b.hh | 2
mln/core/macros.hh | 5 +-
mln/core/trait/is_lowq.hh | 6 +-
mln/level/fast_median.hh | 2
mln/level/median.hh | 5 +-
mln/level/naive/median.hh | 2
mln/level/transform.hh | 2
mln/level/was.median.hh | 4 -
mln/value/cast.hh | 6 +-
mln/value/int_u.hh | 8 ---
mln/value/internal/iterable_set.hh | 57 ++++++++++-------------
mln/value/props.hh | 13 +----
mln/value/set.hh | 91 +++++++++++--------------------------
tests/histo.cc | 22 +-------
tests/vset.cc | 32 ++++++-------
20 files changed, 138 insertions(+), 244 deletions(-)
Index: tests/vset.cc
--- tests/vset.cc (revision 1035)
+++ tests/vset.cc (working copy)
@@ -35,29 +35,31 @@
-int main()
+template <typename T>
+void test()
{
- using namespace mln;
-
- typedef bool T;
- // typedef value::int_u8 T;
- // typedef short T;
-
- typedef value::set_<T> S;
+ typedef mln::value::set<T> S;
S s;
- {
- S::fwd_viter v(s);
+ mln_fwd_viter(S) v(s);
for_all(v)
std::cout << v << ' ';
std::cout << std::endl;
- }
- {
- S::bkd_viter v(s);
- for_all(v)
- std::cout << v << ' ';
+ mln_bkd_viter(S) w(s);
+ for_all(w)
+ std::cout << w << ' ';
std::cout << std::endl;
}
+
+
+int main()
+{
+ using namespace mln;
+
+ test<bool>();
+// test<unsigned char>();
+// test<unsigned short>();
+// test<value::int_u8>();
}
Index: tests/histo.cc
--- tests/histo.cc (revision 1035)
+++ tests/histo.cc (working copy)
@@ -30,7 +30,6 @@
* \brief Tests on mln::value::histo<S>.
*/
-#include <mln/value/int_u.hh>
#include <mln/accu/histo.hh>
@@ -38,11 +37,8 @@
int main()
{
using namespace mln;
- using namespace mln::value;
- using namespace mln::accu;
-
- histo_on_type<bool> h;
+ accu::histo< value::set<bool> > h;
for (unsigned i = 0; i < 5; ++i)
h.take(false);
@@ -50,18 +46,6 @@
h.take(true);
h.untake(true);
- std::cout << h << std::endl;
- std::cout << h[0] * 10 + h[1] << std::endl;
- std::cout << h(false) * 10 + h(true) << std::endl;
-
- h.init();
- std::cout << h << std::endl;
-
-
- // ...
-
-
- typedef value::set_<int_u8> S;
- histo_on_set<S> h_u8(S::the());
- std::cout << h_u8 << std::endl;
+ mln_assertion(h[0] * 10 + h[1] = 51);
+ mln_assertion(h(false) * 10 + h(true) = 51);
}
Index: TODO
--- TODO (revision 1035)
+++ TODO (working copy)
@@ -18,7 +18,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
-image defined by f/pset
** extensions
@@ -35,7 +34,6 @@
* clean-up
-accu::histo and median: remove inheritance
select_function in fun::internal::selector_p2? etc.
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1035)
+++ mln/core/macros.hh (working copy)
@@ -149,7 +149,10 @@
# define mln_value(T) typename T::value
/// Shortcut to the kind of values for an image with type \c I.
-# define mln_value_kind(T) typename mln::value::props< mln_value(I) >::kind
+# define mln_value_kind(I) typename mln::value::props< mln_value(I) >::kind
+
+/// Shortcut to test if the values of an image with type \c I are lowly quantifized.
+# define mln_is_value_lowq(I) typename mln::trait::is_lowq< mln_value(I) >::ret
/// Shortcut to access the type of value set (vset) associated to T.
# define mln_vset(T) typename T::vset
Index: mln/core/trait/is_lowq.hh
--- mln/core/trait/is_lowq.hh (revision 1035)
+++ mln/core/trait/is_lowq.hh (working copy)
@@ -37,7 +37,7 @@
# include <mln/value/props.hh>
-# define mln_is_lowq(I) typename mln::trait::is_lowq< I >::ret
+# define mln_is_lowq(T) typename mln::trait::is_lowq< T >::ret
@@ -50,10 +50,10 @@
// FIXME: Doc!
- template <typename I>
+ template <typename T>
struct is_lowq
{
- typedef typename metal::bool_<( mln_card(mln_value(I)) != 0 )>::type ret;
+ typedef typename metal::bool_<( mln_card(T) != 0 )>::type ret;
};
Index: mln/core/fimage.hh
--- mln/core/fimage.hh (revision 1035)
+++ mln/core/fimage.hh (working copy)
@@ -63,7 +63,7 @@
typedef void lvalue; // FIXME
/// Value set associated type.
- typedef mln::value::set_<mln_result(F)> vset;
+ typedef mln::value::set<mln_result(F)> vset;
/// Constructor.
@@ -156,7 +156,7 @@
}
template <typename F, typename S>
- const mln::value::set_<mln_result(F)>&
+ const mln::value::set<mln_result(F)>&
fimage<F,S>::values() const
{
return vset::the();
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1035)
+++ mln/core/image2d_b.hh (working copy)
@@ -119,7 +119,7 @@
};
/// Value_Set associated type.
- typedef mln::value::set_<T> vset;
+ typedef mln::value::set<T> vset;
/// Constructor without argument.
Index: mln/level/naive/median.hh
--- mln/level/naive/median.hh (revision 1035)
+++ mln/level/naive/median.hh (working copy)
@@ -78,7 +78,7 @@
{
mln_piter(I) p(input.domain());
mln_qiter(W) q(win, p);
- accu::median_on<mln_value(I)> med;
+ accu::median<mln_vset(I)> med(input.values());
for_all(p)
{
Index: mln/level/was.median.hh
--- mln/level/was.median.hh (revision 1035)
+++ mln/level/was.median.hh (working copy)
@@ -72,7 +72,7 @@
q_bp(win_bkd_plus, p), q_bm(win_bkd_minus, p),
q_top(win_top, p), q_bot(win_bot, p);
- accu::median_on<mln_value(I)> med;
+ accu::median<mln_vset(I)> med(input.values());
// initialization
@@ -146,7 +146,7 @@
int& row = p.row();
int& col = p.col();
- accu::median_on<mln_value(I)> med;
+ accu::median<mln_vset(I)> med(input.values());
for (row = input.min_row(); row <= max_row; ++row)
{
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 1035)
+++ mln/level/fast_median.hh (working copy)
@@ -84,7 +84,7 @@
win_bot = win - (win + up),
win_top = (win + up) - win;
- accu::median_on<mln_value(I)> med;
+ accu::median<mln_vset(I)> med(input.values());
// initialization
Index: mln/level/transform.hh
--- mln/level/transform.hh (revision 1035)
+++ mln/level/transform.hh (working copy)
@@ -120,7 +120,7 @@
void transform(const Image<I>& input, const Function_v2v<F>& f, Image<O>& output)
{
mln_precondition(exact(output).domain() >= exact(input).domain());
- impl::transform(mln_is_lowq(I)(),
+ impl::transform(mln_is_value_lowq(I)(),
exact(input), exact(f), exact(output));
}
Index: mln/level/median.hh
--- mln/level/median.hh (revision 1035)
+++ mln/level/median.hh (working copy)
@@ -80,10 +80,10 @@
// aux data
+ accu::median<mln_vset(I)> med;
mln_point(I) p;
window2d win_fp, win_fm, win_bp, win_bm, win_dp, win_dm;
mln_qiter(W) q_fp, q_fm, q_bp, q_bm, q_dp, q_dm;
- accu::median_on<mln_value(I)> med;
// ctor
@@ -94,6 +94,7 @@
win(exact(win_)),
output(exact(output_)),
// aux data
+ med(input.values()),
p(),
win_fp(win - (win + left)), win_fm((win + left) - win),
win_bp(win - (win + right)), win_bm((win + right) - win),
@@ -171,7 +172,7 @@
coord& row = p.row();
coord& col = p.col();
- accu::median_on<mln_value(I)> med;
+ accu::median<mln_vset(I)> med(input.values());
for (row = input.min_row(); row <= max_row; ++row)
{
Index: mln/accu/histo.hh
--- mln/accu/histo.hh (revision 1035)
+++ mln/accu/histo.hh (working copy)
@@ -51,9 +51,10 @@
/*! Generic histogram class over a value set with type \c S.
*/
template <typename S>
- struct histo_on_set : public Accumulator< histo_on_set<S> >
+ struct histo : public Accumulator< histo<S> >
{
- histo_on_set(const Value_Set<S>& s);
+ histo(const Value_Set<S>& s);
+ histo();
typedef mln_value(S) value;
@@ -79,41 +80,32 @@
template <typename S>
- std::ostream& operator<<(std::ostream& ostr, const histo_on_set<S>& h);
-
-
-
-
- /*! Generic histogram class over the set of values of type \c T.
- *
- * \todo Inheritance is badly formed since this concrete class
- * derives from another concrete class.
- */
- template <typename T>
- struct histo_on_type : public histo_on_set< value::set_<T> >
- {
- histo_on_type();
- };
+ std::ostream& operator<<(std::ostream& ostr, const histo<S>& h);
# ifndef MLN_INCLUDE_ONLY
-
- // histo_on_set<S>
-
template <typename S>
- histo_on_set<S>::histo_on_set(const Value_Set<S>& s)
+ histo<S>::histo(const Value_Set<S>& s)
: s_(exact(s)),
- h_(exact(s).nvalues(), 0),
+ h_(s_.nvalues(), 0),
+ sum_(0)
+ {
+ }
+
+ template <typename S>
+ histo<S>::histo()
+ : s_(S::the()),
+ h_(s_.nvalues(), 0),
sum_(0)
{
}
template <typename S>
void
- histo_on_set<S>::take(const value& v)
+ histo<S>::take(const value& v)
{
++h_[s_.index_of(v)];
++sum_;
@@ -121,7 +113,7 @@
template <typename S>
void
- histo_on_set<S>::untake(const value& v)
+ histo<S>::untake(const value& v)
{
mln_precondition(h_[s_.index_of(v)] > 0);
mln_precondition(sum_ > 0);
@@ -131,7 +123,7 @@
template <typename S>
void
- histo_on_set<S>::init()
+ histo<S>::init()
{
std::fill(h_.begin(), h_.end(), 0);
sum_ = 0;
@@ -139,14 +131,14 @@
template <typename S>
std::size_t
- histo_on_set<S>::operator()(const value& v) const
+ histo<S>::operator()(const value& v) const
{
return h_[s_.index_of(v)];
}
template <typename S>
std::size_t
- histo_on_set<S>::operator[](std::size_t i) const
+ histo<S>::operator[](std::size_t i) const
{
mln_precondition(i < s_.nvalues());
return h_[i];
@@ -154,54 +146,42 @@
template <typename S>
std::size_t
- histo_on_set<S>::nvalues() const
+ histo<S>::nvalues() const
{
return s_.nvalues();
}
template <typename S>
std::size_t
- histo_on_set<S>::sum() const
+ histo<S>::sum() const
{
return sum_;
}
template <typename S>
const std::vector<std::size_t>&
- histo_on_set<S>::vec() const
+ histo<S>::vec() const
{
return h_;
}
template <typename S>
const S&
- histo_on_set<S>::vset() const
+ histo<S>::vset() const
{
return s_;
}
template <typename S>
- std::ostream& operator<<(std::ostream& ostr, const histo_on_set<S>& h)
+ std::ostream& operator<<(std::ostream& ostr, const histo<S>& h)
{
mln_viter(S) v(h.vset());
for_all(v)
if (h(v) != 0)
ostr << v << ':' << h(v) << ' ';
- ostr << std::endl;
return ostr;
}
-
- // histo_on_type<T>
-
- template <typename T>
- histo_on_type<T>::histo_on_type()
- : histo_on_set< value::set_<T> >(value::set_<T>::the())
- {
- }
-
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
Index: mln/accu/median.hh
--- mln/accu/median.hh (revision 1035)
+++ mln/accu/median.hh (working copy)
@@ -53,6 +53,7 @@
typedef mln_value(S) value;
median(const Value_Set<S>& s);
+ median();
void take(const value& v);
void untake(const value& v);
@@ -63,20 +64,11 @@
operator mln_value(S) () const;
value to_value() const;
- const histo_on_set<S>& histo() const;
-
- // FIXME: remove
- void debug__() const
- {
- std::cout << " i = " << i_
- << " v = " << v_
- << " s = " << sum_minus_ << " ; " << h_[i_] << " ; " << sum_plus_ << " = " << h_.sum()
- << std::endl;
- }
+ const accu::histo<S>& histo() const;
protected:
- mutable histo_on_set<S> h_;
+ mutable accu::histo<S> h_;
const S& s_; // derived from h_
mutable std::size_t sum_minus_, sum_plus_;
@@ -92,24 +84,8 @@
};
- /*! Generic median class over the set of values of type \c T.
- *
- * \todo Inheritance is badly formed since this concrete class
- * derives from another concrete class.
- */
- template <typename T>
- struct median_on : public median< value::set_<T> >
- {
- median_on()
- : median< value::set_<T> >(value::set_<T>::the())
- {
- }
- };
-
-
# ifndef MLN_INCLUDE_ONLY
-
template <typename S>
median<S>::median(const Value_Set<S>& s)
: h_(s),
@@ -118,6 +94,13 @@
init();
}
+ template <typename S>
+ median<S>::median()
+ : h_(),
+ s_(h_.vset())
+ {
+ init();
+ }
template <typename S>
void
@@ -134,7 +117,6 @@
valid_ = false;
}
-
template <typename S>
void
median<S>::untake(const value& v)
@@ -151,7 +133,6 @@
valid_ = false;
}
-
template <typename S>
void
median<S>::update_() const
@@ -177,7 +158,6 @@
}
}
-
template <typename S>
void
median<S>::go_minus_() const
@@ -194,7 +174,6 @@
v_ = s_[i_];
}
-
template <typename S>
void
median<S>::go_plus_() const
@@ -211,7 +190,6 @@
v_ = s_[i_];
}
-
template <typename S>
void
median<S>::init()
@@ -224,7 +202,6 @@
valid_ = true;
}
-
template <typename S>
median<S>::operator mln_value(S) () const
{
@@ -241,7 +218,7 @@
}
template <typename S>
- const histo_on_set<S>&
+ const accu::histo<S>&
median<S>::histo() const
{
return h_;
@@ -250,11 +227,9 @@
template <typename S>
std::ostream& operator<<(std::ostream& ostr, const median<S>& m)
{
- m.debug__();
return ostr << m.to_value();
}
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
Index: mln/accu/median_alt.hh
--- mln/accu/median_alt.hh (revision 1035)
+++ mln/accu/median_alt.hh (working copy)
@@ -86,10 +86,10 @@
template <typename T>
- struct median_alt_on : public median_alt< value::set_<T> >
+ struct median_alt_on : public median_alt< value::set<T> >
{
median_alt_on()
- : median_alt< value::set_<T> >(value::set_<T>::the())
+ : median_alt< value::set<T> >(value::set<T>::the())
{
}
};
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1035)
+++ mln/value/props.hh (working copy)
@@ -65,19 +65,14 @@
{
- /*! Class that defines the properties of the value type \c T.
+ /*! Class that defines the properties (by default) of any value
+ * type \c T.
*/
template <typename T>
struct props
{
- /// Minimum value for type \c T.
- static const T min;
-
- /// Maximum value for type \c T.
- static const T max;
-
- /// Number of values for type \c T.
- static const std::size_t card;
+ typedef data_kind kind;
+ static const std::size_t card = 0;
};
Index: mln/value/cast.hh
--- mln/value/cast.hh (revision 1035)
+++ mln/value/cast.hh (working copy)
@@ -47,7 +47,7 @@
*
*/
template <typename T, typename I>
- struct cast_image : public internal::image_base_< mln_pset(I), cast_image<T,I> >
+ struct cast_image : public mln::internal::image_base_< mln_pset(I), cast_image<T,I> >
{
/// Point_Site associated type.
typedef mln_psite(I) psite;
@@ -65,7 +65,7 @@
typedef void lvalue; // FIXME
/// Value set associated type.
- typedef mln::value::set_<T> vset;
+ typedef mln::value::set<T> vset;
/// Constructor.
@@ -159,7 +159,7 @@
}
template <typename T, typename I>
- const mln::value::set_<T>&
+ const mln::value::set<T>&
cast_image<T,I>::values() const
{
return vset::the();
Index: mln/value/set.hh
--- mln/value/set.hh (revision 1035)
+++ mln/value/set.hh (working copy)
@@ -33,8 +33,8 @@
* \brief Define some basic sets of values from value types.
*/
-# include <mln/core/concept/value_set.hh>
-# include <mln/value/props.hh>
+# include <mln/value/internal/iterable_set.hh>
+# include <mln/core/trait/is_lowq.hh>
namespace mln
@@ -43,41 +43,41 @@
namespace value
{
- // Fwd decls.
- template <typename S> struct fwd_viter_;
- template <typename S> struct bkd_viter_;
+ // Fwd decl.
+ template <typename T> struct set;
- /*! Class that defines the set of values of type \c T.
- *
- * This is an exhaustive value set over \c T.
- */
- template <typename T>
- struct set_ : public Value_Set< set_<T> >
+
+ namespace internal
{
- /// Value associated type.
- typedef T value;
- /// Forward Value_Iterator associated type.
- typedef fwd_viter_< set_<T> > fwd_viter;
+ template <typename T, typename lowq = metal::false_ >
+ struct run_set_selector_ // no inheritance
+ {};
- /// Backward Value_Iterator associated type.
- typedef bkd_viter_< set_<T> > bkd_viter;
+ template <typename T>
+ struct run_set_selector_< T, metal::true_ > // lowq so iterable
+ :
+ public iterable_set< T, mln::value::set<T> >
+ {};
- /// Test if \p v belongs to this set: always true!
- bool has(const T& v) const;
+ template <typename T>
+ struct set_selector_ : public run_set_selector_< T, mln_is_lowq(T) >
+ {};
- /// Give the \p i-th value.
- T operator[](std::size_t i) const;
+ } // end of namespace mln::value::internal
- /// Give the index of value \p v in this set.
- std::size_t index_of(const T& v) const;
- /// Give the number of values.
- std::size_t nvalues() const;
+ /*! Class that defines the set of values of type \c T.
+ *
+ * This is the exhaustive set of values obtainable from type \c T.
+ */
+ template <typename T>
+ struct set : public internal::set_selector_<T>
+ {
/// Return a singleton.
- static const set_<T>& the();
+ static const set<T>& the();
};
@@ -85,39 +85,10 @@
# ifndef MLN_INCLUDE_ONLY
template <typename T>
- bool
- set_<T>::has(const T&) const
- {
- return true;
- }
-
- template <typename T>
- T
- set_<T>::operator[](std::size_t i) const
+ const set<T>&
+ set<T>::the()
{
- mln_precondition(i < nvalues());
- return mln_min(T) + i;
- }
-
- template <typename T>
- std::size_t
- set_<T>::index_of(const T& v) const
- {
- return v - mln_min(T);
- }
-
- template <typename T>
- std::size_t
- set_<T>::nvalues() const
- {
- return mln_card(T);
- }
-
- template <typename T>
- const set_<T>&
- set_<T>::the()
- {
- static set_<T> the_;
+ static set<T> the_;
return the_;
}
@@ -125,11 +96,7 @@
} // end of namespace mln::value
-
} // end of namespace mln
-# include <mln/value/viter.hh>
-
-
#endif // ! MLN_VALUE_SET_HH
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1035)
+++ mln/value/int_u.hh (working copy)
@@ -33,10 +33,10 @@
* \brief Define a generic class for unsigned integers.
*/
-# include <mln/core/concept/value.hh>
# include <mln/metal/math.hh>
# include <mln/value/internal/value_like.hh>
# include <mln/value/props.hh>
+# include <mln/value/set.hh>
namespace mln
@@ -89,15 +89,11 @@
};
- // Fwd decl.
- template <typename T> struct vset_;
-
-
/// Alias for unsigned 8bit integers.
typedef int_u_<8> int_u8;
/// Alias for the set of unsigned 8bit integers.
- typedef vset_<int_u8> int_u8_set;
+ typedef set<int_u8> int_u8_set;
Index: mln/value/internal/iterable_set.hh
--- mln/value/internal/iterable_set.hh (revision 1035)
+++ mln/value/internal/iterable_set.hh (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_SET_HH
-# define MLN_VALUE_SET_HH
+#ifndef MLN_VALUE_INTERNAL_ITERABLE_SET_HH
+# define MLN_VALUE_INTERNAL_ITERABLE_SET_HH
-/*! \file mln/value/set.hh
+/*! \file mln/value/internal/iterable_set.hh
*
- * \brief Define some basic sets of values from value types.
+ * \brief Define the iterable value set derived from a type.
*/
# include <mln/core/concept/value_set.hh>
@@ -48,83 +48,76 @@
template <typename S> struct bkd_viter_;
+ namespace internal
+ {
+
/*! Class that defines the set of values of type \c T.
*
- * This is an exhaustive value set over \c T.
+ * This is the exhaustive iterable_set of values obtainable from type \c T.
*/
- template <typename T>
- struct set_ : public Value_Set< set_<T> >
+ template <typename T, typename E>
+ struct iterable_set : public Value_Set<E>
{
/// Value associated type.
typedef T value;
/// Forward Value_Iterator associated type.
- typedef fwd_viter_< set_<T> > fwd_viter;
+ typedef fwd_viter_<E> fwd_viter;
/// Backward Value_Iterator associated type.
- typedef bkd_viter_< set_<T> > bkd_viter;
+ typedef bkd_viter_<E> bkd_viter;
- /// Test if \p v belongs to this set: always true!
+ /// Test if \p v belongs to this iterable_set: always true!
bool has(const T& v) const;
/// Give the \p i-th value.
T operator[](std::size_t i) const;
- /// Give the index of value \p v in this set.
+ /// Give the index of value \p v in this iterable_set.
std::size_t index_of(const T& v) const;
/// Give the number of values.
std::size_t nvalues() const;
-
- /// Return a singleton.
- static const set_<T>& the();
};
# ifndef MLN_INCLUDE_ONLY
- template <typename T>
+ template <typename T, typename E>
bool
- set_<T>::has(const T&) const
+ iterable_set<T,E>::has(const T&) const
{
return true;
}
- template <typename T>
+ template <typename T, typename E>
T
- set_<T>::operator[](std::size_t i) const
+ iterable_set<T,E>::operator[](std::size_t i) const
{
mln_precondition(i < nvalues());
return mln_min(T) + i;
}
- template <typename T>
+ template <typename T, typename E>
std::size_t
- set_<T>::index_of(const T& v) const
+ iterable_set<T,E>::index_of(const T& v) const
{
return v - mln_min(T);
}
- template <typename T>
+ template <typename T, typename E>
std::size_t
- set_<T>::nvalues() const
+ iterable_set<T,E>::nvalues() const
{
return mln_card(T);
}
- template <typename T>
- const set_<T>&
- set_<T>::the()
- {
- static set_<T> the_;
- return the_;
- }
-
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::value
+ } // end of namespace mln::value::internal
+ } // end of namespace mln::value
} // end of namespace mln
@@ -132,4 +125,4 @@
# include <mln/value/viter.hh>
-#endif // ! MLN_VALUE_SET_HH
+#endif // ! MLN_VALUE_INTERNAL_ITERABLE_SET_HH
1
0