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
October 2006
- 3 participants
- 108 discussions
2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Tiny fix just before pastis.
* oln/basics1d.hh (include): Add missing headers.
* oln/basics2d.hh: Likewise.
* oln/basics3d.hh: Likewise.
Index: oln/basics1d.hh
===================================================================
--- oln/basics1d.hh (revision 680)
+++ oln/basics1d.hh (working copy)
@@ -32,6 +32,10 @@
# define OLN_ENV_1D
+# include <oln/core/typedefs.hh>
+# include <oln/core/case.hh>
+# include <oln/core/traits.hh>
+# include <oln/value/proxy.hh>
# include <oln/core/1d/aliases.hh>
Index: oln/basics2d.hh
===================================================================
--- oln/basics2d.hh (revision 680)
+++ oln/basics2d.hh (working copy)
@@ -32,6 +32,10 @@
# define OLN_ENV_2D
+# include <oln/core/typedefs.hh>
+# include <oln/core/case.hh>
+# include <oln/core/traits.hh>
+# include <oln/value/proxy.hh>
# include <oln/core/2d/aliases.hh>
Index: oln/basics3d.hh
===================================================================
--- oln/basics3d.hh (revision 680)
+++ oln/basics3d.hh (working copy)
@@ -32,6 +32,10 @@
# define OLN_ENV_3D
+# include <oln/core/typedefs.hh>
+# include <oln/core/case.hh>
+# include <oln/core/traits.hh>
+# include <oln/value/proxy.hh>
# include <oln/core/3d/aliases.hh>
1
0
2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* xtd/math.hh (include): Move ops inclusion into...
* xtd/math/ops.hh: ... this new file.
Index: xtd/math.hh
===================================================================
--- xtd/math.hh (revision 681)
+++ xtd/math.hh (working copy)
@@ -68,9 +68,7 @@
/// \{
/// Definition of xtd operators and related functions.
-# include <xtd/math/arith.hh>
-# include <xtd/math/logic.hh>
-# include <xtd/math/cmp.hh>
+# include <xtd/math/ops.hh>
/// \}
Index: xtd/math/ops.hh
===================================================================
--- xtd/math/ops.hh (revision 0)
+++ xtd/math/ops.hh (revision 0)
@@ -0,0 +1,37 @@
+// Copyright (C) 2002, 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 XTD_MATH_OPS_HH
+# define XTD_MATH_OPS_HH
+
+
+# include <xtd/math/arith.hh>
+# include <xtd/math/logic.hh>
+# include <xtd/math/cmp.hh>
+
+
+#endif // ! XTD_MATH_OPS_HH
1
0
2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add two-way morpher.
* tests/morphers/two_way_morpher.cc: New.
* tests/morphers/Makefile.am: Update.
* oln/morpher/two_way.hh: New.
* oln/Makefile.am: Update.
* oln/core/abstract/image.hh (id_): Unconst.
* oln/core/abstract/functions.hh (fun_v2w2v): New.
* oln/core/traits.hh (oln_xtd_case_op_id): Fix number.
(include): Add commentary.
Index: tests/morphers/Makefile.am
===================================================================
--- tests/morphers/Makefile.am (revision 680)
+++ tests/morphers/Makefile.am (working copy)
@@ -24,6 +24,7 @@
count_rw_morpher \
slice_morpher \
stack_morpher \
+ two_way_morpher \
value_cast \
with_lut \
\
@@ -35,6 +36,7 @@
count_rw_morpher_SOURCES = count_rw_morpher.cc
slice_morpher_SOURCES = slice_morpher.cc
stack_morpher_SOURCES = stack_morpher.cc
+two_way_morpher_SOURCES = two_way_morpher.cc
value_cast_SOURCES = value_cast.cc
with_lut_SOURCES = with_lut.cc
Index: tests/morphers/two_way_morpher.cc
===================================================================
--- tests/morphers/two_way_morpher.cc (revision 0)
+++ tests/morphers/two_way_morpher.cc (revision 0)
@@ -0,0 +1,68 @@
+// 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.
+
+/// Test the two-way morpher.
+
+#include <cassert>
+
+#include <oln/core/traits.hh>
+#include <oln/basics2d.hh>
+#include <oln/morpher/two_way.hh>
+
+
+struct F : public oln::abstract::fun_v2w2v< F >
+{
+ typedef int result_type;
+
+ int direct(int i) const
+ {
+ return i + 1;
+ }
+
+ int reverse(int i) const
+ {
+ return i - 1;
+ }
+};
+
+
+int main()
+{
+ F fun;
+
+ using namespace oln;
+ typedef image2d<int> I;
+ I ima(1,1);
+ point2d p(0,0);
+
+ ima(p) = 50;
+ assert(fun(ima)(p) == 51);
+
+ morpher::two_way<I,F> ima_bis(ima);
+ ima_bis(p) = 52;
+ assert(ima(p) == 51);
+}
Index: oln/core/abstract/image.hh
===================================================================
--- oln/core/abstract/image.hh (revision 680)
+++ oln/core/abstract/image.hh (working copy)
@@ -133,7 +133,7 @@
private:
- const unsigned id_;
+ unsigned id_;
};
Index: oln/core/abstract/functions.hh
===================================================================
--- oln/core/abstract/functions.hh (revision 680)
+++ oln/core/abstract/functions.hh (working copy)
@@ -30,11 +30,19 @@
# include <stc/any.hh>
# include <oln/core/type.hh>
+# include <oln/core/abstract/image.hh>
namespace oln
{
+
+ // Fwd decl.
+ namespace morpher {
+ template <typename I, typename F> class two_way;
+ }
+
+
namespace abstract
{
@@ -60,6 +68,21 @@
};
+ // Value1 -> Value2 *and* Value2 -> Value1.
+
+ template <typename E>
+ struct fun_v2w2v : public virtual stc::any__simple<E>,
+ public oln::type
+ {
+ public:
+ template <typename I>
+ oln::morpher::two_way<I, E>
+ operator()(oln::abstract::mutable_image<I>& input) const;
+ protected:
+ fun_v2w2v();
+ };
+
+
// Point -> Point.
template <typename E>
@@ -84,6 +107,11 @@
}
template <typename E>
+ fun_v2w2v<E>::fun_v2w2v()
+ {
+ }
+
+ template <typename E>
fun_p2p<E>::fun_p2p()
{
}
Index: oln/core/traits.hh
===================================================================
--- oln/core/traits.hh (revision 680)
+++ oln/core/traits.hh (working copy)
@@ -28,11 +28,12 @@
#ifndef OLN_CORE_TRAITS_HH
# define OLN_CORE_TRAITS_HH
-
# include <mlc/assert.hh>
# include <mlc/abort.hh>
-# include <xtd/optraits.hh>
-# include <xtd/math/ops.hh>
+
+# include <xtd/optraits.hh> // case #1 for C++ builtins
+# include <xtd/math/ops.hh> // case #2 for xtd::fun_expr_
+
# include <stc/exact.hh>
# include <oln/core/type.hh>
@@ -56,7 +57,7 @@
namespace xtd
{
- static const unsigned oln_xtd_case_op_id = 2;
+ static const unsigned oln_xtd_case_op_id = 3; // case #3
template <typename name,
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 680)
+++ oln/Makefile.am (working copy)
@@ -183,6 +183,7 @@
morpher/stack.hh \
morpher/thru_fun.hh \
morpher/thru_mfun.hh \
+ morpher/two_way.hh \
morpher/value_cast.hh \
morpher/with_lut.hh \
\
Index: oln/morpher/two_way.hh
===================================================================
--- oln/morpher/two_way.hh (revision 0)
+++ oln/morpher/two_way.hh (revision 0)
@@ -0,0 +1,238 @@
+// 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_TWO_WAY_HH
+# define OLN_MORPHER_TWO_WAY_HH
+
+# include <oln/value/two_way.hh>
+# include <oln/morpher/internal/image_value_morpher.hh>
+
+
+namespace oln
+{
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <typename Image, typename Fun> struct two_way;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <typename Image, typename Fun>
+ struct set_super_type< morpher::two_way<Image, Fun> >
+ {
+ typedef morpher::two_way<Image, Fun> self_t;
+ typedef morpher::internal::image_value_morpher<Image, self_t> ret;
+ };
+
+
+ template <typename Image, typename Fun>
+ struct vtypes< morpher::two_way<Image, Fun> >
+ {
+ typedef morpher::two_way<Image, Fun> self_t;
+ public:
+ typedef mlc::true_ is_computed_type;
+
+ typedef typename Fun::result_type value_type;
+ typedef value::two_way<Image, Fun> lvalue_type;
+ };
+
+ template <typename Image, typename Fun>
+ struct single_vtype< morpher::two_way<Image, Fun>, typedef_::rvalue_type >
+ {
+ typedef typename Fun::result_type ret;
+ };
+
+
+ namespace morpher
+ {
+
+ /// 'Image thru Function' morpher.
+ template <typename Image, typename Fun>
+ class two_way : public internal::image_value_morpher< Image,
+ morpher::two_way<Image, Fun> >
+ {
+ private:
+
+ typedef two_way<Image, Fun> self_t;
+
+ typedef internal::image_value_morpher<Image, self_t> super_t;
+ using super_t::image_;
+
+ typedef oln_rvalue(self_t) rvalue_t;
+ typedef oln_lvalue(self_t) lvalue_t;
+ typedef oln_psite(self_t) psite_t;
+
+ public:
+
+ two_way(Image& image, Fun fun);
+ two_way(Image& image);
+
+ two_way(oln::abstract::mutable_image<Image>& image,
+ const oln::abstract::fun_v2w2v<Fun>& fun);
+
+ rvalue_t impl_op_read(const psite_t& p) const;
+ lvalue_t impl_op_readwrite(const psite_t& p);
+
+ protected:
+
+ Fun fun_;
+ };
+
+
+ namespace ERROR
+ {
+
+ struct FIXME;
+
+ } // end of namespace oln::morpher::ERROR
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // public
+
+ template <typename Image, typename Fun>
+ two_way<Image, Fun>::two_way(Image& image) :
+ super_t(image),
+ fun_()
+ {
+ }
+
+ template <typename Image, typename Fun>
+ two_way<Image, Fun>::two_way(Image& image, Fun fun) :
+ super_t(image),
+ fun_(fun)
+ {
+ }
+
+ template <typename Image, typename Fun>
+ two_way<Image, Fun>::two_way(oln::abstract::mutable_image<Image>& image,
+ const oln::abstract::fun_v2w2v<Fun>& fun) :
+ super_t(image.exact()),
+ fun_(fun.exact())
+ {
+ }
+
+ template <typename Image, typename Fun>
+ typename two_way<Image, Fun>::rvalue_t
+ two_way<Image, Fun>::impl_op_read(const typename two_way<Image, Fun>::psite_t& p) const
+ {
+ return fun_.direct(image_(p));
+ }
+
+ template <typename Image, typename Fun>
+ typename two_way<Image, Fun>::lvalue_t
+ two_way<Image, Fun>::impl_op_readwrite(const typename two_way<Image, Fun>::psite_t& p)
+ {
+ value::two_way<Image, Fun> tmp(image_, fun_, p);
+ return tmp;
+ }
+
+# endif
+
+ } // end of namespace oln::morpher
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace value
+ {
+
+ // Ctor.
+ template <typename I, typename F>
+ two_way<I,F>::two_way(I& ima,
+ F fun,
+ const oln_psite(I)& p)
+ : ima_(ima),
+ fun_(fun),
+ p_(p)
+ {
+ }
+
+ // Read.
+ template <typename I, typename F>
+ template <typename V>
+ two_way<I,F>::operator V() const
+ {
+ return fun_.direct(ima_(p_));
+ }
+
+ // Explicit read.
+ template <typename I, typename F>
+ typename F::result_type
+ two_way<I,F>::value() const
+ {
+ return fun_.direct(ima_(p_));
+ }
+
+ // Write.
+
+ template <typename I, typename F>
+ template <typename V>
+ two_way<I,F>&
+ two_way<I,F>::operator=(const V& value)
+ {
+ ima_(p_) = fun_.reverse(value);
+ return *this;
+ }
+
+ // Op <<.
+ template <typename I, typename F>
+ std::ostream& operator<<(std::ostream& ostr,
+ const two_way<I,F>& proxy)
+ {
+ return ostr << proxy.value();
+ }
+
+ } // end of namespace oln::value
+
+
+ namespace abstract
+ {
+
+ template <typename F>
+ template <typename I>
+ oln::morpher::two_way<I, F>
+ fun_v2w2v<F>::operator()(oln::abstract::mutable_image<I>& input) const
+ {
+ morpher::two_way<I, F> tmp(input.exact(), this->exact());
+ return tmp;
+ }
+
+ } // end of namespace oln::abstract
+
+# endif
+
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHER_TWO_WAY_HH
1
0
2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add oln::level::apply_inplace.
* tests/level/apply_inplace.cc: New.
* oln/level/assign.hh: Typo.
* oln/level/apply.hh (apply_inplace): New.
* oln/level/fill.hh (include): Fix.
* oln/core/traits.hh (include): Add xtd/math/ops.hh.
Index: tests/level/apply_inplace.cc
===================================================================
--- tests/level/apply_inplace.cc (revision 0)
+++ tests/level/apply_inplace.cc (revision 0)
@@ -0,0 +1,40 @@
+#include <oln/basics2d.hh>
+#include <oln/debug/print.hh>
+
+#include <oln/level/apply.hh>
+#include <oln/level/assign.hh>
+#include <oln/level/clone.hh>
+#include <oln/level/fill.hh>
+
+
+
+struct chessboard_2d : public oln::abstract::fun_p2v< chessboard_2d >
+{
+ bool operator()(const oln::point2d& p) const
+ {
+ return (p.row() + p.col()) % 2;
+ }
+};
+
+
+struct negate : public oln::abstract::fun_v2v< negate >
+{
+ bool operator()(bool b) const
+ {
+ return not b;
+ }
+};
+
+
+
+int main()
+{
+ using namespace oln;
+ image2d<bool> ima(3,3);
+
+ oln::level::fill(ima, chessboard_2d());
+ debug::print(ima);
+
+ oln::level::apply_inplace(ima, negate());
+ debug::print(ima);
+}
Index: oln/level/assign.hh
===================================================================
--- oln/level/assign.hh (revision 679)
+++ oln/level/assign.hh (working copy)
@@ -45,8 +45,7 @@
namespace level
{
- /// Fwd decls.
-
+ /// Fwd decl.
template <typename Idest, typename Isrc>
void assign(abstract::mutable_image<Idest>& dest, const abstract::image<Isrc>& src);
Index: oln/level/apply.hh
===================================================================
--- oln/level/apply.hh (revision 679)
+++ oln/level/apply.hh (working copy)
@@ -50,7 +50,15 @@
oln_plain_value(I, typename F::result_value)
apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
+ /// Fwd decl.
+ template <typename I, typename V>
+ void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
+ /// Fwd decl.
+ template <typename I, typename F>
+ void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
+
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
@@ -80,6 +88,27 @@
return output;
}
+
+ /// Generic version.
+ template <typename I, typename V>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
+ {
+ oln_piter(I) p(input.topo());
+ for_all(p)
+ input(p) = fun(input(p));
+ }
+
+ /// Generic version.
+ template <typename I, typename F>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
+ {
+ oln_piter(I) p(input.topo());
+ for_all(p)
+ input(p) = fun.exact()(input(p));
+ }
+
} // end of namespace oln::level::impl
@@ -99,6 +128,23 @@
return impl::apply(input, fun);
}
+
+ /// Facade.
+ template <typename I, typename V>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
+ {
+ return impl::apply_inplace(input, fun);
+ }
+
+ /// Facade.
+ template <typename I, typename F>
+ void
+ apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
+ {
+ return impl::apply_inplace(input, fun);
+ }
+
# endif
} // end of namespace oln::level
Index: oln/level/fill.hh
===================================================================
--- oln/level/fill.hh (revision 679)
+++ oln/level/fill.hh (working copy)
@@ -31,13 +31,9 @@
# include <iostream>
-# include <mlc/assert.hh>
-# include <mlc/is_a.hh>
-
# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/iterator.hh>
# include <oln/core/abstract/functions.hh>
-# include <oln/core/automatic/image/mutable_image.hh>
namespace oln
@@ -75,8 +71,7 @@
/// Fwd decl.
template <typename I, typename F>
- void fill(abstract::mutable_image<I>& input,
- const abstract::fun_p2v<F>& fun);
+ void fill(abstract::mutable_image<I>& input, const abstract::fun_p2v<F>& fun);
# ifndef OLN_INCLUDE_ONLY
@@ -115,11 +110,9 @@
/// Generic version.
template <typename I, typename F>
- void fill(abstract::mutable_image<I>& input,
- const abstract::fun_p2v<F>& fun)
+ void fill(abstract::mutable_image<I>& input, const abstract::fun_p2v<F>& fun)
{
oln_piter(I) p(input.topo());
- unsigned i = 0;
for_all(p)
input(p) = fun.exact()(p);
}
@@ -150,8 +143,7 @@
/// Facade.
template <typename I, typename F>
- void fill(abstract::mutable_image<I>& input,
- const abstract::fun_p2v<F>& fun)
+ void fill(abstract::mutable_image<I>& input, const abstract::fun_p2v<F>& fun)
{
return impl::fill(input.exact(), fun);
}
Index: oln/core/traits.hh
===================================================================
--- oln/core/traits.hh (revision 678)
+++ oln/core/traits.hh (working copy)
@@ -32,6 +32,7 @@
# include <mlc/assert.hh>
# include <mlc/abort.hh>
# include <xtd/optraits.hh>
+# include <xtd/math/ops.hh>
# include <stc/exact.hh>
# include <oln/core/type.hh>
1
0
25 Oct '06
2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add oln abstract functions + move slice vtype definitions.
* oln/level/assign.hh: New.
* oln/level/apply.hh: New.
* oln/level/clone.hh: New.
* oln/core/abstract/functions.hh: New.
* oln/debug/track.hh (dummy): Add code to remove warning.
* oln/debug/print.hh (OLN_ENV_2D): Guard specific code.
* oln/level/fill.hh (fill): New couple of versions.
* oln/basics1d.hh (OLN_ENV_1D): New.
* oln/core/typedefs.hh (oln_plain_value, oln_plain_value_): New.
* oln/core/iterator_vtypes.hh (slice): Move type definitions to...
* oln/morpher/slice.hh: ...here.
* oln/basics2d.hh (OLN_ENV_2D): New.
* oln/basics3d.hh (OLN_ENV_3D): New.
* oln/Makefile.am: Update.
Index: oln/debug/track.hh
===================================================================
--- oln/debug/track.hh (revision 678)
+++ oln/debug/track.hh (working copy)
@@ -38,6 +38,16 @@
static unsigned n_images = 0;
static unsigned n_arrays = 0;
+
+# ifndef OLN_INCLUDE_ONLY
+ namespace dummy {
+ // FIXME: Quick hack to suppress the warning
+ // "'oln::debug::n_arrays' defined but not used"
+ void foo() { n_arrays = n_arrays; }
+ }
+# endif
+
+
} // end of namespace oln::debug
} // end of namespace oln
Index: oln/debug/print.hh
===================================================================
--- oln/debug/print.hh (revision 678)
+++ oln/debug/print.hh (working copy)
@@ -34,9 +34,12 @@
# include <oln/core/abstract/iterator.hh>
# include <oln/core/spe/row.hh>
# include <oln/core/spe/col.hh>
-# include <oln/core/2d/point2d.hh>
+# ifdef OLN_ENV_2D
+# include <oln/core/2d/point2d.hh>
+# endif
+
namespace oln
{
@@ -76,6 +79,8 @@
}
+# ifdef OLN_ENV_2D
+
/// Version for classical 2D images.
template <typename I>
void print(const abstract::classical_2d_image<I>& input,
@@ -96,10 +101,12 @@
}
}
+# endif
+
+
} // end of namespace oln::debug::impl
-
/// Facade.
template <typename I>
void print(const abstract::image<I>& input, std::ostream& ostr)
Index: oln/level/assign.hh
===================================================================
--- oln/level/assign.hh (revision 0)
+++ oln/level/assign.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 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_LEVEL_ASSIGN_HH
+# define OLN_LEVEL_ASSIGN_HH
+
+# include <iostream>
+
+# include <mlc/assert.hh>
+# include <mlc/is_a.hh>
+
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/iterator.hh>
+# include <oln/core/automatic/image/mutable_image.hh>
+
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ /// Fwd decls.
+
+ template <typename Idest, typename Isrc>
+ void assign(abstract::mutable_image<Idest>& dest, const abstract::image<Isrc>& src);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /// Generic version.
+ template <typename Idest, typename Isrc>
+ void assign(abstract::mutable_image<Idest>& dest, const abstract::image<Isrc>& src)
+ {
+ oln_piter(Isrc) p(src.topo());
+ for_all(p)
+ dest(p) = src(p);
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ /// Facade.
+ template <typename Idest, typename Isrc>
+ void assign(abstract::mutable_image<Idest>& dest, const abstract::image<Isrc>& src)
+ {
+ impl::assign(dest.exact(), src.exact());
+ }
+
+# endif
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LEVEL_ASSIGN_HH
Index: oln/level/apply.hh
===================================================================
--- oln/level/apply.hh (revision 0)
+++ oln/level/apply.hh (revision 0)
@@ -0,0 +1,109 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 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_LEVEL_APPLY_HH
+# define OLN_LEVEL_APPLY_HH
+
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/iterator.hh>
+# include <oln/core/abstract/functions.hh>
+
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ /// Fwd decl.
+ template <typename I, typename V>
+ oln_plain_value(I, V)
+ apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&));
+
+ /// Fwd decl.
+ template <typename I, typename F>
+ oln_plain_value(I, typename F::result_value)
+ apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /// Generic version.
+ template <typename I, typename V>
+ oln_plain_value(I, V)
+ apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&))
+ {
+ oln_plain_value(I, V) output(input.topo());
+ oln_piter(I) p(input.topo());
+ for_all(p)
+ output(p) = fun(input(p));
+ return output;
+ }
+
+ /// Generic version.
+ template <typename I, typename F>
+ oln_plain_value(I, typename F::result_value)
+ apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
+ {
+ oln_plain_value(I, typename F::result_value) output(input.topo());
+ oln_piter(I) p(input.topo());
+ for_all(p)
+ output(p) = fun.exact()(input(p));
+ return output;
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ /// Facade.
+ template <typename I, typename V>
+ oln_plain_value(I, V)
+ apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&))
+ {
+ return impl::apply(input, fun);
+ }
+
+ /// Facade.
+ template <typename I, typename F>
+ oln_plain_value(I, typename F::result_value)
+ apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
+ {
+ return impl::apply(input, fun);
+ }
+
+# endif
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LEVEL_APPLY_HH
Index: oln/level/fill.hh
===================================================================
--- oln/level/fill.hh (revision 678)
+++ oln/level/fill.hh (working copy)
@@ -36,6 +36,7 @@
# include <oln/core/abstract/image.hh>
# include <oln/core/abstract/iterator.hh>
+# include <oln/core/abstract/functions.hh>
# include <oln/core/automatic/image/mutable_image.hh>
@@ -68,7 +69,16 @@
template <typename I, typename V>
void fill(abstract::mutable_image<I>& input, const V values[]);
+ /// Fwd decl.
+ template <typename I, typename V, typename P>
+ void fill(abstract::mutable_image<I>& input, V (*fun)(const P&));
+ /// Fwd decl.
+ template <typename I, typename F>
+ void fill(abstract::mutable_image<I>& input,
+ const abstract::fun_p2v<F>& fun);
+
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
@@ -93,9 +103,30 @@
input(p) = values[i++];
}
- } // end of namespace oln::level::fill
+ /// Generic version.
+ template <typename I, typename V, typename P>
+ void fill(abstract::mutable_image<I>& input, V (*fun)(const P&))
+ {
+ oln_piter(I) p(input.topo());
+ unsigned i = 0;
+ for_all(p)
+ input(p) = fun(p);
+ }
+ /// Generic version.
+ template <typename I, typename F>
+ void fill(abstract::mutable_image<I>& input,
+ const abstract::fun_p2v<F>& fun)
+ {
+ oln_piter(I) p(input.topo());
+ unsigned i = 0;
+ for_all(p)
+ input(p) = fun.exact()(p);
+ }
+ } // end of namespace oln::level::impl
+
+
/// Facade.
template <typename I>
void fill(abstract::mutable_image<I>& input, const oln_value(I)& value)
@@ -110,7 +141,21 @@
return impl::fill(input.exact(), values);
}
+ /// Facade.
+ template <typename I, typename V, typename P>
+ void fill(abstract::mutable_image<I>& input, V (*fun)(const P&))
+ {
+ return impl::fill(input.exact(), fun);
+ }
+ /// Facade.
+ template <typename I, typename F>
+ void fill(abstract::mutable_image<I>& input,
+ const abstract::fun_p2v<F>& fun)
+ {
+ return impl::fill(input.exact(), fun);
+ }
+
# endif
} // end of namespace oln::level
Index: oln/level/clone.hh
===================================================================
--- oln/level/clone.hh (revision 0)
+++ oln/level/clone.hh (revision 0)
@@ -0,0 +1,80 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 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_LEVEL_CLONE_HH
+# define OLN_LEVEL_CLONE_HH
+
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/iterator.hh>
+
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ /// Fwd decl.
+ template <typename I>
+ oln_plain(I) clone(const abstract::image<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /// Generic version.
+ template <typename I>
+ oln_plain(I) clone(const abstract::image<I>& input)
+ {
+ oln_plain(I) output(input.topo());
+ oln_piter(I) p(input.topo());
+ for_all(p)
+ output(p) = input(p);
+ return output;
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ /// Facade.
+ template <typename I>
+ oln_plain(I) clone(const abstract::image<I>& input)
+ {
+ return impl::clone(input);
+ }
+
+# endif
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LEVEL_CLONE_HH
Index: oln/basics1d.hh
===================================================================
--- oln/basics1d.hh (revision 678)
+++ oln/basics1d.hh (working copy)
@@ -30,6 +30,9 @@
# define OLN_BASICS1D_HH
+# define OLN_ENV_1D
+
+
# include <oln/core/1d/aliases.hh>
# include <oln/core/gen/grid.hh>
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 678)
+++ oln/core/typedefs.hh (working copy)
@@ -279,6 +279,9 @@
# define oln_plain(T) typename oln::type_fun::plain<T>::ret
# define oln_plain_(T) oln::type_fun::plain<T>::ret
+# define oln_plain_value(I, V) typename oln::type_fun::ch_value< oln_plain(I), V >::ret
+# define oln_plain_value_(I, V) oln::type_fun::ch_value< oln_plain(I), V >::ret
+
/// \}
Index: oln/core/iterator_vtypes.hh
===================================================================
--- oln/core/iterator_vtypes.hh (revision 678)
+++ oln/core/iterator_vtypes.hh (working copy)
@@ -33,7 +33,7 @@
# include <oln/core/1d/aliases.hh>
# include <oln/core/2d/aliases.hh>
# include <oln/core/3d/aliases.hh>
-# include <oln/core/type_fun/slice.hh>
+// # include <oln/core/type_fun/slice.hh>
namespace oln
@@ -272,67 +272,7 @@
};
- /*-----------------------------.
- | oln::morpher::slice<Image>. |
- `-----------------------------*/
- // Forward declarations.
- namespace morpher
- {
- template <typename Image> struct slice;
- }
- template <typename Piter, typename Topo> class piter_slice_;
-
-
- // piters.
-
- /// fwd_piter vtype of morpher::slice.
- template <typename Image>
- struct single_vtype< morpher::slice<Image>, typedef_::fwd_piter_type >
- {
- private:
- typedef oln_type_of(Image, fwd_piter) orig_fwd_piter;
- public:
- typedef typename type_fun::slice_iterator<orig_fwd_piter>::ret ret;
- };
-
- /// bkd_piter vtype of morpher::slice.
- template <typename Image>
- struct single_vtype< morpher::slice<Image>, typedef_::bkd_piter_type >
- {
- private:
- typedef oln_type_of(Image, bkd_piter) orig_bkd_piter;
- public:
- typedef typename type_fun::slice_iterator<orig_bkd_piter>::ret ret;
- };
-
-
- // qiters.
-
- /// fwd_qiter vtype of morpher::slice.
- template <typename Image>
- struct single_vtype< morpher::slice<Image>, typedef_::fwd_qiter_type >
- {
- private:
- typedef oln_type_of(Image, fwd_qiter) orig_fwd_qiter;
- public:
- typedef typename type_fun::slice_iterator<orig_fwd_qiter>::ret ret;
- };
-
- /// bkd_qiter vtype of morpher::slice.
- template <typename Image>
- struct single_vtype< morpher::slice<Image>, typedef_::bkd_qiter_type >
- {
- private:
- typedef oln_type_of(Image, bkd_qiter) orig_bkd_qiter;
- public:
- typedef typename type_fun::slice_iterator<orig_bkd_qiter>::ret ret;
- };
-
-
- // FIXME: What about niters?
-
-
} // end of namespace oln
Index: oln/core/abstract/functions.hh
===================================================================
--- oln/core/abstract/functions.hh (revision 0)
+++ oln/core/abstract/functions.hh (revision 0)
@@ -0,0 +1,98 @@
+// 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_ABSTRACT_FUNCTIONS_HH
+# define OLN_CORE_ABSTRACT_FUNCTIONS_HH
+
+# include <stc/any.hh>
+# include <oln/core/type.hh>
+
+
+namespace oln
+{
+
+ namespace abstract
+ {
+
+ // Point -> Value.
+
+ template <typename E>
+ struct fun_p2v : public virtual stc::any__simple<E>,
+ public oln::type
+ {
+ protected:
+ fun_p2v();
+ };
+
+
+ // Value -> Value.
+
+ template <typename E>
+ struct fun_v2v : public virtual stc::any__simple<E>,
+ public oln::type
+ {
+ protected:
+ fun_v2v();
+ };
+
+
+ // Point -> Point.
+
+ template <typename E>
+ struct fun_p2p : public virtual stc::any__simple<E>,
+ public oln::type
+ {
+ protected:
+ fun_p2p();
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename E>
+ fun_p2v<E>::fun_p2v()
+ {
+ }
+
+ template <typename E>
+ fun_v2v<E>::fun_v2v()
+ {
+ }
+
+ template <typename E>
+ fun_p2p<E>::fun_p2p()
+ {
+ }
+
+# endif
+
+ } // end of namespace oln::abstract
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_ABSTRACT_FUNCTIONS_HH
Index: oln/basics2d.hh
===================================================================
--- oln/basics2d.hh (revision 678)
+++ oln/basics2d.hh (working copy)
@@ -30,6 +30,9 @@
# define OLN_BASICS2D_HH
+# define OLN_ENV_2D
+
+
# include <oln/core/2d/aliases.hh>
# include <oln/core/gen/grid.hh>
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 678)
+++ oln/Makefile.am (working copy)
@@ -80,6 +80,7 @@
core/abstract/bbox.hh \
core/abstract/dpoint.hh \
core/abstract/entry.hh \
+ core/abstract/functions.hh \
core/abstract/fwd_decls.hh \
core/abstract/grid.hh \
core/abstract/image.hh \
@@ -165,6 +166,9 @@
\
io/pnm.hh \
\
+ level/apply.hh \
+ level/assign.hh \
+ level/clone.hh \
level/fill.hh \
\
morpher/internal/image_extension.hh \
Index: oln/basics3d.hh
===================================================================
--- oln/basics3d.hh (revision 678)
+++ oln/basics3d.hh (working copy)
@@ -30,6 +30,9 @@
# define OLN_BASICS3D_HH
+# define OLN_ENV_3D
+
+
# include <oln/core/3d/aliases.hh>
# include <oln/core/gen/grid.hh>
Index: oln/morpher/slice.hh
===================================================================
--- oln/morpher/slice.hh (revision 678)
+++ oln/morpher/slice.hh (working copy)
@@ -140,6 +140,58 @@
/// \}
+
+
+
+ // piters.
+
+ /// fwd_piter vtype of morpher::slice.
+ template <typename Image>
+ struct single_vtype< morpher::slice<Image>, typedef_::fwd_piter_type >
+ {
+ private:
+ typedef oln_type_of(Image, fwd_piter) orig_fwd_piter;
+ public:
+ typedef typename type_fun::slice_iterator<orig_fwd_piter>::ret ret;
+ };
+
+ /// bkd_piter vtype of morpher::slice.
+ template <typename Image>
+ struct single_vtype< morpher::slice<Image>, typedef_::bkd_piter_type >
+ {
+ private:
+ typedef oln_type_of(Image, bkd_piter) orig_bkd_piter;
+ public:
+ typedef typename type_fun::slice_iterator<orig_bkd_piter>::ret ret;
+ };
+
+
+ // qiters.
+
+ /// fwd_qiter vtype of morpher::slice.
+ template <typename Image>
+ struct single_vtype< morpher::slice<Image>, typedef_::fwd_qiter_type >
+ {
+ private:
+ typedef oln_type_of(Image, fwd_qiter) orig_fwd_qiter;
+ public:
+ typedef typename type_fun::slice_iterator<orig_fwd_qiter>::ret ret;
+ };
+
+ /// bkd_qiter vtype of morpher::slice.
+ template <typename Image>
+ struct single_vtype< morpher::slice<Image>, typedef_::bkd_qiter_type >
+ {
+ private:
+ typedef oln_type_of(Image, bkd_qiter) orig_bkd_qiter;
+ public:
+ typedef typename type_fun::slice_iterator<orig_bkd_qiter>::ret ret;
+ };
+
+
+
+
+
namespace morpher
{
@@ -203,4 +255,5 @@
} // end of namespace oln
+
#endif // ! OLN_MORPHER_SLICE_HH
1
0
25 Oct '06
2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Introduce ids for images and better oln::morpher::count_rw_.
* tests/morphers/count_rw_morpher.cc: Add sample code in comments.
* oln/core/abstract/iterator_on_points.hh (operator<<): New.
* oln/core/abstract/image.hh (image, operator=): New.
(id_, id): New.
* oln/core/gen/piter_isubset.hh (isubset_): Remove &.
* oln/core/gen/pw_value.hh (ima_): Remove &.
(impl_calc): Fix static check.
* oln/core/gen/topo_add_isubset.hh (isubset_): Add comment.
* oln/core/gen/fwd_piter_bbox.hh (operator<<): Remove; obsolete.
* oln/core/gen/bkd_piter_bbox.hh: Likewise.
* oln/morpher/add_isubset.hh (operator|): New overloading.
(add_isubset): Relax static check.
* oln/morpher/internal/image_value_morpher.hh (image_): Remove &.
* oln/morpher/internal/image_extension.hh (image_): Remove &.
(image_extension): New cpy ctor.
* oln/morpher/count_rw.hh (count_rw): Rename the class as...
(count_rw_): ...this.
(count_rw): New overloading.
* oln/value/rw_counter.hh (counter_rw): Rewrite.
(rw_counter): Remove & from ima_ type.
(ro_counter): Likewise.
Index: tests/morphers/count_rw_morpher.cc
===================================================================
--- tests/morphers/count_rw_morpher.cc (revision 677)
+++ tests/morphers/count_rw_morpher.cc (working copy)
@@ -38,7 +38,7 @@
typedef image2d<int> image_t;
image_t ima(3,3);
- morpher::count_rw<image_t> ima2(ima);
+ morpher::count_rw_<image_t> ima2(ima);
point2d p(0,0);
ima2(p);
@@ -46,8 +46,84 @@
int i = ima2(p);
i = 0; // suppress "unused i" warning
- assert(value::counter::n_readwrite_calls(ima) == 3);
- assert(value::counter::n_readonly_calls(ima) == 0);
- assert(value::counter::n_reads(ima) == 1);
- assert(value::counter::n_writes(ima) == 1);
+ assert(value::counter_rw::n_readwrite_calls(ima) == 3);
+ assert(value::counter_rw::n_readonly_calls(ima) == 0);
+ assert(value::counter_rw::n_reads(ima) == 1);
+ assert(value::counter_rw::n_writes(ima) == 1);
}
+
+
+/*
+
+// another piece of nice code:
+
+
+#include <cassert>
+
+#include <oln/basics2d.hh>
+#include <oln/core/gen/pw_value.hh>
+
+#include <oln/morpher/add_isubset.hh>
+#include <oln/morpher/add_neighborhood.hh>
+#include <oln/morpher/count_rw.hh>
+
+#include <oln/debug/print.hh>
+#include <oln/level/fill.hh>
+
+
+template <typename I>
+void test(const oln::abstract::image<I>& input)
+{
+ oln_value(I) dev_null;
+ oln_piter(I) p(input.topo());
+ oln_niter(I) n(p, input.topo());
+ for_all(p)
+ {
+ std::cout << p << ": ";
+ for_all(n)
+ {
+ std::cout << n << ' ';
+ dev_null = input(n); // read
+ }
+ std::cout << std::endl;
+ }
+}
+
+int main()
+{
+ using namespace oln;
+ typedef image2d<int> image_t;
+
+ image_t ima(5, 5);
+ int values[] =
+ { 3, 7, 1, 1, 7,
+ 9, 3, 2, 1, 1,
+ 1, 6, 5, 4, 3,
+ 7, 9, 8, 1, 3,
+ 3, 3, 9, 7, 1 };
+ ima << values;
+
+# define pred (pw_value(ima) % 2 == 0 or pw_value(ima) == 5)
+
+ debug::print(ima | pred);
+ test(count_rw((ima + c4) | pred));
+
+ value::counter_rw::print();
+
+// gives:
+// - - - - -
+// - - 2 - -
+// - 6 5 4 -
+// - - 8 - -
+// - - - - -
+// (1, 2): (2, 2)
+// (2, 1): (2, 2)
+// (2, 2): (1, 2) (2, 1) (2, 3) (3, 2)
+// (2, 3): (2, 2)
+// (3, 2): (2, 2)
+// n_readwrite_calls = 0
+// n_readonly_calls = 8
+// n_reads = 8
+// n_writes = 0
+
+*/
Index: oln/core/abstract/iterator_on_points.hh
===================================================================
--- oln/core/abstract/iterator_on_points.hh (revision 677)
+++ oln/core/abstract/iterator_on_points.hh (working copy)
@@ -91,7 +91,10 @@
}; // end of class oln::abstract::iterator_on_points<E>
+ template <typename E>
+ std::ostream& operator<<(std::ostream& ostr, const iterator_on_points<E>& pit);
+
# ifndef OLN_INCLUDE_ONLY
template <typename E>
@@ -130,6 +133,13 @@
}
+ template <typename E>
+ std::ostream& operator<<(std::ostream& ostr, const iterator_on_points<E>& pit)
+ {
+ return ostr << pit.to_point();
+ }
+
+
# endif
} // end of namespace oln::abstract
Index: oln/core/abstract/image.hh
===================================================================
--- oln/core/abstract/image.hh (revision 677)
+++ oln/core/abstract/image.hh (working copy)
@@ -40,6 +40,12 @@
namespace oln
{
+
+ // Fwd decl.
+ static unsigned& current_image_id();
+
+
+
/*! \namespace oln::abstract
** \brief oln::abstract namespace.
*/
@@ -108,17 +114,26 @@
oln_rvalue(E) operator()(const oln_psite(E)& p) const;
+ unsigned id() const;
+
protected:
- /*! \brief Constructor (protected, empty).
+ /*! \brief Constructors (protected).
*/
image();
- image(const image&);
+ image(const image& rhs);
+ /*! \brief Assignment (protected).
+ */
+ E& operator=(const image& rhs);
+
/*! \brief Destructor.
*/
virtual ~image();
+ private:
+
+ const unsigned id_;
};
@@ -139,17 +154,26 @@
template <typename E>
image<E>::image()
+ : id_(++current_image_id())
{
++debug::n_images;
}
template <typename E>
- image<E>::image(const image&)
+ image<E>::image(const image& rhs)
+ : id_(rhs.id_)
{
++debug::n_images;
}
template <typename E>
+ E& image<E>::operator=(const image<E>& rhs)
+ {
+ this->id_ = rhs.id_;
+ return this->exact();
+ }
+
+ template <typename E>
image<E>::~image()
{
decl();
@@ -157,6 +181,13 @@
}
template <typename E>
+ unsigned
+ image<E>::id() const
+ {
+ return id_;
+ }
+
+ template <typename E>
const oln_topo(E)&
image<E>::topo() const
{
@@ -176,6 +207,19 @@
} // end of namespace oln::abstract
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ static unsigned& current_image_id()
+ {
+ static unsigned id_ = 0;
+ return id_;
+ }
+
+# endif
+
+
} // end of namespace oln
Index: oln/core/gen/piter_isubset.hh
===================================================================
--- oln/core/gen/piter_isubset.hh (revision 677)
+++ oln/core/gen/piter_isubset.hh (working copy)
@@ -97,7 +97,7 @@
protected:
piter_t p_;
- const isubset_t& isubset_;
+ isubset_t isubset_; // Cpy.
}; // end of class oln::piter_isubset_<point>
Index: oln/core/gen/pw_value.hh
===================================================================
--- oln/core/gen/pw_value.hh (revision 677)
+++ oln/core/gen/pw_value.hh (working copy)
@@ -61,7 +61,7 @@
protected:
- const I& ima_;
+ const I ima_;
};
@@ -72,7 +72,8 @@
oln_rvalue(I)
pw_value_type<I>::impl_calc(const A& a) const
{
- mlc::assert_< mlc_is_a(A, oln::abstract::point) >::check();
+ mlc::assert_< mlc::or_< mlc_is_a(A, oln::abstract::point),
+ mlc_is_a(A, oln::abstract::iterator_on_points) > >::check();
return ima_(a);
}
Index: oln/core/gen/topo_add_isubset.hh
===================================================================
--- oln/core/gen/topo_add_isubset.hh (revision 677)
+++ oln/core/gen/topo_add_isubset.hh (working copy)
@@ -84,7 +84,7 @@
protected:
topo_t topo_;
- isubset_t isubset_;
+ isubset_t isubset_; // Cpy.
};
Index: oln/core/gen/fwd_piter_bbox.hh
===================================================================
--- oln/core/gen/fwd_piter_bbox.hh (revision 677)
+++ oln/core/gen/fwd_piter_bbox.hh (working copy)
@@ -79,11 +79,7 @@
}; // end of class oln::fwd_piter_bbox_<point>
- template <typename point_t>
- std::ostream& operator<<(std::ostream& ostr, const fwd_piter_bbox_<point_t>& t);
-
-
# ifndef OLN_INCLUDE_ONLY
template <typename point_t>
@@ -100,14 +96,6 @@
<< " }";
}
- template <typename point_t>
- std::ostream& operator<<(std::ostream& ostr, const fwd_piter_bbox_<point_t>& t)
- {
- t.print(ostr);
- return ostr;
- }
-
-
# endif
} // end of namespace oln
Index: oln/core/gen/bkd_piter_bbox.hh
===================================================================
--- oln/core/gen/bkd_piter_bbox.hh (revision 677)
+++ oln/core/gen/bkd_piter_bbox.hh (working copy)
@@ -79,11 +79,7 @@
}; // end of class oln::bkd_piter_bbox_<point_t>
- template <typename point_t>
- std::ostream& operator<<(std::ostream& ostr, const bkd_piter_bbox_<point_t>& t);
-
-
# ifndef OLN_INCLUDE_ONLY
template <typename point_t>
@@ -100,13 +96,6 @@
<< " }";
}
- template <typename point_t>
- std::ostream& operator<<(std::ostream& ostr, const bkd_piter_bbox_<point_t>& t)
- {
- t.print(ostr);
- return ostr;
- }
-
# endif
} // end of namespace oln
Index: oln/morpher/add_isubset.hh
===================================================================
--- oln/morpher/add_isubset.hh (revision 677)
+++ oln/morpher/add_isubset.hh (working copy)
@@ -34,7 +34,10 @@
# include <oln/core/gen/topo_add_isubset.hh>
# include <oln/core/gen/piter_isubset.hh>
+# include <xtd/abstract/fun_nary_expr.hh>
+# include <oln/core/gen/pw_value.hh>
+
namespace oln
{
@@ -124,7 +127,7 @@
super_t(image),
topo_(image.topo(), isubset)
{
- mlc::assert_equal_<oln_type_of(Image, grid), oln_type_of(Isubset, grid)>::check();
+ // mlc::assert_equal_<oln_type_of(Image, grid), oln_type_of(Isubset, grid)>::check();
// FIXME: check that Image is without a isubset
}
@@ -151,6 +154,13 @@
// FIXME: Add mutable version.
+ template <typename I, typename S>
+ morpher::add_isubset<I, S>
+ operator | (const abstract::image<I>& image,
+ const xtd::abstract::fun_nary_expr_<1,S>& fsubset);
+
+
+
# ifndef OLN_INCLUDE_ONLY
template <typename I, typename S>
@@ -164,6 +174,15 @@
return tmp;
}
+ template <typename I, typename S>
+ morpher::add_isubset<I, S>
+ operator | (const abstract::image<I>& image,
+ const xtd::abstract::fun_nary_expr_<1,S>& fsubset)
+ {
+ morpher::add_isubset<I, S> tmp(image.exact(), fsubset.exact_());
+ return tmp;
+ }
+
# endif
} // end of namespace oln
Index: oln/morpher/internal/image_value_morpher.hh
===================================================================
--- oln/morpher/internal/image_value_morpher.hh (revision 677)
+++ oln/morpher/internal/image_value_morpher.hh (working copy)
@@ -96,7 +96,7 @@
Image& delegate();
protected:
- Image& image_;
+ Image image_;
};
Index: oln/morpher/internal/image_extension.hh
===================================================================
--- oln/morpher/internal/image_extension.hh (revision 677)
+++ oln/morpher/internal/image_extension.hh (working copy)
@@ -86,6 +86,7 @@
// FIXME: Handle the constness.
image_extension(const Image& image);
+ image_extension(Image& image);
const Image& delegate() const;
Image& delegate();
@@ -100,6 +101,12 @@
template <typename Image, typename Exact>
image_extension<Image, Exact>::image_extension(const Image& image) :
+ image_(const_cast<Image&>(image))
+ {
+ }
+
+ template <typename Image, typename Exact>
+ image_extension<Image, Exact>::image_extension(Image& image) :
image_(image)
{
}
Index: oln/morpher/count_rw.hh
===================================================================
--- oln/morpher/count_rw.hh (revision 677)
+++ oln/morpher/count_rw.hh (working copy)
@@ -39,22 +39,22 @@
namespace morpher
{
// Forward declaration.
- template <typename Image> struct count_rw;
+ template <typename Image> struct count_rw_;
} // end of namespace oln::morpher
/// Super type.
template <typename Image>
- struct set_super_type< morpher::count_rw<Image> >
+ struct set_super_type< morpher::count_rw_<Image> >
{
- typedef morpher::count_rw<Image> self_t;
+ typedef morpher::count_rw_<Image> self_t;
typedef morpher::internal::image_value_morpher<Image, self_t> ret;
};
template <typename Image>
- struct vtypes< morpher::count_rw<Image> >
+ struct vtypes< morpher::count_rw_<Image> >
{
public:
typedef mlc::true_ is_computed_type;
@@ -64,7 +64,7 @@
};
template <typename Image>
- struct single_vtype< morpher::count_rw<Image>, typedef_::rvalue_type >
+ struct single_vtype< morpher::count_rw_<Image>, typedef_::rvalue_type >
{
typedef value::ro_counter<Image> ret;
};
@@ -76,20 +76,20 @@
/// 'Image thru Function' morpher.
template <typename Image>
- class count_rw : public internal::image_value_morpher< Image,
- morpher::count_rw<Image> >
+ class count_rw_ : public internal::image_value_morpher< Image,
+ morpher::count_rw_<Image> >
{
private:
- typedef count_rw<Image> self_t;
+ typedef count_rw_<Image> self_t;
typedef internal::image_value_morpher<Image, self_t> super_t;
using super_t::image_;
public:
- count_rw(Image& image);
- count_rw(oln::abstract::mutable_image<Image>& image);
+ count_rw_(Image& image);
+ count_rw_(oln::abstract::mutable_image<Image>& image);
oln_rvalue(self_t) impl_op_read(const oln_psite(self_t)& p) const;
oln_lvalue(self_t) impl_op_readwrite(const oln_psite(self_t)& p);
@@ -109,28 +109,28 @@
// public
template <typename Image>
- count_rw<Image>::count_rw(Image& image) :
+ count_rw_<Image>::count_rw_(Image& image) :
super_t(image)
{
}
template <typename Image>
- count_rw<Image>::count_rw(oln::abstract::mutable_image<Image>& image) :
+ count_rw_<Image>::count_rw_(oln::abstract::mutable_image<Image>& image) :
super_t(image.exact())
{
}
template <typename Image>
- oln_rvalue(count_rw<Image>)
- count_rw<Image>::impl_op_read(const oln_psite(count_rw<Image>)& p) const
+ oln_rvalue(count_rw_<Image>)
+ count_rw_<Image>::impl_op_read(const oln_psite(count_rw_<Image>)& p) const
{
value::ro_counter<Image> tmp(image_, p);
return tmp;
}
template <typename Image>
- oln_lvalue(count_rw<Image>)
- count_rw<Image>::impl_op_readwrite(const oln_psite(count_rw<Image>)& p)
+ oln_lvalue(count_rw_<Image>)
+ count_rw_<Image>::impl_op_readwrite(const oln_psite(count_rw_<Image>)& p)
{
value::rw_counter<Image> tmp(image_, p);
return tmp;
@@ -142,14 +142,24 @@
template <typename I>
- morpher::count_rw<I>
+ morpher::count_rw_<I>
count_rw(oln::abstract::mutable_image<I>& input)
{
- morpher::count_rw<I> tmp(input.exact());
+ morpher::count_rw_<I> tmp(input.exact());
return tmp;
}
+ template <typename I>
+ morpher::count_rw_<I>
+ count_rw(const oln::abstract::mutable_image<I>& input)
+ {
+ // FIXME: Hack.
+ I& input_ = const_cast<I&>(input.exact());
+ morpher::count_rw_<I> tmp(input_);
+ return tmp;
+ }
+
} // end of namespace oln
Index: oln/value/rw_counter.hh
===================================================================
--- oln/value/rw_counter.hh (revision 677)
+++ oln/value/rw_counter.hh (working copy)
@@ -30,6 +30,7 @@
# include <iostream>
# include <map>
+# include <set>
# include <oln/value/proxy.hh>
# include <oln/core/abstract/image/all.hh>
@@ -42,45 +43,80 @@
{
- struct counter
+ struct counter_rw
{
- typedef std::map<void*, unsigned> map_t;
+ typedef std::map<unsigned, unsigned> map_t;
+ typedef std::set<unsigned> set_t;
+ static map_t n_rwc_;
+ static map_t n_roc_;
+ static map_t n_r_;
+ static map_t n_w_;
+ static set_t ids_;
// read-write call
- static unsigned& n_readwrite_calls(const oln::type& ima)
+ template <typename I>
+ static unsigned& n_readwrite_calls(const oln::abstract::image<I>& ima)
{
- static map_t n;
- return n[(void*)(&ima)];
+ ids_.insert(ima.id());
+ return n_rwc_[ima.id()];
}
// read-only call
- static unsigned& n_readonly_calls(const oln::type& ima)
+ template <typename I>
+ static unsigned& n_readonly_calls(const oln::abstract::image<I>& ima)
{
- static map_t n;
- return n[(void*)(&ima)];
+ ids_.insert(ima.id());
+ return n_roc_[ima.id()];
}
// read (effective)
- static unsigned& n_reads(const oln::type& ima)
+ template <typename I>
+ static unsigned& n_reads(const oln::abstract::image<I>& ima)
{
- static map_t n;
- return n[(void*)(&ima)];
+ ids_.insert(ima.id());
+ return n_r_[ima.id()];
}
// write (effective)
- static unsigned& n_writes(const oln::type& ima)
+ template <typename I>
+ static unsigned& n_writes(const oln::abstract::image<I>& ima)
{
- static map_t n;
- return n[(void*)(&ima)];
+ ids_.insert(ima.id());
+ return n_w_[ima.id()];
}
- static void print(const oln::type& ima)
+ static void print(unsigned id)
{
- std::cout << "n_readwrite_calls = " << n_readwrite_calls(ima) << std::endl
- << "n_readonly_calls = " << n_readonly_calls(ima) << std::endl
- << "n_reads = " << n_reads(ima) << std::endl
- << "n_writes = " << n_writes(ima) << std::endl;
+ ids_.insert(id);
+ std::cout << "n_readwrite_calls = " << n_rwc_[id] << std::endl
+ << "n_readonly_calls = " << n_roc_[id] << std::endl
+ << "n_reads = " << n_r_[id] << std::endl
+ << "n_writes = " << n_w_[id] << std::endl;
}
+
+ template <typename I>
+ static void print(const oln::abstract::image<I>& ima)
+ {
+ print(ima.id());
+ }
+
+ static void print()
+ {
+ set_t::const_iterator it;
+ for (it = ids_.begin(); it != ids_.end(); ++it)
+ print(*it);
+ }
};
+# ifndef OLN_INCLUDE_ONLY
+
+ counter_rw::map_t counter_rw::n_rwc_;
+ counter_rw::map_t counter_rw::n_roc_;
+ counter_rw::map_t counter_rw::n_r_;
+ counter_rw::map_t counter_rw::n_w_;
+ counter_rw::set_t counter_rw::ids_;
+
+# endif
+
+
template <typename I>
class rw_counter : public abstract::proxy< rw_counter<I> >
{
@@ -104,7 +140,7 @@
rw_counter<I>& operator=(const V& value);
protected:
- I& ima_;
+ I ima_;
const oln_psite(I)& p_;
};
@@ -132,7 +168,7 @@
oln_rvalue(I) value() const;
protected:
- const I& ima_;
+ const I ima_;
const oln_psite(I)& p_;
};
@@ -151,7 +187,7 @@
: ima_(ima.exact()),
p_(p)
{
- ++counter::n_readwrite_calls(ima_);
+ ++counter_rw::n_readwrite_calls(ima_);
}
// Read.
@@ -159,7 +195,7 @@
template <typename V>
rw_counter<I>::operator V() const
{
- ++counter::n_reads(ima_);
+ ++counter_rw::n_reads(ima_);
V tmp = ima_(p_);
return tmp;
}
@@ -169,7 +205,7 @@
oln_rvalue(I)
rw_counter<I>::value() const
{
- ++counter::n_reads(ima_);
+ ++counter_rw::n_reads(ima_);
return ima_(p_);
}
@@ -181,7 +217,7 @@
rw_counter<I>::operator=(const V& value)
{
ima_(p_) = value;
- ++counter::n_writes(ima_);
+ ++counter_rw::n_writes(ima_);
return *this;
}
@@ -201,7 +237,7 @@
: ima_(ima.exact()),
p_(p)
{
- ++counter::n_readonly_calls(ima_);
+ ++counter_rw::n_readonly_calls(ima_);
}
// Read.
@@ -209,7 +245,7 @@
template <typename V>
ro_counter<I>::operator V() const
{
- ++counter::n_reads(ima_);
+ ++counter_rw::n_reads(ima_);
V tmp = ima_(p_);
return tmp;
}
@@ -219,7 +255,7 @@
oln_rvalue(I)
ro_counter<I>::value() const
{
- ++counter::n_reads(ima_);
+ ++counter_rw::n_reads(ima_);
return ima_(p_);
}
1
0
2006-10-25 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Update xtd bool op traits.
* xtd/builtin/traits.hh (bool): Fix partially.
* xtd/internal/opmacros.hh
(xtd_internal_decl_binary_logical_operator): New macro.
* xtd/math/logic.hh: Update.
Index: xtd/math/logic.hh
===================================================================
--- xtd/math/logic.hh (revision 676)
+++ xtd/math/logic.hh (working copy)
@@ -34,9 +34,9 @@
namespace xtd
{
- xtd_internal_decl_binary_operator( land, and );
- xtd_internal_decl_binary_operator( lor, or );
- xtd_internal_decl_binary_operator( lxor, xor );
+ xtd_internal_decl_binary_logical_operator( land, and );
+ xtd_internal_decl_binary_logical_operator( lor, or );
+ xtd_internal_decl_binary_logical_operator( lxor, xor );
xtd_internal_decl_unary_operator( lnot, not );
Index: xtd/builtin/traits.hh
===================================================================
--- xtd/builtin/traits.hh (revision 676)
+++ xtd/builtin/traits.hh (working copy)
@@ -76,7 +76,8 @@
: public mlc::where_< mlc::or_< mlc::eq_<L, bool>,
mlc::eq_<R, bool> > >
{
- typedef mlc::undefined ret;
+ // FIXME: check that both L and R are bool and that it is not an arithmetical trait
+ typedef bool ret;
};
// 2) If either operand is of type long double, the other shall be
Index: xtd/internal/opmacros.hh
===================================================================
--- xtd/internal/opmacros.hh (revision 676)
+++ xtd/internal/opmacros.hh (working copy)
@@ -199,4 +199,73 @@
+# define xtd_internal_decl_binary_logical_operator(OperatorName, OperatorSymbol) \
+ \
+ \
+ template <typename T1, typename T2> \
+ struct plain_##OperatorName##_; \
+ \
+ template <typename T1, typename T2> \
+ struct fun_traits_< plain_##OperatorName##_<T1, T2> > \
+ { \
+ typedef T1 arg1_type; \
+ typedef T2 arg2_type; \
+ typedef xtd_op_##OperatorName##_trait(T1, T2) res_type; \
+ }; \
+ \
+ \
+ template <typename T1, typename T2> \
+ struct plain_##OperatorName##_ \
+ \
+ : public abstract::plain_nary_fun_< 2, plain_##OperatorName##_<T1, T2> > \
+ { \
+ typedef plain_##OperatorName##_<T1, T2> self; \
+ xtd_res(self) impl_op(const T1& arg1, const T2& arg2) const \
+ { \
+ return arg1 OperatorSymbol arg2; \
+ } \
+ }; \
+ \
+ \
+ typedef m2fun_<plain_##OperatorName##_> OperatorName##_type; \
+ const OperatorName##_type OperatorName; \
+ \
+ \
+ template <typename L, typename R> \
+ struct case_ < op_##OperatorName, mlc::pair_<L, R>, \
+ 2 > : public mlc::where_< mlc::or_< mlc_is_a(L, xtd::abstract::fun_expr_), \
+ mlc_is_a(R, xtd::abstract::fun_expr_) > > \
+ { \
+ struct protected_ { \
+ typedef typename mlc::if_< mlc_is_a(L, xtd::abstract::fun_expr_), \
+ L, \
+ xtd::literal_expr_<L> >::ret Lexpr; \
+ \
+ typedef typename mlc::if_< mlc_is_a(R, xtd::abstract::fun_expr_), \
+ R, \
+ xtd::literal_expr_<R> >::ret Rexpr; \
+ \
+ typedef xtd::m2expr_<xtd::OperatorName##_type, Lexpr, Rexpr> ret; \
+ }; \
+ }; \
+ \
+ \
+ template <typename Lexpr, typename Rexpr> \
+ xtd::m2expr_<xtd::OperatorName##_type, Lexpr, Rexpr> \
+ operator OperatorSymbol (const xtd::abstract::fun_expr_<Lexpr>& lexpr, \
+ const xtd::abstract::fun_expr_<Rexpr>& rexpr) \
+ { \
+ xtd::m2expr_<xtd::OperatorName##_type, Lexpr, Rexpr> tmp(lexpr, rexpr); \
+ return tmp; \
+ } \
+ \
+ \
+ xtd_internal_decl_binop_w_lit(OperatorName, OperatorSymbol, bool); \
+ \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+
#endif // ! XTD_INTERNAL_OPMACROS_HH
1
0
2006-10-24 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add point-wise values.
* tests/core/pw_value.cc: New.
* tests/core/Makefile.am: Update.
* oln/core/gen/pw_value.hh: New.
* oln/Makefile.am: Update.
Index: tests/core/pw_value.cc
===================================================================
--- tests/core/pw_value.cc (revision 0)
+++ tests/core/pw_value.cc (revision 0)
@@ -0,0 +1,50 @@
+// 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.
+
+/// Test pw_value.
+
+#include <cassert>
+
+#include <oln/basics2d.hh>
+#include <oln/core/gen/pw_value.hh>
+
+
+
+int main()
+{
+ using namespace oln;
+
+ point2d p(0,0);
+ image2d<int> ima1(3,3);
+ ima1(p) = 1;
+
+ image2d<float> ima2(3,3);
+ ima2(p) = 2.3;
+
+ double d = ((pw_value(ima1) + 4 * pw_value(ima2)) / .2)(p);
+ assert(d > 50.9999 and d < 51.0001);
+}
Index: tests/core/Makefile.am
===================================================================
--- tests/core/Makefile.am (revision 675)
+++ tests/core/Makefile.am (working copy)
@@ -27,6 +27,7 @@
image2d \
image3d \
npoints \
+ pw_value \
window2d \
\
at
@@ -40,6 +41,7 @@
image2d_SOURCES = image2d.cc
image3d_SOURCES = image3d.cc
npoints_SOURCES = npoints.cc
+pw_value_SOURCES = pw_value.cc
window2d_SOURCES = window2d.cc
# Methods.
Index: oln/core/gen/pw_value.hh
===================================================================
--- oln/core/gen/pw_value.hh (revision 0)
+++ oln/core/gen/pw_value.hh (revision 0)
@@ -0,0 +1,106 @@
+// 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_GEN_PW_VALUE_HH
+# define OLN_CORE_GEN_PW_VALUE_HH
+
+# include <oln/core/abstract/image.hh>
+# include <xtd/abstract/meta_nary_fun.hh>
+# include <xtd/math.hh>
+
+
+
+namespace xtd
+{
+
+ // Fwd decl.
+ template <typename I>
+ class pw_value_type;
+
+
+ template <typename I, typename A>
+ struct res_< pw_value_type<I>, A >
+ {
+ typedef oln_rvalue(I) ret;
+ };
+
+
+ template <typename I>
+ class pw_value_type : public xtd::abstract::meta_nary_fun_< 1, pw_value_type<I> >
+ {
+ public:
+
+ pw_value_type(const I& ima);
+
+ template <typename P>
+ oln_rvalue(I) impl_calc(const P& p) const;
+
+ protected:
+
+ const I& ima_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ template <typename A>
+ oln_rvalue(I)
+ pw_value_type<I>::impl_calc(const A& a) const
+ {
+ mlc::assert_< mlc_is_a(A, oln::abstract::point) >::check();
+ return ima_(a);
+ }
+
+ template <typename I>
+ pw_value_type<I>::pw_value_type(const I& ima)
+ : ima_(ima)
+ {
+ }
+
+# endif
+
+
+} // end of namespace xtd
+
+
+namespace oln
+{
+
+ template <typename I>
+ xtd::m1expr_< xtd::pw_value_type<I>, xtd::arg_<1> >
+ pw_value(const abstract::image<I>& ima)
+ {
+ xtd::pw_value_type<I> pwv(ima.exact());
+ using xtd::_1;
+ return pwv(_1); // expects one argument (for instance a point) or an expression :)
+ }
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_PW_VALUE_HH
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 675)
+++ oln/Makefile.am (working copy)
@@ -123,6 +123,7 @@
core/gen/grid.hh \
core/gen/mapimage.hh \
core/gen/neighb.hh \
+ core/gen/pw_value.hh \
core/gen/topo_add_nbh.hh \
core/gen/topo_bbox.hh \
core/gen/topo_lbbox.hh \
1
0
2006-10-24 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add a morpher to count read-write ops.
* tests/morphers/count_rw_morpher.cc: New.
* tests/morphers/Makefile.am: Update.
* oln/morpher/count_rw.hh: New.
* oln/value/proxy.hh: New.
* oln/value/rw_counter.hh: New.
* oln/Makefile.am: Update.
* oln/core/traits_id.hh (unop_vproxy, binop_vproxy): New.
(others): Update.
* oln/core/typedefs.hh
(oln_is_computed, oln_is_computed_): New.
* oln/morpher/internal/image_value_morpher.hh
(image_value_morpher): New overloading for ctor.
(image_): Add & to its type.
Index: tests/morphers/count_rw_morpher.cc
===================================================================
--- tests/morphers/count_rw_morpher.cc (revision 0)
+++ tests/morphers/count_rw_morpher.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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.
+
+/// Test the count_rw morpher.
+
+#include <cassert>
+#include <oln/basics2d.hh>
+#include <oln/morpher/count_rw.hh>
+
+
+int main()
+{
+ using namespace oln;
+
+ typedef image2d<int> image_t;
+ image_t ima(3,3);
+ morpher::count_rw<image_t> ima2(ima);
+ point2d p(0,0);
+
+ ima2(p);
+ ima2(p) = 51;
+ int i = ima2(p);
+ i = 0; // suppress "unused i" warning
+
+ assert(value::counter::n_readwrite_calls(ima) == 3);
+ assert(value::counter::n_readonly_calls(ima) == 0);
+ assert(value::counter::n_reads(ima) == 1);
+ assert(value::counter::n_writes(ima) == 1);
+}
Index: tests/morphers/Makefile.am
===================================================================
--- tests/morphers/Makefile.am (revision 674)
+++ tests/morphers/Makefile.am (working copy)
@@ -21,6 +21,7 @@
check_PROGRAMS = \
identity_morpher \
add_neighborhood_morpher \
+ count_rw_morpher \
slice_morpher \
stack_morpher \
value_cast \
@@ -31,6 +32,7 @@
# Morphers.
identity_morpher_SOURCES = identity_morpher.cc
add_neighborhood_morpher_SOURCES = add_neighborhood_morpher.cc
+count_rw_morpher_SOURCES = count_rw_morpher.cc
slice_morpher_SOURCES = slice_morpher.cc
stack_morpher_SOURCES = stack_morpher.cc
value_cast_SOURCES = value_cast.cc
Index: oln/core/traits_id.hh
===================================================================
--- oln/core/traits_id.hh (revision 674)
+++ oln/core/traits_id.hh (working copy)
@@ -37,12 +37,22 @@
namespace id
{
+ /// \{
+ /// Generic identifiers for operators.
+ enum {
+ unop_vproxy = 1,
+ binop_vproxy = 1
+ };
+
+ /// \}
+
+
/// \{
/// Identifiers for oln binary operators +.
enum {
- op_plus_pointnd_dpointnd = 1
+ op_plus_pointnd_dpointnd = 2
};
/// \}
@@ -53,8 +63,8 @@
/// Identifiers for oln binary operators -.
enum {
- op_minus_pointnd_pointnd = 1,
- op_minus_pointnd_dpointnd = 2
+ op_minus_pointnd_pointnd = 2,
+ op_minus_pointnd_dpointnd = 3
};
/// \}
@@ -65,7 +75,7 @@
/// Identifiers for oln unary operators -.
enum {
- op_uminus_dpointnd = 1
+ op_uminus_dpointnd = 2
};
/// \}
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 674)
+++ oln/core/typedefs.hh (working copy)
@@ -227,6 +227,9 @@
# define oln_dpoint(T) oln_type_of(T, dpoint)
# define oln_dpoint_(T) oln_type_of_(T, dpoint)
+# define oln_is_computed(T) oln_type_of(T, is_computed)
+# define oln_is_computed_(T) oln_type_of_(T, is_computed)
+
# define oln_value(T) oln_type_of(T, value)
# define oln_value_(T) oln_type_of_(T, value)
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 674)
+++ oln/Makefile.am (working copy)
@@ -170,6 +170,7 @@
morpher/internal/image_value_morpher.hh \
\
morpher/add_neighborhood.hh \
+ morpher/count_rw.hh \
morpher/fwd_decls.hh \
morpher/identity.hh \
morpher/tags.hh \
@@ -186,6 +187,8 @@
value/all.hh \
value/default.hh \
value/greylevel.hh \
+ value/proxy.hh \
+ value/rw_counter.hh \
value/tags.hh \
\
basics1d.hh \
Index: oln/morpher/internal/image_value_morpher.hh
===================================================================
--- oln/morpher/internal/image_value_morpher.hh (revision 674)
+++ oln/morpher/internal/image_value_morpher.hh (working copy)
@@ -88,13 +88,15 @@
{
public:
- // FIXME: Handle the constness.
+ // FIXME: Hack here; constness should be properly handled.
image_value_morpher(const Image& image);
+ image_value_morpher(Image& image);
+
const Image& delegate() const;
Image& delegate();
protected:
- Image image_;
+ Image& image_;
};
@@ -103,6 +105,12 @@
template <typename Image, typename Exact>
image_value_morpher<Image, Exact>::image_value_morpher(const Image& image) :
+ image_(const_cast<Image&>(image))
+ {
+ }
+
+ template <typename Image, typename Exact>
+ image_value_morpher<Image, Exact>::image_value_morpher(Image& image) :
image_(image)
{
}
Index: oln/morpher/count_rw.hh
===================================================================
--- oln/morpher/count_rw.hh (revision 0)
+++ oln/morpher/count_rw.hh (revision 0)
@@ -0,0 +1,156 @@
+// 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_COUNT_RW_HH
+# define OLN_MORPHER_COUNT_RW_HH
+
+# include <oln/value/rw_counter.hh>
+# include <oln/morpher/internal/image_value_morpher.hh>
+
+
+namespace oln
+{
+
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <typename Image> struct count_rw;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <typename Image>
+ struct set_super_type< morpher::count_rw<Image> >
+ {
+ typedef morpher::count_rw<Image> self_t;
+ typedef morpher::internal::image_value_morpher<Image, self_t> ret;
+ };
+
+
+ template <typename Image>
+ struct vtypes< morpher::count_rw<Image> >
+ {
+ public:
+ typedef mlc::true_ is_computed_type;
+
+ typedef oln_value(Image) value_type;
+ typedef value::rw_counter<Image> lvalue_type;
+ };
+
+ template <typename Image>
+ struct single_vtype< morpher::count_rw<Image>, typedef_::rvalue_type >
+ {
+ typedef value::ro_counter<Image> ret;
+ };
+
+
+
+ namespace morpher
+ {
+
+ /// 'Image thru Function' morpher.
+ template <typename Image>
+ class count_rw : public internal::image_value_morpher< Image,
+ morpher::count_rw<Image> >
+ {
+ private:
+
+ typedef count_rw<Image> self_t;
+ typedef internal::image_value_morpher<Image, self_t> super_t;
+
+ using super_t::image_;
+
+ public:
+
+ count_rw(Image& image);
+ count_rw(oln::abstract::mutable_image<Image>& image);
+
+ oln_rvalue(self_t) impl_op_read(const oln_psite(self_t)& p) const;
+ oln_lvalue(self_t) impl_op_readwrite(const oln_psite(self_t)& p);
+ };
+
+
+ namespace ERROR
+ {
+
+ struct FIXME;
+
+ } // end of namespace oln::morpher::ERROR
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // public
+
+ template <typename Image>
+ count_rw<Image>::count_rw(Image& image) :
+ super_t(image)
+ {
+ }
+
+ template <typename Image>
+ count_rw<Image>::count_rw(oln::abstract::mutable_image<Image>& image) :
+ super_t(image.exact())
+ {
+ }
+
+ template <typename Image>
+ oln_rvalue(count_rw<Image>)
+ count_rw<Image>::impl_op_read(const oln_psite(count_rw<Image>)& p) const
+ {
+ value::ro_counter<Image> tmp(image_, p);
+ return tmp;
+ }
+
+ template <typename Image>
+ oln_lvalue(count_rw<Image>)
+ count_rw<Image>::impl_op_readwrite(const oln_psite(count_rw<Image>)& p)
+ {
+ value::rw_counter<Image> tmp(image_, p);
+ return tmp;
+ }
+
+# endif
+
+ } // end of namespace oln::morpher
+
+
+ template <typename I>
+ morpher::count_rw<I>
+ count_rw(oln::abstract::mutable_image<I>& input)
+ {
+ morpher::count_rw<I> tmp(input.exact());
+ return tmp;
+ }
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHER_COUNT_RW_HH
Index: oln/value/proxy.hh
===================================================================
--- oln/value/proxy.hh (revision 0)
+++ oln/value/proxy.hh (revision 0)
@@ -0,0 +1,472 @@
+// 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_VALUE_PROXY_HH
+# define OLN_CORE_VALUE_PROXY_HH
+
+# include <xtd/optraits.hh>
+# include <oln/core/type.hh>
+# include <oln/core/traits_id.hh>
+
+
+namespace oln
+{
+
+
+ namespace value
+ {
+
+ namespace abstract
+ {
+
+ template <typename E>
+ struct proxy : public virtual stc::any__simple<E>,
+ public oln::type
+ {
+ protected:
+ proxy();
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename E>
+ proxy<E>::proxy()
+ {
+ }
+
+# endif
+
+ } // end of namespace oln::value::abstract
+
+
+ } // end of namespace oln::value
+
+
+
+ // Traits.
+ //---------------------------
+
+
+ /// unary op on a value proxy
+ template <typename name, typename T>
+ struct case_ < xtd::op_<name>, T,
+ oln::id::unop_vproxy >
+ : where_< mlc_is_a(T, value::abstract::proxy) >
+ {
+ struct protected_ {
+ typedef typename T::value_type V;
+ typedef xtd_unop_trait(xtd::op_<name>, V) ret;
+ };
+ };
+
+
+ /// binary op involving at least one value proxy
+ template <typename name, typename T1, typename T2>
+ struct case_ < xtd::op_<name>, mlc::pair_<T1,T2>,
+ oln::id::binop_vproxy >
+ : where_< mlc::or_< mlc_is_a(T1, value::abstract::proxy),
+ mlc_is_a(T2, value::abstract::proxy) > >
+ {
+ template <typename T>
+ struct value_type
+ {
+ typedef mlc_typedef(T, value_type) V;
+ typedef typename mlc::if_< mlc_is_found(V), V, T >::ret ret;
+ };
+ struct protected_ {
+ typedef mlc_ret(value_type<T1>) V1;
+ typedef mlc_ret(value_type<T2>) V2;
+ typedef xtd_binop_trait(xtd::op_<name>, V1, V2) ret;
+ };
+ };
+
+
+
+ // Unary ops.
+ //---------------------------
+
+
+ // Op -.
+ template <typename P>
+ xtd_op_uminus_trait(P) operator - (const value::abstract::proxy<P>& val);
+ // Op not.
+ template <typename P>
+ xtd_op_lnot_trait(P) operator not (const value::abstract::proxy<P>& val);
+
+ // FIXME: To be continued.
+
+
+
+ // Binary ops.
+ //---------------------------
+
+ // Op +.
+ template <typename P, typename V>
+ xtd_op_plus_trait(P, V) operator + (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_plus_trait(V, P) operator + (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op -.
+ template <typename P, typename V>
+ xtd_op_minus_trait(P, V) operator - (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_minus_trait(V, P) operator - (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op *.
+ template <typename P, typename V>
+ xtd_op_mult_trait(P, V) operator * (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_mult_trait(V, P) operator * (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op /.
+ template <typename P, typename V>
+ xtd_op_div_trait(P, V) operator / (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_div_trait(V, P) operator / (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op %.
+ template <typename P, typename V>
+ xtd_op_mod_trait(P, V) operator % (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_mod_trait(V, P) operator % (const V& lhs, const value::abstract::proxy<P>& rhs);
+
+ // Op ==.
+ template <typename P, typename V>
+ xtd_op_eq_trait(P, V) operator == (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_eq_trait(V, P) operator == (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op !=.
+ template <typename P, typename V>
+ xtd_op_neq_trait(P, V) operator != (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_neq_trait(V, P) operator != (const V& lhs, const value::abstract::proxy<P>& rhs);
+
+ // Op <.
+ template <typename P, typename V>
+ xtd_op_less_trait(P, V) operator < (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_less_trait(V, P) operator < (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op <=.
+ template <typename P, typename V>
+ xtd_op_leq_trait(P, V) operator <= (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_leq_trait(V, P) operator <= (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op >=.
+ template <typename P, typename V>
+ xtd_op_geq_trait(P, V) operator >= (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_geq_trait(V, P) operator >= (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op >.
+ template <typename P, typename V>
+ xtd_op_greater_trait(P, V) operator > (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_greater_trait(V, P) operator > (const V& lhs, const value::abstract::proxy<P>& rhs);
+
+ // Op and.
+ template <typename P, typename V>
+ xtd_op_land_trait(P, V) operator and (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_land_trait(V, P) operator and (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op or.
+ template <typename P, typename V>
+ xtd_op_lor_trait(P, V) operator or (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_lor_trait(V, P) operator or (const V& lhs, const value::abstract::proxy<P>& rhs);
+ // Op xor.
+ template <typename P, typename V>
+ xtd_op_lxor_trait(P, V) operator xor (const value::abstract::proxy<P>& lhs, const V& rhs);
+ template <typename V, typename P>
+ xtd_op_lxor_trait(V, P) operator xor (const V& lhs, const value::abstract::proxy<P>& rhs);
+
+ // FIXME: To be continued.
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+ // Unary ops.
+ //---------------------------
+
+
+ // Op -.
+ template <typename P>
+ xtd_op_uminus_trait(P) operator - (const value::abstract::proxy<P>& val)
+ {
+ return - val.exact().value();
+ }
+
+ // Op not.
+
+ template <typename P>
+ xtd_op_lnot_trait(P)
+ operator not (const value::abstract::proxy<P>& val)
+ {
+ return not val.exact().value();
+ }
+
+
+ // FIXME: To be continued.
+
+
+
+ // Binary ops.
+ //---------------------------
+
+ // Op +.
+
+ template <typename P, typename V>
+ xtd_op_plus_trait(P, V)
+ operator + (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() + rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_plus_trait(V, P)
+ operator + (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs + rhs.exact().value();
+ }
+
+ // Op -.
+
+ template <typename P, typename V>
+ xtd_op_minus_trait(P, V)
+ operator - (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() - rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_minus_trait(V, P)
+ operator - (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs - rhs.exact().value();
+ }
+
+ // Op *.
+
+ template <typename P, typename V>
+ xtd_op_mult_trait(P, V)
+ operator * (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() * rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_mult_trait(V, P)
+ operator * (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs * rhs.exact().value();
+ }
+
+ // Op /.
+
+ template <typename P, typename V>
+ xtd_op_div_trait(P, V)
+ operator / (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() / rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_div_trait(V, P)
+ operator / (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs / rhs.exact().value();
+ }
+
+ // Op %.
+
+ template <typename P, typename V>
+ xtd_op_mod_trait(P, V)
+ operator % (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() % rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_mod_trait(V, P)
+ operator % (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs % rhs.exact().value();
+ }
+
+
+ // Op ==.
+
+ template <typename P, typename V>
+ xtd_op_eq_trait(P, V)
+ operator == (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() == rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_eq_trait(V, P)
+ operator == (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs == rhs.exact().value();
+ }
+
+
+ // Op !=.
+
+ template <typename P, typename V>
+ xtd_op_neq_trait(P, V)
+ operator != (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() != rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_neq_trait(V, P)
+ operator != (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs != rhs.exact().value();
+ }
+
+
+ // Op <.
+
+ template <typename P, typename V>
+ xtd_op_less_trait(P, V)
+ operator < (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() < rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_less_trait(V, P)
+ operator < (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs < rhs.exact().value();
+ }
+
+ // Op <=.
+
+ template <typename P, typename V>
+ xtd_op_leq_trait(P, V)
+ operator <= (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() <= rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_leq_trait(V, P)
+ operator <= (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs <= rhs.exact().value();
+ }
+
+ // Op >=.
+
+ template <typename P, typename V>
+ xtd_op_geq_trait(P, V)
+ operator >= (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() >= rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_geq_trait(V, P)
+ operator >= (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs >= rhs.exact().value();
+ }
+
+ // Op >.
+
+ template <typename P, typename V>
+ xtd_op_greater_trait(P, V)
+ operator > (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() > rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_greater_trait(V, P)
+ operator > (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs > rhs.exact().value();
+ }
+
+
+ // Op and.
+
+ template <typename P, typename V>
+ xtd_op_land_trait(P, V)
+ operator and (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() and rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_land_trait(V, P)
+ operator and (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs and rhs.exact().value();
+ }
+
+ // Op or.
+
+ template <typename P, typename V>
+ xtd_op_lor_trait(P, V)
+ operator or (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() or rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_lor_trait(V, P)
+ operator or (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs or rhs.exact().value();
+ }
+
+ // Op xor.
+
+ template <typename P, typename V>
+ xtd_op_lxor_trait(P, V)
+ operator xor (const value::abstract::proxy<P>& lhs, const V& rhs)
+ {
+ return lhs.exact().value() xor rhs;
+ }
+
+ template <typename V, typename P>
+ xtd_op_lxor_trait(V, P)
+ operator xor (const V& lhs, const value::abstract::proxy<P>& rhs)
+ {
+ return lhs xor rhs.exact().value();
+ }
+
+ // FIXME: To be continued.
+
+# endif
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_VALUE_PROXY_HH
Index: oln/value/rw_counter.hh
===================================================================
--- oln/value/rw_counter.hh (revision 0)
+++ oln/value/rw_counter.hh (revision 0)
@@ -0,0 +1,241 @@
+// 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_VALUE_RW_COUNTER_HH
+# define OLN_CORE_VALUE_RW_COUNTER_HH
+
+# include <iostream>
+# include <map>
+# include <oln/value/proxy.hh>
+# include <oln/core/abstract/image/all.hh>
+
+
+namespace oln
+{
+
+
+ namespace value
+ {
+
+
+ struct counter
+ {
+ typedef std::map<void*, unsigned> map_t;
+
+ // read-write call
+ static unsigned& n_readwrite_calls(const oln::type& ima)
+ {
+ static map_t n;
+ return n[(void*)(&ima)];
+ }
+ // read-only call
+ static unsigned& n_readonly_calls(const oln::type& ima)
+ {
+ static map_t n;
+ return n[(void*)(&ima)];
+ }
+ // read (effective)
+ static unsigned& n_reads(const oln::type& ima)
+ {
+ static map_t n;
+ return n[(void*)(&ima)];
+ }
+ // write (effective)
+ static unsigned& n_writes(const oln::type& ima)
+ {
+ static map_t n;
+ return n[(void*)(&ima)];
+ }
+
+ static void print(const oln::type& ima)
+ {
+ std::cout << "n_readwrite_calls = " << n_readwrite_calls(ima) << std::endl
+ << "n_readonly_calls = " << n_readonly_calls(ima) << std::endl
+ << "n_reads = " << n_reads(ima) << std::endl
+ << "n_writes = " << n_writes(ima) << std::endl;
+ }
+ };
+
+
+ template <typename I>
+ class rw_counter : public abstract::proxy< rw_counter<I> >
+ {
+ public:
+
+ typedef oln_value(I) value_type;
+
+ // Ctor.
+ rw_counter(oln::abstract::mutable_image<I>& ima,
+ const oln_psite(I)& p);
+
+ // Read.
+ template <typename V>
+ operator V() const;
+
+ // Explicit read.
+ oln_rvalue(I) value() const;
+
+ // Write.
+ template <typename V>
+ rw_counter<I>& operator=(const V& value);
+
+ protected:
+ I& ima_;
+ const oln_psite(I)& p_;
+ };
+
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const rw_counter<I>& proxy);
+
+
+ template <typename I>
+ class ro_counter : public abstract::proxy< ro_counter<I> >
+ {
+ public:
+
+ typedef oln_value(I) value_type;
+
+ // Ctor.
+ ro_counter(const oln::abstract::image<I>& ima,
+ const oln_psite(I)& p);
+
+ // Read.
+ template <typename V>
+ operator V() const;
+
+ // Explicit read.
+ oln_rvalue(I) value() const;
+
+ protected:
+ const I& ima_;
+ const oln_psite(I)& p_;
+ };
+
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const ro_counter<I>& proxy);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // Ctor.
+ template <typename I>
+ rw_counter<I>::rw_counter(oln::abstract::mutable_image<I>& ima,
+ const oln_psite(I)& p)
+ : ima_(ima.exact()),
+ p_(p)
+ {
+ ++counter::n_readwrite_calls(ima_);
+ }
+
+ // Read.
+ template <typename I>
+ template <typename V>
+ rw_counter<I>::operator V() const
+ {
+ ++counter::n_reads(ima_);
+ V tmp = ima_(p_);
+ return tmp;
+ }
+
+ // Explicit read.
+ template <typename I>
+ oln_rvalue(I)
+ rw_counter<I>::value() const
+ {
+ ++counter::n_reads(ima_);
+ return ima_(p_);
+ }
+
+ // Write.
+
+ template <typename I>
+ template <typename V>
+ rw_counter<I>&
+ rw_counter<I>::operator=(const V& value)
+ {
+ ima_(p_) = value;
+ ++counter::n_writes(ima_);
+ return *this;
+ }
+
+ // Op <<.
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr,
+ const rw_counter<I>& proxy)
+ {
+ return ostr << proxy.value();
+ }
+
+
+ // Ctor.
+ template <typename I>
+ ro_counter<I>::ro_counter(const oln::abstract::image<I>& ima,
+ const oln_psite(I)& p)
+ : ima_(ima.exact()),
+ p_(p)
+ {
+ ++counter::n_readonly_calls(ima_);
+ }
+
+ // Read.
+ template <typename I>
+ template <typename V>
+ ro_counter<I>::operator V() const
+ {
+ ++counter::n_reads(ima_);
+ V tmp = ima_(p_);
+ return tmp;
+ }
+
+ // Explicit read.
+ template <typename I>
+ oln_rvalue(I)
+ ro_counter<I>::value() const
+ {
+ ++counter::n_reads(ima_);
+ return ima_(p_);
+ }
+
+ // Op <<.
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr,
+ const ro_counter<I>& proxy)
+ {
+ return ostr << proxy.value();
+ }
+
+# endif
+
+ } // end of namespace oln::value
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_VALUE_RW_COUNTER_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a morpher adding a look-up table to an image.
* oln/core/lookup_table.hh: New.
* oln/morpher/with_lut.hh: New morpher.
* oln/Makefile.am (nobase_oln_HEADERS): Add core/lookup_table.hh
and morpher/with_lut.hh.
* tests/morphers/with_lut.cc: New test.
* tests/morphers/Makefile.am (check_PROGRAMS): Add with_lut.
(with_lut_SOURCES): New.
oln/Makefile.am | 2
oln/core/lookup_table.hh | 125 +++++++++++++++++++++++++++++++
oln/morpher/with_lut.hh | 177 +++++++++++++++++++++++++++++++++++++++++++++
tests/morphers/Makefile.am | 2
tests/morphers/with_lut.cc | 96 ++++++++++++++++++++++++
5 files changed, 402 insertions(+)
Index: tests/morphers/with_lut.cc
--- tests/morphers/with_lut.cc (revision 0)
+++ tests/morphers/with_lut.cc (revision 0)
@@ -0,0 +1,96 @@
+// 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.
+
+/// Test the look-up table morpher.
+
+#include <oln/basics2d.hh>
+#include <oln/morpher/with_lut.hh>
+#include <oln/value/color/rgb.hh>
+#include <oln/level/fill.hh>
+#include <oln/debug/print.hh>
+
+
+// FIXME: Remove.
+using namespace oln;
+
+template <typename I>
+void image_test(const oln::abstract::image<I>&)
+{
+ // Do nothing.
+}
+
+oln::value::color::rgb8 white(255, 255, 255);
+oln::value::color::rgb8 blue ( 0, 0, 255);
+
+int main()
+{
+ using oln::value::color::rgb8;
+
+ unsigned data[] = { 0, 1, 2, 0, 1, 2, 0, 1, 2};
+
+ typedef image2d<unsigned> image_t;
+ image_t ima(3, 3);
+ level::fill(ima, data);
+ debug::print(ima);
+
+ typedef lookup_table<unsigned, rgb8> lut_t;
+ lut_t lut;
+ rgb8 c(16, 6, 4);
+ lut.
+ add(0, blue).
+ add(1, white).
+ add(2, c);
+ std::cout << lut << std::endl;
+
+ typedef morpher::with_lut<image_t, lut_t> lutimage_t;
+ lutimage_t ima2 = ima + lut;
+
+ // ima2 is an image, and can be as argument to to image routines.
+ image_test(ima2);
+
+ // FIXME: To be enabled later.
+#if 0
+ // it is value-wise accessible:
+ ima2.value(c) = red;
+#endif
+
+ // let's look at it
+ debug::print(ima2);
+ std::cout << std::endl;
+
+ // it is a 2D image so we have:
+ point2d p(1, 1);
+ std::cout << "ima2(p) =" << ima2(p) << std::endl;
+ // or (likewise):
+ std::cout << "ima2.at(1, 1) =" << ima2.at(1, 1) << std::endl;
+
+ // FIXME: To be enabled later.
+#if 0
+ // FIXME...
+ level::apply(ima2, fun); // 3 ops only !!!
+#endif
+}
Index: tests/morphers/Makefile.am
--- tests/morphers/Makefile.am (revision 673)
+++ tests/morphers/Makefile.am (working copy)
@@ -24,6 +24,7 @@
slice_morpher \
stack_morpher \
value_cast \
+ with_lut \
\
morphers
@@ -33,6 +34,7 @@
slice_morpher_SOURCES = slice_morpher.cc
stack_morpher_SOURCES = stack_morpher.cc
value_cast_SOURCES = value_cast.cc
+with_lut_SOURCES = with_lut.cc
morphers_SOURCES = morphers.cc
Index: oln/core/lookup_table.hh
--- oln/core/lookup_table.hh (revision 0)
+++ oln/core/lookup_table.hh (revision 0)
@@ -0,0 +1,125 @@
+// 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_LOOKUP_TABLE_HH
+# define OLN_CORE_LOOKUP_TABLE_HH
+
+# include <map>
+# include <ostream>
+
+namespace oln
+{
+
+ template <typename Key, typename Data>
+ class lookup_table
+ {
+ typedef lookup_table<Key, Data> self_t;
+
+ public:
+ typedef Key key_type;
+ typedef Data data_type;
+ typedef std::map<Key, Data> map_type;
+
+ public:
+ lookup_table();
+
+ self_t& add (const key_type& k, const data_type& d);
+
+ const data_type operator () (const key_type& key) const;
+
+ const map_type& map() const;
+
+ private:
+ std::map<Key, Data> map_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Key, typename Data>
+ lookup_table<Key, Data>::lookup_table() :
+ map_()
+ {
+ }
+
+ template <typename Key, typename Data>
+ lookup_table<Key, Data>&
+ lookup_table<Key, Data>::add (const Key& k, const Data& d)
+ {
+ map_.insert(std::make_pair(k, d));
+ return *this;
+ }
+
+ template <typename Key, typename Data>
+ const Data
+ lookup_table<Key, Data>::operator () (const Key& key) const
+ {
+ typedef typename lookup_table<Key, Data>::map_type map_t;
+ typename map_t::const_iterator i = map_.find(key);
+ // FIXME: Is this the expected behavior when the LUT has no data
+ // for \a key.
+ assert(i != map_.end());
+ return i->second;
+ }
+
+ template <typename Key, typename Data>
+ const typename lookup_table<Key, Data>::map_type&
+ lookup_table<Key, Data>::map() const
+ {
+ return map_;
+ }
+
+# endif
+
+
+ /// Print a look-up table.
+ template <typename Key, typename Data>
+ std::ostream&
+ operator<< (std::ostream& ostr, const lookup_table<Key, Data>& lut);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Key, typename Data>
+ std::ostream&
+ operator<< (std::ostream& ostr, const lookup_table<Key, Data>& lut)
+ {
+ typedef lookup_table<Key, Data> lut_t;
+ const typename lut_t::map_type& map = lut.map();
+ for (typename lut_t::map_type::const_iterator i = map.begin ();
+ i != map.end(); ++i)
+ ostr << " " << i->first << " -> " << i->second << std::endl;
+ return ostr;
+ }
+
+# endif
+
+} // end of namespace oln
+
+
+
+#endif // ! OLN_CORE_LOOKUP_TABLE_HH
Index: oln/Makefile.am
--- oln/Makefile.am (revision 673)
+++ oln/Makefile.am (working copy)
@@ -148,6 +148,7 @@
core/fwd_decls.hh \
core/image_entry.hh \
core/iterator_vtypes.hh \
+ core/lookup_table.hh \
core/macros.hh \
core/neighborhood_entry.hh \
core/point_set_entry.hh \
@@ -177,6 +178,7 @@
morpher/thru_fun.hh \
morpher/thru_mfun.hh \
morpher/value_cast.hh \
+ morpher/with_lut.hh \
\
value/color/rgb.hh \
\
Index: oln/morpher/with_lut.hh
--- oln/morpher/with_lut.hh (revision 0)
+++ oln/morpher/with_lut.hh (revision 0)
@@ -0,0 +1,177 @@
+// 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_WITH_LUT_HH
+# define OLN_MORPHER_WITH_LUT_HH
+
+# include <oln/morpher/internal/image_value_morpher.hh>
+# include <oln/core/lookup_table.hh>
+
+
+namespace oln
+{
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <typename Image, typename Lut> struct with_lut;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <typename Image, typename Lut>
+ struct set_super_type< morpher::with_lut<Image, Lut> >
+ {
+ typedef morpher::with_lut<Image, Lut> self_t;
+ typedef morpher::internal::image_value_morpher<Image, self_t> ret;
+ };
+
+ /// Virtual types associated to oln::morpher::with_lut<Image, Lut>.
+ /// \{
+ template <typename Image, typename Lut>
+ struct vtypes< morpher::with_lut<Image, Lut> >
+ {
+ private:
+ typedef oln_type_of(Image, rvalue) orig_value_type;
+ public:
+ typedef mlc::true_ is_computed_type;
+ // Value type.
+ typedef typename Lut::data_type value_type;
+ // Look-up table type.
+ typedef Lut lut_type;
+ };
+
+ // Rvalue.
+ template <typename Image, typename Lut>
+ struct single_vtype< morpher::with_lut<Image, Lut>, typedef_::rvalue_type >
+ {
+ typedef morpher::with_lut<Image, Lut> self_t;
+ typedef oln_value(self_t) ret;
+ };
+
+ // FIXME: What about lvalue type?
+
+// // Lvalue.
+// template <typename Image>
+// struct single_vtype< morpher::slice<Image>, typedef_::lvalue_type >
+// {
+// typedef oln_type_of(Image, lvalue) ret;
+// };
+ /// \}
+
+
+ namespace morpher
+ {
+ /// Look-up table addition morpher.
+ template <typename Image, typename Lut>
+ class with_lut : public stc_get_supers(mlc_comma_1(with_lut<Image, Lut>))
+ // FIXME: Ensure oln_value(Image) == Lut::data_type? Or just let
+ // the ctor check this property?
+ {
+ private:
+ typedef with_lut<Image, Lut> self_t;
+ typedef stc_get_super(self_t) super_t;
+ typedef Lut lut_t;
+ typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, psite) psite_t;
+ // FIXME: Useful typedef?
+// typedef oln_type_of(Image, value) orig_value_t;
+
+ public:
+ with_lut(const Image& image, const Lut& lut);
+ const lut_t& lut() const;
+
+ rvalue_t impl_op_read(const psite_t& p) const;
+
+ // FIXME: Implement impl_op_write() when there is value proxy?
+
+ protected:
+ lut_t lut_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Image, typename Lut>
+ with_lut<Image, Lut>::with_lut(const Image& image, const Lut& lut) :
+ super_t(image),
+ lut_(lut)
+ {
+ mlc::assert_equal_< oln_value(Image), typename Lut::key_type >::check();
+ }
+
+ template <typename Image, typename Lut>
+ typename with_lut<Image, Lut>::rvalue_t
+ with_lut<Image, Lut>::
+ impl_op_read(const typename with_lut<Image, Lut>::psite_t& p) const
+ {
+ // FIXME: What if lut_ has no value for `this->image_(p)'? At
+ // least, document the behavior of this method (will it abort,
+ // does the LUT have to provide a default value, etc.)
+ return lut_(this->image_(p));
+ }
+
+ template <typename Image, typename Lut>
+ const typename with_lut<Image, Lut>::lut_t&
+ with_lut<Image, Lut>::lut() const
+ {
+ return lut_;
+ }
+
+# endif
+
+ } // end of namespace oln::morpher
+
+
+
+ template <typename I, typename K, typename D>
+ morpher::with_lut< I, lookup_table<K, D> >
+ operator + (const abstract::image<I>& image,
+ const lookup_table<K, D>& lut);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I, typename K, typename D>
+ morpher::with_lut< I, lookup_table<K, D> >
+ operator + (const abstract::image<I>& image,
+ const lookup_table<K, D>& lut)
+ {
+ typedef lookup_table<K, D> lut_t;
+ mlc::assert_equal_< oln_value(I), typename lut_t::key_type >::check();
+ morpher::with_lut<I, lut_t> tmp(image.exact(), lut);
+ return tmp;
+ }
+
+# endif
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHER_WITH_LUT_HH
1
0