3092: Fix warnings due to g++ -Wconversion option.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Fix warnings due to g++ -Wconversion option. * mln/core/site_set/box.hh, * mln/core/site_set/p_line2d.hh, * mln/core/image/extension_val.hh, * mln/math/jacobi.hh, * mln/level/transform.hh, * mln/data/paste.spe.hh, * mln/data/fill_with_image.hh, * mln/data/fill_with_value.spe.hh, * mln/data/fill.hh, * mln/data/paste.hh, * mln/data/fill_with_value.hh, * mln/linear/gaussian.hh, * mln/accu/convolve.hh, * mln/value/ops.hh, * mln/value/int_u_sat.hh, * mln/border/mirror.hh, * mln/convert/to_image.hh, * mln/geom/essential.hh, * mln/fun/v2v/inc.hh, * mln/fun/v2v/cast.hh, * mln/fun/v2v/linear.hh, * mln/fun/v2v/dec.hh, * mln/win/cuboid3d.hh, * mln/win/cube3d.hh, * mln/algebra/quat.hh, * mln/algebra/vec.hh, * mln/io/pbm/load.hh, * mln/norm/linfty.hh, * mln/norm/l1.hh, * mln/norm/l2.hh, * mln/canvas/browsing/snake_fwd.hh, * mln/canvas/browsing/dir_struct_elt_incr_update.hh, * tests/opt/at.cc, * tests/level/transform_inplace.cc, * tests/level/transform.cc, * tests/level/sort_psites.cc, * tests/level/Makefile.am, * tests/data/paste.cc, * tests/data/fill_with_image.cc, * tests/linear/convolve.cc, * tests/linear/convolve_directional.cc, * tests/linear/gaussian.cc, * tests/norm/l2.cc, * tests/norm/common.hh, * tests/norm/linfty.cc: Fix warning with Wconversion. Upgrade file doc style. Layout. Remove a couple of (full of crap) files. * mln/geom/resize.hh: Remove. * mln/geom/all.hh: Update. * tests/geom/resize.cc: Remove. * tests/geom/Makefile.am: Update. * tests/level/sort_psites_full.cc: Remove. mln/accu/convolve.hh | 6 - mln/algebra/quat.hh | 25 ++-- mln/algebra/vec.hh | 2 mln/border/mirror.hh | 16 +- mln/canvas/browsing/dir_struct_elt_incr_update.hh | 8 - mln/canvas/browsing/snake_fwd.hh | 2 mln/convert/to_image.hh | 8 - mln/core/image/extension_val.hh | 18 +-- mln/core/site_set/box.hh | 8 - mln/core/site_set/p_line2d.hh | 20 ++- mln/data/fill.hh | 12 +- mln/data/fill_with_image.hh | 15 +- mln/data/fill_with_value.hh | 2 mln/data/fill_with_value.spe.hh | 9 - mln/data/paste.hh | 17 +- mln/data/paste.spe.hh | 11 - mln/fun/v2v/cast.hh | 14 +- mln/fun/v2v/dec.hh | 11 - mln/fun/v2v/inc.hh | 11 - mln/fun/v2v/linear.hh | 26 +++- mln/geom/all.hh | 5 mln/geom/essential.hh | 13 +- mln/io/pbm/load.hh | 2 mln/level/transform.hh | 18 +-- mln/linear/gaussian.hh | 129 +++++++++++----------- mln/math/jacobi.hh | 51 ++++---- mln/norm/l1.hh | 29 +++- mln/norm/l2.hh | 29 +++- mln/norm/linfty.hh | 15 +- mln/value/int_u_sat.hh | 20 +-- mln/value/ops.hh | 22 ++- mln/win/cube3d.hh | 18 +-- mln/win/cuboid3d.hh | 21 ++- tests/data/fill_with_image.cc | 6 - tests/data/paste.cc | 6 - tests/geom/Makefile.am | 2 tests/level/Makefile.am | 4 tests/level/sort_psites.cc | 19 +-- tests/level/transform.cc | 16 +- tests/level/transform_inplace.cc | 61 +++++----- tests/linear/convolve.cc | 22 +-- tests/linear/convolve_directional.cc | 10 - tests/linear/gaussian.cc | 10 - tests/norm/common.hh | 18 ++- tests/norm/l2.cc | 15 +- tests/norm/linfty.cc | 14 +- tests/opt/at.cc | 8 - 47 files changed, 449 insertions(+), 375 deletions(-) Index: mln/core/site_set/box.hh --- mln/core/site_set/box.hh (revision 3091) +++ mln/core/site_set/box.hh (working copy) @@ -314,8 +314,8 @@ mln_precondition(is_valid()); for (unsigned i = 0; i < P::dim; ++i) { - pmin_[i] -= b; - pmax_[i] += b; + pmin_[i] = static_cast<mln_coord(P)>(pmin_[i] - b); + pmax_[i] = static_cast<mln_coord(P)>(pmax_[i] + b); } mln_postcondition(is_valid()); } @@ -326,8 +326,8 @@ box<P>::enlarge(unsigned dim, unsigned b) { mln_precondition(is_valid()); - pmin_[dim] -= b; - pmax_[dim] += b; + pmin_[dim] = static_cast<mln_coord(P)>(pmin_[dim] - b); + pmax_[dim] = static_cast<mln_coord(P)>(pmax_[dim] + b); mln_postcondition(is_valid()); } Index: mln/core/site_set/p_line2d.hh --- mln/core/site_set/p_line2d.hh (revision 3091) +++ mln/core/site_set/p_line2d.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 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 @@ -35,7 +36,11 @@ # include <mln/core/site_set/p_array.hh> # include <mln/core/alias/box2d.hh> -# include <mln/math/all.hh> + +# include <mln/math/sign.hh> +# include <mln/math/abs.hh> +# include <mln/math/min.hh> +# include <mln/math/max.hh> namespace mln @@ -187,7 +192,8 @@ int e = ddrow - dcol; for (int i = 0; i < dcol; ++i) { - arr_.append(point2d(row, col)); + arr_.append(point2d(static_cast<def::coord>(row), + static_cast<def::coord>(col))); while (e >= 0) { row += srow; @@ -202,7 +208,8 @@ int e = ddcol - drow; for (int i = 0; i < drow; ++i) { - arr_.append(point2d(row, col)); + arr_.append(point2d(static_cast<def::coord>(row), + static_cast<def::coord>(col))); while (e >= 0) { col += scol; @@ -213,7 +220,8 @@ } } if (! is_end_excluded) - arr_.append(point2d(row, col)); + arr_.append(point2d(static_cast<def::coord>(row), + static_cast<def::coord>(col))); // Compute bb_. point2d end_ = arr_[arr_.nsites() - 1]; @@ -280,8 +288,8 @@ p_line2d::to_vec() const { algebra::vec<2, float> res; - res[0] = end().row() - begin().row(); - res[1] = end().col() - begin().col(); + res[0] = float(end().row() - begin().row()); + res[1] = float(end().col() - begin().col()); return res; } Index: mln/core/image/extension_val.hh --- mln/core/image/extension_val.hh (revision 3091) +++ mln/core/image/extension_val.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -28,14 +28,12 @@ #ifndef MLN_CORE_IMAGE_EXTENSION_VAL_HH # define MLN_CORE_IMAGE_EXTENSION_VAL_HH -/*! - * \file mln/core/image/extension_val.hh - * - * \brief Definition of a morpher that extends the domain of an image. - * - * \todo Use the 'instant' mechanism. - * \todo Use an envelop as lvalue to test extension writing. - */ +/// \file mln/core/image/extension_val.hh +/// +/// \brief Definition of a morpher that extends the domain of an image. +/// +/// \todo Use the 'instant' mechanism. +/// \todo Use an envelop as lvalue to test extension writing. # include <mln/core/internal/image_identity.hh> @@ -267,7 +265,7 @@ void init_(tag::extension_t, V& target, const extension_val<I>& model) { mlc_converts_to(mln_value(I), V)::check(); - target = model.extension(); + target = static_cast<V>(model.extension()); } # endif // ! MLN_INCLUDE_ONLY Index: mln/math/jacobi.hh --- mln/math/jacobi.hh (revision 3091) +++ mln/math/jacobi.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -28,12 +28,17 @@ #ifndef MLN_MATH_JACOBI_HH # define MLN_MATH_JACOBI_HH +/// \file mln/math/jacobi.hh + +# include <cmath> + # include <mln/algebra/quat.hh> # include <mln/algebra/mat.hh> // from num. rec. in C // FIXME: what about numrec licence? + namespace mln { @@ -42,12 +47,14 @@ algebra::quat jacobi(algebra::mat < 4, 4, float >a); + # ifndef MLN_INCLUDE_ONLY // FIXME: nD ? #define rotateJacobi(a,i,j,k,l) g=a(i,j);h=a(k,l);a(i,j)=g-s*(h+g*tau); \ a(k,l)=h+s*(g-h*tau) + algebra::quat jacobi(algebra::mat < 4, 4, float >a) { float dd, d[4]; @@ -57,23 +64,23 @@ for (ip = 0; ip < 4; ip++) { for (iq = 0; iq < 4; iq++) - v(ip, iq) = 0.0; - v(ip, ip) = 1.0; + v(ip, iq) = 0.0f; + v(ip, ip) = 1.0f; } for (ip = 0; ip < 4; ip++) { b[ip] = d[ip] = a(ip, ip); - z[ip] = 0.0; + z[ip] = 0.0f; } while (1) { - sm = 0.0; + sm = 0.0f; for (ip = 0; ip < 3; ip++) { for (iq = ip + 1; iq < 4; iq++) - sm += fabs(a(ip, iq)); + sm += std::fabs(a(ip, iq)); } - if (sm < 1e-12) + if (sm < 1e-12f) { // 1e-12 dd = d[0]; iq = 0; @@ -90,7 +97,7 @@ if (i < 4) { i++; - tresh = 0.0125 * sm; + tresh = 0.0125f * sm; } else tresh = 0.0; @@ -98,27 +105,26 @@ { for (iq = ip + 1; iq < 4; iq++) { - g = 100.0 * fabs(a(ip, iq)); - if (i > 4 && (float)(fabs(d[ip])+g) == - (float)fabs(d[ip]) - && (float)(fabs(d[iq])+g) == (float)fabs(d[iq])) - a(ip, iq) = 0.0; - else if (fabs(a(ip, iq)) > tresh) + g = 100.0f * std::fabs(a(ip, iq)); + if (i > 4 && std::fabs(d[ip]) + g == std::fabs(d[ip]) + && std::fabs(d[iq]) + g == std::fabs(d[iq])) + a(ip, iq) = 0.0f; + else if (std::fabs(a(ip, iq)) > tresh) { h = d[iq] - d[ip]; - if ((float)(fabs(h)+g) == (float)fabs(h)) // unsafe? + if (std::fabs(h) + g == std::fabs(h)) // unsafe? t = (a(ip, iq)) / h; else { - theta = 0.5 * h / (a(ip, iq)); - t = 1.0 / (fabs(theta) + sqrt(1.0 + + theta = 0.5f * h / (a(ip, iq)); + t = 1.0f / (std::fabs(theta) + std::sqrt(1.0f + theta * theta)); - if (theta < 0.0) + if (theta < 0.0f) t = -t; } - c = 1.0 / sqrt(1 + t * t); + c = 1.0f / std::sqrt(1 + t * t); s = t * c; - tau = s / (1.0 + c); + tau = s / (1.0f + c); h = t * a(ip, iq); z[ip] -= h; z[iq] += h; @@ -140,7 +146,7 @@ { b[ip] += z[ip]; d[ip] = b[ip]; - z[ip] = 0.0; + z[ip] = 0.0f; } } } @@ -151,5 +157,6 @@ } // end of namespace mln -#endif /* MLN_MATH_JACOBI_HH */ + +#endif // ! MLN_MATH_JACOBI_HH Index: mln/level/transform.hh --- mln/level/transform.hh (revision 3091) +++ mln/level/transform.hh (working copy) @@ -29,14 +29,13 @@ #ifndef MLN_LEVEL_TRANSFORM_HH # define MLN_LEVEL_TRANSFORM_HH -/*! \file mln/level/transform.hh - * - * \brief Transform the contents of an image into another one. - * - * \todo Clean this file + overload with pixel iterators. - * - * \todo Re-activate tests and make them static. - */ +/// \file mln/level/transform.hh +/// +/// Transform the contents of an image into another one. +/// +/// \todo Clean this file + overload with pixel iterators. +/// +/// \todo Re-activate tests and make them static. # include <mln/core/concept/image.hh> # include <mln/core/concept/function.hh> @@ -145,9 +144,6 @@ mln_ch_value(I, mln_result(F)) output; initialize(output, input); - mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))), - trait::image::pw_io::read_write)::check(); - mln_piter(I) p(input.domain()); for_all(p) output(p) = f(input(p)); Index: mln/data/paste.spe.hh --- mln/data/paste.spe.hh (revision 3091) +++ mln/data/paste.spe.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 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 @@ -28,11 +29,9 @@ #ifndef MLN_DATA_PASTE_SPE_HH # define MLN_DATA_PASTE_SPE_HH -/*! \file mln/data/paste.spe.hh - * - * \brief Specializations for mln::data::paste. - * - */ +/// \file mln/data/paste.spe.hh +/// +/// Specializations for mln::data::paste. # ifndef MLN_DATA_PASTE_HH # error "Forbidden inclusion of *.spe.hh" @@ -89,7 +88,7 @@ po.start(); for_all(pi) { - po.val() = pi.val(); + po.val() = static_cast<mln_value(J)>(pi.val()); po.next(); } trace::exiting("data::impl::paste_fast"); Index: mln/data/fill_with_image.hh --- mln/data/fill_with_image.hh (revision 3091) +++ mln/data/fill_with_image.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -28,12 +28,11 @@ #ifndef MLN_DATA_FILL_WITH_IMAGE_HH # define MLN_DATA_FILL_WITH_IMAGE_HH -/*! \file mln/data/fill_with_image.hh - * - * \brief Fill an image with the values from another image. - * - * \todo Specialize with line_piter... - */ +/// \file mln/data/fill_with_image.hh +/// +/// Fill an image with the values from another image. +/// +/// \todo Specialize with line_piter... # include <mln/core/concept/image.hh> @@ -107,7 +106,7 @@ mln_piter(I) p(ima.domain()); for_all(p) - ima(p) = data(p); + ima(p) = static_cast<mln_value(I)>(data(p)); trace::exiting("data::impl::generic::fill_with_image"); } Index: mln/data/fill_with_value.spe.hh --- mln/data/fill_with_value.spe.hh (revision 3091) +++ mln/data/fill_with_value.spe.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -29,8 +29,8 @@ # define MLN_DATA_FILL_WITH_VALUE_SPE_HH /// \file mln/data/fill_with_value.spe.hh -/// Specializations for mln::data::fill_with_value. /// +/// Specializations for mln::data::fill_with_value. # ifndef MLN_DATA_FILL_WITH_VALUE_HH # error "Forbidden inclusion of *.spe.hh" @@ -87,7 +87,8 @@ mlc_is(mln_trait_image_value_access(I), trait::image::value_access::direct))::check(); - data::memset_(ima, ima.point_at_index(0), val, ima.nelements()); + mln_value(I) v = static_cast<mln_value(I)>(val); + data::memset_(ima, ima.point_at_index(0), v, ima.nelements()); trace::exiting("data::impl::fill_with_value_one_block"); } @@ -123,7 +124,7 @@ mlc_is(mln_trait_image_vw_io(I), trait::image::vw_io::read_write))::check(); - ima.val() = val; + ima.val() = static_cast<mln_value(I)>(val); trace::exiting("data::impl::fill_with_value_singleton"); } Index: mln/data/fill.hh --- mln/data/fill.hh (revision 3091) +++ mln/data/fill.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 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 @@ -28,12 +29,11 @@ #ifndef MLN_DATA_FILL_HH # define MLN_DATA_FILL_HH -/*! \file mln/data/fill.hh - * - * \brief Fill an image, that is, set pixel values. - * - * \todo Add a conversion "arr->fun" then get rid of the C array overload. - */ +/// \file mln/data/fill.hh +/// +/// Fill an image, that is, set pixel values. +/// +/// \todo Add a conversion "arr->fun" then get rid of the C array overload. # include <mln/core/concept/function.hh> # include <mln/pw/image.hh> Index: mln/data/paste.hh --- mln/data/paste.hh (revision 3091) +++ mln/data/paste.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 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 @@ -28,16 +29,12 @@ #ifndef MLN_DATA_PASTE_HH # define MLN_DATA_PASTE_HH -/*! \file mln/data/paste.hh - * - * \brief Paste the contents of an image into another one. - * - */ +/// \file mln/data/paste.hh +/// +/// Paste the contents of an image into another one. # include <mln/core/concept/image.hh> - - // Specializations are in: # include <mln/data/paste.spe.hh> @@ -65,10 +62,8 @@ /// /// \pre \p input.domain <= \p output.domain /// - /// \{ template <typename I, typename J> void paste(const Image<I>& input, Image<J>& output); - /// \} @@ -95,6 +90,7 @@ } // end of namespace mln::data::internal + namespace impl { @@ -115,7 +111,7 @@ mln_piter(I) p(input.domain()); for_all(p) - output(p) = input(p); + output(p) = static_cast<mln_value(J)>(input(p)); trace::exiting("data::impl::generic::paste"); } @@ -133,7 +129,6 @@ { trace::entering("data::paste"); - internal::paste_tests(input, output); internal::paste_(input, output); Index: mln/data/fill_with_value.hh --- mln/data/fill_with_value.hh (revision 3091) +++ mln/data/fill_with_value.hh (working copy) @@ -104,7 +104,7 @@ mlc_is(mln_trait_image_pw_io(I), trait::image::pw_io::read_write)::check(); - mln_value(I) v = exact(val); + mln_value(I) v = static_cast<mln_value(I)>(exact(val)); mln_piter(I) p(ima.domain()); for_all(p) ima(p) = v; Index: mln/linear/gaussian.hh --- mln/linear/gaussian.hh (revision 3091) +++ mln/linear/gaussian.hh (working copy) @@ -33,26 +33,21 @@ /// /// Gaussian filter. /// -/// \todo Add a clean reference David Deriche +/// \todo Add a clean reference Rachid Deriche /// Recursively implementing the gaussian and its derivatives (1993) +# include <vector> +# include <cmath> + # include <mln/core/concept/image.hh> # include <mln/core/alias/point2d.hh> -# include <mln/data/paste.hh> +# include <mln/extension/adjust_fill.hh> # include <mln/geom/ncols.hh> # include <mln/geom/nrows.hh> - -# include <mln/trait/image/props.hh> - -# include <mln/extension/adjust_fill.hh> +# include <mln/data/paste.hh> # include <mln/level/stretch.hh> - # include <mln/algebra/vec.hh> -# include <vector> -# include <cmath> - -# include <mln/debug/println.hh> namespace mln { @@ -111,10 +106,10 @@ w0 /= s; w1 /= s; - float sin0 = sin(w0); - float sin1 = sin(w1); - float cos0 = cos(w0); - float cos1 = cos(w1); + float sin0 = std::sin(w0); + float sin1 = std::sin(w1); + float cos0 = std::cos(w0); + float cos1 = std::cos(w1); int sign = 1; float n_ = norm(a0, a1, b0, b1, c0, c1, cos0, sin0, cos1, sin1, sign); @@ -125,37 +120,37 @@ c1 /= n_; n[3] = - exp(-b1 - 2*b0) * (c1 * sin1 - cos1 * c0) + - exp(-b0 - 2*b1) * (a1 * sin0 - cos0 * a0); + std::exp(-b1 - 2*b0) * (c1 * sin1 - cos1 * c0) + + std::exp(-b0 - 2*b1) * (a1 * sin0 - cos0 * a0); n[2] = - 2 * exp(-b0 - b1) * ((a0 + c0) * cos1 * cos0 - + 2 * std::exp(-b0 - b1) * ((a0 + c0) * cos1 * cos0 - cos1 * a1 * sin0 - cos0 * c1 * sin1) + - c0 * exp(-2*b0) + a0 * exp(-2*b1); + c0 * std::exp(-2*b0) + a0 * std::exp(-2*b1); n[1] = - exp(-b1) * (c1 * sin1 - (c0 + 2 * a0) * cos1) + - exp(-b0) * (a1 * sin0 - (2 * c0 + a0) * cos0); + std::exp(-b1) * (c1 * sin1 - (c0 + 2 * a0) * cos1) + + std::exp(-b0) * (a1 * sin0 - (2 * c0 + a0) * cos0); n[0] = a0 + c0; d[4] = - exp(-2 * b0 - 2 * b1); + std::exp(-2 * b0 - 2 * b1); d[3] = - -2 * cos0 * exp(-b0 - 2*b1) - - 2 * cos1 * exp(-b1 - 2*b0); + -2 * cos0 * std::exp(-b0 - 2*b1) - + 2 * cos1 * std::exp(-b1 - 2*b0); d[2] = - 4 * cos1 * cos0 * exp(-b0 - b1) + - exp(-2*b1) + exp(-2*b0); + 4 * cos1 * cos0 * std::exp(-b0 - b1) + + std::exp(-2*b1) + std::exp(-2*b0); d[1] = - -2 * exp(-b1) * cos1 - 2 * exp(-b0) * cos0; + -2 * std::exp(-b1) * cos1 - 2 * std::exp(-b0) * cos0; for (unsigned i = 1; i <= 3; ++i) { dm[i] = d[i]; - nm[i] = sign * (n[i] - d[i] * n[0]); + nm[i] = float(sign) * (n[i] - d[i] * n[0]); } dm[4] = d[4]; - nm[4] = sign * (-d[4] * n[0]); + nm[4] = float(sign) * (-d[4] * n[0]); } @@ -267,14 +262,14 @@ float cos1, float sin1, int& sign) { - float expb0 = exp(b0); - float exp2b0 = exp(2.0 * b0); + float expb0 = std::exp(b0); + float exp2b0 = std::exp(2.f * b0); float scale0 = 1 + exp2b0 - 2 * cos0 * expb0; float scaleA = 2 * a1 * sin0 * expb0 - a0 * (1 - exp2b0); - float expb1 = exp(b1); - float exp2b1 = exp(2.0 * b1); + float expb1 = std::exp(b1); + float exp2b1 = std::exp(2.f * b1); float scale1 = 1 + exp2b1 - 2 * cos1 * expb1; float scaleC = 2 * c1 * sin1 * expb1 - c0 * (1 - exp2b1); @@ -295,16 +290,16 @@ float cos1, float sin1, int& sign) { - float expb0 = exp(b0); - float exp2b0 = exp(2.0 * b0); + float expb0 = std::exp(b0); + float exp2b0 = std::exp(2.f * b0); float scale0 = 1 + exp2b0 - 2 * cos0 * expb0; scale0 *= scale0; float scaleA = - 2 * a1 * sin0 * expb0 * (1 - exp2b0) + 2 * a0 * expb0 * (2 * expb0 - cos0 * (1 + exp2b0)); - float expb1 = exp(b1); - float exp2b1 = exp(2.0 * b1); + float expb1 = std::exp(b1); + float exp2b1 = std::exp(2.f * b1); float scale1 = 1 + exp2b1 - 2 * cos1 * expb1; scale1 *= scale1; @@ -327,8 +322,8 @@ float cos1, float sin1, int& sign) { - float expb0 = exp(b0); - float exp2b0 = exp(2.0 * b0); + float expb0 = std::exp(b0); + float exp2b0 = std::exp(2.f * b0); float scale0 = 1 + exp2b0 - 2 * cos0 * expb0; scale0 *= scale0 * scale0; @@ -338,8 +333,8 @@ a0 * expb0 * (2 * expb0 * (2 - cos0 * cos0) * (1 - exp2b0) - cos0 * (1 - exp2b0 * exp2b0)); - float expb1 = exp(b1); - float exp2b1 = exp(2.0 * b1); + float expb1 = std::exp(b1); + float exp2b1 = std::exp(2.f * b1); float scale1 = 1 + exp2b1 - 2 * cos1 * expb1; scale1 *= scale1 * scale1; @@ -368,9 +363,9 @@ recursivefilter_<mln_value(I)>(img, coef, - point1d(-img.border()), - point1d(geom::ninds(img) - 1 + - img.border()), + point1d(static_cast<def::coord>(-img.border())), + point1d(static_cast<def::coord>(geom::ninds(img) - 1 + + img.border())), geom::ninds(img) + 2 * img.border(), dpoint1d(1)); } @@ -391,9 +386,11 @@ // Apply on rows. for (unsigned j = 0; j < geom::ncols(img); ++j) recursivefilter_<mln_value(I)>(img, coef, - point2d(-img.border(), j), - point2d(geom::nrows(img) - 1 + - img.border(), j), + point2d(static_cast<def::coord>(-img.border()), + static_cast<def::coord>(j)), + point2d(static_cast<def::coord>(geom::nrows(img) - 1 + + img.border()), + static_cast<def::coord>(j)), geom::nrows(img) + 2 * img.border(), dpoint2d(1, 0)); } @@ -403,9 +400,11 @@ // Apply on columns. for (unsigned i = 0; i < geom::nrows(img); ++i) recursivefilter_<mln_value(I)>(img, coef, - point2d(i, -img.border()), - point2d(i, geom::ncols(img) - 1 + - img.border()), + point2d(static_cast<def::coord>(i), + static_cast<def::coord>(-img.border())), + point2d(static_cast<def::coord>(i), + static_cast<def::coord>(geom::ncols(img) - 1 + + img.border())), geom::ncols(img) + 2 * img.border(), dpoint2d(0, 1)); } @@ -426,9 +425,13 @@ for (unsigned j = 0; j < geom::nrows(img); ++j) for (unsigned k = 0; k < geom::ncols(img); ++k) recursivefilter_<mln_value(I)>(img, coef, - point3d(-img.border(), j , k), - point3d(geom::nslis(img) - 1 + - img.border(), j, k), + point3d(static_cast<def::coord>(-img.border()), + static_cast<def::coord>(j), + static_cast<def::coord>(k)), + point3d(static_cast<def::coord>(geom::nslis(img) - 1 + + img.border()), + static_cast<def::coord>(j), + static_cast<def::coord>(k)), geom::nslis(img) + 2 * img.border(), dpoint3d(1, 0, 0)); @@ -441,9 +444,13 @@ for (unsigned i = 0; i < geom::nslis(img); ++i) for (unsigned k = 0; k < geom::ncols(img); ++k) recursivefilter_<mln_value(I)>(img, coef, - point3d(i, -img.border(), k), - point3d(i, geom::nrows(img) - 1 + - img.border(), k), + point3d(static_cast<def::coord>(i), + static_cast<def::coord>(-img.border()), + static_cast<def::coord>(k)), + point3d(static_cast<def::coord>(i), + static_cast<def::coord>(geom::nrows(img) - 1 + + img.border()), + static_cast<def::coord>(k)), geom::nrows(img) + 2 * img.border(), dpoint3d(0, 1, 0)); @@ -455,9 +462,13 @@ for (unsigned i = 0; i < geom::nslis(img); ++i) for (unsigned j = 0; j < geom::nrows(img); ++i) recursivefilter_<mln_value(I)>(img, coef, - point3d(i, j, -img.border()), - point3d(i, j, geom::ncols(img) - - 1 + img.border()), + point3d(static_cast<def::coord>(i), + static_cast<def::coord>(j), + static_cast<def::coord>(-img.border())), + point3d(static_cast<def::coord>(i), + static_cast<def::coord>(j), + static_cast<def::coord>(geom::ncols(img) - + 1 + img.border())), geom::ncols(img) + 2 * img.border(), dpoint3d(0, 0, 1)); Index: mln/accu/convolve.hh --- mln/accu/convolve.hh (revision 3091) +++ mln/accu/convolve.hh (working copy) @@ -103,7 +103,7 @@ void convolve<T1,T2,R>::take(const argument& t) { - s_ += t.first * t.second; + s_ = static_cast<S>(s_ + static_cast<S>(t.first) * static_cast<S>(t.second)); } template <typename T1, typename T2, typename R> @@ -111,7 +111,7 @@ void convolve<T1,T2,R>::take(const T1& t1, const T2& t2) { - s_ += t1 * t2; + s_ = static_cast<S>(s_ + static_cast<S>(t1) * static_cast<S>(t2)); } template <typename T1, typename T2, typename R> @@ -119,7 +119,7 @@ void convolve<T1,T2,R>::take(const convolve<T1,T2,R>& other) { - s_ += other.s_; + s_ = static_cast<S>(s_ + other.s_); } template <typename T1, typename T2, typename R> Index: mln/value/ops.hh --- mln/value/ops.hh (revision 3091) +++ mln/value/ops.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -28,10 +29,9 @@ #ifndef MLN_VALUE_OPS_HH # define MLN_VALUE_OPS_HH -/*! \file mln/value/ops.hh - * - * \brief Definitions of operators for value types. - */ +/// \file mln/value/ops.hh +/// +/// Definitions of operators for value types. # include <mln/trait/op/all.hh> # include <mln/value/builtin/all.hh> @@ -216,7 +216,8 @@ mln_trait_op_plus(Vl, Vr) operator + (const value::Scalar<Vl>& lhs, const value::Scalar<Vr>& rhs) { - return value::equiv(lhs) + value::equiv(rhs); + typedef mln_trait_op_plus(Vl, Vr) R; + return static_cast<R>(value::equiv(lhs)) + static_cast<R>(value::equiv(rhs)); } template <typename Vl, typename Vr> @@ -224,7 +225,8 @@ mln_trait_op_minus(Vl, Vr) operator - (const value::Scalar<Vl>& lhs, const value::Scalar<Vr>& rhs) { - return value::equiv(lhs) - value::equiv(rhs); + typedef mln_trait_op_minus(Vl, Vr) R; + return static_cast<R>(value::equiv(lhs)) - static_cast<R>(value::equiv(rhs)); } template <typename Vl, typename Vr> @@ -232,7 +234,8 @@ mln_trait_op_times(Vl, Vr) operator * (const value::Scalar<Vl>& lhs, const value::Scalar<Vr>& rhs) { - return value::equiv(lhs) * value::equiv(rhs); + typedef mln_trait_op_times(Vl, Vr) R; + return static_cast<R>(value::equiv(lhs)) * static_cast<R>(value::equiv(rhs)); } template <typename Vl, typename Vr> @@ -256,7 +259,8 @@ mln_trait_op_uminus(S) operator - (const value::scalar_<S>& rhs) { - return - rhs.to_equiv(); + typedef mln_trait_op_uminus(S) R; + return static_cast<R>(- rhs.to_equiv()); } template <typename S, typename O> Index: mln/value/int_u_sat.hh --- mln/value/int_u_sat.hh (revision 3091) +++ mln/value/int_u_sat.hh (working copy) @@ -29,11 +29,10 @@ #ifndef MLN_VALUE_INT_U_SAT_HH # define MLN_VALUE_INT_U_SAT_HH -/*! \file mln/value/int_u_sat.hh - * - * \brief Define a generic class for unsigned integers with saturation - * behavior. - */ +/// \file mln/value/int_u_sat.hh +/// +/// Define a generic class for unsigned integers with saturation +/// behavior. # include <mln/metal/math/pow.hh> # include <mln/value/internal/value_like.hh> @@ -117,6 +116,9 @@ /// Self subtraction. int_u_sat<n>& operator-=(int i); + + private: + typedef mln_enc(int_u<n>) enc_; }; @@ -155,9 +157,9 @@ // Explicitly cast I to unsigned to avoid a warning between // signed and unsigned values from the compiler. else if (static_cast<unsigned>(i) > max_) - this->v_ = max_; + this->v_ = static_cast<enc_>(max_); else - this->v_ = i; + this->v_ = static_cast<enc_>(i); } template <unsigned n> @@ -178,9 +180,9 @@ // Explicitly cast I to unsigned to avoid a warning between // signed and unsigned values from the compiler. else if (static_cast<unsigned>(i) > max_) - this->v_ = max_; + this->v_ = static_cast<enc_>(max_); else - this->v_ = i; + this->v_ = static_cast<enc_>(i); return *this; } Index: mln/border/mirror.hh --- mln/border/mirror.hh (revision 3091) +++ mln/border/mirror.hh (working copy) @@ -81,9 +81,10 @@ trace::entering("border::impl::mirror_"); I& ima = const_cast<I&>(ima_); - unsigned border = ima.border(); - unsigned nbinds = geom::ninds(ima); - unsigned min; + def::coord + border = static_cast<def::coord>(ima.border()), + nbinds = static_cast<def::coord>(geom::ninds(ima)), + min; if (border > nbinds) min = nbinds; @@ -92,18 +93,19 @@ /// left border { - unsigned i = 0; + def::coord i = 0; for (; i < min; ++i) ima.element(border - 1 - i) = ima(point1d(i)); for (; i < border; ++i) - ima.element(border - 1 - i) = ima(point1d(min - 1)); + ima.element(border - 1 - i) = ima(point1d(static_cast<def::coord>(min - 1))); } /// right border { - unsigned i = 0, - j = nbinds - 1; + def::coord + i = 0, + j = static_cast<def::coord>(nbinds - 1); for (; i < min; ++i, --j) Index: mln/convert/to_image.hh --- mln/convert/to_image.hh (revision 3091) +++ mln/convert/to_image.hh (working copy) @@ -140,10 +140,12 @@ image1d<unsigned> to_image(const histo::data<T>& h) { - T v_min = h.vset()[0], - v_max = h.vset()[h.vset().nvalues() - 1]; + def::coord + n = static_cast<def::coord>(h.vset().nvalues()), + v_min = static_cast<def::coord>(h.vset()[0]), + v_max = static_cast<def::coord>(h.vset()[n - 1]); image1d<unsigned> ima(make::box1d(v_min, v_max)); - for (unsigned i = 0; i < h.vset().nvalues(); ++i) + for (def::coord i = 0; i < n; ++i) ima(point1d(i)) = h[i]; return ima; } Index: mln/geom/essential.hh --- mln/geom/essential.hh (revision 3091) +++ mln/geom/essential.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -28,10 +28,9 @@ #ifndef MLN_GEOM_ESSENTIAL_HH # define MLN_GEOM_ESSENTIAL_HH -/*! \file mln/geom/essential.hh - * - * \brief File that includes essential geometry related things. - */ +/// \file mln/geom/essential.hh +/// +/// File that includes essential geometry related things. namespace mln @@ -43,12 +42,11 @@ /// Implementation namespace of geom namespace. namespace impl {} } - } + # include <mln/geom/bbox.hh> # include <mln/geom/chamfer.hh> -# include <mln/geom/resize.hh> # include <mln/geom/size1d.hh> # include <mln/geom/size2d.hh> # include <mln/geom/size3d.hh> @@ -64,4 +62,5 @@ # include <mln/geom/min_row.hh> # include <mln/geom/min_sli.hh> + #endif // ! MLN_GEOM_ESSENTIAL_HH Index: mln/geom/all.hh --- mln/geom/all.hh (revision 3091) +++ mln/geom/all.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008 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 @@ -63,11 +64,11 @@ # include <mln/geom/nsites.hh> # include <mln/geom/nslis.hh> # include <mln/geom/pmin_pmax.hh> -# include <mln/geom/resize.hh> # include <mln/geom/seeds2tiling.hh> # include <mln/geom/seeds2tiling_roundness.hh> # include <mln/geom/size1d.hh> # include <mln/geom/size2d.hh> # include <mln/geom/size3d.hh> + #endif // ! MLN_GEOM_ALL_HH Index: mln/fun/v2v/inc.hh --- mln/fun/v2v/inc.hh (revision 3091) +++ mln/fun/v2v/inc.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -28,10 +28,9 @@ #ifndef MLN_FUN_V2V_INC_HH # define MLN_FUN_V2V_INC_HH -/*! \file mln/fun/v2v/inc.hh - * - * \brief Incrementation function. - */ +/// \file mln/fun/v2v/inc.hh +/// +/// Incrementation function. # include <mln/fun/internal/selector.hh> @@ -63,7 +62,7 @@ T inc<T>::operator()(const T& t) const { - return t + 1; + return static_cast<T>(t + 1); } # endif // ! MLN_INCLUDE_ONLY Index: mln/fun/v2v/cast.hh --- mln/fun/v2v/cast.hh (revision 3091) +++ mln/fun/v2v/cast.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 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 @@ -28,13 +29,12 @@ #ifndef MLN_FUN_V2V_CAST_HH # define MLN_FUN_V2V_CAST_HH -/*! \file mln/fun/v2v/cast.hh - * - * \brief FIXME. - * - * \todo The function is intrisically meta; how to handle that - * particular case? - */ +/// \file mln/fun/v2v/cast.hh +/// +/// FIXME. +/// +/// \todo The function is intrisically meta; how to handle that +/// particular case? # include <mln/core/concept/function.hh> # include <mln/value/cast.hh> Index: mln/fun/v2v/linear.hh --- mln/fun/v2v/linear.hh (revision 3091) +++ mln/fun/v2v/linear.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -28,12 +29,12 @@ #ifndef MLN_FUN_V2V_LINEAR_HH # define MLN_FUN_V2V_LINEAR_HH -/*! \file mln/fun/v2v/linear.hh - * - * \brief FIXME. - */ +/// \file mln/fun/v2v/linear.hh +/// +/// FIXME. # include <mln/core/concept/function.hh> +# include <mln/convert/to.hh> namespace mln @@ -57,8 +58,12 @@ struct linear : public Function_v2v< linear<V,T,R> > { typedef R result; + R operator()(const V& v) const; + template <typename U> + R operator()(const U& u) const; + linear(T a, T b); T a, b; }; @@ -79,7 +84,16 @@ R linear<V,T,R>::operator()(const V& v) const { - return R(a * T(v) + b); + return convert::to<R>(a * static_cast<T>(v) + b); + } + + template <typename V, typename T, typename R> + template <typename U> + inline + R + linear<V,T,R>::operator()(const U& u) const + { + return this->operator()(static_cast<V>(u)); } # endif // ! MLN_INCLUDE_ONLY Index: mln/fun/v2v/dec.hh --- mln/fun/v2v/dec.hh (revision 3091) +++ mln/fun/v2v/dec.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -28,10 +28,9 @@ #ifndef MLN_FUN_V2V_DEC_HH # define MLN_FUN_V2V_DEC_HH -/*! \file mln/fun/v2v/dec.hh - * - * \brief Decrementation function. - */ +/// \file mln/fun/v2v/dec.hh +/// +/// Decrementation function. # include <mln/fun/internal/selector.hh> @@ -63,7 +62,7 @@ T dec<T>::operator()(const T& t) const { - return t - 1; + return static_cast<T>(t - 1); } # endif // ! MLN_INCLUDE_ONLY Index: mln/win/cuboid3d.hh --- mln/win/cuboid3d.hh (revision 3091) +++ mln/win/cuboid3d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 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 @@ -29,7 +29,8 @@ # define MLN_WIN_CUBOID3D_HH /// \file mln/win/cuboid3d.hh -/// \brief Definition of the mln::win::cuboid3d window. +/// +/// Definition of the mln::win::cuboid3d window. # include <mln/core/internal/classical_window_base.hh> # include <mln/core/alias/dpoint3d.hh> @@ -126,12 +127,16 @@ width_(width) { mln_precondition(height % 2 == 1 && width % 2 == 1); - const int dsli = depth / 2; - const int drow = height / 2; - const int dcol = width / 2; - for (int sli = -dsli; sli <= dsli; ++sli) - for (int row = -drow; row <= drow; ++row) - for (int col = -dcol; col <= dcol; ++col) + const def::coord + dsli = static_cast<def::coord>(depth / 2), + drow = static_cast<def::coord>(height / 2), + dcol = static_cast<def::coord>(width / 2), + minus_dsli = static_cast<def::coord>(- dsli), + minus_drow = static_cast<def::coord>(- drow), + minus_dcol = static_cast<def::coord>(- dcol); + for (def::coord sli = minus_dsli; sli <= dsli; ++sli) + for (def::coord row = minus_drow; row <= drow; ++row) + for (def::coord col = minus_dcol; col <= dcol; ++col) insert(dpoint3d(sli, row, col)); } Index: mln/win/cube3d.hh --- mln/win/cube3d.hh (revision 3091) +++ mln/win/cube3d.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 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 @@ -28,10 +29,9 @@ #ifndef MLN_WIN_CUBE3D_HH # define MLN_WIN_CUBE3D_HH -/*! \file mln/win/cube3d.hh - * - * \brief Definition of the mln::win::cube3d window. - */ +/// \file mln/win/cube3d.hh +/// +/// Definition of the mln::win::cube3d window. # include <mln/core/internal/classical_window_base.hh> # include <mln/core/alias/dpoint3d.hh> @@ -99,10 +99,12 @@ : length_(length) { mln_precondition(length % 2 == 1); - const int dind = length / 2; - for (int sli = - dind; sli <= dind; ++sli) - for (int row = - dind; row <= dind; ++row) - for (int col = - dind; col <= dind; ++col) + const def::coord + d = static_cast<def::coord>(length / 2), + minus_d = static_cast<def::coord>(- d); + for (def::coord sli = minus_d; sli <= d; ++sli) + for (def::coord row = minus_d; row <= d; ++row) + for (def::coord col = minus_d; col <= d; ++col) insert(dpoint3d(sli, row, col)); } Index: mln/algebra/quat.hh --- mln/algebra/quat.hh (revision 3091) +++ mln/algebra/quat.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -28,10 +29,9 @@ #ifndef MLN_ALGEBRA_QUAT_HH # define MLN_ALGEBRA_QUAT_HH -/*! \file mln/algebra/quat.hh - * - * \brief Define a class for quaternion algebra values. - */ +/// \file mln/algebra/quat.hh +/// +/// Define a class for quaternion algebra values. # include <cmath> @@ -47,6 +47,7 @@ // FIXME: pow, exp etc... are def here and in value::... + namespace mln { @@ -427,15 +428,15 @@ inline void quat::set_unit(float theta, const algebra::vec<3,T>& uv) { - static const float pi = 3.14159265358979323846; + static const float pi = 3.14159265358979323846f; mln_precondition(theta > - pi - mln_epsilon(float) && theta < pi + mln_epsilon(float)); mln_precondition(about_equal(norm::l2(uv), 1.f)); (void) pi; - this->v_[0] = cos(theta); - float sint = sin(theta); + this->v_[0] = std::cos(theta); + float sint = std::sin(theta); this->v_[1] = uv[0] * sint; this->v_[2] = uv[1] * sint; this->v_[3] = uv[2] * sint; @@ -456,7 +457,7 @@ float quat::theta() const { mln_precondition(is_unit()); - return acos(s()); + return std::acos(s()); } inline @@ -558,7 +559,7 @@ float theta = norm::l2(v); mln_precondition(!about_equal(theta, 0.f)); algebra::vec<3, float> uv = v / theta; - return quat(cos(theta), sin(theta) * uv); + return quat(std::cos(theta), std::sin(theta) * uv); } @@ -611,11 +612,11 @@ quat slerp(const quat& p, const quat& q, float h) { assert(interpol_ok(p, q, h)); - float omega = acos(p.sprod(q)); + float omega = std::acos(p.sprod(q)); return about_equal(omega, 0.f) ? lerp(p, q, h) : - quat((sin((1-h)*omega) * p + sin(h*omega) * q) / sin(omega)); + quat((std::sin((1-h)*omega) * p + std::sin(h*omega) * q) / std::sin(omega)); } inline Index: mln/algebra/vec.hh --- mln/algebra/vec.hh (revision 3091) +++ mln/algebra/vec.hh (working copy) @@ -434,7 +434,7 @@ float n_l2 = 0; for (unsigned i = 0; i < n; ++i) n_l2 += data_[i] * data_[i]; - n_l2 = sqrt(n_l2); + n_l2 = float(std::sqrt(n_l2)); for (unsigned i = 0; i < n; ++i) data_[i] = static_cast<T>(data_[i] / n_l2); return *this; Index: mln/io/pbm/load.hh --- mln/io/pbm/load.hh (revision 3091) +++ mln/io/pbm/load.hh (working copy) @@ -115,7 +115,7 @@ if (i % 8 == 0) file.read((char*)(&c), 1); ima(p) = !(c & 128); - c *= 2; + c = static_cast<char>(c * 2); ++i; } } Index: mln/norm/linfty.hh --- mln/norm/linfty.hh (revision 3091) +++ mln/norm/linfty.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -28,12 +29,12 @@ #ifndef MLN_NORM_LINFTY_HH # define MLN_NORM_LINFTY_HH -/*! \file mln/norm/linfty.hh - * - * \brief Define some L-infinity-norm related routines. - * \see http://mathworld.wolfram.com/L-Infinity-Norm.html for more - * information. - */ +/// \file mln/norm/linfty.hh +/// +/// Define some L-infinity-norm related routines. +/// +/// \see http://mathworld.wolfram.com/L-Infinity-Norm.html for more +/// information. # include <mln/math/abs.hh> # include <mln/algebra/vec.hh> Index: mln/norm/l1.hh --- mln/norm/l1.hh (revision 3091) +++ mln/norm/l1.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -28,11 +29,10 @@ #ifndef MLN_NORM_L1_HH # define MLN_NORM_L1_HH -/*! \file mln/norm/l1.hh - * - * \brief Define some L1-norm related routines. - * \see http://mathworld.wolfram.com/L1-Norm.html for more information. - */ +/// \file mln/norm/l1.hh +/// +/// \brief Define some L1-norm related routines. +/// \see http://mathworld.wolfram.com/L1-Norm.html for more information. # include <mln/math/abs.hh> # include <mln/algebra/vec.hh> @@ -40,6 +40,7 @@ // FIXME: Use mln_sum_x (to be renamed as mln_sum_product) instead of // mln_sum. + namespace mln { @@ -75,9 +76,13 @@ mln_sum(C) l1_(const V& vec) { - mln_sum(C) m = 0; + typedef mln_sum(C) M; + M m = 0; for (unsigned i = 0; i < n; ++i) - m += mln::math::abs (vec[i]); + { + M v_i = static_cast<M>(mln::math::abs(vec[i])); + m = static_cast<M>(m + v_i); + } return m; } @@ -86,9 +91,13 @@ mln_sum(C) l1_distance_(const V& vec1, const V& vec2) { - mln_sum(C) d = 0; + typedef mln_sum(C) D; + D d = 0; for (unsigned i = 0; i < n; ++i) - d += mln::math::abs (vec1[i] - vec2[i]); + { + D v1_v2 = static_cast<D>(mln::math::abs(vec1[i] - vec2[i])); + d = static_cast<D>(d + v1_v2); + } return d; } Index: mln/norm/l2.hh --- mln/norm/l2.hh (revision 3091) +++ mln/norm/l2.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -28,11 +29,11 @@ #ifndef MLN_NORM_L2_HH # define MLN_NORM_L2_HH -/*! \file mln/norm/l2.hh - * - * \brief Define some L2-norm related routines. - * \see http://mathworld.wolfram.com/L2-Norm.html for more information. - */ +/// \file mln/norm/l2.hh +/// +/// Define some L2-norm related routines. +/// +/// \see http://mathworld.wolfram.com/L2-Norm.html for more information. # include <mln/math/sqr.hh> # include <mln/math/sqrt.hh> @@ -78,9 +79,13 @@ mln_sum(C) l2_(const V& vec) { - mln_sum(C) m = 0; + typedef mln_sum(C) M; + M m = 0; for (unsigned i = 0; i < n; ++i) - m += mln::math::sqr(vec[i]); + { + M sqr_v_i = static_cast<M>(mln::math::sqr(vec[i])); + m = static_cast<M>(m + sqr_v_i); + } return mln::math::sqrt(m); } @@ -89,9 +94,13 @@ mln_sum(C) l2_distance_(const V& vec1, const V& vec2) { - mln_sum(C) d = 0; + typedef mln_sum(C) D; + D d = 0; for (unsigned i = 0; i < n; ++i) - d += mln::math::sqr(vec1[i] - vec2[i]); + { + D sqr_v1_v2 = static_cast<D>(mln::math::sqr(vec1[i] - vec2[i])); + d = static_cast<D>(d + sqr_v1_v2); + } return mln::math::sqrt(d); } Index: mln/canvas/browsing/snake_fwd.hh --- mln/canvas/browsing/snake_fwd.hh (revision 3091) +++ mln/canvas/browsing/snake_fwd.hh (working copy) @@ -105,7 +105,7 @@ // trait::image::dimension::two_d)::check(); trace::entering("canvas::browsing::snake_fwd"); mln_precondition(f.input.has_data()); - int + def::coord min_row = geom::min_row(f.input), max_row = geom::max_row(f.input), min_col = geom::min_col(f.input), max_col = geom::max_col(f.input); Index: mln/canvas/browsing/dir_struct_elt_incr_update.hh --- mln/canvas/browsing/dir_struct_elt_incr_update.hh (revision 3091) +++ mln/canvas/browsing/dir_struct_elt_incr_update.hh (working copy) @@ -36,6 +36,7 @@ # include <mln/core/concept/browsing.hh> # include <mln/core/concept/image.hh> + namespace mln { @@ -110,11 +111,12 @@ pmin = f.input.domain().pmin(), pmax = f.input.domain().pmax(); - const mln_deduce(I, site, coord) + typedef mln_deduce(I, site, coord) C; + const C pmin_dir = pmin[f.dir], pmax_dir = pmax[f.dir], - pmin_dir_plus_half_length = pmin_dir + f.length / 2, - pmax_dir_minus_half_length = pmax_dir - f.length / 2; + pmin_dir_plus_half_length = static_cast<C>(pmin_dir + f.length / 2), + pmax_dir_minus_half_length = static_cast<C>(pmax_dir - f.length / 2); mln_psite(I) pt, pu; Index: tests/opt/at.cc --- tests/opt/at.cc (revision 3091) +++ tests/opt/at.cc (working copy) @@ -78,7 +78,7 @@ const II csub_ima(ima, make::box1d(4, 10)); point1d p(5); - data::fill(ima, 51); + data::fill(ima, short(51)); mln_assertion(csub_ima(p) == opt::at(csub_ima, 5)); opt::at(sub_ima, 5) = 12; mln_assertion(sub_ima(p) == 12); @@ -92,7 +92,7 @@ const II ccast(in); point1d p(5); - data::fill(in, 51); + data::fill(in, (unsigned short)51); mln_assertion(ccast(p) == opt::at(ccast, 5)); // FIXME //opt::at(cast, 5) = 12; @@ -120,7 +120,7 @@ const II csub_ima(ima, make::box2d(4, 4, 10, 10)); point2d p(5, 5); - data::fill(ima, 51); + data::fill(ima, short(51)); mln_assertion(csub_ima(p) == opt::at(csub_ima, 5, 5)); opt::at(sub_ima, 5, 5) = 12; mln_assertion(sub_ima(p) == 12); @@ -134,7 +134,7 @@ const II ccast(in); point2d p(5,5); - data::fill(in, 51); + data::fill(in, (unsigned short)51); mln_assertion(ccast(p) == opt::at(ccast, 5, 5)); // FIXME //opt::at(cast, 5) = 12; Index: tests/level/transform_inplace.cc --- tests/level/transform_inplace.cc (revision 3091) +++ tests/level/transform_inplace.cc (working copy) @@ -27,7 +27,7 @@ /// \file tests/level/transform_inplace.cc /// -/// Tests on mln::level::transform_inplace +/// Tests on mln::level::transform_inplace. #include <mln/core/image/image1d.hh> @@ -37,19 +37,17 @@ #include <mln/core/image/image_if.hh> #include <mln/core/image/sub_image.hh> #include <mln/core/image/extension_val.hh> - - #include <mln/core/routine/duplicate.hh> - #include <mln/fun/v2v/inc.hh> #include <mln/fun/v2v/dec.hh> +#include <mln/fun/p2b/chess.hh> + #include <mln/debug/iota.hh> #include <mln/level/transform_inplace.hh> #include <mln/level/compare.hh> -#include <mln/fun/p2b/chess.hh> int main() @@ -60,24 +58,26 @@ // image 2d tests { - image2d<int> ref(size, size); + typedef int T; + image2d<T> ref(size, size); debug::iota(ref); - image2d<int> ima = duplicate(ref); - level::transform_inplace(ima, fun::v2v::inc<int>()); - level::transform_inplace(ima, fun::v2v::dec<int>()); + image2d<T> ima = duplicate(ref); + level::transform_inplace(ima, fun::v2v::inc<T>()); + level::transform_inplace(ima, fun::v2v::dec<T>()); mln_assertion(ima == ref); } /// image 1d test { - image1d<unsigned short> ref(size); + typedef unsigned short T; + image1d<T> ref(size); debug::iota(ref); - image1d<unsigned short> ima = duplicate(ref); - level::transform_inplace(ima, fun::v2v::inc<int>()); - level::transform_inplace(ima, fun::v2v::dec<int>()); + image1d<T> ima = duplicate(ref); + level::transform_inplace(ima, fun::v2v::inc<T>()); + level::transform_inplace(ima, fun::v2v::dec<T>()); mln_assertion(ima == ref); } @@ -85,30 +85,34 @@ /// image 3d test { - image3d<unsigned short> ref(size, size, size); + typedef unsigned short T; + image3d<T> ref(size, size, size); debug::iota(ref); - image3d<unsigned short> ima = duplicate(ref); - level::transform_inplace(ima, fun::v2v::inc<int>()); - level::transform_inplace(ima, fun::v2v::dec<int>()); + image3d<T> ima = duplicate(ref); + level::transform_inplace(ima, fun::v2v::inc<T>()); + level::transform_inplace(ima, fun::v2v::dec<T>()); mln_assertion(ima == ref); } // flat image test { - flat_image<short, box2d> ref(5, make::box2d(size, size)); + typedef short T; + flat_image<T, box2d> + ref(5, make::box2d(size, size)), + ima(5, make::box2d(size, size)); - flat_image<short, box2d> ima(5, make::box2d(size, size)); - level::transform_inplace(ima, fun::v2v::inc<int>()); - level::transform_inplace(ima, fun::v2v::dec<int>()); + level::transform_inplace(ima, fun::v2v::inc<T>()); + level::transform_inplace(ima, fun::v2v::dec<T>()); mln_assertion(ima == ref); } // image if test { - typedef image2d<unsigned short> I; + typedef unsigned short T; + typedef image2d<T> I; typedef image_if<I, fun::p2b::chess> II; I ref(size, size); @@ -118,8 +122,8 @@ I ima = duplicate(ref); II ima_if = ima | fun::p2b::chess(); - level::transform_inplace(ima_if, fun::v2v::inc<int>()); - level::transform_inplace(ima_if, fun::v2v::dec<int>()); + level::transform_inplace(ima_if, fun::v2v::inc<T>()); + level::transform_inplace(ima_if, fun::v2v::dec<T>()); mln_assertion(ima_if == ref_if); } @@ -145,16 +149,17 @@ // extended image test { - typedef image2d<int> I; - typedef extension_val< image2d<int> > II; + typedef int T; + typedef image2d<T> I; + typedef extension_val< image2d<T> > II; I ref(size, size); I ima = duplicate(ref); II extend_ima(ima, 5); - level::transform_inplace(extend_ima, fun::v2v::inc<int>()); - level::transform_inplace(extend_ima, fun::v2v::dec<int>()); + level::transform_inplace(extend_ima, fun::v2v::inc<T>()); + level::transform_inplace(extend_ima, fun::v2v::dec<T>()); mln_assertion(extend_ima == ref); Index: tests/level/transform.cc --- tests/level/transform.cc (revision 3091) +++ tests/level/transform.cc (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 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 @@ -27,7 +28,7 @@ /// \file tests/level/transform.cc /// -/// Tests on mln::level::transform +/// Tests on mln::level::transform. #include <cmath> @@ -54,12 +55,14 @@ #include <mln/debug/iota.hh> #include <mln/debug/println.hh> + struct mysqrt : mln::Function_v2v<mysqrt> { typedef unsigned short result; - result operator()(unsigned short c) const + template <typename T> + result operator()(T c) const { - return result( std::sqrt(float(c)) ); + return static_cast<result>( std::sqrt(float(c)) ); } }; @@ -121,12 +124,11 @@ /// pw image test { - const pw::image<fun::p2v::iota, box2d> ima(fun::p2v::iota(), make::box2d(2,2, 5,5)); image2d<short unsigned int> out(8, 8); - data::fill(out, 0); + data::fill(out, (short unsigned int)0); out = level::transform(ima, mysqrt()); } @@ -171,8 +173,8 @@ II cast(in); III out(size, size); - data::fill(in, 51); - data::fill(out, 42); + data::fill(in, (unsigned short)51); + data::fill(out, (unsigned short)42); out = level::transform(cast, mysqrt()); Index: tests/level/sort_psites.cc --- tests/level/sort_psites.cc (revision 3091) +++ tests/level/sort_psites.cc (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008 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 @@ -25,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/level/sort_psites.cc - * - * \brief Tests on mln::level::sort_psites. - */ +/// \file tests/level/sort_psites.cc +/// +/// Tests on mln::level::sort_psites. #include <mln/core/image/image2d.hh> #include <mln/debug/iota.hh> @@ -48,12 +48,13 @@ p_array<point2d> array_inc_ref; p_array<point2d> array_dec_ref; - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 3; ++j) + typedef def::coord C; + for (C i = 0; i < 3; ++i) + for (C j = 0; j < 3; ++j) array_inc_ref.append(point2d(i, j)); - for (int i = 2; i >= 0; --i) - for (int j = 2; j >= 0; --j) + for (C i = 2; i >= 0; --i) + for (C j = 2; j >= 0; --j) array_dec_ref.append(point2d(i, j)); mln_assertion(array_inc == array_inc_ref); Index: tests/level/Makefile.am --- tests/level/Makefile.am (revision 3091) +++ tests/level/Makefile.am (working copy) @@ -22,7 +22,6 @@ paste \ saturate \ sort_psites \ - sort_psites_full \ stretch \ transform \ transform_inplace \ @@ -50,7 +49,4 @@ transform_inplace_SOURCES = transform_inplace.cc update_SOURCES = update.cc -# Lengthy tests. -sort_psites_full_SOURCES = sort_psites_full.cc - TESTS = $(check_PROGRAMS) Index: tests/data/paste.cc --- tests/data/paste.cc (revision 3091) +++ tests/data/paste.cc (working copy) @@ -113,7 +113,7 @@ make::box2d(2,2, 5,5)); image2d<short unsigned int> out(8, 8); - data::fill(out, 0); + data::fill(out, (short unsigned int)0); data::paste(ima, out); } @@ -154,8 +154,8 @@ II cast(in); III out(size, size); - data::fill(in, 51); - data::fill(out, 42); + data::fill(in, (unsigned short)51); + data::fill(out, (unsigned short)42); data::paste(cast, out); Index: tests/data/fill_with_image.cc --- tests/data/fill_with_image.cc (revision 3091) +++ tests/data/fill_with_image.cc (working copy) @@ -149,7 +149,7 @@ make::box2d(-2,-2, 15,15)); image2d<short unsigned int> out(8, 8); - data::fill(out, 0); + data::fill(out, (short unsigned int)0); data::fill_with_image(out, ima); } @@ -191,8 +191,8 @@ II cast(in); I out(size, size); - data::fill(in, 51); - data::fill(out, 42); + data::fill(in, (unsigned short)51); + data::fill(out, (unsigned short)42); data::fill_with_image(out, cast); Index: tests/linear/convolve.cc --- tests/linear/convolve.cc (revision 3091) +++ tests/linear/convolve.cc (working copy) @@ -26,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/linear/convolve.cc - * - * \brief Tests on mln::linear::convolve. - */ +/// \file tests/linear/convolve.cc +/// +/// Tests on mln::linear::convolve. #include <mln/core/image/image2d.hh> #include <mln/value/int_u8.hh> @@ -56,13 +55,14 @@ image2d<int_u8> lena; io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm"); - float ws[] = { .04, .04, .04, .04, .04, - .04, .04, .04, .04, .04, - .04, .04, .04, .04, .04, - .04, .04, .04, .04, .04, - .04, .04, .04, .04, .04 }; - w_window2d_float w = make::w_window2d(ws); - image2d<float> tmp = linear::convolve(lena, w); + float w = .04f; + float ws[] = { w, w, w, w, w, + w, w, w, w, w, + w, w, w, w, w, + w, w, w, w, w, + w, w, w, w, w }; + w_window2d_float w_win = make::w_window2d(ws); + image2d<float> tmp = linear::convolve(lena, w_win); io::pgm::save(level::transform(tmp, math::round<int_u8>()), "out.pgm"); Index: tests/linear/convolve_directional.cc --- tests/linear/convolve_directional.cc (revision 3091) +++ tests/linear/convolve_directional.cc (working copy) @@ -26,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/linear/convolve_directional.cc - * - * \brief Tests on mln::linear::convolve_directional. - */ +/// \file tests/linear/convolve_directional.cc +/// +/// Tests on mln::linear::convolve_directional. #include <mln/core/image/image2d.hh> #include <mln/value/int_u8.hh> @@ -56,7 +55,8 @@ image2d<int_u8> lena; io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm"); - float ws[] = { .11, .11, .11, .11, .11, .11, .11, .11, .11 }; + float w = .11f; + float ws[] = { w, w, w, w, w, w, w, w, w }; image2d<float> tmp = linear::convolve_directional(lena, 1, ws); io::pgm::save(level::transform(tmp, math::round<int_u8>()), Index: tests/linear/gaussian.cc --- tests/linear/gaussian.cc (revision 3091) +++ tests/linear/gaussian.cc (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008 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 @@ -25,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/linear/gaussian.cc - * - * \brief Test on mln::linear::gaussian. - */ +/// \file tests/linear/gaussian.cc +/// +/// Test on mln::linear::gaussian. #include <mln/core/image/image2d.hh> #include <mln/value/int_u8.hh> Index: tests/geom/Makefile.am --- tests/geom/Makefile.am (revision 3091) +++ tests/geom/Makefile.am (working copy) @@ -18,7 +18,6 @@ nsites \ nslis \ pmin_pmax \ -resize \ seed2tiling \ seed2tiling_roundness @@ -38,7 +37,6 @@ nsites_SOURCES = nsites.cc nslis_SOURCES = nslis.cc pmin_pmax_SOURCES = pmin_pmax.cc -resize_SOURCES = resize.cc seed2tiling_SOURCES = seed2tiling.cc seed2tiling_roundness_SOURCES = seed2tiling_roundness.cc Index: tests/norm/l2.cc --- tests/norm/l2.cc (revision 3091) +++ tests/norm/l2.cc (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -25,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/norm/l2.cc - * - * \brief Test the L2-norm. - */ +/// \file tests/norm/l2.cc +/// +/// \brief Test the L2-norm. #include <cmath> #include <cassert> @@ -59,14 +59,15 @@ } } + int main() { typedef mln::algebra::vec<3, int> vec_t; // Reference value. - float d = std::sqrt((4 - 2) * (4 - 2) + + float d = float(std::sqrt((4 - 2) * (4 - 2) + (1 + 2) * (1 + 2) + - (0 - 3) * (0 - 3)); + (0 - 3) * (0 - 3))); // Tests using mln::algebra::vec. vec_t t, u; Index: tests/norm/common.hh --- tests/norm/common.hh (revision 3091) +++ tests/norm/common.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -32,27 +33,32 @@ #include <mln/math/abs.hh> + // FIXME: We should have a almost_equal function somewhere in Milena. -static const float epsilon = 0.0001; +static const float epsilon = 0.0001f; + namespace test { template <typename Norm, typename V> void - check_norm(const Norm norm, const V& vec1, const V& vec2) + check_norm(const Norm& norm, const V& vec1, const V& vec2) { assert(mln::math::abs(norm(vec1) - norm(vec2)) < epsilon); } template <typename Distance, typename V, typename S> void - check_distance (const Distance dist, const V& vec1, const V& vec2, + check_distance(const Distance& dist, const V& vec1, const V& vec2, const S& ref_val) { - assert(mln::math::abs(dist(vec1, vec2) - ref_val) < epsilon); + float delta = mln::math::abs(static_cast<float>(dist(vec1, vec2)) + - static_cast<float>(ref_val)); + assert(delta < epsilon); } -} // End of namespace test. +} // end of namespace test. + #endif // !TESTS_NORM_COMMON_HH Index: tests/norm/linfty.cc --- tests/norm/linfty.cc (revision 3091) +++ tests/norm/linfty.cc (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -25,10 +26,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/norm/linfty.cc - * - * \brief Test the L-infinity-norm. - */ +/// \file tests/norm/linfty.cc +/// +/// Test the L-infinity-norm. #include <tests/norm/common.hh> @@ -62,9 +62,9 @@ typedef mln::algebra::vec<3, int> vec_t; // Reference value. - float d = std::max(std::abs(4 - 2), + float d = float(std::max(std::abs(4 - 2), std::max(std::abs(1 + 2), - std::abs(0 - 4))); + std::abs(0 - 4)))); vec_t t, u; t.set(2, -2, 4);
participants (1)
-
Thierry Geraud