https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some 2d window types and refactor window impl hierarchy.
* oln/core/2d/vline2d.hh,
* oln/core/2d/hline2d.hh,
* oln/core/2d/rectangle2d.hh,
* oln/core/internal/window.hh: New.
* oln/core/concept/window.hh (op_unary_minus_): New.
* oln/core/gen/dpoints_piter.hh: Cosmetic change.
* oln/core/gen/window.hh (window_): Rename as...
(gen_window): ...this and inherit from internal::window_.
(fwd_qiter, bkd_qiter, take, impl_op_unary_minus_): Move to...
(internal::window_): ...here.
* oln/core/2d/window2d.hh (window2d): Replace window_ by
gen_window.
* oln/core/internal/window_base.hh (point): New.
* oln/morpho/closing.hh,
* oln/morpho/opening.hh: Fix.
* oln/morpho/erosion.hh (erosion_on_function_): New version on
rectangle2d.
core/2d/hline2d.hh | 94 ++++++++++++++++++++++++++++++++++
core/2d/rectangle2d.hh | 116 +++++++++++++++++++++++++++++++++++++++++++
core/2d/vline2d.hh | 101 +++++++++++++++++++++++++++++++++++++
core/2d/window2d.hh | 27 ++++------
core/concept/window.hh | 11 +++-
core/gen/dpoints_piter.hh | 2
core/gen/window.hh | 55 +++++---------------
core/internal/window.hh | 116 +++++++++++++++++++++++++++++++++++++++++++
core/internal/window_base.hh | 7 +-
morpho/closing.hh | 2
morpho/erosion.hh | 23 +++++++-
morpho/opening.hh | 2
12 files changed, 492 insertions(+), 64 deletions(-)
Index: oln/core/concept/window.hh
--- oln/core/concept/window.hh (revision 927)
+++ oln/core/concept/window.hh (working copy)
@@ -47,6 +47,8 @@
stc_typename(fwd_qiter);
stc_typename(bkd_qiter);
+ Exact op_unary_minus_() const;
+
protected:
Window();
@@ -61,7 +63,14 @@
{
}
-# endif
+ template <typename Exact>
+ Exact
+ Window<Exact>::op_unary_minus_() const
+ {
+ return exact(this)->impl_op_unary_minus_();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/vline2d.hh
--- oln/core/2d/vline2d.hh (revision 0)
+++ oln/core/2d/vline2d.hh (revision 0)
@@ -0,0 +1,101 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_2D_VLINE2D_HH
+# define OLN_CORE_2D_VLINE2D_HH
+
+# include <oln/core/internal/window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ class vline2d;
+
+
+ // Super type.
+ template <>
+ struct super_trait_< vline2d >
+ {
+ typedef internal::window_<vline2d> ret;
+ };
+
+
+ // Virtual types.
+ template <>
+ struct vtypes< vline2d >
+ {
+ typedef point2d point;
+ };
+
+
+ /// 2D vertical line window.
+
+ class vline2d : public internal::window_< vline2d >
+ {
+ public:
+
+ vline2d(unsigned half_length);
+ vline2d(int drow_min, int drow_max);
+
+ private:
+ void init_(int drow_min, int drow_max);
+ void take(); // safety; w/o impl, it provides from calling super::take(dp).
+
+ }; // end of class oln::vline2d
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ vline2d::vline2d(unsigned half_length)
+ {
+ precondition(half_length > 0);
+ this->init_(- half_length, half_length);
+ }
+
+ vline2d::vline2d(int drow_min, int drow_max)
+ {
+ precondition(drow_max > drow_min);
+ this->init_(drow_min, drow_max);
+ }
+
+ void
+ vline2d::init_(int drow_min, int drow_max)
+ {
+ for (int drow = drow_min; drow <= drow_max; ++drow)
+ this->internal::window_<vline2d>::take(dpoint2d(drow, 0));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_VLINE2D_HH
Index: oln/core/2d/hline2d.hh
--- oln/core/2d/hline2d.hh (revision 0)
+++ oln/core/2d/hline2d.hh (revision 0)
@@ -0,0 +1,94 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_2D_HLINE2D_HH
+# define OLN_CORE_2D_HLINE2D_HH
+
+# include <oln/core/internal/window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ class hline2d;
+
+
+ // Super type.
+ template <>
+ struct super_trait_< hline2d >
+ {
+ typedef internal::window_<hline2d> ret;
+ };
+
+
+ // Virtual types.
+ template <>
+ struct vtypes< hline2d >
+ {
+ typedef point2d point;
+ };
+
+
+ /// 2D horizontal line window.
+
+ class hline2d : public internal::window_< hline2d >
+ {
+ public:
+
+ hline2d(unsigned half_length);
+
+ private:
+ void init_(int dcol_min, int dcol_max);
+ void take(); // safety; w/o impl, it provides from calling super::take(dp).
+
+ }; // end of class oln::hline2d
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ hline2d::hline2d(unsigned half_length)
+ {
+ precondition(half_length > 0);
+ this->init_(- half_length, + half_length);
+ }
+
+ void
+ hline2d::init_(int dcol_min, int dcol_max)
+ {
+ for (int dcol = dcol_min; dcol <= dcol_max; ++dcol)
+ this->internal::window_<hline2d>::take(dpoint2d(0, dcol));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_HLINE2D_HH
Index: oln/core/2d/rectangle2d.hh
--- oln/core/2d/rectangle2d.hh (revision 0)
+++ oln/core/2d/rectangle2d.hh (revision 0)
@@ -0,0 +1,116 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_2D_RECTANGLE2D_HH
+# define OLN_CORE_2D_RECTANGLE2D_HH
+
+# include <oln/core/internal/window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ class rectangle2d;
+
+
+ // Super type.
+ template <>
+ struct super_trait_< rectangle2d >
+ {
+ typedef internal::window_<rectangle2d> ret;
+ };
+
+
+ // Virtual types.
+ template <>
+ struct vtypes< rectangle2d >
+ {
+ typedef point2d point;
+ };
+
+
+ /// 2D rectangular window.
+
+ class rectangle2d : public internal::window_< rectangle2d >
+ {
+ public:
+
+ // FIXME: Use instant-init facilities.
+ rectangle2d(unsigned half_height, unsigned half_width);
+
+ unsigned half_height() const;
+ unsigned half_width() const;
+
+ private:
+ void init_(int drow_min, int dcol_min,
+ int drow_max, int dcol_max);
+ void take(); // safety; w/o impl, it provides from calling super::take(dp).
+
+ unsigned half_height_, half_width_;
+
+ }; // end of class oln::rectangle2d
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ rectangle2d::rectangle2d(unsigned half_height, unsigned half_width)
+ {
+ precondition(half_height > 0 and half_width > 0 );
+ this->half_height_ = half_height;
+ this->half_width_ = half_width;
+ this->init_(- half_height, - half_width,
+ + half_height, + half_width);
+ }
+
+ unsigned rectangle2d::half_height() const
+ {
+ return this->half_height_;
+ }
+
+ unsigned rectangle2d::half_width() const
+ {
+ return this->half_width_;
+ }
+
+ void
+ rectangle2d::init_(int drow_min, int dcol_min,
+ int drow_max, int dcol_max)
+ {
+ for (int drow = drow_min; drow <= drow_max; ++drow)
+ for (int dcol = dcol_min; dcol <= dcol_max; ++dcol)
+ this->internal::window_<rectangle2d>::take(dpoint2d(drow, dcol));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_RECTANGLE2D_HH
Index: oln/core/2d/window2d.hh
--- oln/core/2d/window2d.hh (revision 927)
+++ oln/core/2d/window2d.hh (working copy)
@@ -29,46 +29,43 @@
# define OLN_CORE_2D_WINDOW2D_HH
# include <oln/core/gen/window.hh>
-# include <oln/core/2d/dpoint2d.hh>
+# include <oln/core/2d/rectangle2d.hh>
namespace oln
{
// FIXME: window2d should be an actual type, not an alias...
- typedef window_<dpoint2d> window2d;
+ typedef gen_window<dpoint2d> window2d;
- window2d mk_square(unsigned odd_len);
+ rectangle2d mk_square(unsigned odd_len);
# ifndef OLN_INCLUDE_ONLY
- window2d mk_square(unsigned odd_len)
+ rectangle2d mk_square(unsigned odd_len)
{
precondition(odd_len % 2 = 1);
- window2d tmp;
- int half_len = odd_len / 2;
- for (int drow = - half_len; drow <= half_len; ++drow)
- for (int dcol = - half_len; dcol <= half_len; ++dcol)
- tmp.take(dpoint2d(drow, dcol));
+ unsigned half_len = odd_len / 2;
+ rectangle2d tmp(half_len, half_len);
return tmp;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
- extern const window2d win3x3;
- extern const window2d win5x5;
+ extern const rectangle2d win3x3;
+ extern const rectangle2d win5x5;
# ifndef OLN_INCLUDE_ONLY
- const window2d win3x3 = mk_square(3);
- const window2d win5x5 = mk_square(5);
+ const rectangle2d win3x3 = mk_square(3);
+ const rectangle2d win5x5 = mk_square(5);
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 927)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -187,7 +187,7 @@
{
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/window.hh
--- oln/core/gen/window.hh (revision 927)
+++ oln/core/gen/window.hh (working copy)
@@ -28,9 +28,7 @@
#ifndef OLN_CORE_GEN_WINDOW_HH
# define OLN_CORE_GEN_WINDOW_HH
-# include <oln/core/internal/window_base.hh>
-# include <oln/core/internal/dpoints_impl.hh>
-# include <oln/core/gen/dpoints_piter.hh>
+# include <oln/core/internal/window.hh>
namespace oln
@@ -38,72 +36,47 @@
// Fwd decl.
- template <typename Dp> class window_;
+ template <typename Dp> class gen_window;
// Super type.
template <typename Dp>
- struct super_trait_< window_<Dp> >
+ struct super_trait_< gen_window<Dp> >
{
- typedef window_<Dp> current__;
- typedef internal::window_base_<current__> ret;
+ typedef gen_window<Dp> current__;
+ typedef internal::window_<current__> ret;
};
- /// Virtual types.
+ // Virtual types.
template <typename Dp>
- struct vtypes< window_<Dp> >
+ struct vtypes< gen_window<Dp> >
{
- typedef stc_type(Dp, point) point;
- typedef dpoints_fwd_piter_<point> fwd_qiter;
- typedef dpoints_bkd_piter_<point> bkd_qiter;
+ typedef oln_point(Dp) point;
};
- /// Generic classical windoworhood class.
+ /// Generic classical window class.
template <typename Dp>
- class window_ : public internal::window_base_< window_<Dp> >,
- public internal::dpoints_impl_<Dp>
+ class gen_window : public internal::window_< gen_window<Dp> >
{
public:
- window_();
+ gen_window();
- window_<Dp>& take(const Dp& dp);
-
- window_<Dp> impl_op_unary_minus_() const;
-
- }; // end of class oln::window_<Dp>
+ }; // end of class oln::gen_window<Dp>
# ifndef OLN_INCLUDE_ONLY
template <typename Dp>
- window_<Dp>::window_()
- {
- }
-
- template <typename Dp>
- window_<Dp>&
- window_<Dp>::take(const Dp& dp)
- {
- this->take_( dp);
- return *this;
- }
-
- template <typename Dp>
- window_<Dp>
- window_<Dp>::impl_op_unary_minus_() const
+ gen_window<Dp>::gen_window()
{
- window_<Dp> tmp;
- for (unsigned i = 0; i < this->size(); ++i)
- tmp.take(- this->v_[i]);
- return tmp;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/window.hh
--- oln/core/internal/window.hh (revision 0)
+++ oln/core/internal/window.hh (revision 0)
@@ -0,0 +1,116 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_WINDOW_HH
+# define OLN_CORE_INTERNAL_WINDOW_HH
+
+# include <oln/core/internal/window_base.hh>
+# include <oln/core/internal/dpoints_impl.hh>
+# include <oln/core/gen/dpoints_piter.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class window_; }
+
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::window_<Exact> >
+ {
+ typedef internal::window_base_<Exact> ret;
+ };
+
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::window_<Exact> >
+ {
+ typedef stc_deferred(point) point__;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
+ typedef stc::final< dpoints_fwd_piter_<point__> > fwd_qiter;
+ typedef stc::final< dpoints_bkd_piter_<point__> > bkd_qiter;
+ };
+
+ namespace internal
+ {
+
+ /// Base implementation class for regular window classes.
+
+ template <typename Exact>
+ class window_ : public window_base_<Exact>,
+ public dpoints_impl_< stc_deferred(dpoint) >
+ {
+ typedef window_base_<Exact> super;
+ public:
+
+ stc_using(point);
+ typedef typename point::dpoint dpoint;
+
+ window_();
+ Exact& take(const dpoint& dp);
+ Exact impl_op_unary_minus_() const;
+
+ }; // end of class oln::internal::window_<Exact>
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ window_<Exact>::window_()
+ {
+ }
+
+ template <typename Exact>
+ Exact&
+ window_<Exact>::take(const typename window_<Exact>::dpoint& dp)
+ {
+ this->take_( dp);
+ return exact(*this);
+ }
+
+ template <typename Exact>
+ Exact
+ window_<Exact>::impl_op_unary_minus_() const
+ {
+ Exact tmp;
+ for (unsigned i = 0; i < this->size(); ++i)
+ tmp.take(- this->v_[i]);
+ return tmp;
+ }
+
+ } // end of namespace oln::internal
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WINDOW_HH
Index: oln/core/internal/window_base.hh
--- oln/core/internal/window_base.hh (revision 927)
+++ oln/core/internal/window_base.hh (working copy)
@@ -66,15 +66,18 @@
namespace internal
{
- /// Base class for implementation of windows class.
+ /// Base class for implementation of window classes.
template <typename Exact>
class window_base_ : public Window<Exact>
{
+ public:
+ stc_typename(point);
+
protected:
window_base_();
- }; // end of class oln::window_base_<Exact>
+ }; // end of class oln::internal::window_base_<Exact>
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 927)
+++ oln/morpho/closing.hh (working copy)
@@ -57,7 +57,7 @@
closing_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) tmp = morpho::dilation(input, win);
- return morpho::erosion(tmp, win); // FIXME : inverse(win).
+ return morpho::erosion(tmp, - win);
}
// FIXME: Add a fast version.
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 927)
+++ oln/morpho/opening.hh (working copy)
@@ -57,7 +57,7 @@
opening_(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) ero = morpho::erosion(input, win);
- return morpho::dilation(ero, win); // FIXME : inverse(win).
+ return morpho::dilation(ero, - win);
}
// FIXME: Add a fast version.
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 927)
+++ oln/morpho/erosion.hh (working copy)
@@ -34,6 +34,11 @@
# include <oln/accumulator/min.hh>
# include <oln/accumulator/and.hh>
+// FIXME: Add guard.
+# include <oln/core/2d/rectangle2d.hh>
+# include <oln/core/2d/hline2d.hh>
+# include <oln/core/2d/vline2d.hh>
+
namespace oln
{
@@ -53,7 +58,7 @@
namespace impl
{
- // Generic version.
+ // Generic versions.
template <typename I, typename W>
oln_plain(I)
@@ -73,7 +78,21 @@
return level::apply_local(accu_and, input, win);
}
- // FIXME: Add a fast version.
+
+ // FIXME: Add guard here.
+ // Versions for rectangles.
+
+ template <typename I>
+ oln_plain(I)
+ erosion_on_function_(const Image_2D<I>& input, const rectangle2d&
win)
+ {
+ hline2d hl(win.half_width());
+ vline2d hv(win.half_height());
+ oln_plain(I) tmp = erosion(input, hl);
+ return erosion(tmp, hv);
+ }
+
+ // FIXME: Add other fast versions.
// Impl facade.