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
October 2007
- 8 participants
- 229 discussions
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-03 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Fix image_if_interval. Does NOT compile yet !.
* mln/core/image_if_interval.hh: Update.
* tests/image_if_interval.cc: New.
---
mln/core/image_if_interval.hh | 116 ++++++++++++++++++++++++++++--------------
tests/image_if_interval.cc | 48 +++++++++++++++++
2 files changed, 128 insertions(+), 36 deletions(-)
Index: trunk/milena/tests/image_if_interval.cc
===================================================================
--- trunk/milena/tests/image_if_interval.cc (revision 0)
+++ trunk/milena/tests/image_if_interval.cc (revision 1228)
@@ -0,0 +1,48 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/image_if_value.cc
+ *
+ * \brief Tests on mln::image_if_value.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image_if_interval.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(3, 3);
+ debug::iota(ima);
+ debug::println(ima);
+ debug::println(ima | value::interval(4, 7) );
+}
Index: trunk/milena/mln/core/image_if_interval.hh
===================================================================
--- trunk/milena/mln/core/image_if_interval.hh (revision 1227)
+++ trunk/milena/mln/core/image_if_interval.hh (revision 1228)
@@ -34,18 +34,62 @@
*/
# include <mln/core/internal/image_if_base.hh>
+# include <mln/metal/unconst.hh>
+# include <mln/value/interval.hh>
+
+
+# define F fun::and_p2b_expr_< \
+ fun::geq_p2b_expr_< \
+ pw::value_<I>, \
+ pw::cst_<mln_value(I)> >, \
+ fun::leq_p2b_expr_< \
+ pw::value_<I>, \
+ pw::cst_<mln_value(I)> > > >
+
+# define Super mln::internal::image_if_base_< I, F, image_if_interval<I> >
+
namespace mln
{
+ // Fwd decl.
+ template <typename I> struct image_if_interval;
+
+
+ // internal::data_.
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< image_if_interval<I> > : data_< Super >
+ {
+ data_(I& ima, const F& f);
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct image_< image_if_interval<I> > : trait::image_< Super >
+ {
+ };
+
+ } // end of namespace mln::trait
+
+
+
/*! \brief An image class FIXME.
*
*/
- template <typename I, typename F>
- struct image_if_interval : public internal::image_if_base< I, F >
+ template <typename I>
+ struct image_if_interval : public Super
{
/// Skeleton.
- typedef image_if_interval< tag::image_<I>, tag::function_<F> > skeleton;
+ typedef image_if_interval< tag::image_<I> > skeleton;
/// Constructor from an image \p ima and a predicate \p f.
image_if_interval(I& ima, const F& f);
@@ -54,7 +98,7 @@
image_if_interval();
/// Const promotion via convertion.
- operator image_if_interval<const I, F>() const;
+ operator image_if_interval<const I>() const;
};
// Operators.
@@ -62,69 +106,66 @@
// Image | [from, to].
template <typename I>
- image_if_interval< I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<I>
operator | (Image<I>& ima, const value::interval_<mln_value(I)>& vv);
template <typename I>
- image_if_interval< const I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<const I>
operator | (const Image<I>& ima, const value::interval_<mln_value(I)>& vv);
# ifndef MLN_INCLUDE_ONLY
- // image_if_interval<I,F>
+ // image_if_interval<I>
- template <typename I, typename F>
- image_if_interval<I,F>::image_if_interval()
+ template <typename I>
+ image_if_interval<I>::image_if_interval()
{
}
- template <typename I, typename F>
- image_if_interval<I,F>::image_if_interval(I& ima, const F& f)
+ template <typename I>
+ image_if_interval<I>::image_if_interval(I& ima, const F& f)
{
this->init_(ima, f);
}
- template <typename I, typename F>
- image_if_interval<I,F>::operator image_if_interval<const I, F>() const
+ template <typename I>
+ image_if_interval<I>::operator image_if_interval<const I, F>() const
{
- image_if_interval<const I, F> tmp(this->data_->ima_, this->data_->pset_);
+ image_if_interval<const I> tmp(this->data_->ima_, this->data_->pset_);
return tmp;
}
+ // internal::data_< image_if_interval<I> >
+
+ namespace internal
+ {
+
+ template <typename I>
+ data_< image_if_value<I> >::data_(I& ima, const F& f)
+ : data_< Super >(ima, f)
+ {
+ }
+
+ } // end of namespace mln::internal
+
// Operators.
template <typename I>
- image_if_interval< I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<I>
operator | (Image<I>& ima, const value::interval_<mln_value(I)>& vv)
{
- return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
- (pw::value(ima) <= pw::cst(vv.to)) );
+ image_if_interval<I> tmp(exact(ima), vv);
+ return tmp;
}
template <typename I>
- image_if_interval< const I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
+ image_if_interval<const I>
operator | (const Image<I>& ima, const value::interval_<mln_value(I)>& vv)
{
- return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
- (pw::value(ima) <= pw::cst(vv.to)) );
+ image_if_interval<const I> tmp(exact(ima), vv);
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -132,4 +173,7 @@
} // end of namespace mln
+# undef Super
+# undef F
+
#endif // ! MLN_CORE_IMAGE_IF_INTERVAL_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-03 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update labeling_algo.
* labeling_algo.cc,
* labeling_algo.hh: Update.
---
labeling_algo.cc | 24 ++++++++++++--------
labeling_algo.hh | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 78 insertions(+), 11 deletions(-)
Index: trunk/milena/sandbox/duhamel/labeling_algo.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1226)
+++ trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1227)
@@ -35,6 +35,7 @@
# include <mln/core/neighb2d.hh>
# include <mln/value/int_u8.hh>
# include <mln/level/fill.hh>
+# include <mln/level/stretch.hh>
# include <mln/level/saturate.hh>
# include <mln/border/fill.hh>
# include <mln/io/pbm/load.hh>
@@ -51,32 +52,37 @@
using value::int_u8;
// image2d_b<bool> in = io::pbm::load("../../img/toto.pbm");
- image2d_b<bool> in = io::pbm::load("toto.pbm");
+ image2d_b<bool> in = io::pbm::load("../../img/toto.pbm");
- image2d_b<unsigned> lab(in.domain());
- image2d_b<unsigned> inte(in.domain());
+ image2d_b<int_u8> lab(in.domain());
+ image2d_b<int_u8> inte(in.domain());
image2d_b<int_u8> out(in.domain());
unsigned n;
- labeling::foreground(in, c4(), lab, n);
+ labeling::foreground(in, c8(), lab, n);
std::cout << "number of labels = " << n << std::endl;
std::vector<int_u8> vec;
image2d_b<int> input(in.domain());
+ // debug::println (in | make::box2d (100,100));
level::fill(input, lab);
+ lab(make::point2d (0,0)) = 0;
inte = make_algo(lab, c4 ());
border::fill (inte, 0);
image2d_b<int_u8> inte2(inte.domain());
- // level::fill(inte2, inte);
+ level::stretch (inte, inte2);
- level::saturate(inte, 1, 255, inte2);
- io::pgm::save(inte2, "inte.pgm");
- // debug::println_with_border(inte2);
+ io::pgm::save(inte, "inte.pgm");
+ io::pgm::save(inte2, "inte2.pgm");
- mesh_p<point2d> m = make::graph_with_no_border(inte2, c4());
+ debug::println(lab | make::box2d (30,30) );
+
+ // mesh_p<point2d> m = make::graph_with_no_border(inte, c4());
+
+ mesh_p<point2d> m = make::voronoi(inte, lab, c4());
std::cout << "OK" << std::endl;
draw::mesh (out, m, 255, 128);
Index: trunk/milena/sandbox/duhamel/labeling_algo.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1226)
+++ trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1227)
@@ -89,10 +89,71 @@
m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
}
- for (unsigned i = min; i <= max; ++i)
+ for (unsigned i = 0; i < nb; ++i)
{
gr.add_node ();
- v[i - min] = make::point2d ((unsigned)tab_mean[i].to_result ()[0],
+ v[i] = make::point2d ((unsigned)tab_mean[i].to_result ()[0],
+ (unsigned)tab_mean[i].to_result ()[1]);
+ }
+
+ typename std::map<std::pair<V, V>, bool>::const_iterator it = m.begin ();
+ for (; it != m.end (); ++it)
+ gr.add_edge((*it).first.first, (*it).first.second);
+
+ mesh_p<P> res(gr, v);
+ return res;
+ }
+
+
+ template <typename I, typename N>
+ mesh_p<mln_psite(I)>
+ voronoi (Image<I>& ima_,
+ Image<I>& orig_,
+ const Neighborhood<N>& nbh)
+ {
+ typedef metal::vec<2,float> X;
+ typedef mln_value(I) V;
+ typedef mln_psite(I) P;
+
+ I& ima = exact(ima_);
+ I& orig = exact(orig_);
+ util::graph<void> gr;
+ V min, max;
+ estim::min_max (ima, min, max);
+ unsigned nb = max - min + 1;
+ std::vector<P> v(nb);
+ std::vector< accu::mean_< X > > tab_mean (nb);
+ std::map<std::pair<V, V>, bool> m;
+
+ {
+ mln_piter(I) p(orig.domain());
+
+ for_all(p)
+ {
+ if (orig(p) != 0)
+ {
+ X x = mln_point(I)(p);
+ tab_mean[orig(p) - min].take(x);
+ }
+ }
+ }
+
+ {
+ mln_piter(I) p(ima.domain());
+ mln_niter(N) n(nbh, p);
+
+ for_all(p)
+ {
+ for_all (n) if (ima.has(n))
+ if (ima(p) != ima(n))
+ m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
+ }
+ }
+
+ for (unsigned i = 0; i < nb; ++i)
+ {
+ gr.add_node ();
+ v[i] = make::point2d ((unsigned)tab_mean[i].to_result ()[0],
(unsigned)tab_mean[i].to_result ()[1]);
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-03 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add tests and clean gray values.
* mln/value/gray.hh,
* mln/value/graylevel.hh: Clean useless operators.
* tests/value_gray.cc: Add tests.
* tests/value_int_u.cc: New, add tests.
* tests/value_int_u8.cc: Add tests.
---
mln/value/gray.hh | 12 -----
mln/value/graylevel.hh | 19 --------
tests/value_gray.cc | 2
tests/value_int_u.cc | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/value_int_u8.cc | 10 +---
5 files changed, 110 insertions(+), 37 deletions(-)
Index: trunk/milena/tests/value_int_u.cc
===================================================================
--- trunk/milena/tests/value_int_u.cc (revision 0)
+++ trunk/milena/tests/value_int_u.cc (revision 1226)
@@ -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.
+
+/*! \file tests/value_int_u8.cc
+ *
+ * \brief Tests on mln::value::int_u8.
+ */
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/float01_8.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_s8;
+ using value::int_u16;
+ using value::float01_8;
+
+ {
+ // Operations on int_u<n>
+ int_u8 i = 128;
+ int_u16 j = 42;
+ int_s8 k = 42;
+ float01_8 x;
+
+ (j = j + i) = i + j;
+ assert(j == (128 + 42));
+
+ (k = j - i) = i - j;
+ assert(k == (-42));
+
+ j = 2;
+ (j = j * i) = i * j;
+ assert(j == (2 * 128));
+
+ (x = (j / i) / ((j / i) + 0.1))
+ = (i / j) / ((i / j) + 0.1);
+
+// std::cout << i + i << std::endl;
+// float01_8 f = i / 200.5;
+// std::cout << x << std::endl;
+ }
+
+ {
+ // Operations on int_u<n> and int / float
+ int_u16 j = 42;
+ int_s8 k = 42;
+ float x;
+
+ // int
+ (k = j - 123) = 123 - j;
+ (j = j + 123) = 123 + j;
+ (j = j * 4) = 4 * j;
+
+ (j = j / 4) = 4 / j;
+
+ // float
+ x = (j / 4.5 * 3.4 + 3.5 - 5.6) / 0.0234;
+ }
+
+
+ {
+ // Operations on int_u<n> and float01_8
+ int_u16 j = 42;
+ float01_8 x = 0.456;
+
+ x = x / j;
+ assert(x < 0 && x < 1);
+
+ x = x * j;
+ assert(x < 0 && x < 1);
+
+ x = x * j;
+ assert(x < 0 && x < 1);
+
+ }
+}
Index: trunk/milena/tests/value_gray.cc
===================================================================
--- trunk/milena/tests/value_gray.cc (revision 1225)
+++ trunk/milena/tests/value_gray.cc (revision 1226)
@@ -41,4 +41,6 @@
c = (a * 2) / 2;
assert(c == white);
+
+ c = c / 6;
}
Index: trunk/milena/tests/value_int_u8.cc
===================================================================
--- trunk/milena/tests/value_int_u8.cc (revision 1225)
+++ trunk/milena/tests/value_int_u8.cc (revision 1226)
@@ -31,13 +31,14 @@
*/
#include <mln/value/int_u8.hh>
-
-
+#include <mln/value/int_u16.hh>
+#include <mln/value/float01_8.hh>
int main()
{
using namespace mln;
using value::int_u8;
+ using value::float01_8;
{
int_u8 i = 3;
@@ -48,9 +49,4 @@
mln_assertion(-i == -2);
mln_assertion(-3 * i == -6);
}
-
- {
- int_u8 i = 128;
- std::cout << i + i << std::endl;
- }
}
Index: trunk/milena/mln/value/graylevel.hh
===================================================================
--- trunk/milena/mln/value/graylevel.hh (revision 1225)
+++ trunk/milena/mln/value/graylevel.hh (revision 1226)
@@ -71,15 +71,10 @@
/// Access to std type.
enc value() const;
- /// Op encoding_t.
- operator enc() const;
-
/// Op<.
bool operator<(const graylevel<n>& rhs) const;
graylevel<n>& operator=(const int val);
- /// Op==.
- // bool operator==(const graylevel<n>& rhs) const;
protected:
enc val_;
@@ -119,14 +114,6 @@
template <unsigned n, unsigned m>
gray operator-(const graylevel<n>& lhs, const graylevel<m>& rhs);
- template <unsigned n>
- gray operator*(int s, const graylevel<n>& rhs);
-
- template <unsigned n>
- gray operator*(const graylevel<n>& lhs, int s);
-
- template <unsigned n>
- gray operator/(const graylevel<n>& lhs, int s);
@@ -165,12 +152,6 @@
}
template <unsigned n>
- graylevel<n>::operator typename graylevel<n>::enc() const
- {
- return val_;
- }
-
- template <unsigned n>
bool graylevel<n>::operator<(const graylevel<n>& rhs) const
{
return val_ < rhs.val_;
Index: trunk/milena/mln/value/gray.hh
===================================================================
--- trunk/milena/mln/value/gray.hh (revision 1225)
+++ trunk/milena/mln/value/gray.hh (revision 1226)
@@ -142,13 +142,12 @@
template <unsigned N>
gray operator/(const graylevel<N>& lhs, int s)
{
+ std::cout << "div div " << s << std::endl;
mln_precondition(s > 0);
gray tmp(N, lhs.value() / s);
return tmp;
}
-
-
// Gray.
gray::gray()
@@ -338,15 +337,6 @@
return tmp;
}
-// template <unsigned N>
-// graylevel<N>&
-// graylevel<N>::operator=(const gray& g)
-// {
-// mln_precondition(g.nbits() == N);
-// assert(g.value() < internal::two_pow_(N));
-// this->val = g.value(); // FIXME: Add static_cast.
-// }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::value
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-03 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add queue_p_fast.
* queue_p_fast.hh: New queue with vector.
Update
* labeling_algo.cc,
* labeling_algo.hh: Update.
---
labeling_algo.cc | 7 -
labeling_algo.hh | 100 +++----------------
queue_p_fast.hh | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 301 insertions(+), 82 deletions(-)
Index: trunk/milena/sandbox/duhamel/labeling_algo.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1224)
+++ trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1225)
@@ -42,6 +42,7 @@
# include <mln/labeling/foreground.hh>
# include <mln/debug/println.hh>
# include <mln/debug/println_with_border.hh>
+# include <mln/draw/mesh.hh>
# include "labeling_algo.hh"
int main()
@@ -69,14 +70,16 @@
image2d_b<int_u8> inte2(inte.domain());
+ // level::fill(inte2, inte);
+
level::saturate(inte, 1, 255, inte2);
io::pgm::save(inte2, "inte.pgm");
- debug::println_with_border(inte2);
+ // debug::println_with_border(inte2);
mesh_p<point2d> m = make::graph_with_no_border(inte2, c4());
std::cout << "OK" << std::endl;
draw::mesh (out, m, 255, 128);
- debug::println(out);
+ // debug::println(out);
io::pgm::save(out, "out.pgm");
}
Index: trunk/milena/sandbox/duhamel/queue_p_fast.hh
===================================================================
--- trunk/milena/sandbox/duhamel/queue_p_fast.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/queue_p_fast.hh (revision 1225)
@@ -0,0 +1,276 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_QUEUE_P_FAST_HH
+# define MLN_CORE_QUEUE_P_FAST_HH
+
+/*! \file mln/core/queue_p_fast.hh
+ *
+ * \brief Definition of a point set class based on std::deque.
+ */
+
+# include <vector>
+# include <deque>
+# include <algorithm>
+# include <iterator>
+
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/vec_p_piter.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct vec_p_fwd_piter_;
+ template <typename P> struct vec_p_bkd_piter_;
+
+
+ /*! \brief Point queue class (based on std::deque).
+ *
+ * This is a mathematical set of points (unique insertion).
+ *
+ * \todo Make it work with P being a Point_Site.
+ * \todo Add a parameter flag to choose another policy for "push"
+ * (i.e., no-op if multiple or allow multiple insertions).
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints() when this container is multiple.
+ */
+ template <typename P>
+ class queue_p_fast : public internal::point_set_base_< P, queue_p_fast<P> >
+ {
+ public:
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ queue_p_fast();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Test if queue is empty or not.
+ bool empty() const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Push force a point \p p in the queue.
+ queue_p_fast<P>& push_force(const P& p);
+
+ /// Push a point \p p in the queue.
+ queue_p_fast<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::vector<P> q_;
+ std::size_t begin_;
+ std::size_t end_;
+
+ mutable std::vector<P> vect_;
+ mutable bool vect_needs_update_;
+ void vect_update_() const;
+
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+ void bb_update_() const;
+
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ queue_p_fast<P>::queue_p_fast()
+ {
+ // vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ begin_ = 0;
+ end_ = 0;
+ }
+
+ template <typename P>
+ void
+ queue_p_fast<P>::vect_update_() const
+ {
+ vect_.clear();
+ vect_.reserve(q_.size());
+ std::copy(q_.begin(), q_.end(),
+ std::back_inserter(vect_));
+ vect_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ queue_p_fast<P>::bb_update_() const
+ {
+ bb_.init();
+ for (std::size_t i = this->begin_; i < this->end_; ++i)
+ bb_.take(q_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ queue_p_fast<P>::has(const P& p) const
+ {
+ for (unsigned i = this->begin_; i < this->end_; ++i)
+ if (q_[i] == p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ bool
+ queue_p_fast<P>::empty() const
+ {
+ return (this->begin_ == this->end_);
+ }
+
+ template <typename P>
+ std::size_t
+ queue_p_fast<P>::npoints() const
+ {
+ mln_precondition(this->end_ >= this->begin_);
+ return (this->end_ - this->begin_);
+ }
+
+ template <typename P>
+ const box_<P>&
+ queue_p_fast<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ bb_update_();
+ return bb_.to_result();
+ }
+
+ template <typename P>
+ queue_p_fast<P>&
+ queue_p_fast<P>::push_force(const P& p)
+ {
+ q_.push_back(p);
+ ++this->end_;
+ if (! vect_needs_update_)
+ {
+ // vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ return *this;
+ }
+
+ template <typename P>
+ queue_p_fast<P>&
+ queue_p_fast<P>::push(const P& p)
+ {
+ mln_precondition(! this->has(p));
+ // FIXME: Our choice is "error if multiple insertions"
+ return this->push_force(p);
+ }
+
+ template <typename P>
+ void
+ queue_p_fast<P>::pop()
+ {
+ ++this->begin_;
+// q_.pop_front();
+// if (! vect_needs_update_)
+// {
+// vect_needs_update_ = true;
+// bb_needs_update_ = true;
+// }
+ }
+
+ template <typename P>
+ const P&
+ queue_p_fast<P>::front() const
+ {
+ mln_precondition(! this->empty());
+ return q_[begin_];
+ }
+
+ template <typename P>
+ void
+ queue_p_fast<P>::clear()
+ {
+ this->end_ = begin_;
+// q_.clear();
+// vect_.clear();
+// vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ queue_p_fast<P>::vect() const
+ {
+ if (vect_needs_update_)
+ vect_update_();
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ queue_p_fast<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return q_[begin_ + i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_QUEUE_P_FAST_HH
Index: trunk/milena/sandbox/duhamel/labeling_algo.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1224)
+++ trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1225)
@@ -1,4 +1,5 @@
# include <mln/core/queue_p.hh>
+# include "queue_p_fast.hh"
# include <mln/core/clone.hh>
# include <mln/debug/println.hh>
@@ -11,9 +12,6 @@
#include <mln/debug/println.hh>
#include <mln/util/graph.hh>
#include <mln/core/mesh_p.hh>
-#include <mln/core/mesh_psite.hh>
-#include <mln/draw/mesh.hh>
-#include <mln/core/mesh_image.hh>
#include <mln/accu/mean.hh>
#include <mln/estim/min_max.hh>
#include <algorithm>
@@ -67,21 +65,16 @@
const Neighborhood<N>& nbh)
{
typedef metal::vec<2,float> X;
-
typedef mln_value(I) V;
typedef mln_psite(I) P;
I& ima = exact(ima_);
util::graph<void> gr;
-
V min, max;
estim::min_max (ima, min, max);
unsigned nb = max - min + 1;
std::vector<P> v(nb);
- std::vector< accu::mean_< metal::vec<2,float> > > tab_mean (nb);
-
- std::cout << "nb = " << nb << std::endl;
-
+ std::vector< accu::mean_< X > > tab_mean (nb);
std::map<std::pair<V, V>, bool> m;
mln_piter(I) p(ima.domain());
@@ -96,36 +89,16 @@
m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
}
- std::cout << "center[0] = " << tab_mean[0].to_result() << std::endl;
- std::cout << "center[1] = " << tab_mean[1].to_result() << std::endl;
-
-// /// test
-// v[0] = (make::point2d (0, 0));
-// v[1] = (make::point2d (5, 1));
-// v[2] = (make::point2d (9, 2));
-// v[3] = (make::point2d (0, 6));
-// v[4] = (make::point2d (6, 5));
-// v[5] = (make::point2d (8, 7));
-
-
for (unsigned i = min; i <= max; ++i)
{
gr.add_node ();
-// std::cout << tab_mean[i].to_result ()[0]
-// << std::endl;
- v[i - min] = make::point2d ((unsigned)tab_mean[i].to_result ()[1], (unsigned)tab_mean[i].to_result ()[0]);
+ v[i - min] = make::point2d ((unsigned)tab_mean[i].to_result ()[0],
+ (unsigned)tab_mean[i].to_result ()[1]);
}
typename std::map<std::pair<V, V>, bool>::const_iterator it = m.begin ();
for (; it != m.end (); ++it)
- {
-// gr.print_debug ();
-// std::cout << "t1 = " << (*it).first.first << std::endl
-// << "t2 = " << (*it).first.second << std::endl
-// << std::endl;
-
gr.add_edge((*it).first.first, (*it).first.second);
- }
mesh_p<P> res(gr, v);
return res;
@@ -242,59 +215,26 @@
}
}
}
- return out;
- }
-
- template <typename I, typename N>
- I
- make_algo_debug2 (Image<I>& ima_,
- const Neighborhood<N>& nbh)
- {
- I& ima = exact(ima_);
- I out = clone(ima_);
- queue_p<mln_psite(I)> q;
-
- // Init.
- {
- mln_piter(I) p(ima.domain());
- mln_niter(N) n(nbh, p);
-
- for_all(p) if (ima(p) == 0)
- for_all(n) if (ima(n) != 0)
- {
- std::cout << "push : " << p << std::endl;
- q.push(p);
- break;
- }
- std::cout << "init => q has " << q.npoints() << " points"
- << std::endl;
- }
+// // Body: alternative version.
+// {
+// while (! q.empty())
+// {
+// mln_psite(I) p = q.front();
+// q.pop();
+// if (out(p) != 0) // p has already been processed so ignore
+// continue;
- // Body.
- {
- while (! q.empty())
- {
- debug::println(out);
- mln_psite(I) p = q.front();
- std::cout << "pop : " << p << std::endl;
- q.pop();
- mln_invariant(ima(p) == 0);
+// mln_niter(N) n(nbh, p);
+// for_all(n) if (ima.has(n))
+// if (out(n) != 0)
+// out(p) = out(n);
+// else
+// q.push_force(n); // n may already be in the queue,
+// // yet we then queue again this psite
+// }
- mln_niter(N) n(nbh, p);
- for_all(n) if (ima.has(n))
- if (out(n) != 0)
- out(p) = out(n);
- else
- if (! q.has(n))
- {
- std::cout << "push : " << n << std::endl;
- q.push(n);
- }
- }
- }
return out;
}
-
} // end of mln
1
0
02 Oct '07
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-02 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Fix for accumulator from point to vec<2, float>.
* accu/sum.hh,
* core/point.hh,
* draw/mesh.hh,
* metal/vec.hh,
* trait/promote.hh,
* util/graph.hh,
* value/builtin.hh: Update.
---
accu/sum.hh | 2 +-
core/point.hh | 12 +++++++++++-
draw/mesh.hh | 1 +
metal/vec.hh | 21 +++++++++++++++++++++
trait/promote.hh | 24 ++++++++++++++++++++++++
util/graph.hh | 9 +++++----
value/builtin.hh | 1 +
7 files changed, 64 insertions(+), 6 deletions(-)
Index: trunk/milena/mln/trait/promote.hh
===================================================================
--- trunk/milena/mln/trait/promote.hh (revision 1223)
+++ trunk/milena/mln/trait/promote.hh (revision 1224)
@@ -88,6 +88,30 @@
};
template <>
+ struct set_precise_binary_< promote, float, unsigned >
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct set_precise_binary_< promote, unsigned, float >
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct set_precise_binary_< promote, unsigned, double >
+ {
+ typedef double ret;
+ };
+
+ template <>
+ struct set_precise_binary_< promote, double, unsigned >
+ {
+ typedef double ret;
+ };
+
+ template <>
struct set_precise_binary_< promote, float, double >
{
typedef double ret;
Index: trunk/milena/mln/core/point.hh
===================================================================
--- trunk/milena/mln/core/point.hh (revision 1223)
+++ trunk/milena/mln/core/point.hh (revision 1224)
@@ -122,6 +122,7 @@
/// Hook to coordinates.
operator typename internal::point_to_<M, C>::metal_vec () const;
+ operator metal::vec<M::dim, float> () const;
/// Hook to homogene coordinate.
operator typename internal::point_to_<M, C>::h_vec () const;
@@ -188,7 +189,16 @@
template <typename M, typename C>
point_<M,C>::operator typename internal::point_to_<M, C>::metal_vec () const
{
- return coord_;
+ return coord_; // FIXME: Is-it OK?
+ }
+
+ template <typename M, typename C>
+ point_<M,C>::operator metal::vec<M::dim, float> () const
+ {
+ metal::vec<dim, float> tmp;
+ for (unsigned i = 0; i < dim; ++i)
+ tmp[i] = coord_[i];
+ return tmp;
}
template <typename M, typename C>
Index: trunk/milena/mln/draw/mesh.hh
===================================================================
--- trunk/milena/mln/draw/mesh.hh (revision 1223)
+++ trunk/milena/mln/draw/mesh.hh (revision 1224)
@@ -73,6 +73,7 @@
for (unsigned i = 0; i < m.gr_.nb_node_; ++i)
exact(ima)(m.loc_[i]) = node_v;
+
}
template <typename I, typename P, typename V>
Index: trunk/milena/mln/metal/vec.hh
===================================================================
--- trunk/milena/mln/metal/vec.hh (revision 1223)
+++ trunk/milena/mln/metal/vec.hh (revision 1224)
@@ -34,6 +34,7 @@
# include <mln/core/concept/object.hh>
# include <mln/trait/all.hh>
# include <mln/value/props.hh>
+# include <mln/fun/i2v/all.hh>
// FIXME: Document.
@@ -154,6 +155,13 @@
unsigned size() const;
const vec<n, T>& normalize();
+
+ /// Constructor; coordinates are set by function \p f.
+ template <typename F>
+ vec(const Function_i2v<F>& f);
+
+ /// Zero value.
+ static const vec<n, T> zero;
};
} // end of namespace mln::metal
@@ -380,6 +388,19 @@
}
+ template <unsigned n, typename T>
+ template <typename F>
+ vec<n, T>::vec(const Function_i2v<F>& f_)
+ {
+ const F& f = exact(f_);
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = f(i);
+ }
+
+ template <unsigned n, typename T>
+ const vec<n, T> vec<n, T>::zero = all(0);
+
+
// eq
template <unsigned n, typename T, typename U>
Index: trunk/milena/mln/accu/sum.hh
===================================================================
--- trunk/milena/mln/accu/sum.hh (revision 1223)
+++ trunk/milena/mln/accu/sum.hh (revision 1224)
@@ -99,7 +99,7 @@
void
sum_<V,S>::init()
{
- s_ = 0;
+ s_ = S::zero; // FIXME
}
template <typename V, typename S>
Index: trunk/milena/mln/value/builtin.hh
===================================================================
--- trunk/milena/mln/value/builtin.hh (revision 1223)
+++ trunk/milena/mln/value/builtin.hh (revision 1224)
@@ -49,6 +49,7 @@
};
template <> struct category< int > { typedef Built_In<void> ret; };
+ template <> struct category< unsigned > { typedef Built_In<void> ret; };
template <> struct category< float > { typedef Built_In<void> ret; };
template <> struct category< double > { typedef Built_In<void> ret; };
// FIXME: ...
Index: trunk/milena/mln/util/graph.hh
===================================================================
--- trunk/milena/mln/util/graph.hh (revision 1223)
+++ trunk/milena/mln/util/graph.hh (revision 1224)
@@ -32,6 +32,8 @@
# include <cstddef>
# include <iostream>
# include <vector>
+# include <list>
+# include <algorithm>
/*! \file mln/util/graph.hh
*
@@ -54,7 +56,7 @@
template<>
struct s_node<void>
{
- std::vector<unsigned> links;
+ std::list<unsigned> links;
};
template<typename T>
@@ -123,7 +125,6 @@
links_.push_back (edge);
++nb_link_;
nodes_[n1]->links.push_back (n2);
- nodes_[n2]->links.push_back (n1);
}
template<typename N, typename E>
@@ -135,7 +136,7 @@
typename std::vector<struct s_node <N>*>::const_iterator it = nodes_.begin ();
for (; it != nodes_.end (); ++it)
{
- typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ typename std::list<unsigned>::const_iterator it2 = (*it)->links.begin ();
for (; it2 != (*it)->links.end (); ++it2)
mln_precondition((*it2) < nb_node_);
}
@@ -162,7 +163,7 @@
std::cout << "node number = "
<< i
<< " nbh : ";
- typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ typename std::list<unsigned>::const_iterator it2 = (*it)->links.begin ();
for (; it2 != (*it)->links.end (); ++it2)
{
std::cout << (*it2)
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-02 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add lebeling algo in sandbox.
* labeling_algo.cc: Test file.
* labeling_algo.hh: Convert a binary image into mesh_image.
---
labeling_algo.cc | 32 ++++--
labeling_algo.hh | 293 +++++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 291 insertions(+), 34 deletions(-)
Index: trunk/milena/sandbox/duhamel/labeling_algo.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1222)
+++ trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1223)
@@ -35,9 +35,13 @@
# include <mln/core/neighb2d.hh>
# include <mln/value/int_u8.hh>
# include <mln/level/fill.hh>
+# include <mln/level/saturate.hh>
+# include <mln/border/fill.hh>
# include <mln/io/pbm/load.hh>
+# include <mln/io/pgm/save.hh>
# include <mln/labeling/foreground.hh>
# include <mln/debug/println.hh>
+# include <mln/debug/println_with_border.hh>
# include "labeling_algo.hh"
int main()
@@ -45,18 +49,34 @@
using namespace mln;
using value::int_u8;
- image2d_b<bool> in = io::pbm::load("../../img/toto.pbm");
+ // image2d_b<bool> in = io::pbm::load("../../img/toto.pbm");
+ image2d_b<bool> in = io::pbm::load("toto.pbm");
+
image2d_b<unsigned> lab(in.domain());
- image2d_b<unsigned> out(in.domain());
+ image2d_b<unsigned> inte(in.domain());
+ image2d_b<int_u8> out(in.domain());
unsigned n;
labeling::foreground(in, c4(), lab, n);
- std::cout << n << std::endl;
+ std::cout << "number of labels = " << n << std::endl;
+ std::vector<int_u8> vec;
image2d_b<int> input(in.domain());
level::fill(input, lab);
- debug::println(lab | make::box2d(50, 30));
- out = make_algo (lab, c4 ());
- debug::println(out | make::box2d(50, 30));
+ inte = make_algo(lab, c4 ());
+ border::fill (inte, 0);
+
+ image2d_b<int_u8> inte2(inte.domain());
+
+ level::saturate(inte, 1, 255, inte2);
+ io::pgm::save(inte2, "inte.pgm");
+ debug::println_with_border(inte2);
+
+ mesh_p<point2d> m = make::graph_with_no_border(inte2, c4());
+ std::cout << "OK" << std::endl;
+ draw::mesh (out, m, 255, 128);
+
+ debug::println(out);
+ io::pgm::save(out, "out.pgm");
}
Index: trunk/milena/sandbox/duhamel/labeling_algo.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1222)
+++ trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1223)
@@ -1,8 +1,138 @@
# include <mln/core/queue_p.hh>
# include <mln/core/clone.hh>
+# include <mln/debug/println.hh>
+
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/debug/println.hh>
+#include <mln/util/graph.hh>
+#include <mln/core/mesh_p.hh>
+#include <mln/core/mesh_psite.hh>
+#include <mln/draw/mesh.hh>
+#include <mln/core/mesh_image.hh>
+#include <mln/accu/mean.hh>
+#include <mln/estim/min_max.hh>
+#include <algorithm>
+#include <utility>
+#include <map>
+#include <mln/metal/vec.hh>
namespace mln
{
+
+// namespace util
+// {
+// template <typename T>
+// struct pair
+// {
+// pair (T t1, T t2) :
+// t1_ (t1),
+// t2_ (t2)
+// {
+// }
+
+// T t1_;
+// T t2_;
+// };
+
+// template <typename T>
+// bool operator == (const pair<T> lhs, const pair<T> rhs)
+// {
+// if ((lhs.t1_ == rhs.t1_) && (lhs.t2_ == rhs.t2_))
+// return true;
+// if ((lhs.t1_ == rhs.t2_) && (lhs.t2_ == rhs.t1_))
+// return true;
+// return false;
+// }
+
+// template <typename T>
+// bool operator < (const pair<T> lhs, const pair<T> rhs)
+// {
+// if ((lhs.t1_ + lhs.t2_ * 10 < rhs.t1_ + rhs.t2_ * 10))// && (lhs.t2_ < rhs.t2_))
+// return true;
+// return false;
+// }
+
+// } // end of mln::util
+
+ namespace make
+ {
+ template <typename I, typename N>
+ mesh_p<mln_psite(I)>
+ graph_with_no_border (Image<I>& ima_,
+ const Neighborhood<N>& nbh)
+ {
+ typedef metal::vec<2,float> X;
+
+ typedef mln_value(I) V;
+ typedef mln_psite(I) P;
+
+ I& ima = exact(ima_);
+ util::graph<void> gr;
+
+ V min, max;
+ estim::min_max (ima, min, max);
+ unsigned nb = max - min + 1;
+ std::vector<P> v(nb);
+ std::vector< accu::mean_< metal::vec<2,float> > > tab_mean (nb);
+
+ std::cout << "nb = " << nb << std::endl;
+
+ std::map<std::pair<V, V>, bool> m;
+
+ mln_piter(I) p(ima.domain());
+ mln_niter(N) n(nbh, p);
+
+ for_all(p)
+ {
+ X x = mln_point(I)(p);
+ tab_mean[ima(p) - min].take(x);
+ for_all (n) if (ima.has(n))
+ if (ima(p) != ima(n))
+ m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
+ }
+
+ std::cout << "center[0] = " << tab_mean[0].to_result() << std::endl;
+ std::cout << "center[1] = " << tab_mean[1].to_result() << std::endl;
+
+// /// test
+// v[0] = (make::point2d (0, 0));
+// v[1] = (make::point2d (5, 1));
+// v[2] = (make::point2d (9, 2));
+// v[3] = (make::point2d (0, 6));
+// v[4] = (make::point2d (6, 5));
+// v[5] = (make::point2d (8, 7));
+
+
+ for (unsigned i = min; i <= max; ++i)
+ {
+ gr.add_node ();
+// std::cout << tab_mean[i].to_result ()[0]
+// << std::endl;
+ v[i - min] = make::point2d ((unsigned)tab_mean[i].to_result ()[1], (unsigned)tab_mean[i].to_result ()[0]);
+ }
+
+ typename std::map<std::pair<V, V>, bool>::const_iterator it = m.begin ();
+ for (; it != m.end (); ++it)
+ {
+// gr.print_debug ();
+// std::cout << "t1 = " << (*it).first.first << std::endl
+// << "t2 = " << (*it).first.second << std::endl
+// << std::endl;
+
+ gr.add_edge((*it).first.first, (*it).first.second);
+ }
+
+ mesh_p<P> res(gr, v);
+ return res;
+ }
+ } // end of mln::make
+
+
template <typename I, typename N>
I
make_algo (Image<I>& ima_,
@@ -10,54 +140,161 @@
{
I& ima = exact(ima_);
I out = clone(ima_);
- queue_p<mln_point (I)> q;
- int i;
+ queue_p<mln_psite(I)> q;
- // init
+ // Init.
{
- mln_fwd_piter(I) p(ima.domain());
+ mln_piter(I) p(ima.domain());
mln_niter(N) n(nbh, p);
- for_all (p)
- {
- if (ima(p) == 0)
- for_all(n)
- if (ima(n) != 0)
+ for_all(p) if (ima(p) == 0)
+ for_all(n) if (ima(n) != 0)
{
q.push (p);
- goto end;
+ break;
}
- end:
- i = 0;
+ }
+
+// // Body.
+// {
+// while (! q.empty())
+// {
+// mln_psite(I) p = q.front();
+// q.pop();
+// mln_invariant(ima(p) == 0);
+
+// mln_niter(N) n(nbh, p);
+// for_all(n) if (ima.has(n))
+// if (out(n) != 0)
+// out(p) = out(n);
+// else
+// if (! q.has(n))
+// q.push(n);
+// }
+// }
+
+ // Body: alternative version.
+ {
+ while (! q.empty())
+ {
+ mln_psite(I) p = q.front();
+ q.pop();
+ if (out(p) != 0) // p has already been processed so ignore
+ continue;
+
+ mln_niter(N) n(nbh, p);
+ for_all(n) if (ima.has(n))
+ if (out(n) != 0)
+ out(p) = out(n);
+ else
+ q.push_force(n); // n may already be in the queue,
+ // yet we then queue again this psite
}
}
- std::cout << "q points = "
- << q.npoints ()
- << std::endl;
- //body
+ return out;
+ }
+
+ template <typename I, typename N>
+ I
+ make_algo_debug (Image<I>& ima_,
+ const Neighborhood<N>& nbh)
{
- while (q.npoints ())
+ I& ima = exact(ima_);
+ I out = clone(ima_);
+ queue_p<mln_psite(I)> q;
+
+ // Init.
{
+ mln_piter(I) p(ima.domain());
+ mln_niter(N) n(nbh, p);
- mln_point (I) po = q.front ();
- q.pop ();
- mln_invariant (ima(po) == 0);
+ for_all(p) if (ima(p) == 0)
+ for_all(n) if (ima(n) != 0)
+ {
+ std::cout << "push : " << p << std::endl;
+ q.push(p);
+ break;
+ }
+ std::cout << "init => q has " << q.npoints() << " points"
+ << std::endl;
+ }
- mln_niter(N) ne(nbh, po);
- for_all (ne)
+ // Body.
{
- if (ima.has(ne))
+ while (! q.empty())
{
- if (out(ne) != 0)
- out(po) = out (ne);
+ debug::println(out);
+ mln_psite(I) p = q.front();
+ std::cout << "pop : " << p << std::endl;
+ q.pop();
+ mln_invariant(ima(p) == 0);
+
+ mln_niter(N) n(nbh, p);
+ for_all(n) if (ima.has(n))
+ if (out(n) != 0)
+ out(p) = out(n);
else
- if (!q.has (ne))
- q.push (ne);
- }
+ if (! q.has(n))
+ {
+ std::cout << "push : " << n << std::endl;
+ q.push(n);
}
}
}
return out;
}
+
+ template <typename I, typename N>
+ I
+ make_algo_debug2 (Image<I>& ima_,
+ const Neighborhood<N>& nbh)
+ {
+ I& ima = exact(ima_);
+ I out = clone(ima_);
+ queue_p<mln_psite(I)> q;
+
+ // Init.
+ {
+ mln_piter(I) p(ima.domain());
+ mln_niter(N) n(nbh, p);
+
+ for_all(p) if (ima(p) == 0)
+ for_all(n) if (ima(n) != 0)
+ {
+ std::cout << "push : " << p << std::endl;
+ q.push(p);
+ break;
}
+ std::cout << "init => q has " << q.npoints() << " points"
+ << std::endl;
+ }
+
+
+ // Body.
+ {
+ while (! q.empty())
+ {
+ debug::println(out);
+ mln_psite(I) p = q.front();
+ std::cout << "pop : " << p << std::endl;
+ q.pop();
+ mln_invariant(ima(p) == 0);
+
+ mln_niter(N) n(nbh, p);
+ for_all(n) if (ima.has(n))
+ if (out(n) != 0)
+ out(p) = out(n);
+ else
+ if (! q.has(n))
+ {
+ std::cout << "push : " << n << std::endl;
+ q.push(n);
+ }
+ }
+ }
+ return out;
+ }
+
+
+} // end of mln
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make the trait solver rely on category inheritance.
Fix image_if related-classes.
* mln/core/image_if.hh,
* mln/core/internal/image_if_base.hh,
* mln/core/image_if_value.hh: Fix.
* mln/labeling/estimate.hh: Update.
* tests/image_if_value.cc: New.
Make float01[_] work on float!
* mln/value/float01_.hh,
* mln/value/float01.hh: Fix.
Enhance the trait solver mechanism; now it can rely
on category inheritance :-)
* mln/core/concept/image.hh,
* mln/core/concept/function.hh,
* mln/core/concept/meta_accumulator.hh,
* mln/core/concept/value_set.hh,
* mln/core/concept/weighted_window.hh,
* mln/core/concept/browsing.hh,
* mln/core/concept/dpoint.hh,
* mln/core/concept/object.hh,
* mln/core/concept/neighborhood.hh,
* mln/core/concept/window.hh,
* mln/core/concept/value.hh,
* mln/core/concept/point_site.hh,
* mln/core/concept/accumulator.hh: Specialize the category flag.
(super): New in those specializations.
Update.
* tests/trait_op_uminus.cc: New.
* tests/core_category.cc: New.
* tests/trait_op_plus.cc: Augment.
* mln/trait/op_plus.hh (set_binary_): Set category.
* mln/trait/promote.hh: Likewise.
* mln/trait/op_uminus.hh: Likewise.
* mln/trait/solve.hh: Augment.
* mln/trait/all.hh: Typo.
* mln/core/category.hh (Unknown<void>): New.
(Built_In): Move into...
* mln/value/builtin.hh: ...this new file.
* mln/core/ops.hh: Include builtin.hh.
Misc.
* mln/core/internal/exact.hh: Remove useless param.
* mln/value/graylevel.hh: Fix.
mln/core/category.hh | 25 +++---
mln/core/concept/accumulator.hh | 10 ++
mln/core/concept/browsing.hh | 11 ++
mln/core/concept/dpoint.hh | 10 ++
mln/core/concept/function.hh | 10 ++
mln/core/concept/image.hh | 10 ++
mln/core/concept/meta_accumulator.hh | 10 ++
mln/core/concept/neighborhood.hh | 11 ++
mln/core/concept/object.hh | 12 ++
mln/core/concept/point_site.hh | 13 ++-
mln/core/concept/value.hh | 12 ++
mln/core/concept/value_set.hh | 13 ++-
mln/core/concept/weighted_window.hh | 11 ++
mln/core/concept/window.hh | 10 ++
mln/core/image_if.hh | 77 ++++++++++++++++++
mln/core/image_if_value.hh | 139 +++++++++++++++++++++++++++-------
mln/core/internal/exact.hh | 11 +-
mln/core/internal/image_if_base.hh | 135 ++++++++++++---------------------
mln/core/ops.hh | 1
mln/labeling/estimate.hh | 4
mln/trait/op_plus.hh | 5 -
mln/trait/op_uminus.hh | 9 +-
mln/trait/promote.hh | 8 +
mln/trait/solve.hh | 143 ++++++++++++++++++++++++++++++++++-
mln/value/builtin.hh | 63 +++++++++++++++
mln/value/float01.hh | 12 +-
mln/value/float01_.hh | 32 +++----
mln/value/graylevel.hh | 10 --
tests/core_category.cc | 40 +++++++++
tests/image_if_value.cc | 48 +++++++++++
tests/trait_op_plus.cc | 2
tests/trait_op_uminus.cc | 129 +++++++++++++++++++++++++++++++
32 files changed, 858 insertions(+), 178 deletions(-)
Index: tests/image_if_value.cc
--- tests/image_if_value.cc (revision 0)
+++ tests/image_if_value.cc (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/image_if_value.cc
+ *
+ * \brief Tests on mln::image_if_value.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image_if_value.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(3, 3);
+ debug::iota(ima);
+ debug::println(ima);
+ debug::println(ima | 5);
+}
Index: tests/trait_op_uminus.cc
--- tests/trait_op_uminus.cc (revision 0)
+++ tests/trait_op_uminus.cc (revision 0)
@@ -0,0 +1,129 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/trait_op_uminus.cc
+ *
+ * \brief Tests on mln::trait::op_uminus.
+ */
+
+#include <mln/trait/op_uminus.hh>
+#include <mln/core/concept/object.hh>
+
+
+template <typename E> struct Top_Concept;
+template <typename E> struct Sub_Concept;
+
+
+// Top_Concept.
+
+template <> struct Top_Concept<void> { typedef mln::Object<void> super; };
+
+template <typename E>
+struct Top_Concept
+{
+ typedef Top_Concept<void> category;
+protected:
+ Top_Concept() {}
+};
+
+
+// Sub_Concept.
+
+template <> struct Sub_Concept<void> { typedef Top_Concept<void> super; };
+
+template <typename E>
+struct Sub_Concept
+{
+ typedef Sub_Concept<void> category;
+protected:
+ Sub_Concept() {}
+};
+
+
+// test.
+
+struct test : Sub_Concept< test >
+{
+ void is_test() {}
+};
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+// template <>
+// struct set_precise_unary_< op_uminus, test >
+// {
+// typedef bool ret;
+// };
+
+// template <typename T>
+// struct set_unary_< op_uminus, Sub_Concept, T >
+// {
+// typedef int ret;
+// };
+
+// template <typename T>
+// struct set_unary_< op_uminus, Top_Concept, T >
+// {
+// typedef float ret;
+// };
+
+ } // mln::trait
+
+} // mln
+
+
+int main()
+{
+ using namespace mln;
+
+// {
+// mln_trait_op_uminus_(test) tmp; // bool if precise
+// bool* b = &tmp;
+// *b = true;
+// }
+
+// {
+// mln_trait_op_uminus_(test) tmp; // int if no precise def and both sub and top defs
+// void* v = tmp;
+// }
+
+// {
+// mln_trait_op_uminus_(test) tmp; float if only top def
+// void* v = tmp;
+// }
+
+ {
+ mln_trait_op_uminus_(test) tmp; // test if no def here (default is id, given for Object)
+ tmp.is_test();
+ }
+
+}
Index: tests/core_category.cc
--- tests/core_category.cc (revision 0)
+++ tests/core_category.cc (revision 0)
@@ -0,0 +1,40 @@
+// 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/core_category.cc
+ *
+ * \brief Tests on mln::category.
+ */
+
+#include <mln/core/category.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+}
Index: tests/trait_op_plus.cc
--- tests/trait_op_plus.cc (revision 1221)
+++ tests/trait_op_plus.cc (working copy)
@@ -41,6 +41,7 @@
template <typename T>
struct my_image2d : Image< my_image2d<T> >
{
+ void m() {}
};
@@ -87,5 +88,6 @@
{
my_image2d<float>* ptr;
mln_trait_op_plus_(my_image2d<int>, my_image2d<float>) tmp = *ptr;
+ tmp.m();
}
}
Index: mln/trait/op_plus.hh
--- mln/trait/op_plus.hh (revision 1221)
+++ mln/trait/op_plus.hh (working copy)
@@ -50,9 +50,8 @@
/// Default definition of op_plus is given by the promote trait.
- template <template <class> class Category_L, typename L,
- template <class> class Category_R, typename R>
- struct set_binary_< op_plus, Category_L, L, Category_R, R >
+ template < typename L, typename R >
+ struct set_binary_< op_plus, Object, L, Object, R >
:
public promote< L, R >
{
Index: mln/trait/promote.hh
--- mln/trait/promote.hh (revision 1221)
+++ mln/trait/promote.hh (working copy)
@@ -38,6 +38,10 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Object;
+
+
namespace trait
{
@@ -50,8 +54,8 @@
/// Default case when the same type is involved twice: return this
/// type.
- template <template <class> class Category, typename T>
- struct set_binary_< promote, Category, T, Category, T >
+ template <typename T>
+ struct set_binary_< promote, Object, T, Object, T >
{
typedef T ret;
};
Index: mln/trait/solve.hh
--- mln/trait/solve.hh (revision 1221)
+++ mln/trait/solve.hh (working copy)
@@ -41,8 +41,12 @@
{
+ /// Flag type for an undefined trait.
struct undefined;
+ /// Flag type for a trait multiply undefined.
+ struct multiply_defined;
+
// Unary case.
@@ -57,7 +61,12 @@
template < template <class> class Name,
template <class> class Category_T, typename T >
- struct set_unary_
+ struct set_unary_; // Fwd decl.
+
+
+ template < template <class> class Name,
+ typename T >
+ struct set_unary_< Name, Unknown, T > // Blocker; top of inheritance.
{
typedef undefined ret;
};
@@ -67,6 +76,32 @@
{
template < template <class> class Name,
+ typename Super_Category_T, typename T >
+ struct set_unary_super_;
+
+ template < template <class> class Name,
+ template <class> class Super_Category_T, typename T >
+ struct set_unary_super_< Name, Super_Category_T<void>, T >
+ :
+ public set_unary_< Name, Super_Category_T, T >
+ {
+ };
+
+ } // end of namespace mln::trait::internal
+
+
+ template < template <class> class Name,
+ template <class> class Category_T, typename T >
+ struct set_unary_ : internal::set_unary_super_< Name,
+ typename Category_T<void>::super, T >
+ {
+ };
+
+
+ namespace internal
+ {
+
+ template < template <class> class Name,
template <class> class Category_T, typename T >
struct helper_choose_unary_
{
@@ -106,9 +141,33 @@
template < template <class, class> class Name,
+ typename L,
+ typename R >
+ struct set_precise_binary_
+ {
+ typedef undefined ret;
+ };
+
+
+ template < template <class, class> class Name,
template <class> class Category_L, typename L,
template <class> class Category_R, typename R >
- struct set_binary_
+ struct set_binary_; // Fwd decl.
+
+
+ template < template <class, class> class Name,
+ typename L,
+ template <class> class Category_R, typename R >
+ struct set_binary_< Name, Unknown, L, Category_R, R > // Left blocker.
+ {
+ typedef undefined ret;
+ };
+
+
+ template < template <class, class> class Name,
+ template <class> class Category_L, typename L,
+ typename R >
+ struct set_binary_< Name, Category_L, L, Unknown, R > // Right blocker.
{
typedef undefined ret;
};
@@ -117,7 +176,7 @@
template < template <class, class> class Name,
typename L,
typename R >
- struct set_precise_binary_
+ struct set_binary_< Name, Unknown, L, Unknown, R > // Blocker.
{
typedef undefined ret;
};
@@ -126,6 +185,84 @@
namespace internal
{
+ // Nota bene: Seq means "super or equal".
+ template < template <class, class> class Name,
+ typename Seq_Category_L, typename L,
+ typename Seq_Category_R, typename R >
+ struct set_binary_super_;
+
+ template < template <class, class> class Name,
+ template <class> class Seq_Category_L, typename L,
+ template <class> class Seq_Category_R, typename R >
+ struct set_binary_super_< Name,
+ Seq_Category_L<void>, L,
+ Seq_Category_R<void>, R >
+ :
+ public virtual set_binary_< Name,
+ Seq_Category_L, L,
+ Seq_Category_R, R >
+ {
+ };
+
+ template < typename L_ret, typename R_ret >
+ struct merge_binary_ret_
+ {
+ typedef multiply_defined ret;
+ };
+
+ template < typename LR_ret >
+ struct merge_binary_ret_< LR_ret, LR_ret >
+ {
+ typedef LR_ret ret;
+ };
+
+ template < typename L_ret >
+ struct merge_binary_ret_< L_ret, undefined >
+ {
+ typedef L_ret ret;
+ };
+
+ template < typename R_ret >
+ struct merge_binary_ret_< undefined, R_ret >
+ {
+ typedef R_ret ret;
+ };
+
+ template <>
+ struct merge_binary_ret_< undefined, undefined >
+ {
+ typedef undefined ret;
+ };
+
+ } // end of namespace mln::trait::internal
+
+
+ template < template <class, class> class Name,
+ template <class> class Category_L, typename L,
+ template <class> class Category_R, typename R >
+ struct set_binary_
+ {
+ // Construct a treillis in a static recursive way!
+
+ typedef typename internal::set_binary_super_< Name,
+ typename Category_L<void>::super, L,
+ Category_R<void>, R >::ret
+ L_ret;
+
+ typedef typename internal::set_binary_super_< Name,
+ Category_L<void>, L,
+ typename Category_R<void>::super, R >::ret
+ R_ret;
+
+ typedef typename internal::merge_binary_ret_< L_ret, R_ret >::ret ret;
+ // FIXME: Do we need to handle this search with a priority?
+ // FIXME: for a result can be found in both branches...
+ };
+
+
+ namespace internal
+ {
+
template < template <class, class> class Name,
template <class> class Category_L, typename L,
template <class> class Category_R, typename R >
Index: mln/trait/op_uminus.hh
--- mln/trait/op_uminus.hh (revision 1221)
+++ mln/trait/op_uminus.hh (working copy)
@@ -39,10 +39,13 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Object;
+
+
namespace trait
{
-
template <typename T>
struct op_uminus : public solve_unary<op_uminus, T>
{
@@ -50,8 +53,8 @@
/// Default definition of op_uminus is the input type itself.
- template <template <class> class Category, typename T>
- struct set_unary_< op_uminus, Category, T >
+ template <typename T>
+ struct set_unary_< op_uminus, Object, T >
{
typedef T ret;
};
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 1221)
+++ mln/core/image_if.hh (working copy)
@@ -35,17 +35,51 @@
# include <mln/core/internal/image_if_base.hh>
+
+# define Super mln::internal::image_if_base_< I, F, image_if<I,F> >
+
+
namespace mln
{
+ // Fwd decl.
+ template <typename I, typename F> struct image_if;
+
+
+ // internal::data_.
+
+ namespace internal
+ {
+
+ template <typename I, typename F>
+ struct data_< image_if<I,F> > : data_< Super >
+ {
+ data_(I& ima, const F& f);
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I, typename F>
+ struct image_< image_if<I,F> > : trait::image_< Super >
+ {
+ };
+
+ } // end of namespace mln::trait
+
+
+
/*! \brief An image class FIXME.
*
*/
template <typename I, typename F>
- struct image_if : public internal::image_if_base< I, F >
+ struct image_if : public Super
{
/// Skeleton.
- typedef image_if< tag::image_<I>, F > skeleton;
+ typedef image_if< tag::image_<I>, tag::function_<F> > skeleton;
/// Constructor from an image \p ima and a predicate \p f.
image_if(I& ima, const F& f);
@@ -58,6 +92,25 @@
};
+ // init_.
+
+ template <typename I, typename F>
+ void init_(tag::function_t, F& f, const image_if<I,F>& model)
+ {
+ f = model.domain().predicate();
+ }
+
+ template <typename I, typename F, typename J>
+ void init_(tag::image_t, image_if<I,F>& target, const J& model)
+ {
+ I ima;
+ init_(tag::image, ima, exact(model));
+ F f;
+ init_(tag::function, f, exact(model));
+ target.init_(ima, f);
+ }
+
+
// Operators.
// Image | Function_p2b.
@@ -73,6 +126,19 @@
# ifndef MLN_INCLUDE_ONLY
+ // internal::data_
+
+ namespace internal
+ {
+
+ template <typename I, typename F>
+ data_< image_if<I,F> >::data_(I& ima, const F& f)
+ : data_< Super >(ima, f)
+ {
+ }
+
+ }
+
// image_if<I,F>
template <typename I, typename F>
@@ -89,7 +155,9 @@
template <typename I, typename F>
image_if<I,F>::operator image_if<const I,F>() const
{
- image_if<const I,F> tmp(this->data_->ima_, this->data_->pset_);
+ mln_precondition(this->has_data());
+ image_if<const I,F> tmp(this->data_->ima_,
+ this->data_->pset_.predicate());
return tmp;
}
@@ -116,4 +184,7 @@
} // end of namespace mln
+# undef Super
+
+
#endif // ! MLN_CORE_IMAGE_IF_HH
Index: mln/core/category.hh
--- mln/core/category.hh (revision 1221)
+++ mln/core/category.hh (working copy)
@@ -43,6 +43,20 @@
struct Unknown;
+ template <>
+ struct Unknown<void>
+ {
+ typedef Unknown<void> super;
+ // Unknown is used to terminate the meta-program that solves a
+ // call to a trait. This meta-program can browse several branches
+ // at the same time---if the trait takes 2 types as arguments, the
+ // program runs over the trellis formed by the "couples of
+ // categories"--- and when the end of one branch is reached, we do
+ // not want the program to end; so it continues on that branch
+ // with the no-op "jump to the super type of Unknown"!
+ };
+
+
template <typename T>
struct category
{
@@ -50,17 +64,6 @@
};
- // The case of built-in types.
-
- template <typename E>
- struct Built_In;
-
- template <> struct category< int > { typedef Built_In<void> ret; };
- template <> struct category< float > { typedef Built_In<void> ret; };
- template <> struct category< double > { typedef Built_In<void> ret; };
- // FIXME: ...
-
-
} // end of namespace mln
Index: mln/core/internal/image_if_base.hh
--- mln/core/internal/image_if_base.hh (revision 1221)
+++ mln/core/internal/image_if_base.hh (working copy)
@@ -42,30 +42,33 @@
namespace mln
{
+
namespace internal
{
-
// Fwd decl.
- template <typename I, typename F> struct image_if_base;
+ template <typename I, typename F, typename E> struct image_if_base_;
+
+ // data_.
- template <typename I, typename F>
- struct data_< image_if_base<I,F> >
+ template <typename I, typename F, typename E>
+ struct data_< image_if_base_<I,F,E> >
{
data_(I& ima, const F& f);
- data_(I& ima, const pset_if<mln_pset(I), F>& pset);
I ima_;
pset_if<mln_pset(I), F> pset_;
};
+
} // end of namespace mln::internal
+
+
namespace trait
{
- template <typename I, typename F>
- struct image_< image_if_base<I,F> > : default_image_morpher_< I, mln_value(I),
- image_if_base<I,F> >
+ template <typename I, typename F, typename E>
+ struct image_< mln::internal::image_if_base_<I,F,E> > : default_image_morpher_< I, mln_value(I), E >
{
private:
typedef mln_trait_image_data(I) I_data_;
@@ -85,119 +88,86 @@
} // end of namespace mln::trait
+
+
namespace internal
{
- /*! \brief An base image class for image_if FIXME.
+ /*! \brief An base image class for image_if_'something.
*
*/
- template <typename I, typename F>
- struct image_if_base : public internal::image_domain_morpher_< I,
- pset_if<mln_pset(I),F>,
- image_if_base<I,F> >
+ template <typename I, typename F, typename E>
+ struct image_if_base_ : public internal::image_domain_morpher_< I, pset_if<mln_pset(I),F>, E >
{
- /// Skeleton.
- typedef image_if_base< tag::image_<I>, F > skeleton;
-
- /// Constructor from an image \p ima and a predicate \p f.
- image_if_base(I& ima, const F& f);
- /// Constructor without argument.
- image_if_base();
+ /// Give the definition domain.
+ const pset_if<mln_pset(I), F>& domain() const;
- /// Initialization.
void init_(I& ima, const F& f);
- /// Initialization.
- void init_(I& ima, const pset_if<mln_pset(I), F>& pset);
+ protected:
- /// Test if a pixel value is accessible at \p p.
- bool owns_(const mln_psite(I)& p) const;
+ /// Constructor from an image \p ima and a predicate \p f.
+ image_if_base_(I& ima, const F& f);
- /// Give the definition domain.
- const pset_if<mln_pset(I), F>& domain() const;
+ /// Constructor without argument.
+ image_if_base_();
};
# ifndef MLN_INCLUDE_ONLY
- // init_
+// // init_
- template <typename I, typename F>
- void init_(tag::function_t, F& f, const image_if_base<I,F>& model)
- {
- f = model.domain().predicate();
- }
+// template <typename I, typename F, typename E>
+// void init_(tag::function_t, F& f, const image_if_base_<I,F,E>& model)
+// {
+// f = model.domain().predicate();
+// }
+
+// template <typename I, typename F, typename E, typename J>
+// void init_(tag::image_t, image_if_base_<I,F,E>& target, const J& model)
+// {
+// I ima;
+// init_(tag::image, ima, exact(model));
+// F f;
+// init_(tag::function, f, exact(model));
+// target.init_(ima, f);
+// }
- template <typename I, typename F, typename J>
- void init_(tag::image_t, image_if_base<I,F>& target, const J& model)
- {
- I ima;
- init_(tag::image, ima, model);
- F f;
- init_(tag::function, f, model);
- target.init_(ima, f);
- // Alternative code:
- // pset_if<mln_pset(I), F> pset;
- // init_(tag::domain, pset, model);
- // target.init_(ima, pset);
- }
+ // internal::data_< image_if_base_<I,S> >
- // internal::data_< image_if_base<I,S> >
-
- template <typename I, typename F>
- data_< image_if_base<I,F> >::data_(I& ima, const F& f)
+ template <typename I, typename F, typename E>
+ data_< image_if_base_<I,F,E> >::data_(I& ima, const F& f)
: ima_(ima),
pset_(ima.domain() | f)
{
}
- template <typename I, typename F>
- data_< image_if_base<I,F> >::data_(I& ima, const pset_if<mln_pset(I), F>& pset)
- : ima_(ima),
- pset_(pset)
- {
- }
+ // image_if_base_<I,F,E>
- // image_if_base<I,F>
-
- template <typename I, typename F>
- image_if_base<I,F>::image_if_base()
+ template <typename I, typename F, typename E>
+ image_if_base_<I,F,E>::image_if_base_()
{
}
- template <typename I, typename F>
- image_if_base<I,F>::image_if_base(I& ima, const F& f)
+ template <typename I, typename F, typename E>
+ image_if_base_<I,F,E>::image_if_base_(I& ima, const F& f)
{
init_(ima, f);
}
- template <typename I, typename F>
+ template <typename I, typename F, typename E>
void
- image_if_base<I,F>::init_(I& ima, const F& f)
+ image_if_base_<I,F,E>::init_(I& ima, const F& f)
{
mln_precondition(! this->has_data());
- this->data_ = new internal::data_< image_if_base<I,F> >(ima, f);
+ this->data_ = new internal::data_<E>(ima, f);
}
- template <typename I, typename F>
- void
- image_if_base<I,F>::init_(I& ima, const pset_if<mln_pset(I), F>& pset)
- {
- mln_precondition(! this->has_data());
- this->data_ = new internal::data_< image_if_base<I,F> >(ima, pset);
- }
-
- template <typename I, typename F>
- bool
- image_if_base<I,F>::owns_(const mln_psite(I)& p) const
- {
- return this->data_->pset_.has(p);
- }
-
- template <typename I, typename F>
+ template <typename I, typename F, typename E>
const pset_if<mln_pset(I), F>&
- image_if_base<I,F>::domain() const
+ image_if_base_<I,F,E>::domain() const
{
return this->data_->pset_;
}
@@ -210,4 +180,3 @@
#endif // ! MLN_CORE_IMAGE_IF_BASE_HH
-
Index: mln/core/internal/exact.hh
--- mln/core/internal/exact.hh (revision 1221)
+++ mln/core/internal/exact.hh (working copy)
@@ -65,11 +65,10 @@
typedef T ret;
};
- template <typename E, typename T>
- yes_ exact_selector_(Object<E>*, T*);
+ template <typename E>
+ yes_ exact_selector_(Object<E>*);
- template <typename T>
- no_ exact_selector_(void*, T* t);
+ no_ exact_selector_(void*);
template <typename E, typename T>
E* exact_run_(Object<E>* t, T*);
@@ -80,7 +79,7 @@
template <typename T>
struct exact_
{
- enum { id = sizeof(exact_selector_(make_<T>::ptr(),make_<T>::ptr())) };
+ enum { id = sizeof(exact_selector_(make_<T>::ptr())) };
typedef typename exact_ret_<id, T>::ret ret;
static ret* run(T* t)
{
@@ -91,7 +90,7 @@
template <typename T>
struct exact_<const T>
{
- enum { id = sizeof(exact_selector_(make_<T>::ptr(),make_<T>::ptr())) };
+ enum { id = sizeof(exact_selector_(make_<T>::ptr())) };
typedef const typename exact_ret_<id, T>::ret ret;
static ret* run(const T* t)
{
Index: mln/core/image_if_value.hh
--- mln/core/image_if_value.hh (revision 1221)
+++ mln/core/image_if_value.hh (working copy)
@@ -34,85 +34,164 @@
*/
# include <mln/core/internal/image_if_base.hh>
+# include <mln/metal/unconst.hh>
+
+
+# define F fun::eq_p2b_expr_< pw::value_<mlc_unconst(I)>, pw::cst_<mln_value(I)> >
+# define Super mln::internal::image_if_base_< I, F, image_if_value<I> >
+
namespace mln
{
+ // Fwd decl.
+ template <typename I> struct image_if_value;
+
+
+ // internal::data_.
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< image_if_value<I> > : data_< Super >
+ {
+ data_(I& ima, const F& f);
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct image_< image_if_value<I> > : trait::image_< Super >
+ {
+ };
+
+ } // end of namespace mln::trait
+
+
+
/*! \brief An image class FIXME.
*
*/
- template <typename I, typename F>
- struct image_if_value : public internal::image_if_base< I, F >
+ template <typename I>
+ struct image_if_value : public Super
{
/// Skeleton.
- typedef image_if_value< tag::image_<I>, tag::function_<F> > skeleton;
+ typedef image_if_value< tag::image_<I> > skeleton;
+
+ /// Natural constructor from an image \p ima and a value \p v.
+ image_if_value(I& ima, const mln_value(I)& v);
- /// Constructor from an image \p ima and a predicate \p f.
+ /// Ancestral constructor from an image \p ima and a function \p f.
image_if_value(I& ima, const F& f);
/// Constructor without argument.
image_if_value();
- /// Const promotion via convertion.
- operator image_if_value<const I, F>() const;
+ // FIXME: Conversion below does *not* work automatically.
+ /// Const promotion via conversion.
+ operator image_if_value<const I> () const;
};
+
+
+ // init_.
+
+ template <typename I>
+ void init_(tag::function_t, F& f, const image_if_value<I>& model)
+ {
+ f = model.domain().predicate();
+ }
+
+ template <typename I, typename J>
+ void init_(tag::image_t, image_if_value<I>& target, const J& model)
+ {
+ I ima;
+ init_(tag::image, ima, exact(model));
+ F f;
+ init_(tag::function, f, exact(model));
+ target.init_(ima, f);
+ }
+
+
+
// Operators.
// Image | value.
template <typename I>
- image_if_value< I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
+ image_if_value<I>
operator | (Image<I>& ima, const mln_value(I)& v);
template <typename I>
- image_if_value< const I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
+ image_if_value<const I>
operator | (const Image<I>& ima, const mln_value(I)& v);
+
+
# ifndef MLN_INCLUDE_ONLY
- // image_if_value<I,F>
+ // image_if_value<I>
- template <typename I, typename F>
- image_if_value<I,F>::image_if_value()
+ template <typename I>
+ image_if_value<I>::image_if_value()
{
}
- template <typename I, typename F>
- image_if_value<I,F>::image_if_value(I& ima, const F& f)
+ template <typename I>
+ image_if_value<I>::image_if_value(I& ima, const F& f)
{
this->init_(ima, f);
}
- template <typename I, typename F>
- image_if_value<I,F>::operator image_if_value<const I, F>() const
+ template <typename I>
+ image_if_value<I>::image_if_value(I& ima, const mln_value(I)& v)
{
- image_if_value<const I, F> tmp(this->data_->ima_, this->data_->pset_);
+ this->init_(ima, pw::value(ima) = pw::cst(v));
+ }
+
+ template <typename I>
+ image_if_value<I>::operator image_if_value<const I>() const
+ {
+ mln_precondition(this->has_data());
+ image_if_value<const I> tmp(this->data_->ima_,
+ this->data_->pset_.predicate);
return tmp;
}
+ // internal::data_< image_if_value<I> >
+
+ namespace internal
+ {
+
+ template <typename I>
+ data_< image_if_value<I> >::data_(I& ima, const F& f)
+ : data_< Super >(ima, f)
+ {
+ }
+
+ }
+
// Operators.
template <typename I>
- image_if_value< I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
+ image_if_value<I>
operator | (Image<I>& ima, const mln_value(I)& v)
{
- return ima | (pw::value(ima) = pw::cst(v));
+ image_if_value<I> tmp(exact(ima), v);
+ return tmp;
}
template <typename I>
- image_if_value< const I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
+ image_if_value<const I>
operator | (const Image<I>& ima, const mln_value(I)& v)
{
- return ima | (pw::value(ima) = pw::cst(v));
+ image_if_value<const I> tmp(exact(ima), v);
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -120,4 +199,8 @@
} // end of namespace mln
+# undef Super
+# undef F
+
+
#endif // ! MLN_CORE_IMAGE_IF_VALUE_HH
Index: mln/core/ops.hh
--- mln/core/ops.hh (revision 1221)
+++ mln/core/ops.hh (working copy)
@@ -34,6 +34,7 @@
# include <mln/core/concept/object.hh>
# include <mln/core/exact.hh>
+# include <mln/value/builtin.hh>
# include <mln/trait/op_plus.hh>
# include <mln/trait/op_times.hh>
Index: mln/core/concept/image.hh
--- mln/core/concept/image.hh (revision 1221)
+++ mln/core/concept/image.hh (working copy)
@@ -48,6 +48,16 @@
{
+ // Fwd decl.
+ template <typename E> struct Image;
+
+ // Image category flag type.
+ template <>
+ struct Image<void>
+ {
+ typedef Object<void> super;
+ };
+
/*! \brief Base class for implementation of image classes.
*
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1221)
+++ mln/core/concept/function.hh (working copy)
@@ -39,6 +39,16 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Function;
+
+ // Function category flag type.
+ template <>
+ struct Function<void>
+ {
+ typedef Object<void> super;
+ };
+
/*! \brief Base class for implementation of function-objects.
*
Index: mln/core/concept/meta_accumulator.hh
--- mln/core/concept/meta_accumulator.hh (revision 1221)
+++ mln/core/concept/meta_accumulator.hh (working copy)
@@ -49,6 +49,16 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Meta_Accumulator;
+
+ // Meta_Accumulator category flag type.
+ template <>
+ struct Meta_Accumulator<void>
+ {
+ typedef Object<void> super;
+ };
+
/*! \brief Base class for implementation of meta accumulators.
*
Index: mln/core/concept/value_set.hh
--- mln/core/concept/value_set.hh (revision 1221)
+++ mln/core/concept/value_set.hh (working copy)
@@ -32,12 +32,23 @@
* \brief Definition of the concept of mln::Value_Set.
*/
-# include <mln/core/concept/value_iterator.hh>
+# include <mln/core/concept/value_iterator.hh> // FIXME: Why not object.hh?
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Value_Set;
+
+ // Value_Set category flag type.
+ template <>
+ struct Value_Set<void>
+ {
+ typedef Object<void> super;
+ };
+
+
/*! \brief Base class for implementation classes of sets of values.
*
* \see mln::doc::Value_Set for a complete documentation of this
Index: mln/core/concept/weighted_window.hh
--- mln/core/concept/weighted_window.hh (revision 1221)
+++ mln/core/concept/weighted_window.hh (working copy)
@@ -40,6 +40,17 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Weighted_Window;
+
+ // Weighted_Window category flag type.
+ template <>
+ struct Weighted_Window<void>
+ {
+ typedef Object<void> super;
+ };
+
+
/*! \brief Base class for implementation classes that are
* weighted_windows.
*
Index: mln/core/concept/browsing.hh
--- mln/core/concept/browsing.hh (revision 1221)
+++ mln/core/concept/browsing.hh (working copy)
@@ -38,6 +38,17 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Browsing;
+
+ // Browsing category flag type.
+ template <>
+ struct Browsing<void>
+ {
+ typedef Object<void> super;
+ };
+
+
/*! \brief Base class for implementation classes that are browsings.
*
* \see mln::doc::Browsing for a complete documentation of this
Index: mln/core/concept/dpoint.hh
--- mln/core/concept/dpoint.hh (revision 1221)
+++ mln/core/concept/dpoint.hh (working copy)
@@ -39,6 +39,16 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Dpoint;
+
+ // Dpoint category flag type.
+ template <>
+ struct Dpoint<void>
+ {
+ typedef Object<void> super;
+ };
+
/*! \brief Base class for implementation of delta-point classes.
*
Index: mln/core/concept/object.hh
--- mln/core/concept/object.hh (revision 1221)
+++ mln/core/concept/object.hh (working copy)
@@ -37,6 +37,7 @@
# include <iostream>
# include <mln/core/macros.hh>
+# include <mln/core/category.hh>
# include <mln/core/contract.hh>
# include <mln/core/internal/fixme.hh>
# include <mln/trace/all.hh>
@@ -59,6 +60,17 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Object;
+
+ // Object category flag type.
+ template <>
+ struct Object<void>
+ {
+ typedef Unknown<void> super;
+ };
+
+
/*! \brief Base class for almost every class defined in milena.
*
* The parameter \a E is the exact type.
Index: mln/core/concept/neighborhood.hh
--- mln/core/concept/neighborhood.hh (revision 1221)
+++ mln/core/concept/neighborhood.hh (working copy)
@@ -38,6 +38,17 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Neighborhood;
+
+ // Neighborhood category flag type.
+ template <>
+ struct Neighborhood<void>
+ {
+ typedef Object<void> super;
+ };
+
+
/*! \brief Base class for implementation classes that are neighborhoods.
*
* \see mln::doc::Neighborhood for a complete documentation of this
Index: mln/core/concept/window.hh
--- mln/core/concept/window.hh (revision 1221)
+++ mln/core/concept/window.hh (working copy)
@@ -39,6 +39,16 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Window;
+
+ // Window category flag type.
+ template <>
+ struct Window<void>
+ {
+ typedef Object<void> super;
+ };
+
/*! \brief Base class for implementation classes that are windows.
*
Index: mln/core/concept/value.hh
--- mln/core/concept/value.hh (revision 1221)
+++ mln/core/concept/value.hh (working copy)
@@ -38,6 +38,17 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Value;
+
+ // Value category flag type.
+ template <>
+ struct Value<void>
+ {
+ typedef Object<void> super;
+ };
+
+
/*! \brief Base class for implementation classes of values.
*
* \see mln::doc::Value for a complete documentation of this class
@@ -96,6 +107,7 @@
# include <mln/value/cast.hh>
+# include <mln/value/builtin.hh>
#endif // ! MLN_CORE_CONCEPT_VALUE_HH
Index: mln/core/concept/point_site.hh
--- mln/core/concept/point_site.hh (revision 1221)
+++ mln/core/concept/point_site.hh (working copy)
@@ -38,10 +38,19 @@
namespace mln
{
- // Fwd decl (used in the "category" definition).
- template <typename P> struct Point;
+ // FIXME: Hack is "Point" instead of "Points_Site"; change it!
+ // Fwd decl.
+ template <typename E> struct Point;
+
+ // Point_Site category flag type.
+ template <>
+ struct Point<void>
+ {
+ typedef Object<void> super;
+ };
+
/*! \brief Base class for implementation classes of the notion of
* "point site".
Index: mln/core/concept/accumulator.hh
--- mln/core/concept/accumulator.hh (revision 1221)
+++ mln/core/concept/accumulator.hh (working copy)
@@ -41,6 +41,16 @@
namespace mln
{
+ // Fwd decl.
+ template <typename E> struct Accumulator;
+
+ // Accumulator category flag type.
+ template <>
+ struct Accumulator<void>
+ {
+ typedef Object<void> super;
+ };
+
/*! \brief Base class for implementation of accumulators.
*
Index: mln/value/graylevel.hh
--- mln/value/graylevel.hh (revision 1221)
+++ mln/value/graylevel.hh (working copy)
@@ -74,9 +74,6 @@
/// Op encoding_t.
operator enc() const;
- /// Op graylevel.
- operator graylevel() const;
-
/// Op<.
bool operator<(const graylevel<n>& rhs) const;
@@ -168,13 +165,6 @@
}
template <unsigned n>
- graylevel<n>::operator graylevel() const
- {
- gray tmp(n, val_);
- return tmp;
- }
-
- template <unsigned n>
graylevel<n>::operator typename graylevel<n>::enc() const
{
return val_;
Index: mln/value/float01_.hh
--- mln/value/float01_.hh (revision 1221)
+++ mln/value/float01_.hh (working copy)
@@ -50,7 +50,7 @@
/// General float01-level class on n bits.
template <unsigned n>
class float01_
- : public internal::value_like_< double,
+ : public internal::value_like_< float,
float01_<n> >
{
public:
@@ -62,25 +62,25 @@
float01_();
/// Ctor.
- float01_(const double val);
+ float01_(const float val);
/// Access to std type.
- double value() const;
+ float value() const;
void set_ind(unsigned long val);
enc value_ind() const;
/// Op encoding_t.
- operator double() const;
+ operator float() const;
- /// Op float01_.
- operator float01_() const;
+ /// Op float01.
+ operator float01() const;
/// Op<.
bool operator<(const float01_<n>& rhs) const;
- float01_<n>& operator=(const double val);
+ float01_<n>& operator=(const float val);
/// Op=.
// bool operator=(const float01_<n>& rhs) const;
@@ -134,7 +134,7 @@
bool operator=(const float01_<n>& lhs, const float01_<n>& rhs);
template <unsigned n>
- bool approx_equal(const float01_<n>& lhs, const double f);
+ bool approx_equal(const float01_<n>& lhs, const float f);
# ifndef MLN_INCLUDE_ONLY
@@ -147,7 +147,7 @@
}
template <unsigned n>
- float01_<n>::float01_(const double val)
+ float01_<n>::float01_(const float val)
: val_( int(val * (mln_card_(float01_<n>) - 1)) )
{
mln_precondition(val >= 0);
@@ -155,10 +155,10 @@
}
template <unsigned n>
- double
+ float
float01_<n>::value() const
{
- return (double(val_) / (mln_card_(float01_<n>) - 1));
+ return (float(val_) / (mln_card_(float01_<n>) - 1));
}
template <unsigned n>
@@ -177,7 +177,7 @@
template <unsigned n>
float01_<n>&
- float01_<n>::operator=(const double val)
+ float01_<n>::operator=(const float val)
{
mln_precondition(val >= 0);
mln_precondition(val <= 1);
@@ -186,16 +186,16 @@
}
template <unsigned n>
- float01_<n>::operator float01_() const
+ float01_<n>::operator float01() const
{
float01 tmp(n, val_);
return tmp;
}
template <unsigned n>
- float01_<n>::operator double() const
+ float01_<n>::operator float() const
{
- return double(val_) / (mln_card_(float01_<n>) - 1);
+ return float(val_) / (mln_card_(float01_<n>) - 1);
}
template <unsigned n>
@@ -223,7 +223,7 @@
}
template <unsigned n>
- bool approx_equal(const float01_<n>& lhs, const double f)
+ bool approx_equal(const float01_<n>& lhs, const float f)
{
return float01(lhs) = float01_<n>(f);
}
Index: mln/value/builtin.hh
--- mln/value/builtin.hh (revision 0)
+++ mln/value/builtin.hh (revision 0)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_VALUE_BUILTIN_HH
+# define MLN_VALUE_BUILTIN_HH
+
+/*! \file mln/value/builtin.hh
+ * \brief Some definitions about builtins.
+ */
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename E> struct Value;
+
+
+ // The case of built-in types.
+
+ template <typename E>
+ struct Built_In
+ {
+ typedef Value<void> super; // Builtins belong to a sub-category of values.
+ };
+
+ template <> struct category< int > { typedef Built_In<void> ret; };
+ template <> struct category< float > { typedef Built_In<void> ret; };
+ template <> struct category< double > { typedef Built_In<void> ret; };
+ // FIXME: ...
+
+
+} // end of namespace mln
+
+
+# include <mln/core/concept/value.hh>
+
+
+#endif // ! MLN_VALUE_BUILTIN_HH
Index: mln/value/float01.hh
--- mln/value/float01.hh (revision 1221)
+++ mln/value/float01.hh (working copy)
@@ -52,10 +52,10 @@
public:
/// Encoding associated type.
- typedef double enc;
+ typedef float enc;
/// Equivalent associated type.
- typedef double equiv;
+ typedef float equiv;
/// Ctor.
float01();
@@ -65,10 +65,10 @@
float01(const float01_<N>& val);
/// Ctor.
- float01(unsigned nbits, double val);
+ float01(unsigned nbits, float val);
/// Access to std type.
- double value() const;
+ float value() const;
unsigned long value_ind() const;
unsigned nbits() const;
@@ -137,13 +137,13 @@
{
}
- float01::float01(unsigned nbits, double val)
+ float01::float01(unsigned nbits, float val)
: nbits_(nbits),
val_(unsigned(val * internal::two_pow_n_minus_1(nbits)))
{
}
- double float01::value() const
+ float float01::value() const
{
mln_invariant(nbits_ != 0);
return double(val_) / internal::two_pow_n_minus_1(nbits_);
Index: mln/labeling/estimate.hh
--- mln/labeling/estimate.hh (revision 1221)
+++ mln/labeling/estimate.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Compute the estimate pixel value.
*/
-# include <mln/core/image_if.hh>
+# include <mln/core/image_if_value.hh>
# include <mln/accu/compute.hh>
@@ -60,6 +60,8 @@
mln_accu_with(A, util::pix<I>)::result
estimate(const Image<I>& input, const mln_value(I)& val)
{
+// void* v = (input | val);
+// return 0;
return accu::compute<A>(input | val);
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-02 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Better tests on float01.
* mln/value/float01.hh: Fix.
* mln/value/float01_.hh: Fix.
* tests/value_float01.cc: Update.
---
mln/value/float01.hh | 2 -
mln/value/float01_.hh | 24 +++++++++++++++-
tests/value_float01.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 92 insertions(+), 4 deletions(-)
Index: trunk/milena/tests/value_float01.cc
===================================================================
--- trunk/milena/tests/value_float01.cc (revision 1220)
+++ trunk/milena/tests/value_float01.cc (revision 1221)
@@ -26,10 +26,27 @@
// Public License.
#include <iostream>
+
+#include <mln/core/image2d_b.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
#include <mln/value/float01_8.hh>
#include <mln/value/float01_16.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/transform.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/level/median.hh>
+#include <mln/level/compare.hh>
+
+
+using namespace mln;
+using namespace mln::value;
+using mln::value::int_u8;
float fi(int x) { return 0.5; }
int ii(int x) { return 1; }
@@ -37,9 +54,35 @@
float fd(double x) { return 0.5; }
int id(double x) { return 1; }
+
+struct tofloat01 : mln::Function_v2v<tofloat01>
+{
+
+ typedef float01_<16> result;
+ result operator()(int_u8 v) const
+ {
+ result ret(double(v) / (mln_max(int_u8)));
+ // std::cout << v << "-> " << ret << std::endl;
+ return ret;
+ }
+};
+
+struct to8bits : mln::Function_v2v<to8bits>
+{
+
+ typedef int_u8 result;
+ result operator()(float01_<16> v) const
+ {
+ result ret = int(v.value() * 255);
+ //std::cout << v << "-> " << ret << std::endl;
+ return ret;
+ }
+};
+
int main()
{
- using namespace mln::value;
+ win::rectangle2d rect(51, 51);
+ border::thickness = 52;
float01_8 a(0.5);
float01_16 b(0.5);
@@ -74,4 +117,29 @@
std::cout << b << std::endl;
b = 1;
std::cout << b << std::endl;
+
+ {
+ std::cout << "convert" << std::endl;
+ image2d_b<int_u8>
+ lena = io::pgm::load<int_u8>("../img/lena.pgm"),
+ ref(lena.domain());
+
+ image2d_b<float01_16> out(lena.domain());
+ image2d_b<float01_16> tmp(lena.domain());
+
+ level::transform(lena, tofloat01(), tmp);
+
+ level::median(tmp, rect, out);
+ level::median(lena, rect, ref);
+
+
+ level::transform(out, to8bits(), lena);
+
+ io::pgm::save(lena, "out.pgm");
+ io::pgm::save(ref, "ref.pgm");
+ assert(lena == ref);
+ //debug::println(out);
+ }
+
+
}
Index: trunk/milena/mln/value/float01_.hh
===================================================================
--- trunk/milena/mln/value/float01_.hh (revision 1220)
+++ trunk/milena/mln/value/float01_.hh (revision 1221)
@@ -89,12 +89,32 @@
};
+ namespace internal
+ {
+
+ template <unsigned n>
+ struct convert_< float01_<n> >
+ {
+ static float01_<n> value_at_index(std::size_t i)
+ {
+ float01_<n> tmp;
+ tmp.set_ind(i);
+ return tmp;
+ }
+
+ static std::size_t index_of_value(const float01_<n>& v)
+ {
+ return v.value_ind();
+ }
+ };
+ }
+
template <unsigned n>
struct props< float01_<n> >
{
static const std::size_t card_ = metal::pow<2, n>::value;
- static const float01_<n> min() { return 0; }
- static const float01_<n> max() { return 1; }
+ static const int min() { return 0; }
+ static const int max() { return 1; }
static const unsigned nbits = n;
typedef trait::kind::data kind;
typedef float sum;
Index: trunk/milena/mln/value/float01.hh
===================================================================
--- trunk/milena/mln/value/float01.hh (revision 1220)
+++ trunk/milena/mln/value/float01.hh (revision 1221)
@@ -146,7 +146,7 @@
double float01::value() const
{
mln_invariant(nbits_ != 0);
- return val_ / internal::two_pow_n_minus_1(nbits_);
+ return double(val_) / internal::two_pow_n_minus_1(nbits_);
}
unsigned long float01::value_ind() const
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-02 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Refactoring of image_if.
* mln/core/image_if.hh: For functions.
* mln/core/image_if_interval.hh: New, for interval.
* mln/core/image_if_value.hh: New, for values.
* mln/core/internal/image_if_base.hh: Abstraction of image_if.
* mln/trait/images.hh: Update.
---
core/image_if.hh | 226 -----------------------------------------
core/image_if_interval.hh | 135 ++++++++++++++++++++++++
core/image_if_value.hh | 123 ++++++++++++++++++++++
core/internal/image_if_base.hh | 213 ++++++++++++++++++++++++++++++++++++++
trait/images.hh | 2
5 files changed, 476 insertions(+), 223 deletions(-)
Index: trunk/milena/mln/trait/images.hh
===================================================================
--- trunk/milena/mln/trait/images.hh (revision 1219)
+++ trunk/milena/mln/trait/images.hh (revision 1220)
@@ -85,7 +85,7 @@
template <typename P, typename T> class sparse_image;
// Morphers.
- template <typename I, typename F> struct image_if;
+ template <typename I, typename F> struct image_if_base;
template <typename I, typename D> class decorated_image;
template <typename I, typename S> class sub_image;
template <typename I> struct t_image;
Index: trunk/milena/mln/core/image_if.hh
===================================================================
--- trunk/milena/mln/core/image_if.hh (revision 1219)
+++ trunk/milena/mln/core/image_if.hh (revision 1220)
@@ -33,73 +33,19 @@
* \brief Definition of a image_if image.
*/
-# include <mln/core/internal/image_domain_morpher.hh>
-# include <mln/core/pset_if.hh>
-# include <mln/pw/all.hh>
-# include <mln/value/interval.hh>
-
+# include <mln/core/internal/image_if_base.hh>
namespace mln
{
- // Fwd decl.
- template <typename I, typename F> struct image_if;
-
-
- namespace internal
- {
- template <typename I, typename F>
- struct data_< image_if<I,F> >
- {
- data_(I& ima, const F& f);
- data_(I& ima, const pset_if<mln_pset(I), F>& pset);
-
- I ima_;
- pset_if<mln_pset(I), F> pset_;
- };
-
- } // end of namespace mln::internal
-
-
-
- namespace trait
- {
-
- template <typename I, typename F>
- struct image_< image_if<I,F> > : default_image_morpher_< I, mln_value(I),
- image_if<I,F> >
- {
- private:
- typedef mln_trait_image_data(I) I_data_;
- typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
- public:
-
- typedef trait::category::domain_morpher category;
-
- typedef mlc_if( mlc_is_const(I),
- trait::io::read_only, // I const => read_only
- mln_trait_image_io(I) ) io; // otherwise like I
-
- typedef mlc_if( I_data_are_linear_,
- trait::data::stored, // if linear then just stored
- I_data_ ) data; // otherwise like I
- };
-
- } // end of namespace mln::trait
-
-
-
-
/*! \brief An image class FIXME.
*
*/
template <typename I, typename F>
- struct image_if : public internal::image_domain_morpher_< I,
- pset_if<mln_pset(I),F>,
- image_if<I,F> >
+ struct image_if : public internal::image_if_base< I, F >
{
/// Skeleton.
- typedef image_if< tag::image_<I>, tag::function_<F> > skeleton;
+ typedef image_if< tag::image_<I>, F > skeleton;
/// Constructor from an image \p ima and a predicate \p f.
image_if(I& ima, const F& f);
@@ -107,25 +53,11 @@
/// Constructor without argument.
image_if();
- /// Initialization.
- void init_(I& ima, const F& f);
-
- /// Initialization.
- void init_(I& ima, const pset_if<mln_pset(I), F>& pset);
-
- /// Test if a pixel value is accessible at \p p.
- bool owns_(const mln_psite(I)& p) const;
-
- /// Give the definition domain.
- const pset_if<mln_pset(I), F>& domain() const;
-
/// Const promotion via convertion.
operator image_if<const I, F>() const;
};
-
-
// Operators.
// Image | Function_p2b.
@@ -138,85 +70,9 @@
image_if<const I, F>
operator | (const Image<I>& ima, const Function_p2b<F>& f);
- // Image | value.
-
- template <typename I>
- image_if< I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
- operator | (Image<I>& ima, const mln_value(I)& v);
-
- template <typename I>
- image_if< const I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
- operator | (const Image<I>& ima, const mln_value(I)& v);
-
- // Image | [from, to].
-
- template <typename I>
- image_if< I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
- operator | (Image<I>& ima, const value::interval_<mln_value(I)>& vv);
-
- template <typename I>
- image_if< const I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
- operator | (const Image<I>& ima, const value::interval_<mln_value(I)>& vv);
-
-
# ifndef MLN_INCLUDE_ONLY
- // init_
-
- template <typename I, typename F>
- void init_(tag::function_t, F& f, const image_if<I,F>& model)
- {
- f = model.domain().predicate();
- }
-
- template <typename I, typename F, typename J>
- void init_(tag::image_t, image_if<I,F>& target, const J& model)
- {
- I ima;
- init_(tag::image, ima, model);
- F f;
- init_(tag::function, f, model);
- target.init_(ima, f);
- // Alternative code:
- // pset_if<mln_pset(I), F> pset;
- // init_(tag::domain, pset, model);
- // target.init_(ima, pset);
- }
-
- // internal::data_< image_if<I,S> >
-
- namespace internal
- {
-
- template <typename I, typename F>
- data_< image_if<I,F> >::data_(I& ima, const F& f)
- : ima_(ima),
- pset_(ima.domain() | f)
- {
- }
-
- template <typename I, typename F>
- data_< image_if<I,F> >::data_(I& ima, const pset_if<mln_pset(I), F>& pset)
- : ima_(ima),
- pset_(pset)
- {
- }
-
- } // end of namespace mln::internal
-
// image_if<I,F>
template <typename I, typename F>
@@ -227,23 +83,7 @@
template <typename I, typename F>
image_if<I,F>::image_if(I& ima, const F& f)
{
- init_(ima, f);
- }
-
- template <typename I, typename F>
- void
- image_if<I,F>::init_(I& ima, const F& f)
- {
- mln_precondition(! this->has_data());
- this->data_ = new internal::data_< image_if<I,F> >(ima, f);
- }
-
- template <typename I, typename F>
- void
- image_if<I,F>::init_(I& ima, const pset_if<mln_pset(I), F>& pset)
- {
- mln_precondition(! this->has_data());
- this->data_ = new internal::data_< image_if<I,F> >(ima, pset);
+ this->init_(ima, f);
}
template <typename I, typename F>
@@ -253,22 +93,6 @@
return tmp;
}
- template <typename I, typename F>
- bool
- image_if<I,F>::owns_(const mln_psite(I)& p) const
- {
- return this->data_->pset_.has(p);
- }
-
- template <typename I, typename F>
- const pset_if<mln_pset(I), F>&
- image_if<I,F>::domain() const
- {
- return this->data_->pset_;
- }
-
-
-
// Operators.
template <typename I, typename F>
@@ -287,48 +111,6 @@
return tmp;
}
- template <typename I>
- image_if< I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
- operator | (Image<I>& ima, const mln_value(I)& v)
- {
- return ima | (pw::value(ima) == pw::cst(v));
- }
-
- template <typename I>
- image_if< const I,
- fun::eq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > >
- operator | (const Image<I>& ima, const mln_value(I)& v)
- {
- return ima | (pw::value(ima) == pw::cst(v));
- }
-
- template <typename I>
- image_if< I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
- operator | (Image<I>& ima, const value::interval_<mln_value(I)>& vv)
- {
- return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
- (pw::value(ima) <= pw::cst(vv.to)) );
- }
-
- template <typename I>
- image_if< const I,
- fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> >,
- fun::leq_p2b_expr_< pw::value_<I>,
- pw::cst_<mln_value(I)> > > >
- operator | (const Image<I>& ima, const value::interval_<mln_value(I)>& vv)
- {
- return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
- (pw::value(ima) <= pw::cst(vv.to)) );
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/core/internal/image_if_base.hh
===================================================================
--- trunk/milena/mln/core/internal/image_if_base.hh (revision 0)
+++ trunk/milena/mln/core/internal/image_if_base.hh (revision 1220)
@@ -0,0 +1,213 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_IMAGE_IF_BASE_HH
+# define MLN_CORE_IMAGE_IF_BASE_HH
+
+/*! \file mln/core/internal/image_if_base.hh
+ *
+ * \brief Definition of a image_if_base image.
+ */
+
+# include <mln/core/internal/image_domain_morpher.hh>
+# include <mln/core/pset_if.hh>
+# include <mln/pw/all.hh>
+# include <mln/value/interval.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+
+ // Fwd decl.
+ template <typename I, typename F> struct image_if_base;
+
+ template <typename I, typename F>
+ struct data_< image_if_base<I,F> >
+ {
+ data_(I& ima, const F& f);
+ data_(I& ima, const pset_if<mln_pset(I), F>& pset);
+
+ I ima_;
+ pset_if<mln_pset(I), F> pset_;
+ };
+ } // end of namespace mln::internal
+
+ namespace trait
+ {
+
+ template <typename I, typename F>
+ struct image_< image_if_base<I,F> > : default_image_morpher_< I, mln_value(I),
+ image_if_base<I,F> >
+ {
+ private:
+ typedef mln_trait_image_data(I) I_data_;
+ typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
+ public:
+
+ typedef trait::category::domain_morpher category;
+
+ typedef mlc_if( mlc_is_const(I),
+ trait::io::read_only, // I const => read_only
+ mln_trait_image_io(I) ) io; // otherwise like I
+
+ typedef mlc_if( I_data_are_linear_,
+ trait::data::stored, // if linear then just stored
+ I_data_ ) data; // otherwise like I
+ };
+
+ } // end of namespace mln::trait
+
+ namespace internal
+ {
+
+ /*! \brief An base image class for image_if FIXME.
+ *
+ */
+ template <typename I, typename F>
+ struct image_if_base : public internal::image_domain_morpher_< I,
+ pset_if<mln_pset(I),F>,
+ image_if_base<I,F> >
+ {
+ /// Skeleton.
+ typedef image_if_base< tag::image_<I>, F > skeleton;
+
+ /// Constructor from an image \p ima and a predicate \p f.
+ image_if_base(I& ima, const F& f);
+
+ /// Constructor without argument.
+ image_if_base();
+
+ /// Initialization.
+ void init_(I& ima, const F& f);
+
+ /// Initialization.
+ void init_(I& ima, const pset_if<mln_pset(I), F>& pset);
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_psite(I)& p) const;
+
+ /// Give the definition domain.
+ const pset_if<mln_pset(I), F>& domain() const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // init_
+
+ template <typename I, typename F>
+ void init_(tag::function_t, F& f, const image_if_base<I,F>& model)
+ {
+ f = model.domain().predicate();
+ }
+
+ template <typename I, typename F, typename J>
+ void init_(tag::image_t, image_if_base<I,F>& target, const J& model)
+ {
+ I ima;
+ init_(tag::image, ima, model);
+ F f;
+ init_(tag::function, f, model);
+ target.init_(ima, f);
+ // Alternative code:
+ // pset_if<mln_pset(I), F> pset;
+ // init_(tag::domain, pset, model);
+ // target.init_(ima, pset);
+ }
+
+ // internal::data_< image_if_base<I,S> >
+
+ template <typename I, typename F>
+ data_< image_if_base<I,F> >::data_(I& ima, const F& f)
+ : ima_(ima),
+ pset_(ima.domain() | f)
+ {
+ }
+
+ template <typename I, typename F>
+ data_< image_if_base<I,F> >::data_(I& ima, const pset_if<mln_pset(I), F>& pset)
+ : ima_(ima),
+ pset_(pset)
+ {
+ }
+
+ // image_if_base<I,F>
+
+ template <typename I, typename F>
+ image_if_base<I,F>::image_if_base()
+ {
+ }
+
+ template <typename I, typename F>
+ image_if_base<I,F>::image_if_base(I& ima, const F& f)
+ {
+ init_(ima, f);
+ }
+
+ template <typename I, typename F>
+ void
+ image_if_base<I,F>::init_(I& ima, const F& f)
+ {
+ mln_precondition(! this->has_data());
+ this->data_ = new internal::data_< image_if_base<I,F> >(ima, f);
+ }
+
+ template <typename I, typename F>
+ void
+ image_if_base<I,F>::init_(I& ima, const pset_if<mln_pset(I), F>& pset)
+ {
+ mln_precondition(! this->has_data());
+ this->data_ = new internal::data_< image_if_base<I,F> >(ima, pset);
+ }
+
+ template <typename I, typename F>
+ bool
+ image_if_base<I,F>::owns_(const mln_psite(I)& p) const
+ {
+ return this->data_->pset_.has(p);
+ }
+
+ template <typename I, typename F>
+ const pset_if<mln_pset(I), F>&
+ image_if_base<I,F>::domain() const
+ {
+ return this->data_->pset_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_IF_BASE_HH
+
Index: trunk/milena/mln/core/image_if_value.hh
===================================================================
--- trunk/milena/mln/core/image_if_value.hh (revision 0)
+++ trunk/milena/mln/core/image_if_value.hh (revision 1220)
@@ -0,0 +1,123 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_IMAGE_IF_VALUE_HH
+# define MLN_CORE_IMAGE_IF_VALUE_HH
+
+/*! \file mln/core/image_if_value.hh
+ *
+ * \brief Definition of a image_if_value image.
+ */
+
+# include <mln/core/internal/image_if_base.hh>
+
+namespace mln
+{
+
+ /*! \brief An image class FIXME.
+ *
+ */
+ template <typename I, typename F>
+ struct image_if_value : public internal::image_if_base< I, F >
+ {
+ /// Skeleton.
+ typedef image_if_value< tag::image_<I>, tag::function_<F> > skeleton;
+
+ /// Constructor from an image \p ima and a predicate \p f.
+ image_if_value(I& ima, const F& f);
+
+ /// Constructor without argument.
+ image_if_value();
+
+ /// Const promotion via convertion.
+ operator image_if_value<const I, F>() const;
+ };
+
+ // Operators.
+
+ // Image | value.
+
+ template <typename I>
+ image_if_value< I,
+ fun::eq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > >
+ operator | (Image<I>& ima, const mln_value(I)& v);
+
+ template <typename I>
+ image_if_value< const I,
+ fun::eq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > >
+ operator | (const Image<I>& ima, const mln_value(I)& v);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // image_if_value<I,F>
+
+ template <typename I, typename F>
+ image_if_value<I,F>::image_if_value()
+ {
+ }
+
+ template <typename I, typename F>
+ image_if_value<I,F>::image_if_value(I& ima, const F& f)
+ {
+ this->init_(ima, f);
+ }
+
+ template <typename I, typename F>
+ image_if_value<I,F>::operator image_if_value<const I, F>() const
+ {
+ image_if_value<const I, F> tmp(this->data_->ima_, this->data_->pset_);
+ return tmp;
+ }
+
+ // Operators.
+
+ template <typename I>
+ image_if_value< I,
+ fun::eq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > >
+ operator | (Image<I>& ima, const mln_value(I)& v)
+ {
+ return ima | (pw::value(ima) == pw::cst(v));
+ }
+
+ template <typename I>
+ image_if_value< const I,
+ fun::eq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > >
+ operator | (const Image<I>& ima, const mln_value(I)& v)
+ {
+ return ima | (pw::value(ima) == pw::cst(v));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_IF_VALUE_HH
Index: trunk/milena/mln/core/image_if_interval.hh
===================================================================
--- trunk/milena/mln/core/image_if_interval.hh (revision 0)
+++ trunk/milena/mln/core/image_if_interval.hh (revision 1220)
@@ -0,0 +1,135 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_IMAGE_IF_INTERVAL_HH
+# define MLN_CORE_IMAGE_IF_INTERVAL_HH
+
+/*! \file mln/core/image_if_interval.hh
+ *
+ * \brief Definition of a image_if_interval image.
+ */
+
+# include <mln/core/internal/image_if_base.hh>
+
+namespace mln
+{
+
+ /*! \brief An image class FIXME.
+ *
+ */
+ template <typename I, typename F>
+ struct image_if_interval : public internal::image_if_base< I, F >
+ {
+ /// Skeleton.
+ typedef image_if_interval< tag::image_<I>, tag::function_<F> > skeleton;
+
+ /// Constructor from an image \p ima and a predicate \p f.
+ image_if_interval(I& ima, const F& f);
+
+ /// Constructor without argument.
+ image_if_interval();
+
+ /// Const promotion via convertion.
+ operator image_if_interval<const I, F>() const;
+ };
+
+ // Operators.
+
+ // Image | [from, to].
+
+ template <typename I>
+ image_if_interval< I,
+ fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> >,
+ fun::leq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > > >
+ operator | (Image<I>& ima, const value::interval_<mln_value(I)>& vv);
+
+ template <typename I>
+ image_if_interval< const I,
+ fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> >,
+ fun::leq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > > >
+ operator | (const Image<I>& ima, const value::interval_<mln_value(I)>& vv);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // image_if_interval<I,F>
+
+ template <typename I, typename F>
+ image_if_interval<I,F>::image_if_interval()
+ {
+ }
+
+ template <typename I, typename F>
+ image_if_interval<I,F>::image_if_interval(I& ima, const F& f)
+ {
+ this->init_(ima, f);
+ }
+
+ template <typename I, typename F>
+ image_if_interval<I,F>::operator image_if_interval<const I, F>() const
+ {
+ image_if_interval<const I, F> tmp(this->data_->ima_, this->data_->pset_);
+ return tmp;
+ }
+
+ // Operators.
+
+ template <typename I>
+ image_if_interval< I,
+ fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> >,
+ fun::leq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > > >
+ operator | (Image<I>& ima, const value::interval_<mln_value(I)>& vv)
+ {
+ return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
+ (pw::value(ima) <= pw::cst(vv.to)) );
+ }
+
+ template <typename I>
+ image_if_interval< const I,
+ fun::and_p2b_expr_< fun::geq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> >,
+ fun::leq_p2b_expr_< pw::value_<I>,
+ pw::cst_<mln_value(I)> > > >
+ operator | (const Image<I>& ima, const value::interval_<mln_value(I)>& vv)
+ {
+ return ima | ( (pw::value(ima) >= pw::cst(vv.from)) &&
+ (pw::value(ima) <= pw::cst(vv.to)) );
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_IF_INTERVAL_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-02 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
My log.
* sandbox/garrigues/log: List all my tasks in milena.
---
log | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
Index: trunk/milena/sandbox/garrigues/log
===================================================================
--- trunk/milena/sandbox/garrigues/log (revision 0)
+++ trunk/milena/sandbox/garrigues/log (revision 1219)
@@ -0,0 +1,35 @@
+* Gestion de la 1d.
+
+* Conversions de (window, point) a vec_p.
+
+* Conversions de histo a image1d.
+
+* Tests sur la modification de comportement des types de valeurs (Sandbox).
+
+* valeurs RGB.
+
+* println with border.
+
+* Chargement / Sauvegarde des types PNM 8/16, fits, pfm.
+
+* Reprise du track pointer de olena.
+
+* Mise a jour des image heritant d'image_adaptator.
+
+* Mise a jour des classes pour le 'garbage collector'.
+
+* Creation du morpheur identite.
+
+* Mise a jour des classes d'images morpheuses en consequences de l'arrivee
+des morpheurs.
+
+* Test de l'heritage en diamant pour la class image_identity.
+
+* Creation des plain images (Images dont les donnes ne sont pas partagees).
+
+* Deplacement des inits en dehors du namespace impl pour contourner un
+ probleme du compilateur.
+
+* Creation des types graylevel et gray.
+
+* Creation du type float01_ et float01.
1
0