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) \