milena r1596: Add new full tests for level subdirectory

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-12-06 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Add new full tests for level subdirectory. * tests/level/apply_full.cc, * tests/level/paste_full.cc, * tests/level/saturate_full.cc, * tests/level/sort_points_full.cc, * tests/level/stretch_full.cc, * tests/level/transform_full.cc: New full tests for level. * mln/fun/v2v/saturate.hh: Fix bug but need to review. * mln/level/paste.spe.hh: Add comment. --- mln/fun/v2v/saturate.hh | 14 + mln/level/paste.spe.hh | 1 tests/level/apply_full.cc | 172 +++++++++++++++++++++ tests/level/paste_full.cc | 280 +++++++++++++++++++++++++++++++++++ tests/level/saturate_full.cc | 241 ++++++++++++++++++++++++++++++ tests/level/sort_points_full.cc | 318 ++++++++++++++++++++++++++++++++++++++++ tests/level/stretch_full.cc | 174 +++++++++++++++++++++ tests/level/transform_full.cc | 165 ++++++++++++++++++++ 8 files changed, 1363 insertions(+), 2 deletions(-) Index: trunk/milena/tests/level/transform_full.cc =================================================================== --- trunk/milena/tests/level/transform_full.cc (revision 0) +++ trunk/milena/tests/level/transform_full.cc (revision 1596) @@ -0,0 +1,165 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/level/transform_full.cc + * + * \brief Tests on mln::level::transform + */ + +#include <cmath> + +#include <mln/core/image1d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/image3d.hh> +#include <mln/core/sub_image.hh> + +#include <mln/core/image_if.hh> +#include <mln/fun/p2b/chess.hh> + +#include <mln/literal/origin.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> + +#include <mln/value/int_s8.hh> +#include <mln/value/int_s16.hh> + +#include <mln/level/fill.hh> +#include <mln/level/transform.hh> + +#include <mln/debug/iota.hh> + +#include <mln/arith/plus.hh> + + + + +struct mysqrt : mln::Function_v2v<mysqrt> +{ + typedef unsigned short result; + result operator()(int c) const + { + return result(c % 42); + } +}; + + +namespace mln +{ + template <typename I> + void + chck(const Image<I>& ref_) + { + const I& ref = exact(ref_); + + I out (ref.domain()); + { + level::transform(ref, mysqrt(), out); + mln_piter(I) p (ref.domain ()); + for_all(p) + mln_assertion ((mln_value(I))(ref(p) % 42) == out(p) ); + } + } + + template <typename V> + void + chk() + { + unsigned sli = 4; + unsigned row = 16; + unsigned col = 64; + + + (std::cerr << "in 1d ... ").flush (); + { + typedef image1d<V> I; + typedef sub_image<I, box1d> J; + + for (unsigned i = 1; i < col; ++i) + { + I ima(i); + debug::iota(ima); + chck (ima); + } + } + std::cerr << "OK" << std::endl; + + (std::cerr << "in 2d ... ").flush (); + { + typedef image2d<V> I; + + for (unsigned i = 1; i < col; ++i) + for (unsigned j = 1; j < row; ++j) + { + I ima(j, i); + debug::iota(ima); + chck (ima); + } + } + std::cerr << "OK" << std::endl; + + (std::cerr << "in 3d ... ").flush (); + { + typedef image3d<V> I; + + for (unsigned i = 1; i < col; ++i) + for (unsigned j = 1; j < row; ++j) + for (unsigned k = 1; k < sli; ++k) + { + I ima(k, j, i); + debug::iota(ima); + chck (ima); + } + } + std::cerr << "OK" << std::endl; + } + +} + + + + + +int main() +{ + using namespace mln; + + std::cerr << "Tests level::transform:" << std::endl; + std::cerr << "on int:" << std::endl; + chk<int>(); + std::cerr << "on unsigned:" << std::endl; + chk<unsigned>(); + std::cerr << "on int_u8:" << std::endl; + chk<value::int_u8>(); + std::cerr << "on int_u16:" << std::endl; + chk<value::int_u16>(); + std::cerr << "on int_s8:" << std::endl; + chk<value::int_s8>(); + std::cerr << "on int_s16:" << std::endl; + chk<value::int_s16>(); +} + Index: trunk/milena/tests/level/apply_full.cc =================================================================== --- trunk/milena/tests/level/apply_full.cc (revision 0) +++ trunk/milena/tests/level/apply_full.cc (revision 1596) @@ -0,0 +1,172 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/level/apply_full.cc + * + * \brief Tests on mln::level::apply. + */ + +#include <mln/core/image1d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/image3d.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> +#include <mln/value/int_s8.hh> +#include <mln/value/int_s16.hh> + + +#include <mln/core/clone.hh> +#include <mln/level/apply.hh> +#include <mln/debug/iota.hh> + +#include <mln/debug/println.hh> + +struct qrde : mln::Function_v2v<qrde> +{ + typedef unsigned short result; + result operator()(int c) const + { + return result(c % 42); + } +}; + + +namespace mln +{ + template <typename I> + void + chck(I& ref) + { + I out = clone (ref); + + mln_piter(I) p (ref.domain ()); + + { + level::apply(out, qrde()); + + for_all(p) + mln_assertion((mln_value(I))(ref(p) % 42) == out(p)); + } + + } + + template <typename I> + void + chk1d(unsigned cols) + { + image1d<I> ima (cols); + debug::iota (ima); + chck(ima); + } + + template <typename I> + void + chk2d(unsigned rows, + unsigned cols) + { + image2d<I> ima (rows, cols); + debug::iota (ima); + chck(ima); + } + + template <typename I> + void + chk3d(unsigned slis, + unsigned rows, + unsigned cols) + { + image3d<I> ima (slis, rows, cols); + debug::iota (ima); + chck(ima); + } + +} + + +int main() +{ + using namespace mln; + + unsigned slis_start = 1; + unsigned slis_end = 3; + + unsigned rows_start = 1; + unsigned rows_end = 8; + + unsigned cols_start = 2; + unsigned cols_end = 256; + + + std::cerr << "Tests level::apply" << std::endl; + + (std::cerr << "in 1d ... ").flush (); + { + for (unsigned i = cols_start; i < cols_end; ++i) + { + chk1d<int>(i); + chk1d<unsigned>(i); + chk1d<value::int_u8>(i); + chk1d<value::int_u16>(i); + chk1d<value::int_s8>(i); + chk1d<value::int_s16>(i); + } + } + std::cerr << "OK" << std::endl; + + (std::cerr << "in 2d ... ").flush (); + { + for (unsigned h = rows_start; h < rows_end; ++h) + for (unsigned i = cols_start; i < cols_end; ++i) + { + chk2d<int>(h, i); + chk2d<unsigned>(h, i); + chk2d<value::int_u8>(h, i); + chk2d<value::int_u16>(h, i); + chk2d<value::int_s8>(h, i); + chk2d<value::int_s16>(h, i); + } + } + std::cerr << "OK" << std::endl; + + + (std::cerr << "in 3d ... ").flush (); + { + for (unsigned g = slis_start; g < slis_end; ++g) + for (unsigned h = rows_start; h < rows_end; ++h) + for (unsigned i = cols_start; i < cols_end; ++i) + { + chk3d<int>(g, h, i); + chk3d<unsigned>(g, h, i); + chk3d<value::int_u8>(g, h, i); + chk3d<value::int_u16>(g, h, i); + chk3d<value::int_s8>(g, h, i); + chk3d<value::int_s16>(g, h, i); + } + } + std::cerr << "OK" << std::endl; +} Index: trunk/milena/tests/level/paste_full.cc =================================================================== --- trunk/milena/tests/level/paste_full.cc (revision 0) +++ trunk/milena/tests/level/paste_full.cc (revision 1596) @@ -0,0 +1,280 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/level/paste_full.cc + * + * \brief Tests on mln::level::paste. + */ + + + +#include <mln/core/image1d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/image3d.hh> +#include <mln/core/sub_image.hh> + +#include <mln/core/image_if.hh> +#include <mln/fun/p2b/chess.hh> + +#include <mln/literal/origin.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> + +#include <mln/value/int_s8.hh> +#include <mln/value/int_s16.hh> + + +#include <mln/debug/iota.hh> + +#include <mln/level/saturate.hh> +#include <mln/level/paste.hh> + + + +struct f_box1d_t : mln::Function_p2b< f_box1d_t > +{ + f_box1d_t(const mln::box1d& b) + : b_(b) + { + } + mln::box1d b_; + bool operator()(const mln::point1d& p) const + { + return b_.has(p); + } +}; + +struct f_box2d_t : mln::Function_p2b< f_box2d_t > +{ + f_box2d_t(const mln::box2d& b) + : b_(b) + { + } + mln::box2d b_; + bool operator()(const mln::point2d& p) const + { + return b_.has(p); + } +}; + +struct f_box3d_t : mln::Function_p2b< f_box3d_t > +{ + f_box3d_t(const mln::box3d& b) + : b_(b) + { + } + mln::box3d b_; + bool operator()(const mln::point3d& p) const + { + return b_.has(p); + } +}; + + + +namespace mln +{ + template <typename I, typename J> + void + chck(Image<I>& input_, Image<J>& output_) + { + typedef mln_value(I) T; + typedef mln_value(J) V; + unsigned max_i = mln_max (T); + unsigned max_j = mln_max (V); + I& input = exact(input_); + J& output = exact(output_); + + if (max_i > max_j) + level::saturate_inplace(input, 0, (T)max_j); + + level::paste(input, output); + + mln_piter(I) p (input.domain ()); + for_all(p) + mln_assertion ((V)(input(p)) == output(p)); + } + + template <typename I, typename J> + void + chk1d(unsigned cols) + { + box1d b1(literal::origin, point1d(1)); + f_box1d_t f_b1(b1); + + { + image1d<I> input (cols); + debug::iota(input); + image1d<J> output (cols); + chck(input, output); + } + + { + image1d<I> in (cols); + sub_image<image1d<I>, box1d> input (in, b1); + debug::iota(input); + image1d<J> output (cols); + chck(input, output); + } + +// { +// image1d<I> in (cols); +// image_if<image1d<I>, f_box1d_t> input(in, f_b1); +// debug::iota(input); +// image1d<J> output (cols); +// chck(input, output); +// } + } + + template <typename I, typename J> + void + chk2d(unsigned rows, unsigned cols) + { + box2d b2(literal::origin, point2d(1, 1)); + f_box2d_t f_b2(b2); + + { + image2d<I> input (rows, cols); + debug::iota(input); + image2d<J> output (rows, cols); + chck(input, output); + } + + { + image2d<I> in (rows, cols); + sub_image<image2d<I>, box2d> input (in, b2); + debug::iota(input); + image2d<J> output (rows, cols); + chck(input, output); + } + +// { +// image2d<I> in (rows, cols); +// image_if<image2d<I>, f_box2d_t> input(in, f_b2); +// debug::iota(input); +// image2d<J> output (rows, cols); +// chck(input, output); +// } + } + + template <typename I, typename J> + void + chk3d(unsigned slis, unsigned rows, unsigned cols) + { + box3d b3(literal::origin, point3d(1, 1, 1)); + f_box3d_t f_b3(b3); + + { + image3d<I> input (slis, rows, cols); + debug::iota(input); + image3d<J> output (slis, rows, cols); + chck(input, output); + } + + { + image3d<I> in (slis, rows, cols); + sub_image<image3d<I>, box3d> input (in, b3); + debug::iota(input); + image3d<J> output (slis, rows, cols); + chck(input, output); + } + +// { +// image3d<I> in (slis, rows, cols); +// image_if<image3d<I>, f_box3d_t> input(in, f_b3); +// debug::iota(input); +// image3d<J> output (slis, rows, cols); +// chck(input, output); +// } + } + + + template <typename I, typename J> + void + chk(unsigned slis, unsigned rows, unsigned cols) + { + (std::cerr << " in 1d ... ").flush (); + { + for (unsigned i = 2; i < cols; ++i) + chk1d<I, J>(i); + } + std::cerr << "OK" << std::endl; + + (std::cerr << " in 2d ... ").flush (); + { + for (unsigned j = 2; j < rows; ++j) + for (unsigned i = 2; i < cols; ++i) + chk2d<I, J>(j, i); + } + std::cerr << "OK" << std::endl; + + (std::cerr << " in 3d ... ").flush (); + { + for (unsigned k = 2; k < slis; ++k) + for (unsigned j = 2; j < rows; ++j) + for (unsigned i = 2; i < cols; ++i) + chk3d<I, J>(k, j, i); + } + std::cerr << "OK" << std::endl; + } + + template <typename I> + void + ch(unsigned slis, unsigned rows, unsigned cols) + { + std::cerr << " into int:" << std::endl; + chk<I, int>(slis, rows, cols); + std::cerr << " into unsigned:" << std::endl; + chk<I, unsigned>(slis, rows, cols); + std::cerr << " into int_u8:" << std::endl; + chk<I, value::int_u8>(slis, rows, cols); + std::cerr << " into int_u16:" << std::endl; + chk<I, value::int_u16>(slis, rows, cols); + std::cerr << " into int_s8:" << std::endl; + chk<I, value::int_s8>(slis, rows, cols); + std::cerr << " into int_s16:" << std::endl; + chk<I, value::int_s16>(slis, rows, cols); + } +} + + +int main() +{ + using namespace mln; + + unsigned slis = 4; + unsigned rows = 4; + unsigned cols = 16; + + std::cerr << "Tests level::paste:" << std::endl; + std::cerr << "on int:" << std::endl; + ch<int>(slis, rows, cols); + std::cerr << "on unsigned:" << std::endl; + ch<unsigned>(slis, rows, cols); +} + Index: trunk/milena/tests/level/stretch_full.cc =================================================================== --- trunk/milena/tests/level/stretch_full.cc (revision 0) +++ trunk/milena/tests/level/stretch_full.cc (revision 1596) @@ -0,0 +1,174 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/level/stretch_full.cc + * + * \brief Tests on mln::level::stretch. + */ + + +#include <mln/core/image1d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/image3d.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> + +#include <mln/value/int_s8.hh> +#include <mln/value/int_s16.hh> + + +#include <mln/debug/iota.hh> + +#include <mln/level/saturate.hh> +#include <mln/level/stretch.hh> + + + +namespace mln +{ + template <typename I, typename J> + void + chck(Image<I>& input_, Image<J>& output_) + { + typedef mln_value(I) T; + typedef mln_value(J) V; + unsigned max_i = mln_max (T); + unsigned max_j = mln_max (V); + I& input = exact(input_); + J& output = exact(output_); + + level::stretch(input, output); + + // FIXME : How test that? + } + + template <typename I, typename J> + void + chk1d(unsigned cols) + { + { + image1d<I> input (cols); + debug::iota(input); + image1d<J> output (cols); + chck(input, output); + } + + } + + template <typename I, typename J> + void + chk2d(unsigned rows, unsigned cols) + { + + { + image2d<I> input (rows, cols); + debug::iota(input); + image2d<J> output (rows, cols); + chck(input, output); + } + + } + + template <typename I, typename J> + void + chk3d(unsigned slis, unsigned rows, unsigned cols) + { + + { + image3d<I> input (slis, rows, cols); + debug::iota(input); + image3d<J> output (slis, rows, cols); + chck(input, output); + } + + } + + + template <typename I, typename J> + void + chk(unsigned slis, unsigned rows, unsigned cols) + { + (std::cerr << " in 1d ... ").flush (); + { + for (unsigned i = 2; i < cols; ++i) + chk1d<I, J>(i); + } + std::cerr << "OK" << std::endl; + + (std::cerr << " in 2d ... ").flush (); + { + for (unsigned j = 2; j < rows; ++j) + for (unsigned i = 2; i < cols; ++i) + chk2d<I, J>(j, i); + } + std::cerr << "OK" << std::endl; + + (std::cerr << " in 3d ... ").flush (); + { + for (unsigned k = 2; k < slis; ++k) + for (unsigned j = 2; j < rows; ++j) + for (unsigned i = 2; i < cols; ++i) + chk3d<I, J>(k, j, i); + } + std::cerr << "OK" << std::endl; + } + + template <typename I> + void + ch(unsigned slis, unsigned rows, unsigned cols) + { + std::cerr << " into int_u8:" << std::endl; + chk<I, value::int_u8>(slis, rows, cols); + std::cerr << " into int_u16:" << std::endl; + chk<I, value::int_u16>(slis, rows, cols); + } +} + + +int main() +{ + using namespace mln; + + unsigned slis = 4; + unsigned rows = 4; + unsigned cols = 16; + + std::cerr << "Tests level::stretch:" << std::endl; + std::cerr << "on int:" << std::endl; + ch<int>(slis, rows, cols); + std::cerr << "on unsigned:" << std::endl; + ch<unsigned>(slis, rows, cols); + std::cerr << "on int_u8:" << std::endl; + ch<value::int_u8>(slis, rows, cols); + std::cerr << "on int_u16:" << std::endl; + ch<value::int_u16>(slis, rows, cols); + std::cerr << "on int_s8:" << std::endl; + ch<value::int_s8>(slis, rows, cols); + std::cerr << "on int_s16:" << std::endl; + ch<value::int_s16>(slis, rows, cols); +} Index: trunk/milena/tests/level/sort_points_full.cc =================================================================== --- trunk/milena/tests/level/sort_points_full.cc (revision 0) +++ trunk/milena/tests/level/sort_points_full.cc (revision 1596) @@ -0,0 +1,318 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/level/sort_points.cc + * + * \brief Tests on mln::level::sort_points. + */ + +#include <mln/core/image1d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/image3d.hh> +#include <mln/core/sub_image.hh> + +#include <mln/core/image_if.hh> +#include <mln/fun/p2b/chess.hh> + +#include <mln/literal/origin.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> + +#include <mln/value/int_s8.hh> +#include <mln/value/int_s16.hh> + +#include <mln/core/p_array.hh> +#include <mln/debug/iota.hh> + +#include <mln/level/saturate.hh> +#include <mln/level/paste.hh> +#include <mln/level/sort_points.hh> + + + +struct f_box1d_t : mln::Function_p2b< f_box1d_t > +{ + f_box1d_t(const mln::box1d& b) + : b_(b) + { + } + mln::box1d b_; + bool operator()(const mln::point1d& p) const + { + return b_.has(p); + } +}; + +struct f_box2d_t : mln::Function_p2b< f_box2d_t > +{ + f_box2d_t(const mln::box2d& b) + : b_(b) + { + } + mln::box2d b_; + bool operator()(const mln::point2d& p) const + { + return b_.has(p); + } +}; + +struct f_box3d_t : mln::Function_p2b< f_box3d_t > +{ + f_box3d_t(const mln::box3d& b) + : b_(b) + { + } + mln::box3d b_; + bool operator()(const mln::point3d& p) const + { + return b_.has(p); + } +}; + + + +namespace mln +{ + template <typename I, typename J> + void + chck(Image<I>& input_, p_array<J>& array_inc_ref, p_array<J>& array_dec_ref) + { + I& input = exact(input_); + + p_array<J> array_inc = level::sort_points_increasing(input); + p_array<J> array_dec = level::sort_points_decreasing(input); + + mln_assertion(array_inc == array_inc_ref); + mln_assertion(array_dec == array_dec_ref); + } + + template <typename I> + void + chk1d(int cols) + { + box1d b1(literal::origin, point1d(1)); + f_box1d_t f_b1(b1); + + { + image1d<I> input (cols); + debug::iota(input); + + p_array<point1d> array_inc_ref; + p_array<point1d> array_dec_ref; + + for (int i = 0; i < cols; ++i) + array_inc_ref.append(point1d(i)); + + for (int i = cols - 1; i >= 0; --i) + array_dec_ref.append(point1d(i)); + + chck(input, array_inc_ref, array_dec_ref); + } + + p_array<point1d> array_inc_ref; + p_array<point1d> array_dec_ref; + + for (int i = 0; i < 2; ++i) + array_inc_ref.append(point1d(i)); + + for (int i = 1; i >= 0; --i) + array_dec_ref.append(point1d(i)); + + { + image1d<I> in (cols); + sub_image<image1d<I>, box1d> input (in, b1); + debug::iota(input); + chck(input, array_inc_ref, array_dec_ref); + } + + { + image1d<I> in (cols); + image_if<image1d<I>, f_box1d_t> input(in, f_b1); + debug::iota(input); + chck(input, array_inc_ref, array_dec_ref); + } + } + + template <typename I> + void + chk2d(int rows, int cols) + { + box2d b2(literal::origin, point2d(1, 1)); + f_box2d_t f_b2(b2); + + { + image2d<I> input (rows, cols); + debug::iota(input); + + p_array<point2d> array_inc_ref; + p_array<point2d> array_dec_ref; + + for (int j = 0; j < rows; ++j) + for (int i = 0; i < cols; ++i) + array_inc_ref.append(point2d(j, i)); + + for (int j = rows - 1; j >= 0; --j) + for (int i = cols - 1; i >= 0; --i) + array_dec_ref.append(point2d(j, i)); + + chck(input, array_inc_ref, array_dec_ref); + } + + p_array<point2d> array_inc_ref; + p_array<point2d> array_dec_ref; + + for (int j = 0; j < 2; ++j) + for (int i = 0; i < 2; ++i) + array_inc_ref.append(point2d(j, i)); + + for (int j = 1; j >= 0; --j) + for (int i = 1; i >= 0; --i) + array_dec_ref.append(point2d(j, i)); + + { + image2d<I> in (rows, cols); + sub_image<image2d<I>, box2d> input (in, b2); + debug::iota(input); + chck(input, array_inc_ref, array_dec_ref); + } + + { + image2d<I> in (rows, cols); + image_if<image2d<I>, f_box2d_t> input(in, f_b2); + debug::iota(input); + chck(input, array_inc_ref, array_dec_ref); + } + } + + template <typename I> + void + chk3d(int slis, int rows, int cols) + { + box3d b3(literal::origin, point3d(1, 1, 1)); + f_box3d_t f_b3(b3); + + { + image3d<I> input (slis, rows, cols); + debug::iota(input); + + p_array<point3d> array_inc_ref; + p_array<point3d> array_dec_ref; + + for (int k = 0; k < slis; ++k) + for (int j = 0; j < rows; ++j) + for (int i = 0; i < cols; ++i) + array_inc_ref.append(point3d(k, j, i)); + + for (int k = slis - 1; k >= 0; --k) + for (int j = rows - 1; j >= 0; --j) + for (int i = cols - 1; i >= 0; --i) + array_dec_ref.append(point3d(k, j, i)); + + chck(input, array_inc_ref, array_dec_ref); + } + + p_array<point3d> array_inc_ref; + p_array<point3d> array_dec_ref; + + for (int k = 0; k < 2; ++k) + for (int j = 0; j < 2; ++j) + for (int i = 0; i < 2; ++i) + array_inc_ref.append(point3d(k, j, i)); + + for (int k = 1; k >= 0; --k) + for (int j = 1; j >= 0; --j) + for (int i = 1; i >= 0; --i) + array_dec_ref.append(point3d(k, j, i)); + + { + image3d<I> in (slis, rows, cols); + sub_image<image3d<I>, box3d> input (in, b3); + debug::iota(input); + chck(input, array_inc_ref, array_dec_ref); + } + + { + image3d<I> in (slis, rows, cols); + image_if<image3d<I>, f_box3d_t> input(in, f_b3); + debug::iota(input); + chck(input, array_inc_ref, array_dec_ref); + } + + } + + + template <typename I> + void + chk(int slis, int rows, int cols) + { + (std::cerr << " in 1d ... ").flush (); + { + for (int i = 2; i < cols; ++i) + chk1d<I>(i); + } + std::cerr << "OK" << std::endl; + + (std::cerr << " in 2d ... ").flush (); + { + for (int j = 2; j < rows; ++j) + for (int i = 2; i < cols; ++i) + chk2d<I>(j, i); + } + std::cerr << "OK" << std::endl; + + (std::cerr << " in 3d ... ").flush (); + { + for (int k = 2; k < slis; ++k) + for (int j = 2; j < rows; ++j) + for (int i = 2; i < cols; ++i) + chk3d<I>(k, j, i); + } + std::cerr << "OK" << std::endl; + } + +} + + +int main() +{ + using namespace mln; + + int slis = 8; + int rows = 8; + int cols = 8; + + std::cerr << "Tests level::sort_points:" << std::endl; + std::cerr << "in int:" << std::endl; + chk<int>(slis, rows, cols); + std::cerr << "in unsigned:" << std::endl; + chk<unsigned>(slis, rows, cols); + std::cerr << "in int_u16:" << std::endl; + chk<value::int_u16>(slis, rows, cols); + std::cerr << "in int_s16:" << std::endl; + chk<value::int_s16>(slis, rows, cols); +} Index: trunk/milena/tests/level/saturate_full.cc =================================================================== --- trunk/milena/tests/level/saturate_full.cc (revision 0) +++ trunk/milena/tests/level/saturate_full.cc (revision 1596) @@ -0,0 +1,241 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/level/saturate_full.cc + * + * \brief Tests on mln::level::saturate. + */ + + +#include <mln/core/image1d.hh> +#include <mln/core/image2d.hh> +#include <mln/core/image3d.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u16.hh> +#include <mln/value/int_s8.hh> +#include <mln/value/int_s16.hh> + + +#include <mln/core/clone.hh> +#include <mln/level/saturate.hh> +#include <mln/debug/iota.hh> + +#include <mln/debug/println.hh> + + +namespace mln +{ + template <typename I, typename J> + void + chck(I& ref, J& out, mln_value(I) min, mln_value(I) max) + { + mln_value(J) min2 = min; + mln_value(J) max2 = max; + + mln_piter(I) p (ref.domain ()); + + { + level::saturate(ref, min, max, out); + + for_all(p) + { + if (ref(p) <= min) + { + mln_assertion(out(p) == min2); + continue; + } + if (ref(p) >= max) + { + mln_assertion(out(p) == max2); + continue; + } + mln_assertion(ref(p) == (mln_value(I)) out(p)); + } + } + + { + level::saturate_inplace(ref, min, max); + + for_all(p) + { + mln_assertion(ref(p) == (mln_value(I)) out(p)); + } + } + } + + template <typename I, typename J> + void + chk1d(unsigned cols, + int min, + int max) + { + image1d<I> ima (cols); + image1d<J> out (cols); + debug::iota (ima); + chck(ima, out, min, max); + } + + template <typename I, typename J> + void + chk2d(unsigned rows, + unsigned cols, + int min, + int max) + { + image2d<I> ima (rows, cols); + image2d<J> out (rows, cols); + debug::iota (ima); + chck(ima, out, min, max); + } + + template <typename I, typename J> + void + chk3d(unsigned slis, + unsigned rows, + unsigned cols, + int min, + int max) + { + image3d<I> ima (slis, rows, cols); + image3d<J> out (slis, rows, cols); + debug::iota (ima); + chck(ima, out, min, max); + } + +} + + +int main() +{ + using namespace mln; + + unsigned slis_start = 1; + unsigned slis_end = 3; + + unsigned rows_start = 1; + unsigned rows_end = 5; + + unsigned cols_start = 2; + unsigned cols_end = 6; + + + std::cerr << "Tests level::saturate" << std::endl; + + (std::cerr << "in 1d ... ").flush (); + { + for (unsigned i = cols_start; i < cols_end; ++i) + for (unsigned j = 1; j < i; ++j) + for (unsigned k = j + 1; k <= i; ++k) + { + chk1d<int, int>(i, j, k); + chk1d<unsigned, unsigned>(i, j, k); + chk1d<int, unsigned>(i, j, k); + chk1d<unsigned, int>(i, j, k); + + chk1d<value::int_u8, value::int_u8>(i, j, k); + chk1d<value::int_u16, value::int_u16>(i, j, k); + chk1d<value::int_s8, value::int_s8>(i, j, k); + chk1d<value::int_s16, value::int_s16>(i, j, k); + + chk1d<unsigned, value::int_u8>(i, j, k); + chk1d<unsigned, value::int_u16>(i, j, k); + chk1d<int, value::int_s8>(i, j, k); + chk1d<int, value::int_s16>(i, j, k); + + chk1d<value::int_u8, unsigned>(i, j, k); + chk1d<value::int_u16, unsigned>(i, j, k); + chk1d<value::int_s8, int>(i, j, k); + chk1d<value::int_s16, int>(i, j, k); + } + } + std::cerr << "OK" << std::endl; + + (std::cerr << "in 2d ... ").flush (); + { + for (unsigned h = rows_start; h < rows_end; ++h) + for (unsigned i = cols_start; i < cols_end; ++i) + for (unsigned j = 1; j < i; ++j) + for (unsigned k = j + 1; k <= i; ++k) + { + chk2d<int, int>(h, i, j, k); + chk2d<unsigned, unsigned>(h, i, j, k); + chk2d<int, unsigned>(h, i, j, k); + chk2d<unsigned, int>(h, i, j, k); + + chk2d<value::int_u8, value::int_u8>(h, i, j, k); + chk2d<value::int_u16, value::int_u16>(h, i, j, k); + chk2d<value::int_s8, value::int_s8>(h, i, j, k); + chk2d<value::int_s16, value::int_s16>(h, i, j, k); + + chk2d<unsigned, value::int_u8>(h, i, j, k); + chk2d<unsigned, value::int_u16>(h, i, j, k); + chk2d<int, value::int_s8>(h, i, j, k); + chk2d<int, value::int_s16>(h, i, j, k); + + chk2d<value::int_u8, unsigned>(h, i, j, k); + chk2d<value::int_u16, unsigned>(h, i, j, k); + chk2d<value::int_s8, int>(h, i, j, k); + chk2d<value::int_s16, int>(h, i, j, k); + } + } + std::cerr << "OK" << std::endl; + + + (std::cerr << "in 3d ... ").flush (); + { + for (unsigned g = slis_start; g < slis_end; ++g) + for (unsigned h = rows_start; h < rows_end; ++h) + for (unsigned i = cols_start; i < cols_end; ++i) + for (unsigned j = 1; j < i; ++j) + for (unsigned k = j + 1; k <= i; ++k) + { + chk3d<int, int>(g, h, i, j, k); + chk3d<unsigned, unsigned>(g, h, i, j, k); + chk3d<int, unsigned>(g, h, i, j, k); + chk3d<unsigned, int>(g, h, i, j, k); + + chk3d<value::int_u8, value::int_u8>(g, h, i, j, k); + chk3d<value::int_u16, value::int_u16>(g, h, i, j, k); + chk3d<value::int_s8, value::int_s8>(g, h, i, j, k); + chk3d<value::int_s16, value::int_s16>(g, h, i, j, k); + + chk3d<unsigned, value::int_u8>(g, h, i, j, k); + chk3d<unsigned, value::int_u16>(g, h, i, j, k); + chk3d<int, value::int_s8>(g, h, i, j, k); + chk3d<int, value::int_s16>(g, h, i, j, k); + + chk3d<value::int_u8, unsigned>(g, h, i, j, k); + chk3d<value::int_u16, unsigned>(g, h, i, j, k); + chk3d<value::int_s8, int>(g, h, i, j, k); + chk3d<value::int_s16, int>(g, h, i, j, k); + } + } + std::cerr << "OK" << std::endl; + + +} Index: trunk/milena/mln/level/paste.spe.hh =================================================================== --- trunk/milena/mln/level/paste.spe.hh (revision 1595) +++ trunk/milena/mln/level/paste.spe.hh (revision 1596) @@ -65,6 +65,7 @@ // FIXME: For linear data images, we should get the len for each line... typename I::line_piter p(data.domain()); // FIXME: Alias mln_line_piter! + // mln_line_piter(I) p(data.domain()); for_all(p) memcpy_(inplace(make::pixel(destination, p)), make::pixel(data, p), Index: trunk/milena/mln/fun/v2v/saturate.hh =================================================================== --- trunk/milena/mln/fun/v2v/saturate.hh (revision 1595) +++ trunk/milena/mln/fun/v2v/saturate.hh (revision 1596) @@ -62,6 +62,7 @@ protected: V min_, max_; + bool needs_update_; }; @@ -73,6 +74,7 @@ : min_(mln_min(V)), max_(mln_max(V)) { + needs_update_ = true; } template <typename V> @@ -82,6 +84,7 @@ max_(max) { mln_precondition(max > min); + needs_update_ = true; } template <typename V> @@ -92,8 +95,15 @@ { // FIXME: Check that W is a larger type than V; otherwise // alt code. - static const W min_W = mln::value::cast<W>(min_); - static const W max_W = mln::value::cast<W>(max_); + + static W min_W, max_W; + if (needs_update_) + { + min_W = mln::value::cast<W>(min_); + max_W = mln::value::cast<W>(max_); + // FIXME +// needs_update_ = false; + } // FIXME: Below we need something more powerful that mlc_converts_to // for instance, with W=int_s<10u> and V=int_u<8u>, it does not
participants (1)
-
Guillaume Duhamel