LRE
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
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
List overview
Download
Olena-patches
----- 2025 -----
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
olena-patches@lrde.epita.fr
9625 discussions
Start a n
N
ew thread
milena r1229: Fix image_if_interval, it works !
by Simon Nivault
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, it works !. * mln/core/image_if_interval.hh: Fix. --- image_if_interval.hh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) Index: trunk/milena/mln/core/image_if_interval.hh =================================================================== --- trunk/milena/mln/core/image_if_interval.hh (revision 1228) +++ trunk/milena/mln/core/image_if_interval.hh (revision 1229) @@ -44,7 +44,7 @@ pw::cst_<mln_value(I)> >, \ fun::leq_p2b_expr_< \ pw::value_<I>, \ - pw::cst_<mln_value(I)> > > > + pw::cst_<mln_value(I)> > > # define Super mln::internal::image_if_base_< I, F, image_if_interval<I> > @@ -94,6 +94,9 @@ /// Constructor from an image \p ima and a predicate \p f. image_if_interval(I& ima, const F& f); + /// Natural constructor from an image \p ima and a interval of value \p vv. + image_if_interval(I& ima, const value::interval_<mln_value(I)>&); + /// Constructor without argument. image_if_interval(); @@ -131,7 +134,14 @@ } template <typename I> - image_if_interval<I>::operator image_if_interval<const I, F>() const + image_if_interval<I>::image_if_interval(I& ima, const value::interval_<mln_value(I)>& vv) + { + this->init_(ima, (pw::value(ima) >= pw::cst(vv.from)) + && (pw::value(ima) <= pw::cst(vv.to))); + } + + template <typename I> + image_if_interval<I>::operator image_if_interval<const I>() const { image_if_interval<const I> tmp(this->data_->ima_, this->data_->pset_); return tmp; @@ -143,7 +153,7 @@ { template <typename I> - data_< image_if_value<I> >::data_(I& ima, const F& f) + data_< image_if_interval<I> >::data_(I& ima, const F& f) : data_< Super >(ima, f) { }
17Â years, 3Â months
1
0
0
0
milena r1228: Fix image_if_interval. Does NOT compile yet !
by Simon Nivault
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
17Â years, 3Â months
1
0
0
0
milena r1227: Update labeling_algo
by Guillaume Duhamel
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]); }
17Â years, 3Â months
1
0
0
0
milena r1226: Add tests and clean gray values
by Matthieu Garrigues
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
17Â years, 3Â months
1
0
0
0
milena r1225: Add queue_p_fast
by Guillaume Duhamel
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
17Â years, 3Â months
1
0
0
0
milena r1224: Fix for accumulator from point to vec<2, float>
by Guillaume Duhamel
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)
17Â years, 3Â months
1
0
0
0
milena r1223: Add lebeling algo in sandbox
by Guillaume Duhamel
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
17Â years, 3Â months
1
0
0
0
1222: Make the trait solver rely on category inheritance.
by Thierry Geraud
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); }
17Â years, 3Â months
1
0
0
0
milena r1221: Better tests on float01
by Matthieu Garrigues
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
17Â years, 3Â months
1
0
0
0
milena r1220: Refactoring of image_if
by Simon Nivault
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
17Â years, 3Â months
1
0
0
0
← Newer
1
...
836
837
838
839
840
841
842
...
963
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
Results per page:
10
25
50
100
200