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.
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add the type of stack of images.
* tests/core/stack.cc,
* oln/core/gen/image_stack.hh,
* oln/core/internal/value_proxy.hh: New.
* tests/core/Makefile.am (check_PROGRAMS): Add stack.
* oln/core/concept/image.hh (inplace): New.
* oln/core/equipment.hh (oln_psite): New.
* oln/core/internal/instant_value.hh: Cosmetic change.
* oln/stc/scoop.hh (stc_is_found_type): New.
oln/core/concept/image.hh | 10 +
oln/core/equipment.hh | 1
oln/core/gen/image_stack.hh | 210 +++++++++++++++++++++++++++++++++++++
oln/core/internal/instant_value.hh | 2
oln/core/internal/value_proxy.hh | 119 ++++++++++++++++++++
oln/stc/scoop.hh | 2
tests/core/Makefile.am | 2
tests/core/stack.cc | 59 ++++++++++
8 files changed, 404 insertions(+), 1 deletion(-)
Index: tests/core/stack.cc
--- tests/core/stack.cc (revision 0)
+++ tests/core/stack.cc (revision 0)
@@ -0,0 +1,59 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// Test stack.
+
+#include <cassert>
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/gen/image_stack.hh>
+#include <oln/level/fill.hh>
+
+
+xtd::vec<2,int> coords(const oln::point2d& p)
+{
+ return p.vec();
+}
+
+
+int main()
+{
+ using namespace oln;
+
+ typedef image2d<int> I;
+ I ima_0(3, 3), ima_1(3, 3);
+ level::fill(stack(ima_0, ima_1).inplace(), coords);
+ {
+ I::piter p(ima_0.points());
+ for_all(p)
+ assert(ima_0(p) = p.row());
+ }
+ {
+ I::piter p(ima_1.points());
+ for_all(p)
+ assert(ima_1(p) = p.col());
+ }
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 926)
+++ tests/core/Makefile.am (working copy)
@@ -33,6 +33,7 @@
pw_value \
rle_image \
sparse_image \
+ stack \
subset \
window2d
@@ -50,6 +51,7 @@
pw_value_SOURCES = pw_value.cc
rle_image_SOURCES = rle_image.cc
sparse_image_SOURCES = sparse_image.cc
+stack_SOURCES = stack.cc
subset_SOURCES = subset.cc
window2d_SOURCES = window2d.cc
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 926)
+++ oln/core/concept/image.hh (working copy)
@@ -191,6 +191,9 @@
lvalue operator()(const psite& p);
void write_(const psite& p, const value& v);
+ // final.
+ Exact& inplace();
+
protected:
Mutable_Image();
};
@@ -526,6 +529,13 @@
{
}
+ template <typename Exact>
+ Exact&
+ Mutable_Image<Exact>::inplace()
+ {
+ return exact(*this);
+ }
+
// ----------------------------------- Point_Wise_Accessible_Image<Exact>
template <typename Exact>
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 926)
+++ oln/core/equipment.hh (working copy)
@@ -127,6 +127,7 @@
# define oln_plain(T) oln_typename_shortcut__(T, plain)
# define oln_point(T) oln_typename_shortcut__(T, point)
# define oln_pset(T) oln_typename_shortcut__(T, pset)
+# define oln_psite(T) oln_typename_shortcut__(T, psite)
// q
stc_decl_associated_type( qiter );
Index: oln/core/gen/image_stack.hh
--- oln/core/gen/image_stack.hh (revision 0)
+++ oln/core/gen/image_stack.hh (revision 0)
@@ -0,0 +1,210 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_GEN_IMAGE_STACK_HH
+# define OLN_CORE_GEN_IMAGE_STACK_HH
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/value_proxy.hh>
+
+# include <mlc/int.hh>
+# include <xtd/vec.hh>
+
+
+namespace oln
+{
+
+# define current image_stack<n_, I>
+
+# define super internal::multiple_image_morpher_< current >
+
+
+ // Fwd decl.
+ template <unsigned n_, typename I> class image_stack;
+
+
+ // Super type.
+ template <unsigned n_, typename I>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ /// Virtual types.
+ template <unsigned n_, typename I>
+ struct vtypes< current >
+ {
+ typedef I delegatee;
+ typedef behavior::identity behavior;
+
+ typedef internal::singleton< xtd::vec<n_,I> > data;
+
+ typedef mlc::uint_<n_> n;
+
+ typedef xtd::vec<n_, oln_value(I)> value;
+ typedef value rvalue;
+
+ typedef typename mlc::if_< stc_is_found_type(I, lvalue),
+ internal::value_proxy_< current >,
+ stc::not_delegated >::ret lvalue;
+
+ typedef oln_plain_value(I, value) plain;
+ typedef image_stack< n_, pl::rec<I> > skeleton;
+ };
+
+
+ /// Class for a stack of n images.
+
+ template <unsigned n_, typename I>
+ class image_stack : public super
+ {
+ public:
+
+ stc_using(psite);
+ stc_using(rvalue);
+ stc_using(lvalue);
+ stc_using(value);
+ stc_using(data);
+ stc_using(delegatee);
+
+ image_stack();
+ image_stack(const xtd::vec<n_,I>& imas);
+
+ // FIXME: Force this type to be read-only?
+ rvalue impl_read(const psite& p) const;
+ lvalue impl_read_write(const psite& p);
+ void impl_write(const psite& p, const value& v);
+
+ delegatee& impl_image(unsigned i);
+ const delegatee& impl_image(unsigned i) const;
+
+ }; // end of current
+
+
+
+ template <typename I>
+ image_stack<2,I> stack(I& ima_0, I& ima_1);
+
+ template <typename I>
+ image_stack<3,I> stack(I& ima_0, I& ima_1, I& ima_2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <unsigned n_, typename I>
+ current::image_stack()
+ {
+ }
+
+ template <unsigned n_, typename I>
+ current::image_stack(const xtd::vec<n_,I>& imas)
+ {
+ for (unsigned i = 0; i < n_; ++i)
+ precondition(imas[i].has_data());
+ this->data_ = new data(imas);
+ }
+
+ template <unsigned n_, typename I>
+ typename current::rvalue
+ current::impl_read(const typename current::psite& p) const
+ {
+ assert(this->has_data());
+ rvalue tmp;
+ for (unsigned i = 0; i < n_; ++i)
+ tmp[i] = this->data_->value[i](p);
+ return tmp;
+ }
+
+ template <unsigned n_, typename I>
+ typename current::lvalue
+ current::impl_read_write(const typename current::psite& p)
+ {
+ assert(this->has_data());
+ lvalue tmp(*this, p);
+ return tmp;
+ }
+
+ template <unsigned n_, typename I>
+ void
+ current::impl_write(const typename current::psite& p,
+ const typename current::value& v)
+ {
+ assert(this->has_data());
+ for (unsigned i = 0; i < n_; ++i)
+ this->data_->value[i](p) = v[i];
+ }
+
+ template <unsigned n_, typename I>
+ typename current::delegatee&
+ current::impl_image(unsigned i)
+ {
+ precondition(i < n_);
+ assert(this->has_data());
+ return this->data_->value[i];
+ }
+
+ template <unsigned n_, typename I>
+ const typename current::delegatee&
+ current::impl_image(unsigned i) const
+ {
+ precondition(i < n_);
+ assert(this->has_data());
+ return this->data_->value[i];
+ }
+
+ template <typename I>
+ image_stack<2,I> stack(I& ima_0, I& ima_1)
+ {
+ xtd::vec<2,I> v;
+ v[0] = ima_0;
+ v[1] = ima_1;
+ image_stack<2,I> tmp(v);
+ return tmp;
+ }
+
+ template <typename I>
+ image_stack<3,I> stack(I& ima_0, I& ima_1, I& ima_2)
+ {
+ xtd::vec<3,I> v;
+ v[0] = ima_0;
+ v[1] = ima_1;
+ v[2] = ima_2;
+ image_stack<3,I> tmp(v);
+ return tmp;
+ }
+
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_IMAGE_STACK_HH
Index: oln/core/internal/value_proxy.hh
--- oln/core/internal/value_proxy.hh (revision 0)
+++ oln/core/internal/value_proxy.hh (revision 0)
@@ -0,0 +1,119 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_VALUE_PROXY_HH
+# define OLN_CORE_INTERNAL_VALUE_PROXY_HH
+
+# include <ostream>
+# include <oln/core/concept/value.hh>
+
+
+namespace oln
+{
+
+ namespace internal
+ {
+
+
+ template <typename I>
+ class value_proxy_
+ {
+ public:
+
+ // ctor
+ value_proxy_(I& ima, const oln_psite(I)& p);
+
+ // assignment => write
+ template <typename T>
+ value_proxy_<I>& operator=(const T& val);
+
+ // conversion => read
+ template <typename T>
+ operator T() const;
+
+ // explicit read
+ oln_value(I) value() const;
+
+ private:
+
+ I& ima_;
+ oln_psite(I) p_;
+ };
+
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const value_proxy_<I>& v);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ value_proxy_<I>::value_proxy_(I& ima, const oln_psite(I)& p)
+ : ima_(ima),
+ p_(p)
+ {
+ }
+
+ template <typename I>
+ template <typename T>
+ value_proxy_<I>&
+ value_proxy_<I>::operator=(const T& val)
+ {
+ ima_.write_(this->p_, val);
+ return *this;
+ }
+
+ template <typename I>
+ template <typename T>
+ value_proxy_<I>::operator T() const
+ {
+ T tmp = this->ima_.read_(this->p_);
+ return tmp;
+ }
+
+ template <typename I>
+ oln_value(I)
+ value_proxy_<I>::value() const
+ {
+ oln_value(I) tmp = this->ima_.read_(this->p_);
+ return tmp;
+ }
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const value_proxy_<I>& v)
+ {
+ return ostr << v.value();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_VALUE_PROXY_HH
Index: oln/core/internal/instant_value.hh
--- oln/core/internal/instant_value.hh (revision 926)
+++ oln/core/internal/instant_value.hh (working copy)
@@ -93,7 +93,7 @@
}
*/
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::internal
Index: oln/stc/scoop.hh
--- oln/stc/scoop.hh (revision 926)
+++ oln/stc/scoop.hh (working copy)
@@ -118,6 +118,8 @@
# define stc_type_is_found(Type) stc::is_found< stc_deferred(Type) >
# define stc_type_is_not_found(Type) stc::is_not_found< stc_deferred(Type) >
+# define stc_is_found_type(From, Type) stc::is_found< stc_deferred_type(From, Type) >
+
# define stc_is_a(T, U) \