Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
April 2007
- 7 participants
- 47 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add ''non-reference'' check.
* mlc/cmp.hh (mlc_is_not_reference): New.
(is_not_const_): Update.
cmp.hh | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletion(-)
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 942)
+++ mlc/cmp.hh (working copy)
@@ -67,6 +67,7 @@
# define mlc_is_const(T) mlc::is_const_< T >
# define mlc_is_not_const(T) mlc::is_not_const_< T >
# define mlc_is_reference(T) mlc::is_reference_< T >
+# define mlc_is_not_reference(T) mlc::is_not_reference_< T >
/// \}
@@ -233,7 +234,12 @@
};
template <typename T>
- struct is_not_const_ : public not_< is_const_<T> >::bexpr
+ struct is_not_const_ : public bexpr_<true>
+ {
+ };
+
+ template <typename T>
+ struct is_not_const_< const T > : public bexpr_<false>
{
};
/// \}
@@ -251,6 +257,16 @@
struct is_reference_< T& > : public bexpr_<true>
{
};
+
+ template <typename T>
+ struct is_not_reference_ : public bexpr_<true>
+ {
+ };
+
+ template <typename T>
+ struct is_not_reference_< T& > : public bexpr_<false>
+ {
+ };
/// \}
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add ''theoretical bounding box'' for point set types.
* TODO: Augment.
* oln/core/concept/point_set.hh (theoretical_bbox): New.
(impl_theoretical_bbox): New.
(infty): New in Box.
* oln/core/gen/pset_compare.hh (op_subset_): Fix.
* oln/core/gen/infty_pset.hh (b_): Remove.
(infty_pset, impl_bbox): Update.
(operator<<): New.
* oln/core/gen/torus_pset.hh (impl_theoretical_bbox): New.
(operator<<): Separate decl and def.
* oln/core/gen/op.hh: Cosmetic change.
* oln/core/internal/op_image_through_fv2v.hh
(value, rvalue, lvalue): Fix.
* oln/core/internal/dpoint_base.hh (impl_op_mod_equal_): Fix.
* oln/core/internal/category_of.hh: New commentary.
TODO | 2 +
oln/core/concept/point_set.hh | 35 +++++++++++++++++++++++++++++
oln/core/gen/infty_pset.hh | 23 ++++++++++---------
oln/core/gen/op.hh | 5 +++-
oln/core/gen/pset_compare.hh | 21 +++++++++++------
oln/core/gen/torus_pset.hh | 22 ++++++++++++++----
oln/core/internal/category_of.hh | 2 -
oln/core/internal/dpoint_base.hh | 4 +++
oln/core/internal/op_image_through_fv2v.hh | 12 +++++----
9 files changed, 98 insertions(+), 28 deletions(-)
Index: TODO
--- TODO (revision 941)
+++ TODO (working copy)
@@ -2,6 +2,8 @@
* Rough list
+fast iterators
+
value types (including gray level types, label types, (bool, T) type,
color types, etc.)
Index: oln/core/concept/point_set.hh
--- oln/core/concept/point_set.hh (revision 941)
+++ oln/core/concept/point_set.hh (working copy)
@@ -57,6 +57,9 @@
bool has(const point& p) const;
const box& bbox() const;
+ const box& theoretical_bbox() const;
+ const box& impl_theoretical_bbox() const; // FIXME: default?
+
protected:
Point_Set();
@@ -78,6 +81,8 @@
const point& pmax() const;
point& pmax();
+ static const Exact& infty();
+
protected:
Box();
@@ -114,6 +119,21 @@
return exact(this)->impl_bbox();
}
+
+ template <typename Exact>
+ const typename Point_Set<Exact>::box&
+ Point_Set<Exact>::theoretical_bbox() const
+ {
+ return exact(this)->impl_theoretical_bbox();
+ }
+
+ template <typename Exact>
+ const typename Point_Set<Exact>::box&
+ Point_Set<Exact>::impl_theoretical_bbox() const
+ {
+ return this->bbox();
+ }
+
template <typename Exact>
Point_Set<Exact>::Point_Set()
{
@@ -164,6 +184,21 @@
return exact(this)->impl_pmax();
}
+ template <typename Exact>
+ const Exact&
+ Box<Exact>::infty()
+ {
+ static bool flower = false;
+ static Exact the_;
+ if (not flower)
+ {
+ flower = true;
+ the_.pmin().set_all( std::numeric_limits< oln_coord(point) >::min() );
+ the_.pmax().set_all( std::numeric_limits< oln_coord(point) >::max() );
+ }
+ return the_;
+ }
+
template <typename Ps>
std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts)
{
Index: oln/core/gen/pset_compare.hh
--- oln/core/gen/pset_compare.hh (revision 941)
+++ oln/core/gen/pset_compare.hh (working copy)
@@ -128,22 +128,29 @@
bool op_subset_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
// first quick test
- if (lhs.npoints() > rhs.npoints())
+ if (lhs.npoints() > rhs.npoints()) // FIXME: May be erroneous for types like plist...
return false;
// second quick test
- if (not intersects(lhs.bbox(), rhs.bbox()))
+ if (not intersects(lhs.theoretical_bbox(), rhs.theoretical_bbox()))
return false;
// all points of lhs are IN rhs?
- oln_piter(R) p_rhs(rhs);
- p_rhs.start();
oln_piter(L) p_lhs(lhs);
for_all(p_lhs)
{
- while (p_rhs.is_valid() and p_rhs.to_point() != p_lhs.to_point())
- p_rhs.next();
- if (not p_rhs.is_valid())
+ if (not rhs.has(p_lhs))
return false;
}
+ // the following code was erroneous w.r.t. given types of psets:
+ // oln_piter(R) p_rhs(rhs);
+ // p_rhs.start();
+ // oln_piter(L) p_lhs(lhs);
+ // for_all(p_lhs)
+ // {
+ // while (p_rhs.is_valid() and p_rhs.to_point() != p_lhs.to_point())
+ // p_rhs.next();
+ // if (not p_rhs.is_valid())
+ // return false;
+ // }
return true;
}
Index: oln/core/gen/infty_pset.hh
--- oln/core/gen/infty_pset.hh (revision 941)
+++ oln/core/gen/infty_pset.hh (working copy)
@@ -29,6 +29,8 @@
# define OLN_CORE_GEN_INFTY_PSET_HH
# include <limits>
+# include <ostream>
+
# include <oln/core/concept/grid.hh>
# include <oln/core/internal/f_grid_to_box.hh>
# include <oln/core/internal/point_set_base.hh>
@@ -79,26 +81,21 @@
infty_pset();
unsigned impl_npoints() const;
- bool impl_has(const point& p) const;
+ bool impl_has(const point&) const;
const box& impl_bbox() const;
- protected:
- box b_;
-
}; // end of class oln::infty_pset<G>.
+ template <typename G>
+ std::ostream& operator<<(std::ostream& ostr, const infty_pset<G>& ps);
+
# ifndef OLN_INCLUDE_ONLY
template <typename G>
infty_pset<G>::infty_pset()
{
- typedef oln_coord(point) C;
- point minus_infty, plus_infty;
- minus_infty.set_all( std::numeric_limits<C>::min() );
- plus_infty. set_all( std::numeric_limits<C>::max() );
- this->b_ = init(from(minus_infty), to(plus_infty));
}
template <typename G>
@@ -119,7 +116,13 @@
const typename infty_pset<G>::box&
infty_pset<G>::impl_bbox() const
{
- return this->b_;
+ return box::infty();
+ }
+
+ template <typename G>
+ std::ostream& operator<<(std::ostream& ostr, const infty_pset<G>&)
+ {
+ return ostr << "infty pset";
}
#endif // ! OLN_INCLUDE_ONLY
Index: oln/core/gen/torus_pset.hh
--- oln/core/gen/torus_pset.hh (revision 941)
+++ oln/core/gen/torus_pset.hh (working copy)
@@ -28,6 +28,8 @@
#ifndef OLN_CORE_GEN_TORUS_PSET_HH
# define OLN_CORE_GEN_TORUS_PSET_HH
+# include <ostream>
+
# include <oln/core/internal/pset_adaptor.hh>
# include <oln/core/concept/dpoint.hh>
@@ -77,6 +79,8 @@
point relocate(const point& p) const;
bool impl_has(const point& p) const;
+ const box& impl_theoretical_bbox() const;
+
private:
point pmin_;
dpoint size_;
@@ -85,10 +89,7 @@
template <typename Ps>
- std::ostream& operator<<(std::ostream& ostr, const torus_pset<Ps>& ps)
- {
- return ostr << "torus " << ps.adapted_();
- }
+ std::ostream& operator<<(std::ostream& ostr, const torus_pset<Ps>& ps);
# ifndef OLN_INCLUDE_ONLY
@@ -133,6 +134,19 @@
return this->ps_.has(relocate(p));
}
+ template <typename Ps>
+ const typename current::box&
+ current::impl_theoretical_bbox() const
+ {
+ return box::infty();
+ }
+
+ template <typename Ps>
+ std::ostream& operator<<(std::ostream& ostr, const torus_pset<Ps>& ps)
+ {
+ return ostr << "torus " << ps.adapted_();
+ }
+
# endif // ! OLN_INCLUDE_ONLY
# undef super
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 941)
+++ oln/core/gen/op.hh (working copy)
@@ -91,6 +91,9 @@
+// FIXME: Split into different files so that the client can explicitly include
+// what is really needed...
+
# define oln_decl_op_extended_by(Lconcept, Rconcept) oln_decl_op_( extended_by, Lconcept, +, Rconcept)
# define oln_decl_op_such_as(Lconcept, Rconcept) oln_decl_op_( such_as, Lconcept, |, Rconcept)
# define oln_decl_op_restricted_to(Lconcept, Rconcept) oln_decl_op_( restricted_to, Lconcept, |, Rconcept)
@@ -179,7 +182,7 @@
postcondition(op_ok);
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
# undef super
Index: oln/core/internal/op_image_through_fv2v.hh
--- oln/core/internal/op_image_through_fv2v.hh (revision 941)
+++ oln/core/internal/op_image_through_fv2v.hh (working copy)
@@ -64,14 +64,16 @@
typedef I delegatee;
typedef internal::pair<I,F> data;
- typedef oln_result(F) rvalue;
- typedef mlc_basic(rvalue) value;
+ typedef oln_result(F) F_result__;
+
+ typedef mlc_basic(F_result__) value;
+ typedef value rvalue;
typedef typename mlc::if_< mlc::and_list_< mlc_is_not_const(I),
stc_is_found_type(I, lvalue),
- mlc_is_reference(oln_result(F)),
- mlc_is_not_const(oln_result(F)) >,
- stc_find_type(I, lvalue),
+ mlc_is_reference(F_result__),
+ mlc_is_not_const(F_result__) >,
+ F_result__,
stc::not_delegated >::ret lvalue;
typedef op_<oln_plain(I), through, F> plain;
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 941)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -155,7 +155,11 @@
Exact& dpoint_base_<Exact>::impl_op_mod_equal_(const Exact& rhs)
{
for (unsigned i = 0; i < n; ++i)
+ {
v_[i] %= rhs.v_[i];
+ if (v_[i] < 0)
+ v_[i] += rhs.v_[i];
+ }
return exact(*this);
}
Index: oln/core/internal/category_of.hh
--- oln/core/internal/category_of.hh (revision 941)
+++ oln/core/internal/category_of.hh (working copy)
@@ -55,7 +55,7 @@
};
template <>
- struct set_category_of_< bool >
+ struct set_category_of_< bool > // FIXME: Move into oln/core/value/*.
{
typedef stc::is< Boolean > ret;
};
1
0
> Very low two compile.
humhum s/two/to :).
-> compilation is low : 15s.
10s with cc_tarjan (without external canvas).
1
0
My first (and very small) mlc patch ever :).
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Add : mlc_is_not_const.
* mlc/cmp.hh: Fix.
cmp.hh | 7 +++++++
1 file changed, 7 insertions(+)
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 938)
+++ mlc/cmp.hh (working copy)
@@ -65,6 +65,7 @@
# define mlc_is_not_builtin(T) mlc::is_not_builtin_< T >
# define mlc_is_const(T) mlc::is_const_< T >
+# define mlc_is_not_const(T) mlc::is_not_const_< T >
# define mlc_is_reference(T) mlc::is_reference_< T >
/// \}
@@ -230,9 +231,15 @@
struct is_const_< const T > : public bexpr_<true>
{
};
+
+ template <typename T>
+ struct is_not_const_ : public not_< is_const_<T> >::bexpr
+ {
+ };
/// \}
+
/// Check whether a type is a reference.
/// \{
template <typename T>
1
0
Very low two compile.
- I didn't find mlc_is_not_const :( -
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix union_find.
* oln/morpho/union_find.hh: .
* oln/canvas/two_pass.hh: .
canvas/two_pass.hh | 4 ++--
morpho/union_find.hh | 25 ++++++++++++++-----------
2 files changed, 16 insertions(+), 13 deletions(-)
Index: oln/morpho/union_find.hh
--- oln/morpho/union_find.hh (revision 937)
+++ oln/morpho/union_find.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/concept/image.hh>
# include <oln/canvas/two_pass.hh>
+# include <oln/level/fill.hh>
namespace oln
{
@@ -40,7 +41,7 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Binary_Image<I>& input);
+ union_find(const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -50,7 +51,7 @@
struct union_find_
{
const I& input;
- oln_plain(I) output;
+ oln_plain_value(I, unsigned) output;
oln_plain(I) is_processed;
oln_plain_value(I, oln_point(I)) parent;
@@ -58,12 +59,13 @@
union_find_(const I& in)
: input(in)
{
- prepare(is_processed, oln::with, input);
- prepare(output, oln::with, input);
- prepare(parent, oln::with, input);
+ prepare(is_processed, with, in);
+ prepare(output, with, in);
+ prepare(parent, with, in);
}
- oln_point(I) find_root(I& ima,
+ oln_point(I)
+ find_root(const I& ima,
const oln_point(I)& x,
oln_plain_value(I, oln_point(I))& parent)
{
@@ -75,7 +77,8 @@
return x;
}
- void do_union(I& ima,
+ void
+ do_union(const I& ima,
const oln_point(I)& n,
const oln_point(I)& p,
oln_plain_value(I, oln_point(I))& parent)
@@ -87,7 +90,7 @@
void init()
{
- oln::level::fill(is_processed, false);
+ level::fill(is_processed, false);
}
void first_pass_body(const oln_point(I)& p)
@@ -127,10 +130,10 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Binary_Image<I>& input)
+ union_find(const Image_with_Nbh<I>& input)
{
- union_find_<I> f(input);
- canvas::two_pass(f);
+ impl::union_find_<I> f(exact(input));
+ canvas::two_pass(f, input);
return f.output;
}
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 937)
+++ oln/canvas/two_pass.hh (working copy)
@@ -36,11 +36,11 @@
{
f.init();
- oln_piter(I) p1(f.input.points());
+ oln_piter(I) p1(input.points());
for_all(p1)
f.first_pass_body(p1);
- oln_bkd_piter(I) p2(f.input.points());
+ oln_bkd_piter(I) p2(input.points());
for_all(p2)
f.second_pass_body(p2);
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Draft union_find using canvas (two_pass).
* oln/morpho/reconstruction.hh: Fix.
* oln/morpho/cc_tarjan.hh: Fix.
* oln/morpho/union_find.hh: New.
* oln/canvas: New.
* oln/canvas/two_pass.hh: New.
canvas/two_pass.hh | 52 ++++++++++++++++
morpho/cc_tarjan.hh | 3
morpho/reconstruction.hh | 10 +--
morpho/union_find.hh | 144 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 202 insertions(+), 7 deletions(-)
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 936)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -63,7 +63,7 @@
template <typename I>
oln_plain(I)
- reconstruction_loop(const Image_with_Nbh<I>& marker,
+ reconstruction_loop(Image_with_Nbh<I>& marker,
const Binary_Image<I>& mask)
{
oln_plain(I) output;
@@ -86,10 +86,10 @@
template <typename I , typename J>
void // FIXME : Slow impl.
- reconstruction_(const Image_with_Nbh<I>& marker,
+ reconstruction_(Image_with_Nbh<I>& marker,
const Binary_Image<J>& mask)
{
- image2d<int> tmp = level::clone(exact(marker).image());
+ I tmp = level::clone(marker);
while ( not stability(marker, tmp) )
{
@@ -104,10 +104,10 @@
template <typename I , typename J>
void
- reconstruction(const Image_with_Nbh<I>& marker,
+ reconstruction(Image_with_Nbh<I>& marker,
const Binary_Image<J>& mask)
{
- impl::reconstruction_(exact(marker), exact(mask));
+ impl::reconstruction_(marker, exact(mask));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 936)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -118,8 +118,7 @@
oln_plain(I) is_processed;
prepare(is_processed, with, input);
- oln_piter(I) p1(input.points());
- for_all(p1)
+ oln_piter(I) p1(is_processed.points());
is_processed(p1) = false; // FIXME : built with ?.
first_pass(input, parent, is_processed);
Index: oln/morpho/union_find.hh
--- oln/morpho/union_find.hh (revision 0)
+++ oln/morpho/union_find.hh (revision 0)
@@ -0,0 +1,144 @@
+// 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 receiv 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 OLN_MORPHO_UNION_FIND_HH
+# define OLN_MORPHO_UNION_FIND_HH
+
+# include <oln/core/concept/image.hh>
+
+# include <oln/canvas/two_pass.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Binary_Image<I>& input);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+ template <typename I>
+ struct union_find_
+ {
+ const I& input;
+ oln_plain(I) output;
+
+ oln_plain(I) is_processed;
+ oln_plain_value(I, oln_point(I)) parent;
+
+ union_find_(const I& in)
+ : input(in)
+ {
+ prepare(is_processed, oln::with, input);
+ prepare(output, oln::with, input);
+ prepare(parent, oln::with, input);
+ }
+
+ oln_point(I) find_root(I& ima,
+ const oln_point(I)& x,
+ oln_plain_value(I, oln_point(I))& parent)
+ {
+ if (parent(x) != x)
+ {
+ parent(x) = find_root(ima, parent(x), parent);
+ return parent(x);
+ }
+ return x;
+ }
+
+ void do_union(I& ima,
+ const oln_point(I)& n,
+ const oln_point(I)& p,
+ oln_plain_value(I, oln_point(I))& parent)
+ {
+ oln_point(I) r = find_root(ima, n, parent);
+ if (r != p)
+ parent(r) = p;
+ }
+
+ void init()
+ {
+ oln::level::fill(is_processed, false);
+ }
+
+ void first_pass_body(const oln_point(I)& p)
+ {
+ parent(p) = p;
+ if ( input(p) )
+ {
+ oln_niter(I) n(p, input);
+ for_all(n)
+ {
+ if ( input(n) == true and is_processed(n) )
+ do_union(input, n, p, parent);
+ }
+ is_processed(p) = true;
+ }
+
+ }
+
+ void second_pass_body(const oln_point(I)& p)
+ {
+ unsigned current_label = 0;
+ if ( input(p) == true and parent(p) == p )
+ output(p) = ++current_label;
+ else
+ output(p) = output(parent(p));
+ }
+
+ void final()
+ {
+ }
+
+ };
+
+ } // end of namespace oln::morpho::impl
+
+// Facades.
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Binary_Image<I>& input)
+ {
+ union_find_<I> f(input);
+ canvas::two_pass(f);
+ return f.output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_UNION_FIND_HH
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 0)
+++ oln/canvas/two_pass.hh (revision 0)
@@ -0,0 +1,52 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have receiv 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 OLN_CANVAS_TWO_PASS_HH
+# define OLN_CANVAS_TWO_PASS_HH
+
+namespace canvas
+{
+
+ template <typename F, typename I>
+ void two_pass(F f, I input)
+ {
+ f.init();
+
+ oln_piter(I) p1(f.input.points());
+ for_all(p1)
+ f.first_pass_body(p1);
+
+ oln_bkd_piter(I) p2(f.input.points());
+ for_all(p2)
+ f.second_pass_body(p2);
+
+ f.final();
+ }
+
+}
+
+#endif // ! OLN_CANVAS_TWO_PASS_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add torus topology and type of ''image >> fun''.
* oln/core/gen/torus_pset.hh: New.
* oln/core/gen/torus_image.hh: New.
* oln/core/internal/op_image_through_fv2v.hh: New.
* oln/core/concept/dpoint.hh (op_mod_equal_): New.
(check__): Update.
* oln/core/concept/operators.hh (operator%=, operator%): New.
* oln/core/gen/op.hh (through, oln_decl_op_through): New.
* oln/core/internal/dpoint_base.hh (impl_op_mod_equal_, set_all): New.
* oln/core/internal/box.hh (box_fwd_piter_, box_bkd_piter_): Better ctors.
* oln/core/internal/image_ops.hh (operator>>): New.
* oln/core/internal/pset_adaptor.hh (adapted_): New.
* oln/morpho/elementary_erosion.hh (comment): Extend.
* oln/level/local.hh,
* oln/level/apply_local.hh: Cosmetic changes.
core/concept/dpoint.hh | 11 +
core/concept/operators.hh | 21 ++
core/gen/op.hh | 2
core/gen/torus_image.hh | 267 +++++++++++++++++++++++++++++++++
core/gen/torus_pset.hh | 144 +++++++++++++++++
core/internal/box.hh | 16 +
core/internal/dpoint_base.hh | 28 ++-
core/internal/image_ops.hh | 32 +++
core/internal/op_image_through_fv2v.hh | 193 +++++++++++++++++++++++
core/internal/pset_adaptor.hh | 2
level/apply_local.hh | 0
morpho/elementary_erosion.hh | 18 ++
12 files changed, 723 insertions(+), 11 deletions(-)
Index: oln/core/concept/dpoint.hh
--- oln/core/concept/dpoint.hh (revision 935)
+++ oln/core/concept/dpoint.hh (working copy)
@@ -71,6 +71,9 @@
/// Operator -=.
Exact& op_minus_equal_(const Exact& rhs);
+ /// Operator %=.
+ Exact& op_mod_equal_(const Exact& rhs);
+
/// Operator -.
Exact op_unary_minus_() const;
@@ -153,6 +156,12 @@
}
template <typename Exact>
+ Exact& Dpoint<Exact>::op_mod_equal_(const Exact& rhs)
+ {
+ return exact(this)->impl_op_mod_equal_(rhs);
+ }
+
+ template <typename Exact>
Exact Dpoint<Exact>::op_unary_minus_() const
{
return exact(this)->impl_op_unary_minus_();
@@ -181,6 +190,8 @@
impl_op_plus_equal_adr = 0;
Exact& (Exact::*impl_op_minus_equal_adr)(const Exact& rhs) = & Exact::impl_op_minus_equal_;
impl_op_minus_equal_adr = 0;
+ Exact& (Exact::*impl_op_mod_equal_adr)(const Exact& rhs) = & Exact::impl_op_mod_equal_;
+ impl_op_mod_equal_adr = 0;
Exact (Exact::*impl_op_unary_minus_adr)() const = & Exact::impl_op_unary_minus_;
impl_op_unary_minus_adr = 0;
}
Index: oln/core/concept/operators.hh
--- oln/core/concept/operators.hh (revision 935)
+++ oln/core/concept/operators.hh (working copy)
@@ -67,6 +67,14 @@
template <typename T>
T operator+ (const Any<T>& lhs, const Any<T>& rhs);
+ /// Operator %= (default version).
+ template <typename L, typename R>
+ L& operator%=(Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator % (default version).
+ template <typename T>
+ T operator% (const Any<T>& lhs, const Any<T>& rhs);
+
/// Operator -= (default version).
template <typename L, typename R>
L& operator-=(Any<L>& lhs, const Any<R>& rhs);
@@ -129,6 +137,19 @@
}
template <typename L, typename R>
+ L& operator%=(Any<L>& lhs, const Any<R>& rhs)
+ {
+ return exact(lhs).op_mod_equal_(exact(rhs));
+ }
+
+ template <typename T>
+ T operator% (const Any<T>& lhs, const Any<T>& rhs)
+ {
+ T tmp = exact(lhs);
+ return tmp %= exact(rhs);
+ }
+
+ template <typename L, typename R>
L& operator-=(Any<L>& lhs, const Any<R>& rhs)
{
return exact(lhs).op_minus_equal_(exact(rhs));
Index: oln/core/gen/torus_pset.hh
--- oln/core/gen/torus_pset.hh (revision 0)
+++ oln/core/gen/torus_pset.hh (revision 0)
@@ -0,0 +1,144 @@
+// 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 OLN_CORE_GEN_TORUS_PSET_HH
+# define OLN_CORE_GEN_TORUS_PSET_HH
+
+# include <oln/core/internal/pset_adaptor.hh>
+# include <oln/core/concept/dpoint.hh>
+
+
+
+namespace oln
+{
+
+# define current torus_pset<Ps>
+# define super internal::pset_adaptor_< current >
+
+ // Fwd decl.
+ template <typename Ps> class torus_pset;
+
+
+ // Super type.
+ template <typename Ps>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename Ps>
+ struct vtypes< current >
+ {
+ typedef Ps adapted;
+ };
+
+
+ /// Generic box class based on a point class.
+
+ template <typename Ps>
+ class torus_pset : public super
+ {
+ public:
+
+ stc_using(point);
+ stc_using(box);
+ typedef oln_dpoint(point) dpoint;
+
+ torus_pset();
+ torus_pset(const Ps& pset);
+ void init_pset(const Ps& pset);
+
+ point relocate(const point& p) const;
+ bool impl_has(const point& p) const;
+
+ private:
+ point pmin_;
+ dpoint size_;
+
+ }; // end of class oln::torus_pset<Ps>
+
+
+ template <typename Ps>
+ std::ostream& operator<<(std::ostream& ostr, const torus_pset<Ps>& ps)
+ {
+ return ostr << "torus " << ps.adapted_();
+ }
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Ps>
+ current::torus_pset()
+ {
+ mlc::assert_< mlc_is_a(Ps, Point_Set) >::check();
+ }
+
+ template <typename Ps>
+ current::torus_pset(const Ps& pset)
+ : super(pset)
+ {
+ mlc::assert_< mlc_is_a(Ps, Point_Set) >::check();
+ this->pmin_ = pset.pmin();
+ dpoint unit; unit.set_all(1);
+ this->size_ = pset.pmax() - pset.pmin() + unit;
+ }
+
+ template <typename Ps>
+ void
+ current::init_pset(const Ps& pset)
+ {
+ this->ps_ = pset;
+ this->pmin_ = pset.pmin();
+ dpoint unit; unit.set_all(1);
+ this->size_ = pset.pmax() - pset.pmin() + unit;
+ }
+
+ template <typename Ps>
+ typename current::point
+ current::relocate(const typename current::point& p) const
+ {
+ return pmin_ + (p - pmin_) % size_;
+ }
+
+ template <typename Ps>
+ bool
+ current::impl_has(const typename current::point& p) const
+ {
+ return this->ps_.has(relocate(p));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_TORUS_PSET_HH
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 935)
+++ oln/core/gen/op.hh (working copy)
@@ -96,6 +96,7 @@
# define oln_decl_op_restricted_to(Lconcept, Rconcept) oln_decl_op_( restricted_to, Lconcept, |, Rconcept)
# define oln_decl_op_over(Lconcept, Rconcept) oln_decl_op_( over, Lconcept, /, Rconcept)
# define oln_decl_op_applied_on(Lconcept, Rconcept) oln_decl_op_( applied_on, Lconcept, <<, Rconcept)
+# define oln_decl_op_through(Lconcept, Rconcept) oln_decl_op_( through, Lconcept, >>, Rconcept)
// ...
@@ -112,6 +113,7 @@
struct restricted_to;
struct over;
struct applied_on;
+ struct through;
/// \}
Index: oln/core/gen/torus_image.hh
--- oln/core/gen/torus_image.hh (revision 0)
+++ oln/core/gen/torus_image.hh (revision 0)
@@ -0,0 +1,267 @@
+// 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 OLN_CORE_GEN_TORUS_IMAGE_HH
+# define OLN_CORE_GEN_TORUS_IMAGE_HH
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/gen/torus_pset.hh>
+# include <oln/core/gen/inplace.hh>
+
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ template <typename I> class torus_image;
+
+
+ /// Virtual types.
+ template <typename I>
+ struct vtypes< torus_image<I> >
+ {
+ typedef I delegatee;
+ typedef behavior::identity behavior;
+
+ typedef torus_pset<oln_pset(I)> pset;
+ typedef internal::pair<I, pset> data;
+
+ typedef oln_possible_lvalue(I) lvalue;
+
+ typedef torus_image< oln_plain(I) > plain;
+ typedef torus_image< pl::rec<I> > skeleton;
+ };
+
+
+ /// Super type.
+ template <typename I>
+ struct super_trait_< torus_image<I> >
+ {
+ typedef torus_image<I> current__;
+ typedef internal::single_image_morpher_<current__> ret;
+ };
+
+
+ /// Class for images defined by a point set and a single value.
+
+ template <typename I>
+ class torus_image : public internal::single_image_morpher_< torus_image<I> >
+ {
+ typedef torus_image<I> current;
+ typedef internal::single_image_morpher_<current> super;
+ public:
+
+ stc_using(point);
+ stc_using(rvalue);
+ typedef stc_find_type(I, lvalue) lvalue; // FIXME: macro; propagate in similar classes.
+ stc_using(value);
+ stc_using(data);
+ stc_using(pset);
+ stc_using(delegatee);
+
+ torus_image();
+ torus_image(I& ima);
+
+ const pset& impl_points() const;
+ point relocate(const point& p) const;
+
+ bool impl_owns_(const point& p) const;
+
+ rvalue impl_read(const point& p) const;
+ lvalue impl_read_write(const point& p);
+ void impl_write(const point& p, const value& v);
+
+ delegatee& impl_image();
+ const delegatee& impl_image() const;
+
+ }; // end of torus_image<I>
+
+
+
+ template <typename I, typename D>
+ bool prepare(torus_image<I>& target, with_t, const D& dat);
+
+ template <typename I>
+ bool init_(Image<I>* this_,
+ const torus_image<I>& data);
+
+ template <typename Ps, typename I>
+ bool init_(torus_pset<Ps>* this_,
+ const torus_image<I>& data);
+
+
+
+ template <typename I>
+ torus_image<const I> torus(const Image<I>& ima);
+
+ template <typename I>
+ torus_image<I> torus(Mutable_Image<I>& ima);
+
+ template <typename I>
+ inplace_< torus_image<I> > torus(inplace_<I> ima);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ torus_image<I>::torus_image()
+ {
+ }
+
+ template <typename I>
+ torus_image<I>::torus_image(I& ima)
+ {
+ precondition(exact(ima).has_data());
+ this->data_ = new data(ima, pset(ima.points()));
+ }
+
+ template <typename I>
+ const typename torus_image<I>::pset&
+ torus_image<I>::impl_points() const
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
+ template <typename I>
+ typename torus_image<I>::point
+ torus_image<I>::relocate(const typename torus_image<I>::point& p) const
+ {
+ assert(this->has_data());
+ return this->data_->second.relocate(p);
+ }
+
+ template <typename I>
+ bool
+ torus_image<I>::impl_owns_(const typename torus_image<I>::point& p) const
+ {
+ return this->image().owns_(this->relocate(p));
+ }
+
+ template <typename I>
+ typename torus_image<I>::rvalue
+ torus_image<I>::impl_read(const typename torus_image<I>::point& p) const
+ {
+ assert(this->has_data());
+ assert(this->image().has_data());
+ return this->image()(this->relocate(p));
+ }
+
+ template <typename I>
+ typename torus_image<I>::lvalue
+ torus_image<I>::impl_read_write(const typename torus_image<I>::point& p)
+ {
+ assert(this->image().has_data());
+ return this->image()(this->relocate(p));
+ }
+
+ template <typename I>
+ void
+ torus_image<I>::impl_write(const typename torus_image<I>::point& p,
+ const typename torus_image<I>::value& v)
+ {
+ assert(this->image().has_data());
+ this->image().write_(this->relocate(p), v);
+ }
+
+ template <typename I>
+ typename torus_image<I>::delegatee&
+ torus_image<I>::impl_image()
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename I>
+ const typename torus_image<I>::delegatee&
+ torus_image<I>::impl_image() const
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+
+ template <typename I>
+ torus_image<const I> torus(const Image<I>& ima)
+ {
+ torus_image<const I> tmp(exact(ima));
+ return tmp;
+ }
+
+ template <typename I>
+ torus_image<I> torus(Mutable_Image<I>& ima)
+ {
+ torus_image<I> tmp(exact(ima));
+ return tmp;
+ }
+
+ template <typename I>
+ inplace_< torus_image<I> > torus(inplace_<I> ima)
+ {
+ torus_image<I> tmp_ = torus(ima.unwrap());
+ inplace_< torus_image<I> > tmp(tmp_);
+ return tmp;
+ }
+
+
+ template <typename I, typename D>
+ bool prepare(torus_image<I>& target, with_t, const D& dat)
+ {
+ precondition(not target.has_data());
+
+ target.data__() = new typename torus_image<I>::data;
+ bool ima_ok = prepare(target.data__()->first, with, dat);
+ bool pset_ok = init(target.data__()->second, with, dat);
+ postcondition(ima_ok);
+ postcondition(pset_ok);
+ return ima_ok and pset_ok;
+ }
+
+ template <typename I>
+ bool init_(Image<I>* this_,
+ const torus_image<I>& data)
+ {
+ exact(*this_) = data.image();
+ return true;
+ }
+
+ template <typename Ps, typename I>
+ bool init_(torus_pset<Ps>* this_,
+ const torus_image<I>& data)
+ {
+ exact(*this_) = data.points();
+ return true;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_TORUS_IMAGE_HH
Index: oln/core/internal/op_image_through_fv2v.hh
--- oln/core/internal/op_image_through_fv2v.hh (revision 0)
+++ oln/core/internal/op_image_through_fv2v.hh (revision 0)
@@ -0,0 +1,193 @@
+// 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 OLN_CORE_INTERNAL_OP_IMAGE_THROUGH_FV2V_HH
+# define OLN_CORE_INTERNAL_OP_IMAGE_THROUGH_FV2V_HH
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/gen/op.hh>
+
+
+namespace oln
+{
+
+
+# define current \
+ special_op_< stc::is<Image>, I, through, stc::is<Function_v2v>, F >
+
+
+ // Fwd decl.
+ namespace internal { template <typename I, typename F> class current; }
+
+
+ // Super type.
+ template <typename I, typename F>
+ struct super_trait_< internal::current >
+ {
+ typedef internal::value_morpher_< op_<I, through, F> > ret;
+ };
+
+
+# define super \
+ super_trait_< internal::current >::ret
+
+
+ // Virtual types.
+ template <typename I, typename F>
+ struct vtypes< internal::current >
+ {
+ typedef I delegatee;
+ typedef internal::pair<I,F> data;
+
+ typedef oln_result(F) rvalue;
+ typedef mlc_basic(rvalue) value;
+
+ typedef typename mlc::if_< mlc::and_list_< mlc_is_not_const(I),
+ stc_is_found_type(I, lvalue),
+ mlc_is_reference(oln_result(F)),
+ mlc_is_not_const(oln_result(F)) >,
+ stc_find_type(I, lvalue),
+ stc::not_delegated >::ret lvalue;
+
+ typedef op_<oln_plain(I), through, F> plain;
+ typedef op_<pl::rec<I>, through, F> skeleton;
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class for the result of "Function_v2v F << Image I".
+
+ template <typename I, typename F>
+ class current : public super
+ {
+ typedef op_<I, through, F> Exact;
+ public:
+
+ stc_using(delegatee);
+ stc_using(data);
+
+ stc_using(psite);
+ stc_using(value);
+ stc_using(rvalue);
+ typedef stc_find_type(Exact, lvalue) lvalue; // FIXME: macro; propagate in similar classes.
+
+ delegatee& impl_image();
+ const delegatee& impl_image() const;
+
+ rvalue impl_read(const psite& p) const;
+ lvalue impl_read_write(const psite& p);
+ void impl_write(const psite& p, const value& v);
+
+ const F& fun() const;
+
+ protected:
+ special_op_();
+ special_op_(I& ima, F& f);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I, typename F>
+ current::special_op_()
+ {
+ }
+
+ template <typename I, typename F>
+ current::special_op_(I& ima, F& f)
+ {
+ this->data_ = new data(ima, f);
+ }
+
+ template <typename I, typename F>
+ typename current::delegatee&
+ current::impl_image()
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename I, typename F>
+ const typename current::delegatee&
+ current::impl_image() const
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename I, typename F>
+ typename current::rvalue
+ current::impl_read(const typename current::psite& p) const
+ {
+ assert(this->image().has_data());
+ return this->fun()(this->image()(p));
+ }
+
+ template <typename I, typename F>
+ typename current::lvalue
+ current::impl_read_write(const typename current::psite& p)
+ {
+ assert(this->image().has_data());
+ return this->fun()(this->image()(p));
+ }
+
+ template <typename I, typename F>
+ void
+ current::impl_write(const typename current::psite& p,
+ const typename current::value& v)
+ {
+ assert(this->image().has_data());
+ this->image()(p) = v;
+ }
+
+ template <typename I, typename F>
+ const F&
+ current::fun() const
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+
+ // FIXME: Add init.
+
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_THROUGH_FV2V_HH
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 935)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -66,6 +66,8 @@
namespace internal
{
+ // FIXME: Factor code for classes defined over vectors (dpoint_base_ and point_base_).
+
template <typename Exact>
class dpoint_base_ : public Dpoint<Exact>
{
@@ -88,14 +90,15 @@
bool impl_op_less_(const Exact& rhs) const;
Exact& impl_op_plus_equal_(const Exact& rhs);
-
Exact& impl_op_minus_equal_(const Exact& rhs);
+ Exact& impl_op_mod_equal_(const Exact& rhs);
Exact impl_op_unary_minus_() const;
typedef xtd::vec<n, coord> vec_t;
const vec_t& vec() const;
vec_t& vec();
+ void set_all(const coord& c);
protected:
dpoint_base_();
@@ -138,14 +141,22 @@
Exact& dpoint_base_<Exact>::impl_op_plus_equal_(const Exact& rhs)
{
v_ += rhs.v_;
- return *exact(this);
+ return exact(*this);
}
template <typename Exact>
Exact& dpoint_base_<Exact>::impl_op_minus_equal_(const Exact& rhs)
{
v_ -= rhs.v_;
- return *exact(this);
+ return exact(*this);
+ }
+
+ template <typename Exact>
+ Exact& dpoint_base_<Exact>::impl_op_mod_equal_(const Exact& rhs)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ v_[i] %= rhs.v_[i];
+ return exact(*this);
}
template <typename Exact>
@@ -171,6 +182,13 @@
}
template <typename Exact>
+ void
+ dpoint_base_<Exact>::set_all(const typename dpoint_base_<Exact>::coord& c)
+ {
+ v_.set_all(c);
+ }
+
+ template <typename Exact>
dpoint_base_<Exact>::dpoint_base_()
{
}
@@ -183,7 +201,7 @@
point_base_<Exact>::impl_op_plus_equal_(const typename point_base_<Exact>::dpoint& rhs)
{
this->v_ += rhs.vec();
- return *exact(this);
+ return exact(*this);
}
template <typename Exact>
@@ -191,7 +209,7 @@
point_base_<Exact>::impl_op_minus_equal_(const typename point_base_<Exact>::dpoint& rhs)
{
this->v_ -= rhs.vec();
- return *exact(this);
+ return exact(*this);
}
template <typename Exact>
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 935)
+++ oln/core/internal/box.hh (working copy)
@@ -154,7 +154,8 @@
public:
stc_using(point);
- box_fwd_piter_(const Point_Set<B>& b);
+ template <typename Ps>
+ box_fwd_piter_(const Point_Set<Ps>& ps);
void impl_start();
void impl_next();
@@ -180,7 +181,8 @@
public:
stc_using(point);
- box_bkd_piter_(const Point_Set<B>& b);
+ template <typename Ps>
+ box_bkd_piter_(const Point_Set<Ps>& ps);
void impl_start();
void impl_next();
@@ -300,8 +302,9 @@
// -------------------- box_fwd_piter_<B>
template <typename B>
- box_fwd_piter_<B>::box_fwd_piter_(const Point_Set<B>& b)
- : b_(exact(b))
+ template <typename Ps>
+ box_fwd_piter_<B>::box_fwd_piter_(const Point_Set<Ps>& ps)
+ : b_(ps.bbox())
{
nop_ = b_.pmax();
++nop_[0];
@@ -364,8 +367,9 @@
// -------------------- box_bkd_piter_<P>
template <typename B>
- box_bkd_piter_<B>::box_bkd_piter_(const Point_Set<B>& b)
- : b_(exact(b))
+ template <typename Ps>
+ box_bkd_piter_<B>::box_bkd_piter_(const Point_Set<Ps>& ps)
+ : b_(ps.bbox())
{
nop_ = b_.pmin();
--nop_[0];
Index: oln/core/internal/image_ops.hh
--- oln/core/internal/image_ops.hh (revision 935)
+++ oln/core/internal/image_ops.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/internal/op_image_such_as_fp2b.hh>
# include <oln/core/internal/op_fp2v_over_pset.hh>
# include <oln/core/internal/op_fv2v_applied_on_image.hh>
+# include <oln/core/internal/op_image_through_fv2v.hh>
# include <oln/core/gen/literal.hh>
@@ -65,6 +66,12 @@
oln_decl_op_applied_on(Function_v2v, Image);
+ // Image >> Function_v2v ( f(ima), i.e., for all p, ( f(ima) )(p) = f( ima(p) ) )
+
+ oln_decl_op_through(Image, Function_v2v);
+ oln_decl_inplace_image_op(through, >>, Function_v2v);
+
+
// Specialization "f : P -> V over Point_Set".
@@ -187,6 +194,31 @@
}
+ // Specialization
+
+ template <typename I, typename W, typename V>
+ inplace_< op_<const I, through, const fun_v2v_<W (*)(V)> > >
+ operator >> (const Image<I>& ima, W (*f)(V))
+ {
+ op_<const I, through, const fun_v2v_<W (*)(V)> > tmp(f, exact(ima));
+ return tmp;
+ }
+
+ template <typename I, typename W, typename V>
+ op_<I, through, const fun_v2v_<W (*)(V)> >
+ operator >> (Mutable_Image<I>& ima, W (*f)(V))
+ {
+ op_<I, through, const fun_v2v_<W (*)(V)> > tmp(exact(ima), f);
+ return tmp;
+ }
+
+ template <typename W, typename V, typename I>
+ inplace_< op_<I, through, const fun_v2v_<W (*)(V)> > >
+ operator >> (inplace_<I> ima, W (*f)(V))
+ {
+ return (ima.unwrap() >> f).inplace();
+ }
+
} // end of namespace oln
Index: oln/core/internal/pset_adaptor.hh
--- oln/core/internal/pset_adaptor.hh (revision 935)
+++ oln/core/internal/pset_adaptor.hh (working copy)
@@ -81,6 +81,8 @@
bool impl_has(const point& p) const;
const box& impl_bbox() const;
+ const adapted& adapted_() const { return this->ps_; }
+
protected:
adapted ps_;
pset_adaptor_();
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 935)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -106,6 +106,24 @@
// }
// delete[] jump;
// return output;
+
+// std::cout << "fast" << std::endl;
+
+// typedef oln_value(I) T;
+// border::fill(input, oln_max(T));
+// accumulator::min_<T> min;
+
+// oln_plain(I) output;
+// prepare(output, with, input);
+// oln_fast_piter(I) p(input), out(output);
+// oln_fast_niter(I) n(p, input);
+// for_all(p)
+// {
+// for_all(n)
+// min.take(*n);
+// *out = min.value();
+// }
+// return output;
// }
Index: oln/level/local.hh
Index: oln/level/apply_local.hh
1
0
935: Add a couple of morphers: ''read/write count'' and ''f:v->v applied on image''.
by Thierry Geraud 04 Apr '07
by Thierry Geraud 04 Apr '07
04 Apr '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a couple of morphers: ''read/write count'' and ''f:v->v applied on image''.
* oln/core/gen/rw_count_image.hh: New.
* oln/core/internal/op_fv2v_applied_on_image.hh: New.
* oln/core/gen/neighb.hh: Update.
* oln/core/gen/inplace.hh (inplace): Remove const.
* oln/core/gen/op.hh (oln_decl_op_applied_on, applied_on): New.
* oln/core/internal/image_base.hh (value_morpher_): New.
* oln/core/internal/category_of.hh (oln_strip_, strip_): Remove.
* oln/core/internal/point_set_base.hh: Update.
* oln/core/internal/image_ops.hh: Update.
(operator<<): New specializations.
* oln/stc/scoop.hh (stc_is_not_found_type): New.
* oln/level/fill.hh (fill): New inplace versions.
* oln/level/local.hh: Fix window versions.
* oln/level/clone.hh: Update.
core/gen/inplace.hh | 7
core/gen/neighb.hh | 1
core/gen/op.hh | 4
core/gen/rw_count_image.hh | 227 ++++++++++++++++++++++++++++++
core/internal/category_of.hh | 36 ----
core/internal/image_base.hh | 33 ++++
core/internal/image_ops.hh | 49 +++++-
core/internal/op_fv2v_applied_on_image.hh | 193 +++++++++++++++++++++++++
core/internal/point_set_base.hh | 2
level/clone.hh | 18 +-
level/fill.hh | 41 +++++
level/local.hh | 8 -
stc/scoop.hh | 2
13 files changed, 563 insertions(+), 58 deletions(-)
Index: oln/core/gen/neighb.hh
--- oln/core/gen/neighb.hh (revision 934)
+++ oln/core/gen/neighb.hh (working copy)
@@ -40,6 +40,7 @@
// Op.
oln_decl_op_extended_by(Image, Neighborhood);
+ oln_decl_inplace_image_op(extended_by, +, Neighborhood);
Index: oln/core/gen/rw_count_image.hh
--- oln/core/gen/rw_count_image.hh (revision 0)
+++ oln/core/gen/rw_count_image.hh (revision 0)
@@ -0,0 +1,227 @@
+// 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 OLN_CORE_GEN_RW_COUNT_IMAGE_HH
+# define OLN_CORE_GEN_RW_COUNT_IMAGE_HH
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/value_proxy.hh>
+# include <oln/core/gen/inplace.hh>
+
+
+namespace oln
+{
+
+# define current rw_count_image<I>
+
+
+ // Fwd decl.
+ template <typename I> class rw_count_image;
+
+
+ /// Virtual types.
+ template <typename I>
+ struct vtypes< current >
+ {
+ typedef I delegatee;
+ typedef behavior::identity behavior;
+
+ typedef typename mlc::if_< stc_is_found_type(I, lvalue),
+ internal::value_proxy_< current >,
+ stc::not_delegated >::ret lvalue;
+
+ typedef internal::triplet<I, unsigned, unsigned> data;
+
+ typedef rw_count_image< oln_plain(I) > plain;
+ typedef rw_count_image< pl::rec<I> > skeleton;
+ };
+
+
+ /// Super type.
+ template <typename I>
+ struct super_trait_< current >
+ {
+ typedef internal::single_image_morpher_< current > ret;
+ };
+
+
+ /// Class to count the number of read and write in images.
+
+ template <typename I>
+ class rw_count_image : public internal::single_image_morpher_< current >
+ {
+ typedef internal::single_image_morpher_< current > super;
+ public:
+
+ stc_using(point);
+ stc_using(rvalue);
+ stc_using(lvalue);
+ stc_using(value);
+ stc_using(data);
+ stc_using(delegatee);
+
+ rw_count_image();
+ rw_count_image(Mutable_Image<I>& ima);
+
+ rvalue impl_read(const point& p) const;
+ lvalue impl_read_write(const point& p);
+ void impl_write(const point& p, const value& v);
+
+ delegatee& impl_image();
+ const delegatee& impl_image() const;
+
+ unsigned nreads() const;
+ unsigned nwrites() const;
+
+ }; // end of rw_count_image<I>
+
+
+ template <typename I, typename D>
+ bool prepare(rw_count_image<I>& target, with_t, const D& dat);
+
+
+ template <typename I>
+ current rw_count(Mutable_Image<I>& ima);
+
+ template <typename I>
+ inplace_< current > rw_count(inplace_<I> ima);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ current::rw_count_image()
+ {
+ }
+
+ template <typename I>
+ current::rw_count_image(Mutable_Image<I>& ima)
+ {
+ precondition(exact(ima).has_data());
+ unsigned nreads = 0, nwrites = 0;
+ this->data_ = new data(exact(ima), nreads, nwrites);
+ }
+
+ template <typename I>
+ typename current::rvalue
+ current::impl_read(const typename current::point& p) const
+ {
+ assert(this->has_data());
+ assert(this->image().has_data());
+ const_cast<unsigned&>(this->data_->second) += 1;
+ return this->data_->first(p);
+ }
+
+ template <typename I>
+ typename current::lvalue
+ current::impl_read_write(const typename current::point& p)
+ {
+ assert(this->has_data());
+ assert(this->image().has_data());
+ lvalue tmp(*this, p);
+ return tmp;
+ }
+
+ template <typename I>
+ void
+ current::impl_write(const typename current::point& p,
+ const typename current::value& v)
+ {
+ assert(this->has_data());
+ assert(this->image().has_data());
+ this->data_->third += 1;
+ this->image().write_(p, v);
+ }
+
+ template <typename I>
+ typename current::delegatee&
+ current::impl_image()
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename I>
+ const typename current::delegatee&
+ current::impl_image() const
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename I>
+ unsigned
+ current::nreads() const
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
+ template <typename I>
+ unsigned
+ current::nwrites() const
+ {
+ assert(this->has_data());
+ return this->data_->third;
+ }
+
+ template <typename I>
+ current rw_count(Mutable_Image<I>& ima)
+ {
+ current tmp(ima);
+ return tmp;
+ }
+
+ template <typename I>
+ inplace_< current > rw_count(inplace_<I> ima)
+ {
+ current tmp_ = rw_count(ima.unwrap());
+ inplace_< current > tmp(tmp_);
+ return tmp;
+ }
+
+ template <typename I, typename D>
+ bool prepare(rw_count_image<I>& target, with_t, const D& dat)
+ {
+ precondition(not target.has_data());
+ target.data__() = new typename rw_count_image<I>::data;
+ bool ima_ok = prepare(target.data__()->first, with, dat);
+ target.data__()->second = 0;
+ target.data__()->third = 0;
+ postcondition(ima_ok);
+ return ima_ok;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_RW_COUNT_IMAGE_HH
Index: oln/core/gen/inplace.hh
--- oln/core/gen/inplace.hh (revision 934)
+++ oln/core/gen/inplace.hh (working copy)
@@ -54,7 +54,7 @@
template <typename I>
inplace_<I>
- inplace(const Mutable_Image<I>& ima);
+ inplace(Mutable_Image<I>& ima);
@@ -82,10 +82,9 @@
template <typename I>
inplace_<I>
- inplace(const Mutable_Image<I>& ima)
+ inplace(Mutable_Image<I>& ima)
{
- I& ima_ = const_cast<I&>(exact(ima));
- inplace_<I> tmp(ima_);
+ inplace_<I> tmp(exact(ima));
return tmp;
}
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 934)
+++ oln/core/gen/op.hh (working copy)
@@ -83,7 +83,7 @@
operator OpSym (inplace_<L> lhs, Rconcept<R>& rhs) \
{ \
mlc::assert_< mlc_is_a(L, Mutable_Image) >::check(); \
- op_<L, OpName, R> tmp(exact(lhs), exact(rhs)); \
+ op_<L, OpName, R> tmp(lhs.unwrap(), exact(rhs)); \
return inplace(tmp); \
} \
\
@@ -95,6 +95,7 @@
# define oln_decl_op_such_as(Lconcept, Rconcept) oln_decl_op_( such_as, Lconcept, |, Rconcept)
# define oln_decl_op_restricted_to(Lconcept, Rconcept) oln_decl_op_( restricted_to, Lconcept, |, Rconcept)
# define oln_decl_op_over(Lconcept, Rconcept) oln_decl_op_( over, Lconcept, /, Rconcept)
+# define oln_decl_op_applied_on(Lconcept, Rconcept) oln_decl_op_( applied_on, Lconcept, <<, Rconcept)
// ...
@@ -110,6 +111,7 @@
struct such_as;
struct restricted_to;
struct over;
+ struct applied_on;
/// \}
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 934)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -154,7 +154,7 @@
op_<const S, such_as, const fun_p2b_<B (*)(P)> >
operator | (const Point_Set<S>& lhs, B (*f)(P))
{
- typedef oln_strip_(P) P_;
+ typedef mlc_basic(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
mlc::assert_equal_< P_, oln_point(S) >::check();
op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f);
Index: oln/core/internal/image_ops.hh
--- oln/core/internal/image_ops.hh (revision 934)
+++ oln/core/internal/image_ops.hh (working copy)
@@ -32,6 +32,7 @@
# include <oln/core/internal/op_image_restricted_to_pset.hh>
# include <oln/core/internal/op_image_such_as_fp2b.hh>
# include <oln/core/internal/op_fp2v_over_pset.hh>
+# include <oln/core/internal/op_fv2v_applied_on_image.hh>
# include <oln/core/gen/literal.hh>
@@ -59,6 +60,10 @@
oln_decl_op_over(Function_p2v, Point_Set);
+ // Function_v2v << Image ( f(ima), i.e., for all p, ( f(ima) )(p) = f( ima(p) ) )
+
+ oln_decl_op_applied_on(Function_v2v, Image);
+
// Specialization "f : P -> V over Point_Set".
@@ -67,7 +72,7 @@
op_<const fun_p2v_<V (*)(P)>, over, const S>
operator / (V (*f)(P), const Point_Set<S>& pts)
{
- typedef oln_strip_(P) P_;
+ typedef mlc_basic(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
mlc::assert_equal_< P_, oln_point(S) >::check();
op_<const fun_p2v_<V (*)(P)>, over, const S> tmp(f, exact(pts));
@@ -93,7 +98,7 @@
op_<const I, such_as, const fun_p2b_<B (*)(P)> >
operator | (const Image<I>& ima, B (*f)(P))
{
- typedef oln_strip_(P) P_;
+ typedef mlc_basic(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
mlc::assert_equal_< P_, oln_point(I) >::check();
op_<const I, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(ima), f);
@@ -104,7 +109,7 @@
op_<I, such_as, const fun_p2b_<B (*)(P)> >
operator | (Mutable_Image<I>& ima, B (*f)(P))
{
- typedef oln_strip_(P) P_;
+ typedef mlc_basic(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
mlc::assert_equal_< P_, oln_point(I) >::check();
op_<I, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(ima), f);
@@ -115,7 +120,7 @@
inplace_< op_<I, such_as, const fun_p2b_<B (*)(P)> > >
operator | (inplace_<I> ima, B (*f)(P))
{
- return inplace(ima.unwrap() | f);
+ return (ima.unwrap() | f).inplace();
}
@@ -145,9 +150,43 @@
inplace_< op_<I, such_as, const fun_p2b_< Binary_Image<J> > > >
operator | (inplace_<I> ima, const Binary_Image<J>& f_ima_b)
{
- return inplace(ima.unwrap() | f_ima_b);
+ return (ima.unwrap() | f_ima_b).inplace();
+ }
+
+
+ // Specialization
+
+ template <typename W, typename V, typename I>
+ op_<const fun_v2v_<W (*)(V)>, applied_on, const I>
+ operator << (W (*f)(V), const Image<I>& ima)
+ {
+ op_<const fun_v2v_<W (*)(V)>, applied_on, const I> tmp(f, exact(ima));
+ return tmp;
}
+ template <typename W, typename V, typename I>
+ op_<const fun_v2v_<W (*)(V)>, applied_on, I>
+ operator << (W (*f)(V), Mutable_Image<I>& ima)
+ {
+ op_<const fun_v2v_<W (*)(V)>, applied_on, I> tmp(f, exact(ima));
+ return tmp;
+ }
+
+ template <typename W, typename V, typename I>
+ inplace_< op_<const fun_v2v_<W (*)(V)>, applied_on, I> >
+ operator << (W (*f)(V), inplace_<I> ima)
+ {
+ return (f << ima.unwrap()).inplace();
+ }
+
+ template <typename F, typename I>
+ inplace_< op_<const F, applied_on, I> >
+ operator << (const Function_v2v<F>& f, inplace_<I> ima)
+ {
+ return (exact(f) << ima.unwrap()).inplace();
+ }
+
+
} // end of namespace oln
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 934)
+++ oln/core/internal/image_base.hh (working copy)
@@ -74,6 +74,7 @@
template <typename Exact> struct image_morpher_;
template <typename Exact> struct single_image_morpher_;
template <typename Exact> struct image_extension_;
+ template <typename Exact> struct value_morpher_;
template <typename Exact> struct multiple_image_morpher_;
}
@@ -117,6 +118,12 @@
};
template <typename Exact>
+ struct super_trait_< internal::value_morpher_<Exact> >
+ {
+ typedef internal::single_image_morpher_<Exact> ret;
+ };
+
+ template <typename Exact>
struct super_trait_< internal::multiple_image_morpher_<Exact> >
{
typedef internal::image_morpher_<Exact> ret;
@@ -198,6 +205,15 @@
};
template <typename Exact>
+ struct vtypes< internal::value_morpher_<Exact> >
+ {
+ typedef stc::final< behavior::identity > behavior;
+ typedef stc::not_delegated value;
+ typedef stc::not_delegated lvalue;
+ typedef stc::not_delegated rvalue;
+ };
+
+ template <typename Exact>
struct vtypes< internal::multiple_image_morpher_<Exact> >
{
typedef stc::abstract n;
@@ -307,6 +323,16 @@
};
+ /// value_morpher_<Exact>
+
+ template <typename Exact>
+ class value_morpher_ : public single_image_morpher_<Exact>
+ {
+ protected:
+ value_morpher_();
+ };
+
+
/// multiple_image_morpher_<Exact>
template <typename Exact>
@@ -410,6 +436,13 @@
{
}
+ // value_morpher_<Exact>
+
+ template <typename Exact>
+ value_morpher_<Exact>::value_morpher_()
+ {
+ }
+
// multiple_image_morpher_<Exact>
template <typename Exact>
Index: oln/core/internal/op_fv2v_applied_on_image.hh
--- oln/core/internal/op_fv2v_applied_on_image.hh (revision 0)
+++ oln/core/internal/op_fv2v_applied_on_image.hh (revision 0)
@@ -0,0 +1,193 @@
+// 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 OLN_CORE_INTERNAL_OP_FV2V_APPLIED_ON_IMAGE_HH
+# define OLN_CORE_INTERNAL_OP_FV2V_APPLIED_ON_IMAGE_HH
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/gen/op.hh>
+
+
+namespace oln
+{
+
+
+# define current \
+ special_op_< stc::is<Function_v2v>, F, applied_on, stc::is<Image>, I >
+
+
+ // Fwd decl.
+ namespace internal { template <typename F, typename I> class current; }
+
+
+ // Super type.
+ template <typename F, typename I>
+ struct super_trait_< internal::current >
+ {
+ typedef internal::value_morpher_< op_<F, applied_on, I> > ret;
+ };
+
+
+# define super \
+ super_trait_< internal::current >::ret
+
+
+ // Virtual types.
+ template <typename F, typename I>
+ struct vtypes< internal::current >
+ {
+ typedef I delegatee;
+ typedef internal::pair<I,F> data;
+
+ typedef oln_result(F) rvalue;
+ typedef mlc_basic(rvalue) value;
+
+ typedef typename mlc::if_< mlc::and_list_< mlc_is_not_const(I),
+ stc_is_found_type(I, lvalue),
+ mlc_is_reference(oln_result(F)),
+ mlc_is_not_const(oln_result(F)) >,
+ stc_find_type(I, lvalue),
+ stc::not_delegated >::ret lvalue;
+
+ typedef op_<F, applied_on, oln_plain(I)> plain;
+ typedef op_<F, applied_on, pl::rec<I> > skeleton;
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class for the result of "Function_v2v F << Image I".
+
+ template <typename F, typename I>
+ class current : public super
+ {
+ typedef op_<F, applied_on, I> Exact;
+ public:
+
+ stc_using(delegatee);
+ stc_using(data);
+
+ stc_using(psite);
+ stc_using(value);
+ stc_using(rvalue);
+ typedef stc_find_type(Exact, lvalue) lvalue; // FIXME: macro; propagate in similar classes.
+
+ delegatee& impl_image();
+ const delegatee& impl_image() const;
+
+ rvalue impl_read(const psite& p) const;
+ lvalue impl_read_write(const psite& p);
+ void impl_write(const psite& p, const value& v);
+
+ const F& fun() const;
+
+ protected:
+ special_op_();
+ special_op_(F& f, I& ima);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename F, typename I>
+ current::special_op_()
+ {
+ }
+
+ template <typename F, typename I>
+ current::special_op_(F& f, I& ima)
+ {
+ this->data_ = new data(ima, f);
+ }
+
+ template <typename F, typename I>
+ typename current::delegatee&
+ current::impl_image()
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename F, typename I>
+ const typename current::delegatee&
+ current::impl_image() const
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename F, typename I>
+ typename current::rvalue
+ current::impl_read(const typename current::psite& p) const
+ {
+ assert(this->image().has_data());
+ return this->fun()(this->image()(p));
+ }
+
+ template <typename F, typename I>
+ typename current::lvalue
+ current::impl_read_write(const typename current::psite& p)
+ {
+ assert(this->image().has_data());
+ return this->fun()(this->image()(p));
+ }
+
+ template <typename F, typename I>
+ void
+ current::impl_write(const typename current::psite& p,
+ const typename current::value& v)
+ {
+ assert(this->image().has_data());
+ this->image()(p) = v;
+ }
+
+ template <typename F, typename I>
+ const F&
+ current::fun() const
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+
+ // FIXME: Add init.
+
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_FV2V_APPLIED_ON_IMAGE_HH
Index: oln/core/internal/category_of.hh
--- oln/core/internal/category_of.hh (revision 934)
+++ oln/core/internal/category_of.hh (working copy)
@@ -28,9 +28,10 @@
#ifndef OLN_CORE_INTERNAL_CATEGORY_OF_HH
# define OLN_CORE_INTERNAL_CATEGORY_OF_HH
+# include <mlc/basic.hh>
+
# define oln_category_of_(Type) typename oln::internal::category_of_< Type >::ret
-# define oln_strip_(Type) typename oln::internal::strip_< Type >::ret
namespace oln
@@ -44,36 +45,6 @@
namespace internal
{
- // Strip_
-
-
- template <typename T>
- struct strip_
- {
- typedef T ret;
- };
-
- template <typename T>
- struct strip_< T* >
- {
- typedef typename strip_<T>::ret ret;
- };
-
- template <typename T>
- struct strip_< T& >
- {
- typedef typename strip_<T>::ret ret;
- };
-
- template <typename T>
- struct strip_< const T >
- {
- typedef typename strip_<T>::ret ret;
- };
-
-
-
-
// Category_of_
@@ -93,8 +64,7 @@
template <typename T>
struct category_of_
{
- typedef typename strip_<T>::ret T_;
- typedef typename set_category_of_<T_>::ret ret;
+ typedef typename set_category_of_< mlc_basic(T) >::ret ret;
};
// ...
Index: oln/stc/scoop.hh
--- oln/stc/scoop.hh (revision 934)
+++ oln/stc/scoop.hh (working copy)
@@ -35,6 +35,7 @@
# include <mlc/abort.hh>
# include <mlc/bool.hh>
# include <mlc/pair.hh>
+# include <mlc/basic.hh>
# include <mlc/cmp.hh>
# include <mlc/if.hh>
# include <mlc/is_a.hh>
@@ -119,6 +120,7 @@
# define stc_type_is_not_found(Type) stc::is_not_found< stc_deferred(Type) >
# define stc_is_found_type(From, Type) stc::is_found< stc_deferred_type(From, Type) >
+# define stc_is_not_found_type(From, Type) stc::is_not_found< stc_deferred_type(From, Type) >
Index: oln/level/fill.hh
--- oln/level/fill.hh (revision 934)
+++ oln/level/fill.hh (working copy)
@@ -34,6 +34,7 @@
# include <oln/core/concept/image.hh>
# include <oln/core/concept/point.hh>
# include <oln/core/gen/fun.hh>
+# include <oln/core/gen/inplace.hh>
@@ -68,6 +69,20 @@
// template <typename I>
// void fill(Value_Wise_Mutable_Image<I>& target, const oln_value(I)& value);
+ // versions for temporary images
+
+ template <typename I>
+ void fill(inplace_<I> target, /* with */ const oln_value(I)& value);
+
+ template <typename I, typename J>
+ void fill(inplace_<I> target, /* with */ const Image<J>& data);
+
+ template <typename I, typename F>
+ void fill(inplace_<I> target, /* with */ const Function_p2v<F>& fun);
+
+ template <typename I, typename V, typename P>
+ void fill(inplace_<I> target, /* with */ V (*fun)(P));
+
# ifndef OLN_INCLUDE_ONLY
@@ -141,6 +156,32 @@
impl::fill_from_function_(exact(target), functorize_p2v(f));
}
+ // with inplace_<I>
+
+ template <typename I>
+ void fill(inplace_<I> target, const oln_value(I)& value)
+ {
+ fill(target.unwrap(), value);
+ }
+
+ template <typename I, typename J>
+ void fill(inplace_<I> target, const Image<J>& data)
+ {
+ fill(target.unwrap(), data);
+ }
+
+ template <typename I, typename F>
+ void fill(inplace_<I> target, const Function_p2v<F>& fun)
+ {
+ fill(target.unwrap(), fun);
+ }
+
+ template <typename I, typename V, typename P>
+ void fill(inplace_<I> target, V (*fun)(P))
+ {
+ fill(target.unwrap(), fun);
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::level
Index: oln/level/local.hh
--- oln/level/local.hh (revision 934)
+++ oln/level/local.hh (working copy)
@@ -129,7 +129,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- f.init_with(input(p));
+ f.init();
oln_qiter(W) q(p, win);
for_all(q)
if (input.owns_(q))
@@ -146,9 +146,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- f.init_with(input(p));
- if (f.value() = true)
- return true;
+ f.init();
oln_qiter(W) q(p, win);
for_all(q)
{
@@ -169,7 +167,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- f.init_with(input(p));
+ f.init();
oln_qiter(W) q(p, win);
for_all(q)
{
Index: oln/level/clone.hh
--- oln/level/clone.hh (revision 934)
+++ oln/level/clone.hh (working copy)
@@ -29,7 +29,8 @@
#ifndef OLN_LEVEL_CLONE_HH
# define OLN_LEVEL_CLONE_HH
-# include <oln/core/concept/image.hh>
+# include <oln/level/fill.hh>
+
namespace oln
{
@@ -37,7 +38,7 @@
namespace level
{
- /// Fwd decl.
+ // Fwd decl.
template <typename I>
oln_plain(I) clone(const Image<I>& input);
@@ -47,28 +48,27 @@
namespace impl
{
- /// Generic version.
+ // Generic version.
template <typename I>
oln_plain(I) clone(const Image<I>& input)
{
- oln_plain(I) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = input(p);
+ oln_plain(I) output;
+ prepare(output, with, input);
+ level::fill(output, input);
return output;
}
} // end of namespace oln::level::impl
- /// Facade.
+ // Facade.
template <typename I>
oln_plain(I) clone(const Image<I>& input)
{
return impl::clone(input);
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::level
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
minor modifications.
* oln/core/concept/iterator_on_points.hh,
* oln/core/concept/point.hh: change class name Generalised_Point to Generalized_Point.
* oln/core/concept/generalised_point.hh: Remove.
* oln/core/concept/generalized_point.hh: New,
Change class name Generalised_Point to Generalized_Point.
* oln/core/gen/dpoints_piter.hh,
* oln/core/gen/niter_has.hh: Strengthen methods signatures.
concept/generalized_point.hh | 14 +++++++-------
concept/iterator_on_points.hh | 4 ++--
concept/point.hh | 6 +++---
gen/dpoints_piter.hh | 41 +++++++++++++++++++----------------------
gen/niter_has.hh | 7 +++----
5 files changed, 34 insertions(+), 38 deletions(-)
Index: oln/core/concept/iterator_on_points.hh
--- oln/core/concept/iterator_on_points.hh (revision 933)
+++ oln/core/concept/iterator_on_points.hh (working copy)
@@ -31,7 +31,7 @@
# include <ostream>
-# include <oln/core/concept/generalised_point.hh>
+# include <oln/core/concept/generalized_point.hh>
# include <oln/core/concept/iterator.hh>
# include <oln/core/concept/point.hh>
@@ -43,7 +43,7 @@
template <typename Exact>
struct Iterator_on_Points : public Iterator<Exact>,
- virtual public Generalised_Point<Exact>
+ virtual public Generalized_Point<Exact>
{
stc_typename(point);
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 933)
+++ oln/core/concept/point.hh (working copy)
@@ -31,7 +31,7 @@
# include <mlc/value.hh>
-# include <oln/core/concept/generalised_point.hh>
+# include <oln/core/concept/generalized_point.hh>
# include <oln/core/concept/grid.hh>
# include <oln/core/concept/operators.hh>
@@ -47,9 +47,9 @@
/// Concept-class "Point".
template <typename Exact>
- struct Point : public Generalised_Point<Exact>
+ struct Point : public Generalized_Point<Exact>
{
- stc_using_from(Generalised_Point, dpoint);
+ stc_using_from(Generalized_Point, dpoint);
/// Operator ==.
bool op_equal_(const Exact& rhs) const;
Index: oln/core/concept/generalized_point.hh
--- oln/core/concept/generalized_point.hh (revision 933)
+++ oln/core/concept/generalized_point.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
-# define OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
+#ifndef OLN_CORE_CONCEPT_GENERALIZED_POINTS_HH
+# define OLN_CORE_CONCEPT_GENERALIZED_POINTS_HH
# include <oln/core/equipment.hh>
@@ -34,10 +34,10 @@
namespace oln
{
- // Generalised_Point concept
+ // Generalized_Point concept
template <typename Exact>
- struct Generalised_Point : virtual public Any<Exact>
+ struct Generalized_Point : virtual public Any<Exact>
{
stc_typename(grid);
stc_typename(dim);
@@ -47,7 +47,7 @@
enum { n = mlc_value(dim) };
protected:
- Generalised_Point();
+ Generalized_Point();
};
@@ -55,7 +55,7 @@
# ifndef OLN_INCLUDE_ONLY
template <typename Exact>
- Generalised_Point<Exact>::Generalised_Point()
+ Generalized_Point<Exact>::Generalized_Point()
{
}
@@ -63,4 +63,4 @@
} // end of namespace oln
-#endif // ! OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
+#endif // ! OLN_CORE_CONCEPT_GENERALIZED_POINTS_HH
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 933)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CORE_GEN_DPOINTS_PITER_HH
# define OLN_CORE_GEN_DPOINTS_PITER_HH
+# include <oln/core/concept/generalized_point.hh>
# include <oln/core/concept/window.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/concept/image.hh>
@@ -71,16 +72,14 @@
{
public:
- // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
-
template <typename Pl, typename W>
- dpoints_fwd_piter_(const Pl& p, const Window<W>& win);
+ dpoints_fwd_piter_(const Generalized_Point<Pl>& p, const Window<W>& win);
template <typename Pl, typename I>
- dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
+ dpoints_fwd_piter_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima);
template <typename Pl, typename N>
- dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh);
+ dpoints_fwd_piter_(const Generalized_Point<Pl>& p, const Neighborhood<N>& nbh);
}; // end of class oln::dpoints_fwd_piter_<P>
@@ -118,16 +117,14 @@
{
public:
- // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
-
template <typename Pl, typename W>
- dpoints_bkd_piter_(const Pl& p, const Window<W>& win);
+ dpoints_bkd_piter_(const Generalized_Point<Pl>& p, const Window<W>& win);
template <typename Pl, typename I>
- dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
+ dpoints_bkd_piter_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima);
template <typename Pl, typename N>
- dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh);
+ dpoints_bkd_piter_(const Generalized_Point<Pl>& p, const Neighborhood<N>& nbh);
}; // end of class oln::dpoints_bkd_piter_<P>
@@ -139,25 +136,25 @@
template <typename P>
template <typename Pl, typename W>
- dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Window<W>& win)
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Generalized_Point<Pl>& p, const Window<W>& win)
:
- internal::dpoints_fwd_piter_impl_<P>(p, exact(win))
+ internal::dpoints_fwd_piter_impl_<P>(exact(p), exact(win))
{
}
template <typename P>
template <typename Pl, typename I>
- dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima)
:
- internal::dpoints_fwd_piter_impl_<P>(p, ima.nbhood())
+ internal::dpoints_fwd_piter_impl_<P>(exact(p), ima.nbhood())
{
}
template <typename P>
template <typename Pl, typename N>
- dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh)
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Generalized_Point<Pl>& p, const Neighborhood<N>& nbh)
:
- internal::dpoints_fwd_piter_impl_<P>(p, exact(nbh))
+ internal::dpoints_fwd_piter_impl_<P>(exact(p), exact(nbh))
{
}
@@ -165,25 +162,25 @@
template <typename P>
template <typename Pl, typename W>
- dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Window<W>& win)
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Generalized_Point<Pl>& p, const Window<W>& win)
:
- internal::dpoints_bkd_piter_impl_<P>(p, exact(win))
+ internal::dpoints_bkd_piter_impl_<P>(exact(p), exact(win))
{
}
template <typename P>
template <typename Pl, typename I>
- dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima)
:
- internal::dpoints_bkd_piter_impl_<P>(p, ima.nbhood())
+ internal::dpoints_bkd_piter_impl_<P>(exact(p), ima.nbhood())
{
}
template <typename P>
template <typename Pl, typename N>
- dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh)
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Generalized_Point<Pl>& p, const Neighborhood<N>& nbh)
:
- internal::dpoints_bkd_piter_impl_<P>(p, exact(nbh))
+ internal::dpoints_bkd_piter_impl_<P>(exact(p), exact(nbh))
{
}
Index: oln/core/gen/niter_has.hh
--- oln/core/gen/niter_has.hh (revision 933)
+++ oln/core/gen/niter_has.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CORE_GEN_NITER_HAS_HH
# define OLN_CORE_GEN_NITER_HAS_HH
+# include <oln/core/concept/generalized_point.hh>
# include <oln/core/internal/piter_adaptor.hh>
# include <oln/core/gen/dpoints_piter.hh>
@@ -68,10 +69,8 @@
{
public:
- // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
-
template <typename Pl, typename I>
- niter_has_(const Pl& p, const Image_with_Nbh<I>& ima);
+ niter_has_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima);
void impl_start();
void impl_next();
@@ -89,7 +88,7 @@
template <typename It, typename Ps>
template <typename Pl, typename I>
- current::niter_has_(const Pl& p, const Image_with_Nbh<I>& ima)
+ current::niter_has_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>& ima)
:
super( It(p, ima) ),
pset_( ima.points() )
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add reference check.
* mlc/cmp.hh (mlc_is_reference, is_reference_): New.
cmp.hh | 15 +++++++++++++++
1 files changed, 15 insertions(+)
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 932)
+++ mlc/cmp.hh (working copy)
@@ -65,6 +65,7 @@
# define mlc_is_not_builtin(T) mlc::is_not_builtin_< T >
# define mlc_is_const(T) mlc::is_const_< T >
+# define mlc_is_reference(T) mlc::is_reference_< T >
/// \}
@@ -232,6 +233,20 @@
/// \}
+ /// Check whether a type is a reference.
+ /// \{
+ template <typename T>
+ struct is_reference_ : public bexpr_<false>
+ {
+ };
+
+ template <typename T>
+ struct is_reference_< T& > : public bexpr_<true>
+ {
+ };
+ /// \}
+
+
/// Check whether a type is a builtin type.
/// \{
1
0