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
March 2007
- 7 participants
- 73 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add pw_value and operators on functions.
* oln/core/concept/generator.hh,
* oln/core/gen/literal.hh,
* oln/core/gen/fun_ops.hh: New.
* tests/core/image1d.cc,
* tests/core/pw_value.cc: Update.
* tests/core/Makefile.am (check_PROGRAMS): Clean.
Add image1d and pw_value.
* oln/level/fill.hh: Remove too restrictive const&.
* oln/core/equipment.hh (result, oln_result, oln_rvalue): New.
* oln/core/gen/pw_value.hh: Update.
* oln/core/gen/fun.hh (fun_p2b_): New specialization for binary
images.
* oln/core/internal/image_base.hh (operator|): Likewise.
Add a FIXME as a reminder.
oln/core/concept/generator.hh | 60 +++++++
oln/core/equipment.hh | 4
oln/core/gen/fun.hh | 22 ++
oln/core/gen/fun_ops.hh | 325 ++++++++++++++++++++++++++++++++++++++++
oln/core/gen/literal.hh | 158 +++++++++++++++++++
oln/core/gen/pw_value.hh | 80 ++++-----
oln/core/internal/image_base.hh | 17 ++
oln/level/fill.hh | 6
tests/core/Makefile.am | 20 +-
tests/core/image1d.cc | 24 +-
tests/core/pw_value.cc | 14 -
11 files changed, 653 insertions(+), 77 deletions(-)
Index: tests/core/image1d.cc
--- tests/core/image1d.cc (revision 900)
+++ tests/core/image1d.cc (working copy)
@@ -28,33 +28,33 @@
/// Test oln::image1d.
#include <cassert>
-// FIXME: We should not include oln/basics1d.hh, but
-// oln/core/1d/image1d.hh (and oln/core/1d/neigh1d.hh ?).
-#include <oln/basics1d.hh>
+#include <oln/core/1d/image1d.hh>
#include <oln/level/fill.hh>
int
main()
{
+ using namespace oln;
+
// Fill a 1D image using its iterator.
- oln::image1d<char> ima1(3);
- oln_vtype_(oln::image1d<char>, piter) p1(ima1.topo());
+ image1d<char> ima1(3);
+ image1d<char>::piter p1(ima1.points());
for_all(p1)
ima1(p1) = 1;
// Fill a 1D image using a classic loop.
- oln::image1d<int> ima2(ima1.topo());
+ image1d<int> ima2(ima1.points());
for (unsigned i = 0; i < 3; ++i)
- ima2(oln::point1d(i)) = 2;
+ ima2(i) = 2;
- // Fill a 1D image using the routine oln::level::fill.
- oln::image1d<long> ima3(ima1.topo());
- oln::level::fill(ima3, 3);
+ // Fill a 1D image using the routine level::fill.
+ image1d<long> ima3(ima1.points());
+ level::fill(ima3, 3);
// Add the three images.
- oln::image1d<long> sum(ima1.topo());
- oln_vtype_(oln::image1d<long>, piter) p(sum.topo());
+ image1d<long> sum(ima1.points());
+ image1d<long>::piter p(sum.points());
for_all(p)
sum(p) = ima1(p) + ima2(p) + ima3(p);
// And check the sum.
Index: tests/core/pw_value.cc
--- tests/core/pw_value.cc (revision 900)
+++ tests/core/pw_value.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
@@ -29,9 +29,9 @@
#include <cassert>
-#include <oln/basics2d.hh>
+#include <oln/core/2d/image2d.hh>
#include <oln/core/gen/pw_value.hh>
-
+#include <oln/debug/iota.hh>
int main()
@@ -39,12 +39,12 @@
using namespace oln;
point2d p(0,0);
- image2d<int> ima1(3,3);
- ima1(p) = 1;
+ image2d<double> ima1(3,3);
+ ima1(p) = 1.;
- image2d<float> ima2(3,3);
+ image2d<double> ima2(3,3);
ima2(p) = 2.3;
- double d = ((pw_value(ima1) + 4 * pw_value(ima2)) / .2)(p);
+ double d = ((pw_value(ima1) + pw_value(ima2) * literal(4.)) / literal(.2))(p);
assert(d > 50.9999 and d < 51.0001);
}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 900)
+++ tests/core/Makefile.am (working copy)
@@ -19,31 +19,35 @@
check_PROGRAMS = \
- rle_image \
- sparse_image \
apply \
+ at \
dpoint2d \
- point2d \
grid \
+ image1d \
image2d \
neighb2d \
npoints \
+ point2d \
+ pw_value \
+ rle_image \
+ sparse_image \
subset \
- window2d \
- at
+ window2d
# Images and auxiliary structures.
dpoint2d_SOURCES = dpoint2d.cc
-point2d_SOURCES = point2d.cc
grid_SOURCES = grid.cc
+image1d_SOURCES = image1d.cc
image2d_SOURCES = image2d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
-subset_SOURCES = subset.cc
-window2d_SOURCES = window2d.cc
+point2d_SOURCES = point2d.cc
+pw_value_SOURCES = pw_value.cc
rle_image_SOURCES = rle_image.cc
sparse_image_SOURCES = sparse_image.cc
+subset_SOURCES = subset.cc
+window2d_SOURCES = window2d.cc
# Methods.
at_SOURCES = at.cc
Index: oln/level/fill.hh
--- oln/level/fill.hh (revision 900)
+++ oln/level/fill.hh (working copy)
@@ -54,7 +54,7 @@
void fill(Mutable_Image<I>& input, const V values[]);
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(const P&));
+ void fill(Mutable_Image<I>& input, V (*fun)(P));
@@ -100,7 +100,7 @@
}
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(const P&))
+ void fill(Mutable_Image<I>& input, V (*fun)(P))
{
oln_piter(I) p(input.points());
for_all(p)
@@ -134,7 +134,7 @@
}
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(const P&))
+ void fill(Mutable_Image<I>& input, V (*fun)(P))
{
impl::fill(exact(input), fun);
}
Index: oln/core/concept/generator.hh
--- oln/core/concept/generator.hh (revision 0)
+++ oln/core/concept/generator.hh (revision 0)
@@ -0,0 +1,60 @@
+// 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_CONCEPT_GENERATOR_HH
+# define OLN_CORE_CONCEPT_GENERATOR_HH
+
+# include <oln/core/concept/function.hh>
+
+
+namespace oln
+{
+
+ // void -> Value.
+
+ template <typename Exact>
+ struct Generator : public Function<Exact>
+ {
+ protected:
+ Generator();
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Generator<Exact>::Generator()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_GENERATOR_HH
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 900)
+++ oln/core/equipment.hh (working copy)
@@ -131,10 +131,14 @@
# define oln_qiter(T) oln_typename_shortcut__(T, qiter)
// r
+ stc_decl_associated_type( result );
stc_decl_associated_type( right );
stc_decl_associated_type( rvalue );
stc_decl_associated_type( rvaluep );
+# define oln_result(T) oln_typename_shortcut__(T, result)
+# define oln_rvalue(T) oln_typename_shortcut__(T, rvalue)
+
// s
stc_decl_associated_type( std_container );
stc_decl_associated_type( skeleton );
Index: oln/core/gen/pw_value.hh
--- oln/core/gen/pw_value.hh (revision 900)
+++ oln/core/gen/pw_value.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2005, 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,79 +29,68 @@
#ifndef OLN_CORE_GEN_PW_VALUE_HH
# define OLN_CORE_GEN_PW_VALUE_HH
-# include <oln/core/abstract/image.hh>
-# include <xtd/abstract/meta_nary_fun.hh>
-# include <xtd/math.hh>
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/fun_ops.hh>
-
-namespace xtd
+namespace oln
{
- // Fwd decl.
- template <typename I>
- class pw_value_type;
-
-
- template <typename I, typename A>
- struct res_< pw_value_type<I>, A >
+ namespace ERROR
{
- typedef oln_rvalue(I) ret;
- };
+ template <typename I>
+ struct pw_value_works_on_images_not_on_;
+ } // end of namespace oln::ERROR
template <typename I>
- class pw_value_type : public xtd::abstract::meta_nary_fun_< 1, pw_value_type<I> >
+ class pw_value_ : public Function_p2v< pw_value_<I> >,
+ private mlc::assert_< mlc_is_a(I, Image),
+ ERROR::pw_value_works_on_images_not_on_<I> >
{
public:
+ typedef oln_point(I) argument; // FIXME: psite?
+ typedef oln_value(I) result;
- pw_value_type(const I& ima);
-
- template <typename P>
- oln_rvalue(I) impl_calc(const P& p) const;
+ pw_value_(const Point_Wise_Accessible_Image<I>& ima);
+ oln_value(I) operator()(const oln_point(I)& p) const;
protected:
-
- const I ima_;
+ const I& ima_;
};
+ template <typename I>
+ pw_value_<I>
+ pw_value(const Image<I>& ima);
+
+
# ifndef OLN_INCLUDE_ONLY
template <typename I>
- template <typename A>
- oln_rvalue(I)
- pw_value_type<I>::impl_calc(const A& a) const
- {
- mlc::assert_< mlc::or_< mlc_is_a(A, oln::abstract::point),
- mlc_is_a(A, oln::abstract::iterator_on_points) > >::check();
- return ima_(a);
+ pw_value_<I>::pw_value_(const Point_Wise_Accessible_Image<I>& ima)
+ : ima_(exact(ima))
+ {
}
template <typename I>
- pw_value_type<I>::pw_value_type(const I& ima)
- : ima_(ima)
+ oln_value(I)
+ pw_value_<I>::operator()(const oln_point(I)& p) const
{
+ precondition(this->ima_.owns_(p));
+ return this->ima_(p);
}
-# endif
-
-
-} // end of namespace xtd
-
-
-namespace oln
-{
-
template <typename I>
- xtd::m1expr_< xtd::pw_value_type<I>, xtd::arg_<1> >
- pw_value(const abstract::image<I>& ima)
+ pw_value_<I>
+ pw_value(const Point_Wise_Accessible_Image<I>& ima)
{
- xtd::pw_value_type<I> pwv(ima.exact());
- using xtd::_1;
- return pwv(_1); // expects one argument (for instance a point) or an expression :)
+ pw_value_<I> tmp(ima);
+ return tmp;
}
+# endif // ! OLN_INCLUDE_ONLY
+
} // end of namespace oln
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 900)
+++ oln/core/gen/fun.hh (working copy)
@@ -30,7 +30,7 @@
# include <oln/core/internal/category_of.hh>
# include <oln/core/concept/function.hh>
-# include <oln/core/concept/point.hh>
+# include <oln/core/concept/image.hh>
# include <oln/core/concept/value.hh>
@@ -116,6 +116,25 @@
F f_;
};
+ // Specialization.
+ template <typename I>
+ struct fun_p2b_< Binary_Image<I> > : public Function_p2b< fun_p2b_< Binary_Image<I> > >
+ {
+ typedef const oln_point(I)& argument;
+ typedef oln_rvalue(I) result;
+
+ fun_p2b_(const Binary_Image<I>& ima)
+ : ima_(exact(ima))
+ {}
+
+ result operator()(argument arg) const
+ {
+ return this->ima_(arg);
+ }
+
+ private:
+ I ima_;
+ };
@@ -164,7 +183,6 @@
}
-
} // end of namespace oln
Index: oln/core/gen/literal.hh
--- oln/core/gen/literal.hh (revision 0)
+++ oln/core/gen/literal.hh (revision 0)
@@ -0,0 +1,158 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef 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>
+
+
+
+
+namespace oln
+{
+
+
+
+ // ----------------------------- literal_<T>
+
+
+ template <typename T>
+ struct literal_ : public Generator< literal_<T> >
+ {
+ typedef T result;
+
+ literal_(const T& val) : val_(val) {}
+
+ const result& operator()() const
+ {
+ return this->val_;
+ }
+
+ const result& value() const
+ {
+ return this->val_;
+ }
+
+ private:
+ T val_;
+ };
+
+
+ // literal
+ template <typename T>
+ literal_<T>
+ literal(const T& val)
+ {
+ literal_<T> tmp(val);
+ return tmp;
+ }
+
+
+ // ----------------------------- lit_p2v_<P,T>
+
+
+ // Fwd decl.
+ template <typename P, typename T> struct lit_p2v_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename P, typename T>
+ struct set_category_of_< lit_p2v_<P,T> >
+ {
+ typedef stc::is< Function_p2v > ret;
+ };
+ }
+
+ // Class.
+ template <typename P, typename T>
+ struct lit_p2v_ : public Function_p2v< lit_p2v_<P,T> >
+ {
+ typedef P argument;
+ typedef T result;
+
+ lit_p2v_(const T& val)
+ : val_(val)
+ {
+ }
+
+ result operator()(argument) const
+ {
+ return this->val_;
+ }
+
+ private:
+ T val_;
+ };
+
+
+ // ----------------------------- lit_p2b_<P,B>
+
+
+ // Fwd decl.
+ template <typename P, typename B> struct lit_p2b_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename P, typename B>
+ struct set_category_of_< lit_p2b_<P,B> >
+ {
+ typedef stc::is< Function_p2b > ret;
+ };
+ }
+
+ // Class.
+ template <typename P, typename B>
+ struct lit_p2b_ : public Function_p2b< lit_p2b_<P,B> >
+ {
+ typedef P argument;
+ typedef B result;
+
+ lit_p2b_(const B& val)
+ : val_(val)
+ {
+ }
+
+ result operator()(argument) const
+ {
+ return this->val_;
+ }
+
+ private:
+ B val_;
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_LITERAL_HH
Index: oln/core/gen/fun_ops.hh
--- oln/core/gen/fun_ops.hh (revision 0)
+++ oln/core/gen/fun_ops.hh (revision 0)
@@ -0,0 +1,325 @@
+// 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_FUN_OPS_HH
+# define OLN_CORE_GEN_FUN_OPS_HH
+
+# include <oln/core/concept/function.hh>
+# include <oln/core/concept/point.hh>
+# include <oln/core/gen/literal.hh>
+
+
+
+# define oln_decl_p2v_cmp_(Name, Sym) \
+ \
+ template <typename L, typename R> struct p2v_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename L, typename R> \
+ struct set_category_of_< p2v_##Name##_<L,R> > \
+ { \
+ typedef stc::is< Function_p2b > ret; \
+ }; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct p2v_##Name##_ : public Function_p2b< p2v_##Name##_<L,R> > \
+ { \
+ typedef oln_arg_of_(L) argument; \
+ typedef bool result; /* FIXME: trait! */ \
+ \
+ p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ : left_(exact(left)), \
+ right_(exact(right)) \
+ { \
+ } \
+ bool operator()(argument arg) const \
+ { \
+ return this->left_(arg) Sym this->right_(arg); \
+ } \
+ private: \
+ L left_; \
+ R right_; \
+ }; \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L,R> \
+ operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ mlc::assert_equal_< oln_argument(L), oln_argument(R) >::check(); \
+ p2v_##Name##_<L,R> tmp(left, right); \
+ return tmp; \
+ } \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \
+ operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ lit_p2v_<oln_argument(L), R> right_(right.value()); \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+# define oln_decl_p2v_arith_(Name, Sym) \
+ \
+ template <typename L, typename R> struct p2v_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename L, typename R> \
+ struct set_category_of_< p2v_##Name##_<L,R> > \
+ { \
+ typedef stc::is< Function_p2v > ret; \
+ }; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<L,R> > \
+ { \
+ typedef oln_arg_of_(L) argument; \
+ typedef oln_res_of_(L) result; /* FIXME: trait! */ \
+ \
+ p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ : left_(exact(left)), \
+ right_(exact(right)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return this->left_(arg) Sym this->right_(arg); \
+ } \
+ private: \
+ L left_; \
+ R right_; \
+ }; \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L,R> \
+ operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ p2v_##Name##_<L,R> tmp(left, right); \
+ return tmp; \
+ } \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \
+ operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ lit_p2v_<oln_argument(L), R> right_(right.value()); \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+# define oln_decl_p2v_un_(Name, Sym) \
+ \
+ template <typename T> struct p2v_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename T> \
+ struct set_category_of_< p2v_##Name##_<T> > \
+ { \
+ typedef stc::is< Function_p2v > ret; \
+ }; \
+ } \
+ \
+ template <typename T> \
+ struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<T> > \
+ { \
+ typedef oln_arg_of_(T) argument; \
+ typedef oln_res_of_(T) result; /* FIXME: trait! */ \
+ \
+ p2v_##Name##_(const Function_p2v<T>& oper) \
+ : oper_(exact(oper)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return Sym this->oper_(arg); \
+ } \
+ private: \
+ T oper_; \
+ }; \
+ \
+ template <typename T> \
+ p2v_##Name##_<T> \
+ operator Sym (const Function_p2v<T>& oper) \
+ { \
+ p2v_##Name##_<T> tmp(oper); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+# define oln_decl_p2b_bin_(Name, Sym) \
+ \
+ template <typename L, typename R> struct p2b_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename L, typename R> \
+ struct set_category_of_< p2b_##Name##_<L,R> > \
+ { \
+ typedef stc::is< Function_p2b > ret; \
+ }; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<L,R> > \
+ { \
+ typedef oln_arg_of_(L) argument; \
+ typedef oln_res_of_(L) result; \
+ \
+ p2b_##Name##_(const Function_p2b<L>& left, const Function_p2b<R>& right) \
+ : left_(exact(left)), \
+ right_(exact(right)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return this->left_(arg) Sym this->right_(arg); \
+ } \
+ private: \
+ L left_; \
+ R right_; \
+ }; \
+ \
+ template <typename L, typename R> \
+ p2b_##Name##_<L,R> \
+ operator Sym (const Function_p2b<L>& left, const Function_p2b<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ p2b_##Name##_<L,R> tmp(left, right); \
+ return tmp; \
+ } \
+ \
+ template <typename L, typename R> \
+ p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > \
+ operator Sym (const Function_p2b<L>& left, const literal_<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ lit_p2b_<oln_argument(L), R> right_(right.value()); \
+ p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > tmp(left, right_); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+
+# define oln_decl_p2b_un_(Name, Sym) \
+ \
+ template <typename T> struct p2b_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename T> \
+ struct set_category_of_< p2b_##Name##_<T> > \
+ { \
+ typedef stc::is< Function_p2b > ret; \
+ }; \
+ } \
+ \
+ template <typename T> \
+ struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<T> > \
+ { \
+ typedef oln_arg_of_(T) argument; \
+ typedef oln_res_of_(T) result; /* FIXME: trait! */ \
+ \
+ p2b_##Name##_(const Function_p2b<T>& oper) \
+ : oper_(exact(oper)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return Sym this->oper_(arg); \
+ } \
+ private: \
+ T oper_; \
+ }; \
+ \
+ template <typename T> \
+ p2b_##Name##_<T> \
+ operator Sym (const Function_p2b<T>& oper) \
+ { \
+ p2b_##Name##_<T> tmp(oper); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+namespace oln
+{
+
+ oln_decl_p2v_cmp_( eq, = );
+ oln_decl_p2v_cmp_( not_eq, != );
+ oln_decl_p2v_cmp_( less, < );
+ oln_decl_p2v_cmp_( leq, <= );
+ oln_decl_p2v_cmp_( greater, > );
+ oln_decl_p2v_cmp_( geq, >= );
+
+ oln_decl_p2v_arith_( plus, + );
+ oln_decl_p2v_arith_( minus, - );
+ oln_decl_p2v_arith_( times, * );
+ oln_decl_p2v_arith_( div, / );
+ oln_decl_p2v_arith_( mod, % );
+
+ oln_decl_p2v_un_( uminus, - );
+
+ oln_decl_p2b_bin_( and, && );
+ oln_decl_p2b_bin_( or, || );
+ oln_decl_p2b_bin_( xor, ^ );
+ // FIXME: nand, nor, xnor?
+
+ oln_decl_p2b_un_( not, ! );
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_FUN_OPS_HH
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 900)
+++ oln/core/internal/image_base.hh (working copy)
@@ -504,6 +504,23 @@
return tmp;
}
+
+ // Specialization.
+
+ 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)
+ {
+ // FIXME: Activate 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;
+ }
+
+
+ // FIXME: What about Mutable_Image so that "ima | something" can be left-value?
+
+
} // end of namespace oln
/// \}
1
0
Re: [Olena-patches] 881: New test for rle_class and sparse_image class.
by Thierry GERAUD 23 Mar '07
by Thierry GERAUD 23 Mar '07
23 Mar '07
Nicolas Ballas wrote:
>
> Index: ChangeLog
> from Nicolas Ballas <ballas(a)lrde.epita.fr>
>
> New test for rle_class and sparse_image class.
>
> * tests/core/sparse_image.cc: New.
> * tests/core/rle_image.cc: New.
> * tests/core/Makefile.am: Update
> ...
tests should be quiet
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Optimize the return of Image::points().
* oln/debug/iota.hh: Update.
* oln/core/rle/rle_image.hh,
* oln/core/sparse/sparse_image.hh: Add assertions; Fix include.
* oln/core/gen/niter_has.hh (pset_): Add &.
* oln/core/concept/image.hh (bbox, points, impl_points): Add &.
* oln/core/concept/image_identity.hh,
* oln/core/rle/rle_image.hh,
* oln/core/sparse/sparse_image.hh,
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh,
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh,
* oln/core/internal/op_image_restricted_to_pset.hh (impl_points):
Update.
* oln/basics1d.hh,
* oln/basics2d.hh: Remove; obsolete.
* oln/core/internal/utils.hh (pair, triplet): New specializations.
* oln/core/1d/array1d.hh,
* oln/core/2d/array2d.hh: Add method decls without impl.
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh,
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh: Make use of pair and triplet.
core/1d/array1d.hh | 7 +
core/1d/image1d.hh | 35 ++++-----
core/1d/image1d_b.hh | 20 ++---
core/2d/array2d.hh | 8 ++
core/2d/image2d.hh | 49 +++++++-----
core/2d/image2d_b.hh | 104 ++++++++++-----------------
core/concept/image.hh | 9 +-
core/concept/image_identity.hh | 4 -
core/gen/niter_has.hh | 2
core/internal/op_image_restricted_to_pset.hh | 4 -
core/internal/utils.hh | 75 +++++++++++++++++--
core/rle/rle_image.hh | 17 ++--
core/sparse/sparse_image.hh | 25 ++++--
debug/iota.hh | 4 -
14 files changed, 216 insertions(+), 147 deletions(-)
Index: oln/debug/iota.hh
--- oln/debug/iota.hh (revision 899)
+++ oln/debug/iota.hh (working copy)
@@ -41,8 +41,8 @@
template <typename I>
void iota(Mutable_Image<I>& in_out)
{
- typename I::value v = 0;
- typename I::fwd_piter p(in_out.points());
+ oln_value(I) v = 0;
+ oln_fwd_piter(I) p(in_out.points());
for_all(p)
in_out(p) = v++;
}
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 899)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -26,12 +26,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_IMAGE_HH
-# define OLN_CORE_RLE_RLE_IMAGE_HH
+#ifndef OLN_CORE_GEN_RLE_IMAGE_HH
+# define OLN_CORE_GEN_RLE_IMAGE_HH
# include <map>
-# include <utility>
-
# include <oln/core/internal/image_base.hh>
# include <oln/core/rle/rle_psite.hh>
@@ -97,7 +95,7 @@
rle_image();
/// pset impl_points() const : return image pset
- pset impl_points() const;
+ const pset& impl_points() const;
/// bool impl_owns_(const psite& p) const : same has impl_has
bool impl_owns_(const psite& p) const;
/// void insert(const point& p, unsigned len, value val) : insert a new range on the image
@@ -118,9 +116,10 @@
}
template <typename P, typename T>
- typename rle_image<P, T>::pset
+ const typename rle_image<P, T>::pset&
rle_image<P, T>::impl_points() const
{
+ assert(this->has_data());
return this->data_->first;
}
@@ -128,6 +127,7 @@
bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const
{
+ assert(this->has_data());
return this->data_->first.has(p.start_);
}
@@ -136,6 +136,7 @@
rle_image<P, T>::insert(const typename rle_image<P, T>::point& p,
unsigned len, rle_image<P, T>::value val)
{
+ assert(this->has_data());
this->data_->first.insert(p, len);
this->data_->second[p] = val;
}
@@ -144,6 +145,7 @@
typename rle_image<P, T>::rvalue
rle_image<P, T>::impl_read(const rle_image<P, T>::psite& ps) const
{
+ assert(this->has_data());
typename std::map<point, value>::const_iterator irun;
irun = this->data_->second.find(ps.start_);
@@ -156,6 +158,7 @@
typename rle_image<P, T>::lvalue
rle_image<P, T>::impl_read_write(const rle_image<P, T>::psite& ps)
{
+ assert(this->has_data());
typename std::map<point, value>::iterator irun;
irun = this->data_->second.find(ps.start_);
@@ -168,4 +171,4 @@
} // end of namespace oln
-#endif // !OLN_CORE_RLE_RLE_IMAGE_HH
+#endif // ! OLN_CORE_GEN_RLE_IMAGE_HH
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 899)
+++ oln/core/concept/image.hh (working copy)
@@ -134,10 +134,10 @@
bool owns_(const psite& p) const;
rvalue operator()(const psite& p) const;
- pset points() const;
+ const pset& points() const;
// With final impl:
- box bbox() const;
+ const box& bbox() const;
protected:
Image();
@@ -438,14 +438,14 @@
}
template <typename Exact>
- typename Image<Exact>::box
+ const typename Image<Exact>::box&
Image<Exact>::bbox() const
{
return this->points().bbox(); // Final impl.
}
template <typename Exact>
- typename Image<Exact>::pset
+ const typename Image<Exact>::pset&
Image<Exact>::points() const
{
return exact(this)->impl_points();
@@ -512,7 +512,6 @@
bool
Point_Wise_Accessible_Image<Exact>::has(const typename Point_Wise_Accessible_Image<Exact>::point& p) const
{
- // FIXME: precondition(this->owns_(p)); ?
return this->points().has(p);
}
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 899)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -54,7 +54,7 @@
bool impl_owns_(const psite& p) const;
rvalue impl_read(const psite& p) const;
- pset impl_points() const;
+ const pset& impl_points() const;
};
@@ -192,7 +192,7 @@
}
template <typename Exact>
- typename set_impl< Image, behavior::identity, Exact >::pset
+ const typename set_impl< Image, behavior::identity, Exact >::pset&
set_impl< Image, behavior::identity, Exact >::impl_points() const
{
return exact(this)->image().points();
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 899)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -25,10 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SPARSE_IMAGE_HH_
-# define SPARSE_IMAGE_HH_
+#ifndef OLN_CORE_GEN_SPARSE_IMAGE_HH
+# define OLN_CORE_GEN_SPARSE_IMAGE_HH
# include <vector>
+# include <map>
+
+# include <oln/core/internal/image_base.hh>
+
+
namespace oln
{
@@ -82,7 +87,7 @@
sparse_image();
- pset impl_points() const;
+ const pset& impl_points() const;
bool impl_owns_(const psite& p) const;
void insert(const point& p, unsigned len, const std::vector<value>& val);
rvalue impl_read(const psite& p) const;
@@ -90,8 +95,8 @@
};
-# ifndef OLN_INCLUDE_ONLY
+# ifndef OLN_INCLUDE_ONLY
template <typename P, typename T>
sparse_image<P, T>::sparse_image()
@@ -100,9 +105,10 @@
}
template <typename P, typename T>
- typename sparse_image<P, T>::pset
+ const typename sparse_image<P, T>::pset&
sparse_image<P, T>::impl_points() const
{
+ assert(this->has_data());
return this->data_->first;
}
@@ -110,6 +116,7 @@
bool
sparse_image<P, T>::impl_owns_(const typename sparse_image<P, T>::psite& p) const
{
+ assert(this->has_data());
return this->data_->first.has(p.start_);
}
@@ -117,6 +124,7 @@
void
sparse_image<P, T>::insert(const point& p, unsigned len, const std::vector<typename sparse_image<P, T>::value>& val)
{
+ assert(this->has_data());
this->data_->first.insert(p, len);
this->data_->second[p] = val;
}
@@ -125,6 +133,7 @@
typename sparse_image<P, T>::rvalue
sparse_image<P, T>::impl_read(const sparse_image<P, T>::psite& ps) const
{
+ assert(this->has_data());
typename std::map<point, std::vector<value> >::const_iterator irun;
irun.operator= (this->data_->second.find(ps.start_));
@@ -136,6 +145,7 @@
typename sparse_image<P, T>::lvalue
sparse_image<P, T>::impl_read_write(const sparse_image<P, T>::psite& ps)
{
+ assert(this->has_data());
typename std::map<point, std::vector<value> >::iterator irun;
irun.operator= (this->data_->second.find(ps.start_));
@@ -143,10 +153,9 @@
return irun->second[ps.index_];
}
-
-# endif /* !OLN_INCLUDE_ONLY */
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
-#endif /* !SPARSE_IMAGE_HH_ */
+#endif // ! OLN_CORE_GEN_SPARSE_IMAGE_HH
Index: oln/core/1d/array1d.hh
--- oln/core/1d/array1d.hh (revision 899)
+++ oln/core/1d/array1d.hh (working copy)
@@ -43,6 +43,13 @@
{
public:
+ // Not impled.
+ array1d_();
+ array1d_(const array1d_<T,C>& rhs);
+ void operator=(const array1d_<T,C>&);
+ // end of Not impled.
+
+
/// Ctor.
array1d_(C imin, C imax);
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 899)
+++ oln/core/1d/image1d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_1D_IMAGE1D_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/1d/array1d.hh>
# include <oln/core/1d/box1d.hh>
@@ -41,7 +42,7 @@
template <typename T> class image1d;
- /// Virtual types.
+ // Virtual types.
template <typename T>
struct vtypes< image1d<T> >
{
@@ -55,14 +56,14 @@
typedef T& lvalue;
typedef box1d pset;
- typedef array1d_<value, coord> data;
+ typedef internal::pair< array1d_<value, coord>*, box1d > data;
typedef image1d<T> plain;
typedef image1d<pl::value> skeleton;
};
- /// Super type.
+ // Super type.
template <typename T>
struct super_trait_< image1d<T> >
{
@@ -78,6 +79,7 @@
{
typedef image1d<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array1d_<T, int> array_t;
public:
stc_using(data);
@@ -95,7 +97,7 @@
std::size_t impl_npoints() const;
- box1d impl_points() const;
+ const box1d& impl_points() const;
};
@@ -110,28 +112,30 @@
template <typename T>
image1d<T>::image1d(const box1d& b)
{
- this->data_ = new data(b.pmin().ind(), b.pmax().ind());
+ this->data_ = new data(new array_t(b.pmin().ind(), b.pmax().ind()),
+ b);
}
template <typename T>
image1d<T>::image1d(unsigned n)
{
precondition(n != 0);
- this->data_ = new data(0, n - 1);
+ this->data_ = new data(new array_t(0, n - 1),
+ box1d(0, n - 1));
}
template <typename T>
bool image1d<T>::impl_owns_(const point1d& p) const
{
assert(this->has_data());
- return this->data_->has(p.ind());
+ return this->data_->first.has(p.ind());
}
template <typename T>
const T& image1d<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
- return this->data_->operator()(p.ind());
+ return this->data_->first.operator()(p.ind());
}
template <typename T>
@@ -139,14 +143,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first.operator[](i);
}
template <typename T>
T& image1d<T>::impl_read_write(const point1d& p)
{
assert(this->has_data());
- return this->data_->operator()(p.ind());
+ return this->data_->first.operator()(p.ind());
}
template <typename T>
@@ -154,7 +158,7 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first.operator[](i);
}
template <typename T>
@@ -162,18 +166,17 @@
{
// faster than the default code given by primitive_image_
assert(this->has_data());
- return this->data_->ncells();
+ return this->data_->first.ncells();
}
template <typename T>
- box1d image1d<T>::impl_points() const
+ const box1d& image1d<T>::impl_points() const
{
assert(this->has_data());
- box1d b(this->data_->imin(), this->data_->imax());
- return b;
+ return this->data_->second;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 899)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -46,7 +46,7 @@
template <typename T> class image1d_b;
- /// Virtual types.
+ // Virtual types.
template <typename T>
struct vtypes< image1d_b<T> >
{
@@ -60,9 +60,9 @@
typedef T& lvalue;
typedef box1d pset;
- typedef internal::triplet< array1d_<T, int>,
+ typedef internal::triplet< array1d_<T, int>*,
unsigned,
- box_<point1d> > data;
+ box1d > data;
typedef mlc::true_ vborder;
@@ -71,7 +71,7 @@
};
- /// Super type.
+ // Super type.
template <typename T>
struct super_trait_< image1d_b<T> >
{
@@ -80,7 +80,7 @@
};
- /// General 1D image class.
+ /// General 1D image class with an external virtual border.
template <typename T>
class image1d_b : public internal::plain_primitive_image_< image1d_b<T> >
@@ -105,7 +105,7 @@
std::size_t impl_npoints() const;
- box1d impl_points() const;
+ const box1d& impl_points() const;
unsigned impl_border() const;
};
@@ -122,7 +122,7 @@
template <typename T>
image1d_b<T>::image1d_b(const box1d& b, unsigned border)
{
- this->data_ = new data(array_t(b.pmin().ind() - border,
+ this->data_ = new data(new array_t(b.pmin().ind() - border,
b.pmax().ind() + border),
border,
b);
@@ -132,7 +132,7 @@
image1d_b<T>::image1d_b(unsigned n, unsigned border)
{
precondition(n != 0);
- this->data_ = new data(array_t(- border,
+ this->data_ = new data(new array_t(- border,
n - 1 + border),
border,
box1d(0, n - 1));
@@ -176,7 +176,7 @@
}
template <typename T>
- box1d image1d_b<T>::impl_points() const
+ const box1d& image1d_b<T>::impl_points() const
{
assert(this->has_data());
return this->data_->third;
@@ -189,7 +189,7 @@
return this->data_->second;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/array2d.hh
--- oln/core/2d/array2d.hh (revision 899)
+++ oln/core/2d/array2d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_ARRAY2D_HH
# include <cstddef>
+# include <iostream>
# include <mlc/contract.hh>
@@ -43,6 +44,13 @@
{
public:
+ // Not impled.
+ array2d_();
+ array2d_(const array2d_<T,C>& rhs);
+ void operator=(const array2d_<T,C>&);
+ // end of Not impled.
+
+
/// Ctor.
array2d_(C imin, C jmin, C imax, C jmax);
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 899)
+++ oln/core/2d/image2d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_IMAGE2D_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
@@ -55,7 +56,7 @@
typedef T& lvalue;
typedef box2d pset;
- typedef array2d_<value, coord> data;
+ typedef internal::pair< array2d_<value, coord>*, box2d > data;
typedef image2d<T> plain;
typedef image2d<pl::value> skeleton;
@@ -78,6 +79,7 @@
{
typedef image2d<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array2d_<T, int> array_t;
public:
stc_using(data);
@@ -99,7 +101,7 @@
std::size_t impl_npoints() const;
- box2d impl_points() const;
+ const box2d& impl_points() const;
};
template <typename T, typename D>
@@ -116,36 +118,40 @@
template <typename T>
image2d<T>::image2d(const box2d& b)
{
- this->data_ = new data(b.pmin().row(), b.pmin().col(),
- b.pmax().row(), b.pmax().col());
+ this->data_ = new data(new array_t(b.pmin().row(), b.pmin().col(),
+ b.pmax().row(), b.pmax().col()),
+ b);
}
template <typename T>
image2d<T>::image2d(unsigned nrows, unsigned ncols)
{
precondition(nrows != 0 and ncols != 0);
- this->data_ = new data(0, 0, nrows - 1, ncols - 1);
+ this->data_ = new data(new array_t(0, 0,
+ nrows - 1, ncols - 1),
+ box2d(point2d(0, 0),
+ point2d(nrows - 1, ncols - 1)));
}
template <typename T>
bool image2d<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
- return this->data_->has(p.row(), p.col());
+ return this->data_->first.has(p.row(), p.col());
}
template <typename T>
bool image2d<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->has(row, col);
+ return this->data_->first.has(row, col);
}
template <typename T>
const T& image2d<T>::impl_read(const point2d& p) const
{
assert(this->has_data());
- return this->data_->operator()(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -153,21 +159,21 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first[i];
}
template <typename T>
const T& image2d<T>::impl_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->operator()(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
T& image2d<T>::impl_read_write(const point2d& p)
{
assert(this->has_data());
- return this->data_->operator()(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -175,14 +181,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first[i];
}
template <typename T>
T& image2d<T>::impl_at(int row, int col)
{
assert(this->has_data());
- return this->data_->operator()(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
@@ -190,18 +196,14 @@
{
// faster than the default code given by primitive_image_
assert(this->has_data());
- return this->data_->ncells();
+ return this->data_->first.ncells();
}
template <typename T>
- box2d image2d<T>::impl_points() const
+ const box2d& image2d<T>::impl_points() const
{
assert(this->has_data());
- point2d
- pmin(this->data_->imin(), this->data_->jmin()),
- pmax(this->data_->imax(), this->data_->jmax());
- box2d b(pmin, pmax);
- return b;
+ return this->data_->second;
}
template <typename T, typename D>
@@ -211,8 +213,11 @@
box2d b;
bool box_ok = init(b, with, dat);
postcondition(box_ok);
- target.data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(),
- b.pmax().row(), b.pmax().col());
+ array2d_<T,int> ptr = new array2d_<T,int>(b.pmin().row(),
+ b.pmin().col(),
+ b.pmax().row(),
+ b.pmax().col());
+ target.data__() = new typename image2d<T>::data(ptr, b);
return box_ok;
}
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 899)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_IMAGE2D_B_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
@@ -38,49 +39,6 @@
{
- // FIXME: Move it!
-
- namespace internal
- {
-
-
- template <typename P, typename T>
- struct f_point_value_to_array_;
-
- template <typename T>
- struct f_point_value_to_array_< point2d, T >
- {
- typedef array2d_<T, int> ret;
- };
-
-
- template <typename P, typename T>
- struct array_b_
- {
- typedef typename f_point_value_to_array_<P, T>::ret array_t;
- typedef typename P::coord coord;
-
- array_b_(const P& pmin, const P& pmax, unsigned border)
- : array(pmin.row() - border, pmin.col() - border,
- pmax.row() + border, pmax.col() + border),
- border(border),
- box(pmin, pmax)
- {
- }
-
- array_t array;
- unsigned border;
- box_<P> box;
- };
-
-
- } // end of namespace oln::internal
-
-
- // end of FIXME
-
-
-
// Fwd decl.
template <typename T> class image2d_b;
@@ -99,14 +57,14 @@
typedef T& lvalue;
typedef box2d pset;
- typedef internal::array_b_<point2d, T> data;
+ typedef internal::triplet< array2d_<T, int>*,
+ unsigned,
+ box2d > data;
typedef mlc::true_ vborder;
typedef image2d_b<T> plain;
typedef image2d_b<pl::value> skeleton;
-
- // FIXME: wrong qiter!!!
};
@@ -126,6 +84,7 @@
{
typedef image2d_b<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array2d_<T, int> array_t;
public:
stc_using(data);
@@ -147,7 +106,7 @@
std::size_t impl_npoints() const;
- box2d impl_points() const;
+ const box2d& impl_points() const;
unsigned impl_border() const;
std::size_t pad(const dpoint2d& dp) const;
@@ -156,6 +115,10 @@
// template <typename T, typename D>
// bool init_(image2d_b<T>* this_, const D& dat);
+ template <typename T, typename D>
+ bool prepare(image2d_b<T>& target, with_t, const D& dat);
+
+
# ifndef OLN_INCLUDE_ONLY
@@ -167,37 +130,46 @@
template <typename T>
image2d_b<T>::image2d_b(const box2d& b, unsigned border)
{
- this->data_ = new data(b.pmin(), b.pmax(), border);
+ this->data_ = new data(new array_t(b.pmin().row() - border,
+ b.pmin().col() - border,
+ b.pmax().row() + border,
+ b.pmax().col() + border),
+ border,
+ b);
}
template <typename T>
image2d_b<T>::image2d_b(unsigned nrows, unsigned ncols, unsigned border)
{
precondition(nrows != 0 and ncols != 0);
- this->data_ = new data(point2d(0, 0),
- point2d(nrows - 1, ncols - 1),
- border);
+ this->data_ = new data(new array_t(- border,
+ - border,
+ nrows - 1 + border,
+ ncols - 1 + border),
+ border,
+ box2d(point2d(0, 0),
+ point2d(nrows - 1, ncols - 1)));
}
template <typename T>
bool image2d_b<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
- return this->data_->array.has(p.row(), p.col());
+ return this->data_->first.has(p.row(), p.col());
}
template <typename T>
bool image2d_b<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->array.has(row, col);
+ return this->data_->first.has(row, col);
}
template <typename T>
const T& image2d_b<T>::impl_read(const point2d& p) const
{
assert(this->has_data());
- return this->data_->array(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -205,21 +177,21 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->array[i];
+ return this->data_->first[i];
}
template <typename T>
const T& image2d_b<T>::impl_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->array(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
T& image2d_b<T>::impl_read_write(const point2d& p)
{
assert(this->has_data());
- return this->data_->array(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -227,35 +199,35 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->array[i];
+ return this->data_->first[i];
}
template <typename T>
T& image2d_b<T>::impl_at(int row, int col)
{
assert(this->has_data());
- return this->data_->array(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
- box2d image2d_b<T>::impl_points() const
+ const box2d& image2d_b<T>::impl_points() const
{
assert(this->has_data());
- return this->data_->box;
+ return this->data_->third;
}
template <typename T>
unsigned image2d_b<T>::impl_border() const
{
assert(this->has_data());
- return this->data_->border;
+ return this->data_->second;
}
template <typename T>
std::size_t image2d_b<T>::pad(const dpoint2d& dp) const
{
assert(this->has_data());
- return this->data_->array.row_pad() * dp.row() + dp.col();
+ return this->data_->first.row_pad() * dp.row() + dp.col();
}
// template <typename T, typename D>
@@ -278,7 +250,11 @@
bool box_ok = init(b, with, dat);
postcondition(box_ok);
unsigned border = 2; // FIXME: Use init!
- target.data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border);
+ array2d_<T,int> ptr = new array2d_<T,int>(b.pmin().row() - border,
+ b.pmin().col() - border,
+ b.pmax().row() + border,
+ b.pmax().col() + border);
+ target.data__() = new typename image2d_b<T>::data(ptr, border, b);
return box_ok;
}
Index: oln/core/gen/niter_has.hh
--- oln/core/gen/niter_has.hh (revision 899)
+++ oln/core/gen/niter_has.hh (working copy)
@@ -78,7 +78,7 @@
protected:
- const Ps pset_;
+ const Ps& pset_;
}; // end of class oln::niter_has_<P>
Index: oln/core/internal/utils.hh
--- oln/core/internal/utils.hh (revision 899)
+++ oln/core/internal/utils.hh (working copy)
@@ -28,6 +28,8 @@
#ifndef OLN_CORE_INTERNAL_UTILS_HH
# define OLN_CORE_INTERNAL_UTILS_HH
+# include <mlc/contract.hh>
+
namespace oln
{
@@ -36,10 +38,6 @@
{
- // FIXME: Rename attributes as first / second / third / fourth?
-
-
-
/// Simple singleton class.
template <typename T>
@@ -47,12 +45,15 @@
{
singleton()
{}
- singleton(T value)
+ singleton(const T& value)
: value(value)
{}
T value;
};
+ template <typename T>
+ struct singleton< T* >;
+
/// Simple pair class.
@@ -61,7 +62,7 @@
{
pair()
{}
- pair(T1 first, T2 second)
+ pair(const T1& first, const T2& second)
: first(first),
second(second)
{}
@@ -69,6 +70,37 @@
T2 second;
};
+ template <typename T1, typename T2>
+ struct pair< T1*, T2 >
+ {
+ typedef pair<T1*,T2> self_t;
+
+ // Not impled.
+ pair();
+ pair(const self_t&);
+ void operator=(const self_t&);
+ // end of Not impled.
+
+ pair(T1* p_first, const T2& second)
+ : first(*p_first),
+ second(second)
+ {
+ precondition(p_first != 0);
+ }
+ T1& first;
+ T2 second;
+ ~pair()
+ {
+ delete &first;
+ }
+ };
+
+ template <typename T1, typename T2>
+ struct pair< T1, T2* >;
+
+ template <typename T1, typename T2>
+ struct pair< T1*, T2* >;
+
/// Simple triplet class.
@@ -77,7 +109,7 @@
{
triplet()
{}
- triplet(T1 first, T2 second, T3 third)
+ triplet(const T1& first, const T2& second, const T3& third)
: first(first),
second(second),
third(third)
@@ -87,6 +119,33 @@
T3 third;
};
+ template <typename T1, typename T2, typename T3>
+ struct triplet< T1*, T2, T3 >
+ {
+ typedef triplet<T1*,T2,T3> self_t;
+
+ // Not impled.
+ triplet();
+ triplet(const self_t&);
+ void operator=(const self_t&);
+ // end of Not impled.
+
+ triplet(T1* p_first, const T2& second, const T3& third)
+ : first(*p_first),
+ second(second),
+ third(third)
+ {
+ precondition(p_first != 0);
+ }
+ T1& first;
+ T2 second;
+ T3 third;
+ ~triplet()
+ {
+ delete &first;
+ }
+ };
+
/// Simple quartet class.
@@ -95,7 +154,7 @@
{
quartet()
{}
- quartet(T1 first, T2 second, T3 third, T4 fourth)
+ quartet(const T1& first, const T2& second, const T3& third, const T4& fourth)
: first(first),
second(second),
third(third),
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 899)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -85,7 +85,7 @@
delegatee& impl_image();
const delegatee& impl_image() const;
- pset impl_points() const;
+ const pset& impl_points() const;
protected:
special_op_();
@@ -149,7 +149,7 @@
}
template <typename I, typename S>
- typename current::pset
+ const typename current::pset&
current::impl_points() const
{
assert(this->has_data());
1
0
899: Add type of 'image such_as f:b->p' and factor Image::has as final.
by Thierry Geraud 22 Mar '07
by Thierry Geraud 22 Mar '07
22 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add type of 'image such_as f:b->p' and factor Image::has as final.
* tests/core/neighb2d.cc: Fix.
* oln/core/internal/op_image_such_as_fp2b.hh: New.
* oln/core/gen/pset_such_as.hh: Remove; obsolete.
* oln/core/concept/image.hh (has): New final impl.
(Point_Wise_Accessible_Image): Remove get_impl inheritance.
* oln/core/concept/image_identity.hh: Update.
* oln/core/rle/rle_image.hh,
* oln/core/sparse/sparse_image.hh,
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh,
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh,
* oln/core/gen/single_value_image.hh (impl_has): Remove.
* oln/core/internal/op_pset_such_as_fp2b.hh (point): New vtype.
(point): Remove this vtype from iterators.
* oln/core/internal/point_set_base.hh: Cosmetic.
* oln/core/internal/op_image_restricted_to_pset.hh: Cosmetic.
* oln/core/internal/image_base.hh (oln_decl_op_such_as): New version
for "Image such_as Function_p2b".
(operator |): New specialization for C functions.
oln/core/1d/image1d.hh | 9 -
oln/core/1d/image1d_b.hh | 9 -
oln/core/2d/image2d.hh | 8 -
oln/core/2d/image2d_b.hh | 10 --
oln/core/concept/image.hh | 7 -
oln/core/concept/image_identity.hh | 20 ----
oln/core/gen/single_value_image.hh | 9 -
oln/core/internal/image_base.hh | 22 ++++
oln/core/internal/op_image_restricted_to_pset.hh | 11 --
oln/core/internal/op_image_such_as_fp2b.hh | 114 +++++++++++++++++++++++
oln/core/internal/op_pset_such_as_fp2b.hh | 11 +-
oln/core/internal/point_set_base.hh | 3
oln/core/rle/rle_image.hh | 9 -
oln/core/sparse/sparse_image.hh | 8 -
tests/core/neighb2d.cc | 2
15 files changed, 151 insertions(+), 101 deletions(-)
Index: tests/core/neighb2d.cc
--- tests/core/neighb2d.cc (revision 898)
+++ tests/core/neighb2d.cc (working copy)
@@ -38,7 +38,7 @@
unsigned run(const oln::Image_with_Nbh<I>& input)
{
oln_piter(I) p(input.points());
- oln_niter(I) n(p, input.nbhood());
+ oln_niter(I) n(p, input);
unsigned count = 0;
for_all(p)
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 898)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -98,8 +98,6 @@
/// pset impl_points() const : return image pset
pset impl_points() const;
- /// bool impl_has(const point& p) const : rle_image has p?
- bool impl_has(const point& p) const;
/// bool impl_owns_(const psite& p) const : same has impl_has
bool impl_owns_(const psite& p) const;
/// void insert(const point& p, unsigned len, value val) : insert a new range on the image
@@ -128,13 +126,6 @@
template <typename P, typename T>
bool
- rle_image<P, T>::impl_has(const typename rle_image<P, T>::point& p) const
- {
- return this->data_->first.has(p);
- }
-
- template <typename P, typename T>
- bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const
{
return this->data_->first.has(p.start_);
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 898)
+++ oln/core/concept/image.hh (working copy)
@@ -217,11 +217,11 @@
/// Concept-class "Point_Wise_Accessible_Image".
template <typename Exact>
- struct Point_Wise_Accessible_Image : public virtual Image<Exact>,
- public automatic::get_impl<Point_Wise_Accessible_Image, Exact>
+ struct Point_Wise_Accessible_Image : public virtual Image<Exact>
{
stc_using_from(Image, point);
+ // final
bool has(const point& p) const;
protected:
@@ -512,7 +512,8 @@
bool
Point_Wise_Accessible_Image<Exact>::has(const typename Point_Wise_Accessible_Image<Exact>::point& p) const
{
- return exact(this)->impl_has(p);
+ // FIXME: precondition(this->owns_(p)); ?
+ return this->points().has(p);
}
template <typename Exact>
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 898)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -104,16 +104,6 @@
};
- /// Concept-class "Point_Wise_Accessible_Image".
-
- template <typename Exact>
- struct set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact > : public virtual Any<Exact>
- {
- stc_typename(point);
- bool impl_has(const point& p) const;
- };
-
-
/// Concept-class "Value_Wise_Accessible_Image".
template <typename Exact>
@@ -270,16 +260,6 @@
}
- /// Concept-class "Point_Wise_Accessible_Image".
-
- template <typename Exact>
- bool
- set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact >::impl_has(const typename set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact >::point& p) const
- {
- return exact(this)->image().has(p);
- }
-
-
/// Concept-class "Value_Wise_Accessible_Image".
template <typename Exact>
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 898)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -83,7 +83,6 @@
sparse_image();
pset impl_points() const;
- bool impl_has(const point& p) const;
bool impl_owns_(const psite& p) const;
void insert(const point& p, unsigned len, const std::vector<value>& val);
rvalue impl_read(const psite& p) const;
@@ -109,13 +108,6 @@
template <typename P, typename T>
bool
- sparse_image<P, T>::impl_has(const typename sparse_image<P, T>::point& p) const
- {
- return this->data_->first.has(p);
- }
-
- template <typename P, typename T>
- bool
sparse_image<P, T>::impl_owns_(const typename sparse_image<P, T>::psite& p) const
{
return this->data_->first.has(p.start_);
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 898)
+++ oln/core/1d/image1d.hh (working copy)
@@ -87,8 +87,6 @@
bool impl_owns_(const point1d& p) const;
- bool impl_has(const point1d& p) const;
-
const T& impl_read(const point1d& p) const;
const T& impl_index_read(unsigned i) const;
@@ -130,13 +128,6 @@
}
template <typename T>
- bool image1d<T>::impl_has(const point1d& p) const
- {
- assert(this->has_data());
- return this->data_->has(p.ind());
- }
-
- template <typename T>
const T& image1d<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 898)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -97,8 +97,6 @@
bool impl_owns_(const point1d& p) const;
- bool impl_has(const point1d& p) const;
-
const T& impl_read(const point1d& p) const;
const T& impl_index_read(unsigned i) const;
@@ -148,13 +146,6 @@
}
template <typename T>
- bool image1d_b<T>::impl_has(const point1d& p) const
- {
- assert(this->has_data());
- return this->data_->third.has(p);
- }
-
- template <typename T>
const T& image1d_b<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 898)
+++ oln/core/2d/image2d.hh (working copy)
@@ -87,7 +87,6 @@
bool impl_owns_(const point2d& p) const;
- bool impl_has(const point2d& p) const;
bool impl_has_at(int row, int col) const;
const T& impl_read(const point2d& p) const;
@@ -136,13 +135,6 @@
}
template <typename T>
- bool image2d<T>::impl_has(const point2d& p) const
- {
- assert(this->has_data());
- return this->data_->has(p.row(), p.col());
- }
-
- template <typename T>
bool image2d<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 898)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -135,7 +135,6 @@
bool impl_owns_(const point2d& p) const;
- bool impl_has(const point2d& p) const;
bool impl_has_at(int row, int col) const;
const T& impl_read(const point2d& p) const;
@@ -188,17 +187,10 @@
}
template <typename T>
- bool image2d_b<T>::impl_has(const point2d& p) const
- {
- assert(this->has_data());
- return this->data_->box.has(p);
- }
-
- template <typename T>
bool image2d_b<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->box.has(point2d(row, col));
+ return this->data_->array.has(row, col);
}
template <typename T>
Index: oln/core/gen/single_value_image.hh
--- oln/core/gen/single_value_image.hh (revision 898)
+++ oln/core/gen/single_value_image.hh (working copy)
@@ -89,7 +89,6 @@
single_value_image(const Ps& ps, const T& val);
bool impl_owns_(const point& p) const;
- bool impl_has (const point& p) const;
rvalue impl_read(const point&) const;
@@ -124,14 +123,6 @@
}
template <typename Ps, typename T>
- bool
- single_value_image<Ps, T>::impl_has(const typename single_value_image<Ps, T>::point& p) const
- {
- assert(this->has_data());
- return this->data_->first.has(p);
- }
-
- template <typename Ps, typename T>
typename single_value_image<Ps, T>::rvalue
single_value_image<Ps, T>::impl_read(const typename single_value_image<Ps, T>::point&) const
{
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 898)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy)
@@ -42,7 +42,7 @@
special_op_< stc::is<Point_Set>, S, such_as, stc::is<Function_p2b>, F >
- /// Fwd decls.
+ // Fwd decls.
namespace internal
{
template <typename S, typename F> class current;
@@ -52,7 +52,7 @@
- /// Super type.
+ // Super type.
template <typename S, typename F>
struct super_trait_< internal::current >
{
@@ -60,10 +60,11 @@
};
- /// Virtual types.
+ // Virtual types.
template <typename S, typename F>
struct vtypes< internal::current >
{
+ typedef oln_point(S) point;
typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter;
typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter;
};
@@ -72,7 +73,7 @@
namespace internal
{
- /// Implementation class the result of "Point_Set S | Function_p2b F".
+ /// Implementation class for the result of "Point_Set S | Function_p2b F".
template <typename S, typename F>
class current
@@ -197,7 +198,6 @@
template <typename S, typename F>
struct vtypes< current >
{
- typedef typename S::point point;
typedef typename S::fwd_piter adapted;
};
@@ -274,7 +274,6 @@
template <typename S, typename F>
struct vtypes< current >
{
- typedef typename S::point point;
typedef typename S::fwd_piter adapted;
};
Index: oln/core/internal/op_image_such_as_fp2b.hh
--- oln/core/internal/op_image_such_as_fp2b.hh (revision 0)
+++ oln/core/internal/op_image_such_as_fp2b.hh (revision 0)
@@ -0,0 +1,114 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH
+# define OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH
+
+# include <oln/core/internal/op_image_restricted_to_pset.hh>
+# include <oln/core/internal/op_pset_such_as_fp2b.hh>
+
+
+namespace oln
+{
+
+
+# define current \
+ special_op_< stc::is<Image>, I, such_as, stc::is<Function_p2b>, F >
+
+
+ // Fwd decl.
+ namespace internal { template <typename I, typename F> class current; }
+
+
+ // Super type.
+ template <typename I, typename F>
+ struct super_trait_< internal::current >
+ {
+ typedef 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;
+ };
+
+
+# define super \
+ super_trait_< internal::current >::ret
+
+
+ // Virtual types.
+ template <typename I, typename F>
+ struct vtypes< internal::current >
+ {
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class for the result of "Image I | Function_p2b F".
+
+ template <typename I, typename F>
+ class current : public super
+ {
+ public:
+
+ stc_using(point);
+ stc_using(box);
+
+ protected:
+ special_op_();
+ special_op_(I& ima, F& f);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I, typename F>
+ current::special_op_()
+ {
+ }
+
+ template <typename I, typename F>
+ current::special_op_(I& ima, F& f)
+ : super(ima, (ima.points() | f))
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+
+ // Fixme: Activate init
+
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 898)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -111,8 +111,7 @@
template <typename S, typename B, typename P>
op_<const S, such_as, const fun_p2b_<B (*)(P)> >
- operator | (const Point_Set<S>& lhs,
- B (*f)(P))
+ operator | (const Point_Set<S>& lhs, B (*f)(P))
{
typedef oln_strip_(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 898)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -40,12 +40,7 @@
special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S >
-// /// Fwd decls.
-// template <typename Exact> struct Image;
-// template <typename Exact> struct Point_Set;
-
-
- /// Super type.
+ // Super type.
template <typename I, typename S>
struct super_trait_< internal::current >
{
@@ -53,7 +48,7 @@
};
- /// Virtual types.
+ // Virtual types.
template <typename I, typename S>
struct vtypes< internal::current >
{
@@ -73,7 +68,7 @@
namespace internal
{
- /// Implementation class the result of "Image I | Point_Set S".
+ /// Implementation class for the result of "Image I | Point_Set S".
template <typename I, typename S>
class special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S >
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 898)
+++ oln/core/internal/image_base.hh (working copy)
@@ -477,11 +477,33 @@
# 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.
+
+ 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;
+ }
+
} // end of namespace oln
/// \}
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Make check : test basic morpho.
* olena/tests/algorithms/Makefile.am: .
* olena/tests/algorithms/basic_morpho.cc: New.
Makefile.am | 5 ++-
basic_morpho.cc | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+), 2 deletions(-)
Index: olena/tests/algorithms/Makefile.am
--- olena/tests/algorithms/Makefile.am (revision 897)
+++ olena/tests/algorithms/Makefile.am (working copy)
@@ -23,10 +23,11 @@
check_PROGRAMS = \
- fill
+ fill \
+ basic_morpho
# Algorithms.
fill_SOURCES = fill.cc
-
+basic_morpho_SOURCES = basic_morpho.cc
TESTS = $(check_PROGRAMS)
Index: olena/tests/algorithms/basic_morpho.cc
--- olena/tests/algorithms/basic_morpho.cc (revision 0)
+++ olena/tests/algorithms/basic_morpho.cc (revision 0)
@@ -0,0 +1,84 @@
+
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/window2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+#include <oln/morpho/elementary_dilation.hh>
+#include <oln/morpho/elementary_erosion.hh>
+
+#include <oln/morpho/dilation.hh>
+#include <oln/morpho/erosion.hh>
+
+#include <oln/morpho/opening.hh>
+#include <oln/morpho/closing.hh>
+
+#include <oln/morpho/elementary_closing.hh>
+#include <oln/morpho/elementary_opening.hh>
+
+#include <oln/debug/print.hh>
+
+int main()
+{
+ using namespace oln;
+
+ int i = 0;
+
+ typedef image2d<bool> I;
+
+ I ima(5, 5);
+
+ I::piter p1(ima.points());
+ for_all(p1)
+ ima(p1) = i++ % 2;
+
+ std::cout << "ima" << std::endl;
+ debug::print(ima);
+
+
+ I tmp = (morpho::elementary_erosion(ima + c4)).image();
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 0);
+
+ // std::cout << "elementary_dilation" << std::endl;
+ tmp = (morpho::elementary_dilation(ima + c4)).image();
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "erosion_w" << std::endl;
+ tmp = morpho::erosion(ima, win3x3);
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 0);
+
+ // std::cout << "dilation_w" << std::endl;
+ tmp = morpho::dilation(ima, win3x3);
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "elementary_opening" << std::endl;
+ tmp = (morpho::elementary_opening(ima + c4)).image();
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 0);
+
+ // std::cout << "elementary_closing" << std::endl;
+ tmp = (morpho::elementary_closing(ima + c4)).image();
+ p1 = (tmp.points());
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "opening" << std::endl;
+ tmp = morpho::opening(ima, win3x3);
+ p1 = (tmp.points());
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "closing" << std::endl;
+ debug::print( morpho::closing(ima, win3x3) );
+ p1 = (tmp.points());
+ for_all(p1)
+ assert(tmp(p1) == 1);
+}
1
0
ima
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
elementary_erosion
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
elementary_dilation
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
erosion_w
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
dilation_w
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
elementary_opening
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
elementary_closing
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
opening
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
closing
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Basic Morpho : Tested OK.
* oln/core/2d/image2d.hh: .
* oln/morpho/elementary_erosion.hh: .
* oln/morpho/elementary_closing.hh: .
* oln/morpho/elementary_opening.hh: .
* oln/morpho/erosion.hh: .
* oln/morpho/closing.hh: .
* oln/morpho/opening.hh: .
* oln/level/local.hh: .
* oln/level/apply_local.hh: .
level/apply_local.hh | 28 ++++++++++++
level/local.hh | 100 ++++++++++++++++++++++---------------------
morpho/closing.hh | 5 --
morpho/elementary_closing.hh | 6 --
morpho/elementary_erosion.hh | 3 -
morpho/elementary_opening.hh | 6 --
morpho/erosion.hh | 2
morpho/opening.hh | 6 +-
8 files changed, 91 insertions(+), 65 deletions(-)
Index: oln/core/2d/image2d.hh
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 896)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -65,12 +65,11 @@
template <typename I>
oln_plain(I)
elementary_erosion_on_set_(const Image<I>&,
- const I&)
+ const I& input)
{
border::fill(input, oln_max(oln_value(I)));
accumulator::and_<oln_value(I)> accu_and;
return level::apply_local(accu_and, input);
- return tmp;
}
Index: oln/morpho/elementary_closing.hh
--- oln/morpho/elementary_closing.hh (revision 896)
+++ oln/morpho/elementary_closing.hh (working copy)
@@ -52,11 +52,9 @@
template <typename I>
oln_plain(I)
- elementary_closing_(const Image<I>& input);
+ elementary_closing_(const Image_with_Nbh<I>& input)
{
- oln_plain(I) tmp;
- tmp = elementary_dilation(input);
- return elementary_erosion(tmp);
+ return elementary_erosion( elementary_dilation(input) );
}
// FIXME: Add a fast version.
Index: oln/morpho/elementary_opening.hh
--- oln/morpho/elementary_opening.hh (revision 896)
+++ oln/morpho/elementary_opening.hh (working copy)
@@ -52,11 +52,9 @@
template <typename I>
oln_plain(I)
- elementary_opening_(const Image<I>& input);
+ elementary_opening_(const Image_with_Nbh<I>& input)
{
- oln_plain(I) tmp;
- tmp = elementary_erosion(input);
- return elementary_dilation(tmp);
+ return morpho::elementary_dilation( morpho::elementary_erosion(input) );
}
// FIXME: Add a fast version.
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 896)
+++ oln/morpho/erosion.hh (working copy)
@@ -58,7 +58,7 @@
{
border::fill(input, oln_min(oln_value(I)));
accumulator::min_<oln_value(I)> min;
- return level::apply_local(max, input, win);
+ return level::apply_local(min, input, win);
}
template <typename I>
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 896)
+++ oln/morpho/closing.hh (working copy)
@@ -56,14 +56,13 @@
closing_(const Image<I>& input,
const Window<W>& win)
{
- oln_plain(I) = elementary_dilation(input, win);
- return elementary_erosion(tmp, win); // FIXME : inverse(win).
+ oln_plain(I) tmp = morpho::dilation(input, win);
+ return morpho::erosion(tmp, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
-
} // end of namespace oln::morpho::impl
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 896)
+++ oln/morpho/opening.hh (working copy)
@@ -56,8 +56,8 @@
opening_(const Image<I>& input,
const Window<W>& win)
{
- oln_plain(I) = elementary_dilation(input, win);
- return elementary_erosion(tmp, win); // FIXME : inverse(win).
+ oln_plain(I) tmp = morpho::dilation(input, win);
+ return morpho::erosion(tmp, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
@@ -71,7 +71,7 @@
oln_plain(I)
opening(const Image<I>& input, const Window<W>& win)
{
- return impl::opening_(exact(input), exact(win));
+ return impl::opening_(exact(input), win);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/level/local.hh
--- oln/level/local.hh (revision 896)
+++ oln/level/local.hh (working copy)
@@ -59,6 +59,8 @@
namespace impl
{
+ /// Neigborhood.
+
// Generic version with neighborhood.
template <typename A, typename I>
@@ -70,36 +72,18 @@
f.init_with(input(p));
oln_niter(I) n(p, input);
for_all(n)
+ {
f(input(n));
- return f.value();
}
-
-
- // FIXME: Generic version with nbh given as argument?
-
- // Generic version with window.
-
- template <typename A, typename I, typename W>
- typename A::result
- local_(const A& f,
- const Image<I>& input,
- const oln_point(I)& p,
- const Window<W>& win)
- {
- f.init();
- oln_qiter(W) q(p, win);
- for_all(q)
- f(input(q));
return f.value();
}
-
// Optimised version for OR operator with neighborhood.
template <typename B, typename I>
B
- local_(const accumulator::or_<B>& f,
- const Binary_Image<I>& input,
+ local_(const oln::accumulator::or_<B>& f,
+ const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
@@ -115,55 +99,74 @@
return f.value();
}
+ // Optimised version for AND operator with neighborhood.
- // Optimised version for OR operator with window.
-
- template <typename B, typename I, typename W>
+ template <typename B, typename I>
B
- local_(const accumulator::or_<B>& f,
- const Binary_Image<I>& input,
+ local_(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)
+ {
+ 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_(const A& f,
+ const 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 (input.owns_(q))
f(input(q));
- if (f.value() == true)
- return true;
- }
return f.value();
}
+ // Optimised version for OR operator with window.
- // FIXME : same function for OR.
-
- // Optimised version for AND operator with neighborhood.
-
- template <typename B, typename I>
+ template <typename B, typename I, typename W>
B
- local_(const accumulator::and_< B > f,
+ local_(const oln::accumulator::or_<B>& f,
const Binary_Image<I>& input,
- const oln_point(I)& p)
+ const oln_point(I)& p,
+ const Window<W>& win)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
- for_all(n)
+ if (f.value() == true)
+ return true;
+ oln_qiter(W) q(p, win);
+ for_all(q)
{
- f(input(n)); // FIXME: Change to f.take(input(n))?
+ 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 A, typename I, typename W>
+ template <typename B, typename I, typename W>
B
local_(const accumulator::and_< B > f,
const Image<I>& input,
@@ -174,9 +177,10 @@
oln_qiter(W) q(p, win);
for_all(q)
{
+ if (input.owns_(q))
f(input(q));
- if (f.value() == true)
- return true;
+ if (f.value() == false)
+ return false;
}
return f.value();
}
@@ -192,7 +196,7 @@
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
- return impl::local_(exact(f), input, p);
+ return impl::local_(exact(f), exact(input), p);
}
template <typename A, typename I, typename W>
@@ -202,7 +206,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- return impl::local_(exact(f), input, p, win);
+ return impl::local_(exact(f), exact(input), p, win);
}
#endif // ! OLN_INCLUDE_ONLY
Index: oln/level/apply_local.hh
--- oln/level/apply_local.hh (revision 896)
+++ oln/level/apply_local.hh (working copy)
@@ -47,6 +47,11 @@
apply_local(const Accumulator<F>& f,
const Image_with_Nbh<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);
# ifndef OLN_INCLUDE_ONLY
@@ -68,6 +73,20 @@
return output;
}
+ 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)
+ {
+ oln_plain_value(I, typename F::result) output;
+ prepare(output, with, input);
+ oln_piter(I) p(input.points());
+ for_all(p)
+ output(p) = level::local(f, input, p, win);
+ return output;
+ }
+
} // end of namespace oln::level::impl
@@ -81,6 +100,15 @@
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)
+ {
+ return impl::apply_local_(exact(f), exact(input), win);
+ }
+
# endif
} // end of namespace oln::level
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Provide more suitable niter classes.
* oln/core/gen/niter_has.hh: New.
* oln/debug/print_nbh.hh (impl): Remove; useless.
* oln/core/concept/image.hh (Image_with_Nbh): Overload nbhood
access.
* oln/core/concept/image_identity.hh: Update.
* oln/core/equipment.hh (oln_pset): New.
* oln/core/internal/piter_adaptor.hh (point): Set final.
* oln/core/internal/op_pset_such_as_fp2b.hh (point): Remove.
* oln/core/internal/op_image_plus_nbh.hh (include): Update.
(fwd_niter, bkd_niter): Update.
core/concept/image.hh | 12 ++-
core/concept/image_identity.hh | 12 ++-
core/equipment.hh | 1
core/gen/niter_has.hh | 126 ++++++++++++++++++++++++++++++++++
core/internal/op_image_plus_nbh.hh | 22 ++++-
core/internal/op_pset_such_as_fp2b.hh | 1
core/internal/piter_adaptor.hh | 4 -
debug/print_nbh.hh | 38 ----------
8 files changed, 168 insertions(+), 48 deletions(-)
Index: oln/debug/print_nbh.hh
--- oln/debug/print_nbh.hh (revision 895)
+++ oln/debug/print_nbh.hh (working copy)
@@ -45,14 +45,10 @@
# ifndef OLN_INCLUDE_ONLY
- namespace impl
- {
-
- // Image
+ // Generic version.
template <typename I>
- void print_nbh(const Image<I>&,
- const I& input, std::ostream& ostr)
+ void print_nbh(const Image_with_Nbh<I>& input, std::ostream& ostr = std::cout)
{
oln_piter(I) p(input.points());
oln_niter(I) n(p, input);
@@ -60,41 +56,11 @@
{
ostr << input(p) << ": ";
for_all(n)
- if (input.owns_(n))
ostr << input(n) << " ";
ostr << std::endl;
}
}
-
- // Point_Wise_Accessible_Image
-
- template <typename I>
- void print_nbh(const Point_Wise_Accessible_Image<I>&,
- const I& input, std::ostream& ostr)
- {
- oln_piter(I) p(input.points());
- oln_niter(I) n(p, input);
- for_all(p)
- {
- ostr << input(p) << ": ";
- for_all(n)
- if (input.has(n))
- ostr << input(n) << " ";
- ostr << std::endl;
- }
- }
-
- } // end of namespace oln::debug::impl
-
-
- // facade
- template <typename I>
- void print_nbh(const Image_with_Nbh<I>& input, std::ostream& ostr)
- {
- impl::print_nbh(exact(input), exact(input), ostr);
- }
-
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 895)
+++ oln/core/concept/image.hh (working copy)
@@ -156,7 +156,8 @@
stc_typename(bkd_niter);
typedef fwd_niter niter;
- nbh nbhood() const;
+ const nbh& nbhood() const;
+ nbh& nbhood();
protected:
Image_with_Nbh();
@@ -458,13 +459,20 @@
// ----------------------------------- Image_with_Nbh<Exact>
template <typename Exact>
- typename Image_with_Nbh<Exact>::nbh
+ const typename Image_with_Nbh<Exact>::nbh&
Image_with_Nbh<Exact>::nbhood() const
{
return exact(this)->impl_nbhood();
}
template <typename Exact>
+ typename Image_with_Nbh<Exact>::nbh&
+ Image_with_Nbh<Exact>::nbhood()
+ {
+ return exact(this)->impl_nbhood();
+ }
+
+ template <typename Exact>
Image_with_Nbh<Exact>::Image_with_Nbh()
{
}
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 895)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -64,7 +64,8 @@
struct set_impl< Image_with_Nbh, behavior::identity, Exact > : public virtual Any<Exact>
{
stc_typename(nbh);
- nbh impl_nbhood() const;
+ const nbh& impl_nbhood() const;
+ nbh& impl_nbhood();
};
@@ -211,12 +212,19 @@
/// Concept-class "Image_with_Nbh".
template <typename Exact>
- typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh
+ const typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh&
set_impl< Image_with_Nbh, behavior::identity, Exact >::impl_nbhood() const
{
return exact(this)->image().nbhood();
}
+ template <typename Exact>
+ typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh&
+ set_impl< Image_with_Nbh, behavior::identity, Exact >::impl_nbhood()
+ {
+ return exact(this)->image().nbhood();
+ }
+
/// Concept-class "Image_with_Border".
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 895)
+++ oln/core/equipment.hh (working copy)
@@ -123,6 +123,7 @@
# define oln_piter(T) oln_typename_shortcut__(T, piter)
# 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)
// q
stc_decl_associated_type( qiter );
Index: oln/core/gen/niter_has.hh
--- oln/core/gen/niter_has.hh (revision 0)
+++ oln/core/gen/niter_has.hh (revision 0)
@@ -0,0 +1,126 @@
+// 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_NITER_HAS_HH
+# define OLN_CORE_GEN_NITER_HAS_HH
+
+# include <oln/core/internal/piter_adaptor.hh>
+# include <oln/core/gen/dpoints_piter.hh>
+
+
+namespace oln
+{
+
+
+# define current niter_has_<It, Ps>
+ // --------------------
+
+# define super internal::piter_adaptor_< current >
+
+
+ // Fwd decl.
+ template <typename It, typename Ps> class niter_has_;
+
+
+ // Super type.
+ template <typename It, typename Ps>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual type.
+ template <typename It, typename Ps>
+ struct vtypes< current >
+ {
+ typedef It adapted;
+ };
+
+
+ // Forward point iterator class on a set of dpoints.
+ template <typename It, typename Ps>
+ class niter_has_ : public super
+ {
+ public:
+
+ // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
+
+ template <typename Pl, typename I>
+ niter_has_(const Pl& p, const Image_with_Nbh<I>& ima);
+
+ void impl_start();
+ void impl_next();
+
+ protected:
+
+ const Ps pset_;
+
+ }; // end of class oln::niter_has_<P>
+
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename It, typename Ps>
+ template <typename Pl, typename I>
+ current::niter_has_(const Pl& p, const Image_with_Nbh<I>& ima)
+ :
+ super( It(p, ima) ),
+ pset_( ima.points() )
+ {
+ }
+
+ template <typename It, typename Ps>
+ void
+ current::impl_start()
+ {
+ this->p_.start();
+ while (this->p_.is_valid() and not this->pset_.has(this->p_))
+ this->p_.next();
+ }
+
+ template <typename It, typename Ps>
+ void
+ current::impl_next()
+ {
+ do
+ this->p_.next();
+ while (this->p_.is_valid() and not this->pset_.has(this->p_));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_NITER_HAS_HH
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 895)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy)
@@ -64,7 +64,6 @@
template <typename S, typename F>
struct vtypes< internal::current >
{
- typedef typename S::point point;
typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter;
typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter;
};
Index: oln/core/internal/piter_adaptor.hh
--- oln/core/internal/piter_adaptor.hh (revision 895)
+++ oln/core/internal/piter_adaptor.hh (working copy)
@@ -51,8 +51,10 @@
template <typename Exact>
struct vtypes< internal::piter_adaptor_<Exact> >
{
- typedef stc::abstract point;
typedef stc::abstract adapted;
+
+ typedef stc_deferred(adapted) adapted__;
+ typedef stc::final< oln_point(adapted__) > point;
};
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 895)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -29,9 +29,10 @@
# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# include <oln/core/concept/neighborhood.hh>
+# include <oln/core/internal/image_base.hh>
# include <oln/core/gen/op.hh>
# include <oln/core/gen/dpoints_piter.hh>
-# include <oln/core/internal/image_base.hh>
+# include <oln/core/gen/niter_has.hh>
namespace oln
@@ -62,14 +63,15 @@
struct vtypes< internal::current >
{
typedef op_<I, plus, N> Exact;
- typedef stc_type(I, point) point__;
typedef I delegatee;
typedef internal::pair<I,N> data;
typedef N nbh;
- typedef dpoints_fwd_piter_<point__> fwd_niter;
- typedef dpoints_bkd_piter_<point__> bkd_niter;
+
+ // 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;
@@ -96,7 +98,7 @@
delegatee& impl_image();
const delegatee& impl_image() const;
- nbh impl_nbhood() const;
+ const nbh& impl_nbhood() const;
nbh& impl_nbhood();
protected:
@@ -160,13 +162,21 @@
}
template <typename I, typename N>
- typename current::nbh
+ const typename current::nbh&
current::impl_nbhood() const
{
assert(this->has_data());
return this->data_->second;
}
+ template <typename I, typename N>
+ typename current::nbh&
+ current::impl_nbhood()
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
} // end of namespace oln::internal
1
0
Modification in algorithm specialization (function/set).
Correction of major order errors in opening / closing.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix : Opening, Closing, erosion, dilation.
* oln/morpho/elementary_erosion.hh: .
* oln/morpho/dilation.hh: .
* oln/morpho/elementary_closing.hh: .
* oln/morpho/elementary_opening.hh: .
* oln/morpho/erosion.hh: .
* oln/morpho/closing.hh: New.
* oln/morpho/opening.hh: .
* oln/level/local.hh: .
level/local.hh | 46 +++++++++++++----------
morpho/closing.hh | 86 +++++++++++++++++++++++++++++++++++++++++++
morpho/dilation.hh | 25 ++++++++++++
morpho/elementary_closing.hh | 22 +++++------
morpho/elementary_erosion.hh | 5 +-
morpho/elementary_opening.hh | 22 +++++------
morpho/erosion.hh | 32 ++++++++++++++--
morpho/opening.hh | 9 +---
8 files changed, 192 insertions(+), 55 deletions(-)
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 894)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -67,8 +67,9 @@
elementary_erosion_on_set_(const Image<I>&,
const I&)
{
- oln_plain(I) tmp;
- std::cerr << "morpho::impl::elementary_erosion_on_set_ is not yet impled!" << std::endl;
+ border::fill(input, oln_max(oln_value(I)));
+ accumulator::and_<oln_value(I)> accu_and;
+ return level::apply_local(accu_and, input);
return tmp;
}
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 894)
+++ oln/morpho/dilation.hh (working copy)
@@ -61,8 +61,33 @@
return level::apply_local(max, input, win);
}
+ template <typename I>
+ oln_plain(I)
+ dilation_on_set_(const Image<I>&,
+ const I& input)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::or_<oln_value(I)> accu_or;
+ return level::apply_local(accu_or, input);
+ }
+
// FIXME: Add a fast version.
+
+ // Impl facade.
+
+ template <typename I>
+ oln_plain(I) dilation_(const Image<I>& input)
+ {
+ return dilation_on_function_(exact(input), exact(input));
+ }
+
+ template <typename I>
+ oln_plain(I) dilation_(const Binary_Image<I>& input)
+ {
+ return dilation_on_set_(exact(input), exact(input));
+ }
+
} // end of namespace oln::morpho::impl
Index: oln/morpho/elementary_closing.hh
--- oln/morpho/elementary_closing.hh (revision 894)
+++ oln/morpho/elementary_closing.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_MORPHO_ELEMENTARY_CLOSING_HH
# define OLN_MORPHO_ELEMENTARY_CLOSING_HH
-#include <oln/level/apply_local.hh>
-#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
@@ -41,10 +39,9 @@
// Fwd decl.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_closing(const Image<I>& input, const Window<W>& win);
-
+ elementary_closing(const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -53,12 +50,13 @@
// Generic version.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_closing_(const Image<I>& input,
- const Window<W>& win)
+ elementary_closing_(const Image<I>& input);
{
- return elementary_erosion(elementary_dilation(input, win), win); // FIXME : memory
+ oln_plain(I) tmp;
+ tmp = elementary_dilation(input);
+ return elementary_erosion(tmp);
}
// FIXME: Add a fast version.
@@ -68,11 +66,11 @@
// Facade.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_closing(const Image<I>& input, const Window<W>& win)
+ elementary_closing(const Image_with_Nbh<I>& input)
{
- return impl::elementary_closing_(exact(input), exact(win));
+ return impl::elementary_closing_(exact(input));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_opening.hh
--- oln/morpho/elementary_opening.hh (revision 894)
+++ oln/morpho/elementary_opening.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_MORPHO_ELEMENTARY_OPENING_HH
# define OLN_MORPHO_ELEMENTARY_OPENING_HH
-#include <oln/level/apply_local.hh>
-#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
@@ -41,10 +39,9 @@
// Fwd decl.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_opening(const Image<I>& input, const Window<W>& win);
-
+ elementary_opening(const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -53,12 +50,13 @@
// Generic version.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_opening_(const Image<I>& input,
- const Window<W>& win)
+ elementary_opening_(const Image<I>& input);
{
- return elementary_dilation(elementary_erosion(input, win), win); // FIXME : memory
+ oln_plain(I) tmp;
+ tmp = elementary_erosion(input);
+ return elementary_dilation(tmp);
}
// FIXME: Add a fast version.
@@ -68,11 +66,11 @@
// Facade.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_opening(const Image<I>& input, const Window<W>& win)
+ elementary_opening(const Image_with_Nbh<I>& input)
{
- return impl::elementary_opening_(exact(input), exact(win));
+ return impl::elementary_opening_(exact(input));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 894)
+++ oln/morpho/erosion.hh (working copy)
@@ -30,7 +30,7 @@
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
-#include <oln/accumulator/min.hh>
+#include <oln/accumulator/max.hh>
namespace oln
{
@@ -54,16 +54,40 @@
template <typename I, typename W>
oln_plain(I)
- elementary_erosion_(const Image<I>& input,
- const Window<W>& win)
+ erosion_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::min_<oln_value(I)> min;
- return level::apply_local(min, input, win);
+ return level::apply_local(max, input, win);
+ }
+
+ template <typename I>
+ oln_plain(I)
+ erosion_on_set_(const Image<I>&,
+ const I& input)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::and_<oln_value(I)> accu_and;
+ return level::apply_local(accu_and, input);
}
// FIXME: Add a fast version.
+
+ // Impl facade.
+
+ template <typename I>
+ oln_plain(I) erosion_(const Image<I>& input)
+ {
+ return erosion_on_function_(exact(input), exact(input));
+ }
+
+ template <typename I>
+ oln_plain(I) erosion_(const Binary_Image<I>& input)
+ {
+ return erosion_on_set_(exact(input), exact(input));
+ }
+
} // end of namespace oln::morpho::impl
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 0)
+++ oln/morpho/closing.hh (revision 0)
@@ -0,0 +1,86 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_CLOSING_HH
+# define OLN_MORPHO_CLOSING_HH
+
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ closing(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ closing_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ oln_plain(I) = elementary_dilation(input, win);
+ return elementary_erosion(tmp, win); // FIXME : inverse(win).
+ }
+
+ // FIXME: Add a fast version.
+
+
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ closing(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::closing_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_CLOSING_HH
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 894)
+++ oln/morpho/opening.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_MORPHO_OPENING_HH
# define OLN_MORPHO_OPENING_HH
-#include <oln/level/apply_local.hh>
-#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
@@ -58,9 +56,8 @@
opening_(const Image<I>& input,
const Window<W>& win)
{
- border::fill(input, oln_min(oln_value(I)));
- accumulator::max_<oln_value(I)> max;
- return level::apply_local(max, input, win);
+ oln_plain(I) = elementary_dilation(input, win);
+ return elementary_erosion(tmp, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
@@ -84,4 +81,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_DILATION_HH
+#endif // ! OLN_MORPHO_OPENING_HH
Index: oln/level/local.hh
--- oln/level/local.hh (revision 894)
+++ oln/level/local.hh (working copy)
@@ -115,22 +115,26 @@
return f.value();
}
- /*
// Optimised version for OR operator with window.
- template <typename A, typename I, typename W>
- typename A::result
- local_(const accumulator::or_<oln_value(I)>& f,
+ template <typename B, typename I, typename W>
+ B
+ local_(const accumulator::or_<B>& f,
const Binary_Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
- f.init();
+ f.init_with(input(p));
+ if (f.value() == true)
+ return true;
oln_qiter(W) q(p, win);
for_all(q)
- if (f(input(q)) == f.ultimate)
- return (f.ultimate);
+ {
+ f(input(q));
+ if (f.value() == true)
+ return true;
+ }
return f.value();
}
@@ -139,17 +143,20 @@
// Optimised version for AND operator with neighborhood.
- template <typename A, typename I>
- typename A::result
- local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ template <typename B, typename I>
+ B
+ local_(const accumulator::and_< B > f,
const Binary_Image<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
oln_niter(I) n(p, input);
for_all(n)
- if (f(input(n)) == f.ultimate)
- return (f.ultimate);
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() == true)
+ return true;
+ }
return f.value();
}
@@ -157,22 +164,23 @@
// Optimised version for AND operator with window.
template <typename A, typename I, typename W>
- typename A::result
- local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ B
+ local_(const accumulator::and_< B > f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
- f.init();
+ f.init_with(input(p));
oln_qiter(W) q(p, win);
for_all(q)
- if (f(input(q)) == f.ultimate)
- return (f.ultimate);
+ {
+ f(input(q));
+ if (f.value() == true)
+ return true;
+ }
return f.value();
}
- */
-
} // end of namespace oln::level::impl
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Factor code for iterators on dpoints and update.
* oln/core/internal/dpoints_piter_impl.hh: New; copy of...
* oln/core/internal/dpoints_piter.hh: ...this.
* oln/debug/print_nbh.hh: Update.
* oln/core/gen/dpoints_piter.hh (dpoints_fwd_piter_): Overload.
Update inheritance.
(dpoints_bkd_piter_): Update.
(include): Update.
* oln/core/internal/image_selectors.hh (Image_mutability): Add
FIXME.
* oln/core/internal/op_image_plus_nbh.hh: Better commentary.
Minor fixes.
* oln/accumulator/and.hh (include): Remove max_value.hh.
(init): Use 'true'.
(operator()): Use 'and'.
* oln/accumulator/or.hh (include): Remove max_value.hh.
(ultimate): Remove.
(init): Use 'false'.
(operator()): Use 'or'.
* oln/core/concept/accumulator.hh: Add FIXME.
* oln/core/internal/max_value.hh (oln_min): Remove.
* oln/core/internal/min_value.hh: Add FIXME.
* oln/morpho/dilation.hh: Fix.
* oln/level/local.hh (local_): Update 'or on nbh' version.
(local_): Inactivate other optimized versions.
accumulator/and.hh | 6
accumulator/or.hh | 8 -
core/concept/accumulator.hh | 2
core/gen/dpoints_piter.hh | 222 ++++++++++--------------------------
core/internal/dpoints_piter_impl.hh | 166 ++++++++++----------------
core/internal/image_selectors.hh | 2
core/internal/max_value.hh | 1
core/internal/min_value.hh | 2
core/internal/op_image_plus_nbh.hh | 2
debug/print_nbh.hh | 4
level/local.hh | 29 ++--
morpho/dilation.hh | 3
12 files changed, 157 insertions(+), 290 deletions(-)
Index: oln/accumulator/and.hh
--- oln/accumulator/and.hh (revision 893)
+++ oln/accumulator/and.hh (working copy)
@@ -29,7 +29,6 @@
# define OLN_ACCUMULATOR_AND_HH
# include <oln/core/concept/accumulator.hh>
-# include <oln/core/internal/max_value.hh>
namespace oln
@@ -68,7 +67,7 @@
void
and_<T>::init() const
{
- this->val_ = oln_min(T);
+ this->val_ = true;
}
template <typename T>
@@ -82,8 +81,7 @@
void
and_<T>::operator()(const T& val) const
{
- if (val < this->val_)
- this->val_ = val;
+ this->val_ = this->val_ and val;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/accumulator/or.hh
--- oln/accumulator/or.hh (revision 893)
+++ oln/accumulator/or.hh (working copy)
@@ -29,7 +29,6 @@
# define OLN_ACCUMULATOR_OR_HH
# include <oln/core/concept/accumulator.hh>
-# include <oln/core/internal/max_value.hh>
namespace oln
@@ -51,7 +50,6 @@
void operator()(const T& val) const;
- mutable T ultimate;
private:
mutable T val_;
};
@@ -69,8 +67,7 @@
void
or_<T>::init() const
{
- this->val_ = oln_min(T);
- this->ultimate = oln_max(T);
+ this->val_ = false;
}
template <typename T>
@@ -84,8 +81,7 @@
void
or_<T>::operator()(const T& val) const
{
- if (val < this->val_)
- this->val_ = val;
+ this->val_ = this->val_ or val;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/debug/print_nbh.hh
--- oln/debug/print_nbh.hh (revision 893)
+++ oln/debug/print_nbh.hh (working copy)
@@ -55,7 +55,7 @@
const I& input, std::ostream& ostr)
{
oln_piter(I) p(input.points());
- oln_niter(I) n(p, input.nbhood());
+ oln_niter(I) n(p, input);
for_all(p)
{
ostr << input(p) << ": ";
@@ -74,7 +74,7 @@
const I& input, std::ostream& ostr)
{
oln_piter(I) p(input.points());
- oln_niter(I) n(p, input.nbhood());
+ oln_niter(I) n(p, input);
for_all(p)
{
ostr << input(p) << ": ";
Index: oln/core/concept/accumulator.hh
--- oln/core/concept/accumulator.hh (revision 893)
+++ oln/core/concept/accumulator.hh (working copy)
@@ -60,7 +60,7 @@
Accumulator<Exact>::init_with(const T& val) const
{
exact(this)->init();
- exact(this)->operator()(val);
+ exact(this)->operator()(val); // FIXME: Change to ->take(val)?
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 893)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -28,121 +28,105 @@
#ifndef OLN_CORE_GEN_DPOINTS_PITER_HH
# define OLN_CORE_GEN_DPOINTS_PITER_HH
-# include <oln/core/concept/iterator_on_points.hh>
-# include <oln/core/internal/dpoints_impl.hh>
+# include <oln/core/concept/window.hh>
+# include <oln/core/concept/neighborhood.hh>
+# include <oln/core/concept/image.hh>
+# include <oln/core/internal/dpoints_piter_impl.hh>
namespace oln
{
- /// Fwd decls.
+ // --------------------------- dpoints_fwd_piter_<P>
+
+
+
+ // Fwd decl.
template <typename P> class dpoints_fwd_piter_;
- template <typename P> class dpoints_bkd_piter_;
- // Super types.
+ // Super type.
template <typename P>
struct super_trait_< dpoints_fwd_piter_<P> >
{
typedef dpoints_fwd_piter_<P> current__;
typedef Iterator_on_Points<current__> ret;
};
- template <typename P>
- struct super_trait_< dpoints_bkd_piter_<P> >
- {
- typedef dpoints_bkd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
- /// Virtual types.
+ // Virtual type.
template <typename P>
struct vtypes< dpoints_fwd_piter_<P> >
{
typedef P point;
};
- template <typename P>
- struct vtypes< dpoints_bkd_piter_<P> >
- {
- typedef P point;
- };
-
- namespace internal
- {
-
- /// Class to factor some code.
-
+ // Forward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) >
+ class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
+ public internal::dpoints_fwd_piter_impl_<P>
{
public:
- dpoints_piter_impl_(const dpoints_piter_impl_&);
- void operator=(const dpoints_piter_impl_&);
-
- void impl_invalidate();
+ // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
- bool impl_is_valid() const;
+ template <typename Pl, typename W>
+ dpoints_fwd_piter_(const Pl& p, const Window<W>& win);
- P impl_to_point() const;
+ template <typename Pl, typename I>
+ dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
- const P* impl_point_adr() const;
+ template <typename Pl, typename N>
+ dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh);
- protected:
+ }; // end of class oln::dpoints_fwd_piter_<P>
- const P* p_ref_;
- std::vector<typename P::dpoint> dps_;
- unsigned n_, i_;
- P p_;
- // Ctor.
- template <typename Pl>
- dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data);
- void update_p_();
- };
+ // --------------------------- dpoints_bkd_piter_<P>
- } // end of namespace oln::internal
+ // Fwd decl.
+ template <typename P> class dpoints_bkd_piter_;
- /// Forward point iterator class on a set of dpoints.
+ // Super type.
template <typename P>
- class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ struct super_trait_< dpoints_bkd_piter_<P> >
{
- public:
-
- template <typename Pl, typename X>
- dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh);
-
- void impl_start();
-
- void impl_next();
+ typedef dpoints_bkd_piter_<P> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
- }; // end of class oln::dpoints_fwd_piter_<P>
+ // Virtual type.
+ template <typename P>
+ struct vtypes< dpoints_bkd_piter_<P> >
+ {
+ typedef P point;
+ };
/// Backward point iterator class on a set of dpoints.
-
template <typename P>
class dpoints_bkd_piter_ : public Iterator_on_Points< dpoints_bkd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ public internal::dpoints_bkd_piter_impl_<P>
{
public:
- template <typename Pl, typename X>
- dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh);
+ // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
+
+ template <typename Pl, typename W>
+ dpoints_bkd_piter_(const Pl& p, const Window<W>& win);
- void impl_start();
+ template <typename Pl, typename I>
+ dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
- void impl_next();
+ template <typename Pl, typename N>
+ dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh);
}; // end of class oln::dpoints_bkd_piter_<P>
@@ -150,128 +134,56 @@
# ifndef OLN_INCLUDE_ONLY
- namespace internal
- {
-
- template <typename Pl>
- const Pl* point_adr_(const Point<Pl>& p)
- {
- return exact(&p);
- }
-
- template <typename Pl>
- const typename Pl::point* point_adr_(const Iterator_on_Points<Pl>& p)
- {
- return p.point_adr();
- }
-
- template <typename P>
- template <typename Pl>
- dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data)
- {
- p_ref_ = point_adr_(ref);
- dps_ = data.dpoints();
- n_ = data.size();
- i_ = n_;
- postcondition(n_ != 0);
- }
-
- template <typename P>
- void
- dpoints_piter_impl_<P>::impl_invalidate()
- {
- i_ = n_;
- }
-
- template <typename P>
- bool
- dpoints_piter_impl_<P>::impl_is_valid() const
- {
- return i_ != n_;
- }
-
- template <typename P>
- P
- dpoints_piter_impl_<P>::impl_to_point() const
- {
- return p_;
- }
-
- template <typename P>
- const P*
- dpoints_piter_impl_<P>::impl_point_adr() const
- {
- return &p_;
- }
-
- template <typename P>
- void
- dpoints_piter_impl_<P>::update_p_()
- {
- p_ = *p_ref_+ dps_[i_];
- }
-
- } // end of namespace oln::internal
-
-
// fwd
template <typename P>
- template <typename Pl, typename X>
- dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh)
+ template <typename Pl, typename W>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Window<W>& win)
:
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(win))
{
}
template <typename P>
- void
- dpoints_fwd_piter_<P>::impl_start()
+ template <typename Pl, typename I>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, ima.nbhood())
{
- this->i_ = 0;
- this->update_p_();
}
template <typename P>
- void
- dpoints_fwd_piter_<P>::impl_next()
+ template <typename Pl, typename N>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(nbh))
{
- if (++this->i_ = this->n_)
- return;
- this->update_p_();
}
-
// bkd
template <typename P>
- template <typename Pl, typename X>
- dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh)
+ template <typename Pl, typename W>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Window<W>& win)
:
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(win))
{
}
template <typename P>
- void
- dpoints_bkd_piter_<P>::impl_start()
+ template <typename Pl, typename I>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, ima.nbhood())
{
- this->i_ = this->n_ - 1;
- this->update_p_();
}
template <typename P>
- void
- dpoints_bkd_piter_<P>::impl_next()
- {
- if (this->i_ = 0)
+ template <typename Pl, typename N>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(nbh))
{
- this->i_ = this->n_;
- return;
- }
- --this->i_;
- this->update_p_();
}
# endif
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 893)
+++ oln/core/internal/max_value.hh (working copy)
@@ -31,7 +31,6 @@
# include <limits>
#define oln_max(T) std::numeric_limits< T >::max() // FIXME std lib
-#define oln_min(T) std::numeric_limits< T >::min() // FIXME std lib
#endif // ! OLN_CORE_INTERNAL_MAX_VALUE_HH
Index: oln/core/internal/dpoints_piter_impl.hh
--- oln/core/internal/dpoints_piter_impl.hh (revision 892)
+++ oln/core/internal/dpoints_piter_impl.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_GEN_DPOINTS_PITER_HH
-# define OLN_CORE_GEN_DPOINTS_PITER_HH
+#ifndef OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
+# define OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
# include <oln/core/concept/iterator_on_points.hh>
# include <oln/core/internal/dpoints_impl.hh>
@@ -35,123 +35,79 @@
namespace oln
{
-
- /// Fwd decls.
- template <typename P> class dpoints_fwd_piter_;
- template <typename P> class dpoints_bkd_piter_;
-
-
- // Super types.
- template <typename P>
- struct super_trait_< dpoints_fwd_piter_<P> >
- {
- typedef dpoints_fwd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
- template <typename P>
- struct super_trait_< dpoints_bkd_piter_<P> >
- {
- typedef dpoints_bkd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
-
-
- /// Virtual types.
- template <typename P>
- struct vtypes< dpoints_fwd_piter_<P> >
- {
- typedef P point;
- };
- template <typename P>
- struct vtypes< dpoints_bkd_piter_<P> >
- {
- typedef P point;
- };
-
-
-
namespace internal
{
- /// Class to factor some code.
+ /// Classes to factor code for iterators based on vector of dpoints.
template <typename P>
- class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) >
+ class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) > // FIXME: Add err msg.
{
public:
-
- dpoints_piter_impl_(const dpoints_piter_impl_&);
- void operator=(const dpoints_piter_impl_&);
+ // dpoints_piter_impl_(const dpoints_piter_impl_&);
void impl_invalidate();
-
bool impl_is_valid() const;
P impl_to_point() const;
-
const P* impl_point_adr() const;
protected:
- const P* p_ref_;
- std::vector<typename P::dpoint> dps_;
- unsigned n_, i_;
- P p_;
-
- // Ctor.
template <typename Pl>
- dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data);
+ dpoints_piter_impl_(const Pl& p_ref,
+ const std::vector<typename P::dpoint>& dps);
void update_p_();
- };
-
- } // end of namespace oln::internal
+ const P* p_ref_;
+ const std::vector<typename P::dpoint>& dps_;
+ unsigned n_, i_;
+ P p_;
+ };
- /// Forward point iterator class on a set of dpoints.
+ // fwd
template <typename P>
- class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ class dpoints_fwd_piter_impl_ : public dpoints_piter_impl_<P>
{
public:
- template <typename Pl, typename X>
- dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh);
-
void impl_start();
-
void impl_next();
- }; // end of class oln::dpoints_fwd_piter_<P>
+ protected:
+ template <typename Pl>
+ dpoints_fwd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data);
+ };
- /// Backward point iterator class on a set of dpoints.
+ // bkd
template <typename P>
- class dpoints_bkd_piter_ : public Iterator_on_Points< dpoints_bkd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ class dpoints_bkd_piter_impl_ : public dpoints_piter_impl_<P>
{
public:
- template <typename Pl, typename X>
- dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh);
-
void impl_start();
-
void impl_next();
- }; // end of class oln::dpoints_bkd_piter_<P>
+ protected:
+
+ template <typename Pl>
+ dpoints_bkd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data);
+ };
# ifndef OLN_INCLUDE_ONLY
- namespace internal
- {
+
+ // point_adr_
template <typename Pl>
const Pl* point_adr_(const Point<Pl>& p)
@@ -165,69 +121,70 @@
return p.point_adr();
}
+
+ // dpoints_piter_impl_<P>
+
template <typename P>
template <typename Pl>
- dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data)
+ dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& p_ref,
+ const std::vector<typename P::dpoint>& dps)
+ : p_ref_(point_adr_(p_ref)),
+ dps_(dps),
+ n_(dps.size()),
+ i_(n_)
{
- p_ref_ = point_adr_(ref);
- dps_ = data.dpoints();
- n_ = data.size();
- i_ = n_;
- postcondition(n_ != 0);
+ precondition(dps.size() != 0);
}
template <typename P>
void
dpoints_piter_impl_<P>::impl_invalidate()
{
- i_ = n_;
+ this->i_ = this->n_;
}
template <typename P>
bool
dpoints_piter_impl_<P>::impl_is_valid() const
{
- return i_ != n_;
+ return this->i_ != this->n_;
}
template <typename P>
P
dpoints_piter_impl_<P>::impl_to_point() const
{
- return p_;
+ return this->p_;
}
template <typename P>
const P*
dpoints_piter_impl_<P>::impl_point_adr() const
{
- return &p_;
+ return &(this->p_);
}
template <typename P>
void
dpoints_piter_impl_<P>::update_p_()
{
- p_ = *p_ref_+ dps_[i_];
+ this->p_ = *(this->p_ref_) + this->dps_[i_];
}
- } // end of namespace oln::internal
-
- // fwd
+ // dpoints_fwd_piter_impl_<P>
template <typename P>
- template <typename Pl, typename X>
- dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh)
- :
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ template <typename Pl>
+ dpoints_fwd_piter_impl_<P>::dpoints_fwd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data)
+ : dpoints_piter_impl_<P>(p_ref, data.dpoints())
{
}
template <typename P>
void
- dpoints_fwd_piter_<P>::impl_start()
+ dpoints_fwd_piter_impl_<P>::impl_start()
{
this->i_ = 0;
this->update_p_();
@@ -235,7 +192,7 @@
template <typename P>
void
- dpoints_fwd_piter_<P>::impl_next()
+ dpoints_fwd_piter_impl_<P>::impl_next()
{
if (++this->i_ = this->n_)
return;
@@ -243,19 +200,19 @@
}
- // bkd
+ // dpoints_bkd_piter_impl_<P>
template <typename P>
- template <typename Pl, typename X>
- dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh)
- :
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ template <typename Pl>
+ dpoints_bkd_piter_impl_<P>::dpoints_bkd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data)
+ : dpoints_piter_impl_<P>(p_ref, data.dpoints())
{
}
template <typename P>
void
- dpoints_bkd_piter_<P>::impl_start()
+ dpoints_bkd_piter_impl_<P>::impl_start()
{
this->i_ = this->n_ - 1;
this->update_p_();
@@ -263,7 +220,7 @@
template <typename P>
void
- dpoints_bkd_piter_<P>::impl_next()
+ dpoints_bkd_piter_impl_<P>::impl_next()
{
if (this->i_ = 0)
{
@@ -271,12 +228,13 @@
return;
}
--this->i_;
- this->update_p_();
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
} // end of namespace oln
-#endif // ! OLN_CORE_GEN_DPOINTS_PITER_HH
+#endif // ! OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
Index: oln/core/internal/image_selectors.hh
--- oln/core/internal/image_selectors.hh (revision 893)
+++ oln/core/internal/image_selectors.hh (working copy)
@@ -56,7 +56,7 @@
struct case_< Image_mutability, Exact, 2 >
:
where_< mlc::and_< stc_type_is_found(lvalue),
- stc_type_is_found(index) > >
+ stc_type_is_found(index) > > // FIXME: Wrong!
{
typedef Fast_Image<Exact> ret;
};
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 893)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -79,7 +79,7 @@
namespace internal
{
- /// Implementation class the result of "Image I + Neighborhood N".
+ /// Implementation class for the result of "Image I + Neighborhood N".
template <typename I, typename N>
class current
Index: oln/core/internal/min_value.hh
--- oln/core/internal/min_value.hh (revision 893)
+++ oln/core/internal/min_value.hh (working copy)
@@ -30,6 +30,6 @@
# include <limits>
-# define oln_min(T) std::numeric_limits< T >::min()
+# define oln_min(T) std::numeric_limits< T >::min() // FIXME std lib
# endif // ! OLN_CORE_INTERNAL_MIN_VALUE_HH
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 893)
+++ oln/morpho/dilation.hh (working copy)
@@ -54,8 +54,7 @@
template <typename I, typename W>
oln_plain(I)
- elementary_dilation_(const Image<I>& input,
- const Window<W>& win)
+ dilation_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::max_<oln_value(I)> max;
Index: oln/level/local.hh
--- oln/level/local.hh (revision 893)
+++ oln/level/local.hh (working copy)
@@ -68,8 +68,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
- // 'input'!
+ oln_niter(I) n(p, input);
for_all(n)
f(input(n));
return f.value();
@@ -97,27 +96,32 @@
// Optimised version for OR operator with neighborhood.
- template <typename A, typename I>
- typename A::result
- local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ template <typename B, typename I>
+ B
+ local_(const accumulator::or_<B>& f,
const Binary_Image<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
- // 'input'!
+ if (f.value() = true)
+ return true;
+ oln_niter(I) n(p, input);
for_all(n)
- if (f(input(n)) = f.ultimate)
- return (f.ultimate);
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() = true)
+ return true;
+ }
return f.value();
}
+ /*
// Optimised version for OR operator with window.
template <typename A, typename I, typename W>
typename A::result
- local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ local_(const accumulator::or_<oln_value(I)>& f,
const Binary_Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
@@ -142,8 +146,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
- // 'input'!
+ oln_niter(I) n(p, input);
for_all(n)
if (f(input(n)) = f.ultimate)
return (f.ultimate);
@@ -168,6 +171,8 @@
return f.value();
}
+ */
+
} // end of namespace oln::level::impl
1
0
21 Mar '07
nonconst.hh doesn't exist but was (maybe is) still included.
image2d<bool> + morpho compile but error at execution
: Assertion `this->owns_(p)' failed.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Algo MorphoMath : and, or, opening, closing, elementary algo.
* oln/accumulator/and.hh: New.
* oln/accumulator/or.hh: New.
* oln/core/internal/max_value.hh,
* oln/core/internal/op_image_plus_nbh.hh,
* oln/morpho/elementary_erosion.hh,
* oln/morpho/dilation.hh: Update.
* oln/morpho/elementary_closing.hh,
* oln/morpho/elementary_opening.hh: New.
* oln/morpho/elementary_dilation.hh: Update.
* oln/morpho/erosion.hh: New.
* oln/morpho/opening.hh: New.
* oln/level/local.hh: .
accumulator/and.hh | 95 ++++++++++++++++++++++++++++++++++++
accumulator/or.hh | 97 +++++++++++++++++++++++++++++++++++++
core/internal/max_value.hh | 4 +
core/internal/op_image_plus_nbh.hh | 1
level/local.hh | 81 +++++++++++++++++++++++++++++-
morpho/dilation.hh | 2
morpho/elementary_closing.hh | 85 ++++++++++++++++++++++++++++++++
morpho/elementary_dilation.hh | 10 +--
morpho/elementary_erosion.hh | 1
morpho/elementary_opening.hh | 85 ++++++++++++++++++++++++++++++++
morpho/erosion.hh | 86 ++++++++++++++++++++++++++++++++
morpho/opening.hh | 87 +++++++++++++++++++++++++++++++++
12 files changed, 623 insertions(+), 11 deletions(-)
Index: oln/accumulator/and.hh
--- oln/accumulator/and.hh (revision 0)
+++ oln/accumulator/and.hh (revision 0)
@@ -0,0 +1,95 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_ACCUMULATOR_AND_HH
+# define OLN_ACCUMULATOR_AND_HH
+
+# include <oln/core/concept/accumulator.hh>
+# include <oln/core/internal/max_value.hh>
+
+
+namespace oln
+{
+
+ namespace accumulator
+ {
+
+ template <typename T>
+ struct and_ : public Accumulator< and_<T> >
+ {
+ typedef T argument;
+ typedef T result;
+
+ and_();
+
+ void init() const;
+ const T& value() const;
+
+ void operator()(const T& val) const;
+
+ private:
+ mutable T val_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ and_<T>::and_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ and_<T>::init() const
+ {
+ this->val_ = oln_min(T);
+ }
+
+ template <typename T>
+ const T&
+ and_<T>::value() const
+ {
+ return this->val_;
+ }
+
+ template <typename T>
+ void
+ and_<T>::operator()(const T& val) const
+ {
+ if (val < this->val_)
+ this->val_ = val;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_AND_HH
Index: oln/accumulator/or.hh
--- oln/accumulator/or.hh (revision 0)
+++ oln/accumulator/or.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_ACCUMULATOR_OR_HH
+# define OLN_ACCUMULATOR_OR_HH
+
+# include <oln/core/concept/accumulator.hh>
+# include <oln/core/internal/max_value.hh>
+
+
+namespace oln
+{
+
+ namespace accumulator
+ {
+
+ template <typename T>
+ struct or_ : public Accumulator< or_<T> >
+ {
+ typedef T argument;
+ typedef T result;
+
+ or_();
+
+ void init() const;
+ const T& value() const;
+
+ void operator()(const T& val) const;
+
+ mutable T ultimate;
+ private:
+ mutable T val_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ or_<T>::or_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ or_<T>::init() const
+ {
+ this->val_ = oln_min(T);
+ this->ultimate = oln_max(T);
+ }
+
+ template <typename T>
+ const T&
+ or_<T>::value() const
+ {
+ return this->val_;
+ }
+
+ template <typename T>
+ void
+ or_<T>::operator()(const T& val) const
+ {
+ if (val < this->val_)
+ this->val_ = val;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_OR_HH
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 892)
+++ oln/core/internal/max_value.hh (working copy)
@@ -30,6 +30,8 @@
# include <limits>
-# define oln_max(T) std::numeric_limits< T >::max()
+#define oln_max(T) std::numeric_limits< T >::max() // FIXME std lib
+#define oln_min(T) std::numeric_limits< T >::min() // FIXME std lib
#endif // ! OLN_CORE_INTERNAL_MAX_VALUE_HH
+
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 892)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -28,7 +28,6 @@
#ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
-# include <mlc/unconst.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/gen/op.hh>
# include <oln/core/gen/dpoints_piter.hh>
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 892)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -32,7 +32,6 @@
#include <oln/border/fill.hh>
#include <oln/accumulator/min.hh>
-
namespace oln
{
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 892)
+++ oln/morpho/dilation.hh (working copy)
@@ -32,6 +32,8 @@
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
+namespace oln
+{
namespace morpho
{
Index: oln/morpho/elementary_closing.hh
--- oln/morpho/elementary_closing.hh (revision 0)
+++ oln/morpho/elementary_closing.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_MORPHO_ELEMENTARY_CLOSING_HH
+# define OLN_MORPHO_ELEMENTARY_CLOSING_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_closing(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_closing_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return elementary_erosion(elementary_dilation(input, win), win); // FIXME : memory
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_closing(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::elementary_closing_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_CLOSING_HH
Index: oln/morpho/elementary_opening.hh
--- oln/morpho/elementary_opening.hh (revision 0)
+++ oln/morpho/elementary_opening.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_MORPHO_ELEMENTARY_OPENING_HH
+# define OLN_MORPHO_ELEMENTARY_OPENING_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_opening(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_opening_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return elementary_dilation(elementary_erosion(input, win), win); // FIXME : memory
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_opening(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::elementary_opening_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_OPENING_HH
Index: oln/morpho/elementary_dilation.hh
--- oln/morpho/elementary_dilation.hh (revision 892)
+++ oln/morpho/elementary_dilation.hh (working copy)
@@ -31,7 +31,7 @@
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
-
+#include <oln/accumulator/or.hh>
namespace oln
{
@@ -66,11 +66,11 @@
template <typename I>
oln_plain(I)
elementary_dilation_on_set_(const Image<I>&,
- const I&)
+ const I& input)
{
- oln_plain(I) tmp;
- std::cerr << "morpho::impl::elementary_dilation_on_set_ is not yet impled!" << std::endl;
- return tmp;
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::or_<oln_value(I)> accu_or;
+ return level::apply_local(accu_or, input);
}
// FIXME: Add a fast version.
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 0)
+++ oln/morpho/erosion.hh (revision 0)
@@ -0,0 +1,86 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_EROSION_HH
+# define OLN_MORPHO_EROSION_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/accumulator/min.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ erosion(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_erosion_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::min_<oln_value(I)> min;
+ return level::apply_local(min, input, win);
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ erosion(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::erosion_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_EROSION_HH
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 0)
+++ oln/morpho/opening.hh (revision 0)
@@ -0,0 +1,87 @@
+// 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_MORPHO_OPENING_HH
+# define OLN_MORPHO_OPENING_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ opening(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ opening_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::max_<oln_value(I)> max;
+ return level::apply_local(max, input, win);
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ opening(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::opening_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_DILATION_HH
Index: oln/level/local.hh
--- oln/level/local.hh (revision 892)
+++ oln/level/local.hh (working copy)
@@ -31,7 +31,8 @@
# 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
{
@@ -67,7 +68,8 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be 'input'!
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
+ // 'input'!
for_all(n)
f(input(n));
return f.value();
@@ -76,7 +78,6 @@
// FIXME: Generic version with nbh given as argument?
-
// Generic version with window.
template <typename A, typename I, typename W>
@@ -93,6 +94,80 @@
return f.value();
}
+
+ // Optimised version for OR operator with neighborhood.
+
+ template <typename A, typename I>
+ typename A::result
+ local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
+ // 'input'!
+ for_all(n)
+ if (f(input(n)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
+
+ // Optimised version for OR operator with window.
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init();
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (f(input(q)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
+
+ // FIXME : same function for OR.
+
+ // Optimised version for AND operator with neighborhood.
+
+ template <typename A, typename I>
+ typename A::result
+ local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
+ // 'input'!
+ for_all(n)
+ if (f(input(n)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
+
+ // Optimised version for AND operator with window.
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init();
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (f(input(q)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
} // end of namespace oln::level::impl
1
0