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 \
Show replies by date