Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
April 2005
- 8 participants
- 73 discussions
proto-1.0 155: Add unary point-wise function (PWF) and use it to simplify unary apply on PWF.
by Roland Levillain 14 Apr '05
by Roland Levillain 14 Apr '05
14 Apr '05
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 18 +++++
oln/core/pw/abstract/unary_function.hh | 108 +++++++++++++++++++++++++++++++++
oln/core/pw/apply.hh | 45 ++++---------
oln/makefile.src | 1
4 files changed, 141 insertions(+), 31 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add unary point-wise function (PWF).
Use it to simplify unary apply on PWF.
* oln/core/pw/abstract/unary_function.hh: New file.
* oln/core/pw/apply.hh: Use it to rewrite pw::apply.
(apply): Inherit from pw::abstract::unary_function.
Rename as ...
(apply1): ...this.
(apply1::input_): Remove attribute.
(apply1::apply1): Adjust ctor.
(apply1::impl_get): Adjust method.
(apply1::impl_size, apply1::impl_hold, apply1::impl_hold_large):
Remove methods.
* oln/makefile.src (OLN_DEP): Add
core/pw/abstract/unary_function.hh.
Index: olena/oln/core/pw/abstract/unary_function.hh
--- olena/oln/core/pw/abstract/unary_function.hh (revision 0)
+++ olena/oln/core/pw/abstract/unary_function.hh (revision 0)
@@ -0,0 +1,108 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH
+# define OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH
+
+# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/abstract/size.hh>
+
+
+
+namespace oln {
+
+
+ // fwd decl
+ namespace pw {
+ namespace abstract {
+ template <typename T, typename E> struct unary_function;
+ }
+ }
+
+ // super type
+ template <typename T, typename E>
+ struct set_super_type < pw::abstract::unary_function<T, E> > { typedef pw::abstract::function<E> ret; };
+
+ // props
+ template <typename T, typename E>
+ struct set_props < category::pw, pw::abstract::unary_function<T, E> >
+ {
+ typedef oln_pw_type_of(T, point) point_type;
+ typedef oln_pw_type_of(T, size) size_type;
+ };
+
+
+ namespace pw {
+
+ namespace abstract {
+
+ template <typename T, typename E>
+ struct unary_function : public function<E>
+ {
+ typedef T input_type;
+
+ T input;
+
+ unary_function(const abstract::function<T>& input) :
+ input(input.exact())
+ {
+ }
+
+ typedef oln_pw_type_of(E, point) point_type;
+ typedef oln_pw_type_of(E, size) size_type;
+
+ const size_type& impl_size() const
+ {
+ return input.size();
+ }
+
+ bool impl_hold(const point_type& p) const
+ {
+ return input.hold(p);
+ }
+
+ bool impl_hold_large(const point_type& p) const
+ {
+ return input.hold_large(p);
+ }
+
+ protected:
+ unary_function() {}
+
+ };
+
+
+ } // end of namespace oln::pw::abstract
+
+ } // end of namespace oln::pw
+
+} // end of namespace oln
+
+
+
+#endif // ! OLENA_CORE_PW_ABSTRACT_UNARY_FUNCTION_HH
Index: olena/oln/core/pw/apply.hh
--- olena/oln/core/pw/apply.hh (revision 154)
+++ olena/oln/core/pw/apply.hh (working copy)
@@ -29,7 +29,7 @@
# define OLENA_CORE_PW_APPLY_HH
# include <mlc/fun.hh>
-# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/pw/abstract/unary_function.hh>
# include <oln/core/pw/abstract/binary_function.hh>
# include <oln/core/pw/macros.hh>
@@ -42,19 +42,19 @@
// fwd decl
namespace pw {
- template <typename F, typename T> struct apply;
+ template <typename F, typename T> struct apply1;
}
// super type
template <typename F, typename T>
- struct set_super_type < pw::apply<F, T> >
+ struct set_super_type < pw::apply1<F, T> >
{
- typedef pw::abstract::function< pw::apply<F, T> > ret;
+ typedef pw::abstract::unary_function< T, pw::apply1<F, T> > ret;
};
// props
template <typename F, typename T>
- struct set_props < category::pw, pw::apply<F, T> >
+ struct set_props < category::pw, pw::apply1<F, T> >
{
typedef oln_pw_type_of(T, point) point_type;
typedef typename F::result_type value_type;
@@ -65,45 +65,28 @@
namespace pw {
template <typename F, typename T>
- struct apply : public abstract::function < apply<F, T> >
+ struct apply1 : public abstract::unary_function < T, apply1<F, T> >
{
- typedef apply<F, T> self_type;
+ typedef apply1<F, T> self_type;
typedef oln_pw_type_of(self_type, point) point_type;
typedef oln_pw_type_of(self_type, value) value_type;
typedef oln_pw_type_of(self_type, size) size_type;
- typedef abstract::function<self_type> super_type;
+ typedef abstract::unary_function<T, self_type> super_type;
F f_;
- T input_;
- apply(const mlc::abstract::unary_function<F>& f,
+ apply1(const mlc::abstract::unary_function<F>& f,
const abstract::function<T>& input) :
- super_type(),
- f_(f.exact()),
- input_(input.exact())
- {
- }
-
- const size_type& impl_size() const
+ super_type(input),
+ f_(f.exact())
{
- return input_.size();
}
const value_type impl_get(const point_type& p) const
{
- return f_(input_(p));
- }
-
- bool impl_hold(const point_type& p) const
- {
- return input_.hold(p);
- }
-
- bool impl_hold_large(const point_type& p) const
- {
- return input_.hold_large(p);
+ return f_(this->input(p));
}
};
@@ -173,11 +156,11 @@
/// apply function on pwf
template <typename F, typename T>
-oln::pw::apply<F, T>
+oln::pw::apply1<F, T>
p_apply (const mlc::abstract::unary_function<F>& f,
const oln::pw::abstract::function<T>& x)
{
- oln::pw::apply<F, T> tmp(f, x);
+ oln::pw::apply1<F, T> tmp(f, x);
return tmp;
}
Index: olena/oln/makefile.src
--- olena/oln/makefile.src (revision 154)
+++ olena/oln/makefile.src (working copy)
@@ -109,6 +109,7 @@
\
core/pw/abstract/binary_function.hh \
core/pw/abstract/function.hh \
+ core/pw/abstract/unary_function.hh \
core/pw/apply.hh \
core/pw/all.hh \
core/pw/cmp.hh \
1
0
2005-04-14 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/core/typedefs.hh (oln_super_of): New macro.
* oln/core/abstract/image_operator.hh (set_props): Declare
output_type.
* oln/core/1d/qiter1d.hh: Remove typedefs.
* oln/core/2d/qiter2d.hh: Likewise.
* oln/core/3d/qiter3d.hh: Likewise.
* oln/core/1d/window1d.hh: Use inheritance.
* oln/core/2d/window2d.hh: Likewise.
(win_rectangle2d): New class.
* oln/core/3d/window3d.hh: Likewise.
* oln/core/any/dpoint.hh (operator+): Move to...
* oln/core/any/point.hh: ...here.
* oln/core/gen/regular_fwd_qiter.hh: Add parameter W.
* oln/core/gen/regular_bkd_qiter.hh: Likewise.
* oln/core/gen/regular_qiter.hh: Update.
* oln/core/gen/regular_window.hh: Update.
* oln/core/gen/regular_neighborhood.hh: Update.
* oln/morpho/stat.hh (stat_): Remove.
* oln/morpho/erosion.hh: Rewrite.
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 153)
+++ oln/core/typedefs.hh (working copy)
@@ -38,8 +38,14 @@
# include <mlc/to_string.hh>
+# define oln_super_of_(Type) \
+oln::internal::get_super_type<Type>::ret
+# define oln_super_of(Type) \
+typename oln_super_of_(Type)
+
+
namespace oln
{
Index: oln/core/abstract/image.hh
===================================================================
--- oln/core/abstract/image.hh (revision 153)
+++ oln/core/abstract/image.hh (working copy)
@@ -39,6 +39,7 @@
+
namespace oln {
Index: oln/core/abstract/image_operator.hh
===================================================================
--- oln/core/abstract/image_operator.hh (revision 153)
+++ oln/core/abstract/image_operator.hh (working copy)
@@ -48,8 +48,18 @@
template <typename O, typename I1, typename I2, typename E>
struct set_super_type< abstract::image_binary_operator<O, I1, I2, E> > { typedef abstract::image_operator<O, E> ret; };
+ // props
+ template <typename O, typename E>
+ struct set_props < category::image, abstract::image_operator<O, E> >
+ {
+ typedef O output_type;
+ };
+
+
+
+
namespace abstract {
Index: oln/core/1d/qiter1d.hh
===================================================================
--- oln/core/1d/qiter1d.hh (revision 153)
+++ oln/core/1d/qiter1d.hh (working copy)
@@ -31,18 +31,11 @@
# include <oln/core/1d/grid1d.hh>
# include <oln/core/1d/point1d.hh>
# include <oln/core/1d/dpoint1d.hh>
+
# include <oln/core/1d/window1d.hh>
# include <oln/core/gen/regular_fwd_qiter.hh>
# include <oln/core/gen/regular_bkd_qiter.hh>
-namespace oln {
-
- typedef regular_fwd_qiter<grid1d> fwd_qiter1d;
- typedef regular_bkd_qiter<grid1d> bkd_qiter1d;
-
-}
-
-
#endif // ! OLENA_CORE_1D_QITER1D_HH
Index: oln/core/1d/window1d.hh
===================================================================
--- oln/core/1d/window1d.hh (revision 153)
+++ oln/core/1d/window1d.hh (working copy)
@@ -36,8 +36,37 @@
namespace oln {
- typedef regular_window< grid1d > window1d;
+ // fwd decl
+ struct window1d;
+
+ // super type
+ template <>
+ struct set_super_type< window1d > { typedef abstract::regular_window< grid1d, window1d > ret; };
+
+
+ struct window1d : public abstract::regular_window< grid1d, window1d >
+ {
+ typedef abstract::regular_window< grid1d, window1d > super_type;
+
+ window1d()
+ {}
+
+ window1d(unsigned n, const coord_t crd[]) :
+ super_type(n, crd)
+ {}
+
+ window1d& add(const dpoint1d& dp)
+ {
+ this->add_(dp);
+ return *this;
+ }
+
+ };
+
+
+
+
// classical 1d windows
/*!
Index: oln/core/2d/qiter2d.hh
===================================================================
--- oln/core/2d/qiter2d.hh (revision 153)
+++ oln/core/2d/qiter2d.hh (working copy)
@@ -31,18 +31,11 @@
# include <oln/core/2d/grid2d.hh>
# include <oln/core/2d/point2d.hh>
# include <oln/core/2d/dpoint2d.hh>
+
# include <oln/core/2d/window2d.hh>
# include <oln/core/gen/regular_fwd_qiter.hh>
# include <oln/core/gen/regular_bkd_qiter.hh>
-namespace oln {
-
- typedef regular_fwd_qiter<grid2d> fwd_qiter2d;
- typedef regular_bkd_qiter<grid2d> bkd_qiter2d;
-
-}
-
-
#endif // ! OLENA_CORE_2D_QITER2D_HH
Index: oln/core/2d/window2d.hh
===================================================================
--- oln/core/2d/window2d.hh (revision 153)
+++ oln/core/2d/window2d.hh (working copy)
@@ -37,8 +37,70 @@
namespace oln
{
- typedef regular_window< grid2d > window2d;
+ // fwd decl
+ struct window2d;
+ // super type
+ template <>
+ struct set_super_type< window2d > { typedef abstract::regular_window< grid2d, window2d > ret; };
+
+
+ struct window2d : public oln_super_of_(window2d)
+ {
+ typedef oln_super_of_(window2d) super_type;
+
+ window2d()
+ {}
+
+ window2d(unsigned n, const coord_t crd[]) :
+ super_type(n, crd)
+ {}
+
+ window2d& add(const dpoint2d& dp)
+ {
+ this->add_(dp);
+ return *this;
+ }
+
+ };
+
+
+ // fwd decl
+ struct win_rectangle2d;
+
+ // super type
+ template <>
+ struct set_super_type< win_rectangle2d > { typedef abstract::regular_window< grid2d, win_rectangle2d > ret; };
+
+
+ /// Class win_rectangle2d.
+ struct win_rectangle2d : public oln_super_of_(win_rectangle2d)
+ {
+ typedef oln_super_of_(win_rectangle2d) super_type;
+
+ win_rectangle2d(unsigned height, unsigned width) :
+ height(height),
+ width(width)
+ {
+ int
+ min_drow = (1 - int(height)) / 2,
+ max_drow = int(height) / 2,
+ min_dcol = (1 - int(width)) / 2,
+ max_dcol = int(width) / 2;
+ for (int drow = min_drow; drow <= max_drow; ++drow)
+ for (int dcol = min_dcol; dcol <= max_dcol; ++dcol)
+ {
+ dpoint2d dp(drow, dcol);
+ this->add_(dp);
+ }
+ }
+
+ const unsigned height;
+ const unsigned width;
+ };
+
+
+
// classical 2d windows
/*!
Index: oln/core/3d/qiter3d.hh
===================================================================
--- oln/core/3d/qiter3d.hh (revision 153)
+++ oln/core/3d/qiter3d.hh (working copy)
@@ -31,18 +31,11 @@
# include <oln/core/3d/grid3d.hh>
# include <oln/core/3d/point3d.hh>
# include <oln/core/3d/dpoint3d.hh>
+
# include <oln/core/3d/window3d.hh>
# include <oln/core/gen/regular_fwd_qiter.hh>
# include <oln/core/gen/regular_bkd_qiter.hh>
-namespace oln {
-
- typedef regular_fwd_qiter<grid3d> fwd_qiter3d;
- typedef regular_bkd_qiter<grid3d> bkd_qiter3d;
-
-}
-
-
#endif // ! OLENA_CORE_3D_QITER3D_HH
Index: oln/core/3d/window3d.hh
===================================================================
--- oln/core/3d/window3d.hh (revision 153)
+++ oln/core/3d/window3d.hh (working copy)
@@ -36,8 +36,37 @@
namespace oln {
- typedef regular_window< grid3d > window3d;
+ // fwd decl
+ struct window3d;
+
+ // super type
+ template <>
+ struct set_super_type< window3d > { typedef abstract::regular_window< grid3d, window3d > ret; };
+
+
+ struct window3d : public abstract::regular_window< grid3d, window3d >
+ {
+ typedef abstract::regular_window< grid3d, window3d > super_type;
+
+ window3d()
+ {}
+
+ window3d(unsigned n, const coord_t crd[]) :
+ super_type(n, crd)
+ {}
+
+ window3d& add(const dpoint3d& dp)
+ {
+ this->add_(dp);
+ return *this;
+ }
+
+ };
+
+
+
+
// classical 3d windows
/*!
Index: oln/core/any/point.hh
===================================================================
--- oln/core/any/point.hh (revision 153)
+++ oln/core/any/point.hh (working copy)
@@ -127,8 +127,15 @@
# include <oln/core/any/dpoint.hh>
+
namespace oln {
+ template <typename P>
+ const any_point any_dpoint::operator+(const abstract::point<P>& rhs) const
+ {
+ return any_point();
+ }
+
const any_dpoint any_point::impl_minus(const any_point& rhs) const
{
precondition(false);
Index: oln/core/any/dpoint.hh
===================================================================
--- oln/core/any/dpoint.hh (revision 153)
+++ oln/core/any/dpoint.hh (working copy)
@@ -31,7 +31,6 @@
# include <iostream>
# include <mlc/contract.hh>
# include <oln/core/abstract/dpoint.hh>
-# include <oln/core/any/point.hh>
namespace oln {
@@ -124,14 +123,5 @@
# include <oln/core/any/point.hh>
-namespace oln {
- template <typename P>
- const any_point any_dpoint::operator+(const abstract::point<P>& rhs) const
- {
- return any_point();
- }
-
-}
-
#endif // ! OLENA_CORE_ANY_DPOINT_HH
Index: oln/core/gen/regular_fwd_qiter.hh
===================================================================
--- oln/core/gen/regular_fwd_qiter.hh (revision 153)
+++ oln/core/gen/regular_fwd_qiter.hh (working copy)
@@ -34,20 +34,27 @@
namespace oln {
// fwd decl
- template <typename G> struct regular_fwd_qiter;
+ template <typename G, typename W> struct regular_fwd_qiter;
// category
- template <typename G>
- struct set_super_type< regular_fwd_qiter<G> > { typedef abstract::regular_qiter< G, regular_fwd_qiter<G> > ret; };
+ template <typename G, typename W>
+ struct set_super_type< regular_fwd_qiter<G,W> > { typedef abstract::regular_qiter< G, regular_fwd_qiter<G,W> > ret; };
+ // props
+ template <typename G, typename W>
+ struct set_props < category::qiter, regular_fwd_qiter<G,W> >
+ {
+ typedef W window_type;
+ };
- template <typename G>
- struct regular_fwd_qiter : public abstract::regular_qiter< G, regular_fwd_qiter<G> >
+
+ template <typename G, typename W>
+ struct regular_fwd_qiter : public abstract::regular_qiter< G, regular_fwd_qiter<G,W> >
{
- typedef regular_fwd_qiter<G> self_type;
+ typedef regular_fwd_qiter<G,W> self_type;
typedef abstract::regular_qiter<G, self_type> super_type;
- regular_fwd_qiter(const regular_window<G>& win) :
+ regular_fwd_qiter(const abstract::regular_window<G,W>& win) :
super_type(win)
{
this->invalidate();
Index: oln/core/gen/regular_bkd_qiter.hh
===================================================================
--- oln/core/gen/regular_bkd_qiter.hh (revision 153)
+++ oln/core/gen/regular_bkd_qiter.hh (working copy)
@@ -34,21 +34,27 @@
namespace oln {
// bkd decl
- template <typename G>
- struct regular_bkd_qiter;
+ template <typename G, typename W> struct regular_bkd_qiter;
// category
- template <typename G>
- struct set_super_type< regular_bkd_qiter<G> > { typedef abstract::regular_qiter< G, regular_bkd_qiter<G> > ret; };
+ template <typename G, typename W>
+ struct set_super_type< regular_bkd_qiter<G,W> > { typedef abstract::regular_qiter< G, regular_bkd_qiter<G,W> > ret; };
+ // props
+ template <typename G, typename W>
+ struct set_props < category::qiter, regular_bkd_qiter<G,W> >
+ {
+ typedef W window_type;
+ };
- template <typename G>
- struct regular_bkd_qiter : public abstract::regular_qiter< G, regular_bkd_qiter<G> >
+
+ template <typename G, typename W>
+ struct regular_bkd_qiter : public abstract::regular_qiter< G, regular_bkd_qiter<G,W> >
{
- typedef regular_bkd_qiter<G> self_type;
+ typedef regular_bkd_qiter<G,W> self_type;
typedef abstract::regular_qiter<G, self_type> super_type;
- regular_bkd_qiter(const regular_window<G>& win) :
+ regular_bkd_qiter(const abstract::regular_window<G,W>& win) :
super_type(win)
{
this->invalidate();
Index: oln/core/gen/regular_qiter.hh
===================================================================
--- oln/core/gen/regular_qiter.hh (revision 153)
+++ oln/core/gen/regular_qiter.hh (working copy)
@@ -48,8 +48,7 @@
template <typename G, typename E>
struct set_props < category::qiter, abstract::regular_qiter<G,E> >
{
- typedef G grid_type;
- typedef regular_window<G> window_type;
+ typedef G grid_type;
};
@@ -68,8 +67,8 @@
typedef oln_grd_type_of(G, dimvalue) dimvalue_type;
static const unsigned dim = dimvalue_type::val;
- regular_qiter(const regular_window<G>& win) :
- super_type(win)
+ regular_qiter(const regular_window<G, oln_qit_type_of(E, window)>& win) :
+ super_type(win.exact())
{
}
Index: oln/core/gen/regular_window.hh
===================================================================
--- oln/core/gen/regular_window.hh (revision 153)
+++ oln/core/gen/regular_window.hh (working copy)
@@ -43,124 +43,133 @@
namespace oln {
// fwd decls
- template <typename G> class regular_window;
- template <typename G> class regular_fwd_qiter;
+ template <typename G, typename W> class regular_fwd_qiter;
+ namespace abstract {
+ template <typename G, typename E> class regular_window;
+ }
// super_type
- template <typename G> struct set_super_type< regular_window<G> > { typedef abstract::window< regular_window<G> > ret; };
+ template <typename G, typename E> struct set_super_type< abstract::regular_window<G, E> > { typedef abstract::window<E> ret; };
// props
- template <typename G>
- struct set_props< category::window, regular_window<G> >
+ template <typename G, typename E>
+ struct set_props< category::window, abstract::regular_window<G, E> >
{
typedef G grid_type;
typedef oln_grd_type_of(G, dpoint) dpoint_type;
typedef oln_grd_type_of(G, size) size_type;
- typedef regular_fwd_qiter<G> fwd_iter_type;
-// typedef regular_fwd_dpiter<G> fwd_dpiter_type; // FIXME: later...
+ typedef regular_fwd_qiter<G,E> fwd_iter_type;
+ // typedef regular_fwd_dpiter<G> fwd_dpiter_type; // FIXME: later...
};
- template <typename G>
- class regular_window : public abstract::window< regular_window<G> >
+
+
+ namespace abstract
{
- public:
+ template <typename G, typename E>
+ class regular_window : public window<E>
+ {
+
+ public:
- typedef regular_window<G> self_type;
+ typedef regular_window<G, E> self_type;
- typedef oln_grd_type_of(G, coord) coord_type;
- typedef oln_grd_type_of(G, dpoint) dpoint_type;
- typedef oln_grd_type_of(G, dimvalue) dimvalue_type;
+ typedef oln_grd_type_of(G, coord) coord_type;
+ typedef oln_grd_type_of(G, dpoint) dpoint_type;
+ typedef oln_grd_type_of(G, dimvalue) dimvalue_type;
- static const unsigned dim = dimvalue_type::val;
+ static const unsigned dim = dimvalue_type::val;
- regular_window() :
- dp_(),
- delta_(0)
- {
- }
+ coord_type delta() const
+ {
+ return this->delta_;
+ }
- regular_window(unsigned n, const coord_type crd[]) :
- dp_(),
- delta_(0)
- {
- precondition(n != 0);
- // FIXME: size of crd wrt n
- for (unsigned i = 0; i < n; ++i)
- {
- dpoint_type dp;
- for (unsigned c = 0; c < dim; ++c)
- dp.nth(c) = crd[i * dim + c];
- this->add(dp);
- }
- }
+ unsigned card() const
+ {
+ return this->dp_.size();
+ }
- self_type& add(const dpoint_type& dp)
- {
- this->dpset_.insert(dp);
- this->dp_.clear();
- std::copy(this->dpset_.begin(), this->dpset_.end(),
- std::back_inserter(this->dp_));
- this->delta_update_(dp);
- return *this;
- }
+ const dpoint_type dp(unsigned i) const
+ {
+ precondition(i < this->card());
+ return this->dp_[i];
+ }
- coord_type delta() const
- {
- return this->delta_;
- }
+ const self_type operator-() const
+ {
+ self_type tmp;
+ for (unsigned i = 0; i < this->card(); ++i)
+ tmp.add_(- this->dp_[i]);
+ return tmp;
+ }
- unsigned card() const
- {
- return this->dp_.size();
- }
+ void sym()
+ {
+ *this = - *this;
+ }
- const dpoint_type dp(unsigned i) const
- {
- precondition(i < this->card());
- return this->dp_[i];
- }
+ const std::vector<dpoint_type>& get_dp() const
+ {
+ return this->dp_;
+ }
- const self_type operator-() const
- {
- self_type tmp;
- for (unsigned i = 0; i < this->card(); ++i)
- tmp.add(- this->dp_[i]);
- return tmp;
- }
+ protected:
- void sym()
- {
- *this = - *this;
- }
+ regular_window() :
+ dp_(),
+ delta_(0)
+ {
+ }
- const std::vector<dpoint_type>& get_dp() const
- {
- return this->dp_;
- }
+ regular_window(unsigned n, const coord_type crd[]) :
+ dp_(),
+ delta_(0)
+ {
+ precondition(n != 0);
+ // FIXME: size of crd wrt n
+ for (unsigned i = 0; i < n; ++i)
+ {
+ dpoint_type dp;
+ for (unsigned c = 0; c < dim; ++c)
+ dp.nth(c) = crd[i * dim + c];
+ this->add_(dp);
+ }
+ }
- private:
+ void add_(const dpoint_type& dp)
+ {
+ this->dpset_.insert(dp);
+ this->dp_.clear();
+ std::copy(this->dpset_.begin(), this->dpset_.end(),
+ std::back_inserter(this->dp_));
+ this->delta_update_(dp);
+ }
+
+ private:
- std::set<dpoint_type, fwd_less_dpoint> dpset_;
- std::vector<dpoint_type> dp_;
- coord_type delta_;
+ std::set<dpoint_type, fwd_less_dpoint> dpset_;
+ std::vector<dpoint_type> dp_;
+ coord_type delta_;
- void delta_update_(const dpoint_type& dp)
- {
- for (unsigned c = 0; c < dim; ++c)
- if (abs(dp.nth(c)) > this->delta_)
- this->delta_ = abs(dp.nth(c));
- }
+ void delta_update_(const dpoint_type& dp)
+ {
+ for (unsigned c = 0; c < dim; ++c)
+ if (abs(dp.nth(c)) > this->delta_)
+ this->delta_ = abs(dp.nth(c));
+ }
- };
+ };
+ } // end of namespace oln::abstract
} // end of namespace oln
-template<class G>
-std::ostream& operator<<(std::ostream& ostr, const oln::regular_window<G>& win)
+template<typename G, typename E>
+std::ostream& operator<<(std::ostream& ostr, const oln::abstract::regular_window<G, E>& win)
{
ostr << "[";
for (unsigned i = 0; i < win.card(); ++i)
Index: oln/core/gen/regular_neighborhood.hh
===================================================================
--- oln/core/gen/regular_neighborhood.hh (revision 153)
+++ oln/core/gen/regular_neighborhood.hh (working copy)
@@ -40,13 +40,27 @@
// super_type
template <typename G> struct set_super_type< regular_neighborhood<G> > { typedef abstract::neighborhood< regular_neighborhood<G> > ret; };
+
+ // FIXME: temporary code to get a window type from a grid type
+ struct grid1d; struct window1d;
+ struct grid2d; struct window2d;
+ struct grid3d; struct window3d;
+ namespace internal {
+ template <typename grid_type> struct to_window;
+ template <> struct to_window <grid1d> { typedef window1d ret; };
+ template <> struct to_window <grid2d> { typedef window2d ret; };
+ template <> struct to_window <grid3d> { typedef window3d ret; };
+ }
+ // FIXME: end of temporary code
+
+
// props
template <typename G>
struct set_props< category::neighborhood, regular_neighborhood<G> >
{
typedef oln_grd_type_of(G, dpoint) dpoint_type;
typedef oln_grd_type_of(G, size) size_type;
- typedef regular_window<G> window_type;
+ typedef typename internal::to_window<G>::ret window_type;
};
@@ -58,6 +72,7 @@
public:
typedef regular_neighborhood<G> self_type;
+ typedef oln_nbh_type_of(self_type, window) window_type;
typedef oln_grd_type_of(G, coord) coord_type;
typedef oln_grd_type_of(G, dpoint) dpoint_type;
@@ -69,7 +84,7 @@
{
}
- regular_neighborhood(const regular_window<G>& win)
+ regular_neighborhood(const window_type& win)
{
for (unsigned i = 0; i < win.card(); ++i)
this->add(win.dp(i));
@@ -117,7 +132,7 @@
return this->win_.get_dp();
}
- const regular_neighborhood<G>& get_win() const
+ const window_type& get_win() const
{
return this->win_;
}
@@ -125,7 +140,7 @@
private:
/// Only attribute (to delegate to).
- regular_window<G> win_;
+ window_type win_;
};
Index: oln/morpho/stat.hh
===================================================================
--- oln/morpho/stat.hh (revision 153)
+++ oln/morpho/stat.hh (working copy)
@@ -30,7 +30,7 @@
# include <mlc/cmp.hh>
# include <ntg/bin.hh>
-# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/images.hh>
# include <oln/core/abstract/window.hh>
@@ -38,160 +38,87 @@
namespace morpho {
- namespace internal {
- /*!
- ** \brief Min and Max on a window.
- **
- ** We need to use this inner definition in order to specialize
- ** max and min on binary images.
- **
- ** \param I Image exact type.
- ** \param W Window type.
- ** \param V Associated value type.
- */
- template <class I, class W, class V = oln_type_of(I, value)>
- struct stat_
- {
- /*!
- ** \brief Maximum of a window.
- **
- ** Look for the maximum in the window win disposed
- ** on the image input, at the point p.
- **
- ** \arg input Input image.
- ** \arg p Point of the image to move the window on.
- ** \arg win The window to use.
- */
- static V
- max(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ /// Local min on a function.
- oln_wn_type_of(W, fwd_iter) q(win);
- q.start_at_p(p);
- V val = input[q];
- for_all_remaining_q (q)
- if (input.hold(q))
- if (val < input[q].value())
- val = input[q].value();
- return val;
- }
+ template <typename I, typename W>
+ oln_type_of(I, value) min(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- /*!
- ** \brief Minimum of a window.
- **
- ** Look for the minimum in the window win disposed
- ** on the image input, at the point p.
- **
- ** \arg input Input image.
- ** \arg p Point of the image to move the window on.
- ** \arg win The window to use.
- */
- static V
- min(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ oln_wn_type_of(W, fwd_iter) q(win);
+ oln_type_of(I, value) val;
- oln_wn_type_of(W, fwd_iter) q(win);
- q.start_at(p);
- V val = input[q];
- for_all_remaining_q (q)
- if (input.hold(q))
- if (val > input[q].value())
- val = input[q].value();
- return val;
- }
+ q.start_at_p(p);
+ val = input[q];
+
+ for_all_remaining_q (q)
+ if (input.hold(q) and input[q].value() < val)
+ val = input[q].value();
- };
+ return val;
+ }
- /* Binary specialization. */
- template <class I, class W>
- struct stat_<I, W, ntg::bin>
- {
- static ntg::bin
- max(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- oln_wn_type_of(W, fwd_iter) q(win);
- for_all_q_of_p (q, p)
- if (input.hold(q))
- if (input[q] == true)
- return true;
- return false;
- }
+ /// Local min on a set.
- static ntg::bin
- min(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- oln_wn_type_of(W, fwd_iter) q(win);
- for_all_q_of_p (q, p)
- if (input.hold(q))
- if (input[q] == false)
- return false;
- return true;
- }
+ template <typename I, typename W>
+ bool min(const abstract::binary_image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
+ {
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- };
+ oln_wn_type_of(W, fwd_iter) q(win);
+ for_all_q_of_p (q, p)
+ if (input.hold(q) and not input[q])
+ return false;
+ return true;
+ }
- } // internal
- /*!
- ** \brief Maximum of a window.
- **
- ** Look for the maximum in the window win disposed
- ** on the image input, at the point p.
- **
- ** \param I Image exact type.
- ** \param W Window type.
- **
- ** \arg input Input image.
- ** \arg p Point of the image to move the window on.
- ** \arg win The window to use.
- */
- template<class I, class W>
- oln_type_of(I, value)
- max(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
+ /// Local max on a function.
+
+ template <typename I, typename W>
+ oln_type_of(I, value) max(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
{
- // FIXME: test dim I == dim W
- return internal::stat_<I, W>::max(input.exact(), p, win.exact());
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ oln_wn_type_of(W, fwd_iter) q(win);
+ oln_type_of(I, value) val;
+
+ q.start_at_p(p);
+ val = input[q];
+
+ for_all_remaining_q (q)
+ if (input.hold(q) and input[q].value() > val)
+ val = input[q].value();
+
+ return val;
}
- /*! ** \brief Minimum of a window.
- **
- ** Look for the minimum in the window win disposed
- ** on the image input, at the point p.
- **
- ** \param I Image exact type.
- ** \param W Window type.
- **
- ** \arg input Input image.
- ** \arg p Point of the image to move the window on.
- ** \arg win The window to use.
- */
- template<class I, class W>
- oln_type_of(I, value)
- min(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- // const mlc_exact_type(I)::iter_type& p,
- const abstract::window<W>& win)
+
+ /// Local max on a set.
+
+ template <typename I, typename W>
+ bool max(const abstract::binary_image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
{
- // FIXME: test dim I == dim W
- return internal::stat_<I, W>::min(input.exact(), p, win.exact());
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+
+ oln_wn_type_of(W, fwd_iter) q(win);
+ for_all_q_of_p (q, p)
+ if (input.hold(q) and input[q])
+ return true;
+ return false;
}
+
} // end of namespace morpho
} // end of namespace oln
Index: oln/morpho/erosion.hh
===================================================================
--- oln/morpho/erosion.hh (revision 153)
+++ oln/morpho/erosion.hh (working copy)
@@ -30,23 +30,50 @@
# include <mlc/cmp.hh>
+# include <oln/core/abstract/images.hh>
# include <oln/core/abstract/image_operator.hh>
# include <oln/morpho/stat.hh>
+# include <oln/core/2d/window2d.hh>
+
namespace oln {
+
+ // fwd decl
+
namespace morpho {
+ template <typename I> struct erosion_ret;
+ }
+ // super_type
+ template <typename I>
+ struct set_super_type< morpho::erosion_ret<I> >
+ {
+ typedef oln_type_of(I, concrete) output_type;
+
+ typedef morpho::erosion_ret<I> self_type;
+ typedef abstract::image_unary_operator<output_type, I, self_type > ret;
+ };
+
+
+
+
+ namespace morpho {
+
+
+
+ // Erosion as a 'classical' procedure returning an image (do not
+ // use it; prefer morpho::erosion).
+
namespace proc {
- /// Erosion as a procedure (do not use it; prefer morpho::erosion).
-
template<typename I, typename W>
oln_type_of(I, concrete) erosion(const abstract::image<I>& input,
const abstract::window<W>& win)
{
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
oln_type_of(I, concrete) output(input.size());
oln_type_of(I, fwd_piter) p(input.size());
for_all_p (p)
@@ -58,136 +85,127 @@
- /*!
- ** \brief Perform a morphological erosion.
- **
- ** Compute the morphological erosion of input using win
- ** as structuring element.
- **
- ** On grey-scale images, each point is replaced by the minimum
- ** value of its neighbors, as indicated by win. On binary
- ** images, a logical and is performed between neighbors. The
- ** morpho::fast version of this function use a different
- ** algorithm: an histogram of the value of the neighborhood
- ** indicated by win is updated while iterating over all point of
- ** the image. Doing so is more efficient when the structuring
- ** element is large.
- **
- ** \param I Exact type of the input image.
- ** \param W Exact type of the structuring element.
- **
- **
- ** \arg input Input image.
- ** \arg win Structuring element to use.
- **
- ** \code
- ** #include <oln/basics2d.hh>
- ** #include <oln/morpho/erosion.hh>
- ** #include <oln/level/compare.hh>
- ** #include <ntg/all.hh>
- ** int main()
- ** {
- ** typedef oln::image2d<ntg::bin> im_type;
- **
- ** im_type im1(oln::load(IMG_IN "object.pbm"));
- ** save(oln::morpho::erosion(im1, oln::win_c8p()),
- ** IMG_OUT "oln_morpho_erosion.pbm");
- ** }
- ** \endcode
- **
- ** \image html object_pbm.png
- ** \image latex object_pbm.png
- ** =>
- ** \image html oln_morpho_erosion.png
- ** \image latex oln_morpho_erosion.png
- **
- ** \see oln::morpho::fast::erosion()
- */
+ /// Erosion return type.
- // fwd decl
- template <typename I, typename W> struct erosion_ret;
-
- }
-
- // super_type
- template <typename I, typename W>
- struct set_super_type< morpho::erosion_ret<I,W> >
- {
- typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, morpho::erosion_ret<I,W> > ret;
- };
-
-
-
-
- namespace morpho {
-
- /// Erosion return.
-
- template <typename I, typename W>
- struct erosion_ret : public abstract::image_unary_operator<oln_type_of(I, concrete), I, erosion_ret<I,W> >
+ template <typename I>
+ struct erosion_ret : public oln_super_of_(erosion_ret<I>)
{
- typedef abstract::image_unary_operator<oln_type_of(I, concrete), I, erosion_ret<I,W> > super_type;
- typedef typename super_type::output_type output_type;
+ typedef oln_super_of(erosion_ret<I>) super_type;
- const W win;
-
- erosion_ret(const abstract::image<I>& input,
- const abstract::window<W>& win) :
- super_type(input),
- win(win.exact())
+ erosion_ret(const abstract::image<I>& input) :
+ super_type(input)
{
}
};
+ // Various implementation.
+
namespace impl {
- /// Erosion generic implementation.
+ /// Generic implementation of erosion (type).
+
template <typename I, typename W>
- struct generic_erosion : public erosion_ret<I,W>
+ struct generic_erosion : public erosion_ret<I>
{
- typedef erosion_ret<I,W> super_type;
- typedef typename super_type::output_type output_type;
+ typedef erosion_ret<I> super_type;
+ const W& win;
+
generic_erosion(const abstract::image<I>& input,
const abstract::window<W>& win) :
- super_type(input, win)
+ super_type(input),
+ win(win.exact())
{
}
void impl_run()
{
- mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure();
+ oln_type_of(super_type, output) tmp(input.size()); // FIXME: trick
+ output = tmp;
- output_type tmp(this->input.size()); // FIXME: trick
- this->output = tmp;
-
- oln_type_of(I, fwd_piter) p(this->input.size());
+ oln_type_of(I, fwd_piter) p(input.size());
for_all_p (p)
- this->output[p] = morpho::min(this->input, p, this->win);
+ output[p] = morpho::min(input, p, win);
}
};
+ // Generic implementation of erosion (routine).
+
+ template<typename I, typename W>
+ erosion_ret<I> erosion(const abstract::image<I>& input,
+ const abstract::window<W>& win)
+ {
+ impl::generic_erosion<I,W> tmp(input, win);
+ tmp.run();
+ return tmp;
+ }
+
+
+
+
+ /// Rectangle2d implementation of erosion (type).
+
+ template <typename I>
+ struct rectangle2d_erosion : public erosion_ret<I>
+ {
+ typedef erosion_ret<I> super_type;
+
+ const win_rectangle2d& win;
+
+ rectangle2d_erosion(const abstract::image<I>& input,
+ const win_rectangle2d& win) :
+ super_type(input),
+ win(win)
+ {}
+
+ void impl_run()
+ {
+ oln_type_of(super_type, output) temp(input.size()); // FIXME: trick
+
+ win_rectangle2d hline(1, win.width);
+ win_rectangle2d vline(win.height, 1);
+
+ temp = morpho::erosion(input, hline);
+ output = morpho::erosion(temp, vline);
+ }
+ };
+
+ // Rectangle2d implementation of erosion (routine).
+
+ template<typename I>
+ erosion_ret<I> erosion(const abstract::image<I>& input,
+ const win_rectangle2d& win)
+ {
+ impl::rectangle2d_erosion<I> tmp(input, win);
+ tmp.run();
+ return tmp;
+ }
+
+
+
+
} // end of namespace oln::morpho::impl
- /// Erosion generic routine.
+ /// Generic erosion (facade).
+
template<typename I, typename W>
- erosion_ret<I,W> erosion(const abstract::image<I>& input,
- const abstract::window<W>& win)
+ erosion_ret<I> erosion(const abstract::image<I>& input,
+ const abstract::window<W>& win)
{
- impl::generic_erosion<I,W> tmp(input, win);
- tmp.run();
- return tmp;
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ return impl::erosion(input.exact(), win.exact());
}
} // end of namespace oln::morpho
+
} // end of namespace oln
1
0
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 22 +++++++++
oln/core/abstract/size.hh | 3 -
oln/core/any/dpoint.hh | 6 +-
oln/core/any/grid.hh | 3 -
oln/core/any/point.hh | 28 ++++++++++--
oln/core/pw/abstract/binary_function.hh | 8 +++
oln/core/pw/apply.hh | 74 ++++++++++++++++++++++++++++++--
oln/makefile.src | 3 -
tests/pw/tests/apply-binary | 20 ++++++++
9 files changed, 152 insertions(+), 15 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add binary apply on point-wise functions.
* oln/core/pw/apply.hh (apply2): New class.
(p_apply): New helper for binary point-wise apply.
* tests/pw/tests/apply-binary: New test.
* oln/core/abstract/size.hh (oln_size_type_from_2): Adjust macro
to new Metalic logic system.
* oln/core/pw/abstract/binary_function.hh
(binary_function_helper < any_size, any_size >): New
specialization.
* oln/core/any/point.hh (impl_plus, impl_minus, impl_nth):
Implement (as dummies).
* oln/core/any/grid.hh (any_coord): Define this type.
* oln/core/any/dpoint.hh: Aesthetic changes.
* oln/makefile.src (OLN_DEP): Remove
core/abstract/regular_niter.hh, core/3d/fwd_niter3d.hh and
core/3d/fwd_qiter3d.hh.
2005-04-14 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/pw/tests/apply-binary
--- olena/tests/pw/tests/apply-binary (revision 0)
+++ olena/tests/pw/tests/apply-binary (revision 0)
@@ -0,0 +1,20 @@
+ // -*- C++ -*-
+#include <iostream>
+
+#include <cmath>
+#include <oln/core/pw/apply.hh>
+#include <oln/core/pw/literal.hh>
+#include <oln/core/any/point.hh>
+
+using namespace oln;
+
+bool check()
+{
+ any_point p;
+
+ pw::literal<int> pv1 (p_lit(1));
+ pw::literal<int> pv2 (p_lit(2));
+
+ int res = p_apply(mlc::make_binary_fun(std::plus<int>()), pv1, pv2)(p);
+ return not (res == 3);
+}
Index: olena/oln/core/abstract/size.hh
--- olena/oln/core/abstract/size.hh (revision 151)
+++ olena/oln/core/abstract/size.hh (working copy)
@@ -41,7 +41,8 @@
-# define oln_size_type_from_2(S1, S2) typename mlc::if_< typename mlc::eq< S2, oln::any_size >::ret, S1, S2 >::ret
+# define oln_size_type_from_2(S1, S2) \
+typename mlc::if_< mlc::eq< S2, oln::any_size >, S1, S2 >::ret
Index: olena/oln/core/pw/abstract/binary_function.hh
--- olena/oln/core/pw/abstract/binary_function.hh (revision 151)
+++ olena/oln/core/pw/abstract/binary_function.hh (working copy)
@@ -100,6 +100,14 @@
}
};
+ template <>
+ struct binary_function_helper < any_size, any_size > {
+ template <typename L, typename R>
+ static const L& select(const L& l, R) {
+ return l;
+ }
+ };
+
} // end of namespace oln::pw::abstract::internal
Index: olena/oln/core/pw/apply.hh
--- olena/oln/core/pw/apply.hh (revision 151)
+++ olena/oln/core/pw/apply.hh (working copy)
@@ -30,6 +30,7 @@
# include <mlc/fun.hh>
# include <oln/core/pw/abstract/function.hh>
+# include <oln/core/pw/abstract/binary_function.hh>
# include <oln/core/pw/macros.hh>
@@ -41,8 +42,7 @@
// fwd decl
namespace pw {
- template <typename F, typename T>
- struct apply;
+ template <typename F, typename T> struct apply;
}
// super type
@@ -110,18 +110,86 @@
} // end of namespace oln::pw
+
+ /*---------.
+ | Binary. |
+ `---------*/
+
+ // fwd decl
+ namespace pw {
+ template <typename F, typename T1, typename T2> struct apply2;
+ }
+
+ // super type
+ template <typename F, typename T1, typename T2>
+ struct set_super_type < pw::apply2<F, T1, T2> >
+ {
+ typedef pw::abstract::binary_function<T1, T2, pw::apply2<F, T1, T2> > ret;
+ };
+
+ // props
+ template <typename F, typename T1, typename T2>
+ struct set_props < category::pw, pw::apply2<F, T1, T2> >
+ {
+ typedef typename F::result_type value_type;
+ };
+
+ namespace pw {
+
+ template <typename F, typename T1, typename T2>
+ struct apply2 :
+ public abstract::binary_function <T1, T2, apply2<F, T1, T2> >
+ {
+ typedef apply2<F, T1, T2> self_type;
+
+ typedef oln_pw_type_of(self_type, point) point_type;
+ typedef oln_pw_type_of(self_type, value) value_type;
+ typedef oln_pw_type_of(self_type, size) size_type;
+
+ typedef
+ abstract::binary_function <T1, T2, apply2<F, T1, T2> > super_type;
+
+ F f_;
+
+ apply2(const mlc::abstract::binary_function<F>& f,
+ const abstract::function<T1>& left,
+ const abstract::function<T2>& right) :
+ super_type(left, right),
+ f_(f.exact())
+ {
+ }
+
+ const value_type impl_get(const point_type& p) const
+ {
+ return f_(this->left(p), this->right(p));
+ }
+ };
+
+ } // end of namespace oln::pw
+
} // end of namespace oln
/// apply function on pwf
template <typename F, typename T>
-oln::pw::apply<F, T> p_apply (const mlc::abstract::unary_function<F>& f,
+oln::pw::apply<F, T>
+p_apply (const mlc::abstract::unary_function<F>& f,
const oln::pw::abstract::function<T>& x)
{
oln::pw::apply<F, T> tmp(f, x);
return tmp;
}
+template <typename F, typename T1, typename T2>
+oln::pw::apply2<F, T1, T2>
+p_apply (const mlc::abstract::binary_function<F>& f,
+ const oln::pw::abstract::function<T1>& x,
+ const oln::pw::abstract::function<T2>& y)
+{
+ oln::pw::apply2<F, T1, T2> tmp(f, x, y);
+ return tmp;
+}
+
#endif // ! OLENA_CORE_PW_APPLY_HH
Index: olena/oln/core/any/grid.hh
--- olena/oln/core/any/grid.hh (revision 151)
+++ olena/oln/core/any/grid.hh (working copy)
@@ -39,7 +39,8 @@
struct any_point;
struct any_dpoint;
struct any_size;
- struct any_coord;
+ // Dummy coord type.
+ struct any_coord {};
// super type
template <>
Index: olena/oln/core/any/point.hh
--- olena/oln/core/any/point.hh (revision 151)
+++ olena/oln/core/any/point.hh (working copy)
@@ -63,7 +63,7 @@
bool impl_fwd_less(const any_point& rhs) const
{
- precondition(0);
+ precondition(false);
return false;
}
@@ -72,7 +72,11 @@
return this->exact().impl_eq(rhs.exact());
}
- const any_point impl_plus(const any_dpoint& rhs) const;
+ const any_point impl_plus(const any_dpoint& rhs) const
+ {
+ precondition(false);
+ return any_point();
+ }
template <typename D>
const any_point impl_plus(const abstract::dpoint<D>& rhs) const
@@ -85,9 +89,18 @@
template <typename P>
const any_dpoint impl_minus(const abstract::point<P>& rhs) const;
- const any_coord impl_nth(unsigned i) const;
+ const any_coord impl_nth(unsigned i) const
+ {
+ precondition(false);
+ return any_coord();
+ }
- any_coord& impl_nth(unsigned i);
+ any_coord& impl_nth(unsigned i)
+ {
+ static any_coord dummy = any_coord();
+ precondition(false);
+ return dummy;
+ }
};
@@ -116,9 +129,16 @@
namespace oln {
+ const any_dpoint any_point::impl_minus(const any_point& rhs) const
+ {
+ precondition(false);
+ return any_dpoint();
+ }
+
template <typename P>
const any_dpoint any_point::impl_minus(const abstract::point<P>& rhs) const
{
+ precondition(false);
return any_dpoint();
}
Index: olena/oln/core/any/dpoint.hh
--- olena/oln/core/any/dpoint.hh (revision 151)
+++ olena/oln/core/any/dpoint.hh (working copy)
@@ -69,7 +69,7 @@
bool impl_fwd_less(const any_dpoint& rhs) const
{
- precondition(0);
+ precondition(false);
return false;
}
@@ -80,14 +80,14 @@
const coord_t impl_nth(unsigned i) const
{
- precondition(0);
+ precondition(false);
return 0;
}
coord_t& impl_nth(unsigned i)
{
static coord_t dummy = coord_t();
- precondition(0);
+ precondition(false);
return dummy;
}
Index: olena/oln/makefile.src
--- olena/oln/makefile.src (revision 151)
+++ olena/oln/makefile.src (working copy)
@@ -47,9 +47,7 @@
core/3d/array3d.hh \
core/3d/bkd_piter3d.hh \
core/3d/dpoint3d.hh \
- core/3d/fwd_niter3d.hh \
core/3d/fwd_piter3d.hh \
- core/3d/fwd_qiter3d.hh \
core/3d/image3d.hh \
core/3d/neighborhood3d.hh \
core/3d/niter3d.hh \
@@ -80,7 +78,6 @@
core/abstract/piter.hh \
core/abstract/point.hh \
core/abstract/qiter.hh \
- core/abstract/regular_niter.hh \
core/abstract/size.hh \
core/abstract/window.hh \
\
1
0
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 8 ++++++++
tests/core/tests/readwrite_image | 4 ++++
tests/core/tests/setget | 11 +++++++++--
3 files changed, 21 insertions(+), 2 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Fix remaining tests in tests/core.
* tests/core/tests/readwrite_image, tests/core/tests/setget
(set_props <category::image, dummy_image>): Add missing
properties.
2005-04-14 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/core/tests/readwrite_image
--- olena/tests/core/tests/readwrite_image (revision 151)
+++ olena/tests/core/tests/readwrite_image (working copy)
@@ -29,6 +29,10 @@
typedef point2d point_type;
typedef ntg::int_u8 value_type;
+ typedef fwd_piter2d piter_type;
+ typedef fwd_piter2d fwd_piter_type;
+ typedef bkd_piter2d bkd_piter_type;
+
typedef value_type value_storage_type;
typedef array2d<value_storage_type> storage_type;
};
Index: olena/tests/core/tests/setget
--- olena/tests/core/tests/setget (revision 151)
+++ olena/tests/core/tests/setget (working copy)
@@ -1,4 +1,4 @@
-
+ // -*- C++ -*-
#include <oln/basics.hh>
@@ -13,12 +13,19 @@
};
template <>
- struct set_props < category::image, dummy_image > : public props_of <category::image>
+ struct set_props < category::image, dummy_image >
{
+ typedef int concrete_type;
+ typedef int image_dimension_type;
+
typedef int size_type;
typedef int point_type;
typedef int value_type;
typedef mlc::no_type delegated_type;
+
+ typedef fwd_piter2d piter_type;
+ typedef fwd_piter2d fwd_piter_type;
+ typedef bkd_piter2d bkd_piter_type;
};
struct dummy_image : public abstract::readwrite_image< dummy_image >
1
0
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 9 +++++++
tests/core/tests/image_valuedness | 41 +++++++++++++++++++++++++++--------
tests/core/tests/image_vectorialness | 26 ----------------------
3 files changed, 41 insertions(+), 35 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Fix core/image_valuedness test.
* tests/core/tests/image_vectorialness: Rename file as...
* tests/core/tests/image_valuedness: ...this.
Catch up with the new oln/abstract/image_valuedness.hh, and
augment the test case.
2005-04-14 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/core/tests/image_vectorialness
--- olena/tests/core/tests/image_vectorialness (revision 150)
+++ olena/tests/core/tests/image_vectorialness (working copy)
@@ -1,26 +0,0 @@
-
-#include <iostream>
-
-#include <ntg/all.hh>
-#include <oln/basics2d.hh>
-
-#include <oln/fancy/iota.hh>
-#include <oln/fancy/print.hh>
-
-#include "check.hh"
-#include "data.hh"
-
-
-
-template <typename I>
-void foo_i(const oln::abstract::integer_image<I>& input)
-{}
-
-
-bool check()
-{
- // it lacks test for decimal, vectorial, ... images.
- oln::image2d<ntg::int_u8> ima_i;
- foo_i(ima_i);
- return false;
-}
Index: olena/tests/core/tests/image_valuedness
--- olena/tests/core/tests/image_valuedness (revision 149)
+++ olena/tests/core/tests/image_valuedness (working copy)
@@ -1,26 +1,49 @@
+ // -*- C++ -*-
+#include <string>
-#include <iostream>
-
-#include <ntg/all.hh>
+#include <ntg/bin.hh>
+#include <ntg/int.hh>
+#include <ntg/cplx.hh>
#include <oln/basics2d.hh>
-#include <oln/fancy/iota.hh>
-#include <oln/fancy/print.hh>
-
#include "check.hh"
#include "data.hh"
+template <typename I>
+void foo_scalar(const oln::abstract::scalar_valued_image<I>& input)
+{}
+
+template <typename I>
+void foo_vector(const oln::abstract::vector_valued_image<I>& input)
+{}
+
+template <typename I>
+void foo_label(const oln::abstract::label_valued_image<I>& input)
+{}
template <typename I>
-void foo_i(const oln::abstract::integer_image<I>& input)
+void foo_data(const oln::abstract::data_valued_image<I>& input)
{}
bool check()
{
- // it lacks test for decimal, vectorial, ... images.
+ // Scalar.
oln::image2d<ntg::int_u8> ima_i;
- foo_i(ima_i);
+ foo_scalar(ima_i);
+
+ // Vector.
+ oln::image2d<ntg::cplx<ntg::rect, float> > ima_v;
+ foo_vector(ima_v);
+
+ // Label.
+ oln::image2d<ntg::bin> ima_l;
+ foo_label(ima_l);
+
+ // Other data.
+ oln::image2d<std::string> ima_d;
+ foo_data(ima_d);
+
return false;
}
1
0
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 14 ++++++++++++++
oln/core/abstract/qiter.hh | 2 +-
oln/core/gen/regular_fwd_qiter.hh | 5 +++--
oln/core/gen/regular_qiter.hh | 2 ++
tests/core/tests/fwd_qiter2d | 11 ++++-------
tests/core/tests/fwd_witer2d | 26 --------------------------
6 files changed, 24 insertions(+), 36 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Fix core/fwd_qiter2d test.
* tests/core/tests/fwd_witer2d: Rename file as...
* tests/core/tests/fwd_qiter2d: ...this.
Adjust to the new interface of q-iterators.
* oln/core/gen/regular_fwd_qiter.hh (abstract::qiter<self_type>):
Make it a friend.
(impl_invalidate): Explicitely cast to avoid comparisons between
signed and unsigned values.
* oln/core/gen/regular_qiter.hh (abstract::qiter<E>): Make it a
friend.
2005-04-14 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/core/tests/fwd_witer2d
--- olena/tests/core/tests/fwd_witer2d (revision 149)
+++ olena/tests/core/tests/fwd_witer2d (working copy)
@@ -1,26 +0,0 @@
- // -*- C++ -*-
-#include <oln/core/2d/fwd_witer2d.hh>
-#include <oln/core/abstract/piter.hh>
-
-#include <ntg/all.hh>
-
-#include <cassert>
-
-using namespace oln;
-using namespace ntg;
-
-template <typename E>
-bool foo(const E& w)
-{
- oln_type_of(E, fwd_witer) i(w);
- unsigned cpt = 0;
- for_all(i)
- ++cpt;
- return not (cpt == w.card());
-}
-
-int main()
-{
- window2d w = win_c8p();
- return foo(w);
-}
Index: olena/tests/core/tests/fwd_qiter2d
--- olena/tests/core/tests/fwd_qiter2d (revision 147)
+++ olena/tests/core/tests/fwd_qiter2d (working copy)
@@ -1,20 +1,17 @@
// -*- C++ -*-
-#include <oln/core/2d/fwd_witer2d.hh>
-#include <oln/core/abstract/piter.hh>
-
-#include <ntg/all.hh>
+#include <oln/core/2d/window2d.hh>
#include <cassert>
using namespace oln;
-using namespace ntg;
template <typename E>
bool foo(const E& w)
{
- oln_type_of(E, fwd_witer) i(w);
+ oln_wn_type_of(E, fwd_iter) q(w);
unsigned cpt = 0;
- for_all(i)
+ point2d p;
+ for_all_q_of_p(q, p)
++cpt;
return not (cpt == w.card());
}
Index: olena/oln/core/abstract/qiter.hh
--- olena/oln/core/abstract/qiter.hh (revision 149)
+++ olena/oln/core/abstract/qiter.hh (working copy)
@@ -35,7 +35,7 @@
# define for_all_q_of_p(q, p) \
- for(q.ensure_is_qiter(), q.center_at(p), q.start(); q.is_valid(); q.next())
+ for(q.ensure_is_qiter(), q.start_at_p(p); q.is_valid(); q.next())
# define for_all_remaining_q( q ) \
for(q.ensure_is_piter(); q.is_valid(); q.next())
Index: olena/oln/core/gen/regular_fwd_qiter.hh
--- olena/oln/core/gen/regular_fwd_qiter.hh (revision 149)
+++ olena/oln/core/gen/regular_fwd_qiter.hh (working copy)
@@ -54,6 +54,7 @@
}
friend class abstract::iter<self_type>;
+ friend class abstract::qiter<self_type>;
protected:
@@ -69,12 +70,12 @@
bool impl_is_valid() const
{
- return this->pos_ != this->win_.card();
+ return this->pos_ != int(this->win_.card());
}
void impl_invalidate()
{
- this->pos_ = this->win_.card();
+ this->pos_ = int(this->win_.card());
}
};
Index: olena/oln/core/gen/regular_qiter.hh
--- olena/oln/core/gen/regular_qiter.hh (revision 149)
+++ olena/oln/core/gen/regular_qiter.hh (working copy)
@@ -80,6 +80,8 @@
return point_type(*this).nth(i);
}
+ friend class abstract::qiter<E>;
+
protected:
int pos_;
1
0
14 Apr '05
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 37 +++++++++++++++
oln/core/1d/array1d.hh | 52 +++++++++++++++++++---
oln/core/1d/image1d.hh | 2
oln/core/2d/array2d.hh | 3 -
oln/core/3d/array3d.hh | 91 ++++++++++++++++++++++++++++++---------
oln/core/3d/image3d.hh | 2
tests/core/tests/fwd_witer2d | 1
tests/core/tests/piter1d | 21 +++++++--
tests/core/tests/piter2d | 6 +-
tests/core/tests/piter3d | 21 +++++++--
tests/core/tests/readwrite_image | 5 --
11 files changed, 198 insertions(+), 43 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Fix some 1D and 3D classes and have more tests pass.
* oln/basics1d.hh (oln/core/1d/fwd_piter1d.hh)
(oln/core/1d/bkd_piter1d.hh): Include them.
* oln/core/1d/image1d.hh (bkd_piter_type) New typedef.
* oln/core/1d/array1d.hh: Do not set exact_ptr, since this class
not longer inherits from mlc::any__best_speed, but from mlc::any.
* oln/core/1d/array1d.hh (alloc_and_init): New function.
(resize, impl_clear_data): Handle the border.
(size): Rename method as...
(impl_size): ...this.
(~array1d): Call clear_data() instead of impl_clear_data().
(impl_resize_border): New method.
* oln/core/2d/array2d.hh (alloc_and_init): Remove useless
assignment.
(~array2d): Call clear_data() instead of impl_clear_data().
* oln/basics3d.hh (oln/core/3d/fwd_piter3d.hh)
* oln/core/3d/image3d.hh (bkd_piter_type) New typedef.
* oln/core/3d/array3d.hh: Do not set exact_ptr, since this class
(oln/core/3d/bkd_piter3d.hh): Include them.
not longer inherits from mlc::any__best_speed, but from mlc::any.
(size): Rename method as...
(impl_size): ...this.
(~array3d): Call clear_data() instead of impl_clear_data().
(impl_resize): Move allocation code...
(alloc_and_init): ...here (new function).
(impl_resize_border): New method.
* tests/core/tests/readwrite_image: Catch up with the new property
system.
* tests/core/tests/piter1d (check): Test bkd_piter1d too.
* tests/core/tests/piter3d (check): Test bkd_piter3d too.
Index: olena/tests/core/tests/fwd_witer2d
--- olena/tests/core/tests/fwd_witer2d (revision 147)
+++ olena/tests/core/tests/fwd_witer2d (working copy)
@@ -1,3 +1,4 @@
+ // -*- C++ -*-
#include <oln/core/2d/fwd_witer2d.hh>
#include <oln/core/abstract/piter.hh>
Index: olena/tests/core/tests/readwrite_image
--- olena/tests/core/tests/readwrite_image (revision 147)
+++ olena/tests/core/tests/readwrite_image (working copy)
@@ -1,3 +1,4 @@
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -19,12 +20,10 @@
};
template <>
- struct set_props <category::image, dummy_image> :
- public props_of < category::image >
+ struct set_props <category::image, dummy_image>
{
typedef is_a<abstract::readwrite_image> image_constness;
typedef is_a<abstract::image2d> image_dimension_type;
- typedef vectorialness_from_valuetype_(ntg::int_u8) image_vectorialness_type;
typedef size2d size_type;
typedef point2d point_type;
Index: olena/tests/core/tests/piter1d
--- olena/tests/core/tests/piter1d (revision 147)
+++ olena/tests/core/tests/piter1d (working copy)
@@ -1,4 +1,4 @@
-
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -15,15 +15,28 @@
oln::image1d<int> ima(10);
int cpt = 0;
- oln::fwd_piter1d it(ima.size());
- for_all (it)
+ oln::fwd_piter1d fwd_it(ima.size());
+ for_all_p (fwd_it)
+ {
+ ima[fwd_it] = 0;
+ cpt++;
+ }
+
+ if (cpt != 10)
+ return true;
+
+
+ cpt = 0;
+ oln::bkd_piter1d bkd_it(ima.size());
+ for_all_p (bkd_it)
{
- ima[it] = 0;
+ ima[bkd_it] = 0;
cpt++;
}
if (cpt != 10)
return true;
+
return false;
}
Index: olena/tests/core/tests/piter2d
--- olena/tests/core/tests/piter2d (revision 147)
+++ olena/tests/core/tests/piter2d (working copy)
@@ -1,4 +1,4 @@
-
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -16,7 +16,7 @@
int cpt = 0;
oln::fwd_piter2d fwd_it(ima.size());
- for_all (fwd_it)
+ for_all_p (fwd_it)
{
ima[fwd_it] = 0;
cpt++;
@@ -28,7 +28,7 @@
cpt = 0;
oln::bkd_piter2d bkd_it(ima.size());
- for_all (bkd_it)
+ for_all_p (bkd_it)
{
ima[bkd_it] = 0;
cpt++;
Index: olena/tests/core/tests/piter3d
--- olena/tests/core/tests/piter3d (revision 147)
+++ olena/tests/core/tests/piter3d (working copy)
@@ -1,4 +1,4 @@
-
+ // -*- C++ -*-
#include <iostream>
#include <ntg/all.hh>
@@ -15,15 +15,28 @@
oln::image3d<int> ima(10, 10, 10);
int cpt = 0;
- oln::fwd_piter3d it(ima.size());
- for_all (it)
+ oln::fwd_piter3d fwd_it(ima.size());
+ for_all_p (fwd_it)
+ {
+ ima[fwd_it] = 0;
+ cpt++;
+ }
+
+ if (cpt != 1000)
+ return true;
+
+
+ cpt = 0;
+ oln::bkd_piter3d bkd_it(ima.size());
+ for_all_p (bkd_it)
{
- ima[it] = 0;
+ ima[bkd_it] = 0;
cpt++;
}
if (cpt != 1000)
return true;
+
return false;
}
Index: olena/oln/core/1d/array1d.hh
--- olena/oln/core/1d/array1d.hh (revision 147)
+++ olena/oln/core/1d/array1d.hh (working copy)
@@ -52,6 +52,14 @@
};
+ template<class T>
+ void alloc_and_init(T*& buffer, const size1d& s)
+ {
+ size_t nelts_eff = s.nindices() + 2 * s.border();
+ buffer = new T[nelts_eff];
+ buffer += s.border();
+ }
+
template <typename T>
class array1d : public abstract::data_storage< array1d<T> >
@@ -63,7 +71,6 @@
buffer_(0),
size_()
{
- this->exact_ptr = this;
invariant_();
}
@@ -76,13 +83,12 @@
buffer_(0),
size_()
{
- this->exact_ptr = this;
this->resize(s);
}
~array1d()
{
- this->impl_clear_data();
+ this->clear_data();
}
bool impl_has_data() const
@@ -97,6 +103,7 @@
if (this->has_data())
{
// buffer
+ buffer_ -= size_.border();
delete[] buffer_;
buffer_ = 0;
// size
@@ -105,7 +112,7 @@
invariant_();
}
- const size1d& size() const
+ const size1d& impl_size() const
{
return size_;
}
@@ -117,8 +124,41 @@
invariant_();
this->clear_data();
size_ = s;
- size_t nelts_eff = size_.nindices() + 2 * size_.border();
- buffer_ = new T[nelts_eff];
+
+ alloc_and_init(buffer_, s);
+ invariant_();
+ }
+
+ void impl_resize_border(size_t new_border, bool copy_border)
+ {
+ invariant_();
+ T* new_buffer_;
+ size1d new_size_(this->size_.nindices(), new_border);
+
+ alloc_and_init(new_buffer_, new_size_);
+
+ if (buffer_ != 0)
+ {
+ size_t border = this->size_.border();
+
+ if (border > new_border)
+ border = new_border;
+
+ coord_t indice_min = copy_border ? -border : 0;
+ coord_t indice_max = int(this->size_.nindices())
+ + (copy_border ? border : 0);
+ size_t nindices = int(this->size_.nindices()) +
+ (copy_border ? (border * 2) : 0);
+
+ memcpy(new_buffer_ + indice_min, this->buffer_ + indice_min,
+ nindices * sizeof (T));
+
+ this->clear_data();
+ }
+
+ buffer_ = new_buffer_;
+ size_ = new_size_;
+
invariant_();
}
Index: olena/oln/core/1d/image1d.hh
--- olena/oln/core/1d/image1d.hh (revision 147)
+++ olena/oln/core/1d/image1d.hh (working copy)
@@ -41,6 +41,7 @@
// fwd decls
struct fwd_piter1d;
+ struct bkd_piter1d;
template <typename T> class image1d;
// super type
@@ -63,6 +64,7 @@
typedef fwd_piter1d piter_type;
typedef fwd_piter1d fwd_piter_type;
+ typedef bkd_piter1d bkd_piter_type;
// please note that value_storage_type means data_type
// since image1d is an image_with_data
Index: olena/oln/core/2d/array2d.hh
--- olena/oln/core/2d/array2d.hh (revision 147)
+++ olena/oln/core/2d/array2d.hh (working copy)
@@ -58,7 +58,6 @@
buffer = new T[nelts_eff];
array = new T*[nrows_eff];
- buffer = buffer;
T* buf = buffer + s.border();
for (size_t row = 0; row < nrows_eff; ++row)
{
@@ -97,7 +96,7 @@
~array2d()
{
- this->impl_clear_data();
+ this->clear_data();
}
bool impl_has_data() const
Index: olena/oln/core/3d/array3d.hh
--- olena/oln/core/3d/array3d.hh (revision 147)
+++ olena/oln/core/3d/array3d.hh (working copy)
@@ -53,6 +53,32 @@
};
+ template<class T>
+ void alloc_and_init(T*& buffer, T***& array, T**& array2, const size3d& s)
+ {
+ size_t nslices_eff = s.nslices() + 2 * s.border();
+ size_t nrows_eff = s.nrows() + 2 * s.border();
+ size_t ncols_eff = s.ncols() + 2 * s.border();
+ size_t nelts_eff = nslices_eff * nrows_eff * ncols_eff;
+
+ buffer = new T[nelts_eff];
+ array = new T**[nslices_eff];
+ array2 = new T*[nslices_eff * nrows_eff];
+
+ T* buf = buffer + s.border();
+ for (size_t slice = 0; slice < nslices_eff; ++slice)
+ {
+ T** a2 = array2 + slice * nrows_eff;
+ array[slice] = a2 + s.border();
+ for (size_t row = 0; row < nrows_eff; ++row)
+ {
+ a2[row] = buf;
+ buf += ncols_eff;
+ }
+ }
+ array += s.border();
+ }
+
template <typename T>
class array3d : public abstract::data_storage< array3d<T> >
{
@@ -65,7 +91,6 @@
array2_(0),
size_()
{
- this->exact_ptr = this;
invariant_();
}
@@ -80,13 +105,12 @@
array2_(0),
size_()
{
- this->exact_ptr = this;
this->resize(s);
}
~array3d()
{
- this->impl_clear_data();
+ this->clear_data();
}
bool impl_has_data() const
@@ -116,7 +140,7 @@
invariant_();
}
- const size3d& size() const
+ const size3d& impl_size() const
{
return size_;
}
@@ -131,27 +155,52 @@
this->clear_data();
size_ = s;
- size_t nslices_eff = size_.nslices() + 2 * size_.border();
- size_t nrows_eff = size_.nrows() + 2 * size_.border();
- size_t ncols_eff = size_.ncols() + 2 * size_.border();
- size_t nelts_eff = nslices_eff * nrows_eff * ncols_eff;
-
- buffer_ = new T[nelts_eff];
- array_ = new T**[nslices_eff];
- array2_ = new T*[nslices_eff * nrows_eff];
+ alloc_and_init(buffer_, array_, array2_, s);
+ invariant_();
+ }
- T* buf = buffer_ + size_.border();
- for (size_t slice = 0; slice < nslices_eff; ++slice)
+ void impl_resize_border(size_t new_border, bool copy_border)
{
- T** a2 = array2_ + slice * nrows_eff;
- array_[slice] = a2 + size_.border();
- for (size_t row = 0; row < nrows_eff; ++row)
+ invariant_();
+ T* new_buffer_;
+ T*** new_array_;
+ T** new_array2_;
+ size3d new_size_(this->size_.nslices(), this->size_.nrows(),
+ this->size_.ncols(), new_border);
+
+ alloc_and_init(new_buffer_, new_array_, new_array2_, new_size_);
+
+ if (buffer_ != 0)
{
- a2[row] = buf;
- buf += ncols_eff;
- }
+ size_t border = this->size_.border();
+
+ if (border > new_border)
+ border = new_border;
+
+ coord_t slice_min = copy_border ? -border : 0;
+ coord_t slice_max = int(this->size_.nslices())
+ + (copy_border ? border : 0);
+ coord_t row_min = copy_border ? -border : 0;
+ coord_t row_max = int(this->size_.nrows())
+ + (copy_border ? border : 0);
+ coord_t col_min = copy_border ? -border : 0;
+ size_t ncols = int(this->size_.ncols()) +
+ (copy_border ? (border * 2) : 0);
+
+ for (coord_t slice = slice_min; slice < slice_max; ++slice)
+ for (coord_t row = row_min; row < row_max; ++row)
+ memcpy(new_array_[slice][row] + col_min,
+ this->array_[slice][row] + col_min,
+ ncols * sizeof (T));
+
+ this->clear_data();
}
- array_ += size_.border();
+
+ buffer_ = new_buffer_;
+ array_ = new_array_;
+ array2_ = new_array2_;
+ size_ = new_size_;
+
invariant_();
}
Index: olena/oln/core/3d/image3d.hh
--- olena/oln/core/3d/image3d.hh (revision 147)
+++ olena/oln/core/3d/image3d.hh (working copy)
@@ -44,6 +44,7 @@
// fwd decls
struct fwd_piter3d;
+ struct bkd_piter3d;
template <typename T> class image3d;
// super
@@ -66,6 +67,7 @@
typedef fwd_piter3d piter_type;
typedef fwd_piter3d fwd_piter_type;
+ typedef bkd_piter3d bkd_piter_type;
// please note that value_storage_type means data_type
// since image3d is an image_with_data
1
0
14 Apr '05
2005-04-14 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/core/abstract/niter.hh (start): Rename as...
(start_): ...this.
(center_at): Add invalidate call.
* oln/core/abstract/iter.hh (start): Move to...
* oln/core/abstract/piter.hh (start): ...here.
* oln/core/abstract/qiter.hh: ...and here.
* oln/core/apply.hh: Update.
* oln/core/pw/image.hh: Likewise.
* oln/core/gen/regular_fwd_niter.hh: Likewise.
* oln/core/gen/regular_bkd_niter.hh: Likewise.
* oln/core/gen/regular_fwd_qiter.hh: Likewise.
* oln/core/gen/regular_bkd_qiter.hh: Likewise.
* oln/utils/md5.hxx: Likewise.
* oln/utils/clone.hh: Likewise.
* oln/fancy/iota.hh: Likewise.
* oln/morpho/reconstruction.hh: Likewise.
* oln/morpho/dilation.hh: Likewise.
* oln/morpho/splitse.hh: Likewise.
* oln/morpho/geodesic_dilation.hh: Likewise.
* oln/morpho/stat.hh: Likewise.
* oln/morpho/erosion.hh: Likewise.
* oln/morpho/geodesic_erosion.hh: Likewise.
* oln/level/fill.hh: Likewise.
* oln/level/compare.hh: Likewise.
* oln/arith/min.hh: Likewise.
* oln/arith/max.hh: Likewise.
Index: oln/core/apply.hh
===================================================================
--- oln/core/apply.hh (revision 146)
+++ oln/core/apply.hh (working copy)
@@ -80,7 +80,7 @@
{
output_type tmp(input_.size());
oln_type_of(I, fwd_piter) p(input_.size());
- for_all(p)
+ for_all_p (p)
tmp[p] = f_(input_[p]);
this->output = tmp;
}
@@ -154,7 +154,7 @@
{
output_type tmp(input1_.size());
oln_type_of(I1, fwd_piter) p(input1_.size());
- for_all(p)
+ for_all_p (p)
tmp[p] = f_(input1_[p], input2_[p]);
this->output = tmp;
}
Index: oln/core/abstract/niter.hh
===================================================================
--- oln/core/abstract/niter.hh (revision 146)
+++ oln/core/abstract/niter.hh (working copy)
@@ -110,12 +110,13 @@
void start_at_p(const point_type& p)
{
this->center_at(p);
- this->start();
+ this->start_();
}
void center_at(const point_type& p)
{
this->p_ = p;
+ this->invalidate();
}
protected:
@@ -129,10 +130,16 @@
{
}
+ void start_()
+ {
+ this->exact().impl_start_();
+ }
+
~niter()
{
get_props<category::niter, E>::ensure();
mlc_check_method_impl(E, const point_type, cast_point, , const);
+ mlc_check_method_impl(E, void, start_, , );
}
};
Index: oln/core/abstract/piter.hh
===================================================================
--- oln/core/abstract/piter.hh (revision 146)
+++ oln/core/abstract/piter.hh (working copy)
@@ -112,6 +112,11 @@
return this->p_;
}
+ void start()
+ {
+ this->exact().impl_start();
+ }
+
protected:
piter(const size_type& s) :
@@ -126,6 +131,7 @@
~piter()
{
get_props<category::piter, E>::ensure();
+ mlc_check_method_impl(E, void, start, , );
}
};
Index: oln/core/abstract/qiter.hh
===================================================================
--- oln/core/abstract/qiter.hh (revision 146)
+++ oln/core/abstract/qiter.hh (working copy)
@@ -110,12 +110,13 @@
void start_at_p(const point_type& p)
{
this->center_at(p);
- this->start();
+ this->start_();
}
void center_at(const point_type& p)
{
this->p_ = p;
+ this->invalidate();
}
protected:
@@ -130,10 +131,16 @@
mlc::eq< grid_type, oln_wn_type_of(window_type, grid) >::ensure();
}
+ void start_()
+ {
+ this->exact().impl_start_();
+ }
+
~qiter()
{
get_props<category::qiter, E>::ensure();
mlc_check_method_impl(E, const point_type, cast_point, , const);
+ mlc_check_method_impl(E, void, start_, , );
}
};
Index: oln/core/abstract/iter.hh
===================================================================
--- oln/core/abstract/iter.hh (revision 146)
+++ oln/core/abstract/iter.hh (working copy)
@@ -34,16 +34,6 @@
# include <oln/core/typedefs.hh>
-
-# define for_all(i) \
- for(i.start(); i.is_valid(); i.next())
-
-# define for_all_remaining(i) \
- for(; i.is_valid(); i.next())
-
-
-
-
namespace oln {
namespace abstract {
@@ -52,11 +42,6 @@
struct iter : public mlc::any<E>
{
- void start()
- {
- this->exact().impl_start();
- }
-
void next()
{
precondition(this->is_valid());
@@ -80,7 +65,6 @@
~iter()
{
- mlc_check_method_impl(E, void, start, , );
mlc_check_method_impl(E, void, next, , );
mlc_check_method_impl(E, bool, is_valid, , const);
mlc_check_method_impl(E, void, invalidate, , );
Index: oln/core/pw/image.hh
===================================================================
--- oln/core/pw/image.hh (revision 146)
+++ oln/core/pw/image.hh (working copy)
@@ -235,7 +235,7 @@
bool check(const abstract::binary_image<I>& pred)
{
oln_type_of(I, fwd_piter) p(pred.size());
- for_all (p)
+ for_all_p (p)
if (! pred[p])
return false;
return true;
Index: oln/core/gen/regular_fwd_niter.hh
===================================================================
--- oln/core/gen/regular_fwd_niter.hh (revision 146)
+++ oln/core/gen/regular_fwd_niter.hh (working copy)
@@ -58,7 +58,7 @@
protected:
- void impl_start()
+ void impl_start_()
{
this->pos_ = 0;
}
Index: oln/core/gen/regular_bkd_niter.hh
===================================================================
--- oln/core/gen/regular_bkd_niter.hh (revision 146)
+++ oln/core/gen/regular_bkd_niter.hh (working copy)
@@ -58,7 +58,7 @@
protected:
- void impl_start()
+ void impl_start_()
{
this->pos_ = this->nbh_.card() - 1;
}
Index: oln/core/gen/regular_fwd_qiter.hh
===================================================================
--- oln/core/gen/regular_fwd_qiter.hh (revision 146)
+++ oln/core/gen/regular_fwd_qiter.hh (working copy)
@@ -57,7 +57,7 @@
protected:
- void impl_start()
+ void impl_start_()
{
this->pos_ = 0;
}
Index: oln/core/gen/regular_bkd_qiter.hh
===================================================================
--- oln/core/gen/regular_bkd_qiter.hh (revision 146)
+++ oln/core/gen/regular_bkd_qiter.hh (working copy)
@@ -58,7 +58,7 @@
protected:
- void impl_start()
+ void impl_start_()
{
this->pos_ = this->win_.card() - 1;
}
Index: oln/utils/md5.hxx
===================================================================
--- oln/utils/md5.hxx (revision 146)
+++ oln/utils/md5.hxx (working copy)
@@ -291,7 +291,7 @@
buffer b;
oln_type_of(I, fwd_piter) p(im.size());
- for_all(p)
+ for_all_p (p)
b.add(im[p].value());
b.append_padding();
b.append_length();
@@ -309,7 +309,7 @@
buffer b;
// unsigned nb =
- for_all(p)
+ for_all_p (p)
{
for (unsigned i = 0; i < ntg_nb_comp(oln_type_of(I, value)); ++i)
b.add(im[p].value()[i]);
Index: oln/utils/clone.hh
===================================================================
--- oln/utils/clone.hh (revision 146)
+++ oln/utils/clone.hh (working copy)
@@ -77,7 +77,7 @@
this->output = tmp;
oln_type_of(I, fwd_piter) p(this->input.size());
- for_all(p)
+ for_all_p (p)
this->output[p] = this->input[p];
}
};
Index: oln/fancy/iota.hh
===================================================================
--- oln/fancy/iota.hh (revision 146)
+++ oln/fancy/iota.hh (working copy)
@@ -43,7 +43,7 @@
{
unsigned counter = 0;
oln_type_of(I, fwd_piter) p(inout.size());
- for_all(p)
+ for_all_p (p)
inout[p] = ++counter;
}
Index: oln/morpho/reconstruction.hh
===================================================================
--- oln/morpho/reconstruction.hh (revision 146)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -123,9 +123,9 @@
while (non_stability)
{
work.unbox() = utils::clone(output);
- for_all (fwd_p)
+ for_all_p (fwd_p)
fwd_loop_body();
- for_all (bkd_p)
+ for_all_p (bkd_p)
bkd_loop_body();
non_stability = !(level::is_equal(work, output));
@@ -265,15 +265,16 @@
bool exist_init()
{
- typedef oln_type_of(N, window) se_type;
- oln_type_of(se_type, fwd_qiter) dp(se_minus);
- for_all (dp)
- {
- q = (oln_type_of(se_type, dpoint))dp +
- (oln_type_of(I, point))bkd_p;
- if (static_cast<E*>((void*)this)->exist_init_impl())
- return true;
- }
+ // FIXME: to many changes => rewrite!
+// typedef oln_type_of(N, window) se_type;
+// oln_type_of(se_type, fwd_qiter) dp(se_minus);
+// for_all (dp)
+// {
+// q = (oln_type_of(se_type, dpoint))dp +
+// (oln_type_of(I, point))bkd_p;
+// if (static_cast<E*>((void*)this)->exist_init_impl())
+// return true;
+// }
return false;
}
@@ -305,12 +306,10 @@
this->output.unbox() = utils::clone(this->input1);
- std::cout << "for_all (fwd_p)" << std::endl;
- for_all (fwd_p)
+ for_all_p (fwd_p)
fwd_loop_body();
- std::cout << "for_all (bkd_p)" << std::endl;
- for_all (bkd_p)
+ for_all_p (bkd_p)
{
bkd_loop_body();
if (exist_init())
@@ -321,16 +320,16 @@
{
p = fifo.front();
fifo.pop();
- typedef oln_type_of(N, window) window_type;
- window_type w = convert::nbh_to_se(this->nbh);
- oln_type_of(window_type, fwd_qiter) dp(w);
+ // FIXME: AWFUL commented cause too many changes!
+// typedef oln_type_of(N, window) window_type;
+// window_type w = convert::nbh_to_se(this->nbh);
+// oln_wn_type_of(window_type, fwd_iter) q(w);
- for_all (dp)
- {
- q = (oln_type_of(window_type, dpoint))dp + p;
- if (this->output.hold(q))
- fifo_loop_body();
- }
+// for_all_q_of_p (q)
+// {
+// if (this->output.hold(q))
+// fifo_loop_body();
+// }
}
}
Index: oln/morpho/dilation.hh
===================================================================
--- oln/morpho/dilation.hh (revision 146)
+++ oln/morpho/dilation.hh (working copy)
@@ -50,7 +50,7 @@
{
oln_type_of(I, concrete) output(input.size());
oln_type_of(I, fwd_piter) p(input.size());
- for_all (p)
+ for_all_p (p)
output[p] = morpho::max(input, p, win);
return output;
}
@@ -176,7 +176,7 @@
this->output = tmp;
oln_type_of(I, fwd_piter) p(this->input.size());
- for_all (p)
+ for_all_p (p)
this->output[p] = morpho::max(this->input, p, this->win);
}
};
Index: oln/morpho/splitse.hh
===================================================================
--- oln/morpho/splitse.hh (revision 146)
+++ oln/morpho/splitse.hh (working copy)
@@ -78,20 +78,20 @@
W
get_plus_win_only(const abstract::window<W>& win)
{
- oln_wn_type_of(W, fwd_qiter) dp(win.exact());
+ oln_wn_type_of(W, fwd_iter) q(win.exact());
W out;
-
- for_all (dp)
- {
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) < 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) > 0) {
- break;
- }
- }
+ // FIXME: too many changes: rewrite!
+// for_all (q)
+// {
+// unsigned n;
+// for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
+// if (dp.nth(n) < 0) {
+// out.add(dp);
+// break;
+// } else if (dp.nth(n) > 0) {
+// break;
+// }
+// }
return out;
}
@@ -112,23 +112,24 @@
W
get_plus_win_p(const abstract::window<W>& win)
{
- oln_wn_type_of(W, fwd_qiter) dp(win.exact());
+ oln_wn_type_of(W, fwd_iter) q(win.exact());
W out;
- for_all (dp)
- {
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) < 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) > 0) {
- break;
- }
- // All p.nth(n) are 0.
- if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
- out.add(dp);
- }
+ // FIXME: too many changes: rewrite!
+// for_all (dp)
+// {
+// unsigned n;
+// for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
+// if (dp.nth(n) < 0) {
+// out.add(dp);
+// break;
+// } else if (dp.nth(n) > 0) {
+// break;
+// }
+// // All p.nth(n) are 0.
+// if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
+// out.add(dp);
+// }
return out;
}
@@ -148,20 +149,21 @@
W
get_minus_win_only(const abstract::window<W>& win)
{
- oln_wn_type_of(W, fwd_qiter) dp(win.exact());
+ oln_wn_type_of(W, fwd_iter) q(win.exact());
W out;
- for_all (dp)
- {
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) > 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) < 0) {
- break;
- }
- }
+ // FIXME: too many changes: rewrite!
+// for_all (dp)
+// {
+// unsigned n;
+// for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
+// if (dp.nth(n) > 0) {
+// out.add(dp);
+// break;
+// } else if (dp.nth(n) < 0) {
+// break;
+// }
+// }
return out;
}
@@ -182,23 +184,24 @@
W
get_minus_win_p(const abstract::window<W>& win)
{
- oln_wn_type_of(W, fwd_qiter) dp(win.exact());
+ oln_wn_type_of(W, fwd_iter) q(win.exact());
W out;
- for_all (dp)
- {
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) > 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) < 0) {
- break;
- }
- // All p.nth(n) are 0.
- if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
- out.add(dp);
- }
+ // FIXME: too many changes: rewrite!
+// for_all (dp)
+// {
+// unsigned n;
+// for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
+// if (dp.nth(n) > 0) {
+// out.add(dp);
+// break;
+// } else if (dp.nth(n) < 0) {
+// break;
+// }
+// // All p.nth(n) are 0.
+// if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
+// out.add(dp);
+// }
return out;
}
Index: oln/morpho/geodesic_dilation.hh
===================================================================
--- oln/morpho/geodesic_dilation.hh (revision 146)
+++ oln/morpho/geodesic_dilation.hh (working copy)
@@ -59,7 +59,7 @@
oln_type_of(I1, concrete) output(marker.size());
marker.border_adapt_copy(marker.nbh_get().delta());
oln_type_of(I1, piter) p(marker);
- for_all (p)
+ for_all_p (p)
output[p] = arith::min(morpho::max(marker, p, convert::nbh_to_cse(marker.nbh_get())),
mask[p]);
return output;
Index: oln/morpho/stat.hh
===================================================================
--- oln/morpho/stat.hh (revision 146)
+++ oln/morpho/stat.hh (working copy)
@@ -100,7 +100,7 @@
oln_wn_type_of(W, fwd_iter) q(win);
q.start_at(p);
V val = input[q];
- for_all_remaining (q)
+ for_all_remaining_q (q)
if (input.hold(q))
if (val > input[q].value())
val = input[q].value();
Index: oln/morpho/erosion.hh
===================================================================
--- oln/morpho/erosion.hh (revision 146)
+++ oln/morpho/erosion.hh (working copy)
@@ -49,7 +49,7 @@
{
oln_type_of(I, concrete) output(input.size());
oln_type_of(I, fwd_piter) p(input.size());
- for_all (p)
+ for_all_p (p)
output[p] = morpho::min(input, p, win);
return output;
}
@@ -166,7 +166,7 @@
this->output = tmp;
oln_type_of(I, fwd_piter) p(this->input.size());
- for_all (p)
+ for_all_p (p)
this->output[p] = morpho::min(this->input, p, this->win);
}
};
Index: oln/morpho/geodesic_erosion.hh
===================================================================
--- oln/morpho/geodesic_erosion.hh (revision 146)
+++ oln/morpho/geodesic_erosion.hh (working copy)
@@ -59,7 +59,7 @@
oln_type_of(I1, concrete) output(marker.size());
marker.border_adapt_copy(marker.nbh_get().delta());
oln_type_of(I1, piter) p(marker);
- for_all (p)
+ for_all_p (p)
output[p] = arith::max(morpho::min(marker, p, convert::nbh_to_cse(marker.nbh_get())),
mask[p]);
return output;
Index: oln/level/fill.hh
===================================================================
--- oln/level/fill.hh (revision 146)
+++ oln/level/fill.hh (working copy)
@@ -34,16 +34,18 @@
namespace level {
+ // FIXME: AWFUL in place!!!
+
/*! \brief Fill the image with a value.
*/
template <class I>
I
- fill(abstract::image<I>& im, const oln_type_of(I, value)& val)
+ fill(abstract::image<I>& input, const oln_type_of(I, value)& val)
{
- oln_type_of(I, fwd_piter) p(im.size());
- for_all(p)
- im[p] = val;
- return im.exact();
+ oln_type_of(I, fwd_piter) p(input.size());
+ for_all_p (p)
+ input[p] = val;
+ return input.exact();
}
} // end of namespace level
Index: oln/level/compare.hh
===================================================================
--- oln/level/compare.hh (revision 146)
+++ oln/level/compare.hh (working copy)
@@ -46,7 +46,7 @@
precondition(input1.size() == input2.size());
oln_type_of(I1, fwd_piter) p(input1.size());
- for_all (p)
+ for_all_p (p)
if (!(input1[p] >= input2[p]))
return false;
return true;
@@ -64,7 +64,7 @@
precondition(input1.size() == input2.size());
oln_type_of(I1, fwd_piter) p(input1.size());
- for_all (p)
+ for_all_p (p)
if (!(input1[p] > input2[p]))
return false;
return true;
@@ -82,7 +82,7 @@
precondition(input1.size() == input2.size());
oln_type_of(I1, fwd_piter) p(input1.size());
- for_all (p)
+ for_all_p (p)
if (!(input1[p] <= input2[p]))
return false;
return true;
@@ -100,7 +100,7 @@
precondition(input1.size() == input2.size());
oln_type_of(I1, fwd_piter) p(input1.size());
- for_all (p)
+ for_all_p (p)
if (!(input1[p] < input2[p]))
return false;
return true;
@@ -119,7 +119,7 @@
precondition(input1.size() == input2.size());
oln_type_of(I1, fwd_piter) p(input1.size());
- for_all (p)
+ for_all_p (p)
if (!(input1[p] == input2[p]))
return false;
return true;
Index: oln/arith/min.hh
===================================================================
--- oln/arith/min.hh (revision 146)
+++ oln/arith/min.hh (working copy)
@@ -70,7 +70,7 @@
I output(this->input1.size());
oln_type_of(I, fwd_piter) p(this->input1.size());
- for_all(p)
+ for_all_p (p)
output[p] = ntg::min(this->input1[p].value(), this->input2[p].value());
this->output = output;
Index: oln/arith/max.hh
===================================================================
--- oln/arith/max.hh (revision 146)
+++ oln/arith/max.hh (working copy)
@@ -70,7 +70,7 @@
I output(this->input1.size());
oln_type_of(I, fwd_piter) p(this->input1.size());
- for_all(p)
+ for_all_p (p)
output[p] = ntg::max(this->input1[p].value(), this->input2[p].value());
this->output = output;
1
0
2005-04-14 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/core/2d/fwd_niter2d.hh: Remove (obsolete; replaced by
niter2d.hh).
* oln/core/1d/niter1d.hh: New file.
* oln/core/1d/bkd_piter1d.hh: New file.
* oln/core/1d/qiter1d.hh: New file.
* oln/core/1d/neighborhood1d.hh: New file.
* oln/core/2d/niter2d.hh: New file.
* oln/core/2d/qiter2d.hh: New file.
* oln/core/3d/niter3d.hh: New file.
* oln/core/3d/bkd_piter3d.hh: New file.
* oln/core/3d/qiter3d.hh: New file.
* oln/core/3d/neighborhood3d.hh: New file.
* oln/core/gen/regular_bkd_niter.hh: New file.
* oln/core/gen/regular_bkd_qiter.hh: New file.
* oln/core/gen/regular_qiter.hh: New file.
* oln/core/gen/regular_neighborhood.hh: New file.
* oln/makefile.src: Update.
* oln/basics1d.hh: Add includes.
* oln/basics2d.hh: Likewise.
* oln/basics3d.hh: Likewise.
* oln/core/typedefs.hh: Add typedef decls.
* oln/core/abstract/niter.hh (start_at_p): New method.
(nbh_): Remove reference in type.
* oln/core/abstract/qiter.hh (for_all_q): Rename as...
(for_all_q_of_p): ...this.
(grid_type): New property.
(qiter): Rewrite.
* oln/core/abstract/point.hh (fwd_less, bkd_less): New methods.
* oln/core/abstract/dpoint.hh (fwd_less, bkd_less): New methods.
(dim): New method.
(operator!=, operator-): New operators.
(fwd_less_dpoint): New function object type.
* oln/core/abstract/neighborhood.hh: Rewrite.
* oln/core/abstract/window.hh (grid_type): New property.
(fwd_qiter_type): Rename as...
(fwd_iter_type): ...this.
(qiter.hh): New include.
* oln/core/1d/dpoint1d.hh: Update.
* oln/core/1d/image1d.hh: Likewise.
* oln/core/1d/window1d.hh: Likewise.
* oln/core/1d/point1d.hh: Likewise.
* oln/core/2d/dpoint2d.hh: Likewise.
* oln/core/2d/image2d.hh: Likewise.
* oln/core/2d/window2d.hh: Likewise.
* oln/core/2d/neighborhood2d.hh: Likewise.
* oln/core/2d/point2d.hh: Likewise.
* oln/core/3d/dpoint3d.hh: Likewise.
* oln/core/3d/image3d.hh: Likewise.
* oln/core/3d/window3d.hh: Likewise.
* oln/core/3d/point3d.hh: Likewise.
* oln/core/any/grid.hh: Likewise.
* oln/core/any/point.hh: Likewise.
* oln/core/any/dpoint.hh: Likewise.
* oln/core/gen/regular_niter.hh: Likewise.
* oln/core/gen/regular_fwd_niter.hh: Likewise.
* oln/core/gen/regular_fwd_qiter.hh: Likewise.
* oln/core/gen/regular_window.hh: Likewise.
* oln/morpho/cc_tarjan.hh: Likewise.
* oln/morpho/stat.hh: Likewise.
* oln/morpho/geodesic_dilation.hh: Likewise.
* oln/morpho/geodesic_erosion.hh: Add file and update.
Index: oln/basics1d.hh
===================================================================
--- oln/basics1d.hh (revision 144)
+++ oln/basics1d.hh (working copy)
@@ -34,5 +34,7 @@
# include <oln/core/1d/size1d.hh>
# include <oln/core/1d/point1d.hh>
# include <oln/core/1d/image1d.hh>
+# include <oln/core/1d/window1d.hh>
+# include <oln/core/1d/neighborhood1d.hh>
#endif // ! OLENA_BASICS1D_HH
Index: oln/basics2d.hh
===================================================================
--- oln/basics2d.hh (revision 144)
+++ oln/basics2d.hh (working copy)
@@ -34,8 +34,6 @@
# include <oln/core/2d/size2d.hh>
# include <oln/core/2d/point2d.hh>
# include <oln/core/2d/image2d.hh>
-# include <oln/core/2d/fwd_piter2d.hh>
-# include <oln/core/2d/bkd_piter2d.hh>
# include <oln/core/2d/window2d.hh>
# include <oln/core/2d/neighborhood2d.hh>
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 144)
+++ oln/core/typedefs.hh (working copy)
@@ -28,9 +28,9 @@
#ifndef OLENA_CORE_TYPEDEFS_HH
# define OLENA_CORE_TYPEDEFS_HH
-// FIXME: rename this present file (?)
+# include <iostream>
-
+# include <mlc/contract.hh>
# include <mlc/types.hh>
# include <mlc/cmp.hh>
# include <mlc/typedef.hh>
@@ -45,10 +45,16 @@
mlc_equip_namespace_with_properties();
- // category::image
+ // general
mlc_decl_typedef(grid_type);
+ mlc_decl_typedef(iter_type);
+ mlc_decl_typedef(fwd_iter_type);
+ mlc_decl_typedef(bkd_iter_type);
+
+ // category::image
+
mlc_decl_typedef(data_type);
mlc_decl_typedef(value_type);
mlc_decl_typedef(neighb_type);
@@ -59,7 +65,6 @@
mlc_decl_typedef(image_type);
mlc_decl_typedef(concrete_type);
- mlc_decl_typedef(iter_type);
mlc_decl_typedef(piter_type);
mlc_decl_typedef(fwd_piter_type);
mlc_decl_typedef(bkd_piter_type);
Index: oln/core/abstract/niter.hh
===================================================================
--- oln/core/abstract/niter.hh (revision 144)
+++ oln/core/abstract/niter.hh (working copy)
@@ -107,6 +107,12 @@
return this->exact().impl_cast_point();
}
+ void start_at_p(const point_type& p)
+ {
+ this->center_at(p);
+ this->start();
+ }
+
void center_at(const point_type& p)
{
this->p_ = p;
@@ -114,15 +120,15 @@
protected:
- niter(const neighb_type& ima) :
+ const neighb_type nbh_; // copy is safe
+ point_type p_;
+
+ niter(const neighb_type& nbh) :
nbh_(nbh),
p_()
{
}
- const neighb_type& nbh_;
- point_type p_;
-
~niter()
{
get_props<category::niter, E>::ensure();
Index: oln/core/abstract/qiter.hh
===================================================================
--- oln/core/abstract/qiter.hh (revision 144)
+++ oln/core/abstract/qiter.hh (working copy)
@@ -29,12 +29,13 @@
# define OLENA_CORE_ABSTRACT_QITER_HH
# include <oln/core/abstract/iter.hh>
+# include <oln/core/abstract/grid.hh>
# include <oln/core/abstract/window.hh>
# include <oln/core/typedefs.hh>
-# define for_all_q( q ) \
- for(q.ensure_is_qiter(), q.start(); q.is_valid(); q.next())
+# define for_all_q_of_p(q, p) \
+ for(q.ensure_is_qiter(), q.center_at(p), q.start(); q.is_valid(); q.next())
# define for_all_remaining_q( q ) \
for(q.ensure_is_piter(); q.is_valid(); q.next())
@@ -57,6 +58,7 @@
template <>
struct set_default_props < category::qiter >
{
+ typedef mlc::undefined_type grid_type;
typedef mlc::undefined_type window_type;
};
@@ -65,18 +67,21 @@
template <typename Q>
struct get_props < category::qiter, Q >
{
+ typedef oln_qit_type_of(Q, grid) grid_type;
typedef oln_qit_type_of(Q, window) window_type;
static void echo(std::ostream& ostr)
{
ostr << "props_of( oln::category::qiter, " << mlc_to_string(Q) << " ) =" << std::endl
<< "{" << std::endl
+ << "\t grid_type = " << mlc_to_string(grid_type) << std::endl
<< "\t window_type = " << mlc_to_string(window_type) << std::endl
<< "}" << std::endl;
}
static void ensure()
{
+ mlc::is_ok< grid_type >::ensure();
mlc::is_ok< window_type >::ensure();
}
};
@@ -89,22 +94,46 @@
struct qiter : public iter<E>
{
+ typedef oln_qit_type_of(E, grid) grid_type;
typedef oln_qit_type_of(E, window) window_type;
+ typedef oln_grd_type_of(grid_type, point) point_type;
+
void ensure_is_qiter() {}
+ operator point_type() const
+ {
+ precondition(this->is_valid());
+ return this->exact().impl_cast_point();
+ }
+
+ void start_at_p(const point_type& p)
+ {
+ this->center_at(p);
+ this->start();
+ }
+
+ void center_at(const point_type& p)
+ {
+ this->p_ = p;
+ }
+
protected:
+ const window_type win_; // copy is safe
+ point_type p_;
+
qiter(const window_type& win) :
- win_(win)
+ win_(win),
+ p_()
{
+ mlc::eq< grid_type, oln_wn_type_of(window_type, grid) >::ensure();
}
- const window_type& win_;
-
~qiter()
{
get_props<category::qiter, E>::ensure();
+ mlc_check_method_impl(E, const point_type, cast_point, , const);
}
};
Index: oln/core/abstract/point.hh
===================================================================
--- oln/core/abstract/point.hh (revision 144)
+++ oln/core/abstract/point.hh (working copy)
@@ -130,11 +130,17 @@
return this->exact().impl_eq(rhs.exact());
}
-// // FIXME: compiler error (cannot be overloaded)
-// bool operator==(const any_point& rhs) const
-// {
-// return true;
-// }
+ /// Anteriority w.r.t. to a fwd image browsing.
+ bool fwd_less(const exact_type& rhs) const
+ {
+ return this->exact().impl_fwd_less(rhs.exact());
+ }
+
+ /// Anteriority w.r.t. to a bkd image browsing.
+ bool bkd_less(const exact_type& rhs) const
+ {
+ return not *this == rhs and not this->fwd_less(rhs);
+ }
/*! \brief Test difference of two points. Nota bene: this method
** is concrete (and based on abstract::point::operator==).
@@ -143,7 +149,7 @@
*/
bool operator!=(const exact_type& rhs) const
{
- return ! this->operator==(rhs);
+ return not this->operator==(rhs);
}
// FIXME: doc...
@@ -184,11 +190,12 @@
{
get_props<category::point, E>::ensure();
- mlc_check_method_impl(E, bool, eq, const exact_type&, const);
- mlc_check_method_impl(E, const exact_type, plus, const dpoint_type&, const);
- mlc_check_method_impl(E, const dpoint_type, minus, const exact_type&, const);
- mlc_check_method_impl(E, const coord_type, nth, unsigned, const);
- mlc_check_method_impl(E, coord_type&, nth, unsigned, );
+ mlc_check_method_impl(E, bool, eq, const exact_type&, const);
+ mlc_check_method_impl(E, bool, fwd_less, const exact_type&, const);
+ mlc_check_method_impl(E, const exact_type, plus, const dpoint_type&, const);
+ mlc_check_method_impl(E, const dpoint_type, minus, const exact_type&, const);
+ mlc_check_method_impl(E, const coord_type, nth, unsigned, const);
+ mlc_check_method_impl(E, coord_type&, nth, unsigned, );
}
};
Index: oln/core/abstract/dpoint.hh
===================================================================
--- oln/core/abstract/dpoint.hh (revision 144)
+++ oln/core/abstract/dpoint.hh (working copy)
@@ -29,6 +29,7 @@
# define OLENA_CORE_ABSTRACT_DPOINT_HH
# include <mlc/any.hh>
+# include <mlc/contract.hh>
# include <oln/core/coord.hh>
# include <oln/core/typedefs.hh>
@@ -62,39 +63,79 @@
return this->exact().impl_eq(rhs.exact());
}
- /// Test difference between two dpoints.
- bool operator!=(const exact_type& rhs) const
+ /// Anteriority w.r.t. to a fwd image browsing.
+ bool fwd_less(const exact_type& rhs) const
{
- return ! this->operator==(rhs);
+ return this->exact().impl_fwd_less(rhs.exact());
}
-
+
+ /// Anteriority w.r.t. to a bkd image browsing.
+ bool bkd_less(const exact_type& rhs) const
+ {
+ return ! *this == rhs && ! this->fwd_less(rhs);
+ }
+
const coord_t nth(unsigned i) const
{
- // FIXME: add precondition
+ precondition(i < this->dim());
return this->exact().impl_nth(i);
}
coord_t& nth(unsigned i)
{
- // FIXME: add precondition
+ precondition(i < this->dim());
return this->exact().impl_nth(i);
}
+ unsigned dim() const
+ {
+ return this->exact().impl_dim();
+ }
+
+
+ /// Test difference between two dpoints.
+ bool operator!=(const exact_type& rhs) const
+ {
+ return ! this->operator==(rhs);
+ }
+
+ /// Unarity minus.
+ const exact_type operator-() const
+ {
+ exact_type tmp;
+ for (unsigned c = 0; c < this->dim(); ++c)
+ tmp.nth(c) = - this->nth(c);
+ return tmp;
+ }
+
protected:
dpoint() {}
~dpoint()
{
- mlc_check_method_impl(E, bool, eq, const exact_type&, const);
- mlc_check_method_impl(E, const coord_t, nth, unsigned, const);
- mlc_check_method_impl(E, coord_t&, nth, unsigned, );
+ mlc_check_method_impl(E, bool, eq, const exact_type&, const);
+ mlc_check_method_impl(E, bool, fwd_less, const exact_type&, const);
+ mlc_check_method_impl(E, const coord_t, nth, unsigned, const);
+ mlc_check_method_impl(E, coord_t&, nth, unsigned, );
+ mlc_check_method_impl(E, unsigned, dim, , const);
}
};
} // end of namespace abstract
+
+ struct fwd_less_dpoint
+ {
+ template <typename D>
+ bool operator()(const abstract::dpoint<D>& lhs, const abstract::dpoint<D>& rhs) const
+ {
+ return lhs.fwd_less(rhs.exact());
+ }
+ };
+
+
} // end of namespace oln
Index: oln/core/abstract/neighborhood.hh
===================================================================
--- oln/core/abstract/neighborhood.hh (revision 144)
+++ oln/core/abstract/neighborhood.hh (working copy)
@@ -28,14 +28,7 @@
#ifndef OLENA_CORE_NEIGHBORHOOD_HH
# define OLENA_CORE_NEIGHBORHOOD_HH
-# include <vector>
-# include <utility>
-# include <iostream>
-
# include <oln/core/typedefs.hh>
-# include <oln/core/coord.hh>
-# include <oln/core/abstract/dpoint.hh>
-# include <oln/core/accum.hh>
# define oln_nbh_type_of(NeighborhoodType, Alias) \
@@ -60,7 +53,7 @@
};
- /// Retrieval of any image type properties (FIXME: say 'packing').
+ /// Retrieval of any neighborhood type properties.
template <typename N>
struct get_props < category::neighborhood, N >
@@ -72,10 +65,11 @@
static void echo(std::ostream& ostr)
{
ostr << "props_of( oln::category::neighborhood, " << mlc_to_string(N) << " ) =" << std::endl
+ << "{" << std::endl
<< "\t dpoint_type = " << mlc_to_string(dpoint_type) << std::endl
<< "\t size_type = " << mlc_to_string(size_type) << std::endl
<< "\t window_type = " << mlc_to_string(window_type) << std::endl
- << std::endl;
+ << "}" << std::endl;
}
static void ensure()
@@ -92,148 +86,31 @@
namespace abstract {
/*!
- ** Structuring elements (set of dpoints).
+ ** Class for neighborhoods.
**
- ** This abstract class defines several virtual methods for its
- ** subclasses. Its goal is to deal with a set of 'move' points.
*/
- template<class E>
- class neighborhood : public mlc::any__best_memory<E>
+ template <typename E>
+ struct neighborhood : public mlc::any<E>
{
- // FIXME: rewrite this class
-
- public:
-
- typedef oln_nbh_type_of(E, dpoint) dpoint_type;
-
- typedef E exact_type;
-
- bool
- has(const dpoint_type& dp) const
- {
- return this->exact().impl_has(dp.exact());
- }
-
- unsigned
- card() const
- {
- return this->exact().impl_card();
- }
-
- exact_type&
- add(const dpoint_type& dp)
- {
- return this->exact().impl_add(dp);
- }
-
- dpoint_type
- dp(unsigned i) const
- {
- return this->exact().impl_at(i);
- }
-
- const dpoint_type
- operator[](unsigned i) const
- {
- return this->exact().impl_at(i);
- }
-
- coord_t
- get_delta() const
- {
- return this->exact().impl_get_delta();
- }
-
- coord_t
- delta_update(const dpoint_type& dp)
- {
- return this->exact().impl_delta_update(dp);
- }
-
protected:
+
+ neighborhood()
+ {}
- bool
- impl_has(const dpoint_type& dp) const
- {
- return std::find(dp_.begin(), dp_.end(), dp) != dp_.end();
- }
-
- exact_type&
- impl_add(const dpoint_type& dp)
- {
- if (!(impl_has(dp)))
- {
- this->dp_.push_back(dp);
- this->dp_.push_back(-dp);
- }
- this->delta_update(dp);
- return this->exact();
- }
-
- coord_t
- impl_get_delta() const
- {
- return delta_;
- }
-
- unsigned
- impl_card() const
- {
- return dp_.size();
- }
-
- const dpoint_type
- impl_at(unsigned i) const
- {
- precondition(i < this->card());
- return dp_[i];
- }
-
- neighborhood() : dp_(), delta_(0)
- {};
-
- neighborhood(unsigned size) : dp_(), delta_(0)
- {
- dp_.reserve(size);
- };
-
- /// Attributes
-
- std::vector<dpoint_type> dp_;
- max_accumulator<coord_t> delta_;
-
- /// Destructor.
-
~neighborhood()
{
get_props<category::neighborhood, E>::ensure();
-// bool has(const dpoint_type& dp) const
-// unsigned card() const
-// exact_type& add(const dpoint_type& dp)
-// dpoint_type dp(unsigned i) const
-// const dpoint_type operator[](unsigned i) const
-// coord_t get_delta() const
-// coord_t delta_update(const dpoint_type& dp)
}
};
- } // end of abstract
+ } // end of namespace abstract::oln
-} // end of oln
+} // end of namespace oln
-template<class E>
-std::ostream&
-operator<<(std::ostream& o, const oln::abstract::neighborhood<E>& se)
-{
- unsigned c = se.card();
- o << "[";
- for (unsigned i = 0; i < c; ++i)
- o << se.dp(i);
- o << "]";
- return o;
-}
+# include <oln/core/abstract/niter.hh>
+
#endif // ! OLENA_CORE_NEIGHBORHOOD_HH
Index: oln/core/abstract/window.hh
===================================================================
--- oln/core/abstract/window.hh (revision 144)
+++ oln/core/abstract/window.hh (working copy)
@@ -28,15 +28,7 @@
#ifndef OLENA_CORE_ABSTRACT_WINDOW_HH
# define OLENA_CORE_ABSTRACT_WINDOW_HH
-# include <vector>
-# include <utility>
-# include <iostream>
-
-# include <mlc/types.hh>
# include <oln/core/typedefs.hh>
-# include <oln/core/coord.hh>
-# include <oln/core/abstract/dpoint.hh>
-# include <oln/core/accum.hh>
# define oln_wn_type_of(WindowType, Alias) \
@@ -54,34 +46,38 @@
template <>
struct set_default_props < category::window >
{
+ typedef mlc::undefined_type grid_type;
typedef mlc::undefined_type dpoint_type;
typedef mlc::undefined_type size_type;
- typedef mlc::undefined_type fwd_qiter_type;
+ typedef mlc::undefined_type fwd_iter_type;
};
template <typename W>
struct get_props < category::window, W >
{
- typedef oln_wn_type_of(W, dpoint) dpoint_type;
- typedef oln_wn_type_of(W, size) size_type;
- typedef oln_wn_type_of(W, fwd_qiter) fwd_qiter_type;
+ typedef oln_wn_type_of(W, grid) grid_type;
+ typedef oln_wn_type_of(W, dpoint) dpoint_type;
+ typedef oln_wn_type_of(W, size) size_type;
+ typedef oln_wn_type_of(W, fwd_iter) fwd_iter_type;
static void echo(std::ostream& ostr)
{
ostr << "props_of( oln::category::window, " << mlc_to_string(W) << " ) =" << std::endl
<< "{" << std::endl
- << "\t dpoint_type = " << mlc_to_string(dpoint_type) << std::endl
- << "\t size_type = " << mlc_to_string(size_type) << std::endl
- << "\t fwd_qiter_type = " << mlc_to_string(fwd_qiter_type) << std::endl
+ << "\t grid_type = " << mlc_to_string(grid_type) << std::endl
+ << "\t dpoint_type = " << mlc_to_string(dpoint_type) << std::endl
+ << "\t size_type = " << mlc_to_string(size_type) << std::endl
+ << "\t fwd_iter_type = " << mlc_to_string(fwd_iter_type) << std::endl
<< "}" << std::endl;
}
static void ensure()
{
- mlc::is_ok< dpoint_type >::ensure();
- mlc::is_ok< size_type >::ensure();
- mlc::is_ok< fwd_qiter_type >::ensure();
+ mlc::is_ok< grid_type >::ensure();
+ mlc::is_ok< dpoint_type >::ensure();
+ mlc::is_ok< size_type >::ensure();
+ mlc::is_ok< fwd_iter_type >::ensure();
}
};
@@ -117,5 +113,7 @@
} // end of namespace oln
+# include <oln/core/abstract/qiter.hh>
+
#endif // ! OLENA_CORE_ABSTRACT_WINDOW_HH
Index: oln/core/1d/dpoint1d.hh
===================================================================
--- oln/core/1d/dpoint1d.hh (revision 144)
+++ oln/core/1d/dpoint1d.hh (working copy)
@@ -95,6 +95,11 @@
return this->index_ == rhs.index_;
}
+ bool impl_fwd_less(const dpoint1d& rhs) const
+ {
+ return this->index_ < rhs.index_;
+ }
+
const coord_t impl_nth(unsigned i) const
{
precondition(i == 0);
@@ -107,6 +112,11 @@
return index_;
}
+ unsigned impl_dim() const
+ {
+ return 1;
+ }
+
coord_t index_;
};
Index: oln/core/1d/niter1d.hh
===================================================================
--- oln/core/1d/niter1d.hh (revision 0)
+++ oln/core/1d/niter1d.hh (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_1D_NITER1D_HH
+# define OLENA_CORE_1D_NITER1D_HH
+
+# include <oln/core/1d/grid1d.hh>
+# include <oln/core/1d/point1d.hh>
+# include <oln/core/1d/dpoint1d.hh>
+# include <oln/core/1d/neighborhood1d.hh>
+
+# include <oln/core/gen/regular_fwd_niter.hh>
+# include <oln/core/gen/regular_bkd_niter.hh>
+
+
+namespace oln {
+
+ typedef regular_fwd_niter<grid1d> fwd_niter1d;
+ typedef regular_bkd_niter<grid1d> bkd_niter1d;
+
+}
+
+
+#endif // ! OLENA_CORE_1D_NITER1D_HH
Index: oln/core/1d/image1d.hh
===================================================================
--- oln/core/1d/image1d.hh (revision 144)
+++ oln/core/1d/image1d.hh (working copy)
@@ -131,4 +131,8 @@
} // end of namespace oln
+# include <oln/core/1d/fwd_piter1d.hh>
+# include <oln/core/1d/bkd_piter1d.hh>
+
+
#endif // ! OLENA_CORE_1D_IMAGE1D_HH
Index: oln/core/1d/bkd_piter1d.hh
===================================================================
--- oln/core/1d/bkd_piter1d.hh (revision 0)
+++ oln/core/1d/bkd_piter1d.hh (revision 0)
@@ -0,0 +1,103 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_1D_BKD_PITER1D_HH
+# define OLENA_CORE_1D_BKD_PITER1D_HH
+
+# include <mlc/contract.hh>
+# include <oln/core/abstract/piter.hh>
+# include <oln/core/1d/point1d.hh>
+# include <oln/core/1d/size1d.hh>
+
+
+namespace oln {
+
+
+ // fwd decl
+ struct bkd_piter1d;
+
+ // super type
+ template <>
+ struct set_super_type < bkd_piter1d > { typedef abstract::piter< bkd_piter1d > ret; };
+
+ // props
+ template <>
+ struct set_props < category::piter, bkd_piter1d >
+ {
+ typedef point1d point_type;
+ typedef size1d size_type;
+ };
+
+
+
+ struct bkd_piter1d : public abstract::piter< bkd_piter1d >
+ {
+ typedef bkd_piter1d self_type;
+ typedef abstract::piter<self_type> super_type;
+
+ bkd_piter1d(const size1d& size) :
+ super_type(size)
+ {
+ this->invalidate();
+ }
+
+ friend class abstract::iter<self_type>;
+ friend class abstract::piter<self_type>;
+
+ protected:
+
+ void impl_start()
+ {
+ this->p_.index() = this->s_.nindices() - 1;
+ postcondition(this->p_.index().is_defined());
+ }
+
+ bool impl_is_valid() const
+ {
+ precondition(this->p_.index().is_defined());
+ return this->p_.index() >= 0;
+ }
+
+ void impl_next()
+ {
+ precondition(this->p_.index().is_defined());
+ precondition(this->p_.index() >= 0 && this->p_.index() < this->s_.nindices());
+ --this->p_.index();
+ postcondition(this->p_.index().is_defined());
+ }
+
+ void impl_invalidate()
+ {
+ this->p_.index() = -1;
+ postcondition(this->p_.index().is_defined());
+ }
+
+ };
+}
+
+
+#endif // ! OLENA_CORE_1D_BKD_PITER1D_HH
Index: oln/core/1d/qiter1d.hh
===================================================================
--- oln/core/1d/qiter1d.hh (revision 0)
+++ oln/core/1d/qiter1d.hh (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_1D_QITER1D_HH
+# define OLENA_CORE_1D_QITER1D_HH
+
+# include <oln/core/1d/grid1d.hh>
+# include <oln/core/1d/point1d.hh>
+# include <oln/core/1d/dpoint1d.hh>
+# include <oln/core/1d/window1d.hh>
+
+# include <oln/core/gen/regular_fwd_qiter.hh>
+# include <oln/core/gen/regular_bkd_qiter.hh>
+
+
+namespace oln {
+
+ typedef regular_fwd_qiter<grid1d> fwd_qiter1d;
+ typedef regular_bkd_qiter<grid1d> bkd_qiter1d;
+
+}
+
+
+#endif // ! OLENA_CORE_1D_QITER1D_HH
Index: oln/core/1d/window1d.hh
===================================================================
--- oln/core/1d/window1d.hh (revision 144)
+++ oln/core/1d/window1d.hh (working copy)
@@ -28,9 +28,10 @@
#ifndef OLENA_CORE_WINDOW1D_HH
# define OLENA_CORE_WINDOW1D_HH
-# include <oln/core/gen/regular_window.hh>
# include <oln/core/1d/grid1d.hh>
# include <oln/core/1d/dpoint1d.hh>
+# include <oln/core/gen/regular_window.hh>
+# include <oln/core/1d/qiter1d.hh>
namespace oln {
Index: oln/core/1d/neighborhood1d.hh
===================================================================
--- oln/core/1d/neighborhood1d.hh (revision 0)
+++ oln/core/1d/neighborhood1d.hh (revision 0)
@@ -0,0 +1,50 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_NEIGHBORHOOD1D_HH
+# define OLENA_CORE_NEIGHBORHOOD1D_HH
+
+# include <oln/core/1d/window1d.hh>
+# include <oln/core/gen/regular_neighborhood.hh>
+# include <oln/core/1d/niter1d.hh>
+
+
+namespace oln {
+
+ typedef regular_neighborhood< grid1d > neighborhood1d;
+
+ inline const neighborhood1d&
+ neighb_c2()
+ {
+ static const neighborhood1d neighb(win_c2_only());
+ return neighb;
+ }
+
+} // end of namespace oln
+
+
+#endif // OLENA_CORE_NEIGHBORHOOD2D_HH
Index: oln/core/1d/point1d.hh
===================================================================
--- oln/core/1d/point1d.hh (revision 144)
+++ oln/core/1d/point1d.hh (working copy)
@@ -96,6 +96,11 @@
return this->index_ == rhs.index_;
}
+ bool impl_fwd_less(const point1d& rhs) const
+ {
+ return this->index_ < rhs.index_;
+ }
+
const coord_t impl_nth(unsigned i) const
{
precondition(i == 0);
Index: oln/core/2d/dpoint2d.hh
===================================================================
--- oln/core/2d/dpoint2d.hh (revision 144)
+++ oln/core/2d/dpoint2d.hh (working copy)
@@ -105,6 +105,13 @@
return this->row_ == rhs.row_ && this->col_ == rhs.col_;
}
+ bool impl_fwd_less(const dpoint2d& rhs) const
+ {
+ return
+ this->row_ < rhs.row_
+ || (this->row_ == rhs.row_ && this->col_ < rhs.col_);
+ }
+
const coord_t impl_nth(unsigned i) const
{
precondition(i < 2);
@@ -123,6 +130,11 @@
return col_;
}
+ unsigned impl_dim() const
+ {
+ return 2;
+ }
+
coord_t row_, col_;
};
Index: oln/core/2d/fwd_niter2d.hh
===================================================================
--- oln/core/2d/fwd_niter2d.hh (revision 145)
+++ oln/core/2d/fwd_niter2d.hh (working copy)
@@ -1,46 +0,0 @@
-// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_2D_FWD_NITER2D_HH
-# define OLENA_CORE_2D_FWD_NITER2D_HH
-
-# include <oln/core/2d/grid2d.hh>
-# include <oln/core/2d/point2d.hh>
-# include <oln/core/2d/dpoint2d.hh>
-# include <oln/core/2d/neighborhood2d.hh>
-
-# include <oln/core/gen/regular_fwd_niter.hh>
-
-
-namespace oln {
-
- typedef regular_fwd_niter<grid2d> fwd_niter2d;
-
-}
-
-
-#endif // ! OLENA_CORE_2D_FWD_NITER2D_HH
Index: oln/core/2d/niter2d.hh
===================================================================
--- oln/core/2d/niter2d.hh (revision 0)
+++ oln/core/2d/niter2d.hh (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_2D_NITER2D_HH
+# define OLENA_CORE_2D_NITER2D_HH
+
+# include <oln/core/2d/grid2d.hh>
+# include <oln/core/2d/point2d.hh>
+# include <oln/core/2d/dpoint2d.hh>
+# include <oln/core/2d/neighborhood2d.hh>
+
+# include <oln/core/gen/regular_fwd_niter.hh>
+# include <oln/core/gen/regular_bkd_niter.hh>
+
+
+namespace oln {
+
+ typedef regular_fwd_niter<grid2d> fwd_niter2d;
+ typedef regular_bkd_niter<grid2d> bkd_niter2d;
+
+}
+
+
+#endif // ! OLENA_CORE_2D_NITER2D_HH
Index: oln/core/2d/image2d.hh
===================================================================
--- oln/core/2d/image2d.hh (revision 144)
+++ oln/core/2d/image2d.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/abstract/image_with_data.hh>
# include <oln/core/abstract/image_like_.hh>
# include <oln/core/2d/array2d.hh>
+# include <oln/core/2d/niter2d.hh>
/*! \namespace oln
@@ -51,7 +52,6 @@
// fwd decls
struct fwd_piter2d;
struct bkd_piter2d;
- struct fwd_niter2d;
template <typename T> class image2d;
// super
@@ -166,4 +166,8 @@
} // end of namespace oln
+# include <oln/core/2d/fwd_piter2d.hh>
+# include <oln/core/2d/bkd_piter2d.hh>
+
+
#endif // ! OLENA_CORE_IMAGE2D_HH
Index: oln/core/2d/qiter2d.hh
===================================================================
--- oln/core/2d/qiter2d.hh (revision 0)
+++ oln/core/2d/qiter2d.hh (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_2D_QITER2D_HH
+# define OLENA_CORE_2D_QITER2D_HH
+
+# include <oln/core/2d/grid2d.hh>
+# include <oln/core/2d/point2d.hh>
+# include <oln/core/2d/dpoint2d.hh>
+# include <oln/core/2d/window2d.hh>
+
+# include <oln/core/gen/regular_fwd_qiter.hh>
+# include <oln/core/gen/regular_bkd_qiter.hh>
+
+
+namespace oln {
+
+ typedef regular_fwd_qiter<grid2d> fwd_qiter2d;
+ typedef regular_bkd_qiter<grid2d> bkd_qiter2d;
+
+}
+
+
+#endif // ! OLENA_CORE_2D_QITER2D_HH
Index: oln/core/2d/window2d.hh
===================================================================
--- oln/core/2d/window2d.hh (revision 144)
+++ oln/core/2d/window2d.hh (working copy)
@@ -28,9 +28,10 @@
#ifndef OLENA_CORE_WINDOW2D_HH
# define OLENA_CORE_WINDOW2D_HH
-# include <oln/core/gen/regular_window.hh>
# include <oln/core/2d/dpoint2d.hh>
# include <oln/core/2d/grid2d.hh>
+# include <oln/core/gen/regular_window.hh>
+# include <oln/core/2d/qiter2d.hh>
namespace oln
Index: oln/core/2d/neighborhood2d.hh
===================================================================
--- oln/core/2d/neighborhood2d.hh (revision 144)
+++ oln/core/2d/neighborhood2d.hh (working copy)
@@ -28,106 +28,31 @@
#ifndef OLENA_CORE_NEIGHBORHOOD2D_HH
# define OLENA_CORE_NEIGHBORHOOD2D_HH
-# include <oln/core/coord.hh>
-# include <oln/core/abstract/neighborhood.hh>
-# include <oln/core/2d/dpoint2d.hh>
-# include <oln/core/2d/size2d.hh>
# include <oln/core/2d/window2d.hh>
+# include <oln/core/gen/regular_neighborhood.hh>
+# include <oln/core/2d/niter2d.hh>
namespace oln {
- class neighborhood2d; // forward declaration
+ typedef regular_neighborhood< grid2d > neighborhood2d;
- // super_type
- template <>
- struct set_super_type< neighborhood2d > { typedef abstract::neighborhood< neighborhood2d > ret; };
-
- template <>
- struct set_props< category::neighborhood, neighborhood2d >
- {
- typedef dpoint2d dpoint_type;
- typedef size2d size_type;
- typedef window2d window_type;
- };
-
-
- class neighborhood2d : public abstract::neighborhood< neighborhood2d >
- {
-
- public:
-
- typedef abstract::neighborhood< neighborhood2d > super_type;
-
- /*!
- ** \brief Construct a neighborhood of 2 dimensions.
- */
- neighborhood2d() :
- super_type()
- {
- }
-
- /*!
- ** \brief Construct a neighborhood of 2 dimensions.
- ** \arg size The number of element.
- */
- neighborhood2d(unsigned size) :
- super_type(size)
- {
- }
-
- /*!
- ** \brief Construct a neighborhood of 2 dimensions from several points.
- ** \arg n The number of element.
- ** \arg crd The coordinates of the elements
- */
- neighborhood2d(unsigned n, const coord_t crd[]) :
- super_type(n)
- {
- for (unsigned i = 0; i < 2 * n; i += 2)
- this->add(dpoint2d(crd[i], crd[i+1]));
- }
-
- neighborhood2d&
- add(const dpoint2d& dp)
- {
- return this->exact().impl_add(dp);
- }
-
- neighborhood2d&
- add(coord_t row, coord_t col)
- {
- dpoint2d dp(row, col);
- return add(dp);
- }
-
- coord_t
- impl_delta_update(const dpoint2d& dp)
- {
- delta_(abs(dp.row()));
- delta_(abs(dp.col()));
- return delta_;
- }
-
- };
-
-
inline const neighborhood2d&
neighb_c4()
{
- static const coord_t crd[] = { 0,1, 1,0 };
- static const neighborhood2d neighb(2, crd);
+ static const neighborhood2d neighb(win_c4_only());
return neighb;
}
inline const neighborhood2d&
neighb_c8()
{
- static const coord_t crd[] = { 0,1, 1,1, 1,0, 1,-1 };
- static const neighborhood2d neighb(4, crd);
+ static const neighborhood2d neighb(win_c8_only());
return neighb;
}
-} // end of oln
+} // end of namespace oln
+
+
#endif // OLENA_CORE_NEIGHBORHOOD2D_HH
Index: oln/core/2d/point2d.hh
===================================================================
--- oln/core/2d/point2d.hh (revision 144)
+++ oln/core/2d/point2d.hh (working copy)
@@ -108,6 +108,13 @@
return this->row_ == rhs.row_ && this->col_ == rhs.col_;
}
+ bool impl_fwd_less(const point2d& rhs) const
+ {
+ return
+ this->row_ < rhs.row_
+ || (this->row_ == rhs.row_ && this->col_ < rhs.col_);
+ }
+
const coord_t impl_nth(unsigned i) const
{
precondition(i < 2);
Index: oln/core/3d/dpoint3d.hh
===================================================================
--- oln/core/3d/dpoint3d.hh (revision 144)
+++ oln/core/3d/dpoint3d.hh (working copy)
@@ -99,6 +99,15 @@
return this->row_ == rhs.row_ && this->col_ == rhs.col_ && this->slice_ == rhs.slice_;
}
+ bool impl_fwd_less(const dpoint3d& rhs) const
+ {
+ return
+ this->slice_ < rhs.slice_
+ || (this->slice_ == rhs.slice_
+ && (this->row_ < rhs.row_
+ || (this->row_ == rhs.row_ && this->col_ < rhs.col_)));
+ }
+
const coord_t impl_nth(unsigned i) const
{
precondition(i < 3);
@@ -132,6 +141,11 @@
return dummy;
}
+ unsigned impl_dim() const
+ {
+ return 3;
+ }
+
coord_t slice_, row_, col_;
};
Index: oln/core/3d/niter3d.hh
===================================================================
--- oln/core/3d/niter3d.hh (revision 0)
+++ oln/core/3d/niter3d.hh (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_3D_NITER3D_HH
+# define OLENA_CORE_3D_NITER3D_HH
+
+# include <oln/core/3d/grid3d.hh>
+# include <oln/core/3d/point3d.hh>
+# include <oln/core/3d/dpoint3d.hh>
+# include <oln/core/3d/neighborhood3d.hh>
+
+# include <oln/core/gen/regular_fwd_niter.hh>
+# include <oln/core/gen/regular_bkd_niter.hh>
+
+
+namespace oln {
+
+ typedef regular_fwd_niter<grid3d> fwd_niter3d;
+ typedef regular_bkd_niter<grid3d> bkd_niter3d;
+
+}
+
+
+#endif // ! OLENA_CORE_3D_NITER3D_HH
Index: oln/core/3d/image3d.hh
===================================================================
--- oln/core/3d/image3d.hh (revision 144)
+++ oln/core/3d/image3d.hh (working copy)
@@ -131,4 +131,8 @@
} // end of namespace oln
+# include <oln/core/3d/fwd_piter3d.hh>
+# include <oln/core/3d/bkd_piter3d.hh>
+
+
#endif // ! OLENA_CORE_3D_IMAGE3D_HH
Index: oln/core/3d/bkd_piter3d.hh
===================================================================
--- oln/core/3d/bkd_piter3d.hh (revision 0)
+++ oln/core/3d/bkd_piter3d.hh (revision 0)
@@ -0,0 +1,123 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_3D_BKD_PITER3D_HH
+# define OLENA_CORE_3D_BKD_PITER3D_HH
+
+# include <mlc/contract.hh>
+
+# include <oln/core/abstract/piter.hh>
+# include <oln/core/3d/point3d.hh>
+# include <oln/core/3d/size3d.hh>
+
+
+namespace oln {
+
+ // fwd decl
+ struct bkd_piter3d;
+
+ // props
+ template <>
+ struct set_props < category::piter, bkd_piter3d >
+ {
+ typedef point3d point_type;
+ typedef size3d size_type;
+ };
+
+
+
+ struct bkd_piter3d : public abstract::piter< bkd_piter3d >
+ {
+ typedef bkd_piter3d self_type;
+ typedef abstract::piter<self_type> super_type;
+
+ bkd_piter3d(const size3d& size) :
+ super_type(size)
+ {
+ this->invalidate();
+ }
+
+ friend class abstract::iter<self_type>;
+ friend class abstract::piter<self_type>;
+
+ protected:
+
+ void impl_start()
+ {
+ this->p_.row() = this->s_.nrows() - 1;
+ this->p_.col() = this->s_.ncols() - 1;
+ this->p_.slice() = this->s_.nslices() - 1;
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ }
+
+ bool impl_is_valid() const
+ {
+ precondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ return this->p_.slice() >= 0;
+ }
+
+ void impl_next()
+ {
+ precondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ precondition(this->p_.row() >= 0 && this->p_.row() < this->s_.nrows() &&
+ this->p_.col() >= 0 && this->p_.col() < this->s_.ncols() &&
+ this->p_.slice() >= 0 && this->p_.slice() < this->s_.nslices());
+ --this->p_.col();
+ if (this->p_.col() >= 0)
+ return;
+ this->p_.col() = this->s_.ncols() - 1;
+; --this->p_.row();
+ if (this->p_.row() >= 0)
+ return;
+ this->p_.row() = this->s_.nrows() - 1;
+ --this->p_.slice();
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ }
+
+ void impl_invalidate()
+ {
+ this->p_.row() = -1;
+ this->p_.col() = -1;
+ this->p_.slice() = -1;
+ postcondition(this->p_.row().is_defined() &&
+ this->p_.col().is_defined() &&
+ this->p_.slice().is_defined());
+ }
+
+ };
+}
+
+
+#endif // ! OLENA_CORE_3D_BKD_PITER3D_HH
Index: oln/core/3d/qiter3d.hh
===================================================================
--- oln/core/3d/qiter3d.hh (revision 0)
+++ oln/core/3d/qiter3d.hh (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_3D_QITER3D_HH
+# define OLENA_CORE_3D_QITER3D_HH
+
+# include <oln/core/3d/grid3d.hh>
+# include <oln/core/3d/point3d.hh>
+# include <oln/core/3d/dpoint3d.hh>
+# include <oln/core/3d/window3d.hh>
+
+# include <oln/core/gen/regular_fwd_qiter.hh>
+# include <oln/core/gen/regular_bkd_qiter.hh>
+
+
+namespace oln {
+
+ typedef regular_fwd_qiter<grid3d> fwd_qiter3d;
+ typedef regular_bkd_qiter<grid3d> bkd_qiter3d;
+
+}
+
+
+#endif // ! OLENA_CORE_3D_QITER3D_HH
Index: oln/core/3d/window3d.hh
===================================================================
--- oln/core/3d/window3d.hh (revision 144)
+++ oln/core/3d/window3d.hh (working copy)
@@ -28,9 +28,10 @@
#ifndef OLENA_CORE_WINDOW3D_HH
# define OLENA_CORE_WINDOW3D_HH
-# include <oln/core/gen/regular_window.hh>
# include <oln/core/3d/dpoint3d.hh>
# include <oln/core/3d/grid3d.hh>
+# include <oln/core/gen/regular_window.hh>
+# include <oln/core/3d/qiter3d.hh>
namespace oln {
Index: oln/core/3d/neighborhood3d.hh
===================================================================
--- oln/core/3d/neighborhood3d.hh (revision 0)
+++ oln/core/3d/neighborhood3d.hh (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_NEIGHBORHOOD3D_HH
+# define OLENA_CORE_NEIGHBORHOOD3D_HH
+
+# include <oln/core/3d/window3d.hh>
+# include <oln/core/gen/regular_neighborhood.hh>
+# include <oln/core/3d/niter3d.hh>
+
+
+namespace oln {
+
+ typedef regular_neighborhood< grid3d > neighborhood3d;
+
+ inline const neighborhood3d&
+ neighb_c6()
+ {
+ static const neighborhood3d neighb(win_c6_only());
+ return neighb;
+ }
+
+ inline const neighborhood3d&
+ neighb_c18()
+ {
+ static const neighborhood3d neighb(win_c18_only());
+ return neighb;
+ }
+
+ inline const neighborhood3d&
+ neighb_c26()
+ {
+ static const neighborhood3d neighb(win_c26_only());
+ return neighb;
+ }
+
+
+} // end of namespace oln
+
+
+#endif // OLENA_CORE_NEIGHBORHOOD3D_HH
Index: oln/core/3d/point3d.hh
===================================================================
--- oln/core/3d/point3d.hh (revision 144)
+++ oln/core/3d/point3d.hh (working copy)
@@ -104,6 +104,15 @@
this->col_ == rhs.col_;
}
+ bool impl_fwd_less(const point3d& rhs) const
+ {
+ return
+ this->slice_ < rhs.slice_
+ || (this->slice_ == rhs.slice_
+ && (this->row_ < rhs.row_
+ || (this->row_ == rhs.row_ && this->col_ < rhs.col_)));
+ }
+
const point3d impl_plus(const dpoint3d& rhs) const;
const dpoint3d impl_minus(const point3d& rhs) const;
Index: oln/core/any/grid.hh
===================================================================
--- oln/core/any/grid.hh (revision 144)
+++ oln/core/any/grid.hh (working copy)
@@ -38,6 +38,7 @@
struct any_grid;
struct any_point;
struct any_dpoint;
+ struct any_size;
struct any_coord;
// super type
@@ -54,6 +55,7 @@
typedef any_point point_type;
typedef any_dpoint dpoint_type;
typedef any_coord coord_type;
+ typedef any_size size_type;
typedef mlc::value<unsigned,0> dimvalue_type;
};
Index: oln/core/any/point.hh
===================================================================
--- oln/core/any/point.hh (revision 144)
+++ oln/core/any/point.hh (working copy)
@@ -29,6 +29,7 @@
# define OLENA_CORE_ANY_POINT_HH
# include <iostream>
+# include <mlc/contract.hh>
# include <oln/core/abstract/point.hh>
# include <oln/core/abstract/dpoint.hh>
# include <oln/core/any/grid.hh>
@@ -53,6 +54,19 @@
struct any_point : public abstract::point < any_point >
{
+ any_point()
+ {}
+
+ friend class abstract::point<any_point>;
+
+ protected:
+
+ bool impl_fwd_less(const any_point& rhs) const
+ {
+ precondition(0);
+ return false;
+ }
+
bool impl_eq(const exact_type& rhs) const
{
return this->exact().impl_eq(rhs.exact());
Index: oln/core/any/dpoint.hh
===================================================================
--- oln/core/any/dpoint.hh (revision 144)
+++ oln/core/any/dpoint.hh (working copy)
@@ -29,6 +29,7 @@
# define OLENA_CORE_ANY_DPOINT_HH
# include <iostream>
+# include <mlc/contract.hh>
# include <oln/core/abstract/dpoint.hh>
# include <oln/core/any/point.hh>
@@ -45,6 +46,8 @@
struct any_dpoint : public abstract::dpoint < any_dpoint >
{
+ any_dpoint()
+ {}
template <typename D>
const any_dpoint operator+(const abstract::dpoint<D>& rhs) const
@@ -64,6 +67,12 @@
protected:
+ bool impl_fwd_less(const any_dpoint& rhs) const
+ {
+ precondition(0);
+ return false;
+ }
+
bool impl_eq(const any_dpoint& rhs) const
{
return true;
@@ -82,6 +91,11 @@
return dummy;
}
+ unsigned impl_dim() const
+ {
+ return 0;
+ }
+
};
} // end of namespace oln
Index: oln/core/gen/regular_niter.hh
===================================================================
--- oln/core/gen/regular_niter.hh (revision 144)
+++ oln/core/gen/regular_niter.hh (working copy)
@@ -28,13 +28,9 @@
#ifndef OLENA_CORE_GEN_REGULAR_NITER_HH
# define OLENA_CORE_GEN_REGULAR_NITER_HH
-# include <vector>
-
# include <mlc/contract.hh>
# include <oln/core/abstract/niter.hh>
-# include <oln/core/abstract/grid.hh>
-# include <oln/core/abstract/point.hh>
-# include <oln/core/abstract/dpoint.hh>
+# include <oln/core/gen/regular_neighborhood.hh>
namespace oln {
@@ -52,12 +48,8 @@
template <typename G, typename E>
struct set_props < category::niter, abstract::regular_niter<G,E> >
{
- typedef G grid_type;
- typedef oln_grd_type_of(G, point) point_type;
- typedef oln_grd_type_of(G, dpoint) dpoint_type;
-
- // FIXME: uncomment when class exists
-// typedef regular_neighborhood<G> neighb_type;
+ typedef oln_grd_type_of(G, point) point_type;
+ typedef regular_neighborhood<G> neighb_type;
};
@@ -67,27 +59,37 @@
template <typename G, typename E>
struct regular_niter : public niter<E>
{
+ typedef niter<E> super_type;
- /// typedefs
- typedef niter<E> super_type;
- typedef oln_nit_type_of(E, point) point_type;
- typedef oln_nit_type_of(E, dpoint) dpoint_type;
- typedef oln_nit_type_of(E, neighb) neighb_type;
+ typedef oln_grd_type_of(G, coord) coord_type;
+ typedef oln_grd_type_of(G, point) point_type;
+ typedef oln_grd_type_of(G, dpoint) dpoint_type;
- const point_type impl_cast_point() const
+ typedef oln_grd_type_of(G, dimvalue) dimvalue_type;
+ static const unsigned dim = dimvalue_type::val;
+
+ regular_niter(const regular_neighborhood<G>& nbh) :
+ super_type(nbh)
{
+ }
+
+ const coord_type nth(unsigned i) const
+ {
+ precondition(i < dim);
precondition(this->is_valid());
- return this->p_ + *(this->dp_cur_);
+ return point_type(*this).nth(i);
}
protected:
- regular_niter(const neighb_type& nbh) :
- super_type(nbh)
+ int pos_;
+
+ const point_type impl_cast_point() const
{
+ precondition(this->is_valid());
+ return this->p_ + this->nbh_.dp(this->pos_);
}
- typename std::vector<dpoint_type>::const_iterator dp_cur_;
};
} // end of namespace oln::abstract
Index: oln/core/gen/regular_fwd_niter.hh
===================================================================
--- oln/core/gen/regular_fwd_niter.hh (revision 144)
+++ oln/core/gen/regular_fwd_niter.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory
+// Copyright (C) 2005 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,12 +28,10 @@
#ifndef OLENA_CORE_GEN_REGULAR_FWD_NITER_HH
# define OLENA_CORE_GEN_REGULAR_FWD_NITER_HH
+# include <oln/core/gen/image_with_nbh.hh>
# include <oln/core/gen/regular_niter.hh>
-# include <oln/core/2d/neighborhood2d.hh>
-# include <oln/core/gen/image_with_nbh.hh>
-
namespace oln {
// fwd decl
@@ -43,19 +41,12 @@
template <typename G>
struct set_super_type < regular_fwd_niter<G> > { typedef abstract::regular_niter< G, regular_fwd_niter<G> > ret; };
- // props
- template <typename G>
- struct set_props < category::niter, regular_fwd_niter<G> >
- {
- typedef neighborhood2d neighb_type; // FIXME: see FIXME in regular_niter
- };
-
template <typename G>
struct regular_fwd_niter : public abstract::regular_niter< G, regular_fwd_niter<G> >
{
typedef regular_fwd_niter<G> self_type;
- typedef abstract::regular_niter< G, self_type > super_type;
+ typedef abstract::regular_niter<G, self_type> super_type;
template <typename I>
regular_fwd_niter(const abstract::image_with_nbh<I>& image) :
@@ -69,24 +60,22 @@
void impl_start()
{
- this->dp_cur_ = this->dp_.begin();
+ this->pos_ = 0;
}
void impl_next()
{
- precondition(this->is_valid());
- ++(this->dp_cur_);
+ ++(this->pos_);
}
bool impl_is_valid() const
{
- return this->dp_cur_ != this->dp_.end();
+ return this->pos_ != this->nbh_.card();
}
void impl_invalidate()
{
- this->dp_cur_ = this->dp_.end();
- postcondition(! this->is_valid());
+ this->pos_ = this->nbh_.card();
}
};
Index: oln/core/gen/regular_bkd_niter.hh
===================================================================
--- oln/core/gen/regular_bkd_niter.hh (revision 0)
+++ oln/core/gen/regular_bkd_niter.hh (revision 0)
@@ -0,0 +1,87 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_GEN_REGULAR_BKD_NITER_HH
+# define OLENA_CORE_GEN_REGULAR_BKD_NITER_HH
+
+# include <oln/core/gen/image_with_nbh.hh>
+# include <oln/core/gen/regular_niter.hh>
+
+
+namespace oln {
+
+ // fwd decl
+ template <typename G> struct regular_bkd_niter;
+
+ // super type
+ template <typename G>
+ struct set_super_type < regular_bkd_niter<G> > { typedef abstract::regular_niter< G, regular_bkd_niter<G> > ret; };
+
+
+ template <typename G>
+ struct regular_bkd_niter : public abstract::regular_niter< G, regular_bkd_niter<G> >
+ {
+ typedef regular_bkd_niter<G> self_type;
+ typedef abstract::regular_niter<G, self_type> super_type;
+
+ template <typename I>
+ regular_bkd_niter(const abstract::image_with_nbh<I>& image) :
+ super_type(image.nbh_get())
+ {
+ }
+
+ friend class abstract::iter<self_type>;
+
+ protected:
+
+ void impl_start()
+ {
+ this->pos_ = this->nbh_.card() - 1;
+ }
+
+ void impl_next()
+ {
+ --(this->pos_);
+ }
+
+ bool impl_is_valid() const
+ {
+ return this->pos_ != -1;
+ }
+
+ void impl_invalidate()
+ {
+ this->pos_ = -1;
+ }
+
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_REGULAR_BKD_NITER_HH
Index: oln/core/gen/regular_fwd_qiter.hh
===================================================================
--- oln/core/gen/regular_fwd_qiter.hh (revision 144)
+++ oln/core/gen/regular_fwd_qiter.hh (working copy)
@@ -25,65 +25,35 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLENA_CORE_REGULAR_FWD_QITER_HH
-# define OLENA_CORE_REGULAR_FWD_QITER_HH
+#ifndef OLENA_CORE_GEN_REGULAR_FWD_QITER_HH
+# define OLENA_CORE_GEN_REGULAR_FWD_QITER_HH
-# include <oln/core/abstract/grid.hh>
-# include <oln/core/abstract/qiter.hh>
-# include <oln/core/gen/regular_window.hh>
+# include <oln/core/gen/regular_qiter.hh>
namespace oln {
// fwd decl
- template <typename G>
- struct regular_fwd_qiter;
+ template <typename G> struct regular_fwd_qiter;
// category
template <typename G>
- struct set_super_type< regular_fwd_qiter<G> > { typedef abstract::qiter< regular_fwd_qiter<G> > ret; };
+ struct set_super_type< regular_fwd_qiter<G> > { typedef abstract::regular_qiter< G, regular_fwd_qiter<G> > ret; };
- // props
- template <typename G>
- struct set_props < category::qiter, regular_fwd_qiter<G> >
- {
- typedef regular_window<G> window_type;
- };
-
template <typename G>
- struct regular_fwd_qiter : public abstract::qiter< regular_fwd_qiter<G> >
+ struct regular_fwd_qiter : public abstract::regular_qiter< G, regular_fwd_qiter<G> >
{
typedef regular_fwd_qiter<G> self_type;
- typedef abstract::qiter<self_type> super_type;
+ typedef abstract::regular_qiter<G, self_type> super_type;
- typedef oln_grd_type_of(G, coord) coord_type;
- typedef oln_grd_type_of(G, dpoint) dpoint_type;
-
regular_fwd_qiter(const regular_window<G>& win) :
super_type(win)
{
this->invalidate();
}
- const coord_type nth(unsigned i) const
- {
- return this->win_[this->pos_].nth(i);
- }
-
- coord_type& nth(unsigned i)
- {
- return this->win_[this->pos_].nth(i);
- }
-
- operator dpoint_type() const
- {
- precondition(this->is_valid());
- return this->win_[this->pos_];
- }
-
friend class abstract::iter<self_type>;
- friend class abstract::qiter<self_type>;
protected:
@@ -107,11 +77,9 @@
this->pos_ = this->win_.card();
}
- unsigned pos_;
-
};
} // end of namespace oln
-#endif // OLENA_CORE_REGULAR_FWD_QITER_HH
+#endif // ! OLENA_CORE_GEN_REGULAR_FWD_QITER_HH
Index: oln/core/gen/regular_bkd_qiter.hh
===================================================================
--- oln/core/gen/regular_bkd_qiter.hh (revision 0)
+++ oln/core/gen/regular_bkd_qiter.hh (revision 0)
@@ -0,0 +1,86 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_REGULAR_BKD_QITER_HH
+# define OLENA_CORE_REGULAR_BKD_QITER_HH
+
+# include <oln/core/gen/regular_qiter.hh>
+
+
+namespace oln {
+
+ // bkd decl
+ template <typename G>
+ struct regular_bkd_qiter;
+
+ // category
+ template <typename G>
+ struct set_super_type< regular_bkd_qiter<G> > { typedef abstract::regular_qiter< G, regular_bkd_qiter<G> > ret; };
+
+
+ template <typename G>
+ struct regular_bkd_qiter : public abstract::regular_qiter< G, regular_bkd_qiter<G> >
+ {
+ typedef regular_bkd_qiter<G> self_type;
+ typedef abstract::regular_qiter<G, self_type> super_type;
+
+ regular_bkd_qiter(const regular_window<G>& win) :
+ super_type(win)
+ {
+ this->invalidate();
+ }
+
+ friend class abstract::iter<self_type>;
+
+ protected:
+
+ void impl_start()
+ {
+ this->pos_ = this->win_.card() - 1;
+ }
+
+ void impl_next()
+ {
+ --(this->pos_);
+ }
+
+ bool impl_is_valid() const
+ {
+ return this->pos_ != -1;
+ }
+
+ void impl_invalidate()
+ {
+ this->pos_ = -1;
+ }
+
+ };
+
+} // end of namespace oln
+
+
+#endif // OLENA_CORE_REGULAR_BKD_QITER_HH
Index: oln/core/gen/regular_qiter.hh
===================================================================
--- oln/core/gen/regular_qiter.hh (revision 0)
+++ oln/core/gen/regular_qiter.hh (revision 0)
@@ -0,0 +1,100 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_GEN_REGULAR_QITER_HH
+# define OLENA_CORE_GEN_REGULAR_QITER_HH
+
+# include <oln/core/abstract/grid.hh>
+# include <oln/core/abstract/qiter.hh>
+# include <oln/core/gen/regular_window.hh>
+
+
+namespace oln {
+
+ // fwd decl
+ namespace abstract {
+ template <typename G, typename E> struct regular_qiter;
+ }
+
+ // category
+ template <typename G, typename E>
+ struct set_super_type< abstract::regular_qiter<G,E> > { typedef abstract::qiter<E> ret; };
+
+ // props
+ template <typename G, typename E>
+ struct set_props < category::qiter, abstract::regular_qiter<G,E> >
+ {
+ typedef G grid_type;
+ typedef regular_window<G> window_type;
+ };
+
+
+ namespace abstract
+ {
+
+ template <typename G, typename E>
+ struct regular_qiter : public qiter<E>
+ {
+ typedef qiter<E> super_type;
+
+ typedef oln_grd_type_of(G, coord) coord_type;
+ typedef oln_grd_type_of(G, point) point_type;
+ typedef oln_grd_type_of(G, dpoint) dpoint_type;
+
+ typedef oln_grd_type_of(G, dimvalue) dimvalue_type;
+ static const unsigned dim = dimvalue_type::val;
+
+ regular_qiter(const regular_window<G>& win) :
+ super_type(win)
+ {
+ }
+
+ const coord_type nth(unsigned i) const
+ {
+ precondition(i < dim);
+ precondition(this->is_valid());
+ return point_type(*this).nth(i);
+ }
+
+ protected:
+
+ int pos_;
+
+ const point_type impl_cast_point() const
+ {
+ precondition(this->is_valid());
+ return this->p_ + this->win_.dp(this->pos_);
+ }
+
+ };
+
+ } // end of namespace abstract::oln
+
+} // end of namespace oln
+
+
+#endif // OLENA_CORE_GEN_REGULAR_QITER_HH
Index: oln/core/gen/regular_window.hh
===================================================================
--- oln/core/gen/regular_window.hh (revision 144)
+++ oln/core/gen/regular_window.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory
+// Copyright (C) 2005 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,11 +29,15 @@
# define OLENA_CORE_GEN_REGULAR_WINDOW_HH
# include <iostream>
-
+# include <algorithm>
+# include <iterator>
+# include <vector>
+# include <set>
+
# include <mlc/contract.hh>
-# include <oln/core/abstract/window.hh>
# include <oln/core/abstract/grid.hh>
-# include <oln/core/accum.hh>
+# include <oln/core/abstract/dpoint.hh>
+# include <oln/core/abstract/window.hh>
namespace oln {
@@ -49,15 +53,13 @@
template <typename G>
struct set_props< category::window, regular_window<G> >
{
- typedef oln_grd_type_of(G, point) point_type;
+ typedef G grid_type;
typedef oln_grd_type_of(G, dpoint) dpoint_type;
typedef oln_grd_type_of(G, size) size_type;
- typedef regular_fwd_qiter<G> fwd_qiter_type;
+ typedef regular_fwd_qiter<G> fwd_iter_type;
// typedef regular_fwd_dpiter<G> fwd_dpiter_type; // FIXME: later...
};
-
-
-
+
template <typename G>
class regular_window : public abstract::window< regular_window<G> >
{
@@ -65,9 +67,11 @@
public:
typedef regular_window<G> self_type;
- typedef oln_wn_type_of(self_type, dpoint) dpoint_type;
+ typedef oln_grd_type_of(G, coord) coord_type;
+ typedef oln_grd_type_of(G, dpoint) dpoint_type;
typedef oln_grd_type_of(G, dimvalue) dimvalue_type;
+
static const unsigned dim = dimvalue_type::val;
regular_window() :
@@ -76,8 +80,7 @@
{
}
- regular_window(unsigned n,
- const oln_grd_type_of(G, coord) crd[]) :
+ regular_window(unsigned n, const coord_type crd[]) :
dp_(),
delta_(0)
{
@@ -92,71 +95,63 @@
}
}
- bool has(const dpoint_type& dp) const
- {
- return std::find(this->dp_.begin(), this->dp_.end(), dp) != dp_.end();
- }
-
self_type& add(const dpoint_type& dp)
{
- if (! this->has(dp))
- this->dp_.push_back(dp);
- this->delta_update(dp);
+ this->dpset_.insert(dp);
+ this->dp_.clear();
+ std::copy(this->dpset_.begin(), this->dpset_.end(),
+ std::back_inserter(this->dp_));
+ this->delta_update_(dp);
return *this;
}
- coord_t delta_update(const dpoint_type& dp)
+ coord_type delta() const
{
- for (unsigned c = 0; c < dim; ++c)
- this->delta_(abs(dp.nth(c)));
return this->delta_;
}
- coord_t get_delta() const
- {
- return this->delta_;
- }
-
unsigned card() const
{
return this->dp_.size();
}
- const dpoint_type at(unsigned i) const
+ const dpoint_type dp(unsigned i) const
{
precondition(i < this->card());
- return dp_[i];
+ return this->dp_[i];
}
- // FIXME: redundant...
- dpoint_type dp(unsigned i) const
+ const self_type operator-() const
{
- return this->at(i);
+ self_type tmp;
+ for (unsigned i = 0; i < this->card(); ++i)
+ tmp.add(- this->dp_[i]);
+ return tmp;
}
- // FIXME: redundant...
- const dpoint_type operator[](unsigned i) const
+ void sym()
{
- return this->at(i);
+ *this = - *this;
}
-// const self_type operator-() const
-// {
-// self_type tmp;
-// for (unsigned i = 0; i < this->card(), ++i)
-// tmp.add(- this->at(i));
-// return tmp;
-// }
-
- void sym()
+ const std::vector<dpoint_type>& get_dp() const
{
- *this = - *this;
+ return this->dp_;
}
private:
-
+
+ std::set<dpoint_type, fwd_less_dpoint> dpset_;
std::vector<dpoint_type> dp_;
- max_accumulator<coord_t> delta_;
+ coord_type delta_;
+
+ void delta_update_(const dpoint_type& dp)
+ {
+ for (unsigned c = 0; c < dim; ++c)
+ if (abs(dp.nth(c)) > this->delta_)
+ this->delta_ = abs(dp.nth(c));
+ }
+
};
@@ -167,16 +162,12 @@
template<class G>
std::ostream& operator<<(std::ostream& ostr, const oln::regular_window<G>& win)
{
- unsigned c = win.card();
ostr << "[";
- for (unsigned i = 0; i < c; ++i)
+ for (unsigned i = 0; i < win.card(); ++i)
ostr << win.dp(i);
ostr << "]";
return ostr;
}
-# include <oln/core/gen/regular_fwd_qiter.hh>
-
-
-#endif // OLENA_CORE_GEN_REGULAR_WINDOW_HH
+#endif // ! OLENA_CORE_GEN_REGULAR_WINDOW_HH
Index: oln/core/gen/regular_neighborhood.hh
===================================================================
--- oln/core/gen/regular_neighborhood.hh (revision 0)
+++ oln/core/gen/regular_neighborhood.hh (revision 0)
@@ -0,0 +1,144 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_GEN_REGULAR_NEIGHBORHOOD_HH
+# define OLENA_CORE_GEN_REGULAR_NEIGHBORHOOD_HH
+
+# include <oln/core/abstract/neighborhood.hh>
+# include <oln/core/gen/regular_window.hh>
+
+
+namespace oln {
+
+ // fwd decl
+ template <typename G> class regular_neighborhood;
+
+ // super_type
+ template <typename G> struct set_super_type< regular_neighborhood<G> > { typedef abstract::neighborhood< regular_neighborhood<G> > ret; };
+
+ // props
+ template <typename G>
+ struct set_props< category::neighborhood, regular_neighborhood<G> >
+ {
+ typedef oln_grd_type_of(G, dpoint) dpoint_type;
+ typedef oln_grd_type_of(G, size) size_type;
+ typedef regular_window<G> window_type;
+ };
+
+
+
+ template <typename G>
+ class regular_neighborhood : public abstract::neighborhood< regular_neighborhood<G> >
+ {
+
+ public:
+
+ typedef regular_neighborhood<G> self_type;
+
+ typedef oln_grd_type_of(G, coord) coord_type;
+ typedef oln_grd_type_of(G, dpoint) dpoint_type;
+ typedef oln_grd_type_of(G, dimvalue) dimvalue_type;
+
+ static const unsigned dim = dimvalue_type::val;
+
+ regular_neighborhood()
+ {
+ }
+
+ regular_neighborhood(const regular_window<G>& win)
+ {
+ for (unsigned i = 0; i < win.card(); ++i)
+ this->add(win.dp(i));
+ }
+
+ regular_neighborhood(unsigned n, const coord_type crd[])
+ {
+ precondition(n != 0);
+ // FIXME: size of crd wrt n
+ for (unsigned i = 0; i < n; ++i)
+ {
+ dpoint_type dp;
+ for (unsigned c = 0; c < dim; ++c)
+ dp.nth(c) = crd[i * dim + c];
+ this->add(dp);
+ }
+ }
+
+ self_type& add(const dpoint_type& dp)
+ {
+ precondition(dp != -dp); // means dp is not (0)
+ this->win_.add(dp);
+ this->win_.add(-dp);
+ return *this;
+ }
+
+ coord_type delta() const
+ {
+ return this->win_.delta();
+ }
+
+ unsigned card() const
+ {
+ return this->win_.card();
+ }
+
+ const dpoint_type dp(unsigned i) const
+ {
+ precondition(i < this->card());
+ return this->win_.dp(i);
+ }
+
+ const std::vector<dpoint_type>& get_dp() const
+ {
+ return this->win_.get_dp();
+ }
+
+ const regular_neighborhood<G>& get_win() const
+ {
+ return this->win_;
+ }
+
+ private:
+
+ /// Only attribute (to delegate to).
+ regular_window<G> win_;
+
+ };
+
+
+} // end of namespace oln
+
+
+
+template<class G>
+std::ostream& operator<<(std::ostream& ostr, const oln::regular_neighborhood<G>& nbh)
+{
+ return ostr << nbh.get_win();
+}
+
+
+#endif // OLENA_CORE_GEN_REGULAR_NEIGHBORHOOD_HH
Index: oln/basics3d.hh
===================================================================
--- oln/basics3d.hh (revision 144)
+++ oln/basics3d.hh (working copy)
@@ -33,7 +33,8 @@
# include <oln/core/3d/grid3d.hh>
# include <oln/core/3d/size3d.hh>
# include <oln/core/3d/point3d.hh>
-# include <oln/core/3d/dpoint3d.hh>
# include <oln/core/3d/image3d.hh>
+# include <oln/core/3d/window3d.hh>
+# include <oln/core/3d/neighborhood3d.hh>
#endif // ! OLENA_BASICS3D_HH
Index: oln/makefile.src
===================================================================
--- oln/makefile.src (revision 144)
+++ oln/makefile.src (working copy)
@@ -22,28 +22,39 @@
convert/value_to_point.hh \
\
core/1d/array1d.hh \
+ core/1d/bkd_piter1d.hh \
core/1d/dpoint1d.hh \
core/1d/fwd_piter1d.hh \
core/1d/image1d.hh \
+ core/1d/neighborhood1d.hh \
+ core/1d/niter1d.hh \
core/1d/point1d.hh \
+ core/1d/qiter1d.hh \
core/1d/size1d.hh \
\
core/2d/array2d.hh \
core/2d/bkd_piter2d.hh \
core/2d/dpoint2d.hh \
- core/2d/fwd_niter2d.hh \
core/2d/fwd_piter2d.hh \
core/2d/image2d.hh \
core/2d/neighborhood2d.hh \
+ core/2d/niter2d.hh \
core/2d/point2d.hh \
+ core/2d/qiter2d.hh \
core/2d/size2d.hh \
core/2d/window2d.hh \
\
core/3d/array3d.hh \
+ core/3d/bkd_piter3d.hh \
core/3d/dpoint3d.hh \
+ core/3d/fwd_niter3d.hh \
core/3d/fwd_piter3d.hh \
+ core/3d/fwd_qiter3d.hh \
core/3d/image3d.hh \
+ core/3d/neighborhood3d.hh \
+ core/3d/niter3d.hh \
core/3d/point3d.hh \
+ core/3d/qiter3d.hh \
core/3d/size3d.hh \
\
core/abstract/data_storage.hh \
@@ -90,9 +101,13 @@
core/gen/identity.hh \
core/gen/image_with_nbh.hh \
core/gen/internal/value_box.hh \
- core/gen/regular_fwd_niter.hh.hh \
- core/gen/regular_fwd_qiter.hh.hh \
- core/gen/regular_niter.hh.hh \
+ core/gen/regular_bkd_niter.hh \
+ core/gen/regular_bkd_qiter.hh \
+ core/gen/regular_fwd_niter.hh \
+ core/gen/regular_fwd_qiter.hh \
+ core/gen/regular_neighborhood.hh \
+ core/gen/regular_niter.hh \
+ core/gen/regular_qiter.hh \
core/gen/regular_window.hh \
\
core/pw/abstract/binary_function.hh \
Index: oln/morpho/cc_tarjan.hh
===================================================================
--- oln/morpho/cc_tarjan.hh (revision 144)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -156,7 +156,7 @@
{
std::vector<dpoint2d> neighb = misc::get_inferior(this->ng);
oln_type_of(I, bkd_piter) p(this->input.size());
- for_all(p)
+ for_all_p (p)
if (this->input[p])
{
make_set(p);
@@ -174,7 +174,7 @@
oln_type_of(I, fwd_piter) p(this->input.size());
level::fill(this->output, 0);
ncomps = 0;
- for_all(p)
+ for_all_p (p)
if (this->input[p])
{
oln_type_of(I, point) q = parent[p];
Index: oln/morpho/stat.hh
===================================================================
--- oln/morpho/stat.hh (revision 144)
+++ oln/morpho/stat.hh (working copy)
@@ -30,7 +30,8 @@
# include <mlc/cmp.hh>
# include <ntg/bin.hh>
-# include <oln/basics.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/window.hh>
namespace oln {
@@ -63,18 +64,19 @@
** \arg win The window to use.
*/
static V
- max(const I& input, const oln_type_of(I, point)& p, const W& win)
+ max(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
{
- // FIXME: test dim I == dim
- mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure();
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- oln_wn_type_of(W, fwd_qiter) dp(win);
- dp.start();
- V val = input[p + dp];
- for_all_remaining (dp)
- if (input.hold(p + dp))
- if (val < input[p + dp].value())
- val = input[p + dp].value();
+ oln_wn_type_of(W, fwd_iter) q(win);
+ q.start_at_p(p);
+ V val = input[q];
+ for_all_remaining_q (q)
+ if (input.hold(q))
+ if (val < input[q].value())
+ val = input[q].value();
return val;
}
@@ -89,18 +91,19 @@
** \arg win The window to use.
*/
static V
- min(const I& input, const oln_type_of(I, point)& p, const W& win)
+ min(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
{
- // FIXME: test dim I == dim W
- mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure();
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
- oln_wn_type_of(W, fwd_qiter) dp(win);
- dp.start();
- V val = input[p + dp];
- for_all_remaining (dp)
- if (input.hold(p + dp))
- if (val > input[p + dp].value())
- val = input[p + dp].value();
+ oln_wn_type_of(W, fwd_iter) q(win);
+ q.start_at(p);
+ V val = input[q];
+ for_all_remaining (q)
+ if (input.hold(q))
+ if (val > input[q].value())
+ val = input[q].value();
return val;
}
@@ -112,25 +115,29 @@
struct stat_<I, W, ntg::bin>
{
static ntg::bin
- max(const I& input, const oln_type_of(I, point)& p, const W& win)
+ max(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
{
- mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure();
- oln_wn_type_of(W, fwd_qiter) dp(win);
- for_all (dp)
- if (input.hold(p + dp))
- if (input[p + dp] == true)
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ oln_wn_type_of(W, fwd_iter) q(win);
+ for_all_q_of_p (q, p)
+ if (input.hold(q))
+ if (input[q] == true)
return true;
return false;
}
static ntg::bin
- min(const I& input, const oln_type_of(I, point)& p, const W& win)
+ min(const abstract::image<I>& input,
+ const oln_type_of(I, point)& p,
+ const abstract::window<W>& win)
{
- mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure();
- oln_wn_type_of(W, fwd_qiter) dp(win);
- for_all (dp)
- if (input.hold(p + dp))
- if (input[p + dp] == false)
+ mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
+ oln_wn_type_of(W, fwd_iter) q(win);
+ for_all_q_of_p (q, p)
+ if (input.hold(q))
+ if (input[q] == false)
return false;
return true;
}
Index: oln/morpho/geodesic_erosion.hh
===================================================================
--- oln/morpho/geodesic_erosion.hh (revision 0)
+++ oln/morpho/geodesic_erosion.hh (revision 0)
@@ -0,0 +1,132 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_MORPHO_GEODESIC_EROSION_HH
+# define OLENA_MORPHO_GEODESIC_EROSION_HH
+
+# include <mlc/cmp.hh>
+
+# include <oln/core/abstract/image_operator.hh>
+# include <oln/morpho/stat.hh>
+# include <oln/level/compare.hh>
+# include <oln/convert/nbh_to_se.hh>
+# include <oln/arith/max.hh>
+
+# include <oln/core/abstract/neighborhood.hh>
+# include <oln/morpho/erosion.hh>
+
+namespace oln {
+
+ namespace morpho {
+
+ // fwd declaration
+ template <class I1, class I2> struct geodesic_erosion_ret;
+
+ namespace proc {
+
+ template<class I1, class I2>
+ oln_type_of(I1, concrete)
+ geodesic_erosion(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition(marker.size() == mask.size());
+ precondition(level::is_greater_or_equal(marker, mask));
+ oln_type_of(I1, concrete) output(marker.size());
+ marker.border_adapt_copy(marker.nbh_get().delta());
+ oln_type_of(I1, piter) p(marker);
+ for_all_p (p)
+ output[p] = arith::max(morpho::min(marker, p, convert::nbh_to_cse(marker.nbh_get())),
+ mask[p]);
+ return output;
+ }
+
+ } // end of namespace oln::morpho::proc
+
+ } // end of namespace oln::morpho
+
+
+ // super_type
+ template <class I1, class I2>
+ struct set_super_type< morpho::geodesic_erosion_ret<I1, I2> >
+ {
+ typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> > ret;
+ };
+
+
+ namespace morpho {
+
+ template <class I1, class I2>
+ struct geodesic_erosion_ret : public abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> >
+ {
+ typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, geodesic_erosion_ret<I1, I2> > super_type;
+
+ geodesic_erosion_ret(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker, mask)
+ {}
+ };
+
+
+ namespace safe {
+
+ template <class I1, class I2>
+ struct geodesic_erosion : public geodesic_erosion_ret<I1, I2>
+ {
+ typedef geodesic_erosion_ret<I1, I2> super_type;
+
+ geodesic_erosion(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker, mask)
+ {}
+
+ void impl_run()
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition((this->input1).size() == (this->input2).size());
+ precondition(level::is_greater_or_equal(this->input2, this->input1));
+ this->output = arith::max(erosion(this->input1.unbox(), this->input1.unbox().nbh_get()).output.unbox(), this->input2.unbox()).output;
+ }
+ };
+
+ } // end of namespace oln::morpho::safe
+
+ template<class I1, class I2>
+ geodesic_erosion_ret<I1, I2>
+ geodesic_erosion(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask)
+ {
+ safe::geodesic_erosion<I1, I2> tmp(marker, mask);
+ tmp.run();
+ return tmp;
+ }
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+#endif // OLENA_MORPHO_GEODESIC_EROSION_HH
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* tests/morpho/tests/dilation: Perform tests on small images.
* tests/morpho/tests/erosion: Perform tests on small images.
* tests/level/runs: Remove.
* tests/io/tests/2d: Perform tests on small images.
* tests/check/Makefile.flags: Remove optimization flags.
* img/16x16.ppm: New.
* img/16x16.pbm.gz: New.
* img/16x16.pgm.gz: New.
* img/16x16.ppm.gz: New.
* img/16x16.pbm: New.
* img/16x16.pgm: New.
img/16x16.pgm | 5 +++++
img/16x16.ppm | 5 +++++
tests/check/Makefile.flags | 2 +-
tests/io/tests/2d | 12 ++++++------
tests/morpho/tests/dilation | 3 ++-
tests/morpho/tests/erosion | 4 +++-
6 files changed, 22 insertions(+), 9 deletions(-)
Index: tests/morpho/tests/dilation
--- tests/morpho/tests/dilation (revision 142)
+++ tests/morpho/tests/dilation (working copy)
@@ -17,8 +17,9 @@
typedef oln::image2d<ntg::bin> im_type;
im_type ima;
- ima = oln::io::read(rdata("object.pbm"));
+ ima = oln::io::read(rdata("16x16.pbm"));
+ std::cout << oln::utils::md5(oln::morpho::dilation(ima, oln::win_c8p())) << std::endl;
if (oln::utils::md5(oln::morpho::dilation(ima, oln::win_c8p())) == key)
{
std::cout << "OK" << std::endl;
Index: tests/morpho/tests/erosion
--- tests/morpho/tests/erosion (revision 142)
+++ tests/morpho/tests/erosion (working copy)
@@ -17,7 +17,9 @@
typedef oln::image2d<ntg::bin> im_type;
im_type ima;
- ima = oln::io::read(rdata("object.pbm"));
+ ima = oln::io::read(rdata("16x16.pbm"));
+
+ std::cout << oln::utils::md5(oln::morpho::dilation(ima, oln::win_c8p())) << std::endl;
if (oln::utils::md5(oln::morpho::erosion(ima, oln::win_c8p())) == key)
{
std::cout << "OK" << std::endl;
Index: tests/io/tests/2d
--- tests/io/tests/2d (revision 142)
+++ tests/io/tests/2d (working copy)
@@ -38,14 +38,14 @@
typedef oln::image2d<ntg::rgb_8> ima_rgb_8;
typedef oln::image2d<ntg::bin> ima_bin;
- fail |= loadsave< ima_int_u8 >(rdata("lena.pgm"), "lena.pgm");
- fail |= loadsave< ima_bin >(rdata("lena.pbm"), "lena.pbm");
- fail |= loadsave< ima_rgb_8 >(rdata("lena.ppm"), "lena.ppm");
+ fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm"), "16x16.pgm");
+ fail |= loadsave< ima_bin >(rdata("16x16.pbm"), "16x16.pbm");
+ fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm"), "16x16.ppm");
#if HAVE_ZLIB
- fail |= loadsave< ima_bin >(rdata("lena.pbm.gz"), "lena.pbm.gz");
- fail |= loadsave< ima_int_u8 >(rdata("lena.pgm.gz"), "lena.pgm.gz");
- fail |= loadsave< ima_rgb_8 >(rdata("lena.ppm.gz"), "lena.ppm.gz");
+ fail |= loadsave< ima_bin >(rdata("16x16.pbm.gz"), "16x16.pbm.gz");
+ fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
+ fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm.gz"), "16x16.ppm.gz");
#endif
return fail;
Index: tests/check/Makefile.flags
--- tests/check/Makefile.flags (revision 142)
+++ tests/check/Makefile.flags (working copy)
@@ -1,7 +1,7 @@
# -*- Makefile -*-
AM_CXXFLAGS = \
- $(CXXFLAGS_DEBUG) $(CXXFLAGS_OPTIMIZE) \
+ $(CXXFLAGS_DEBUG) \
$(CXXFLAGS_STRICT_ERRORS) $(ZLIB_CXXFLAGS)
AM_CPPFLAGS = \
-I$(top_srcdir)/metalic/tests/check \
Index: img/16x16.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/16x16.ppm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/16x16.pgm.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/16x16.pgm.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/16x16.ppm.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/16x16.ppm.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/16x16.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/16x16.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/16x16.pgm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/16x16.pgm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: img/16x16.pbm.gz
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: img/16x16.pbm.gz
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
--
Damien Thivolle
damien(a)lrde.epita.fr
2
2