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
- 9625 discussions
Enjoy!!
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix pnm.hh : image loading (pbm, pgm ...).
* oln/morpho/reconstruction.hh: Up.
* oln/io/pnm.hh: Fixed.
io/pnm.hh | 50 +++++++++++++++++++++++------------------------
morpho/reconstruction.hh | 14 ++++++-------
2 files changed, 32 insertions(+), 32 deletions(-)
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 931)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -41,7 +41,7 @@
template <typename I , typename J>
void
- reconstruction(const Mutable_Image<I>& marker,
+ reconstruction(const Image_with_Nbh<I>& marker,
const Binary_Image<J>& mask);
# ifndef OLN_INCLUDE_ONLY
@@ -51,8 +51,8 @@
template <typename I>
bool
- stability(const Image_with_Nbh<I>& marker,
- const Image_with_Nbh<I>& tmp)
+ stability(Image_with_Nbh<I>& marker,
+ I& tmp)
{
oln_piter(I) p(marker.points());
for_all(p) // FIXME : Concept doesn't own .image()? add != is better
@@ -89,22 +89,22 @@
reconstruction_(const Image_with_Nbh<I>& marker,
const Binary_Image<J>& mask)
{
- oln_plain(I) tmp = level::clone(marker);
+ image2d<int> tmp = level::clone(exact(marker).image());
while ( not stability(marker, tmp) )
{
- level::fill(exact(marker).image(), exact(tmp).image()); //add fill version better.
+ level::fill(marker, tmp);
tmp = reconstruction_loop(marker, mask);
}
- level::fill(exact(marker).image(), exact(tmp).image());
+ level::fill(marker, tmp);
}
} // end of namespace oln::morpho::impl
template <typename I , typename J>
void
- reconstruction(const Mutable_Image<I>& marker,
+ reconstruction(const Image_with_Nbh<I>& marker,
const Binary_Image<J>& mask)
{
impl::reconstruction_(exact(marker), exact(mask));
Index: oln/io/pnm.hh
--- oln/io/pnm.hh (revision 931)
+++ oln/io/pnm.hh (working copy)
@@ -147,7 +147,7 @@
template <typename I>
void load_pnm_ascii(std::ifstream& file, I& ima)
{
- oln_fwd_piter(I) p(ima.topo());
+ oln_fwd_piter(I) p(ima.points());
for_all(p)
{
oln_value(I) value;
@@ -163,10 +163,10 @@
template <typename I>
void load_pnm_raw_2d(std::ifstream& file, I& ima)
{
- int col = ima.col();
- size_t len = ima.bbox().ncols();
- for (int row = ima.pmin().row(); row <= ima.pmax().row(); ++row)
- file.read((char*)(ima.adr_at(row, col)),
+ int col = ima.max_col();
+ size_t len = ima.bbox().pmax().col();
+ for (int row = ima.min_row(); row <= ima.max_row(); ++row)
+ file.read((char*)(ima.at(row, col)),
len * sizeof(oln_value(I)));
}
@@ -196,26 +196,26 @@
}
-// image2d<unsigned char> load_pgm(const std::string& filename)
-// {
-// std::ifstream file(filename.c_str());
-// if (not file)
-// {
-// std::cerr << "error: file '" << filename
-// << "' not found!";
-// abort();
-// }
-// char type;
-// int nrows, ncols;
-// internal::read_pnm_header('2', '5', file, type, nrows, ncols);
-// image2d<unsigned char> ima(nrows, ncols);
-// if (type == '4')
-// internal::load_pnm_raw_2d(file, ima);
-// else
-// // type == '1'
-// internal::load_pnm_ascii(file, ima);
-// return ima;
-// }
+ image2d<unsigned char> load_pgm(const std::string& filename)
+ {
+ std::ifstream file(filename.c_str());
+ if (not file)
+ {
+ std::cerr << "error: file '" << filename
+ << "' not found!";
+ abort();
+ }
+ char type;
+ int nrows, ncols;
+ internal::read_pnm_header('2', '5', file, type, nrows, ncols);
+ image2d<unsigned char> ima(nrows, ncols);
+ if (type == '4')
+ internal::load_pnm_raw_2d(file, ima);
+ else
+ // type == '1'
+ internal::load_pnm_ascii(file, ima);
+ return ima;
+ }
} // end of namespace oln::io
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add the explicit 'inplace' mechanism.
* oln/core/internal/op_image_plus_nbh.hh: Rename as...
* oln/core/internal/op_image_extended_by_nbh.hh: ...this.
* oln/core/gen/inplace.hh: New.
* oln/debug/fill.hh,
* oln/debug/iota.hh,
* oln/level/paste.hh,
* oln/level/apply_inplace.hh,
* oln/core/gen/safe_image.hh: Update.
* oln/core/gen/op.hh (plus): Rename as...
(extended_by): ...this; less ambiguous.
(oln_decl_inplace_image_op): New.
* oln/core/internal/op_image_such_as_fp2b.hh: Fix temp hack;
precisely, replace inheritance by delegation.
* oln/core/internal/image_base.hh (oln_possible_lvalue): New.
(possible_lvalue_from_): New.
* oln/core/gen/neighb.hh,
* oln/core/internal/image_ops.hh,
* oln/core/internal/op_image_restricted_to_pset.hh,
* oln/draw/bresenham.hh: Update.
* TODO: Update.
TODO | 6 -
oln/core/gen/inplace.hh | 97 +++++++++++++++++++++++
oln/core/gen/neighb.hh | 4
oln/core/gen/op.hh | 21 ++++
oln/core/gen/safe_image.hh | 25 ++++-
oln/core/internal/image_base.hh | 13 +++
oln/core/internal/image_ops.hh | 36 +++++++-
oln/core/internal/op_image_extended_by_nbh.hh | 26 +++---
oln/core/internal/op_image_restricted_to_pset.hh | 5 -
oln/core/internal/op_image_such_as_fp2b.hh | 37 +++++++-
oln/debug/fill.hh | 18 +++-
oln/debug/iota.hh | 16 +++
oln/draw/bresenham.hh | 23 ++++-
oln/level/apply_inplace.hh | 49 +++++++----
oln/level/paste.hh | 10 ++
15 files changed, 319 insertions(+), 67 deletions(-)
Index: TODO
--- TODO (revision 930)
+++ TODO (working copy)
@@ -26,19 +26,13 @@
draw routines
-window types such as lines, rectangles, and so on
-
meta-window type; for instance, ball, segment, etc.
-provide "- win" for morpho::opening and morpho::closing.
-
const promotions for op_<L,O,R> types + result is Mutable only
if the underlying type is not 'const'
in image_identity.hh use 'current'
-provide arith::minus et al. with explicit output type
-
use Generalized_Point when possible
Index: oln/debug/fill.hh
--- oln/debug/fill.hh (revision 930)
+++ oln/debug/fill.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_DEBUG_FILL_HH
# include <oln/core/concept/image.hh>
+# include <oln/core/gen/inplace.hh>
namespace oln
@@ -38,17 +39,26 @@
{
template <typename I, typename V>
- void fill(Mutable_Image<I>& input, const V values[]);
+ void fill(Mutable_Image<I>& in_out, const V values[]);
+
+ template <typename I, typename V>
+ void fill(inplace_<I> in_out, const V values[]);
# ifndef OLN_INCLUDE_ONLY
template <typename I>
- void fill(Mutable_Image<I>& input, const oln_value(I)& value)
+ void fill(Mutable_Image<I>& in_out, const oln_value(I)& value)
{
- oln_piter(I) p(input.points());
+ oln_piter(I) p(in_out.points());
for_all(p)
- input(p) = value;
+ in_out(p) = value;
+ }
+
+ template <typename I, typename V>
+ void fill(inplace_<I> in_out, const V values[])
+ {
+ fill(in_out.unwrap(), values);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/debug/iota.hh
--- oln/debug/iota.hh (revision 930)
+++ oln/debug/iota.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_DEBUG_IOTA_HH
# include <oln/core/concept/image.hh>
+# include <oln/core/gen/inplace.hh>
namespace oln
@@ -37,6 +38,14 @@
namespace debug
{
+ template <typename I>
+ void iota(Mutable_Image<I>& in_out);
+
+ template <typename I>
+ void iota(inplace_<I> in_out);
+
+
+# ifndef OLN_INCLUDE_ONLY
template <typename I>
void iota(Mutable_Image<I>& in_out)
@@ -47,6 +56,13 @@
in_out(p) = v++;
}
+ template <typename I>
+ void iota(inplace_<I> in_out)
+ {
+ iota(in_out.unwrap());
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::debug
Index: oln/core/gen/neighb.hh
--- oln/core/gen/neighb.hh (revision 930)
+++ oln/core/gen/neighb.hh (working copy)
@@ -31,7 +31,7 @@
# include <oln/core/internal/dpoints_impl.hh>
# include <oln/core/internal/neighborhood_base.hh>
-# include <oln/core/internal/op_image_plus_nbh.hh>
+# include <oln/core/internal/op_image_extended_by_nbh.hh>
namespace oln
@@ -39,7 +39,7 @@
// Op.
- oln_decl_op_plus(Image, Neighborhood);
+ oln_decl_op_extended_by(Image, Neighborhood);
Index: oln/core/gen/inplace.hh
--- oln/core/gen/inplace.hh (revision 0)
+++ oln/core/gen/inplace.hh (revision 0)
@@ -0,0 +1,97 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_GEN_INPLACE_HH
+# define OLN_CORE_GEN_INPLACE_HH
+
+# include <oln/core/concept/image.hh>
+
+
+namespace oln
+{
+
+
+ template <typename I>
+ class inplace_ : private mlc::assert_< mlc_is_a(I, Mutable_Image) >
+ {
+ typedef inplace_<I> current;
+ public:
+
+ inplace_(I& ima);
+
+ I& unwrap() const; // explicit
+ operator I() const; // implicit
+
+ private:
+ I ima_;
+ };
+
+
+
+ template <typename I>
+ inplace_<I>
+ inplace(const Mutable_Image<I>& ima);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ inplace_<I>::inplace_(I& ima)
+ : ima_(ima)
+ {
+ }
+
+ template <typename I>
+ I&
+ inplace_<I>::unwrap() const
+ {
+ current* this_ = const_cast<current*>(this);
+ return this_->ima_;
+ }
+
+ template <typename I>
+ inplace_<I>::operator I() const
+ {
+ return this->unwrap();
+ }
+
+ template <typename I>
+ inplace_<I>
+ inplace(const Mutable_Image<I>& ima)
+ {
+ I& ima_ = const_cast<I&>(exact(ima));
+ inplace_<I> tmp(ima_);
+ return tmp;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_INPLACE_HH
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 930)
+++ oln/core/gen/op.hh (working copy)
@@ -32,6 +32,7 @@
# include <oln/core/internal/category_of.hh>
# include <oln/core/concept/function.hh>
# include <oln/core/concept/value.hh>
+# include <oln/core/gen/inplace.hh>
@@ -74,7 +75,23 @@
struct e_n_d___w_i_t_h___a___s_e_m_i___c_o_l_u_m_n
-# define oln_decl_op_plus(Lconcept, Rconcept) oln_decl_op_( plus, Lconcept, +, Rconcept)
+
+# define oln_decl_inplace_image_op(OpName, OpSym, Rconcept) \
+ \
+ template <typename L, typename R> \
+ inplace_< op_<L, OpName, R> > \
+ 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)); \
+ return inplace(tmp); \
+ } \
+ \
+ struct e_n_d___w_i_t_h___a___s_e_m_i___c_o_l_u_m_n
+
+
+
+# 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)
# define oln_decl_op_over(Lconcept, Rconcept) oln_decl_op_( over, Lconcept, /, Rconcept)
@@ -89,7 +106,7 @@
/// \{
/// Operator Names.
- struct plus;
+ struct extended_by;
struct such_as;
struct restricted_to;
struct over;
Index: oln/core/gen/safe_image.hh
--- oln/core/gen/safe_image.hh (revision 930)
+++ oln/core/gen/safe_image.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/gen/infty_pset.hh>
+# include <oln/core/gen/inplace.hh>
namespace oln
@@ -100,11 +101,10 @@
template <typename I>
- safe_image<I> safe(Mutable_Image<I>& ima)
- {
- safe_image<I> tmp(ima);
- return tmp;
- }
+ safe_image<I> safe(Mutable_Image<I>& ima);
+
+ template <typename I>
+ inplace_< safe_image<I> > safe(inplace_<I> ima);
@@ -192,6 +192,21 @@
return this->data_->value;
}
+ template <typename I>
+ safe_image<I> safe(Mutable_Image<I>& ima)
+ {
+ safe_image<I> tmp(ima);
+ return tmp;
+ }
+
+ template <typename I>
+ inplace_< safe_image<I> > safe(inplace_<I> ima)
+ {
+ safe_image<I> tmp_ = safe(ima.unwrap());
+ inplace_< safe_image<I> > tmp(tmp_);
+ return tmp;
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/op_image_such_as_fp2b.hh
--- oln/core/internal/op_image_such_as_fp2b.hh (revision 930)
+++ oln/core/internal/op_image_such_as_fp2b.hh (working copy)
@@ -48,8 +48,7 @@
template <typename I, typename F>
struct super_trait_< internal::current >
{
- typedef op_< const oln_pset(I), such_as, F > S;
- typedef internal::special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, const S > ret;
+ typedef internal::image_extension_< op_<I, such_as, F> > ret;
};
@@ -61,6 +60,15 @@
template <typename I, typename F>
struct vtypes< internal::current >
{
+ typedef op_< const oln_pset(I), such_as, F > S__;
+ typedef op_< I, restricted_to, const S__ > delegatee;
+
+ typedef internal::singleton<delegatee> data;
+
+ typedef oln_point(I) point;
+ typedef oln_possible_lvalue(I) lvalue;
+ typedef op_<oln_plain(I), such_as, F> plain;
+ typedef op_<pl::rec<I>, such_as, F> skeleton;
};
@@ -74,8 +82,11 @@
{
public:
- stc_using(point);
- stc_using(box);
+ stc_using(delegatee);
+ stc_using(data);
+
+ delegatee& impl_image();
+ const delegatee& impl_image() const;
protected:
special_op_();
@@ -92,8 +103,24 @@
template <typename I, typename F>
current::special_op_(I& ima, F& f)
- : super(ima, (ima.points() | f))
{
+ this->data_ = new data( ima | (ima.points() | f) );
+ }
+
+ template <typename I, typename F>
+ typename current::delegatee&
+ current::impl_image()
+ {
+ assert(this->has_data());
+ return this->data_->value;
+ }
+
+ template <typename I, typename F>
+ const typename current::delegatee&
+ current::impl_image() const
+ {
+ assert(this->has_data());
+ return this->data_->value;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/internal/image_ops.hh
--- oln/core/internal/image_ops.hh (revision 930)
+++ oln/core/internal/image_ops.hh (working copy)
@@ -32,21 +32,25 @@
# 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/gen/literal.hh>
namespace oln
{
+ // FIXME: when L is Image the "non-const" version should feature Mutable_Image
+
// Image | Point_Set ( ima restricted_to pset )
oln_decl_op_restricted_to(Image, Point_Set);
-
+ oln_decl_inplace_image_op(restricted_to, |, Point_Set);
// Image | Function_p2b ( ima such_as "f : p -> b"
// is ima restricted_to (ima.points such_as f) )
oln_decl_op_such_as(Image, Function_p2b);
+ oln_decl_inplace_image_op(such_as, |, Function_p2b);
@@ -70,7 +74,16 @@
return tmp;
}
- // FIXME: Add "literal / point set"...
+ // Specialisation "literal T over Point_Set".
+
+ template <typename V, typename S>
+ op_<const lit_p2v_<oln_point(S), V>, over, const S>
+ operator / (const literal_<V>& value, const Point_Set<S>& pts)
+ {
+ lit_p2v_<oln_point(S), V> lit(value);
+ op_<const lit_p2v_<oln_point(S), V>, over, const S> tmp(lit, exact(pts));
+ return tmp;
+ }
@@ -89,7 +102,7 @@
template <typename I, typename B, typename P>
op_<I, such_as, const fun_p2b_<B (*)(P)> >
- operator | (Image<I>& ima, B (*f)(P))
+ operator | (Mutable_Image<I>& ima, B (*f)(P))
{
typedef oln_strip_(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
@@ -98,6 +111,13 @@
return tmp;
}
+ template <typename I, typename B, typename P>
+ inplace_< op_<I, such_as, const fun_p2b_<B (*)(P)> > >
+ operator | (inplace_<I> ima, B (*f)(P))
+ {
+ return inplace(ima.unwrap() | f);
+ }
+
// Specialization "Image such_as ima : P -> B".
@@ -113,7 +133,7 @@
template <typename I, typename J>
op_<I, such_as, const fun_p2b_< Binary_Image<J> > >
- operator | (Image<I>& ima, const Binary_Image<J>& f_ima_b)
+ operator | (Mutable_Image<I>& ima, const Binary_Image<J>& f_ima_b)
{
precondition(f_ima_b.points() >= ima.points());
mlc::assert_equal_< oln_point(I), oln_point(J) >::check();
@@ -121,8 +141,12 @@
return tmp;
}
-
- // FIXME: What about Mutable_Image so that "ima | something" can be left-value?
+ template <typename I, typename J>
+ 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);
+ }
} // end of namespace oln
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 930)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -52,12 +52,11 @@
template <typename I, typename S>
struct vtypes< internal::current >
{
- typedef op_<I, restricted_to, S> Exact;
- typedef stc_type(I, point) point__;
-
typedef I delegatee;
typedef internal::pair<I,S> data;
+ typedef oln_possible_lvalue(I) lvalue;
+
typedef S pset;
typedef op_<oln_plain(I), restricted_to, S> plain;
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 930)
+++ oln/core/internal/image_base.hh (working copy)
@@ -36,6 +36,10 @@
# include <oln/core/gen/box.hh>
+# define oln_possible_lvalue(I) \
+ typename internal::possible_lvalue_from_< I >::ret
+
+
namespace oln
{
@@ -266,6 +270,15 @@
};
+ template <typename I>
+ struct possible_lvalue_from_
+ {
+ typedef typename mlc::if_< mlc_is_const(I),
+ stc::not_delegated,
+ stc_find_type(I, lvalue) >::ret ret;
+ };
+
+
/// single_image_morpher_<Exact>
template <typename Exact>
Index: oln/core/internal/op_image_extended_by_nbh.hh
--- oln/core/internal/op_image_extended_by_nbh.hh (revision 929)
+++ oln/core/internal/op_image_extended_by_nbh.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
-# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
+#ifndef OLN_CORE_INTERNAL_OP_IMAGE_EXTENDED_BY_NBH_HH
+# define OLN_CORE_INTERNAL_OP_IMAGE_EXTENDED_BY_NBH_HH
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/internal/image_base.hh>
@@ -39,7 +39,7 @@
{
# define current \
- special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N >
+ special_op_< stc::is<Image>, I, extended_by, stc::is<Neighborhood>, N >
// Instant value.
oln_decl_instant_value(nbh);
@@ -54,7 +54,7 @@
template <typename I, typename N>
struct super_trait_< internal::current >
{
- typedef internal::image_extension_< op_<I, plus, N> > ret;
+ typedef internal::image_extension_< op_<I, extended_by, N> > ret;
};
@@ -62,19 +62,21 @@
template <typename I, typename N>
struct vtypes< internal::current >
{
- typedef op_<I, plus, N> Exact;
+ typedef op_<I, extended_by, N> Exact;
typedef I delegatee;
typedef internal::pair<I,N> data;
typedef N nbh;
+ typedef oln_possible_lvalue(I) lvalue;
+
// FIXME: Wrong!
typedef niter_has_< dpoints_fwd_piter_<oln_point(I)>, oln_pset(I) > fwd_niter;
typedef niter_has_< dpoints_bkd_piter_<oln_point(I)>, oln_pset(I) > bkd_niter;
- typedef op_<oln_plain(I), plus, N> plain;
- typedef op_<pl::rec<I>, plus, N> skeleton;
+ typedef op_<oln_plain(I), extended_by, N> plain;
+ typedef op_<pl::rec<I>, extended_by, N> skeleton;
};
@@ -86,10 +88,10 @@
template <typename I, typename N>
class current
:
- public internal::image_extension_< op_<I, plus, N> >,
+ public internal::image_extension_< op_<I, extended_by, N> >,
private mlc::assert_< mlc_is_not_a(I, Image_with_Nbh) > // FIXME: Add err msg.
{
- typedef internal::image_extension_< op_<I, plus, N> > super;
+ typedef internal::image_extension_< op_<I, extended_by, N> > super;
public:
stc_using(nbh);
stc_using(data);
@@ -202,7 +204,7 @@
bool init_(internal::current* this_, const D& dat)
{
precondition(not this_->has_data());
- this_->data__() = new typename op_<I, plus, N>::data;
+ this_->data__() = new typename op_<I, extended_by, N>::data;
bool ima_ok = init(this_->data__()->first, with, dat);
bool nbh_ok = init(this_->data__()->second, with, dat);
postcondition(ima_ok);
@@ -216,7 +218,7 @@
bool prepare(internal::current& target, with_t, const D& dat)
{
precondition(not target.has_data());
- target.data__() = new typename op_<I, plus, N>::data;
+ target.data__() = new typename op_<I, extended_by, N>::data;
bool ima_ok = prepare(target.data__()->first, with, dat);
bool nbh_ok = init(target.data__()->second, with, dat);
postcondition(ima_ok);
@@ -231,4 +233,4 @@
} // end of namespace oln
-#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
+#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_EXTENDED_BY_NBH_HH
Index: oln/draw/bresenham.hh
--- oln/draw/bresenham.hh (revision 930)
+++ oln/draw/bresenham.hh (working copy)
@@ -29,8 +29,8 @@
# define OLN_DRAW_BRESENHAM_HH
# include <oln/core/concept/image.hh>
+# include <oln/core/gen/inplace.hh>
# include <oln/core/2d/line2d.hh>
-# include <oln/core/gen/single_value_image.hh>
# include <oln/level/paste.hh>
@@ -48,6 +48,11 @@
const oln_point(I)& begin, const oln_point(I)& end,
const oln_value(I)& value);
+ template <typename I>
+ void bresenham(inplace_<I> in_out,
+ const oln_point(I)& begin, const oln_point(I)& end,
+ const oln_value(I)& value);
+
# ifndef OLN_INCLUDE_ONLY
@@ -59,15 +64,13 @@
const oln_point(I)& begin, const oln_point(I)& end,
const oln_value(I)& value)
{
- line2d line(begin, end);
- single_value_image<line2d, oln_value(I)> line_image(line, value);
- level::paste(line_image, in_out);
- // FIXME: Make it as simple as level::paste(line2d(begin, end) + value, in_out);
+ level::paste(literal(value) / line2d(begin, end), in_out);
}
} // end of namespace oln::draw::impl
- // Facade.
+
+ // Facades.
template <typename I>
void bresenham(Mutable_Image<I>& in_out,
@@ -77,6 +80,14 @@
impl::bresenham_(exact(in_out), begin, end, value);
}
+ template <typename I>
+ void bresenham(inplace_<I> in_out,
+ const oln_point(I)& begin, const oln_point(I)& end,
+ const oln_value(I)& value)
+ {
+ bresenham(in_out.unwrap(), begin, end, value);
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::draw
Index: oln/level/paste.hh
--- oln/level/paste.hh (revision 930)
+++ oln/level/paste.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_LEVEL_PASTE_HH
# include <oln/core/concept/image.hh>
+# include <oln/core/gen/inplace.hh>
namespace oln
@@ -42,6 +43,9 @@
template <typename I, typename J>
void paste(const Image<I>& data, /* in */ Mutable_Image<J>& destination);
+ template <typename I, typename J>
+ void paste(const Image<I>& data, /* in */ inplace_<J> destination);
+
# ifndef OLN_INCLUDE_ONLY
@@ -73,6 +77,12 @@
impl::paste_(exact(data), exact(destination));
}
+ template <typename I, typename J>
+ void paste(const Image<I>& data, /* in */ inplace_<J> destination)
+ {
+ paste(data, destination.unwrap());
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::level
Index: oln/level/apply_inplace.hh
--- oln/level/apply_inplace.hh (revision 930)
+++ oln/level/apply_inplace.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/concept/image.hh>
# include <oln/core/gen/fun.hh>
+# include <oln/core/gen/inplace.hh>
namespace oln
@@ -41,12 +42,19 @@
/// Fwd decls.
template <typename F, typename I>
- void
- apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input);
+ void apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& in_out);
template <typename R, typename A, typename I>
- void
- apply_inplace(R (*f)(A), Mutable_Image<I>& input);
+ void apply_inplace(R (*f)(A), Mutable_Image<I>& in_out);
+
+
+ // for images created on the fly
+
+ template <typename F, typename I>
+ void apply_inplace(const Function_v2v<F>& f, inplace_<I> in_out);
+
+ template <typename R, typename A, typename I>
+ void apply_inplace(R (*f)(A), inplace_<I> in_out);
# ifndef OLN_INCLUDE_ONLY
@@ -57,13 +65,12 @@
// Generic version.
template <typename F, typename I>
- void
- apply_inplace_(const F& f, Mutable_Image<I>& input)
+ void apply_inplace_(const F& f, Mutable_Image<I>& in_out)
{
- oln_piter(I) p(input.points());
+ oln_piter(I) p(in_out.points());
for_all(p)
- input(p) = f(input(p));
- // FIXME: input(p) = static_cast<oln_value(I)>( f_( static_cast<oln_argument(F)>(input(p)) ) );
+ in_out(p) = f(in_out(p));
+ // FIXME: in_out(p) = static_cast<oln_value(I)>( f_( static_cast<oln_argument(F)>(in_out(p)) ) );
}
@@ -73,20 +80,30 @@
/// Facades.
template <typename F, typename I>
- void
- apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
+ void apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& in_out)
+ {
+ impl::apply_inplace_(exact(f), exact(in_out));
+ }
+
+ template <typename R, typename A, typename I>
+ void apply_inplace(R (*f)(A), Mutable_Image<I>& in_out)
+ {
+ impl::apply_inplace_(functorize_v2v(f), exact(in_out));
+ }
+
+ template <typename F, typename I>
+ void apply_inplace(const Function_v2v<F>& f, inplace_<I> in_out)
{
- impl::apply_inplace_(exact(f), exact(input));
+ apply_inplace(f, in_out.unwrap());
}
template <typename R, typename A, typename I>
- void
- apply_inplace(R (*f)(A), Mutable_Image<I>& input)
+ void apply_inplace(R (*f)(A), inplace_<I> in_out)
{
- impl::apply_inplace_(functorize_v2v(f), exact(input));
+ apply_inplace(f, in_out.unwrap());
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::level
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add constness check.
* mlc/cmp.hh (mlc_is_const, is_const_): New.
cmp.hh | 15 +++++++++++++++
1 files changed, 15 insertions(+)
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 929)
+++ mlc/cmp.hh (working copy)
@@ -64,6 +64,8 @@
# define mlc_is_builtin(T) mlc::is_builtin_< T >
# define mlc_is_not_builtin(T) mlc::is_not_builtin_< T >
+# define mlc_is_const(T) mlc::is_const_< T >
+
/// \}
@@ -216,6 +218,19 @@
/// \}
+ /// Check whether a type is const.
+ /// \{
+ template <typename T>
+ struct is_const_ : public bexpr_<false>
+ {
+ };
+
+ template <typename T>
+ struct is_const_ <const T> : public bexpr_<true>
+ {
+ };
+ /// \}
+
/// Check whether a type is a builtin type.
/// \{
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Add local_sup/inf. Fix clone. Update Reconstruction.
* oln/morpho/reconstruction.hh,
* oln/morpho/cc_tarjan.hh: Updated.
* oln/level/local_sup.hh: New.
* oln/level/local_inf.hh: New.
* oln/level/clone.hh: Fixed.
level/clone.hh | 14 +--
level/local_inf.hh | 219 +++++++++++++++++++++++++++++++++++++++++++++++
level/local_sup.hh | 219 +++++++++++++++++++++++++++++++++++++++++++++++
morpho/cc_tarjan.hh | 10 +-
morpho/reconstruction.hh | 70 +++++++++++----
5 files changed, 507 insertions(+), 25 deletions(-)
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 928)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -30,7 +30,8 @@
# include <oln/core/concept/image.hh>
# include <oln/accumulator/max.hh>
-
+# include <oln/level/clone.hh>
+# include <oln/level/fill.hh>
namespace oln
{
@@ -38,36 +39,75 @@
namespace morpho
{
+ template <typename I , typename J>
+ void
+ reconstruction(const Mutable_Image<I>& marker,
+ const Binary_Image<J>& mask);
+
+# ifndef OLN_INCLUDE_ONLY
+
namespace impl
{
- template <typename I , typename J>
- void // FIXME : slow version.
- reconstruction_(const Image_with_Nbh<I>& marker,
+ template <typename I>
+ bool
+ stability(const Image_with_Nbh<I>& marker,
+ const Image_with_Nbh<I>& tmp)
+ {
+ oln_piter(I) p(marker.points());
+ for_all(p) // FIXME : Concept doesn't own .image()? add != is better
+ if (exact(marker).image()(p) != exact(tmp).image()(p))
+ return false;
+ return true;
+ }
+
+ template <typename I>
+ oln_plain(I)
+ reconstruction_loop(const Image_with_Nbh<I>& marker,
const Binary_Image<I>& mask)
{
- // first
- oln_fwd_piter(I) p(input.points());
- for_all(p)
- marker(p) = local(max, marker, p) and mask(p); // FIXME : local_sup.
+ oln_plain(I) output;
+ prepare(output, with, marker);
+ accumulator::max_<oln_value(I)> max;
- // second
- oln_bkd_piter(I) p(input.points());
+ // first pass
+ oln_fwd_piter(I) p(marker.points());
for_all(p)
- marker(p) = local(max, marker, p) and mask(p); // FIXME : local_inf.
+ output(p) = local_sup(max, marker, p) and mask(p);
+
+ // second pass
+ oln_bkd_piter(I) p2(marker.points());
+ for_all(p2)
+ output(p2) = local_inf(max, marker, p2) and mask(p2);
+
+ return output;
+ }
+
+ template <typename I , typename J>
+ void // FIXME : Slow impl.
+ reconstruction_(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) tmp = level::clone(marker);
+
+ while ( not stability(marker, tmp) )
+ {
+ level::fill(exact(marker).image(), exact(tmp).image()); //add fill version better.
+ tmp = reconstruction_loop(marker, mask);
+ }
+
+ level::fill(exact(marker).image(), exact(tmp).image());
}
} // end of namespace oln::morpho::impl
template <typename I , typename J>
void
- reconstruction(const Image_with_Nbh<I>& marker,
+ reconstruction(const Mutable_Image<I>& marker,
const Binary_Image<J>& mask)
{
- impl::reconstruction_(exact(mask), exact(marker));
- }
-
+ impl::reconstruction_(exact(marker), exact(mask));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 928)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -29,8 +29,6 @@
# define OLN_MORPHO_CC_TARJAN_HH
# include <oln/core/concept/image.hh>
-# include <oln/debug/print.hh>
-
namespace oln
{
@@ -38,6 +36,12 @@
namespace morpho
{
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Binary_Image<I>& input);
+
+# ifndef OLN_INCLUDE_ONLY
+
namespace impl
{
template <typename I>
@@ -134,6 +138,8 @@
return impl::cc_tarjan_(exact(input));
}
+# endif // ! OLN_INCLUDE_ONLY
+
} // end of namespace oln::morpho
} // end of namespace oln
Index: oln/level/local_sup.hh
--- oln/level/local_sup.hh (revision 0)
+++ oln/level/local_sup.hh (revision 0)
@@ -0,0 +1,219 @@
+// 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_LEVEL_LOCAL_SUP_HH
+# define OLN_LEVEL_LOCAL_SUP_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/concept/window.hh>
+# include <oln/core/concept/accumulator.hh>
+# include <oln/accumulator/or.hh>
+# include <oln/accumulator/and.hh>
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ template <typename A, typename I>
+ typename A::result
+ local_sup(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p);
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_sup(const Accumulator<A>& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /// Neigborhood.
+
+ // Generic version with neighborhood.
+
+ template <typename A, typename I>
+ typename A::result
+ local_sup_(const A& f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input);
+ for_all(n)
+ if (n > p)
+ f(input(n));
+ return f.value();
+ }
+
+ // Optimised version for OR operator with neighborhood.
+
+ template <typename B, typename I>
+ B
+ local_sup_(const oln::accumulator::or_<B>& f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ if (f.value() == true)
+ return true;
+ oln_niter(I) n(p, input);
+ for_all(n)
+ if (n > p)
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() == true)
+ return true;
+ }
+ return f.value();
+ }
+
+ // Optimised version for AND operator with neighborhood.
+
+ template <typename B, typename I>
+ B
+ local_sup_(const accumulator::and_< B > f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input);
+ for_all(n)
+ if (n > p)
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() == false)
+ return false;
+ }
+ return f.value();
+ }
+
+ // FIXME: Generic version with nbh given as argument?
+
+
+
+ /// On Window.
+
+ // Generic version with window.
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_sup_(const A& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init_with(input(p));
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (q > p)
+ if (input.owns_(q))
+ f(input(q));
+ return f.value();
+ }
+
+ // Optimised version for OR operator with window.
+
+ template <typename B, typename I, typename W>
+ B
+ local_sup_(const oln::accumulator::or_<B>& f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init_with(input(p));
+ if (f.value() == true)
+ return true;
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (q > p)
+ {
+ if (input.owns_(q))
+ f(input(q));
+ if (f.value() == true)
+ return true;
+ }
+ return f.value();
+ }
+
+ // Optimised version for AND operator with window.
+
+ template <typename B, typename I, typename W>
+ B
+ local_sup_(const accumulator::and_< B > f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init_with(input(p));
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (q > p)
+ {
+ if (input.owns_(q))
+ f(input(q));
+ if (f.value() == false)
+ return false;
+ }
+ return f.value();
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ // Facades.
+
+ template <typename A, typename I>
+ typename A::result
+ local_sup(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p)
+ {
+ mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check();
+ return impl::local_sup_(exact(f), exact(input), p);
+ }
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_sup(const Accumulator<A>& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ return impl::local_sup_(exact(f), exact(input), p, exact(win));
+ }
+
+#endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+#endif // ! OLN_LEVEL_LOCAL_SUP_HH
Index: oln/level/local_inf.hh
--- oln/level/local_inf.hh (revision 0)
+++ oln/level/local_inf.hh (revision 0)
@@ -0,0 +1,219 @@
+// 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_LEVEL_LOCAL_INF_HH
+# define OLN_LEVEL_LOCAL_INF_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/concept/window.hh>
+# include <oln/core/concept/accumulator.hh>
+# include <oln/accumulator/or.hh>
+# include <oln/accumulator/and.hh>
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ template <typename A, typename I>
+ typename A::result
+ local_inf(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p);
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_inf(const Accumulator<A>& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /// Neigborhood.
+
+ // Generic version with neighborhood.
+
+ template <typename A, typename I>
+ typename A::result
+ local_inf_(const A& f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input);
+ for_all(n)
+ if (n < p)
+ f(input(n));
+ return f.value();
+ }
+
+ // Optimised version for OR operator with neighborhood.
+
+ template <typename B, typename I>
+ B
+ local_inf_(const oln::accumulator::or_<B>& f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ if (f.value() == true)
+ return true;
+ oln_niter(I) n(p, input);
+ for_all(n)
+ if (n < p)
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() == true)
+ return true;
+ }
+ return f.value();
+ }
+
+ // Optimised version for AND operator with neighborhood.
+
+ template <typename B, typename I>
+ B
+ local_inf_(const accumulator::and_<B> f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input);
+ for_all(n)
+ if (n < p)
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() == false)
+ return false;
+ }
+ return f.value();
+ }
+
+ // FIXME: Generic version with nbh given as argument?
+
+
+
+ /// On Window.
+
+ // Generic version with window.
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_inf_(const A& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init_with(input(p));
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (q < p)
+ if (input.owns_(q))
+ f(input(q));
+ return f.value();
+ }
+
+ // Optimised version for OR operator with window.
+
+ template <typename B, typename I, typename W>
+ B
+ local_inf_(const oln::accumulator::or_<B>& f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init_with(input(p));
+ if (f.value() == true)
+ return true;
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (q < p)
+ {
+ if (input.owns_(q))
+ f(input(q));
+ if (f.value() == true)
+ return true;
+ }
+ return f.value();
+ }
+
+ // Optimised version for AND operator with window.
+
+ template <typename B, typename I, typename W>
+ B
+ local_inf_(const accumulator::and_< B > f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init_with(input(p));
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (q < p)
+ {
+ if (input.owns_(q))
+ f(input(q));
+ if (f.value() == false)
+ return false;
+ }
+ return f.value();
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ // Facades.
+
+ template <typename A, typename I>
+ typename A::result
+ local_inf(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p)
+ {
+ mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check();
+ return impl::local_inf_(exact(f), exact(input), p);
+ }
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_inf(const Accumulator<A>& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ return impl::local_inf_(exact(f), exact(input), p, exact(win));
+ }
+
+#endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+#endif // ! OLN_LEVEL_LOCAL_INF_HH
Index: oln/level/clone.hh
--- oln/level/clone.hh (revision 928)
+++ oln/level/clone.hh (working copy)
@@ -29,9 +29,7 @@
#ifndef OLN_LEVEL_CLONE_HH
# define OLN_LEVEL_CLONE_HH
-# include <oln/core/abstract/image.hh>
-# include <oln/core/abstract/iterator.hh>
-
+# include <oln/core/concept/image.hh>
namespace oln
{
@@ -41,7 +39,7 @@
/// Fwd decl.
template <typename I>
- oln_plain(I) clone(const abstract::image<I>& input);
+ oln_plain(I) clone(const Image<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -51,10 +49,10 @@
/// Generic version.
template <typename I>
- oln_plain(I) clone(const abstract::image<I>& input)
+ oln_plain(I) clone(const Image<I>& input)
{
- oln_plain(I) output(input.topo());
- oln_piter(I) p(input.topo());
+ oln_plain(I) output(input.points());
+ oln_piter(I) p(input.points());
for_all(p)
output(p) = input(p);
return output;
@@ -65,7 +63,7 @@
/// Facade.
template <typename I>
- oln_plain(I) clone(const abstract::image<I>& input)
+ oln_plain(I) clone(const Image<I>& input)
{
return impl::clone(input);
}
1
0
02 Apr '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some 2d window types and refactor window impl hierarchy.
* oln/core/2d/vline2d.hh,
* oln/core/2d/hline2d.hh,
* oln/core/2d/rectangle2d.hh,
* oln/core/internal/window.hh: New.
* oln/core/concept/window.hh (op_unary_minus_): New.
* oln/core/gen/dpoints_piter.hh: Cosmetic change.
* oln/core/gen/window.hh (window_): Rename as...
(gen_window): ...this and inherit from internal::window_.
(fwd_qiter, bkd_qiter, take, impl_op_unary_minus_): Move to...
(internal::window_): ...here.
* oln/core/2d/window2d.hh (window2d): Replace window_ by
gen_window.
* oln/core/internal/window_base.hh (point): New.
* oln/morpho/closing.hh,
* oln/morpho/opening.hh: Fix.
* oln/morpho/erosion.hh (erosion_on_function_): New version on
rectangle2d.
core/2d/hline2d.hh | 94 ++++++++++++++++++++++++++++++++++
core/2d/rectangle2d.hh | 116 +++++++++++++++++++++++++++++++++++++++++++
core/2d/vline2d.hh | 101 +++++++++++++++++++++++++++++++++++++
core/2d/window2d.hh | 27 ++++------
core/concept/window.hh | 11 +++-
core/gen/dpoints_piter.hh | 2
core/gen/window.hh | 55 +++++---------------
core/internal/window.hh | 116 +++++++++++++++++++++++++++++++++++++++++++
core/internal/window_base.hh | 7 +-
morpho/closing.hh | 2
morpho/erosion.hh | 23 +++++++-
morpho/opening.hh | 2
12 files changed, 492 insertions(+), 64 deletions(-)
Index: oln/core/concept/window.hh
--- oln/core/concept/window.hh (revision 927)
+++ oln/core/concept/window.hh (working copy)
@@ -47,6 +47,8 @@
stc_typename(fwd_qiter);
stc_typename(bkd_qiter);
+ Exact op_unary_minus_() const;
+
protected:
Window();
@@ -61,7 +63,14 @@
{
}
-# endif
+ template <typename Exact>
+ Exact
+ Window<Exact>::op_unary_minus_() const
+ {
+ return exact(this)->impl_op_unary_minus_();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/vline2d.hh
--- oln/core/2d/vline2d.hh (revision 0)
+++ oln/core/2d/vline2d.hh (revision 0)
@@ -0,0 +1,101 @@
+// 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_2D_VLINE2D_HH
+# define OLN_CORE_2D_VLINE2D_HH
+
+# include <oln/core/internal/window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ class vline2d;
+
+
+ // Super type.
+ template <>
+ struct super_trait_< vline2d >
+ {
+ typedef internal::window_<vline2d> ret;
+ };
+
+
+ // Virtual types.
+ template <>
+ struct vtypes< vline2d >
+ {
+ typedef point2d point;
+ };
+
+
+ /// 2D vertical line window.
+
+ class vline2d : public internal::window_< vline2d >
+ {
+ public:
+
+ vline2d(unsigned half_length);
+ vline2d(int drow_min, int drow_max);
+
+ private:
+ void init_(int drow_min, int drow_max);
+ void take(); // safety; w/o impl, it provides from calling super::take(dp).
+
+ }; // end of class oln::vline2d
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ vline2d::vline2d(unsigned half_length)
+ {
+ precondition(half_length > 0);
+ this->init_(- half_length, half_length);
+ }
+
+ vline2d::vline2d(int drow_min, int drow_max)
+ {
+ precondition(drow_max > drow_min);
+ this->init_(drow_min, drow_max);
+ }
+
+ void
+ vline2d::init_(int drow_min, int drow_max)
+ {
+ for (int drow = drow_min; drow <= drow_max; ++drow)
+ this->internal::window_<vline2d>::take(dpoint2d(drow, 0));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_VLINE2D_HH
Index: oln/core/2d/hline2d.hh
--- oln/core/2d/hline2d.hh (revision 0)
+++ oln/core/2d/hline2d.hh (revision 0)
@@ -0,0 +1,94 @@
+// 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_2D_HLINE2D_HH
+# define OLN_CORE_2D_HLINE2D_HH
+
+# include <oln/core/internal/window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ class hline2d;
+
+
+ // Super type.
+ template <>
+ struct super_trait_< hline2d >
+ {
+ typedef internal::window_<hline2d> ret;
+ };
+
+
+ // Virtual types.
+ template <>
+ struct vtypes< hline2d >
+ {
+ typedef point2d point;
+ };
+
+
+ /// 2D horizontal line window.
+
+ class hline2d : public internal::window_< hline2d >
+ {
+ public:
+
+ hline2d(unsigned half_length);
+
+ private:
+ void init_(int dcol_min, int dcol_max);
+ void take(); // safety; w/o impl, it provides from calling super::take(dp).
+
+ }; // end of class oln::hline2d
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ hline2d::hline2d(unsigned half_length)
+ {
+ precondition(half_length > 0);
+ this->init_(- half_length, + half_length);
+ }
+
+ void
+ hline2d::init_(int dcol_min, int dcol_max)
+ {
+ for (int dcol = dcol_min; dcol <= dcol_max; ++dcol)
+ this->internal::window_<hline2d>::take(dpoint2d(0, dcol));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_HLINE2D_HH
Index: oln/core/2d/rectangle2d.hh
--- oln/core/2d/rectangle2d.hh (revision 0)
+++ oln/core/2d/rectangle2d.hh (revision 0)
@@ -0,0 +1,116 @@
+// 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_2D_RECTANGLE2D_HH
+# define OLN_CORE_2D_RECTANGLE2D_HH
+
+# include <oln/core/internal/window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ class rectangle2d;
+
+
+ // Super type.
+ template <>
+ struct super_trait_< rectangle2d >
+ {
+ typedef internal::window_<rectangle2d> ret;
+ };
+
+
+ // Virtual types.
+ template <>
+ struct vtypes< rectangle2d >
+ {
+ typedef point2d point;
+ };
+
+
+ /// 2D rectangular window.
+
+ class rectangle2d : public internal::window_< rectangle2d >
+ {
+ public:
+
+ // FIXME: Use instant-init facilities.
+ rectangle2d(unsigned half_height, unsigned half_width);
+
+ unsigned half_height() const;
+ unsigned half_width() const;
+
+ private:
+ void init_(int drow_min, int dcol_min,
+ int drow_max, int dcol_max);
+ void take(); // safety; w/o impl, it provides from calling super::take(dp).
+
+ unsigned half_height_, half_width_;
+
+ }; // end of class oln::rectangle2d
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ rectangle2d::rectangle2d(unsigned half_height, unsigned half_width)
+ {
+ precondition(half_height > 0 and half_width > 0 );
+ this->half_height_ = half_height;
+ this->half_width_ = half_width;
+ this->init_(- half_height, - half_width,
+ + half_height, + half_width);
+ }
+
+ unsigned rectangle2d::half_height() const
+ {
+ return this->half_height_;
+ }
+
+ unsigned rectangle2d::half_width() const
+ {
+ return this->half_width_;
+ }
+
+ void
+ rectangle2d::init_(int drow_min, int dcol_min,
+ int drow_max, int dcol_max)
+ {
+ for (int drow = drow_min; drow <= drow_max; ++drow)
+ for (int dcol = dcol_min; dcol <= dcol_max; ++dcol)
+ this->internal::window_<rectangle2d>::take(dpoint2d(drow, dcol));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_RECTANGLE2D_HH
Index: oln/core/2d/window2d.hh
--- oln/core/2d/window2d.hh (revision 927)
+++ oln/core/2d/window2d.hh (working copy)
@@ -29,46 +29,43 @@
# define OLN_CORE_2D_WINDOW2D_HH
# include <oln/core/gen/window.hh>
-# include <oln/core/2d/dpoint2d.hh>
+# include <oln/core/2d/rectangle2d.hh>
namespace oln
{
// FIXME: window2d should be an actual type, not an alias...
- typedef window_<dpoint2d> window2d;
+ typedef gen_window<dpoint2d> window2d;
- window2d mk_square(unsigned odd_len);
+ rectangle2d mk_square(unsigned odd_len);
# ifndef OLN_INCLUDE_ONLY
- window2d mk_square(unsigned odd_len)
+ rectangle2d mk_square(unsigned odd_len)
{
precondition(odd_len % 2 = 1);
- window2d tmp;
- int half_len = odd_len / 2;
- for (int drow = - half_len; drow <= half_len; ++drow)
- for (int dcol = - half_len; dcol <= half_len; ++dcol)
- tmp.take(dpoint2d(drow, dcol));
+ unsigned half_len = odd_len / 2;
+ rectangle2d tmp(half_len, half_len);
return tmp;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
- extern const window2d win3x3;
- extern const window2d win5x5;
+ extern const rectangle2d win3x3;
+ extern const rectangle2d win5x5;
# ifndef OLN_INCLUDE_ONLY
- const window2d win3x3 = mk_square(3);
- const window2d win5x5 = mk_square(5);
+ const rectangle2d win3x3 = mk_square(3);
+ const rectangle2d win5x5 = mk_square(5);
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 927)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -187,7 +187,7 @@
{
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/window.hh
--- oln/core/gen/window.hh (revision 927)
+++ oln/core/gen/window.hh (working copy)
@@ -28,9 +28,7 @@
#ifndef OLN_CORE_GEN_WINDOW_HH
# define OLN_CORE_GEN_WINDOW_HH
-# include <oln/core/internal/window_base.hh>
-# include <oln/core/internal/dpoints_impl.hh>
-# include <oln/core/gen/dpoints_piter.hh>
+# include <oln/core/internal/window.hh>
namespace oln
@@ -38,72 +36,47 @@
// Fwd decl.
- template <typename Dp> class window_;
+ template <typename Dp> class gen_window;
// Super type.
template <typename Dp>
- struct super_trait_< window_<Dp> >
+ struct super_trait_< gen_window<Dp> >
{
- typedef window_<Dp> current__;
- typedef internal::window_base_<current__> ret;
+ typedef gen_window<Dp> current__;
+ typedef internal::window_<current__> ret;
};
- /// Virtual types.
+ // Virtual types.
template <typename Dp>
- struct vtypes< window_<Dp> >
+ struct vtypes< gen_window<Dp> >
{
- typedef stc_type(Dp, point) point;
- typedef dpoints_fwd_piter_<point> fwd_qiter;
- typedef dpoints_bkd_piter_<point> bkd_qiter;
+ typedef oln_point(Dp) point;
};
- /// Generic classical windoworhood class.
+ /// Generic classical window class.
template <typename Dp>
- class window_ : public internal::window_base_< window_<Dp> >,
- public internal::dpoints_impl_<Dp>
+ class gen_window : public internal::window_< gen_window<Dp> >
{
public:
- window_();
+ gen_window();
- window_<Dp>& take(const Dp& dp);
-
- window_<Dp> impl_op_unary_minus_() const;
-
- }; // end of class oln::window_<Dp>
+ }; // end of class oln::gen_window<Dp>
# ifndef OLN_INCLUDE_ONLY
template <typename Dp>
- window_<Dp>::window_()
- {
- }
-
- template <typename Dp>
- window_<Dp>&
- window_<Dp>::take(const Dp& dp)
- {
- this->take_( dp);
- return *this;
- }
-
- template <typename Dp>
- window_<Dp>
- window_<Dp>::impl_op_unary_minus_() const
+ gen_window<Dp>::gen_window()
{
- window_<Dp> tmp;
- for (unsigned i = 0; i < this->size(); ++i)
- tmp.take(- this->v_[i]);
- return tmp;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/window.hh
--- oln/core/internal/window.hh (revision 0)
+++ oln/core/internal/window.hh (revision 0)
@@ -0,0 +1,116 @@
+// 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_WINDOW_HH
+# define OLN_CORE_INTERNAL_WINDOW_HH
+
+# include <oln/core/internal/window_base.hh>
+# include <oln/core/internal/dpoints_impl.hh>
+# include <oln/core/gen/dpoints_piter.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class window_; }
+
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::window_<Exact> >
+ {
+ typedef internal::window_base_<Exact> ret;
+ };
+
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::window_<Exact> >
+ {
+ typedef stc_deferred(point) point__;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
+ typedef stc::final< dpoints_fwd_piter_<point__> > fwd_qiter;
+ typedef stc::final< dpoints_bkd_piter_<point__> > bkd_qiter;
+ };
+
+ namespace internal
+ {
+
+ /// Base implementation class for regular window classes.
+
+ template <typename Exact>
+ class window_ : public window_base_<Exact>,
+ public dpoints_impl_< stc_deferred(dpoint) >
+ {
+ typedef window_base_<Exact> super;
+ public:
+
+ stc_using(point);
+ typedef typename point::dpoint dpoint;
+
+ window_();
+ Exact& take(const dpoint& dp);
+ Exact impl_op_unary_minus_() const;
+
+ }; // end of class oln::internal::window_<Exact>
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ window_<Exact>::window_()
+ {
+ }
+
+ template <typename Exact>
+ Exact&
+ window_<Exact>::take(const typename window_<Exact>::dpoint& dp)
+ {
+ this->take_( dp);
+ return exact(*this);
+ }
+
+ template <typename Exact>
+ Exact
+ window_<Exact>::impl_op_unary_minus_() const
+ {
+ Exact tmp;
+ for (unsigned i = 0; i < this->size(); ++i)
+ tmp.take(- this->v_[i]);
+ return tmp;
+ }
+
+ } // end of namespace oln::internal
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WINDOW_HH
Index: oln/core/internal/window_base.hh
--- oln/core/internal/window_base.hh (revision 927)
+++ oln/core/internal/window_base.hh (working copy)
@@ -66,15 +66,18 @@
namespace internal
{
- /// Base class for implementation of windows class.
+ /// Base class for implementation of window classes.
template <typename Exact>
class window_base_ : public Window<Exact>
{
+ public:
+ stc_typename(point);
+
protected:
window_base_();
- }; // end of class oln::window_base_<Exact>
+ }; // end of class oln::internal::window_base_<Exact>
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 927)
+++ oln/morpho/closing.hh (working copy)
@@ -57,7 +57,7 @@
closing_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) tmp = morpho::dilation(input, win);
- return morpho::erosion(tmp, win); // FIXME : inverse(win).
+ return morpho::erosion(tmp, - win);
}
// FIXME: Add a fast version.
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 927)
+++ oln/morpho/opening.hh (working copy)
@@ -57,7 +57,7 @@
opening_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) ero = morpho::erosion(input, win);
- return morpho::dilation(ero, win); // FIXME : inverse(win).
+ return morpho::dilation(ero, - win);
}
// FIXME: Add a fast version.
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 927)
+++ oln/morpho/erosion.hh (working copy)
@@ -34,6 +34,11 @@
# include <oln/accumulator/min.hh>
# include <oln/accumulator/and.hh>
+// FIXME: Add guard.
+# include <oln/core/2d/rectangle2d.hh>
+# include <oln/core/2d/hline2d.hh>
+# include <oln/core/2d/vline2d.hh>
+
namespace oln
{
@@ -53,7 +58,7 @@
namespace impl
{
- // Generic version.
+ // Generic versions.
template <typename I, typename W>
oln_plain(I)
@@ -73,7 +78,21 @@
return level::apply_local(accu_and, input, win);
}
- // FIXME: Add a fast version.
+
+ // FIXME: Add guard here.
+ // Versions for rectangles.
+
+ template <typename I>
+ oln_plain(I)
+ erosion_on_function_(const Image_2D<I>& input, const rectangle2d& win)
+ {
+ hline2d hl(win.half_width());
+ vline2d hv(win.half_height());
+ oln_plain(I) tmp = erosion(input, hl);
+ return erosion(tmp, hv);
+ }
+
+ // FIXME: Add other fast versions.
// Impl facade.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add the type of stack of images.
* tests/core/stack.cc,
* oln/core/gen/image_stack.hh,
* oln/core/internal/value_proxy.hh: New.
* tests/core/Makefile.am (check_PROGRAMS): Add stack.
* oln/core/concept/image.hh (inplace): New.
* oln/core/equipment.hh (oln_psite): New.
* oln/core/internal/instant_value.hh: Cosmetic change.
* oln/stc/scoop.hh (stc_is_found_type): New.
oln/core/concept/image.hh | 10 +
oln/core/equipment.hh | 1
oln/core/gen/image_stack.hh | 210 +++++++++++++++++++++++++++++++++++++
oln/core/internal/instant_value.hh | 2
oln/core/internal/value_proxy.hh | 119 ++++++++++++++++++++
oln/stc/scoop.hh | 2
tests/core/Makefile.am | 2
tests/core/stack.cc | 59 ++++++++++
8 files changed, 404 insertions(+), 1 deletion(-)
Index: tests/core/stack.cc
--- tests/core/stack.cc (revision 0)
+++ tests/core/stack.cc (revision 0)
@@ -0,0 +1,59 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// Test stack.
+
+#include <cassert>
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/gen/image_stack.hh>
+#include <oln/level/fill.hh>
+
+
+xtd::vec<2,int> coords(const oln::point2d& p)
+{
+ return p.vec();
+}
+
+
+int main()
+{
+ using namespace oln;
+
+ typedef image2d<int> I;
+ I ima_0(3, 3), ima_1(3, 3);
+ level::fill(stack(ima_0, ima_1).inplace(), coords);
+ {
+ I::piter p(ima_0.points());
+ for_all(p)
+ assert(ima_0(p) = p.row());
+ }
+ {
+ I::piter p(ima_1.points());
+ for_all(p)
+ assert(ima_1(p) = p.col());
+ }
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 926)
+++ tests/core/Makefile.am (working copy)
@@ -33,6 +33,7 @@
pw_value \
rle_image \
sparse_image \
+ stack \
subset \
window2d
@@ -50,6 +51,7 @@
pw_value_SOURCES = pw_value.cc
rle_image_SOURCES = rle_image.cc
sparse_image_SOURCES = sparse_image.cc
+stack_SOURCES = stack.cc
subset_SOURCES = subset.cc
window2d_SOURCES = window2d.cc
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 926)
+++ oln/core/concept/image.hh (working copy)
@@ -191,6 +191,9 @@
lvalue operator()(const psite& p);
void write_(const psite& p, const value& v);
+ // final.
+ Exact& inplace();
+
protected:
Mutable_Image();
};
@@ -526,6 +529,13 @@
{
}
+ template <typename Exact>
+ Exact&
+ Mutable_Image<Exact>::inplace()
+ {
+ return exact(*this);
+ }
+
// ----------------------------------- Point_Wise_Accessible_Image<Exact>
template <typename Exact>
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 926)
+++ oln/core/equipment.hh (working copy)
@@ -127,6 +127,7 @@
# define oln_plain(T) oln_typename_shortcut__(T, plain)
# define oln_point(T) oln_typename_shortcut__(T, point)
# define oln_pset(T) oln_typename_shortcut__(T, pset)
+# define oln_psite(T) oln_typename_shortcut__(T, psite)
// q
stc_decl_associated_type( qiter );
Index: oln/core/gen/image_stack.hh
--- oln/core/gen/image_stack.hh (revision 0)
+++ oln/core/gen/image_stack.hh (revision 0)
@@ -0,0 +1,210 @@
+// 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_IMAGE_STACK_HH
+# define OLN_CORE_GEN_IMAGE_STACK_HH
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/value_proxy.hh>
+
+# include <mlc/int.hh>
+# include <xtd/vec.hh>
+
+
+namespace oln
+{
+
+# define current image_stack<n_, I>
+
+# define super internal::multiple_image_morpher_< current >
+
+
+ // Fwd decl.
+ template <unsigned n_, typename I> class image_stack;
+
+
+ // Super type.
+ template <unsigned n_, typename I>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ /// Virtual types.
+ template <unsigned n_, typename I>
+ struct vtypes< current >
+ {
+ typedef I delegatee;
+ typedef behavior::identity behavior;
+
+ typedef internal::singleton< xtd::vec<n_,I> > data;
+
+ typedef mlc::uint_<n_> n;
+
+ typedef xtd::vec<n_, oln_value(I)> value;
+ typedef value rvalue;
+
+ typedef typename mlc::if_< stc_is_found_type(I, lvalue),
+ internal::value_proxy_< current >,
+ stc::not_delegated >::ret lvalue;
+
+ typedef oln_plain_value(I, value) plain;
+ typedef image_stack< n_, pl::rec<I> > skeleton;
+ };
+
+
+ /// Class for a stack of n images.
+
+ template <unsigned n_, typename I>
+ class image_stack : public super
+ {
+ public:
+
+ stc_using(psite);
+ stc_using(rvalue);
+ stc_using(lvalue);
+ stc_using(value);
+ stc_using(data);
+ stc_using(delegatee);
+
+ image_stack();
+ image_stack(const xtd::vec<n_,I>& imas);
+
+ // FIXME: Force this type to be read-only?
+ rvalue impl_read(const psite& p) const;
+ lvalue impl_read_write(const psite& p);
+ void impl_write(const psite& p, const value& v);
+
+ delegatee& impl_image(unsigned i);
+ const delegatee& impl_image(unsigned i) const;
+
+ }; // end of current
+
+
+
+ template <typename I>
+ image_stack<2,I> stack(I& ima_0, I& ima_1);
+
+ template <typename I>
+ image_stack<3,I> stack(I& ima_0, I& ima_1, I& ima_2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <unsigned n_, typename I>
+ current::image_stack()
+ {
+ }
+
+ template <unsigned n_, typename I>
+ current::image_stack(const xtd::vec<n_,I>& imas)
+ {
+ for (unsigned i = 0; i < n_; ++i)
+ precondition(imas[i].has_data());
+ this->data_ = new data(imas);
+ }
+
+ template <unsigned n_, typename I>
+ typename current::rvalue
+ current::impl_read(const typename current::psite& p) const
+ {
+ assert(this->has_data());
+ rvalue tmp;
+ for (unsigned i = 0; i < n_; ++i)
+ tmp[i] = this->data_->value[i](p);
+ return tmp;
+ }
+
+ template <unsigned n_, typename I>
+ typename current::lvalue
+ current::impl_read_write(const typename current::psite& p)
+ {
+ assert(this->has_data());
+ lvalue tmp(*this, p);
+ return tmp;
+ }
+
+ template <unsigned n_, typename I>
+ void
+ current::impl_write(const typename current::psite& p,
+ const typename current::value& v)
+ {
+ assert(this->has_data());
+ for (unsigned i = 0; i < n_; ++i)
+ this->data_->value[i](p) = v[i];
+ }
+
+ template <unsigned n_, typename I>
+ typename current::delegatee&
+ current::impl_image(unsigned i)
+ {
+ precondition(i < n_);
+ assert(this->has_data());
+ return this->data_->value[i];
+ }
+
+ template <unsigned n_, typename I>
+ const typename current::delegatee&
+ current::impl_image(unsigned i) const
+ {
+ precondition(i < n_);
+ assert(this->has_data());
+ return this->data_->value[i];
+ }
+
+ template <typename I>
+ image_stack<2,I> stack(I& ima_0, I& ima_1)
+ {
+ xtd::vec<2,I> v;
+ v[0] = ima_0;
+ v[1] = ima_1;
+ image_stack<2,I> tmp(v);
+ return tmp;
+ }
+
+ template <typename I>
+ image_stack<3,I> stack(I& ima_0, I& ima_1, I& ima_2)
+ {
+ xtd::vec<3,I> v;
+ v[0] = ima_0;
+ v[1] = ima_1;
+ v[2] = ima_2;
+ image_stack<3,I> tmp(v);
+ return tmp;
+ }
+
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_IMAGE_STACK_HH
Index: oln/core/internal/value_proxy.hh
--- oln/core/internal/value_proxy.hh (revision 0)
+++ oln/core/internal/value_proxy.hh (revision 0)
@@ -0,0 +1,119 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_VALUE_PROXY_HH
+# define OLN_CORE_INTERNAL_VALUE_PROXY_HH
+
+# include <ostream>
+# include <oln/core/concept/value.hh>
+
+
+namespace oln
+{
+
+ namespace internal
+ {
+
+
+ template <typename I>
+ class value_proxy_
+ {
+ public:
+
+ // ctor
+ value_proxy_(I& ima, const oln_psite(I)& p);
+
+ // assignment => write
+ template <typename T>
+ value_proxy_<I>& operator=(const T& val);
+
+ // conversion => read
+ template <typename T>
+ operator T() const;
+
+ // explicit read
+ oln_value(I) value() const;
+
+ private:
+
+ I& ima_;
+ oln_psite(I) p_;
+ };
+
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const value_proxy_<I>& v);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ value_proxy_<I>::value_proxy_(I& ima, const oln_psite(I)& p)
+ : ima_(ima),
+ p_(p)
+ {
+ }
+
+ template <typename I>
+ template <typename T>
+ value_proxy_<I>&
+ value_proxy_<I>::operator=(const T& val)
+ {
+ ima_.write_(this->p_, val);
+ return *this;
+ }
+
+ template <typename I>
+ template <typename T>
+ value_proxy_<I>::operator T() const
+ {
+ T tmp = this->ima_.read_(this->p_);
+ return tmp;
+ }
+
+ template <typename I>
+ oln_value(I)
+ value_proxy_<I>::value() const
+ {
+ oln_value(I) tmp = this->ima_.read_(this->p_);
+ return tmp;
+ }
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const value_proxy_<I>& v)
+ {
+ return ostr << v.value();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_VALUE_PROXY_HH
Index: oln/core/internal/instant_value.hh
--- oln/core/internal/instant_value.hh (revision 926)
+++ oln/core/internal/instant_value.hh (working copy)
@@ -93,7 +93,7 @@
}
*/
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::internal
Index: oln/stc/scoop.hh
--- oln/stc/scoop.hh (revision 926)
+++ oln/stc/scoop.hh (working copy)
@@ -118,6 +118,8 @@
# define stc_type_is_found(Type) stc::is_found< stc_deferred(Type) >
# 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_a(T, U) \
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add plus and minus with explicit cast.
* TODO: Extend.
* oln/core/gen/pw_value.hh (image): New method.
* oln/core/gen/value_cast.hh: New.
* oln/arith/plus.hh (plus): New.
* oln/arith/minus.hh (minus): New.
* oln/morpho/elementary_gradient.hh,
* oln/morpho/elementary_gradient_external.hh,
* oln/morpho/elementary_laplace.hh,
* oln/morpho/gradient_internal.hh,
* oln/morpho/top_hat_black.hh,
* oln/morpho/gradient.hh,
* oln/morpho/top_hat_white.hh,
* oln/morpho/closing.hh,
* oln/morpho/opening.hh,
* oln/morpho/gradient_external.hh,
* oln/morpho/laplace.hh,
* oln/morpho/elementary_gradient_internal.hh: Update.
* oln/level/compare.hh: Add FIXME.
TODO | 2
oln/arith/minus.hh | 32 +++++++++
oln/arith/plus.hh | 37 ++++++++++-
oln/core/gen/pw_value.hh | 12 +++
oln/core/gen/value_cast.hh | 96 +++++++++++++++++++++++++++++
oln/level/compare.hh | 3
oln/morpho/elementary_gradient.hh | 2
oln/morpho/elementary_gradient_external.hh | 2
oln/morpho/elementary_gradient_internal.hh | 2
oln/morpho/elementary_laplace.hh | 10 +--
oln/morpho/gradient.hh | 2
oln/morpho/gradient_external.hh | 2
oln/morpho/gradient_internal.hh | 2
oln/morpho/laplace.hh | 7 +-
oln/morpho/top_hat_black.hh | 2
oln/morpho/top_hat_white.hh | 3
16 files changed, 195 insertions(+), 21 deletions(-)
Index: TODO
--- TODO (revision 925)
+++ TODO (working copy)
@@ -30,6 +30,8 @@
meta-window type; for instance, ball, segment, etc.
+provide "- win" for morpho::opening and morpho::closing.
+
const promotions for op_<L,O,R> types + result is Mutable only
if the underlying type is not 'const'
Index: oln/core/gen/pw_value.hh
--- oln/core/gen/pw_value.hh (revision 925)
+++ oln/core/gen/pw_value.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/gen/fun_ops.hh>
+
namespace oln
{
@@ -43,6 +44,7 @@
} // end of namespace oln::ERROR
+
template <typename I>
class pw_value_ : public Function_p2v< pw_value_<I> >,
private mlc::assert_< mlc_is_a(I, Image),
@@ -55,6 +57,8 @@
pw_value_(const Image<I>& ima);
oln_value(I) operator()(const oln_point(I)& p) const;
+ const I& image() const;
+
protected:
const I& ima_;
};
@@ -64,6 +68,7 @@
pw_value_<I> pw_value(const Image<I>& ima);
+
# ifndef OLN_INCLUDE_ONLY
template <typename I>
@@ -83,6 +88,13 @@
}
template <typename I>
+ const I&
+ pw_value_<I>::image() const
+ {
+ return this->ima_;
+ }
+
+ template <typename I>
pw_value_<I>
pw_value(const Image<I>& ima)
{
Index: oln/core/gen/value_cast.hh
--- oln/core/gen/value_cast.hh (revision 0)
+++ oln/core/gen/value_cast.hh (revision 0)
@@ -0,0 +1,96 @@
+// 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_VALUE_CAST_HH
+# define OLN_CORE_GEN_VALUE_CAST_HH
+
+# include <oln/core/gen/fun.hh>
+
+
+// FIXME: Separate defs and decls.
+
+
+
+namespace oln
+{
+
+
+ // ----------------------------- casted_fp2v_<F, V>
+
+
+ // Fwd decl.
+ template <typename F, typename V> struct casted_fp2v_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename F, typename V>
+ struct set_category_of_< casted_fp2v_<F, V> >
+ {
+ typedef stc::is< Function_p2v > ret;
+ };
+ }
+
+
+ // Class.
+ template <typename F, typename V>
+ struct casted_fp2v_ : public Function_p2v< casted_fp2v_<F, V> >
+ {
+ typedef oln_arg_of_(F) argument;
+ typedef oln_res_of_(F) f_result;
+ typedef V result;
+
+ casted_fp2v_(const F& f) : f_(f) {}
+
+ result operator()(argument arg) const
+ {
+ return static_cast<V>(this->f_(arg));
+ }
+
+ private:
+ F f_;
+ };
+
+
+ // value_cast
+
+ template <typename V, typename F>
+ casted_fp2v_<F, V> value_cast(const Function_p2v<F>& f)
+ {
+ // FIXME: Check that the cast "F::result -> V" is OK.
+ casted_fp2v_<F, V> tmp(exact(f));
+ return tmp;
+ }
+
+
+ // FIXME: Add casted_fv2v_<F,V>?
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_VALUE_CAST_HH
Index: oln/morpho/elementary_gradient.hh
--- oln/morpho/elementary_gradient.hh (revision 925)
+++ oln/morpho/elementary_gradient.hh (working copy)
@@ -59,7 +59,7 @@
{
oln_plain(I) dil = elementary_dilation(input);
oln_plain(I) ero = elementary_erosion(input);
- return dil - ero;
+ return arith::minus<oln_value(I)>(dil, ero);
}
Index: oln/morpho/elementary_gradient_external.hh
--- oln/morpho/elementary_gradient_external.hh (revision 925)
+++ oln/morpho/elementary_gradient_external.hh (working copy)
@@ -57,7 +57,7 @@
elementary_gradient_external_(const Image_with_Nbh<I>& input)
{
oln_plain(I) dil = elementary_dilation(input);
- return dil - input;
+ return arith::minus<oln_value(I)>(dil, input);
}
Index: oln/morpho/elementary_laplace.hh
--- oln/morpho/elementary_laplace.hh (revision 925)
+++ oln/morpho/elementary_laplace.hh (working copy)
@@ -41,7 +41,7 @@
// Fwd decl.
template <typename I>
- oln_plain(I)
+ oln_minus_trait(I, I)
elementary_laplace(const Image_with_Nbh<I>& input);
@@ -53,7 +53,7 @@
// Generic version.
template <typename I>
- oln_plain(I)
+ oln_minus_trait(I, I)
elementary_laplace_(const Image_with_Nbh<I>& input)
{
oln_plain(I) g_ext = elementary_gradient_external(input);
@@ -61,18 +61,16 @@
return g_ext - g_int;
}
-
- // FIXME: Add a fast version.
-
} // end of namespace oln::morpho::impl
// Facade.
template <typename I>
- oln_plain(I)
+ oln_minus_trait(I, I)
elementary_laplace(const Image_with_Nbh<I>& input)
{
+ // FIXME: Add postcondition.
return impl::elementary_laplace_(exact(input));
}
Index: oln/morpho/gradient_internal.hh
--- oln/morpho/gradient_internal.hh (revision 925)
+++ oln/morpho/gradient_internal.hh (working copy)
@@ -57,7 +57,7 @@
gradient_internal_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) ero = erosion(input, win);
- return input - ero;
+ return arith::minus<oln_value(I)>(input, ero);
}
Index: oln/morpho/top_hat_black.hh
--- oln/morpho/top_hat_black.hh (revision 925)
+++ oln/morpho/top_hat_black.hh (working copy)
@@ -58,7 +58,7 @@
top_hat_black_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) clo = closing(input, win);
- return clo - input;
+ return arith::minus<oln_value(I)>(clo, input);
}
Index: oln/morpho/gradient.hh
--- oln/morpho/gradient.hh (revision 925)
+++ oln/morpho/gradient.hh (working copy)
@@ -59,7 +59,7 @@
{
oln_plain(I) dil = dilation(input, win);
oln_plain(I) ero = erosion(input, win);
- return dil - ero;
+ return arith::minus<oln_value(I)>(dil, ero);
}
Index: oln/morpho/top_hat_white.hh
--- oln/morpho/top_hat_white.hh (revision 925)
+++ oln/morpho/top_hat_white.hh (working copy)
@@ -58,10 +58,9 @@
top_hat_white_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) ope = opening(input, win)
- return input - ope;
+ return arith::minus<oln_value(I)>(input, ope);
}
-
// FIXME: Add a fast version.
} // end of namespace oln::morpho::impl
Index: oln/morpho/closing.hh
Index: oln/morpho/opening.hh
Index: oln/morpho/gradient_external.hh
--- oln/morpho/gradient_external.hh (revision 925)
+++ oln/morpho/gradient_external.hh (working copy)
@@ -57,7 +57,7 @@
gradient_external_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) dil = dilation(input, win);
- return dil - input;
+ return arith::minus<oln_value(I)>(dil, input);
}
Index: oln/morpho/laplace.hh
--- oln/morpho/laplace.hh (revision 925)
+++ oln/morpho/laplace.hh (working copy)
@@ -41,7 +41,7 @@
// Fwd decl.
template <typename I, typename W>
- oln_plain(I)
+ oln_minus_trait(I, I)
laplace(const Image<I>& input, const Window<W>& win);
@@ -53,7 +53,7 @@
// Generic version.
template <typename I, typename W>
- oln_plain(I)
+ oln_minus_trait(I, I)
laplace_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) g_ext = gradient_external(input, win);
@@ -70,9 +70,10 @@
// Facade.
template <typename I, typename W>
- oln_plain(I)
+ oln_minus_trait(I, I)
laplace(const Image<I>& input, const Window<W>& win)
{
+ // FIXME: Add postcondition.
return impl::laplace_(exact(input), exact(win));
}
Index: oln/morpho/elementary_gradient_internal.hh
--- oln/morpho/elementary_gradient_internal.hh (revision 925)
+++ oln/morpho/elementary_gradient_internal.hh (working copy)
@@ -57,7 +57,7 @@
elementary_gradient_internal_(const Image_with_Nbh<I>& input)
{
oln_plain(I) ero = elementary_erosion(input)
- return input - ero;
+ return arith::minus<oln_value(I)>(input, ero);
}
Index: oln/level/compare.hh
--- oln/level/compare.hh (revision 925)
+++ oln/level/compare.hh (working copy)
@@ -60,6 +60,9 @@
bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val);
+ // FIXME: is-it a good idea to have "ima = lit"?
+ // FIXME: should we rather have "ima = f:p->v"?
+
# ifndef OLN_LNCLUDE_ONLY
Index: oln/arith/plus.hh
--- oln/arith/plus.hh (revision 925)
+++ oln/arith/plus.hh (working copy)
@@ -29,8 +29,14 @@
# define OLN_ARITH_PLUS_HH
# include <oln/core/concept/image.hh>
-// # include <oln/core/internal/f_ch_value.hh>
# include <oln/core/gen/traits.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/core/gen/value_cast.hh>
+# include <oln/level/fill.hh>
+# include <oln/core/internal/f_ch_value.hh>
+
+
+// FIXME: what about "ima + literal"?
namespace oln
@@ -46,12 +52,22 @@
typedef oln_plain_value(I, V) ret;
};
- // Fwd decl.
+
+ // Fwd decls.
template <typename I, typename J>
oln_plus_trait(I, J)
operator + (const Image<I>& lhs, const Image<J>& rhs);
+ namespace arith
+ {
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ plus(const Image<I>& lhs, const Image<J>& rhs);
+
+ } // end of namespace oln::arith
+
# ifndef OLN_INCLUDE_ONLY
@@ -68,6 +84,23 @@
return output;
}
+ namespace arith
+ {
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ plus(const Image<I>& lhs, const Image<J>& rhs)
+ {
+ precondition(lhs.points() = rhs.points());
+ oln_plain_value(I, V) output;
+ prepare(output, with, lhs);
+ level::fill(output,
+ value_cast<V>(pw_value(lhs) + pw_value(rhs)));
+ return output;
+ }
+
+ } // end of namespace oln::arith
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/arith/minus.hh
--- oln/arith/minus.hh (revision 925)
+++ oln/arith/minus.hh (working copy)
@@ -30,6 +30,10 @@
# include <oln/core/concept/image.hh>
# include <oln/core/gen/traits.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/core/gen/value_cast.hh>
+# include <oln/level/fill.hh>
+# include <oln/core/internal/f_ch_value.hh>
namespace oln
@@ -45,12 +49,21 @@
};
- // Fwd decl.
+ // Fwd decls.
template <typename I, typename J>
oln_minus_trait(I, J)
operator - (const Image<I>& lhs, const Image<J>& rhs);
+ namespace arith
+ {
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ minus(const Image<I>& lhs, const Image<J>& rhs);
+
+ } // end of namespace oln::arith
+
# ifndef OLN_INCLUDE_ONLY
@@ -67,6 +80,23 @@
return output;
}
+ namespace arith
+ {
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ minus(const Image<I>& lhs, const Image<J>& rhs)
+ {
+ precondition(lhs.points() = rhs.points());
+ oln_plain_value(I, V) output;
+ prepare(output, with, lhs);
+ level::fill(output,
+ value_cast<V>(pw_value(lhs) - pw_value(rhs)));
+ return output;
+ }
+
+ } // end of namespace oln::arith
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add postconditions to morphology.
* oln/value/builtin.hh: Move traits in...
* oln/value/builtin_traits.hh: ...this new file.
* tests/core/Makefile.am (check_PROGRAMS): Remove iter_point3d.
* tests/algorithms/fill.cc: Update.
* TODO: Extend.
* oln/core/concept/function.hh: Remove stupid fwd decl.
* oln/core/concept/operators.hh (operator>=): Rely now on <=.
* oln/core/gen/pset_compare.hh (operator>, operator>=): Remove;
obsolete.
* oln/core/gen/literal.hh (operator T),
(operator U): New conversions.
* oln/core/gen/traits.hh (set_trait_): Add default relying on Any.
* oln/core/internal/image_ops.hh: Add FIXME.
* oln/core/internal/op_fp2v_over_pset.hh (fun): New method.
* oln/morpho/reconstruction.hh (include): Fix missing.
* oln/morpho/cc_tarjan.hh: Likewise.
* oln/morpho/elementary_gradient.hh,
* oln/morpho/elementary_closing.hh,
* oln/morpho/elementary_gradient_external.hh,
* oln/morpho/elementary_opening.hh,
* oln/morpho/elementary_laplace.hh,
* oln/morpho/elementary_dilation.hh,
* oln/morpho/gradient_internal.hh,
* oln/morpho/top_hat_black.hh,
* oln/morpho/gradient.hh,
* oln/morpho/top_hat_white.hh,
* oln/morpho/closing.hh,
* oln/morpho/opening.hh,
* oln/morpho/gradient_external.hh,
* oln/morpho/laplace.hh,
* oln/morpho/dilation.hh,
* oln/morpho/elementary_erosion.hh,
* oln/morpho/erosion.hh,
* oln/morpho/elementary_gradient_internal.hh: Add postconditions.
Introduce explicit temporary variables.
Various clean-ups.
* oln/arith/minus.hh: Remove obsolete inactivated line.
* oln/level/compare.hh (operator=, operator<, operator<=): New
versions with a literal.
* oln/core/gen/pw_value.hh (pw_value_, pw_value): Weaken sig and
add static check.
* oln/level/local.hh (local): Likewise.
* oln/level/apply_local.hh (apply_local): Likewise.
TODO | 4 +
oln/arith/minus.hh | 1
oln/core/concept/function.hh | 3
oln/core/concept/operators.hh | 10 +-
oln/core/gen/literal.hh | 13 +++
oln/core/gen/pset_compare.hh | 21 -----
oln/core/gen/pw_value.hh | 13 ++-
oln/core/gen/traits.hh | 35 ++++++---
oln/core/internal/image_ops.hh | 2
oln/core/internal/op_fp2v_over_pset.hh | 10 ++
oln/level/apply_local.hh | 18 +---
oln/level/compare.hh | 112 ++++++++++++++++++++++++++++-
oln/level/local.hh | 13 +--
oln/morpho/cc_tarjan.hh | 6 +
oln/morpho/closing.hh | 8 +-
oln/morpho/dilation.hh | 25 +++---
oln/morpho/elementary_closing.hh | 8 +-
oln/morpho/elementary_dilation.hh | 18 ++--
oln/morpho/elementary_erosion.hh | 19 ++--
oln/morpho/elementary_gradient.hh | 9 +-
oln/morpho/elementary_gradient_external.hh | 8 +-
oln/morpho/elementary_gradient_internal.hh | 8 +-
oln/morpho/elementary_laplace.hh | 6 +
oln/morpho/elementary_opening.hh | 8 +-
oln/morpho/erosion.hh | 25 +++---
oln/morpho/gradient.hh | 18 ++--
oln/morpho/gradient_external.hh | 17 ++--
oln/morpho/gradient_internal.hh | 17 ++--
oln/morpho/laplace.hh | 21 ++---
oln/morpho/opening.hh | 12 +--
oln/morpho/reconstruction.hh | 6 +
oln/morpho/top_hat_black.hh | 17 ++--
oln/morpho/top_hat_white.hh | 18 ++--
oln/value/builtin.hh | 17 ----
oln/value/builtin_traits.hh | 57 ++++++++++++++
tests/algorithms/fill.cc | 13 +--
tests/core/Makefile.am | 2
37 files changed, 412 insertions(+), 206 deletions(-)
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 924)
+++ tests/core/Makefile.am (working copy)
@@ -27,7 +27,6 @@
image2d \
iter_point1d \
iter_point2d \
- iter_point3d \
neighb2d \
npoints \
point2d \
@@ -45,7 +44,6 @@
image2d_SOURCES = image2d.cc
iter_point1d_SOURCES = iter_point1d.cc
iter_point2d_SOURCES = iter_point2d.cc
-iter_point3d_SOURCES = iter_point3d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: tests/algorithms/fill.cc
--- tests/algorithms/fill.cc (revision 924)
+++ tests/algorithms/fill.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 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
@@ -28,19 +28,18 @@
/// Test oln::level::fill.
#include <cassert>
-// FIXME: We should not include oln/basics2d.hh, but
-// just oln/core/2d/image2d.hh.
-#include <oln/basics2d.hh>
+#include <oln/core/2d/image2d.hh>
#include <oln/level/fill.hh>
int
main()
{
- typedef oln::image2d<int> image_t;
+ using namespace oln;
+ typedef image2d<int> image_t;
image_t ima(3, 3);
- oln::level::fill(ima, 51);
- oln_piter_(image_t) p(ima.topo());
+ level::fill(ima, 51);
+ image_t::piter p(ima.points());
for_all(p)
assert(ima(p) = 51);
}
Index: TODO
--- TODO (revision 924)
+++ TODO (working copy)
@@ -35,6 +35,10 @@
in image_identity.hh use 'current'
+provide arith::minus et al. with explicit output type
+
+use Generalized_Point when possible
+
* Tiny improvements
Index: oln/core/concept/function.hh
--- oln/core/concept/function.hh (revision 924)
+++ oln/core/concept/function.hh (working copy)
@@ -48,9 +48,6 @@
*/
- template <typename Exact>
- struct Function;
-
template <typename Exact>
struct Function : public Any<Exact>
Index: oln/core/concept/operators.hh
--- oln/core/concept/operators.hh (revision 924)
+++ oln/core/concept/operators.hh (working copy)
@@ -100,19 +100,19 @@
template <typename L, typename R>
bool operator> (const Any<L>& lhs, const Any<R>& rhs)
{
- return exact(rhs) < exact(lhs);
+ return exact(rhs) < exact(lhs); // use "operator <"
}
template <typename L, typename R>
- bool operator>=(const Any<L>& lhs, const Any<R>& rhs)
+ bool operator<=(const Any<L>& lhs, const Any<R>& rhs)
{
- return not (exact(lhs) < exact(rhs));
+ return not (exact(rhs) < exact(lhs)); // use "operator <" and "not"
}
template <typename L, typename R>
- bool operator<=(const Any<L>& lhs, const Any<R>& rhs)
+ bool operator>=(const Any<L>& lhs, const Any<R>& rhs)
{
- return not (exact(rhs) < exact(lhs));
+ return exact(rhs) <= exact(lhs); // use "operator <="
}
template <typename L, typename R>
Index: oln/core/gen/pset_compare.hh
--- oln/core/gen/pset_compare.hh (revision 924)
+++ oln/core/gen/pset_compare.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_CORE_GEN_PSET_COMPARE_HH
# include <oln/core/concept/point_set.hh>
+# include <oln/core/concept/operators.hh>
namespace oln
@@ -45,12 +46,6 @@
template <typename L, typename R>
bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
- template <typename L, typename R>
- bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
-
- template <typename L, typename R>
- bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
-
template <typename B1, typename B2>
bool intersects (const Box<B1>& box1, const Box<B2>& box2);
@@ -252,20 +247,6 @@
return impl::op_strict_subset_(exact(lhs), exact(rhs));
}
- template <typename L, typename R>
- bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
- {
- assert_same_grid_<L, R>::check();
- return impl::op_subset_(exact(rhs), exact(lhs));
- }
-
- template <typename L, typename R>
- bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
- {
- assert_same_grid_<L, R>::check();
- return impl::op_strict_subset_(exact(rhs), exact(lhs));
- }
-
// Intersects.
template <typename B1, typename B2>
Index: oln/core/gen/pw_value.hh
--- oln/core/gen/pw_value.hh (revision 924)
+++ oln/core/gen/pw_value.hh (working copy)
@@ -52,7 +52,7 @@
typedef oln_point(I) argument; // FIXME: psite?
typedef oln_value(I) result;
- pw_value_(const Point_Wise_Accessible_Image<I>& ima);
+ pw_value_(const Image<I>& ima);
oln_value(I) operator()(const oln_point(I)& p) const;
protected:
@@ -61,16 +61,17 @@
template <typename I>
- pw_value_<I>
- pw_value(const Image<I>& ima);
+ pw_value_<I> pw_value(const Image<I>& ima);
# ifndef OLN_INCLUDE_ONLY
template <typename I>
- pw_value_<I>::pw_value_(const Point_Wise_Accessible_Image<I>& ima)
+ pw_value_<I>::pw_value_(const Image<I>& ima)
: ima_(exact(ima))
{
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ // FIXME: Add err msg above.
}
template <typename I>
@@ -83,8 +84,10 @@
template <typename I>
pw_value_<I>
- pw_value(const Point_Wise_Accessible_Image<I>& ima)
+ pw_value(const Image<I>& ima)
{
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ // FIXME: Add err msg above.
pw_value_<I> tmp(ima);
return tmp;
}
Index: oln/core/gen/literal.hh
--- oln/core/gen/literal.hh (revision 924)
+++ oln/core/gen/literal.hh (working copy)
@@ -28,7 +28,6 @@
#ifndef OLN_CORE_GEN_LITERAL_HH
# define OLN_CORE_GEN_LITERAL_HH
-# include <oln/core/concept/function.hh>
# include <oln/core/concept/generator.hh>
# include <oln/core/concept/point.hh>
# include <oln/core/concept/value.hh>
@@ -56,6 +55,18 @@
return this->val_;
}
+ operator T() const
+ {
+ return this->val_;
+ }
+
+ template <typename U>
+ operator literal_<U>() const
+ {
+ literal_<U> tmp(this->val_);
+ return tmp;
+ }
+
result value() const
{
return this->val_;
Index: oln/core/gen/traits.hh
--- oln/core/gen/traits.hh (revision 924)
+++ oln/core/gen/traits.hh (working copy)
@@ -90,9 +90,8 @@
# define oln_internal_specialize_bin_trait_bool_(Name) \
\
- template <template <class> class Cl, typename L, \
- template <class> class Cr, typename R> \
- struct set_trait_< Cl, L, Name##_id, Cr, R > \
+ template <typename L, typename R> \
+ struct set_trait_< Any, L, Name##_id, Any, R > \
{ \
typedef bool ret; \
}
@@ -100,9 +99,8 @@
# define oln_internal_specialize_bin_trait_T_(Name) \
\
- template <template <class> class Cl, typename T, \
- template <class> class Cr> \
- struct set_trait_< Cl, T, Name##_id, Cr, T > \
+ template <typename T> \
+ struct set_trait_< Any, T, Name##_id, Any, T > \
{ \
typedef T ret; \
}
@@ -115,12 +113,30 @@
// set_trait_
+
template <template <class> class Cl, typename L,
typename Op,
template <class> class Cr, typename R>
struct set_trait_;
+ template <typename L, typename Op, typename R>
+ struct set_trait_<Any, L, Op, Any, R>
+ {
+ // nothing => do not compile
+ };
+
+
+ template <template <class> class Cl, typename L,
+ typename Op,
+ template <class> class Cr, typename R>
+ struct set_trait_ // default is
+ : public set_trait_<Any, L, Op, Any, R>
+ {
+ };
+
+
+
// ids
struct plus_id;
@@ -145,7 +161,6 @@
// default (see oln/core/concept/operators.hh)
- /*
oln_internal_specialize_bin_trait_T_(plus);
oln_internal_specialize_bin_trait_T_(minus);
@@ -165,8 +180,6 @@
oln_internal_specialize_bin_trait_T_(or);
oln_internal_specialize_bin_trait_T_(xor);
- */
-
namespace internal
{
@@ -196,4 +209,8 @@
} // end of namespace oln
+// FIXME: Bad?
+# include <oln/value/builtin.hh>
+
+
#endif // ! OLN_CORE_GEN_TRAITS_HH
Index: oln/core/internal/image_ops.hh
--- oln/core/internal/image_ops.hh (revision 924)
+++ oln/core/internal/image_ops.hh (working copy)
@@ -70,6 +70,8 @@
return tmp;
}
+ // FIXME: Add "literal / point set"...
+
// Specialization "Image such_as f : P -> B".
Index: oln/core/internal/op_fp2v_over_pset.hh
--- oln/core/internal/op_fp2v_over_pset.hh (revision 924)
+++ oln/core/internal/op_fp2v_over_pset.hh (working copy)
@@ -90,6 +90,8 @@
rvalue impl_read(const point& p) const;
const S& impl_points() const;
+ const F& fun() const;
+
protected:
special_op_();
special_op_(F& fun, S& pts);
@@ -139,6 +141,14 @@
return this->data_->second;
}
+ template <typename F, typename S>
+ const F&
+ current::fun() const
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
} // end of namespace oln::internal
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 924)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -28,8 +28,10 @@
#ifndef OLN_MORPHO_RECONSTRUCTION_HH
# define OLN_MORPHO_RECONSTRUCTION_HH
+# include <oln/core/concept/image.hh>
#include <oln/accumulator/max.hh>
+
namespace oln
{
@@ -47,13 +49,13 @@
// first
oln_fwd_piter(I) p(input.points());
for_all(p)
- marker(p) = local(max, marker, p) && mask(p); // FIXME : local_sup.
+ marker(p) = local(max, marker, p) and mask(p); // FIXME : local_sup.
// second
oln_bkd_piter(I) p(input.points());
for_all(p)
- marker(p) = local(max, marker, p) && mask(p); // FIXME : local_inf.
+ marker(p) = local(max, marker, p) and mask(p); // FIXME : local_inf.
}
} // end of namespace oln::morpho::impl
Index: oln/morpho/elementary_gradient.hh
--- oln/morpho/elementary_gradient.hh (revision 924)
+++ oln/morpho/elementary_gradient.hh (working copy)
@@ -32,6 +32,7 @@
#include <oln/morpho/elementary_dilation.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -56,7 +57,9 @@
oln_plain(I)
elementary_gradient_(const Image_with_Nbh<I>& input)
{
- return elementary_dilation(input) - elementary_erosion(input);
+ oln_plain(I) dil = elementary_dilation(input);
+ oln_plain(I) ero = elementary_erosion(input);
+ return dil - ero;
}
@@ -71,7 +74,9 @@
oln_plain(I)
elementary_gradient(const Image_with_Nbh<I>& input)
{
- return impl::elementary_gradient_(exact(input));
+ oln_plain(I) output = impl::elementary_gradient_(exact(input));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_closing.hh
--- oln/morpho/elementary_closing.hh (revision 924)
+++ oln/morpho/elementary_closing.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
+
namespace oln
{
@@ -54,7 +55,8 @@
oln_plain(I)
elementary_closing_(const Image_with_Nbh<I>& input)
{
- return elementary_erosion( elementary_dilation(input) );
+ oln_plain(I) dil = elementary_dilation(input);
+ return elementary_erosion(dil);
}
// FIXME: Add a fast version.
@@ -68,7 +70,9 @@
oln_plain(I)
elementary_closing(const Image_with_Nbh<I>& input)
{
- return impl::elementary_closing_(exact(input));
+ oln_plain(I) output = impl::elementary_closing_(exact(input));
+ postcondition(output >= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 924)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -28,8 +28,10 @@
#ifndef OLN_MORPHO_CC_TARJAN_HH
# define OLN_MORPHO_CC_TARJAN_HH
+# include <oln/core/concept/image.hh>
#include <oln/debug/print.hh>
+
namespace oln
{
@@ -76,7 +78,7 @@
oln_niter(I) n(p, input);
for_all(n)
{
- if ( input(n) && is_processed(n) )
+ if ( input(n) = true and is_processed(n) )
do_union(input ,n, p, parent);
}
is_processed(p) = true;
@@ -93,7 +95,7 @@
oln_fwd_piter(I) p(input.points());
for_all(p)
{
- if ( input(p) && parent(p) = p )
+ if ( input(p) = true and parent(p) = p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
Index: oln/morpho/elementary_gradient_external.hh
--- oln/morpho/elementary_gradient_external.hh (revision 924)
+++ oln/morpho/elementary_gradient_external.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/elementary_dilation.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -55,7 +56,8 @@
oln_plain(I)
elementary_gradient_external_(const Image_with_Nbh<I>& input)
{
- return elementary_dilation(input) - input;
+ oln_plain(I) dil = elementary_dilation(input);
+ return dil - input;
}
@@ -70,7 +72,9 @@
oln_plain(I)
elementary_gradient_external(const Image_with_Nbh<I>& input)
{
- return impl::elementary_gradient_external_(exact(input));
+ oln_plain(I) output = impl::elementary_gradient_external_(exact(input));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_opening.hh
--- oln/morpho/elementary_opening.hh (revision 924)
+++ oln/morpho/elementary_opening.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
+
namespace oln
{
@@ -54,7 +55,8 @@
oln_plain(I)
elementary_opening_(const Image_with_Nbh<I>& input)
{
- return morpho::elementary_dilation( morpho::elementary_erosion(input) );
+ oln_plain(I) ero = morpho::elementary_erosion(input);
+ return morpho::elementary_dilation(ero);
}
// FIXME: Add a fast version.
@@ -68,7 +70,9 @@
oln_plain(I)
elementary_opening(const Image_with_Nbh<I>& input)
{
- return impl::elementary_opening_(exact(input));
+ oln_plain(I) output = impl::elementary_opening_(exact(input));
+ postcondition(output <= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_laplace.hh
--- oln/morpho/elementary_laplace.hh (revision 924)
+++ oln/morpho/elementary_laplace.hh (working copy)
@@ -30,7 +30,7 @@
#include <oln/morpho/elementary_gradient_external.hh>
#include <oln/morpho/elementary_gradient_internal.hh>
-#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -56,7 +56,9 @@
oln_plain(I)
elementary_laplace_(const Image_with_Nbh<I>& input)
{
- return elementary_gradient_external(input) - elementary_gradient_internal(input);
+ oln_plain(I) g_ext = elementary_gradient_external(input);
+ oln_plain(I) g_int = elementary_gradient_internal(input);
+ return g_ext - g_int;
}
Index: oln/morpho/elementary_dilation.hh
--- oln/morpho/elementary_dilation.hh (revision 924)
+++ oln/morpho/elementary_dilation.hh (working copy)
@@ -29,10 +29,12 @@
# define OLN_MORPHO_ELEMENTARY_DILATION_HH
#include <oln/level/apply_local.hh>
+# include <oln/level/compare.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
#include <oln/accumulator/or.hh>
+
namespace oln
{
@@ -55,8 +57,7 @@
template <typename I>
oln_plain(I)
- elementary_dilation_on_function_(const Image<I>&,
- const I& input)
+ elementary_dilation_on_function_(const Image<I>& input)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::max_<oln_value(I)> max;
@@ -65,10 +66,9 @@
template <typename I>
oln_plain(I)
- elementary_dilation_on_set_(const Image<I>&,
- const I& input)
+ elementary_dilation_on_set_(const Image<I>& input)
{
- border::fill(input, oln_min(oln_value(I)));
+ border::fill(input, false);
accumulator::or_<oln_value(I)> accu_or;
return level::apply_local(accu_or, input);
}
@@ -81,13 +81,13 @@
template <typename I>
oln_plain(I) elementary_dilation_(const Image<I>& input)
{
- return elementary_dilation_on_function_(exact(input), exact(input));
+ return elementary_dilation_on_function_(exact(input));
}
template <typename I>
oln_plain(I) elementary_dilation_(const Binary_Image<I>& input)
{
- return elementary_dilation_on_set_(exact(input), exact(input));
+ return elementary_dilation_on_set_(exact(input));
}
} // end of namespace oln::morpho::impl
@@ -99,7 +99,9 @@
oln_plain(I)
elementary_dilation(const Image_with_Nbh<I>& input)
{
- return impl::elementary_dilation_(exact(input));
+ oln_plain(I) output = impl::elementary_dilation_(exact(input));
+ postcondition(output >= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/gradient_internal.hh
--- oln/morpho/gradient_internal.hh (revision 924)
+++ oln/morpho/gradient_internal.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/erosion.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -41,8 +42,7 @@
template <typename I, typename W>
oln_plain(I)
- gradient_internal(const Image<I>& input,
- const Window<W>& win);
+ gradient_internal(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -54,10 +54,10 @@
template <typename I, typename W>
oln_plain(I)
- gradient_internal_(const Image<I>& input,
- const Window<W>& win)
+ gradient_internal_(const Image<I>& input, const Window<W>& win)
{
- return input - erosion(input, win);
+ oln_plain(I) ero = erosion(input, win);
+ return input - ero;
}
@@ -69,10 +69,11 @@
template <typename I, typename W>
oln_plain(I)
- gradient_internal(const Image<I>& input,
- const Window<W>& win)
+ gradient_internal(const Image<I>& input, const Window<W>& win)
{
- return impl::gradient_internal_(exact(input), win);
+ oln_plain(I) output = impl::gradient_internal_(exact(input), exact(win));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/top_hat_black.hh
--- oln/morpho/top_hat_black.hh (revision 924)
+++ oln/morpho/top_hat_black.hh (working copy)
@@ -32,6 +32,7 @@
#include <oln/morpho/closing.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -42,8 +43,7 @@
template <typename I, typename W>
oln_plain(I)
- top_hat_black(const Image<I>& input,
- const Window<W>& win);
+ top_hat_black(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -55,10 +55,10 @@
template <typename I, typename W>
oln_plain(I)
- top_hat_black_(const Image<I>& input,
- const Window<W>& win)
+ top_hat_black_(const Image<I>& input, const Window<W>& win)
{
- return closing(input, win) - input;
+ oln_plain(I) clo = closing(input, win);
+ return clo - input;
}
@@ -71,10 +71,11 @@
template <typename I, typename W>
oln_plain(I)
- top_hat_black(const Image<I>& input,
- const Window<W>& win)
+ top_hat_black(const Image<I>& input, const Window<W>& win)
{
- return impl::top_hat_black_(exact(input), win);
+ oln_plain(I) output = impl::top_hat_black_(exact(input), exact(win));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/gradient.hh
--- oln/morpho/gradient.hh (revision 924)
+++ oln/morpho/gradient.hh (working copy)
@@ -32,6 +32,7 @@
#include <oln/morpho/dilation.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -42,8 +43,7 @@
template <typename I, typename W>
oln_plain(I)
- gradient(const Image<I>& input,
- const Window<W>& win);
+ gradient(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -55,10 +55,11 @@
template <typename I, typename W>
oln_plain(I)
- gradient_(const Image<I>& input,
- const Window<W>& win)
+ gradient_(const Image<I>& input, const Window<W>& win)
{
- return dilation(input, win) - erosion(input, win);
+ oln_plain(I) dil = dilation(input, win);
+ oln_plain(I) ero = erosion(input, win);
+ return dil - ero;
}
@@ -69,10 +70,11 @@
template <typename I, typename W>
oln_plain(I)
- gradient(const Image<I>& input,
- const Window<W>& win)
+ gradient(const Image<I>& input, const Window<W>& win)
{
- return impl::gradient_(exact(input), win);
+ oln_plain(I) output = impl::gradient_(exact(input), exact(win));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/top_hat_white.hh
--- oln/morpho/top_hat_white.hh (revision 924)
+++ oln/morpho/top_hat_white.hh (working copy)
@@ -32,6 +32,7 @@
#include <oln/morpho/closing.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -42,8 +43,8 @@
template <typename I, typename W>
oln_plain(I)
- top_hat_white(const Image<I>& input,
- const Window<W>& win);
+ top_hat_white(const Image<I>& input, const Window<W>& win);
+
# ifndef OLN_INCLUDE_ONLY
@@ -54,10 +55,10 @@
template <typename I, typename W>
oln_plain(I)
- top_hat_white_(const Image<I>& input,
- const Window<W>& win)
+ top_hat_white_(const Image<I>& input, const Window<W>& win)
{
- return input - opening(input, win);
+ oln_plain(I) ope = opening(input, win)
+ return input - ope;
}
@@ -70,10 +71,11 @@
template <typename I, typename W>
oln_plain(I)
- top_hat_white(const Image<I>& input,
- const Window<W>& win)
+ top_hat_white(const Image<I>& input, const Window<W>& win)
{
- return impl::top_hat_white_(exact(input), win);
+ oln_plain(I) output = impl::top_hat_white_(exact(input), exact(win));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 924)
+++ oln/morpho/closing.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/erosion.hh>
#include <oln/morpho/dilation.hh>
+
namespace oln
{
@@ -53,8 +54,7 @@
template <typename I, typename W>
oln_plain(I)
- closing_(const Image<I>& input,
- const Window<W>& win)
+ closing_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) tmp = morpho::dilation(input, win);
return morpho::erosion(tmp, win); // FIXME : inverse(win).
@@ -72,7 +72,9 @@
oln_plain(I)
closing(const Image<I>& input, const Window<W>& win)
{
- return impl::closing_(exact(input), exact(win));
+ oln_plain(I) output = impl::closing_(exact(input), exact(win));
+ postcondition(output >= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 924)
+++ oln/morpho/opening.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/erosion.hh>
#include <oln/morpho/dilation.hh>
+
namespace oln
{
@@ -53,11 +54,10 @@
template <typename I, typename W>
oln_plain(I)
- opening_(const Image<I>& input,
- const Window<W>& win)
+ opening_(const Image<I>& input, const Window<W>& win)
{
- oln_plain(I) tmp = morpho::erosion(input, win);
- return morpho::dilation(tmp, win); // FIXME : inverse(win).
+ oln_plain(I) ero = morpho::erosion(input, win);
+ return morpho::dilation(ero, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
@@ -71,7 +71,9 @@
oln_plain(I)
opening(const Image<I>& input, const Window<W>& win)
{
- return impl::opening_(exact(input), win);
+ oln_plain(I) output = impl::opening_(exact(input), exact(win));
+ postcondition(output <= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/gradient_external.hh
--- oln/morpho/gradient_external.hh (revision 924)
+++ oln/morpho/gradient_external.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/dilation.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -41,8 +42,7 @@
template <typename I, typename W>
oln_plain(I)
- gradient_external(const Image<I>& input,
- const Window<W>& win);
+ gradient_external(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -54,10 +54,10 @@
template <typename I, typename W>
oln_plain(I)
- gradient_external_(const Image<I>& input,
- const Window<W>& win)
+ gradient_external_(const Image<I>& input, const Window<W>& win)
{
- return dilation(input, win) - input;
+ oln_plain(I) dil = dilation(input, win);
+ return dil - input;
}
@@ -68,10 +68,11 @@
template <typename I, typename W>
oln_plain(I)
- gradient_external(const Image<I>& input,
- const Window<W>& win)
+ gradient_external(const Image<I>& input, const Window<W>& win)
{
- return impl::gradient_external_(exact(input), win);
+ oln_plain(I) output = impl::gradient_external_(exact(input), exact(win));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/laplace.hh
--- oln/morpho/laplace.hh (revision 924)
+++ oln/morpho/laplace.hh (working copy)
@@ -28,9 +28,9 @@
#ifndef OLN_MORPHO_LAPLACE_HH
# define OLN_MORPHO_LAPLACE_HH
-#include <oln/morpho/elementary_gradient_external.hh>
-#include <oln/morpho/elementary_gradient_internal.hh>
-#include <oln/arith/minus.hh>
+# include <oln/morpho/gradient_external.hh>
+# include <oln/morpho/gradient_internal.hh>
+
namespace oln
{
@@ -42,8 +42,7 @@
template <typename I, typename W>
oln_plain(I)
- laplace(const Image<I>& input,
- const Window<W>& win);
+ laplace(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -55,10 +54,11 @@
template <typename I, typename W>
oln_plain(I)
- laplace_(const Image<I>& input,
- const Window<W>& win)
+ laplace_(const Image<I>& input, const Window<W>& win)
{
- return gradient_external(input, win) - gradient_internal(input, win);
+ oln_plain(I) g_ext = gradient_external(input, win);
+ oln_plain(I) g_int = gradient_internal(input, win);
+ return g_ext - g_int;
}
@@ -71,10 +71,9 @@
template <typename I, typename W>
oln_plain(I)
- laplace(const Image<I>& input,
- const Window<W>& win)
+ laplace(const Image<I>& input, const Window<W>& win)
{
- return impl::laplace_(exact(input), win);
+ return impl::laplace_(exact(input), exact(win));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 924)
+++ oln/morpho/dilation.hh (working copy)
@@ -29,8 +29,11 @@
# define OLN_MORPHO_DILATION_HH
#include <oln/level/apply_local.hh>
+# include <oln/level/compare.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
+# include <oln/accumulator/or.hh>
+
namespace oln
{
@@ -54,9 +57,7 @@
template <typename I, typename W>
oln_plain(I)
- dilation_on_function_(const Image<I>&,
- const I& input,
- const Window<W>& win)
+ dilation_on_function_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::max_<oln_value(I)> max;
@@ -65,9 +66,7 @@
template <typename I, typename W>
oln_plain(I)
- dilation_on_set_(const Image<I>&,
- const I& input,
- const Window<W>& win)
+ dilation_on_set_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::or_<oln_value(I)> accu_or;
@@ -80,17 +79,15 @@
// Impl facade.
template <typename I, typename W>
- oln_plain(I) dilation_(const Image<I>& input,
- const Window<W>& win)
+ oln_plain(I) dilation_(const Image<I>& input, const Window<W>& win)
{
- return dilation_on_function_(exact(input), exact(input), win);
+ return dilation_on_function_(exact(input), exact(win));
}
template <typename I, typename W>
- oln_plain(I) dilation_(const Binary_Image<I>& input,
- const Window<W>& win)
+ oln_plain(I) dilation_(const Binary_Image<I>& input, const Window<W>& win)
{
- return dilation_on_set_(exact(input), exact(input), win);
+ return dilation_on_set_(exact(input), exact(win));
}
} // end of namespace oln::morpho::impl
@@ -102,7 +99,9 @@
oln_plain(I)
dilation(const Image<I>& input, const Window<W>& win)
{
- return impl::dilation_(exact(input), exact(win));
+ oln_plain(I) output = impl::dilation_(exact(input), exact(win));
+ postcondition(output >= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 924)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -29,8 +29,11 @@
# define OLN_MORPHO_ELEMENTARY_EROSION_HH
#include <oln/level/apply_local.hh>
+# include <oln/level/compare.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/min.hh>
+# include <oln/accumulator/and.hh>
+
namespace oln
{
@@ -54,8 +57,7 @@
template <typename I>
oln_plain(I)
- elementary_erosion_on_function_(const Image<I>&,
- const I& input)
+ elementary_erosion_on_function_(const Image<I>& input)
{
border::fill(input, oln_max(oln_value(I)));
accumulator::min_<oln_value(I)> min;
@@ -64,10 +66,9 @@
template <typename I>
oln_plain(I)
- elementary_erosion_on_set_(const Image<I>&,
- const I& input)
+ elementary_erosion_on_set_(const Image<I>& input)
{
- border::fill(input, oln_max(oln_value(I)));
+ border::fill(input, true);
accumulator::and_<oln_value(I)> accu_and;
return level::apply_local(accu_and, input);
}
@@ -113,13 +114,13 @@
template <typename I>
oln_plain(I) elementary_erosion_(const Image<I>& input)
{
- return elementary_erosion_on_function_(exact(input), exact(input));
+ return elementary_erosion_on_function_(exact(input));
}
template <typename I>
oln_plain(I) elementary_erosion_(const Binary_Image<I>& input)
{
- return elementary_erosion_on_set_(exact(input), exact(input));
+ return elementary_erosion_on_set_(exact(input));
}
@@ -132,7 +133,9 @@
oln_plain(I)
elementary_erosion(const Image_with_Nbh<I>& input)
{
- return impl::elementary_erosion_(exact(input));
+ oln_plain(I) output = impl::elementary_erosion_(exact(input));
+ postcondition(output <= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 924)
+++ oln/morpho/erosion.hh (working copy)
@@ -29,8 +29,11 @@
# define OLN_MORPHO_EROSION_HH
#include <oln/level/apply_local.hh>
+# include <oln/level/compare.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/min.hh>
+# include <oln/accumulator/and.hh>
+
namespace oln
{
@@ -54,9 +57,7 @@
template <typename I, typename W>
oln_plain(I)
- erosion_on_function_(const Image<I>&,
- const I& input,
- const Window<W>& win)
+ erosion_on_function_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, oln_max(oln_value(I)));
accumulator::min_<oln_value(I)> min;
@@ -65,9 +66,7 @@
template <typename I, typename W>
oln_plain(I)
- erosion_on_set_(const Image<I>&,
- const I& input,
- const Window<W>& win)
+ erosion_on_set_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, true);
accumulator::and_<oln_value(I)> accu_and;
@@ -80,17 +79,15 @@
// Impl facade.
template <typename I, typename W>
- oln_plain(I) erosion_(const Image<I>& input,
- const Window<W>& win)
+ oln_plain(I) erosion_(const Image<I>& input, const Window<W>& win)
{
- return erosion_on_function_(exact(input), exact(input), win);
+ return erosion_on_function_(exact(input), exact(win));
}
template <typename I, typename W>
- oln_plain(I) erosion_(const Binary_Image<I>& input,
- const Window<W>& win)
+ oln_plain(I) erosion_(const Binary_Image<I>& input, const Window<W>& win)
{
- return erosion_on_set_(exact(input), exact(input), win);
+ return erosion_on_set_(exact(input), exact(win));
}
} // end of namespace oln::morpho::impl
@@ -102,7 +99,9 @@
oln_plain(I)
erosion(const Image<I>& input, const Window<W>& win)
{
- return impl::erosion_(exact(input), exact(win));
+ oln_plain(I) output = impl::erosion_(exact(input), exact(win));
+ postcondition(output <= input);
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_gradient_internal.hh
--- oln/morpho/elementary_gradient_internal.hh (revision 924)
+++ oln/morpho/elementary_gradient_internal.hh (working copy)
@@ -31,6 +31,7 @@
#include <oln/morpho/elementary_erosion.hh>
#include <oln/arith/minus.hh>
+
namespace oln
{
@@ -55,7 +56,8 @@
oln_plain(I)
elementary_gradient_internal_(const Image_with_Nbh<I>& input)
{
- return input - elementary_erosion(input);
+ oln_plain(I) ero = elementary_erosion(input)
+ return input - ero;
}
@@ -70,7 +72,9 @@
oln_plain(I)
elementary_gradient_internal(const Image_with_Nbh<I>& input)
{
- return impl::elementary_gradient_internal_(exact(input));
+ oln_plain(I) output = impl::elementary_gradient_internal_(exact(input));
+ postcondition(output >= literal(0));
+ return output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/arith/minus.hh
--- oln/arith/minus.hh (revision 924)
+++ oln/arith/minus.hh (working copy)
@@ -29,7 +29,6 @@
# define OLN_ARITH_MINUS_HH
# include <oln/core/concept/image.hh>
-// # include <oln/core/internal/f_ch_value.hh>
# include <oln/core/gen/traits.hh>
Index: oln/level/compare.hh
--- oln/level/compare.hh (revision 924)
+++ oln/level/compare.hh (working copy)
@@ -30,6 +30,10 @@
# include <oln/core/concept/image.hh>
# include <oln/core/gen/pset_compare.hh>
+# include <oln/core/gen/literal.hh>
+
+// FIXME: Rename this file as "comparison.hh".
+
namespace oln
@@ -40,9 +44,22 @@
template <typename L, typename R>
bool operator = (const Image<L>& lhs, const Image<R>& rhs);
+ template <typename I>
+ bool operator = (const Image<I>& lhs, const literal_<oln_value(I)>& val);
+
template <typename L, typename R>
bool operator < (const Image<L>& lhs, const Image<R>& rhs);
+ template <typename I>
+ bool operator < (const Image<I>& lhs, const literal_<oln_value(I)>& val);
+
+ template <typename L, typename R>
+ bool operator <= (const Image<L>& lhs, const Image<R>& rhs);
+
+ template <typename I>
+ bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val);
+
+
# ifndef OLN_LNCLUDE_ONLY
@@ -55,7 +72,7 @@
// Generic version.
template <typename L, typename R>
- bool op_eq_(const Image<L>& lhs, const Image<R>& rhs);
+ bool op_eq_(const Image<L>& lhs, const Image<R>& rhs)
{
precondition(lhs.points() = rhs.points());
oln_piter(L) p(lhs.points());
@@ -66,13 +83,29 @@
}
+ // Image I = Value V
+ // ----------------------
+
+ // Generic version.
+
+ template <typename I>
+ bool op_eq_(const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ {
+ oln_piter(I) p(lhs.points());
+ for_all(p)
+ if (lhs(p) != val)
+ return false;
+ return true;
+ }
+
+
// Image L < Image R
// ---------------------
// Generic version.
template <typename L, typename R>
- bool op_less_(const Image<L>& lhs, const Image<R>& rhs);
+ bool op_less_(const Image<L>& lhs, const Image<R>& rhs)
{
precondition(lhs.points() = rhs.points());
oln_piter(L) p(lhs.points());
@@ -82,6 +115,56 @@
return true;
}
+
+ // Image I < Value V
+ // ---------------------
+
+ // Generic version.
+
+ template <typename I>
+ bool op_less_(const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ {
+ oln_piter(I) p(lhs.points());
+ for_all(p)
+ if (lhs(p) >= val)
+ return false;
+ return true;
+ }
+
+
+ // Image L <= Image R
+ // ----------------------
+
+ // Generic version.
+
+ template <typename L, typename R>
+ bool op_leq_(const Image<L>& lhs, const Image<R>& rhs)
+ {
+ precondition(lhs.points() = rhs.points());
+ oln_piter(L) p(lhs.points());
+ for_all(p)
+ if (lhs(p) > rhs(p))
+ return false;
+ return true;
+ }
+
+
+ // Image I <= Value V
+ // ----------------------
+
+ // Generic version.
+
+ template <typename I>
+ bool op_leq_(const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ {
+ oln_piter(I) p(lhs.points());
+ for_all(p)
+ if (lhs(p) > val)
+ return false;
+ return true;
+ }
+
+
} // end of namespace oln::level::impl
@@ -94,6 +177,12 @@
return impl::op_eq_(exact(lhs), exact(rhs));
}
+ template <typename I>
+ bool operator = (const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ {
+ return impl::op_eq_(exact(lhs), val);
+ }
+
template <typename L, typename R>
bool operator < (const Image<L>& lhs, const Image<R>& rhs)
{
@@ -101,6 +190,25 @@
return impl::op_less_(exact(lhs), exact(rhs));
}
+ template <typename I>
+ bool operator < (const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ {
+ return impl::op_less_(exact(lhs), val);
+ }
+
+ template <typename L, typename R>
+ bool operator <= (const Image<L>& lhs, const Image<R>& rhs)
+ {
+ assert_same_grid_<L, R>::check();
+ return impl::op_leq_(exact(lhs), exact(rhs));
+ }
+
+ template <typename I>
+ bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ {
+ return impl::op_leq_(exact(lhs), val);
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/level/local.hh
--- oln/level/local.hh (revision 924)
+++ oln/level/local.hh (working copy)
@@ -42,9 +42,7 @@
template <typename A, typename I>
typename A::result
- local(const Accumulator<A>& f,
- const Image_with_Nbh<I>& input,
- const oln_point(I)& p);
+ local(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p);
template <typename A, typename I, typename W>
typename A::result
@@ -72,9 +70,7 @@
f.init_with(input(p));
oln_niter(I) n(p, input);
for_all(n)
- {
f(input(n));
- }
return f.value();
}
@@ -192,10 +188,9 @@
template <typename A, typename I>
typename A::result
- local(const Accumulator<A>& f,
- const Image_with_Nbh<I>& input,
- const oln_point(I)& p)
+ local(const Accumulator<A>& f, const Image<I>& input, const oln_point(I)& p)
{
+ mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check();
return impl::local_(exact(f), exact(input), p);
}
@@ -206,7 +201,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- return impl::local_(exact(f), exact(input), p, win);
+ return impl::local_(exact(f), exact(input), p, exact(win));
}
#endif // ! OLN_INCLUDE_ONLY
Index: oln/level/apply_local.hh
--- oln/level/apply_local.hh (revision 924)
+++ oln/level/apply_local.hh (working copy)
@@ -44,14 +44,12 @@
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input);
+ apply_local(const Accumulator<F>& f, const Image<I>& input);
template <typename F, typename I, typename W>
oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& f,
- const Image<I>& input,
- const Window<W>& win);
+ apply_local(const Accumulator<F>& f, const Image<I>& input, const Window<W>& win);
+
# ifndef OLN_INCLUDE_ONLY
@@ -94,19 +92,17 @@
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input)
+ apply_local(const Accumulator<F>& f, const Image<I>& input)
{
+ mlc::assert_< mlc_is_a(I, Image_with_Nbh) >::check();
return impl::apply_local_(exact(f), exact(input));
}
template <typename F, typename I, typename W>
oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& f,
- const Image<I>& input,
- const Window<W>& win)
+ apply_local(const Accumulator<F>& f, const Image<I>& input, const Window<W>& win)
{
- return impl::apply_local_(exact(f), exact(input), win);
+ return impl::apply_local_(exact(f), exact(input), exact(win));
}
# endif
Index: oln/value/builtin.hh
--- oln/value/builtin.hh (revision 924)
+++ oln/value/builtin.hh (working copy)
@@ -29,7 +29,6 @@
# define OLN_VALUE_BUILTIN_HH
# include <oln/core/concept/value.hh>
-# include <oln/core/gen/traits.hh>
namespace oln
@@ -88,22 +87,12 @@
};
- template <typename Op>
- struct set_trait_< Value, int, Op, Value, float >
- {
- typedef float ret;
- };
- template <typename Op>
- struct set_trait_< Value, float, Op, Value, int >
- {
- typedef float ret;
- };
-
- // FIXME: To be continued...
+} // end of namespace oln
-} // end of namespace oln
+// FIXME: Bad?
+# include <oln/value/builtin_traits.hh>
#endif // ! OLN_VALUE_BUILTIN_HH
Index: oln/value/builtin_traits.hh
--- oln/value/builtin_traits.hh (revision 0)
+++ oln/value/builtin_traits.hh (revision 0)
@@ -0,0 +1,57 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_VALUE_BUILTIN_TRAITS_HH
+# define OLN_VALUE_BUILTIN_TRAITS_HH
+
+# include <oln/value/builtin.hh>
+# include <oln/core/gen/traits.hh>
+
+
+namespace oln
+{
+
+ template <typename Op>
+ struct set_trait_< Value, int, Op, Value, float >
+ {
+ typedef float ret;
+ };
+
+ template <typename Op>
+ struct set_trait_< Value, float, Op, Value, int >
+ {
+ typedef float ret;
+ };
+
+ // FIXME: To be continued...
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_VALUE_BUILTIN_TRAITS_HH
+
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
add point implementation for Iterator_On_Points.
* olena/tests/core/iter_point1d.cc, olena/tests/core/iter_point2d.cc: New.
* olena/tests/core/iter_point3d.cc: New test file.
* olena/tests/core/Makefile.am: Add new tests in make check.
* olena/oln/core/internal/iterator_on_points_impl.hh: New, implementations for Iterator_On_Points.
* olena/oln/core/internal/iterator_on_points_base.hh: Now derive from itertor_on_points_impl
oln/core/internal/iterator_on_points_base.hh | 10 +
oln/core/internal/iterator_on_points_impl.hh | 141 +++++++++++++++++++++++++++
tests/core/Makefile.am | 6 +
tests/core/iter_point1d.cc | 48 +++++++++
tests/core/iter_point2d.cc | 50 +++++++++
tests/core/iter_point3d.cc | 52 +++++++++
6 files changed, 305 insertions(+), 2 deletions(-)
Index: olena/tests/core/iter_point1d.cc
--- olena/tests/core/iter_point1d.cc (revision 0)
+++ olena/tests/core/iter_point1d.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.
+
+#include <cassert>
+
+#include <oln/core/1d/image1d.hh>
+#include <oln/core/internal/iterator_on_points_base.hh>
+
+
+
+int
+main()
+{
+
+ oln::image1d<int> ima1(40);
+ oln::image1d<int>::piter p (ima1.points());
+ oln::point1d p1;
+
+ for (p.start(); p.is_valid(); p.next())
+ p1.ind() = p.ind();
+
+ assert(p1.ind() == 39);
+ return 0;
+}
Index: olena/tests/core/iter_point2d.cc
--- olena/tests/core/iter_point2d.cc (revision 0)
+++ olena/tests/core/iter_point2d.cc (revision 0)
@@ -0,0 +1,50 @@
+// 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.
+
+#include <cassert>
+
+#include <oln/core/2d/image2d.hh>
+
+int
+main()
+{
+
+ oln::image2d<int> ima1(40, 30);
+ oln::image2d<int>::piter p (ima1.points());
+ oln::point2d p1;
+
+ for (p.start(); p.is_valid(); p.next())
+ {
+ p1.row() = p.row();
+ p1.col() = p.col();
+ }
+
+ assert(p1.row() == 39);
+ assert(p1.col() == 29);
+
+ return 0;
+}
Index: olena/tests/core/iter_point3d.cc
--- olena/tests/core/iter_point3d.cc (revision 0)
+++ olena/tests/core/iter_point3d.cc (revision 0)
@@ -0,0 +1,52 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <cassert>
+
+#include <oln/core/3d/image3d.hh>
+
+int
+main()
+{
+
+ oln::image3d<int> ima1(40, 30, 20);
+ oln::image3d<int>::piter p (ima1.points());
+ oln::point3d p1;
+
+ for (p.start(); p.is_valid(); p.next())
+ {
+ p1.row() = p.row();
+ p1.col() = p.col();
+ p1.slice() = p.slice();
+ }
+
+ assert(p1.row() == 39);
+ assert(p1.col() == 29);
+ assert(p1.slice() == 19);
+
+ return 0;
+}
Index: olena/tests/core/Makefile.am
--- olena/tests/core/Makefile.am (revision 923)
+++ olena/tests/core/Makefile.am (working copy)
@@ -25,6 +25,9 @@
grid \
image1d \
image2d \
+ iter_point1d \
+ iter_point2d \
+ iter_point3d \
neighb2d \
npoints \
point2d \
@@ -40,6 +43,9 @@
grid_SOURCES = grid.cc
image1d_SOURCES = image1d.cc
image2d_SOURCES = image2d.cc
+iter_point1d_SOURCES = iter_point1d.cc
+iter_point2d_SOURCES = iter_point2d.cc
+iter_point3d_SOURCES = iter_point3d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: olena/oln/core/internal/iterator_on_points_impl.hh
--- olena/oln/core/internal/iterator_on_points_impl.hh (revision 0)
+++ olena/oln/core/internal/iterator_on_points_impl.hh (revision 0)
@@ -0,0 +1,141 @@
+// 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_ITERATOR_ON_POINTS_IMPL_HH
+# define OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_IMPL_HH
+
+
+namespace oln
+{
+
+ // Forward declarations
+ namespace impl
+ {
+ template <unsigned n, typename Exact, typename P>
+ struct iterator_on_points_impl;
+ }
+
+
+ template <unsigned n, typename Exact, typename P>
+ struct super_trait_< impl::iterator_on_points_impl<n, Exact, P> >
+ {
+ typedef Any<P> ret;
+ };
+
+ template <unsigned n, typename Exact, typename P>
+ struct vtypes< impl::iterator_on_points_impl<n, Exact, P> >
+ {
+ };
+
+
+ namespace impl
+ {
+ template <unsigned n, typename Exact, typename P>
+ struct iterator_on_points_impl : public virtual Any<Exact>
+ {
+ };
+
+ /// point1d interface
+ template <typename Exact, typename P>
+ struct iterator_on_points_impl<1, Exact, P> : public virtual Any< Exact >
+ {
+ typename P::coord ind() const;
+ };
+
+ /// point2d interface
+ template <typename Exact, typename P>
+ struct iterator_on_points_impl<2, Exact, P>: public virtual Any< Exact >
+ {
+ typename P::coord row() const;
+ typename P::coord col() const;
+ };
+
+ /// point3d interface
+ template <typename Exact, typename P>
+ struct iterator_on_points_impl<3, Exact, P>: public virtual Any< Exact >
+ {
+ typename P::coord row() const;
+ typename P::coord col() const;
+ typename P::coord slice() const;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // point1d
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<1, Exact, P>::ind() const
+ {
+ return exact(this)->to_point().ind();
+ }
+
+ // point2d
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<2, Exact, P>::row() const
+ {
+ return exact(this)->to_point().row();
+ }
+
+
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<2, Exact, P>::col() const
+ {
+ return exact(this)->to_point().col();
+ }
+
+ // point3d
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<3, Exact, P>::row() const
+ {
+ return exact(this)->to_point().row();
+ }
+
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<3, Exact, P>::col() const
+ {
+ return exact(this)->to_point().col();
+ }
+
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<3, Exact, P>::slice() const
+ {
+ return exact(this)->to_point().slice();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln
+
+} // end of namespace oln
+
+#endif // ! OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_IMPL_HH
Index: olena/oln/core/internal/iterator_on_points_base.hh
--- olena/oln/core/internal/iterator_on_points_base.hh (revision 923)
+++ olena/oln/core/internal/iterator_on_points_base.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_impl.hh>
namespace oln
@@ -57,15 +58,20 @@
typedef stc::final< oln_coord(point__) > coord;
typedef stc::final< oln_dim(point__) > dim;
typedef stc::final< oln_dpoint(point__) > dpoint;
- };
+ // for getting point implementation
+ typedef stc_deferred(dim) dim__;
+ };
namespace internal
{
template <typename Exact>
- class iterator_on_points_base_ : public Iterator_on_Points<Exact>
+ class iterator_on_points_base_ : public Iterator_on_Points<Exact>,
+ public impl::iterator_on_points_impl
+ <mlc_value(typename vtypes< internal::iterator_on_points_base_<Exact> >::dim__),
+ Exact, typename vtypes< internal::iterator_on_points_base_<Exact> >::point__>
{
protected:
iterator_on_points_base_();
1
0
29 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add the image type ''function: p -> v over a point set''.
* oln/core/gen/image_pset_piter.hh: Remove; obsolete.
* oln/core/internal/image_base.hh: Move end of file to...
* oln/core/internal/image_ops.hh: ...this new file.
(operator/): New.
* oln/core/internal/op_fp2v_over_pset.hh: New.
* oln/core/gen/op.hh (oln_decl_op_over, over): New.
* oln/core/gen/single_value_image.hh,
* oln/core/internal/op_image_plus_nbh.hh: Cosmetic changes.
* oln/core/internal/f_pset_to_plain_image.hh
(pset_to_plain_image__): Fix version op_<S, such_as, F_p2b>.
gen/op.hh | 2
gen/single_value_image.hh | 4 -
internal/f_pset_to_plain_image.hh | 7 -
internal/image_base.hh | 76 -------------------
internal/image_ops.hh | 129 ++++++++++++++++++++++++++++++++
internal/op_fp2v_over_pset.hh | 151 ++++++++++++++++++++++++++++++++++++++
internal/op_image_plus_nbh.hh | 8 +-
7 files changed, 293 insertions(+), 84 deletions(-)
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 922)
+++ oln/core/gen/op.hh (working copy)
@@ -77,6 +77,7 @@
# define oln_decl_op_plus(Lconcept, Rconcept) oln_decl_op_( plus, 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)
+# define oln_decl_op_over(Lconcept, Rconcept) oln_decl_op_( over, Lconcept, /, Rconcept)
// ...
@@ -91,6 +92,7 @@
struct plus;
struct such_as;
struct restricted_to;
+ struct over;
/// \}
Index: oln/core/gen/single_value_image.hh
--- oln/core/gen/single_value_image.hh (revision 922)
+++ oln/core/gen/single_value_image.hh (working copy)
@@ -45,11 +45,11 @@
template <typename Ps, typename T>
struct vtypes< single_value_image<Ps, T> >
{
- typedef typename Ps::point point;
+ typedef oln_point(Ps) point;
typedef point psite;
typedef Ps pset;
- typedef typename point::coord coord;
+ typedef oln_coord(point) coord;
typedef T value;
typedef const T& rvalue;
Index: oln/core/internal/image_ops.hh
--- oln/core/internal/image_ops.hh (revision 0)
+++ oln/core/internal/image_ops.hh (revision 0)
@@ -0,0 +1,129 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_IMAGE_OPS_HH
+# define OLN_CORE_INTERNAL_IMAGE_OPS_HH
+
+# include <oln/core/internal/f_ch_value.hh>
+# 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>
+
+
+
+namespace oln
+{
+
+ // Image | Point_Set ( ima restricted_to pset )
+
+ oln_decl_op_restricted_to(Image, Point_Set);
+
+
+
+ // Image | Function_p2b ( ima such_as "f : p -> b"
+ // is ima restricted_to (ima.points such_as f) )
+ oln_decl_op_such_as(Image, Function_p2b);
+
+
+
+ // Function_p2v / Point_Set ( ima defined by: "f : p -> v" over pset )
+
+ oln_decl_op_over(Function_p2v, Point_Set);
+
+
+
+
+ // Specialization "f : P -> V over Point_Set".
+
+ template <typename V, typename P, typename S>
+ op_<const fun_p2v_<V (*)(P)>, over, const S>
+ operator / (V (*f)(P), const Point_Set<S>& pts)
+ {
+ typedef oln_strip_(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));
+ return tmp;
+ }
+
+
+
+ // Specialization "Image such_as f : P -> B".
+
+ template <typename I, typename B, typename P>
+ op_<const I, such_as, const fun_p2b_<B (*)(P)> >
+ operator | (const Image<I>& ima, B (*f)(P))
+ {
+ typedef oln_strip_(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);
+ return tmp;
+ }
+
+ template <typename I, typename B, typename P>
+ op_<I, such_as, const fun_p2b_<B (*)(P)> >
+ operator | (Image<I>& ima, B (*f)(P))
+ {
+ typedef oln_strip_(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);
+ return tmp;
+ }
+
+
+ // Specialization "Image such_as ima : P -> B".
+
+ template <typename I, typename J>
+ op_<const I, such_as, const fun_p2b_< Binary_Image<J> > >
+ operator | (const Image<I>& ima, const Binary_Image<J>& f_ima_b)
+ {
+ precondition(f_ima_b.points() >= ima.points());
+ mlc::assert_equal_< oln_point(I), oln_point(J) >::check();
+ op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), f_ima_b);
+ return tmp;
+ }
+
+ template <typename I, typename J>
+ op_<I, such_as, const fun_p2b_< Binary_Image<J> > >
+ operator | (Image<I>& ima, const Binary_Image<J>& f_ima_b)
+ {
+ precondition(f_ima_b.points() >= ima.points());
+ mlc::assert_equal_< oln_point(I), oln_point(J) >::check();
+ op_<I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), f_ima_b);
+ return tmp;
+ }
+
+
+ // FIXME: What about Mutable_Image so that "ima | something" can be left-value?
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_IMAGE_OPS_HH
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 922)
+++ oln/core/internal/image_base.hh (working copy)
@@ -473,80 +473,8 @@
-
-/// \{
-/// FIXME: Bad!
-
-# include <oln/core/internal/f_ch_value.hh>
-# include <oln/core/internal/op_image_restricted_to_pset.hh>
-# include <oln/core/internal/op_image_such_as_fp2b.hh>
-
-namespace oln
-{
- // Image | Point_Set ( ima restricted_to pset )
-
- oln_decl_op_restricted_to(Image, Point_Set);
-
-
- // Image | Function_p2b ( ima such_as "f : p -> b"
- // is ima restricted_to (ima.points such_as f) )
- oln_decl_op_such_as(Image, Function_p2b);
-
-
- // Specialization "Image such_as f : P -> B".
-
- template <typename I, typename B, typename P>
- op_<const I, such_as, const fun_p2b_<B (*)(P)> >
- operator | (const Image<I>& ima, B (*f)(P))
- {
- typedef oln_strip_(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);
- return tmp;
- }
-
- template <typename I, typename B, typename P>
- op_<I, such_as, const fun_p2b_<B (*)(P)> >
- operator | (Image<I>& ima, B (*f)(P))
- {
- typedef oln_strip_(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);
- return tmp;
- }
-
-
- // Specialization "Image such_as ima : P -> B".
-
- template <typename I, typename J>
- op_<const I, such_as, const fun_p2b_< Binary_Image<J> > >
- operator | (const Image<I>& ima, const Binary_Image<J>& f_ima_b)
- {
- precondition(f_ima_b.points() >= ima.points());
- mlc::assert_equal_< oln_point(I), oln_point(J) >::check();
- op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), f_ima_b);
- return tmp;
- }
-
- template <typename I, typename J>
- op_<I, such_as, const fun_p2b_< Binary_Image<J> > >
- operator | (Image<I>& ima, const Binary_Image<J>& f_ima_b)
- {
- precondition(f_ima_b.points() >= ima.points());
- mlc::assert_equal_< oln_point(I), oln_point(J) >::check();
- op_<I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), f_ima_b);
- return tmp;
- }
-
-
- // FIXME: What about Mutable_Image so that "ima | something" can be left-value?
-
-
-} // end of namespace oln
-
-/// \}
+// FIXME: Bad!
+# include <oln/core/internal/image_ops.hh>
Index: oln/core/internal/op_fp2v_over_pset.hh
--- oln/core/internal/op_fp2v_over_pset.hh (revision 0)
+++ oln/core/internal/op_fp2v_over_pset.hh (revision 0)
@@ -0,0 +1,151 @@
+// 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_FP2V_OVER_PSET
+# define OLN_CORE_INTERNAL_OP_FP2V_OVER_PSET
+
+# include <oln/core/concept/point_set.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/f_pset_to_plain_image.hh>
+# include <oln/core/gen/op.hh>
+
+
+namespace oln
+{
+
+# define current \
+ special_op_< stc::is<Function_p2v>, F, over, stc::is<Point_Set>, S >
+
+
+ // Super type.
+ template <typename F, typename S>
+ struct super_trait_< internal::current >
+ {
+ typedef internal::primitive_image_< op_<F, over, S> > ret;
+ };
+
+
+ /// Virtual types.
+ template <typename F, typename S>
+ struct vtypes< internal::current >
+ {
+ typedef op_<F, over, S> Exact;
+
+ typedef oln_point(S) point;
+ typedef point psite;
+ typedef S pset;
+
+ typedef oln_coord(point) coord;
+
+ typedef oln_result(F) value; // FIXME: Unconst, unref!
+ typedef oln_result(F) rvalue;
+
+ typedef internal::pair<F, S> data;
+
+ typedef oln_f_pset_to_plain_image(S, value) plain;
+ typedef void skeleton; // FIXME: check that this type is never accessed?
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class for the result of "Function_p2v F / Point_Set S".
+
+ template <typename F, typename S>
+ class current : public internal::primitive_image_< op_<F, over, S> >
+ {
+ typedef internal::primitive_image_< op_<F, over, S> > super;
+ public:
+ stc_using(data);
+ stc_using(point);
+ stc_using(rvalue);
+
+ bool impl_owns_(const point& p) const;
+ rvalue impl_read(const point& p) const;
+ const S& impl_points() const;
+
+ protected:
+ special_op_();
+ special_op_(F& fun, S& pts);
+ };
+
+ } // end of namespace oln::internal
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename F, typename S>
+ current::special_op_()
+ {
+ }
+
+ template <typename F, typename S>
+ current::special_op_(F& fun, S& pts)
+ {
+ this->data_ = new data(fun, pts);
+ }
+
+ template <typename F, typename S>
+ bool
+ current::impl_owns_(const typename current::point& p) const
+ {
+ assert(this->has_data());
+ return this->data_->second.has(p);
+ }
+
+ template <typename F, typename S>
+ typename current::rvalue
+ current::impl_read(const typename current::point& p) const
+ {
+ assert(this->has_data());
+ return this->data_->first(p);
+ }
+
+ template <typename F, typename S>
+ const S&
+ current::impl_points() const
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
+ } // end of namespace oln::internal
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_FP2V_OVER_PSET_HH
Index: oln/core/internal/f_pset_to_plain_image.hh
--- oln/core/internal/f_pset_to_plain_image.hh (revision 922)
+++ oln/core/internal/f_pset_to_plain_image.hh (working copy)
@@ -101,12 +101,11 @@
typedef oln_f_grid_to_plain_image(oln_grid(P), T) ret;
};
- template <typename S, typename F, typename T>
- struct pset_to_plain_image__< op_<S, such_as, F>, T >
+ template <typename S, typename F_p2b, typename T>
+ struct pset_to_plain_image__< op_<S, such_as, F_p2b>, T >
{
- typedef op_<S, such_as, F> Ps;
typedef typename f_pset_to_plain_image_<S, T>::ret I;
- typedef op_<I, restricted_to, Ps> ret;
+ typedef op_<I, such_as, F_p2b> ret;
};
/// \}
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 922)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -45,12 +45,12 @@
oln_decl_instant_value(nbh);
- /// Fwd decls.
+ // Fwd decls.
template <typename Exact> struct Image;
template <typename Exact> struct Neighborhood;
- /// Super type.
+ // Super type.
template <typename I, typename N>
struct super_trait_< internal::current >
{
@@ -58,7 +58,7 @@
};
- /// Virtual types.
+ // Virtual types.
template <typename I, typename N>
struct vtypes< internal::current >
{
@@ -224,7 +224,7 @@
return ima_ok and nbh_ok;
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
# undef current
1
0