https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Externalize element and nelement method in fastest images.
* mln/opt/element.hh: New, define opt::element and opt::nelements.
* mln/debug/println_with_border.spe.hh,
* mln/debug/println_with_border.hh,
* mln/data/paste.spe.hh,
* mln/data/fill_with_value.spe.hh,
* mln/data/fill_with_image.spe.hh,
* mln/data/memcpy_.hh,
* mln/data/memset_.hh,
* mln/border/fill.hh,
* mln/border/duplicate.hh,
* mln/border/mirror.hh,
* tests/opt/value.cc,
* tests/border/duplicate_full.cc,
* tests/border/mirror_full.cc,
* tests/border/fill_full.cc,
* tests/border/duplicate.cc,
* tests/border/mirror.cc,
* tests/border/fill.cc: Use now opt::element and opt::nelements.
* mln/opt/value.hh: Update Copyright.
* tests/opt/element.cc: New tests.
mln/border/duplicate.hh | 29 +++---
mln/border/fill.hh | 13 +-
mln/border/mirror.hh | 33 ++++---
mln/data/fill_with_image.spe.hh | 3
mln/data/fill_with_value.spe.hh | 3
mln/data/memcpy_.hh | 26 ++---
mln/data/memset_.hh | 10 +-
mln/data/paste.spe.hh | 3
mln/debug/println_with_border.hh | 3
mln/debug/println_with_border.spe.hh | 3
mln/opt/element.hh | 165 +++++++++++++++++++++++++++++++++++
mln/opt/value.hh | 2
tests/border/duplicate.cc | 51 +++++-----
tests/border/duplicate_full.cc | 5 -
tests/border/fill.cc | 5 -
tests/border/fill_full.cc | 25 ++---
tests/border/mirror.cc | 101 ++++++++++-----------
tests/border/mirror_full.cc | 5 -
tests/opt/element.cc | 47 +++++++++
tests/opt/value.cc | 4
20 files changed, 390 insertions(+), 146 deletions(-)
Index: mln/debug/println_with_border.spe.hh
--- mln/debug/println_with_border.spe.hh (revision 3178)
+++ mln/debug/println_with_border.spe.hh (working copy)
@@ -40,6 +40,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/window.hh>
# include <mln/debug/format.hh>
+# include <mln/opt/element.hh>
namespace mln
{
@@ -61,7 +62,7 @@
println_with_border(const box2d& b, const I& input)
{
const unsigned ncols = b.ncols() + 2 * input.border();
- for (size_t i = 0; i < input.nelements(); i++)
+ for (size_t i = 0; i < opt::nelements(input); i++)
{
std::cout << format(input.buffer()[i]) << ' ';
if (((i + 1) % ncols) == 0)
Index: mln/debug/println_with_border.hh
--- mln/debug/println_with_border.hh (revision 3178)
+++ mln/debug/println_with_border.hh (working copy)
@@ -43,6 +43,7 @@
# include <mln/debug/format.hh>
// Specializations are in:
# include <mln/debug/println_with_border.spe.hh>
+# include <mln/opt/element.hh>
namespace mln
{
@@ -66,7 +67,7 @@
void
println_with_border(const S&, const I& input)
{
- for (size_t i = 0; i < input.nelements(); i++)
+ for (size_t i = 0; i < opt::nelements(input); i++)
std::cout << format(input.buffer()[i]) << ' ';
std::cout << std::endl;
}
Index: mln/opt/element.hh
--- mln/opt/element.hh (revision 0)
+++ mln/opt/element.hh (revision 0)
@@ -0,0 +1,165 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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 MLN_OPT_ELEMENT_HH
+# define MLN_OPT_ELEMENT_HH
+
+/// \file mln/opt/element.hh
+///
+/// Define the opt::element and opt::nelements routines.
+
+# include <mln/core/concept/image.hh>
+# include <mln/trait/images.hh>
+
+namespace mln
+{
+
+ namespace opt
+ {
+
+ template <typename I>
+ inline
+ mln_rvalue(I) element(const Image<I>& ima, unsigned index);
+
+ template <typename I>
+ inline
+ mln_lvalue(I) element(Image<I>& ima, unsigned index);
+
+ template <typename I>
+ inline
+ unsigned nelements(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ inline
+ mln_rvalue(I) element_impl(trait::image::category::domain_morpher,
+ const Image<I>& ima, unsigned index)
+ {
+ return element(*exact(ima).delegatee_());
+ }
+
+ template <typename I>
+ inline
+ mln_rvalue(I) element_impl(trait::image::category::any,
+ const Image<I>& ima, unsigned index)
+ {
+ mlc_and(mlc_is(mln_trait_image_value_storage(I),
+ trait::image::value_storage::one_block),
+ mlc_is(mln_trait_image_value_access(I),
+ trait::image::value_access::direct))::check();
+
+ return exact(ima).element(index);
+ }
+
+
+ template <typename I>
+ inline
+ mln_lvalue(I) element_impl(trait::image::category::domain_morpher,
+ Image<I>& ima, unsigned index)
+ {
+ return element(*exact(ima).delegatee_());
+ }
+
+ template <typename I>
+ inline
+ mln_lvalue(I) element_impl(trait::image::category::any,
+ Image<I>& ima, unsigned index)
+ {
+ mlc_and(mlc_is(mln_trait_image_value_storage(I),
+ trait::image::value_storage::one_block),
+ mlc_is(mln_trait_image_value_access(I),
+ trait::image::value_access::direct))::check();
+
+ return exact(ima).element(index);
+ }
+
+
+
+
+ template <typename I>
+ inline
+ unsigned nelements_impl(trait::image::category::domain_morpher,
+ const Image<I>& ima)
+ {
+ return nelements(*exact(ima).delegatee_());
+ }
+
+ template <typename I>
+ inline
+ unsigned nelements_impl(trait::image::category::any,
+ const Image<I>& ima)
+ {
+ mlc_is(mln_trait_image_value_storage(I),
+ trait::image::value_storage::one_block)::check();
+
+ return exact(ima).nelements();
+ }
+
+
+
+
+
+
+ } // end of namespace mln::opt::impl
+
+
+ template <typename I>
+ inline
+ mln_rvalue(I) element(const Image<I>& ima, unsigned index)
+ {
+ return impl::element_impl(mln_trait_image_category(I)(), ima, index);
+ }
+
+ template <typename I>
+ inline
+ mln_lvalue(I) element(Image<I>& ima, unsigned index)
+ {
+ return impl::element_impl(mln_trait_image_category(I)(), ima, index);
+ }
+
+
+ template <typename I>
+ inline
+ unsigned nelements(const Image<I>& ima)
+ {
+ return impl::nelements_impl(mln_trait_image_category(I)(), ima);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::opt
+
+} // end of namespace mln
+
+
+#endif // ! MLN_OPT_VALUE_HH
Index: mln/opt/value.hh
--- mln/opt/value.hh (revision 3178)
+++ mln/opt/value.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
Index: mln/data/paste.spe.hh
--- mln/data/paste.spe.hh (revision 3178)
+++ mln/data/paste.spe.hh (working copy)
@@ -43,6 +43,7 @@
# include <mln/core/box_runstart_piter.hh>
# include <mln/border/get.hh>
# include <mln/opt/value.hh>
+# include <mln/opt/element.hh>
@@ -111,7 +112,7 @@
*(src.address_()) = input.buffer();
*(dst.address_()) = output.buffer();
- memcpy_(dst, src, input.nelements());
+ memcpy_(dst, src, opt::nelements(input));
trace::exiting("data::impl::paste_fastest");
}
Index: mln/data/fill_with_value.spe.hh
--- mln/data/fill_with_value.spe.hh (revision 3178)
+++ mln/data/fill_with_value.spe.hh (working copy)
@@ -38,6 +38,7 @@
# include <mln/data/memset_.hh>
# include <mln/opt/value.hh>
+# include <mln/opt/element.hh>
# ifndef MLN_INCLUDE_ONLY
@@ -89,7 +90,7 @@
trait::image::value_access::direct))::check();
mln_value(I) v = static_cast<mln_value(I)>(val);
- data::memset_(ima, ima.point_at_index(0), v, ima.nelements());
+ data::memset_(ima, ima.point_at_index(0), v, opt::nelements(ima));
trace::exiting("data::impl::fill_with_value_one_block");
}
Index: mln/data/fill_with_image.spe.hh
--- mln/data/fill_with_image.spe.hh (revision 3178)
+++ mln/data/fill_with_image.spe.hh (working copy)
@@ -44,6 +44,7 @@
# include <mln/core/box_runstart_piter.hh>
# include <mln/border/get.hh>
# include <mln/opt/value.hh>
+# include <mln/opt/element.hh>
# ifndef MLN_INCLUDE_ONLY
@@ -89,7 +90,7 @@
*(src.address_()) = data.buffer();
*(dst.address_()) = ima.buffer();
- memcpy_(dst, src, ima.nelements());
+ memcpy_(dst, src, opt::nelements(ima));
trace::exiting("data::impl::fill_with_image_fastest");
}
Index: mln/data/memcpy_.hh
--- mln/data/memcpy_.hh (revision 3178)
+++ mln/data/memcpy_.hh (working copy)
@@ -39,6 +39,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/pixel.hh>
# include <mln/metal/is_not_const.hh>
+# include <mln/opt/element.hh>
+
namespace mln
@@ -126,18 +128,18 @@
mln_precondition(dest.ima().is_valid());
mln_precondition(src.ima().is_valid());
- mln_precondition(&dest.val() >= &dest.ima().element(0));
- mln_precondition(&dest.val() < &dest.ima().element(0) +
- dest.ima().nelements());
-
- mln_precondition(&dest.val() + n <= &dest.ima().element(0) +
- dest.ima().nelements());
-
- mln_precondition(&src.val() >= &src.ima().element(0));
- mln_precondition(&src.val() < &src.ima().element(0) +
- src.ima().nelements());
- mln_precondition(&src.val() + n <= &src.ima().element(0) +
- src.ima().nelements());
+ mln_precondition(&dest.val() >= &opt::element(dest.ima(), 0));
+ mln_precondition(&dest.val() < &opt::element(dest.ima(), 0) +
+ opt::nelements(dest.ima()));
+
+ mln_precondition(&dest.val() + n <= &opt::element(dest.ima(), 0) +
+ opt::nelements(dest.ima()));
+
+ mln_precondition(&src.val() >= &opt::element(src.ima(), 0));
+ mln_precondition(&src.val() < &opt::element(src.ima(), 0) +
+ opt::nelements(src.ima()));
+ mln_precondition(&src.val() + n <= &opt::element(src.ima(), 0) +
+ opt::nelements(src.ima()));
impl::memcpy__(dest, src, n);
Index: mln/data/memset_.hh
--- mln/data/memset_.hh (revision 3178)
+++ mln/data/memset_.hh (working copy)
@@ -38,6 +38,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/pixel.hh>
# include <mln/metal/is_not_const.hh>
+# include <mln/opt/element.hh>
+
namespace mln
@@ -132,8 +134,10 @@
P& pix = mln::internal::force_exact<P>(pix_);
mln_precondition(pix.ima().is_valid());
mln_precondition(& pix.val() >= & pix.ima()[0]);
- mln_precondition(& pix.val() < & pix.ima()[0] + pix.ima().nelements());
- mln_precondition(& pix.val() + n <= & pix.ima()[0] +
pix.ima().nelements());
+ mln_precondition(& pix.val() < & pix.ima()[0] +
+ opt::nelements(pix.ima()));
+ mln_precondition(& pix.val() + n <= & pix.ima()[0] +
+ opt::nelements(pix.ima()));
impl::memset__(pix, v, n);
@@ -151,7 +155,7 @@
mln_precondition(input.is_valid());
mln_precondition(input.has(p));
- mln_precondition(input.index_of_point(p) + n <= input.nelements());
+ mln_precondition(input.index_of_point(p) + n <= opt::nelements(input));
pixel<I> pix(input, p);
impl::memset__(pix, v, n);
Index: mln/border/fill.hh
--- mln/border/fill.hh (revision 3178)
+++ mln/border/fill.hh (working copy)
@@ -38,6 +38,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/box_runstart_piter.hh>
+# include <mln/opt/element.hh>
namespace mln
@@ -99,14 +100,14 @@
for_all (pl)
{
unsigned end = ima.index_of_point (pl);
- std::memset((void*)&ima.element(st),
+ std::memset((void*)&opt::element(ima, st),
*(const int*)(&v),
end - st);
st = end + len_r;
}
- std::memset((void*)&ima.element(st),
+ std::memset((void*)&opt::element(ima, st),
*(const int*)(&v),
- ima.nelements () - st);
+ opt::nelements(ima) - st);
trace::exiting("border::impl::fill_size_1");
}
@@ -130,11 +131,11 @@
{
unsigned end = ima.index_of_point (pl);
for (unsigned i = st; i < end; ++i)
- ima.element(i) = v;
+ opt::element(ima, i) = v;
st = end + len_r;
}
- for (unsigned i = st; i < ima.nelements (); ++i)
- ima.element(i) = v;
+ for (unsigned i = st; i < opt::nelements(ima); ++i)
+ opt::element(ima, i) = v;
trace::exiting("border::impl::fill_size_n");
}
Index: mln/border/duplicate.hh
--- mln/border/duplicate.hh (revision 3178)
+++ mln/border/duplicate.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/routine/primary.hh>
# include <mln/core/box_runstart_piter.hh>
# include <mln/border/get.hh>
+# include <mln/opt/element.hh>
namespace mln
@@ -75,11 +76,11 @@
unsigned border = ima.border();
for (unsigned i = 0; i < border; ++i)
- ima.element(i) = ima.element(border);
+ opt::element(ima, i) = opt::element(ima, border);
unsigned st = border + len_c - 1;
- for (unsigned i = st + 1; i < ima.nelements(); ++i)
- ima.element(i) = ima.element(st);
+ for (unsigned i = st + 1; i < opt::nelements(ima); ++i)
+ opt::element(ima, i) = opt::element(ima, st);
trace::exiting("border::impl::duplicate_1D");
}
@@ -104,23 +105,23 @@
{
st = ima.index_of_point (pl);
for (unsigned i = 1; i <= border; ++i)
- ima.element(st - i) = ima.element(st);
+ opt::element(ima, st - i) = opt::element(ima, st);
st = st + len_c - 1;
for (unsigned i = 1; i <= border; ++i)
- ima.element(st + i) = ima.element(st);
+ opt::element(ima, st + i) = opt::element(ima, st);
}
// Duplicate n first * border line
st = real_len_c * border;
for (unsigned k = 0; k < border; ++k)
for (unsigned i = 0; i < real_len_c; ++i)
- ima.element(k * real_len_c + i) = ima.element(st + i);
+ opt::element(ima, k * real_len_c + i) = opt::element(ima, st + i);
// Duplicate n last * border line
st = real_len_c * (border + len_r - 1);
for (unsigned k = 1; k <= border; ++k)
for (unsigned i = st; i < st + real_len_c; ++i)
- ima.element(k * real_len_c + i) = ima.element(i);
+ opt::element(ima, k * real_len_c + i) = opt::element(ima, i);
trace::exiting("border::impl::duplicate_2D");
}
@@ -155,10 +156,10 @@
{
st = ima.index_of_point (pl);
for (unsigned i = 1; i <= border; ++i)
- ima.element(st - i) = ima.element(st);
+ opt::element(ima, st - i) = opt::element(ima, st);
st = st + len_c - 1;
for (unsigned i = 1; i <= border; ++i)
- ima.element(st + i) = ima.element(st);
+ opt::element(ima, st + i) = opt::element(ima, st);
pl.next();
}
@@ -166,26 +167,28 @@
st = border * face + k * face + border * real_len_c ;
for (unsigned j = 1; j <= border; ++j)
for (unsigned i = 0; i < real_len_c; ++i)
- ima.element(st - j * real_len_c + i) = ima.element(st + i);
+ opt::element(ima, st - j * real_len_c + i) =
+ opt::element(ima, st + i);
// Duplicate n last * border line
st = border * face + k * face + (len_r + border - 1) * real_len_c ;
for (unsigned j = 1; j <= border; ++j)
for (unsigned i = 0; i < real_len_c; ++i)
- ima.element(st + j * real_len_c + i) = ima.element(st + i);
+ opt::element(ima, st + j * real_len_c + i) =
+ opt::element(ima, st + i);
}
// Duplicate n first * border face
st = border * face;
for (unsigned k = 0; k < border; ++k)
for (unsigned i = 0; i < face; ++i)
- ima.element(k * face + i) = ima.element(st + i);
+ opt::element(ima, k * face + i) = opt::element(ima, st + i);
// Duplicate n last * border face
st = (len_s + border - 1) * face;
for (unsigned k = 1; k <= border; ++k)
for (unsigned i = 0; i < face; ++i)
- ima.element(st + k * face + i) = ima.element(st + i);
+ opt::element(ima, st + k * face + i) = opt::element(ima, st + i);
trace::exiting("border::impl::duplicate_3D");
}
Index: mln/border/mirror.hh
--- mln/border/mirror.hh (revision 3178)
+++ mln/border/mirror.hh (working copy)
@@ -49,6 +49,8 @@
# include <mln/geom/max_col.hh>
# include <mln/geom/ninds.hh>
+# include <mln/opt/element.hh>
+
namespace mln
{
@@ -95,10 +97,10 @@
{
def::coord i = 0;
for (; i < min; ++i)
- ima.element(border - 1 - i) = ima(point1d(i));
+ opt::element(ima, border - 1 - i) = ima(point1d(i));
for (; i < border; ++i)
- ima.element(border - 1 - i) = ima(point1d(static_cast<def::coord>(min - 1)));
+ opt::element(ima, border - 1 - i) =
ima(point1d(static_cast<def::coord>(min - 1)));
}
/// right border
@@ -109,12 +111,12 @@
for (;
i < min;
++i, --j)
- ima.element(border + nbinds + i) = ima(point1d(j));
+ opt::element(ima, border + nbinds + i) = ima(point1d(j));
++j;
for (;
i < border;
++i)
- ima.element(border + nbinds + i) = ima(point1d(j));
+ opt::element(ima, border + nbinds + i) = ima(point1d(j));
}
trace::exiting("border::impl::mirror_");
}
@@ -136,49 +138,56 @@
// mirror top left corner
for (unsigned i = 0; i < border; ++i)
for (unsigned j = 0; j < border; ++j)
- ima.element(i * ((nbcols + 1) + 2 * border) + j) = ima.element(s);
+ opt::element(ima, i * ((nbcols + 1) + 2 * border) + j) =
+ opt::element(ima, s);
// mirror top left corner
s = start + nbcols;
for (unsigned i = 0; i < border; ++i)
for (unsigned j = 1; j <= border; ++j)
- ima.element(i * ((nbcols + 1) + 2 * border) + (nbcols + border + j)) =
ima.element(s);
+ opt::element(ima, i * ((nbcols + 1) + 2 * border) + (nbcols + border + j)) =
opt::element(ima, s);
// mirror bottom left corner
s = start + (nbrows * real_nbcols);
for (unsigned i = 1; i <= border; ++i)
for (unsigned j = 1; j <= border; ++j)
- ima.element(s - i + (j * (real_nbcols))) = ima.element(s);
+ opt::element(ima, s - i + (j * (real_nbcols))) =
+ opt::element(ima, s);
// mirror bottom right corner
s = start + (nbrows * real_nbcols) + nbcols;
for (unsigned i = 1; i <= border; ++i)
for (unsigned j = 1; j <= border; ++j)
- ima.element(s + i + (j * real_nbcols)) = ima.element(s);
+ opt::element(ima, s + i + (j * real_nbcols)) =
+ opt::element(ima, s);
// mirror top border
s = start;
for (unsigned i = 0; i <= nbcols; ++i)
for (unsigned j = 1; j <= border; ++j)
- ima.element(s + i - (j * real_nbcols)) = ima.element(s + i + ((j - 1)*
real_nbcols));
+ opt::element(ima, s + i - (j * real_nbcols)) =
+ opt::element(ima, s + i + ((j - 1)* real_nbcols));
// mirror left border
s = start;
for (unsigned i = 0; i <= nbrows; ++i)
for (unsigned j = 1; j <= border; ++j)
- ima.element(s + (i * real_nbcols) - j) = ima.element(s + (i * real_nbcols) + (j -
1));
+ opt::element(ima, s + (i * real_nbcols) - j) =
+ opt::element(ima, s + (i * real_nbcols) + (j - 1));
// mirror right border
s = start;
for (unsigned i = 0; i <= nbrows; ++i)
for (unsigned j = 1; j <= border; ++j)
- ima.element(s + (i * real_nbcols + nbcols) + j) = ima.element(s + (i * real_nbcols +
nbcols) - (j - 1));
+ opt::element(ima, s + (i * real_nbcols + nbcols) + j) =
+ opt::element(ima, s + (i * real_nbcols + nbcols) - (j - 1));
// mirror bottom border
s = start + (nbrows * real_nbcols);
for (unsigned i = 0; i <= nbcols; ++i)
for (unsigned j = 1; j <= border; ++j)
- ima.element(s + i + (j * real_nbcols)) = ima.element(s + i - ((j - 1)*
real_nbcols));
+ opt::element(ima, s + i + (j * real_nbcols)) =
+ opt::element(ima, s + i - ((j - 1)* real_nbcols));
trace::exiting("border::impl::mirror_");
}
Index: tests/opt/value.cc
--- tests/opt/value.cc (revision 3178)
+++ tests/opt/value.cc (working copy)
@@ -26,9 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/opt/at.cc
+/// \file tests/opt/value.cc
///
-/// Tests on mln::opt::at.
+/// Tests on mln::opt::value.
#include <mln/opt/value.hh>
#include <mln/core/image/flat_image.hh>
Index: tests/opt/element.cc
--- tests/opt/element.cc (revision 0)
+++ tests/opt/element.cc (revision 0)
@@ -0,0 +1,47 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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.
+
+/// \file tests/opt/value.cc
+///
+/// Tests on mln::opt::at.
+
+#include <mln/opt/element.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/trace/all.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d<short> ima(12, 12);
+
+ opt::element(ima, 2) = 51;
+ mln_precondition(opt::element(ima, 2) == 51);
+ mln_precondition(opt::nelements(ima) == 324);
+}
Index: tests/border/duplicate_full.cc
--- tests/border/duplicate_full.cc (revision 3178)
+++ tests/border/duplicate_full.cc (working copy)
@@ -36,6 +36,7 @@
#include <mln/border/duplicate.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_s8.hh>
+#include <mln/opt/element.hh>
namespace mln
{
@@ -50,7 +51,7 @@
border::duplicate(ima);
for (int i = 0; i < c; ++i)
- mln_assertion(ima.element(i) == ref[i]);
+ mln_assertion(opt::element(ima, i) == ref[i]);
}
template <typename T>
@@ -64,7 +65,7 @@
border::duplicate(ima);
for (int i = 0; i < c * r; ++i)
- mln_assertion(ima.element(i) == ref[i]);
+ mln_assertion(opt::element(ima, i) == ref[i]);
}
}
Index: tests/border/mirror_full.cc
--- tests/border/mirror_full.cc (revision 3178)
+++ tests/border/mirror_full.cc (working copy)
@@ -36,6 +36,7 @@
#include <mln/border/mirror.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_s8.hh>
+#include <mln/opt/element.hh>
namespace mln
@@ -51,7 +52,7 @@
border::mirror(ima);
for (int i = 0; i < c; ++i)
- mln_assertion(ima.element(i) == ref[i]);
+ mln_assertion(opt::element(ima, i) == ref[i]);
}
template <typename T>
@@ -65,7 +66,7 @@
border::mirror(ima);
for (int i = 0; i < c * r; ++i)
- mln_assertion(ima.element(i) == ref[i]);
+ mln_assertion(opt::element(ima, i) == ref[i]);
}
}
Index: tests/border/fill_full.cc
--- tests/border/fill_full.cc (revision 3178)
+++ tests/border/fill_full.cc (working copy)
@@ -32,8 +32,10 @@
///
/// \todo Rewrite this non-sense test file!!!
+
#include <mln/border/fill.hh>
#include <mln/data/fill.hh>
+#include <mln/opt/element.hh>
#include <mln/core/image/image1d.hh>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/image3d.hh>
@@ -47,6 +49,7 @@
#include <mln/value/float01_16.hh>
#include <mln/debug/println_with_border.hh>
+
using namespace mln;
@@ -60,13 +63,13 @@
unsigned i = 0;
for(i = 0; i < border; ++i)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
unsigned bo = border + row;
for(; i < bo; ++i)
- mln_assertion (ima.element(i) == v);
+ mln_assertion (opt::element(ima, i) == v);
bo += border;
for(; i < bo; ++i)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
}
template <typename T>
@@ -85,18 +88,18 @@
unsigned ww = r * c;
for(i = 0; i < bo; ++i)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
bo += c * row;
for(; i < bo; ++i)
{
unsigned cur = i % c;
if (cur < border || cur >= u)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
else
- mln_assertion (ima.element(i) == v);
+ mln_assertion (opt::element(ima, i) == v);
}
for(; i < ww; ++i)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
}
template <typename T>
@@ -115,18 +118,18 @@
unsigned ww = r * c;
for(i = 0; i < bo; ++i)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
bo += c * row;
for(; i < bo; ++i)
{
unsigned cur = i % c;
if (cur < border || cur >= u)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
else
- mln_assertion (ima.element(i) == v);
+ mln_assertion (opt::element(ima, i) == v);
}
for(; i < ww; ++i)
- mln_assertion (ima.element(i) == value);
+ mln_assertion (opt::element(ima, i) == value);
}
Index: tests/border/duplicate.cc
--- tests/border/duplicate.cc (revision 3178)
+++ tests/border/duplicate.cc (working copy)
@@ -34,6 +34,7 @@
#include <mln/core/image/image2d.hh>
#include <mln/debug/iota.hh>
#include <mln/border/duplicate.hh>
+#include <mln/opt/element.hh>
using namespace mln;
@@ -46,30 +47,30 @@
debug::iota(ima);
border::duplicate(ima);
- mln_assertion(ima.element( 0) == 1);
- mln_assertion(ima.element( 1) == 1);
- mln_assertion(ima.element( 2) == 2);
- mln_assertion(ima.element( 3) == 3);
- mln_assertion(ima.element( 4) == 3);
- mln_assertion(ima.element( 5) == 1);
- mln_assertion(ima.element( 6) == 1);
- mln_assertion(ima.element( 7) == 2);
- mln_assertion(ima.element( 8) == 3);
- mln_assertion(ima.element( 9) == 3);
- mln_assertion(ima.element(10) == 4);
- mln_assertion(ima.element(11) == 4);
- mln_assertion(ima.element(12) == 5);
- mln_assertion(ima.element(13) == 6);
- mln_assertion(ima.element(14) == 6);
- mln_assertion(ima.element(15) == 7);
- mln_assertion(ima.element(16) == 7);
- mln_assertion(ima.element(17) == 8);
- mln_assertion(ima.element(18) == 9);
- mln_assertion(ima.element(19) == 9);
- mln_assertion(ima.element(20) == 7);
- mln_assertion(ima.element(21) == 7);
- mln_assertion(ima.element(22) == 8);
- mln_assertion(ima.element(23) == 9);
- mln_assertion(ima.element(24) == 9);
+ mln_assertion(opt::element(ima, 0) == 1);
+ mln_assertion(opt::element(ima, 1) == 1);
+ mln_assertion(opt::element(ima, 2) == 2);
+ mln_assertion(opt::element(ima, 3) == 3);
+ mln_assertion(opt::element(ima, 4) == 3);
+ mln_assertion(opt::element(ima, 5) == 1);
+ mln_assertion(opt::element(ima, 6) == 1);
+ mln_assertion(opt::element(ima, 7) == 2);
+ mln_assertion(opt::element(ima, 8) == 3);
+ mln_assertion(opt::element(ima, 9) == 3);
+ mln_assertion(opt::element(ima, 10) == 4);
+ mln_assertion(opt::element(ima, 11) == 4);
+ mln_assertion(opt::element(ima, 12) == 5);
+ mln_assertion(opt::element(ima, 13) == 6);
+ mln_assertion(opt::element(ima, 14) == 6);
+ mln_assertion(opt::element(ima, 15) == 7);
+ mln_assertion(opt::element(ima, 16) == 7);
+ mln_assertion(opt::element(ima, 17) == 8);
+ mln_assertion(opt::element(ima, 18) == 9);
+ mln_assertion(opt::element(ima, 19) == 9);
+ mln_assertion(opt::element(ima, 20) == 7);
+ mln_assertion(opt::element(ima, 21) == 7);
+ mln_assertion(opt::element(ima, 22) == 8);
+ mln_assertion(opt::element(ima, 23) == 9);
+ mln_assertion(opt::element(ima, 24) == 9);
}
Index: tests/border/mirror.cc
--- tests/border/mirror.cc (revision 3178)
+++ tests/border/mirror.cc (working copy)
@@ -34,6 +34,7 @@
#include <mln/core/image/image2d.hh>
#include <mln/debug/iota.hh>
#include <mln/border/mirror.hh>
+#include <mln/opt/element.hh>
#include <mln/debug/println_with_border.hh>
@@ -46,14 +47,14 @@
image1d<int> ima(2, 3);
debug::iota(ima);
border::mirror(ima);
- mln_assertion(ima.element(0) == 2);
- mln_assertion(ima.element(1) == 2);
- mln_assertion(ima.element(2) == 1);
- mln_assertion(ima.element(3) == 1);
- mln_assertion(ima.element(4) == 2);
- mln_assertion(ima.element(5) == 2);
- mln_assertion(ima.element(6) == 1);
- mln_assertion(ima.element(7) == 1);
+ mln_assertion(opt::element(ima, 0) == 2);
+ mln_assertion(opt::element(ima, 1) == 2);
+ mln_assertion(opt::element(ima, 2) == 1);
+ mln_assertion(opt::element(ima, 3) == 1);
+ mln_assertion(opt::element(ima, 4) == 2);
+ mln_assertion(opt::element(ima, 5) == 2);
+ mln_assertion(opt::element(ima, 6) == 1);
+ mln_assertion(opt::element(ima, 7) == 1);
}
@@ -62,47 +63,47 @@
debug::iota(ima);
border::mirror(ima);
- mln_assertion(ima.element( 0) == 1);
- mln_assertion(ima.element( 1) == 1);
- mln_assertion(ima.element( 2) == 4);
- mln_assertion(ima.element( 3) == 5);
- mln_assertion(ima.element( 4) == 6);
- mln_assertion(ima.element( 5) == 3);
- mln_assertion(ima.element( 6) == 3);
- mln_assertion(ima.element( 7) == 1);
- mln_assertion(ima.element( 8) == 1);
- mln_assertion(ima.element( 9) == 1);
- mln_assertion(ima.element(10) == 2);
- mln_assertion(ima.element(11) == 3);
- mln_assertion(ima.element(12) == 3);
- mln_assertion(ima.element(13) == 3);
- mln_assertion(ima.element(14) == 2);
- mln_assertion(ima.element(15) == 1);
- mln_assertion(ima.element(16) == 1);
- mln_assertion(ima.element(17) == 2);
- mln_assertion(ima.element(18) == 3);
- mln_assertion(ima.element(19) == 3);
- mln_assertion(ima.element(20) == 2);
- mln_assertion(ima.element(21) == 5);
- mln_assertion(ima.element(22) == 4);
- mln_assertion(ima.element(23) == 4);
- mln_assertion(ima.element(24) == 5);
- mln_assertion(ima.element(25) == 6);
- mln_assertion(ima.element(26) == 6);
- mln_assertion(ima.element(27) == 5);
- mln_assertion(ima.element(28) == 4);
- mln_assertion(ima.element(29) == 4);
- mln_assertion(ima.element(30) == 4);
- mln_assertion(ima.element(31) == 5);
- mln_assertion(ima.element(32) == 6);
- mln_assertion(ima.element(33) == 6);
- mln_assertion(ima.element(34) == 6);
- mln_assertion(ima.element(35) == 4);
- mln_assertion(ima.element(36) == 4);
- mln_assertion(ima.element(37) == 1);
- mln_assertion(ima.element(38) == 2);
- mln_assertion(ima.element(39) == 3);
- mln_assertion(ima.element(40) == 6);
- mln_assertion(ima.element(41) == 6);
+ mln_assertion(opt::element(ima, 0) == 1);
+ mln_assertion(opt::element(ima, 1) == 1);
+ mln_assertion(opt::element(ima, 2) == 4);
+ mln_assertion(opt::element(ima, 3) == 5);
+ mln_assertion(opt::element(ima, 4) == 6);
+ mln_assertion(opt::element(ima, 5) == 3);
+ mln_assertion(opt::element(ima, 6) == 3);
+ mln_assertion(opt::element(ima, 7) == 1);
+ mln_assertion(opt::element(ima, 8) == 1);
+ mln_assertion(opt::element(ima, 9) == 1);
+ mln_assertion(opt::element(ima, 10) == 2);
+ mln_assertion(opt::element(ima, 11) == 3);
+ mln_assertion(opt::element(ima, 12) == 3);
+ mln_assertion(opt::element(ima, 13) == 3);
+ mln_assertion(opt::element(ima, 14) == 2);
+ mln_assertion(opt::element(ima, 15) == 1);
+ mln_assertion(opt::element(ima, 16) == 1);
+ mln_assertion(opt::element(ima, 17) == 2);
+ mln_assertion(opt::element(ima, 18) == 3);
+ mln_assertion(opt::element(ima, 19) == 3);
+ mln_assertion(opt::element(ima, 20) == 2);
+ mln_assertion(opt::element(ima, 21) == 5);
+ mln_assertion(opt::element(ima, 22) == 4);
+ mln_assertion(opt::element(ima, 23) == 4);
+ mln_assertion(opt::element(ima, 24) == 5);
+ mln_assertion(opt::element(ima, 25) == 6);
+ mln_assertion(opt::element(ima, 26) == 6);
+ mln_assertion(opt::element(ima, 27) == 5);
+ mln_assertion(opt::element(ima, 28) == 4);
+ mln_assertion(opt::element(ima, 29) == 4);
+ mln_assertion(opt::element(ima, 30) == 4);
+ mln_assertion(opt::element(ima, 31) == 5);
+ mln_assertion(opt::element(ima, 32) == 6);
+ mln_assertion(opt::element(ima, 33) == 6);
+ mln_assertion(opt::element(ima, 34) == 6);
+ mln_assertion(opt::element(ima, 35) == 4);
+ mln_assertion(opt::element(ima, 36) == 4);
+ mln_assertion(opt::element(ima, 37) == 1);
+ mln_assertion(opt::element(ima, 38) == 2);
+ mln_assertion(opt::element(ima, 39) == 3);
+ mln_assertion(opt::element(ima, 40) == 6);
+ mln_assertion(opt::element(ima, 41) == 6);
}
Index: tests/border/fill.cc
--- tests/border/fill.cc (revision 3178)
+++ tests/border/fill.cc (working copy)
@@ -34,6 +34,7 @@
#include <mln/core/image/image2d.hh>
#include <mln/value/int_u8.hh>
#include <mln/debug/println_with_border.hh>
+#include <mln/opt/element.hh>
using namespace mln;
@@ -48,11 +49,11 @@
border::fill (ima, 42);
for(int i = 0; i < ww; ++i)
if ((i / w < border) || (i / w > border + size))
- mln_assertion (ima.element(i) == 42u);
+ mln_assertion (opt::element(ima, i) == 42u);
else
if ((i % w < border) &&
(border + size <= i % w))
- mln_assertion (ima.element(i) == 42u);
+ mln_assertion (opt::element(ima, i) == 42u);
}
int