2006-10-11 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add some tools related to morphers over image value.
* oln/core/abstract/value.hh: New.
* oln/morpher/thru_fun.hh: New.
* oln/morpher/internal/image_value_morpher.hh: New.
* oln/color: New.
* oln/color/rgb.hh: New.
* tests/Makefile.am (check_PROGRAMS): Reorganize.
(io_pnm_SOURCES): New.
* oln/core/abstract/grid.hh (grid): Add inheritance from oln::type.
* oln/Makefile.am (nobase_oln_HEADERS): Update.
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am (revision 617)
+++ tests/Makefile.am (working copy)
@@ -25,14 +25,14 @@
image1d \
image2d \
image3d \
- io_pnm \
npoints \
\
identity_morpher \
add_neighborhood_morpher \
morphers \
\
- fill
+ fill \
+ io_pnm
# Images and auxiliary structures.
dpoint2d_SOURCES = dpoint2d.cc
@@ -51,6 +51,7 @@
# Algorithms.
fill_SOURCES = fill.cc
+io_pnm_SOURCES = io_pnm.cc
TESTS = $(check_PROGRAMS)
Index: oln/core/abstract/grid.hh
===================================================================
--- oln/core/abstract/grid.hh (revision 617)
+++ oln/core/abstract/grid.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CORE_ABSTRACT_GRID_HH
# define OLN_CORE_ABSTRACT_GRID_HH
+# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
@@ -49,7 +50,8 @@
namespace abstract {
template <typename E>
- struct grid : public virtual stc::any__simple<E>
+ struct grid : public virtual stc::any__simple<E>,
+ public oln::type
{
protected:
grid();
Index: oln/core/abstract/value.hh
===================================================================
--- oln/core/abstract/value.hh (revision 0)
+++ oln/core/abstract/value.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2005, 2006 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_ABSTRACT_VALUE_HH
+# define OLN_CORE_ABSTRACT_VALUE_HH
+
+# include <oln/core/type.hh>
+
+
+namespace oln {
+
+ namespace abstract {
+
+ struct value : public oln::type
+ {
+ protected:
+ value();
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ value::value()
+ {
+ }
+
+# endif
+
+ } // end of namespace oln::abstract
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_ABSTRACT_VALUE_HH
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 617)
+++ oln/Makefile.am (working copy)
@@ -3,6 +3,8 @@
olndir = $(includedir)/oln
nobase_oln_HEADERS = \
\
+ color/rgb.hh \
+ \
core/1d/aliases.hh \
core/1d/array1d.hh \
core/1d/dpoint1d.hh \
@@ -82,6 +84,7 @@
core/abstract/point.hh \
core/abstract/point_set.hh \
core/abstract/topology.hh \
+ core/abstract/value.hh \
\
core/automatic/image.hh \
core/automatic/image_being_mutable.hh \
@@ -135,10 +138,12 @@
level/fill.hh \
\
morpher/internal/image_extension.hh \
+ morpher/internal/image_value_morpher.hh \
\
morpher/add_neighborhood.hh \
morpher/identity.hh \
morpher/tags.hh \
+ morpher/thru_fun.hh \
\
basics1d.hh \
basics2d.hh \
Index: oln/morpher/thru_fun.hh
===================================================================
--- oln/morpher/thru_fun.hh (revision 0)
+++ oln/morpher/thru_fun.hh (revision 0)
@@ -0,0 +1,157 @@
+// Copyright (C) 2006 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_MORPHER_THRU_FUN
+# define OLN_MORPHER_THRU_FUN
+
+# include <xtd/abstract/open_nary_fun.hh>
+# include <xtd/res.hh>
+# include <oln/morpher/internal/image_value_morpher.hh>
+
+
+
+namespace oln
+{
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <typename Image, typename Fun> struct thru_fun;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <typename Image, typename Fun>
+ struct set_super_type< morpher::thru_fun<Image, Fun> >
+ {
+ typedef morpher::thru_fun<Image, Fun> self_t;
+ typedef morpher::internal::image_value_morpher<Image, self_t> ret;
+ };
+
+
+ template <typename Image, typename Fun>
+ struct vtypes< morpher::thru_fun<Image, Fun> >
+ {
+ private:
+ typedef oln_type_of(Image, rvalue) old_value_type;
+ public:
+ typedef xtd_res_1(Fun, old_value_type) value_type;
+ typedef mlc::false_ is_mutable_type;
+ };
+
+
+ template <typename Image, typename Fun>
+ struct single_vtype< morpher::thru_fun<Image, Fun>, typedef_::rvalue_type
>
+ {
+ typedef morpher::thru_fun<Image, Fun> self_t;
+ typedef oln_type_of(self_t, value) ret;
+ };
+
+
+
+ namespace morpher
+ {
+
+ /// 'Image thru Function' morpher.
+ template <typename Image, typename Fun>
+ class thru_fun : public internal::image_value_morpher< Image,
+ thru_fun<Image, Fun> >
+ {
+ private:
+
+ typedef thru_fun<Image, Fun> self_t;
+ typedef internal::image_value_morpher<Image, self_t> super_t;
+
+ typedef oln_type_of(self_t, psite) psite_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+
+ public:
+
+ thru_fun(const Image& image, const Fun& fun);
+
+ rvalue_t impl_op_read(const psite_t& p) const;
+
+ protected:
+
+ Fun fun_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Image, typename Fun>
+ thru_fun<Image, Fun>::thru_fun(const Image& image, const Fun& fun) :
+ super_t(image),
+ fun_(fun)
+ {
+ }
+
+ template <typename Image, typename Fun>
+ typename thru_fun<Image, Fun>::rvalue_t
+ thru_fun<Image, Fun>::impl_op_read(const typename thru_fun<Image,
Fun>::psite_t& p) const
+ {
+ return fun_(this->image_(p));
+ }
+
+# endif
+
+ } // end of namespace oln::morpher
+
+
+} // end of namespace oln
+
+
+
+
+namespace xtd
+{
+
+ // open_nary_fun_<1, Fun>::operator()(const A& a) const
+ // where A is an oln::abstract::image<I>
+
+ template <typename Fun, typename A>
+ struct case_ < tag::fun_operator_1, mlc::pair_<Fun, A>, 2 >
+ : where_< mlc_is_a(A, oln::abstract::image) >
+ {
+ typedef stc_to_exact(A) I;
+ typedef oln::morpher::thru_fun<I, Fun> res;
+
+ static res impl(const Fun& fun, // target
+ const oln::abstract::image<I>& ima)
+ {
+ res tmp(ima.exact(), fun);
+ return tmp;
+ }
+ };
+
+} // end of namespace xtd
+
+
+
+
+#endif // ! OLN_MORPHER_THRU_FUN
Index: oln/morpher/internal/image_value_morpher.hh
===================================================================
--- oln/morpher/internal/image_value_morpher.hh (revision 0)
+++ oln/morpher/internal/image_value_morpher.hh (revision 0)
@@ -0,0 +1,137 @@
+// Copyright (C) 2006 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_MORPHER_INTERNAL_IMAGE_VALUE_MORPHER_HH
+# define OLN_MORPHER_INTERNAL_IMAGE_VALUE_MORPHER_HH
+
+# include <oln/core/image_entry.hh>
+# include <oln/morpher/tags.hh>
+
+
+namespace oln
+{
+ namespace morpher
+ {
+ namespace internal
+ {
+
+ // Forward declaration.
+ template <typename Image, typename Exact>
+ class image_value_morpher;
+
+ } // end of namespace oln::morpher::internal
+
+ } // end of namespace oln::morpher
+
+
+ /// Create an ``uplink'' from
+ /// oln::morpher::internal::image_value_morpher to the morphed \a Image,
+ /// so as to get all its virtual types.
+ template <typename Image, typename Exact>
+ struct
+ set_pseudosuper_type< morpher::internal::image_value_morpher<Image, Exact>
>
+ {
+ typedef Image ret;
+ };
+
+
+ template <typename Image, typename Exact>
+ struct vtypes< morpher::internal::image_value_morpher<Image, Exact> >
+ {
+ // Morpher type.
+ typedef oln::morpher::tag::identity morpher_type; // FIXME: Wrong!
+
+ typedef mlc::undefined value_type;
+ };
+
+ template <typename Image, typename Exact>
+ struct single_vtype< morpher::internal::image_value_morpher<Image, Exact>,
+ typedef_::rvalue_type >
+ {
+ typedef mlc::undefined ret;
+ };
+
+ template <typename Image, typename Exact>
+ struct single_vtype< morpher::internal::image_value_morpher<Image, Exact>,
+ typedef_::lvalue_type >
+ {
+ typedef mlc::undefined ret;
+ };
+
+
+ namespace morpher
+ {
+ namespace internal
+ {
+
+ template <typename Image, typename Exact>
+ class image_value_morpher : public oln::image_entry<Exact>
+ {
+ public:
+
+ // FIXME: Handle the constness.
+ image_value_morpher(const Image& image);
+ const Image& delegate() const;
+ Image& delegate();
+
+ protected:
+ Image image_;
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Image, typename Exact>
+ image_value_morpher<Image, Exact>::image_value_morpher(const Image&
image) :
+ image_(image)
+ {
+ }
+
+ template <typename Image, typename Exact>
+ const Image&
+ image_value_morpher<Image, Exact>::delegate() const
+ {
+ return image_;
+ }
+
+ template <typename Image, typename Exact>
+ Image&
+ image_value_morpher<Image, Exact>::delegate()
+ {
+ return image_;
+ }
+
+# endif
+
+ } // end of namespace oln::morpher::internal
+
+ } // end of namespace oln::morpher
+
+} // end of namespace oln
+
+#endif // ! OLN_MORPHER_INTERNAL_IMAGE_VALUE_MORPHER_HH
Index: oln/color/rgb.hh
===================================================================
--- oln/color/rgb.hh (revision 0)
+++ oln/color/rgb.hh (revision 0)
@@ -0,0 +1,185 @@
+// Copyright (C) 2006 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_COLOR_RGB_HH
+# define OLN_CORE_COLOR_RGB_HH
+
+# include <xtd/vec.hh>
+# include <oln/core/abstract/value.hh>
+
+
+namespace oln
+{
+
+ namespace color
+ {
+
+
+ /// General RGB class.
+ template <typename T>
+ class rgb_ : public oln::abstract::value
+ {
+ public:
+
+ /// Ctor.
+ rgb_();
+
+ /// Ctor.
+ rgb_(const T& r, const T& g, const T& b);
+
+ /// Cpy ctor.
+ template <typename U>
+ rgb_(const rgb_<U>& rhs);
+
+ /// Op=.
+ template <typename U>
+ rgb_<T>& operator=(const rgb_<U>& rhs);
+
+ T red() const;
+ T& red();
+ typedef T red_type;
+
+ T green() const;
+ T& green();
+ typedef T green_type;
+
+ T blue() const;
+ T& blue();
+ typedef T blue_type;
+
+ const xtd::vec<3,T>& to_vec() const;
+ xtd::vec<3,T>& to_vec();
+
+ protected:
+ xtd::vec<3,T> val_;
+ };
+
+ typedef rgb_<unsigned char> rgb8;
+
+ template <unsigned n, typename T>
+ std::ostream& operator<<(std::ostream& ostr, const rgb_<T>&
c);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+ template <typename T>
+ rgb_<T>::rgb_()
+ {
+ }
+
+ template <typename T>
+ rgb_<T>::rgb_(const T& r, const T& g, const T& b)
+ {
+ val_[0] = r;
+ val_[1] = g;
+ val_[2] = b;
+ }
+
+ template <typename T>
+ template <typename U>
+ rgb_<T>::rgb_(const rgb_<U>& rhs)
+ {
+ val_[0] = rhs.red();
+ val_[1] = rhs.green();
+ val_[2] = rhs.blue();
+ }
+
+ template <typename T>
+ template <typename U>
+ rgb_<T>& rgb_<T>::operator=(const rgb_<U>& rhs)
+ {
+ val_[0] = rhs.red();
+ val_[1] = rhs.green();
+ val_[2] = rhs.blue();
+ return *this;
+ }
+
+ template <typename T>
+ T rgb_<T>::red() const
+ {
+ return val_[0];
+ }
+
+ template <typename T>
+ T& rgb_<T>::red()
+ {
+ return val_[0];
+ }
+
+ template <typename T>
+ T rgb_<T>::green() const
+ {
+ return val_[1];
+ }
+
+ template <typename T>
+ T& rgb_<T>::green()
+ {
+ return val_[1];
+ }
+
+ template <typename T>
+ T rgb_<T>::blue() const
+ {
+ return val_[2];
+ }
+
+ template <typename T>
+ T& rgb_<T>::blue()
+ {
+ return val_[2];
+ }
+
+ template <typename T>
+ const xtd::vec<3,T>& rgb_<T>::to_vec() const
+ {
+ return val_;
+ }
+
+ template <typename T>
+ xtd::vec<3,T>& rgb_<T>::to_vec()
+ {
+ return val_;
+ }
+
+
+ template <typename T>
+ std::ostream& operator<<(std::ostream& ostr, const rgb_<T>&
c)
+ {
+ return ostr << c.to_vec();
+ }
+
+# endif
+
+
+ } // end of namespace oln::color
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_COLOR_RGB_HH